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 java.util.Vector;
37  import javax.swing.*;
38  import de.tuberlin.ivs.owl.service.*;
39  import java.awt.event.*;
40  
41  /***
42   * Panel that displays a service after it is loaded/parsed.
43   *
44  * @author Stefan Tang (steftang@stanford.edu), Christoph Liebetruth (christophl@voelcker.com)
45   * @version 1.1
46    */
47  public class ShowServicePanel extends JPanel {
48  
49    // --------------------------------------
50    // ------- AUTO-GENERATED FIELDS --------
51    // --------------------------------------
52    JPanel jPanel1 = new JPanel();
53    JPanel jPanel2 = new JPanel();
54    JPanel jPanel3 = new JPanel();
55    JButton actorButton = new JButton();
56    JButton descriptionButton = new JButton();
57    JPanel jPanel4 = new JPanel();
58    JLabel jLabel1 = new JLabel();
59    JPanel jPanel5 = new JPanel();
60    JComboBox profileComboBox = new JComboBox();
61    BorderLayout borderLayout3 = new BorderLayout();
62    GridLayout gridLayout1 = new GridLayout();
63    JPanel jPanel6 = new JPanel();
64    JPanel jPanel7 = new JPanel();
65    JLabel serviceLabel = new JLabel();
66    BorderLayout borderLayout1 = new BorderLayout();
67    BorderLayout borderLayout2 = new BorderLayout();
68    BorderLayout borderLayout4 = new BorderLayout();
69    ImageIcon image1;
70    ImageIcon image2;
71    GridLayout gridLayout2 = new GridLayout();
72    JPanel jSplitPane1 = new JPanel();
73    JPanel jPanel8 = new JPanel();
74    JPanel jPanel9 = new JPanel();
75    JPanel jPanel10 = new JPanel();
76    JPanel jPanel11 = new JPanel();
77    JLabel jLabel2 = new JLabel();
78    JScrollPane jScrollPane1 = new JScrollPane();
79    BorderLayout borderLayout5 = new BorderLayout();
80    GridLayout gridLayout3 = new GridLayout();
81    JList inputsList = new JList();
82    JPanel jPanel12 = new JPanel();
83    JLabel jLabel3 = new JLabel();
84    JPanel jPanel13 = new JPanel();
85    BorderLayout borderLayout6 = new BorderLayout();
86    JScrollPane jScrollPane2 = new JScrollPane();
87    GridLayout gridLayout4 = new GridLayout();
88    JList outputsList = new JList();
89    GridLayout gridLayout5 = new GridLayout();
90  
91    /***
92     * The service that this panel represents.
93     */
94    Service service;
95  
96    boolean request = true;
97    MainFrame mainFrame;
98  
99    /***
100    * Constructor. Initializes the panel.
101    * @param service The service that this panel displays.
102    * @param request True if this panel displays the requested service, false
103    * if it displays the advertised service.
104    * @param parent The main frame.
105    */
106   public ShowServicePanel(Service service, boolean request,MainFrame parent) {
107     this.request = request;
108     try {
109       jbInit();
110     }
111     catch(Exception ex) {
112       ex.printStackTrace();
113     }
114     this.service = service;
115     mainFrame = parent;
116     initFields();
117   }
118 
119   /***
120    * Initializes all fields with the service information.
121    */
122   private void initFields() {
123     if (service!=null) {
124       for (int i=0;i<service.getProfiles().size(); i++) {
125         Profile profile = (Profile)service.getProfiles().elementAt(i);
126         profileComboBox.addItem(profile.getID());
127         if (i==0) {
128           changeProfile(profile);
129         }
130       }
131     }
132     if (request) {
133       serviceLabel.setText("Requested Service");
134     } else {
135       serviceLabel.setText("Advertised Service");
136     }
137 
138   }
139 
140   /***
141    * Changes a the displayed information to a new profile.
142    * @param profile The profile whose information is to be displayed.
143    */
144   private void changeProfile(Profile profile) {
145     if (profile!=null) {
146       if (profile.getInputs()!=null) {
147         Vector listData = new Vector();
148         for (int i=0; i<profile.getInputs().size(); i++) {
149           Input tempInput = (Input)profile.getInputs().elementAt(i);
150           String data = tempInput.getPropertyName();
151           String value = tempInput.getRestrictedTo();
152           if (value!=null) {
153             if (value.lastIndexOf("#")>0) {
154               value = value.substring(value.lastIndexOf("#")+1);
155             }
156             data = data + " : " + value;
157           }
158           listData.addElement(data);
159         }
160         inputsList.setListData(listData);
161       }
162       if (profile.getOutputs()!=null) {
163         Vector listData = new Vector();
164         for (int i=0; i<profile.getOutputs().size(); i++) {
165           Output tempOutput = (Output)profile.getOutputs().elementAt(i);
166           String data = tempOutput.getPropertyName();
167           String value = tempOutput.getRestrictedTo();
168           if (value!=null) {
169             if (value.lastIndexOf("#")>0) {
170               value = value.substring(value.lastIndexOf("#")+1);
171             }
172             data = data + " : " + value;
173           }
174 
175           listData.addElement(data);
176         }
177         outputsList.setListData(listData);
178       }
179     }
180   }
181 
182   /***
183    * Returns the current selected profile.
184    * @return The ID of the selected profile.
185    */
186   public String getSelectedProfile() {
187     return profileComboBox.getSelectedItem().toString();
188   }
189 
190   // component initialization.
191   void jbInit() throws Exception {
192     image1 = new ImageIcon(de.tuberlin.ivs.owl.gui.MainFrame.class.getResource("text.png"));
193     image2 = new ImageIcon(de.tuberlin.ivs.owl.gui.MainFrame.class.getResource("actor.png"));
194     this.setLayout(borderLayout4);
195     jPanel1.setLayout(borderLayout3);
196     jPanel2.setLayout(gridLayout2);
197     actorButton.setPreferredSize(new Dimension(29, 27));
198     actorButton.setToolTipText("View Contact Information");
199     actorButton.setBorderPainted(false);
200     actorButton.setIcon(image2);
201     actorButton.setText("");
202     actorButton.addMouseListener(new ShowServicePanel_actorButton_mouseAdapter(this));
203     actorButton.addActionListener(new ShowServicePanel_actorButton_actionAdapter(this));
204     jLabel1.setText("Current Profile");
205     jPanel5.setBorder(null);
206     jPanel5.setMaximumSize(new Dimension(32767, 32767));
207     jPanel5.setLayout(gridLayout1);
208     jPanel6.setLayout(borderLayout1);
209     jPanel7.setBackground(Color.white);
210     jPanel7.setLayout(borderLayout2);
211     serviceLabel.setFont(new java.awt.Font("Dialog", 1, 11));
212     serviceLabel.setHorizontalAlignment(SwingConstants.LEFT);
213     serviceLabel.setText("Requested Service");
214     serviceLabel.setVerticalAlignment(SwingConstants.CENTER);
215     jPanel1.setBorder(null);
216     jPanel4.setBorder(null);
217     jPanel6.setBorder(null);
218     jPanel3.setBorder(null);
219     descriptionButton.setPreferredSize(new Dimension(29, 27));
220     descriptionButton.setToolTipText("View Service Description");
221     descriptionButton.setBorderPainted(false);
222     descriptionButton.setIcon(image1);
223     descriptionButton.setText("");
224     descriptionButton.addMouseListener(new ShowServicePanel_descriptionButton_mouseAdapter(this));
225     descriptionButton.addActionListener(new ShowServicePanel_descriptionButton_actionAdapter(this));
226     //jSplitPane1.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
227     jPanel10.setBackground(Color.lightGray);
228     jLabel2.setFont(new java.awt.Font("Dialog", 1, 11));
229     jLabel2.setText("Inputs");
230     jPanel8.setLayout(borderLayout5);
231     jPanel11.setLayout(gridLayout3);
232     jPanel12.setBackground(Color.lightGray);
233     jPanel12.setForeground(Color.black);
234     jLabel3.setFont(new java.awt.Font("Dialog", 1, 11));
235     jLabel3.setText("Outputs");
236     jPanel9.setLayout(borderLayout6);
237     jPanel13.setLayout(gridLayout4);
238     jSplitPane1.setLayout(gridLayout5);
239     gridLayout5.setRows(1);
240     jPanel8.setBorder(BorderFactory.createEtchedBorder());
241     jPanel9.setBorder(BorderFactory.createEtchedBorder());
242     profileComboBox.addItemListener(new ShowServicePanel_profileComboBox_itemAdapter(this));
243     jPanel1.add(jPanel4, BorderLayout.WEST);
244     jPanel4.add(jLabel1, null);
245     jPanel1.add(jPanel5,  BorderLayout.CENTER);
246     jPanel5.add(profileComboBox, null);
247     this.add(jPanel2, BorderLayout.CENTER);
248     jPanel2.add(jSplitPane1, null);
249     jSplitPane1.add(jPanel8);
250     jPanel8.add(jPanel10,  BorderLayout.NORTH);
251     jPanel10.add(jLabel2, null);
252     jPanel8.add(jPanel11, BorderLayout.CENTER);
253     jPanel11.add(jScrollPane1, null);
254     jScrollPane1.getViewport().add(inputsList, null);
255     jSplitPane1.add(jPanel9);
256     jPanel9.add(jPanel13, BorderLayout.CENTER);
257     jPanel13.add(jScrollPane2, null);
258     jPanel9.add(jPanel12, BorderLayout.NORTH);
259     jPanel12.add(jLabel3, null);
260     jScrollPane2.getViewport().add(outputsList, null);
261     this.add(jPanel3, BorderLayout.SOUTH);
262     jPanel3.add(actorButton, null);
263     jPanel3.add(descriptionButton, null);
264     this.add(jPanel6, BorderLayout.NORTH);
265     jPanel6.add(jPanel7, BorderLayout.NORTH);
266     jPanel7.add(serviceLabel, BorderLayout.CENTER);
267     jPanel6.add(jPanel1, BorderLayout.CENTER);
268     //jSplitPane1.setDividerLocation(100);
269   }
270 
271   // Is called when the user clicks the 'show actor' button.
272   void actorButton_actionPerformed(ActionEvent e) {
273     Vector contacts = service.getProfileByID(getSelectedProfile()).getContactInformation();
274     if (contacts==null) {
275       JOptionPane.showMessageDialog(mainFrame,"This profile includes no contact information.",
276                                     "No Contacts", JOptionPane.INFORMATION_MESSAGE);
277       return;
278     }
279     ShowActorDialog actDiag = new ShowActorDialog(mainFrame,"Contact Information",true,contacts);
280     actDiag.setSize(500,300);
281     Dimension dlgSize = actDiag.getPreferredSize();
282     Dimension frmSize = mainFrame.getSize();
283     Point loc = mainFrame.getLocation();
284     actDiag.setLocation((frmSize.width - 500) / 2 + loc.x,
285                                    (frmSize.height - 300) / 2 + loc.y);
286     actDiag.show();
287   }
288 
289   // Is called when the user clicks the 'show text description' button.
290   void descriptionButton_actionPerformed(ActionEvent e) {
291     ShowTextDescriptionDialog textDiag = new ShowTextDescriptionDialog(mainFrame,"Text Description",
292         true,service.getProfileByID(getSelectedProfile()).getTextDescription());
293     textDiag.setSize(300,300);
294     Dimension dlgSize = textDiag.getSize();
295     Dimension frmSize = mainFrame.getSize();
296     Point loc = mainFrame.getLocation();
297     textDiag.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
298                                    (frmSize.height - dlgSize.height) / 2 + loc.y);
299     textDiag.show();
300   }
301 
302   // Is called when the mouse enters the 'description' button.
303   void descriptionButton_mouseEntered(MouseEvent e) {
304     descriptionButton.setBorderPainted(true);
305   }
306 
307   // Is called when the mouse exits the 'description' button.
308   void descriptionButton_mouseExited(MouseEvent e) {
309     descriptionButton.setBorderPainted(false);
310   }
311 
312   // Is called when the mouse enters the 'actor' button.
313   void actorButton_mouseEntered(MouseEvent e) {
314     actorButton.setBorderPainted(true);
315   }
316 
317   // Is called when the mouse exits the 'actor' button.
318   void actorButton_mouseExited(MouseEvent e) {
319     actorButton.setBorderPainted(false);
320   }
321 
322   // is called when the user selects a different profile.
323   void profileComboBox_itemStateChanged(ItemEvent e) {
324     String ID = profileComboBox.getSelectedItem().toString();
325     if (service!=null) {
326       if (service.getProfileIDs()!=null) {
327         Profile prof = service.getProfileByID(ID);
328         changeProfile(prof);
329       }
330     }
331   }
332 }
333 
334 // -----------------------------------------
335 // ------- AUTO GENERATED CLASSES ----------
336 // -----------------------------------------
337 class ShowServicePanel_actorButton_actionAdapter implements java.awt.event.ActionListener {
338   ShowServicePanel adaptee;
339   ShowServicePanel_actorButton_actionAdapter(ShowServicePanel adaptee) {
340     this.adaptee = adaptee;
341   }
342   public void actionPerformed(ActionEvent e) {
343     adaptee.actorButton_actionPerformed(e);
344   }
345 }
346 class ShowServicePanel_descriptionButton_actionAdapter implements java.awt.event.ActionListener {
347   ShowServicePanel adaptee;
348   ShowServicePanel_descriptionButton_actionAdapter(ShowServicePanel adaptee) {
349     this.adaptee = adaptee;
350   }
351   public void actionPerformed(ActionEvent e) {
352     adaptee.descriptionButton_actionPerformed(e);
353   }
354 }
355 class ShowServicePanel_descriptionButton_mouseAdapter extends java.awt.event.MouseAdapter {
356   ShowServicePanel adaptee;
357   ShowServicePanel_descriptionButton_mouseAdapter(ShowServicePanel adaptee) {
358     this.adaptee = adaptee;
359   }
360   public void mouseEntered(MouseEvent e) {
361     adaptee.descriptionButton_mouseEntered(e);
362   }
363   public void mouseExited(MouseEvent e) {
364     adaptee.descriptionButton_mouseExited(e);
365   }
366 }
367 class ShowServicePanel_actorButton_mouseAdapter extends java.awt.event.MouseAdapter {
368   ShowServicePanel adaptee;
369   ShowServicePanel_actorButton_mouseAdapter(ShowServicePanel adaptee) {
370     this.adaptee = adaptee;
371   }
372   public void mouseEntered(MouseEvent e) {
373     adaptee.actorButton_mouseEntered(e);
374   }
375   public void mouseExited(MouseEvent e) {
376     adaptee.actorButton_mouseExited(e);
377   }
378 }
379 
380 class ShowServicePanel_profileComboBox_itemAdapter implements java.awt.event.ItemListener {
381   ShowServicePanel adaptee;
382 
383   ShowServicePanel_profileComboBox_itemAdapter(ShowServicePanel adaptee) {
384     this.adaptee = adaptee;
385   }
386   public void itemStateChanged(ItemEvent e) {
387     adaptee.profileComboBox_itemStateChanged(e);
388   }
389 }