KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > engine > sampleclient > gui > Console


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: Console.java 16:40:52 dutoo $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.engine.sampleclient.gui;
23
24 import java.awt.BorderLayout JavaDoc;
25 import java.awt.Color JavaDoc;
26 import java.awt.Dimension JavaDoc;
27 import java.awt.GridBagConstraints JavaDoc;
28 import java.awt.GridBagLayout JavaDoc;
29 import java.awt.GridLayout JavaDoc;
30 import java.awt.Point JavaDoc;
31 import java.awt.Rectangle JavaDoc;
32 import java.awt.event.ActionEvent JavaDoc;
33 import java.awt.event.ActionListener JavaDoc;
34 import java.awt.event.ComponentEvent JavaDoc;
35 import java.awt.event.MouseAdapter JavaDoc;
36 import java.io.DataInputStream JavaDoc;
37 import java.io.File JavaDoc;
38 import java.io.FileInputStream JavaDoc;
39 import java.io.InputStream JavaDoc;
40 import java.util.ArrayList JavaDoc;
41 import java.util.Enumeration JavaDoc;
42 import java.util.List JavaDoc;
43
44 import javax.jbi.servicedesc.ServiceEndpoint;
45 import javax.swing.AbstractButton JavaDoc;
46 import javax.swing.BorderFactory JavaDoc;
47 import javax.swing.ButtonGroup JavaDoc;
48 import javax.swing.DefaultComboBoxModel JavaDoc;
49 import javax.swing.DefaultListModel JavaDoc;
50 import javax.swing.ImageIcon JavaDoc;
51 import javax.swing.JButton JavaDoc;
52 import javax.swing.JFileChooser JavaDoc;
53 import javax.swing.JFrame JavaDoc;
54 import javax.swing.JLabel JavaDoc;
55 import javax.swing.JList JavaDoc;
56 import javax.swing.JOptionPane JavaDoc;
57 import javax.swing.JPanel JavaDoc;
58 import javax.swing.JRadioButton JavaDoc;
59 import javax.swing.JScrollPane JavaDoc;
60 import javax.swing.JSeparator JavaDoc;
61 import javax.swing.JTabbedPane JavaDoc;
62 import javax.swing.JTextArea JavaDoc;
63 import javax.swing.JTextField JavaDoc;
64 import javax.swing.ListModel JavaDoc;
65 import javax.swing.ListSelectionModel JavaDoc;
66 import javax.swing.WindowConstants JavaDoc;
67 import javax.swing.border.TitledBorder JavaDoc;
68
69 import org.objectweb.petals.engine.sampleclient.SampleClient;
70 import org.objectweb.petals.engine.sampleclient.gui.model.ServiceListRenderer;
71
72 /**
73  * Console of the SampleClient
74  *
75  * @author alouis, ddesjardins - eBMWebsourcing
76  * @author Marc Dutoo - Open Wide
77  */

78 public class Console extends javax.swing.JFrame JavaDoc {
79     /**
80      *
81      */

82     private static final long serialVersionUID = -8117896325113377153L;
83
84     public static void main(String JavaDoc[] args) {
85         Console inst = new Console();
86         inst.setVisible(true);
87         inst.setResponse("test");
88     }
89
90     private JButton JavaDoc asreference;
91
92     private JPanel JavaDoc servicesQueryPanel;
93
94     private JTextArea JavaDoc in;
95
96     private JRadioButton JavaDoc inout;
97
98     private JRadioButton JavaDoc inoutopt;
99
100     private JButton JavaDoc jButton1;
101
102     private JButton JavaDoc jButton2;
103
104     private JButton JavaDoc jButton3;
105
106     private JButton JavaDoc jButtonAddAttachments;
107     
108     private JFileChooser JavaDoc jFileChooserAttachment;
109
110     private JButton JavaDoc jButtonRemoveAttachments;
111
112     private JLabel JavaDoc jLabel1;
113
114     private JLabel JavaDoc jLabel2;
115
116     private JLabel JavaDoc jLabel3;
117
118     private JLabel JavaDoc jLabel4;
119
120     private JLabel JavaDoc jLabel8;
121
122     private JLabel JavaDoc jLabel81;
123     
124     private DefaultListModel JavaDoc jListModelSelectedAttachments;
125     
126     private JList JavaDoc jListSelectedAttachments;
127
128     private JList JavaDoc jList1;
129
130     private JPanel JavaDoc jPanel1;
131
132     private JPanel JavaDoc jPanel2;
133
134     private JPanel JavaDoc jPanel3;
135
136     private JPanel JavaDoc jPanel4;
137
138     private JPanel JavaDoc jPanelAttachment;
139
140     private JPanel JavaDoc botQueryPanel;
141
142     private JPanel JavaDoc topQueryPanel;
143
144     private JRadioButton JavaDoc jRadioButton1;
145
146     private JScrollPane JavaDoc jScrollPane1;
147
148     private JScrollPane JavaDoc jScrollPane2;
149
150     private JScrollPane JavaDoc servicesScrollPanel;
151
152     private JSeparator JavaDoc jSeparator1;
153
154     private JSeparator JavaDoc jSeparator11;
155
156     private JTabbedPane JavaDoc jTabbedPane1; // @jve:decl-index=0:visual-constraint="10,842"
157

158     private JTextArea JavaDoc jTextArea1;
159
160     private JTextField JavaDoc operation;
161
162     private JTextArea JavaDoc out;
163
164     private JPanel JavaDoc queryPanel;
165
166     private JButton JavaDoc resolve;
167
168     private JRadioButton JavaDoc robustin;
169
170     private SampleClient sampleClient;
171
172     private JPanel JavaDoc sendPanel;
173
174     private JButton JavaDoc sendSync;
175
176     private JTextField JavaDoc service;
177
178     private JTextField JavaDoc timeout;
179
180     private ButtonGroup JavaDoc typeGroup;
181
182     private JButton JavaDoc jButton31;
183
184     private JLabel JavaDoc background1;
185
186     private JLabel JavaDoc background;
187
188     public Console() {
189         super();
190         initialize();
191         initGUI();
192     }
193
194     public Console(SampleClient sampleClient) {
195         this();
196         this.sampleClient = sampleClient;
197     }
198
199     private void getAsReference() {
200         ServiceEndpoint se = (ServiceEndpoint) services[jList1
201             .getSelectedIndex()];
202
203         String JavaDoc msg = sampleClient.getAsReference(se);
204         openDialogBox("Reference of " + se, msg);
205
206     }
207
208     /**
209      * This method initializes jSeparator11
210      *
211      * @return javax.swing.JSeparator
212      */

213     private JSeparator JavaDoc getJSeparator11() {
214         if (jSeparator11 == null) {
215             jSeparator11 = new JSeparator JavaDoc();
216             jSeparator11.setBounds(new Rectangle JavaDoc(10, 170, 571, 11));
217         }
218         return jSeparator11;
219     }
220
221     private void getServices() {
222         ServiceEndpoint[] se = sampleClient.getEndpoints();
223         this.services = se;
224         // String[] se = new String[] {"test"};
225
DefaultListModel JavaDoc listModel = new DefaultListModel JavaDoc();
226         jList1
227             .setCellRenderer(new ServiceListRenderer(jList1.getCellRenderer()));
228         for (int i = 0; i < se.length; i++) {
229             String JavaDoc name = se[i].toString();
230             JLabel JavaDoc label = new JLabel JavaDoc();
231             label.setText(name);
232             label.setToolTipText("Click to select in the Send Panel");
233             label.addMouseListener(new ServiceSelector(name));
234             listModel.addElement(label);
235         }
236         jList1.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
237             public void mouseClicked(java.awt.event.MouseEvent JavaDoc e) {
238                 if (e.getClickCount() == 2) {
239                     if (jList1.getSelectedValue() != null) {
240                         JLabel JavaDoc label = (JLabel JavaDoc) jList1.getSelectedValue();
241                         String JavaDoc name = label.getText();
242                         if (name.indexOf(" ") > -1) {
243                             name = name.substring(0, name.indexOf(" "));
244                         }
245                         service.setText(name);
246                         jTabbedPane1.setSelectedIndex(0);
247                     }
248                 }
249             }
250         });
251         jList1.setModel(listModel);
252         if (se.length > 0) {
253             jList1.setSelectedIndex(0);
254         }
255     }
256
257     private class ServiceSelector extends MouseAdapter JavaDoc {
258         private String JavaDoc name;
259
260         public ServiceSelector(String JavaDoc name) {
261             this.name = name;
262         }
263
264         public void mousePressed(java.awt.event.MouseEvent JavaDoc e) {
265             service.setText(name);
266             jTabbedPane1.setSelectedIndex(0);
267         }
268
269         public void mouseClicked(java.awt.event.MouseEvent JavaDoc e) {
270             service.setText(name);
271             jTabbedPane1.setSelectedIndex(0);
272         }
273     }
274
275     private void initGUI() {
276         try {
277             GridLayout JavaDoc gridLayout1 = new GridLayout JavaDoc();
278             gridLayout1.setRows(2);
279             GridLayout JavaDoc gridLayout = new GridLayout JavaDoc();
280             gridLayout.setRows(2);
281             setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
282             {
283                 jTabbedPane1 = new JTabbedPane JavaDoc();
284                 getContentPane().add(jTabbedPane1);
285                 jTabbedPane1.setSize(592, 652);
286                 jTabbedPane1.setBackground(new Color JavaDoc(242, 237, 243));
287                 {
288                     sendPanel = new JPanel JavaDoc();
289
290                     byte[] buffer = null;
291                     InputStream JavaDoc inStream = this.getClass().getResourceAsStream(
292                         "/ebmlogo.jpg");
293                     try {
294                         if (inStream == null) {
295                             inStream = new FileInputStream JavaDoc("src"
296                                 + File.separator + "img" + File.separator
297                                 + "ebmlogo.jpg");
298                         }
299                         DataInputStream JavaDoc dis = new DataInputStream JavaDoc(inStream);
300                         buffer = new byte[dis.available()];
301                         dis.readFully(buffer);
302                         ImageIcon JavaDoc img1 = new ImageIcon JavaDoc(buffer);
303                         background = new JLabel JavaDoc(img1);
304                         background.setBounds(360, 540, img1.getIconWidth(),
305                             img1.getIconHeight());
306                         sendPanel.add(background);
307                     } catch (Exception JavaDoc e) {
308                         JOptionPane.showMessageDialog(this, e.getMessage(),
309                             "Error", JOptionPane.ERROR_MESSAGE);
310                     }
311
312                     sendPanel.setLayout(null);
313                     jTabbedPane1.addTab("Send", null, sendPanel, null);
314                     sendPanel.setOpaque(false);
315                     sendPanel.setForeground(new Color JavaDoc(243, 238, 243));
316                     sendPanel.setBackground(new Color JavaDoc(242, 237, 243));
317
318                     {
319                         {
320                             typeGroup = new ButtonGroup JavaDoc();
321                         }
322                         jPanel1 = new JPanel JavaDoc();
323                         jPanel1.setBackground(new Color JavaDoc(242, 237, 243));
324                         jPanel1.setLayout(gridLayout);
325                         jPanel1.setBounds(new Rectangle JavaDoc(0, 0, 586, 80));
326                         jPanel1.setBorder(BorderFactory
327                             .createTitledBorder("Service"));
328                         jPanel1.setOpaque(false);
329                         {
330                             jLabel1 = new JLabel JavaDoc();
331                             jLabel1.setText("Service");
332                         }
333                         {
334                             service = new JTextField JavaDoc();
335                             service.setText("{http://petals.objectweb.org/}HelloworldService");
336                         }
337                         {
338                             jLabel2 = new JLabel JavaDoc();
339                             jLabel2.setText("Operation");
340                         }
341                         {
342                             operation = new JTextField JavaDoc();
343                             jPanel1.add(jLabel1, null);
344                             jPanel1.add(service, null);
345                             jPanel1.add(jLabel2, null);
346                             jPanel1.add(operation, null);
347                             operation.setText("printMessage");
348                         }
349                     }
350
351                     {
352                         // creating attachments panel
353
jPanelAttachment = new JPanel JavaDoc(new BorderLayout JavaDoc());
354                         jPanelAttachment.setBackground(new Color JavaDoc(242, 237, 243));
355                         jPanelAttachment.setLocation(new Point JavaDoc(0, 80));
356                         jPanelAttachment.setSize(586, 100);
357                         jPanelAttachment.setBorder(BorderFactory.createTitledBorder("Attachments"));
358                         jPanelAttachment.setOpaque(false);
359                         {
360                             jListSelectedAttachments = new JList JavaDoc();
361                             jListSelectedAttachments.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
362                             jListModelSelectedAttachments = new DefaultListModel JavaDoc();
363                             jListSelectedAttachments.setModel(jListModelSelectedAttachments);
364                         }
365                         {
366                             // creating add attachment button
367
jButtonAddAttachments = new JButton JavaDoc();
368                             jButtonAddAttachments.setText("Add attachments");
369                             jButtonAddAttachments.setBounds(new Rectangle JavaDoc(5, 20, 196, 26));
370                             jButtonAddAttachments.setPreferredSize(new java.awt.Dimension JavaDoc(130, 18));
371                             jFileChooserAttachment = new JFileChooser JavaDoc();
372                             jFileChooserAttachment.setMultiSelectionEnabled(true);
373                             jButtonAddAttachments.addActionListener(new ActionListener JavaDoc() {
374                                 public void actionPerformed(ActionEvent JavaDoc e) {
375                                     int res = jFileChooserAttachment.showOpenDialog(Console.this);
376                                     if (res == JFileChooser.APPROVE_OPTION) {
377                                         for (File JavaDoc attachmentFile : jFileChooserAttachment.getSelectedFiles()) {
378                                             jListModelSelectedAttachments.addElement(attachmentFile);
379                                         }
380                                     }
381                                 }
382                             });
383                         }
384                         {
385                             // creating remove attachment button
386
jButtonRemoveAttachments = new JButton JavaDoc();
387                             jButtonRemoveAttachments.setText("Remove selected");
388                             jButtonRemoveAttachments.setBounds(new Rectangle JavaDoc(5, 20, 196, 26));
389                             jButtonRemoveAttachments.setPreferredSize(new java.awt.Dimension JavaDoc(130, 18));
390                             jButtonRemoveAttachments.addActionListener(new ActionListener JavaDoc() {
391                                 public void actionPerformed(ActionEvent JavaDoc e) {
392                                     for (Object JavaDoc attachment : jListSelectedAttachments.getSelectedValues()) {
393                                         jListModelSelectedAttachments.removeElement(attachment);
394                                     }
395                                 }
396                             });
397                         }
398                         {
399                             JPanel JavaDoc jPanelAttachmentButtons = new JPanel JavaDoc(new GridLayout JavaDoc(1, 2));
400                             jPanelAttachmentButtons.add(jButtonAddAttachments, null);
401                             jPanelAttachmentButtons.add(jButtonRemoveAttachments, null);
402                             jPanelAttachment.add(new JScrollPane JavaDoc(jListSelectedAttachments), BorderLayout.CENTER);
403                             jPanelAttachment.add(jPanelAttachmentButtons, BorderLayout.SOUTH);
404                         }
405                     }
406                     {
407                         typeGroup = new ButtonGroup JavaDoc();
408                     }
409                     {
410                         jPanel3 = new JPanel JavaDoc();
411                         jPanel3.setBackground(new Color JavaDoc(242, 237, 243));
412                         jPanel3.setLayout(gridLayout1);
413                         jPanel3.setLocation(new Point JavaDoc(0, 180));
414                         jPanel3.setSize(586, 80);
415                         jPanel3.setBorder(BorderFactory
416                             .createTitledBorder("Message exchange pattern"));
417                         jPanel3.setOpaque(false);
418                         {
419                             jRadioButton1 = new JRadioButton JavaDoc();
420                             jRadioButton1.setText("InOnly");
421                             jRadioButton1.setAutoscrolls(true);
422                             typeGroup.add(jRadioButton1);
423                             jRadioButton1.setSelected(true);
424                             jRadioButton1.setOpaque(false);
425                         }
426                         {
427                             inout = new JRadioButton JavaDoc();
428                             inout.setText("InOut");
429                             typeGroup.add(inout);
430                             inout.setOpaque(false);
431                         }
432                         {
433                             inoutopt = new JRadioButton JavaDoc();
434                             jPanel3.add(jRadioButton1, null);
435                             inoutopt.setText("InOptionalOut");
436                             typeGroup.add(inoutopt);
437                             inoutopt.setOpaque(false);
438                         }
439                         {
440                             robustin = new JRadioButton JavaDoc();
441                             jPanel3.add(inout, null);
442                             jPanel3.add(inoutopt, null);
443                             jPanel3.add(robustin, null);
444                             robustin.setText("RobustInOnly");
445                             robustin.setOpaque(false);
446                             typeGroup.add(robustin);
447                         }
448                     }
449                     {
450                         jPanel2 = new JPanel JavaDoc();
451                         jPanel2.setLayout(null);
452                         jPanel2.setSize(586, 344);
453                         jPanel2.setLocation(new Point JavaDoc(0, 260));
454                         jPanel2
455                             .setPreferredSize(new java.awt.Dimension JavaDoc(10, 10));
456                         jPanel2.setBorder(BorderFactory.createTitledBorder(
457                             null, "Request / Response body",
458                             TitledBorder.LEADING, TitledBorder.TOP));
459                         jPanel2.setOpaque(false);
460                         {
461                             jLabel3 = new JLabel JavaDoc();
462                             jLabel3.setText("In");
463                             jLabel3.setBounds(new Rectangle JavaDoc(5, 20, 576, 20));
464                         }
465                         {
466                             jScrollPane1 = new JScrollPane JavaDoc();
467                             jScrollPane1
468                                 .setBounds(new Rectangle JavaDoc(5, 45, 576, 90));
469                             jPanel2.add(jLabel3, null);
470                             {
471                                 in = new JTextArea JavaDoc(3, 40);
472                                 jScrollPane1.setViewportView(in);
473                                 in.setLineWrap(true);
474                                 in.setWrapStyleWord(true);
475                                 in.setPreferredSize(new Dimension JavaDoc(573, 64));
476                                 in.setText("<text>hi !</text>");
477                             }
478                         }
479                         {
480                             jLabel4 = new JLabel JavaDoc();
481                             jPanel2.add(jScrollPane1, null);
482                             jLabel4.setText("Out");
483                             jLabel4.setBounds(new Rectangle JavaDoc(5, 140, 576, 20));
484                         }
485                         {
486                             jScrollPane2 = new JScrollPane JavaDoc();
487                             jScrollPane2.setBounds(new Rectangle JavaDoc(5, 165, 576,
488                                 90));
489                             jPanel2.add(jLabel4, null);
490                             jPanel2.add(jScrollPane2, null);
491                             {
492                                 out = new JTextArea JavaDoc(3, 40);
493                                 out.setLineWrap(true);
494                                 out.setWrapStyleWord(true);
495                                 jScrollPane2.setViewportView(out);
496                             }
497                         }
498                     }
499                     {
500                         jPanel4 = new JPanel JavaDoc();
501                         jPanel2.add(jPanel4, null);
502                         sendPanel.add(jPanel1);
503                         sendPanel.add(jPanelAttachment); // adding the attachments UI
504
sendPanel.add(jPanel3, null);
505                         sendPanel.add(jPanel2, null);
506                         jPanel4.setLayout(null);
507                         jPanel4.setOpaque(false);
508                         jPanel4.setBounds(new Rectangle JavaDoc(2, 259, 586, 99));
509                         jPanel4.setBorder(BorderFactory
510                             .createTitledBorder("Send"));
511                         {
512                             sendSync = new JButton JavaDoc();
513                             sendSync.setText("SendSync");
514                             sendSync.setBounds(new Rectangle JavaDoc(5, 20, 196, 26));
515                             sendSync.setPreferredSize(new java.awt.Dimension JavaDoc(
516                                 130, 18));
517                             sendSync.addActionListener(new ActionListener JavaDoc() {
518                                 public void actionPerformed(ActionEvent JavaDoc evt) {
519                                     sendSync();
520                                 }
521                             });
522                         }
523                         {
524                             timeout = new JTextField JavaDoc();
525                             timeout.setText("0");
526                             timeout.setToolTipText("timeout, in ms");
527                             timeout.setBounds(new Rectangle JavaDoc(209, 23, 42, 23));
528                         }
529                         {
530                             jButton1 = new JButton JavaDoc();
531                             jPanel4.add(sendSync, null);
532                             jPanel4.add(timeout, null);
533                             jPanel4.add(jButton1, null);
534                             jButton1.setText("Send - Accept (block)");
535                             jButton1.setBounds(new Rectangle JavaDoc(5, 55, 196, 27));
536                             jButton1.setPreferredSize(new java.awt.Dimension JavaDoc(
537                                 152, 15));
538                             jButton1.addActionListener(new ActionListener JavaDoc() {
539                                 public void actionPerformed(ActionEvent JavaDoc evt) {
540                                     send();
541                                 }
542                             });
543                         }
544                     }
545                 }
546                 {
547                     queryPanel = new JPanel JavaDoc();
548                     queryPanel.setOpaque(false);
549                     jTabbedPane1.addTab("Query", null, queryPanel, null);
550                     {
551
552                         byte[] buffer = null;
553                         InputStream JavaDoc inStream = this.getClass()
554                             .getResourceAsStream("/ebmlogo.jpg");
555                         try {
556                             if (inStream == null) {
557                                 inStream = new FileInputStream JavaDoc("src"
558                                     + File.separator + "img" + File.separator
559                                     + "ebmlogo.jpg");
560                             }
561                             DataInputStream JavaDoc dis = new DataInputStream JavaDoc(inStream);
562                             buffer = new byte[dis.available()];
563                             dis.readFully(buffer);
564                             ImageIcon JavaDoc img1 = new ImageIcon JavaDoc(buffer);
565                             background1 = new JLabel JavaDoc(img1);
566                             // background1.setBounds(360, 300,
567
// img1.getIconWidth(), img1.getIconHeight());
568

569                         } catch (Exception JavaDoc e) {
570                             JOptionPane.showMessageDialog(this, e.getMessage(),
571                                 "Error", JOptionPane.ERROR_MESSAGE);
572                         }
573
574                         {
575                             topQueryPanel = new JPanel JavaDoc();
576                             topQueryPanel.setLayout(null);
577                             topQueryPanel.setOpaque(false);
578                             // jPanel7.setBounds(new Rectangle(0, 0, 586, 271));
579
{
580                                 jLabel8 = new JLabel JavaDoc();
581                                 jLabel8
582                                     .setText("Query the server to find endpoints");
583                                 jLabel8.setBounds(new Rectangle JavaDoc(5, 0, 241, 23));
584                                 jLabel8.setFont(new java.awt.Font JavaDoc("Tahoma", 0,
585                                     14));
586
587                                 jLabel81 = new JLabel JavaDoc();
588                                 jLabel81.setText("Result : List of endpoints");
589                                 jLabel81.setBounds(new Rectangle JavaDoc(5, 180, 241,
590                                     26));
591                                 jLabel81.setFont(new java.awt.Font JavaDoc("Tahoma", 0,
592                                     14));
593                             }
594                             {
595                                 jButton2 = new JButton JavaDoc();
596                                 jButton2.setText("Find all the endpoints");
597                                 jButton2
598                                     .setBounds(new Rectangle JavaDoc(5, 30, 181, 25));
599                                 jButton2
600                                     .setPreferredSize(new java.awt.Dimension JavaDoc(
601                                         123, 23));
602                                 jButton2
603                                     .addActionListener(new ActionListener JavaDoc() {
604                                         public void actionPerformed(
605                                             ActionEvent JavaDoc evt) {
606                                             getServices();
607                                         }
608                                     });
609                             }
610                             {
611                                 jSeparator1 = new JSeparator JavaDoc();
612                                 jSeparator1.setBounds(new Rectangle JavaDoc(5, 60, 253,
613                                     8));
614                             }
615                             {
616                                 resolve = new JButton JavaDoc();
617                                 resolve
618                                     .setText("Resolve following description");
619                                 resolve
620                                     .setActionCommand("Resolve following description");
621                                 resolve
622                                     .setBounds(new Rectangle JavaDoc(5, 65, 241, 25));
623                                 resolve.addActionListener(new ActionListener JavaDoc() {
624                                     public void actionPerformed(ActionEvent JavaDoc evt) {
625                                         resolveDescription();
626                                     }
627                                 });
628                             }
629                             {
630                                 jTextArea1 = new JTextArea JavaDoc(6, 20);
631                                 topQueryPanel.add(jLabel8, null);
632                                 topQueryPanel.add(jButton2, null);
633                                 topQueryPanel.add(jSeparator1, null);
634                                 topQueryPanel.add(resolve, null);
635                                 topQueryPanel.add(jTextArea1, null);
636                                 jTextArea1
637                                     .setText("< enter a w3c document fragment>");
638                                 jTextArea1.setLineWrap(true);
639                                 jTextArea1.setWrapStyleWord(true);
640                                 jTextArea1.setBounds(new Rectangle JavaDoc(5, 95, 576,
641                                     71));
642                             }
643                         }
644
645                         topQueryPanel.add(getJSeparator11(), null);
646                         topQueryPanel.add(jLabel81, null);
647                         ListModel JavaDoc jList1Model = new DefaultComboBoxModel JavaDoc(
648                             new String JavaDoc[0]);
649                         jList1 = new JList JavaDoc();
650
651                         servicesScrollPanel = new JScrollPane JavaDoc();
652                         servicesScrollPanel.setViewportView(jList1);
653                         jList1.setModel(jList1Model);
654
655                     }
656                     {
657                         botQueryPanel = new JPanel JavaDoc();
658                         botQueryPanel.setLayout(null);
659                         botQueryPanel
660                             .setBorder(BorderFactory
661                                 .createTitledBorder("Action on the selected endpoint"));
662                         botQueryPanel.setOpaque(false);
663                         {
664                             jButton3 = new JButton JavaDoc();
665                             jButton3.setText("Get service description");
666                             jButton3.setBounds(new Rectangle JavaDoc(5, 20, 251, 25));
667                             jButton3.setPreferredSize(new java.awt.Dimension JavaDoc(
668                                 145, 26));
669                             jButton3.addActionListener(new ActionListener JavaDoc() {
670                                 public void actionPerformed(ActionEvent JavaDoc evt) {
671                                     showDescription();
672                                 }
673                             });
674                             jButton31 = new JButton JavaDoc();
675                             jButton31
676                                 .setBounds(new Rectangle JavaDoc(265, 20, 231, 25));
677                             jButton31.setText("Get interfaces");
678                             jButton31.setPreferredSize(new Dimension JavaDoc(145, 26));
679                             jButton31.addActionListener(new ActionListener JavaDoc() {
680                                 public void actionPerformed(ActionEvent JavaDoc evt) {
681                                     showInterfaces();
682                                 }
683                             });
684                         }
685                         {
686                             asreference = new JButton JavaDoc();
687                             botQueryPanel.add(jButton3, null);
688                             botQueryPanel.add(asreference, null);
689                             botQueryPanel.add(jButton31, null);
690                             asreference
691                                 .setText("Get selected endpoint as reference");
692                             asreference
693                                 .setBounds(new Rectangle JavaDoc(5, 55, 251, 25));
694                             asreference.addActionListener(new ActionListener JavaDoc() {
695                                 public void actionPerformed(ActionEvent JavaDoc evt) {
696                                     topQueryPanel.add(jLabel81, null);
697                                     getAsReference();
698                                 }
699                             });
700
701                             if (background1 != null) {
702                                 background1.setBounds(new Rectangle JavaDoc(360, 63,
703                                     background.getWidth(), background
704                                         .getHeight()));
705                                 botQueryPanel.add(background1, null);
706                             }
707                         }
708                     }
709
710                     servicesQueryPanel = new JPanel JavaDoc(new BorderLayout JavaDoc());
711                     servicesQueryPanel.add(servicesScrollPanel,
712                         BorderLayout.CENTER);
713
714                     // botQueryPanel.setBorder(new LineBorder(Color.BLACK, 2));
715
// test.setBorder(new LineBorder(Color.BLACK, 2));
716
// topQueryPanel.setBorder(new LineBorder(Color.BLACK, 2));
717

718                     queryPanel.setLayout(new GridBagLayout JavaDoc());
719
720                     GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
721
722                     c.fill = GridBagConstraints.BOTH;
723                     c.gridx = 0;
724                     c.gridy = 0;
725                     c.gridwidth = 3;
726                     c.ipady = 207;
727                     c.weighty = 0.0;
728                     c.weightx = 0.0;
729                     queryPanel.add(topQueryPanel, c);
730
731                     c.fill = GridBagConstraints.BOTH;
732                     c.gridx = 0;
733                     c.gridy = 1;
734                     c.gridwidth = 3;
735                     c.ipady = 0;
736                     c.ipadx = 0;
737                     c.weighty = 1.0;
738                     c.weightx = 1.0;
739                     queryPanel.add(servicesQueryPanel, c);
740
741                     c.fill = GridBagConstraints.BOTH;
742                     c.gridx = 0;
743                     c.gridy = 3;
744                     c.ipady = 130;
745                     c.ipadx = 500;
746                     c.gridwidth = 3;
747                     c.weighty = 0.0;
748                     c.weightx = 0.0;
749                     queryPanel.add(botQueryPanel, c);
750                 }
751             }
752
753             pack();
754             this.setBackground(new Color JavaDoc(242, 237, 243));
755         } catch (Exception JavaDoc e) {
756             e.printStackTrace();
757         }
758     }
759
760     /**
761      * This method initializes this
762      *
763      */

764     private void initialize() {
765         this.setLayout(new BorderLayout JavaDoc());
766         this.setTitle("Petals - Sample client");
767         this.setBackground(new Color JavaDoc(242, 237, 243));
768         this.setResizable(true);
769         this.setSize(600, 699);
770         lockInMinSize(this);
771     }
772
773     private static void lockInMinSize(final JFrame JavaDoc frame) {
774         // Ensures user cannot resize frame to be smaller than frame is right
775
// now.
776
final int origX = frame.getSize().width;
777         final int origY = frame.getSize().height;
778         frame.addComponentListener(new java.awt.event.ComponentAdapter JavaDoc() {
779             public void componentResized(ComponentEvent JavaDoc event) {
780                 int X = (frame.getWidth() < origX) ? origX : frame.getWidth();
781                 int Y = (frame.getHeight() < origY) ? origY : frame.getHeight();
782                 frame.setSize(X, Y);
783             }
784         });
785     }
786
787     /**
788      * open a new JFrame with a textArea
789      *
790      * @param title
791      * @param textMsg
792      */

793     private void openDialogBox(String JavaDoc title, String JavaDoc textMsg) {
794         JFrame JavaDoc f = new JFrame JavaDoc(title);
795         JTextArea JavaDoc text = new JTextArea JavaDoc(textMsg);
796         text.setLineWrap(true);
797         text.setWrapStyleWord(true);
798         JScrollPane JavaDoc sp = new JScrollPane JavaDoc(text);
799         f.getRootPane().getContentPane().add(sp);
800         f.pack();
801         f.setSize(300, 300);
802         f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
803         f.setVisible(true);
804     }
805
806     private void resolveDescription() {
807         String JavaDoc fragmentDescription = jTextArea1.getText();
808
809         ServiceEndpoint se = sampleClient
810             .resolveDescription(fragmentDescription);
811         DefaultListModel JavaDoc listModel = new DefaultListModel JavaDoc();
812         listModel.addElement(se);
813         jList1.setModel(listModel);
814     }
815     
816     /**
817      * Retrieves the selected attachment files from the UI
818      * and returns them as a List
819      * @return
820      */

821     private List JavaDoc<File JavaDoc> getAttachmentFiles() {
822         ArrayList JavaDoc<File JavaDoc> attachmentFiles = new ArrayList JavaDoc<File JavaDoc>();
823         Enumeration JavaDoc<?> attachmentEnum = jListModelSelectedAttachments.elements();
824         while (attachmentEnum.hasMoreElements()) {
825             Object JavaDoc attachment = attachmentEnum.nextElement();
826             if (attachment instanceof File JavaDoc) {
827                 attachmentFiles.add((File JavaDoc) attachment);
828             } // else silent error
829
}
830         return attachmentFiles;
831     }
832
833     private void send() {
834         JRadioButton JavaDoc selected = null;
835         out.setText("");
836         Enumeration JavaDoc<AbstractButton JavaDoc> rbs = typeGroup.getElements();
837         while (rbs.hasMoreElements()) {
838             AbstractButton JavaDoc but = rbs.nextElement();
839             if (but.isSelected()) {
840                 selected = (JRadioButton JavaDoc) but;
841             }
842         }
843
844         sampleClient.send(service.getText(), operation.getText(), in.getText(),
845             selected.getText(), getAttachmentFiles(), -1);
846     }
847
848     private void sendSync() {
849         JRadioButton JavaDoc selected = null;
850         out.setText("");
851         Enumeration JavaDoc<AbstractButton JavaDoc> rbs = typeGroup.getElements();
852         while (rbs.hasMoreElements()) {
853             AbstractButton JavaDoc but = rbs.nextElement();
854             if (but.isSelected()) {
855                 selected = (JRadioButton JavaDoc) but;
856             }
857         }
858
859         sampleClient.send(service.getText(), operation.getText(), in.getText(),
860             selected.getText(), getAttachmentFiles(),
861             Long.parseLong(timeout.getText()));
862     }
863
864     public void setResponse(String JavaDoc text) {
865         // out.append(text + "\n");
866
out.setText(text);
867     }
868
869     private ServiceEndpoint[] services;
870
871     private void showDescription() {
872         ServiceEndpoint se = (ServiceEndpoint) services[jList1
873             .getSelectedIndex()];
874
875         String JavaDoc msg = sampleClient.getDescription(se);
876         openDialogBox("Description of " + se, msg);
877     }
878
879     private void showInterfaces() {
880         ServiceEndpoint se = (ServiceEndpoint) services[jList1
881             .getSelectedIndex()];
882
883         String JavaDoc msg = sampleClient.getInterfaces(se);
884         openDialogBox("Interfaces of " + se, msg);
885     }
886
887     public void showError(Throwable JavaDoc e) {
888         String JavaDoc error = "";
889         for (StackTraceElement JavaDoc iterable_element : e.getStackTrace()) {
890             error += iterable_element.toString() + "\n";
891         }
892         JOptionPane.showMessageDialog(this, error, "error",
893             JOptionPane.ERROR_MESSAGE);
894     }
895     public void showWarning(String JavaDoc msg) {
896         JOptionPane.showMessageDialog(this, msg, "warning",
897             JOptionPane.WARNING_MESSAGE);
898     }
899 } // @jve:decl-index=0:visual-constraint="10,10"
900
Popular Tags