View Javadoc

1   /***
2   *
3   * The owl-s matcher software is subject to the GNU Lesser General
4   * Public License Version 2.1 (the "License"). You may not copy or use this
5   * file, in either source code or executable form, except in compliance
6   * with the License. You may obtain a copy of the License at
7   * http://www.fsf.org/licenses/lgpl.txt or http://www.opensource.org/.
8   *
9   * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied without
11  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  * PURPOSE. See the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this distribution; if not, write to the
17  *
18  * Free Software Foundation, Inc.,
19  * 59 Temple Place, Suite 330,
20  * Boston, MA  02111-1307 USA
21  *
22  * Copyright (C) 2003-2004
23  * TU Berlin, FG IVS
24  * Stefan Tang,
25  * Christoph Liebetruth,
26  * Michael C. Jaeger, 
27  *
28  * More information available at http://ivs.tu-berlin.de/
29  *
30  * $Id$
31  *
32  */
33  package de.tuberlin.ivs.owl.gui;
34  
35  import java.awt.*;
36  import javax.swing.*;
37  import java.awt.event.*;
38  import java.io.File;
39  import java.net.*;
40  
41  /***
42   * Displays the dialog when the user wants to load a service (either requested
43   * or advertised service).
44   *
45   * @author Stefan Tang (steftang@stanford.edu), Christoph Liebetruth (christophl@voelcker.com)
46   * @version 1.1
47   */
48  public class OpenServiceDialog extends JDialog {
49  
50    // --------------------------------------
51    // ------- AUTO-GENERATED FIELDS --------
52    // --------------------------------------
53    JPanel panel1 = new JPanel();
54    JPanel jPanel1 = new JPanel();
55    JPanel jPanel2 = new JPanel();
56    JButton okButton = new JButton();
57    BorderLayout borderLayout1 = new BorderLayout();
58    JPanel jPanel3 = new JPanel();
59    JPanel jPanel4 = new JPanel();
60    JTextField urlTextField = new JTextField();
61    JButton browseButton = new JButton();
62    JLabel jLabel1 = new JLabel();
63    FlowLayout flowLayout1 = new FlowLayout();
64    FlowLayout flowLayout2 = new FlowLayout();
65    JPanel jPanel6 = new JPanel();
66    BorderLayout borderLayout2 = new BorderLayout();
67    BorderLayout borderLayout3 = new BorderLayout();
68    JButton cancelButton = new JButton();
69    MainFrame mainFrame;
70    boolean request = true;
71  
72    /***
73     * Constructor. Initialiazes this dialog.
74     * @param frame The parent frame of this dialog.
75     * @param title The title of this dialog.
76     * @param modal true if the parent frame should be disabled when this dialog
77     * is displayed, false otherwise.
78     * @param mainFrame The main frame.
79     * @param request true if the service that will be loaded is the requested
80     * service, false if it is the advertised service.
81     */
82    public OpenServiceDialog(Frame frame, String title, boolean modal, MainFrame mainFrame, boolean request) {
83      super(frame, title, modal);
84      this.mainFrame = mainFrame;
85      this.request = request;
86      try {
87        jbInit();
88        pack();
89      }
90      catch(Exception ex) {
91        ex.printStackTrace();
92      }
93      if (request) {
94        setTitle("Open Requested Service");
95      } else {
96        setTitle("Open Advertised Service");
97      }
98    }
99  
100   // component initialization.
101   private void jbInit() throws Exception {
102     panel1.setLayout(borderLayout1);
103     jPanel1.setLayout(borderLayout3);
104     okButton.setToolTipText("");
105     okButton.setText("OK");
106     okButton.addActionListener(new OpenRequestedServiceDialog_okButton_actionAdapter(this));
107     jPanel3.setLayout(flowLayout1);
108     jPanel3.setBorder(null);
109     jPanel3.setDebugGraphicsOptions(0);
110     jPanel4.setLayout(flowLayout2);
111     urlTextField.setMinimumSize(new Dimension(200, 21));
112     urlTextField.setPreferredSize(new Dimension(300, 21));
113     urlTextField.setText("");
114     browseButton.setText("Browse");
115     browseButton.addActionListener(new OpenServiceDialog_browseButton_actionAdapter(this));
116     if (request) {
117       jLabel1.setText(
118           "Enter the URL of the requested Service or browse for a local file.");
119     } else {
120       jLabel1.setText(
121           "Enter the URL of the advertised Service or browse for a local file.");
122     }
123     jPanel2.setBorder(null);
124     jPanel2.setDebugGraphicsOptions(0);
125     jPanel1.setBorder(null);
126     jPanel1.setDebugGraphicsOptions(0);
127     jPanel6.setLayout(borderLayout2);
128     cancelButton.setText("Cancel");
129     cancelButton.addActionListener(new OpenRequestedServiceDialog_cancelButton_actionAdapter(this));
130     this.setResizable(false);
131     jLabel1.setText("Please enter the URL of the service specifiaction or browse for a " +
132     "local file");
133     jPanel4.setBorder(null);
134     getContentPane().add(panel1);
135     panel1.add(jPanel1, BorderLayout.CENTER);
136     panel1.add(jPanel2, BorderLayout.SOUTH);
137     jPanel2.add(okButton, null);
138     jPanel2.add(cancelButton, null);
139     jPanel4.add(urlTextField, null);
140     jPanel4.add(browseButton, null);
141     jPanel6.add(jPanel3, BorderLayout.NORTH);
142     jPanel3.add(jLabel1, null);
143     jPanel6.add(jPanel4, BorderLayout.CENTER);
144     jPanel1.add(jPanel6, BorderLayout.CENTER);
145   }
146 
147   // Is called when the user clicks the 'ok' button.
148   void okButton_actionPerformed(ActionEvent e) {
149     this.hide();
150     try {
151       URL url = new URL(urlTextField.getText());
152       mainFrame.loadService(url, request);
153     } catch (MalformedURLException mfe) {
154       JOptionPane.showMessageDialog(this,"Error forming URL","Error",JOptionPane.WARNING_MESSAGE);
155       return;
156     }
157   }
158 
159   // Is called when the user clicks the 'cancel' button.
160   void cancelButton_actionPerformed(ActionEvent e) {
161     this.hide();
162   }
163 
164   // Is called when the user clicks the 'browse' button.
165   void browseButton_actionPerformed(ActionEvent e) {
166     JFileChooser fileChooser = new JFileChooser();
167     DamlFileFilter filter = new DamlFileFilter();
168     fileChooser.setFileFilter(filter);
169     fileChooser.showOpenDialog(this);
170     File file = fileChooser.getSelectedFile();
171     if (file!=null) {
172       try {
173         urlTextField.setText(file.toURL().toExternalForm());
174       } catch (MalformedURLException mfe) {
175 
176       }
177     }
178   }
179 }
180 
181 
182 // -----------------------------------------
183 // ------- AUTO GENERATED CLASSES ----------
184 // -----------------------------------------
185 class OpenRequestedServiceDialog_okButton_actionAdapter implements java.awt.event.ActionListener {
186   OpenServiceDialog adaptee;
187   OpenRequestedServiceDialog_okButton_actionAdapter(OpenServiceDialog adaptee) {
188     this.adaptee = adaptee;
189   }
190   public void actionPerformed(ActionEvent e) {
191     adaptee.okButton_actionPerformed(e);
192   }
193 }
194 class OpenRequestedServiceDialog_cancelButton_actionAdapter implements java.awt.event.ActionListener {
195   OpenServiceDialog adaptee;
196   OpenRequestedServiceDialog_cancelButton_actionAdapter(OpenServiceDialog adaptee) {
197     this.adaptee = adaptee;
198   }
199   public void actionPerformed(ActionEvent e) {
200     adaptee.cancelButton_actionPerformed(e);
201   }
202 }
203 class OpenServiceDialog_browseButton_actionAdapter implements java.awt.event.ActionListener {
204   OpenServiceDialog adaptee;
205   OpenServiceDialog_browseButton_actionAdapter(OpenServiceDialog adaptee) {
206     this.adaptee = adaptee;
207   }
208   public void actionPerformed(ActionEvent e) {
209     adaptee.browseButton_actionPerformed(e);
210   }
211 }