1 22 package org.objectweb.petals.engine.sampleclient.gui; 23 24 import java.awt.BorderLayout ; 25 import java.awt.Color ; 26 import java.awt.Dimension ; 27 import java.awt.GridBagConstraints ; 28 import java.awt.GridBagLayout ; 29 import java.awt.GridLayout ; 30 import java.awt.Point ; 31 import java.awt.Rectangle ; 32 import java.awt.event.ActionEvent ; 33 import java.awt.event.ActionListener ; 34 import java.awt.event.ComponentEvent ; 35 import java.awt.event.MouseAdapter ; 36 import java.io.DataInputStream ; 37 import java.io.File ; 38 import java.io.FileInputStream ; 39 import java.io.InputStream ; 40 import java.util.ArrayList ; 41 import java.util.Enumeration ; 42 import java.util.List ; 43 44 import javax.jbi.servicedesc.ServiceEndpoint; 45 import javax.swing.AbstractButton ; 46 import javax.swing.BorderFactory ; 47 import javax.swing.ButtonGroup ; 48 import javax.swing.DefaultComboBoxModel ; 49 import javax.swing.DefaultListModel ; 50 import javax.swing.ImageIcon ; 51 import javax.swing.JButton ; 52 import javax.swing.JFileChooser ; 53 import javax.swing.JFrame ; 54 import javax.swing.JLabel ; 55 import javax.swing.JList ; 56 import javax.swing.JOptionPane ; 57 import javax.swing.JPanel ; 58 import javax.swing.JRadioButton ; 59 import javax.swing.JScrollPane ; 60 import javax.swing.JSeparator ; 61 import javax.swing.JTabbedPane ; 62 import javax.swing.JTextArea ; 63 import javax.swing.JTextField ; 64 import javax.swing.ListModel ; 65 import javax.swing.ListSelectionModel ; 66 import javax.swing.WindowConstants ; 67 import javax.swing.border.TitledBorder ; 68 69 import org.objectweb.petals.engine.sampleclient.SampleClient; 70 import org.objectweb.petals.engine.sampleclient.gui.model.ServiceListRenderer; 71 72 78 public class Console extends javax.swing.JFrame { 79 82 private static final long serialVersionUID = -8117896325113377153L; 83 84 public static void main(String [] args) { 85 Console inst = new Console(); 86 inst.setVisible(true); 87 inst.setResponse("test"); 88 } 89 90 private JButton asreference; 91 92 private JPanel servicesQueryPanel; 93 94 private JTextArea in; 95 96 private JRadioButton inout; 97 98 private JRadioButton inoutopt; 99 100 private JButton jButton1; 101 102 private JButton jButton2; 103 104 private JButton jButton3; 105 106 private JButton jButtonAddAttachments; 107 108 private JFileChooser jFileChooserAttachment; 109 110 private JButton jButtonRemoveAttachments; 111 112 private JLabel jLabel1; 113 114 private JLabel jLabel2; 115 116 private JLabel jLabel3; 117 118 private JLabel jLabel4; 119 120 private JLabel jLabel8; 121 122 private JLabel jLabel81; 123 124 private DefaultListModel jListModelSelectedAttachments; 125 126 private JList jListSelectedAttachments; 127 128 private JList jList1; 129 130 private JPanel jPanel1; 131 132 private JPanel jPanel2; 133 134 private JPanel jPanel3; 135 136 private JPanel jPanel4; 137 138 private JPanel jPanelAttachment; 139 140 private JPanel botQueryPanel; 141 142 private JPanel topQueryPanel; 143 144 private JRadioButton jRadioButton1; 145 146 private JScrollPane jScrollPane1; 147 148 private JScrollPane jScrollPane2; 149 150 private JScrollPane servicesScrollPanel; 151 152 private JSeparator jSeparator1; 153 154 private JSeparator jSeparator11; 155 156 private JTabbedPane jTabbedPane1; 158 private JTextArea jTextArea1; 159 160 private JTextField operation; 161 162 private JTextArea out; 163 164 private JPanel queryPanel; 165 166 private JButton resolve; 167 168 private JRadioButton robustin; 169 170 private SampleClient sampleClient; 171 172 private JPanel sendPanel; 173 174 private JButton sendSync; 175 176 private JTextField service; 177 178 private JTextField timeout; 179 180 private ButtonGroup typeGroup; 181 182 private JButton jButton31; 183 184 private JLabel background1; 185 186 private JLabel 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 msg = sampleClient.getAsReference(se); 204 openDialogBox("Reference of " + se, msg); 205 206 } 207 208 213 private JSeparator getJSeparator11() { 214 if (jSeparator11 == null) { 215 jSeparator11 = new JSeparator (); 216 jSeparator11.setBounds(new Rectangle (10, 170, 571, 11)); 217 } 218 return jSeparator11; 219 } 220 221 private void getServices() { 222 ServiceEndpoint[] se = sampleClient.getEndpoints(); 223 this.services = se; 224 DefaultListModel listModel = new DefaultListModel (); 226 jList1 227 .setCellRenderer(new ServiceListRenderer(jList1.getCellRenderer())); 228 for (int i = 0; i < se.length; i++) { 229 String name = se[i].toString(); 230 JLabel label = new JLabel (); 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 () { 237 public void mouseClicked(java.awt.event.MouseEvent e) { 238 if (e.getClickCount() == 2) { 239 if (jList1.getSelectedValue() != null) { 240 JLabel label = (JLabel ) jList1.getSelectedValue(); 241 String 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 { 258 private String name; 259 260 public ServiceSelector(String name) { 261 this.name = name; 262 } 263 264 public void mousePressed(java.awt.event.MouseEvent e) { 265 service.setText(name); 266 jTabbedPane1.setSelectedIndex(0); 267 } 268 269 public void mouseClicked(java.awt.event.MouseEvent e) { 270 service.setText(name); 271 jTabbedPane1.setSelectedIndex(0); 272 } 273 } 274 275 private void initGUI() { 276 try { 277 GridLayout gridLayout1 = new GridLayout (); 278 gridLayout1.setRows(2); 279 GridLayout gridLayout = new GridLayout (); 280 gridLayout.setRows(2); 281 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 282 { 283 jTabbedPane1 = new JTabbedPane (); 284 getContentPane().add(jTabbedPane1); 285 jTabbedPane1.setSize(592, 652); 286 jTabbedPane1.setBackground(new Color (242, 237, 243)); 287 { 288 sendPanel = new JPanel (); 289 290 byte[] buffer = null; 291 InputStream inStream = this.getClass().getResourceAsStream( 292 "/ebmlogo.jpg"); 293 try { 294 if (inStream == null) { 295 inStream = new FileInputStream ("src" 296 + File.separator + "img" + File.separator 297 + "ebmlogo.jpg"); 298 } 299 DataInputStream dis = new DataInputStream (inStream); 300 buffer = new byte[dis.available()]; 301 dis.readFully(buffer); 302 ImageIcon img1 = new ImageIcon (buffer); 303 background = new JLabel (img1); 304 background.setBounds(360, 540, img1.getIconWidth(), 305 img1.getIconHeight()); 306 sendPanel.add(background); 307 } catch (Exception 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 (243, 238, 243)); 316 sendPanel.setBackground(new Color (242, 237, 243)); 317 318 { 319 { 320 typeGroup = new ButtonGroup (); 321 } 322 jPanel1 = new JPanel (); 323 jPanel1.setBackground(new Color (242, 237, 243)); 324 jPanel1.setLayout(gridLayout); 325 jPanel1.setBounds(new Rectangle (0, 0, 586, 80)); 326 jPanel1.setBorder(BorderFactory 327 .createTitledBorder("Service")); 328 jPanel1.setOpaque(false); 329 { 330 jLabel1 = new JLabel (); 331 jLabel1.setText("Service"); 332 } 333 { 334 service = new JTextField (); 335 service.setText("{http://petals.objectweb.org/}HelloworldService"); 336 } 337 { 338 jLabel2 = new JLabel (); 339 jLabel2.setText("Operation"); 340 } 341 { 342 operation = new JTextField (); 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 jPanelAttachment = new JPanel (new BorderLayout ()); 354 jPanelAttachment.setBackground(new Color (242, 237, 243)); 355 jPanelAttachment.setLocation(new Point (0, 80)); 356 jPanelAttachment.setSize(586, 100); 357 jPanelAttachment.setBorder(BorderFactory.createTitledBorder("Attachments")); 358 jPanelAttachment.setOpaque(false); 359 { 360 jListSelectedAttachments = new JList (); 361 jListSelectedAttachments.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 362 jListModelSelectedAttachments = new DefaultListModel (); 363 jListSelectedAttachments.setModel(jListModelSelectedAttachments); 364 } 365 { 366 jButtonAddAttachments = new JButton (); 368 jButtonAddAttachments.setText("Add attachments"); 369 jButtonAddAttachments.setBounds(new Rectangle (5, 20, 196, 26)); 370 jButtonAddAttachments.setPreferredSize(new java.awt.Dimension (130, 18)); 371 jFileChooserAttachment = new JFileChooser (); 372 jFileChooserAttachment.setMultiSelectionEnabled(true); 373 jButtonAddAttachments.addActionListener(new ActionListener () { 374 public void actionPerformed(ActionEvent e) { 375 int res = jFileChooserAttachment.showOpenDialog(Console.this); 376 if (res == JFileChooser.APPROVE_OPTION) { 377 for (File attachmentFile : jFileChooserAttachment.getSelectedFiles()) { 378 jListModelSelectedAttachments.addElement(attachmentFile); 379 } 380 } 381 } 382 }); 383 } 384 { 385 jButtonRemoveAttachments = new JButton (); 387 jButtonRemoveAttachments.setText("Remove selected"); 388 jButtonRemoveAttachments.setBounds(new Rectangle (5, 20, 196, 26)); 389 jButtonRemoveAttachments.setPreferredSize(new java.awt.Dimension (130, 18)); 390 jButtonRemoveAttachments.addActionListener(new ActionListener () { 391 public void actionPerformed(ActionEvent e) { 392 for (Object attachment : jListSelectedAttachments.getSelectedValues()) { 393 jListModelSelectedAttachments.removeElement(attachment); 394 } 395 } 396 }); 397 } 398 { 399 JPanel jPanelAttachmentButtons = new JPanel (new GridLayout (1, 2)); 400 jPanelAttachmentButtons.add(jButtonAddAttachments, null); 401 jPanelAttachmentButtons.add(jButtonRemoveAttachments, null); 402 jPanelAttachment.add(new JScrollPane (jListSelectedAttachments), BorderLayout.CENTER); 403 jPanelAttachment.add(jPanelAttachmentButtons, BorderLayout.SOUTH); 404 } 405 } 406 { 407 typeGroup = new ButtonGroup (); 408 } 409 { 410 jPanel3 = new JPanel (); 411 jPanel3.setBackground(new Color (242, 237, 243)); 412 jPanel3.setLayout(gridLayout1); 413 jPanel3.setLocation(new Point (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 (); 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 (); 428 inout.setText("InOut"); 429 typeGroup.add(inout); 430 inout.setOpaque(false); 431 } 432 { 433 inoutopt = new JRadioButton (); 434 jPanel3.add(jRadioButton1, null); 435 inoutopt.setText("InOptionalOut"); 436 typeGroup.add(inoutopt); 437 inoutopt.setOpaque(false); 438 } 439 { 440 robustin = new JRadioButton (); 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 (); 451 jPanel2.setLayout(null); 452 jPanel2.setSize(586, 344); 453 jPanel2.setLocation(new Point (0, 260)); 454 jPanel2 455 .setPreferredSize(new java.awt.Dimension (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 (); 462 jLabel3.setText("In"); 463 jLabel3.setBounds(new Rectangle (5, 20, 576, 20)); 464 } 465 { 466 jScrollPane1 = new JScrollPane (); 467 jScrollPane1 468 .setBounds(new Rectangle (5, 45, 576, 90)); 469 jPanel2.add(jLabel3, null); 470 { 471 in = new JTextArea (3, 40); 472 jScrollPane1.setViewportView(in); 473 in.setLineWrap(true); 474 in.setWrapStyleWord(true); 475 in.setPreferredSize(new Dimension (573, 64)); 476 in.setText("<text>hi !</text>"); 477 } 478 } 479 { 480 jLabel4 = new JLabel (); 481 jPanel2.add(jScrollPane1, null); 482 jLabel4.setText("Out"); 483 jLabel4.setBounds(new Rectangle (5, 140, 576, 20)); 484 } 485 { 486 jScrollPane2 = new JScrollPane (); 487 jScrollPane2.setBounds(new Rectangle (5, 165, 576, 488 90)); 489 jPanel2.add(jLabel4, null); 490 jPanel2.add(jScrollPane2, null); 491 { 492 out = new JTextArea (3, 40); 493 out.setLineWrap(true); 494 out.setWrapStyleWord(true); 495 jScrollPane2.setViewportView(out); 496 } 497 } 498 } 499 { 500 jPanel4 = new JPanel (); 501 jPanel2.add(jPanel4, null); 502 sendPanel.add(jPanel1); 503 sendPanel.add(jPanelAttachment); sendPanel.add(jPanel3, null); 505 sendPanel.add(jPanel2, null); 506 jPanel4.setLayout(null); 507 jPanel4.setOpaque(false); 508 jPanel4.setBounds(new Rectangle (2, 259, 586, 99)); 509 jPanel4.setBorder(BorderFactory 510 .createTitledBorder("Send")); 511 { 512 sendSync = new JButton (); 513 sendSync.setText("SendSync"); 514 sendSync.setBounds(new Rectangle (5, 20, 196, 26)); 515 sendSync.setPreferredSize(new java.awt.Dimension ( 516 130, 18)); 517 sendSync.addActionListener(new ActionListener () { 518 public void actionPerformed(ActionEvent evt) { 519 sendSync(); 520 } 521 }); 522 } 523 { 524 timeout = new JTextField (); 525 timeout.setText("0"); 526 timeout.setToolTipText("timeout, in ms"); 527 timeout.setBounds(new Rectangle (209, 23, 42, 23)); 528 } 529 { 530 jButton1 = new JButton (); 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 (5, 55, 196, 27)); 536 jButton1.setPreferredSize(new java.awt.Dimension ( 537 152, 15)); 538 jButton1.addActionListener(new ActionListener () { 539 public void actionPerformed(ActionEvent evt) { 540 send(); 541 } 542 }); 543 } 544 } 545 } 546 { 547 queryPanel = new JPanel (); 548 queryPanel.setOpaque(false); 549 jTabbedPane1.addTab("Query", null, queryPanel, null); 550 { 551 552 byte[] buffer = null; 553 InputStream inStream = this.getClass() 554 .getResourceAsStream("/ebmlogo.jpg"); 555 try { 556 if (inStream == null) { 557 inStream = new FileInputStream ("src" 558 + File.separator + "img" + File.separator 559 + "ebmlogo.jpg"); 560 } 561 DataInputStream dis = new DataInputStream (inStream); 562 buffer = new byte[dis.available()]; 563 dis.readFully(buffer); 564 ImageIcon img1 = new ImageIcon (buffer); 565 background1 = new JLabel (img1); 566 569 } catch (Exception e) { 570 JOptionPane.showMessageDialog(this, e.getMessage(), 571 "Error", JOptionPane.ERROR_MESSAGE); 572 } 573 574 { 575 topQueryPanel = new JPanel (); 576 topQueryPanel.setLayout(null); 577 topQueryPanel.setOpaque(false); 578 { 580 jLabel8 = new JLabel (); 581 jLabel8 582 .setText("Query the server to find endpoints"); 583 jLabel8.setBounds(new Rectangle (5, 0, 241, 23)); 584 jLabel8.setFont(new java.awt.Font ("Tahoma", 0, 585 14)); 586 587 jLabel81 = new JLabel (); 588 jLabel81.setText("Result : List of endpoints"); 589 jLabel81.setBounds(new Rectangle (5, 180, 241, 590 26)); 591 jLabel81.setFont(new java.awt.Font ("Tahoma", 0, 592 14)); 593 } 594 { 595 jButton2 = new JButton (); 596 jButton2.setText("Find all the endpoints"); 597 jButton2 598 .setBounds(new Rectangle (5, 30, 181, 25)); 599 jButton2 600 .setPreferredSize(new java.awt.Dimension ( 601 123, 23)); 602 jButton2 603 .addActionListener(new ActionListener () { 604 public void actionPerformed( 605 ActionEvent evt) { 606 getServices(); 607 } 608 }); 609 } 610 { 611 jSeparator1 = new JSeparator (); 612 jSeparator1.setBounds(new Rectangle (5, 60, 253, 613 8)); 614 } 615 { 616 resolve = new JButton (); 617 resolve 618 .setText("Resolve following description"); 619 resolve 620 .setActionCommand("Resolve following description"); 621 resolve 622 .setBounds(new Rectangle (5, 65, 241, 25)); 623 resolve.addActionListener(new ActionListener () { 624 public void actionPerformed(ActionEvent evt) { 625 resolveDescription(); 626 } 627 }); 628 } 629 { 630 jTextArea1 = new JTextArea (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 (5, 95, 576, 641 71)); 642 } 643 } 644 645 topQueryPanel.add(getJSeparator11(), null); 646 topQueryPanel.add(jLabel81, null); 647 ListModel jList1Model = new DefaultComboBoxModel ( 648 new String [0]); 649 jList1 = new JList (); 650 651 servicesScrollPanel = new JScrollPane (); 652 servicesScrollPanel.setViewportView(jList1); 653 jList1.setModel(jList1Model); 654 655 } 656 { 657 botQueryPanel = new JPanel (); 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 (); 665 jButton3.setText("Get service description"); 666 jButton3.setBounds(new Rectangle (5, 20, 251, 25)); 667 jButton3.setPreferredSize(new java.awt.Dimension ( 668 145, 26)); 669 jButton3.addActionListener(new ActionListener () { 670 public void actionPerformed(ActionEvent evt) { 671 showDescription(); 672 } 673 }); 674 jButton31 = new JButton (); 675 jButton31 676 .setBounds(new Rectangle (265, 20, 231, 25)); 677 jButton31.setText("Get interfaces"); 678 jButton31.setPreferredSize(new Dimension (145, 26)); 679 jButton31.addActionListener(new ActionListener () { 680 public void actionPerformed(ActionEvent evt) { 681 showInterfaces(); 682 } 683 }); 684 } 685 { 686 asreference = new JButton (); 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 (5, 55, 251, 25)); 694 asreference.addActionListener(new ActionListener () { 695 public void actionPerformed(ActionEvent evt) { 696 topQueryPanel.add(jLabel81, null); 697 getAsReference(); 698 } 699 }); 700 701 if (background1 != null) { 702 background1.setBounds(new Rectangle (360, 63, 703 background.getWidth(), background 704 .getHeight())); 705 botQueryPanel.add(background1, null); 706 } 707 } 708 } 709 710 servicesQueryPanel = new JPanel (new BorderLayout ()); 711 servicesQueryPanel.add(servicesScrollPanel, 712 BorderLayout.CENTER); 713 714 718 queryPanel.setLayout(new GridBagLayout ()); 719 720 GridBagConstraints c = new GridBagConstraints (); 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 (242, 237, 243)); 755 } catch (Exception e) { 756 e.printStackTrace(); 757 } 758 } 759 760 764 private void initialize() { 765 this.setLayout(new BorderLayout ()); 766 this.setTitle("Petals - Sample client"); 767 this.setBackground(new Color (242, 237, 243)); 768 this.setResizable(true); 769 this.setSize(600, 699); 770 lockInMinSize(this); 771 } 772 773 private static void lockInMinSize(final JFrame frame) { 774 final int origX = frame.getSize().width; 777 final int origY = frame.getSize().height; 778 frame.addComponentListener(new java.awt.event.ComponentAdapter () { 779 public void componentResized(ComponentEvent 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 793 private void openDialogBox(String title, String textMsg) { 794 JFrame f = new JFrame (title); 795 JTextArea text = new JTextArea (textMsg); 796 text.setLineWrap(true); 797 text.setWrapStyleWord(true); 798 JScrollPane sp = new JScrollPane (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 fragmentDescription = jTextArea1.getText(); 808 809 ServiceEndpoint se = sampleClient 810 .resolveDescription(fragmentDescription); 811 DefaultListModel listModel = new DefaultListModel (); 812 listModel.addElement(se); 813 jList1.setModel(listModel); 814 } 815 816 821 private List <File > getAttachmentFiles() { 822 ArrayList <File > attachmentFiles = new ArrayList <File >(); 823 Enumeration <?> attachmentEnum = jListModelSelectedAttachments.elements(); 824 while (attachmentEnum.hasMoreElements()) { 825 Object attachment = attachmentEnum.nextElement(); 826 if (attachment instanceof File ) { 827 attachmentFiles.add((File ) attachment); 828 } } 830 return attachmentFiles; 831 } 832 833 private void send() { 834 JRadioButton selected = null; 835 out.setText(""); 836 Enumeration <AbstractButton > rbs = typeGroup.getElements(); 837 while (rbs.hasMoreElements()) { 838 AbstractButton but = rbs.nextElement(); 839 if (but.isSelected()) { 840 selected = (JRadioButton ) 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 selected = null; 850 out.setText(""); 851 Enumeration <AbstractButton > rbs = typeGroup.getElements(); 852 while (rbs.hasMoreElements()) { 853 AbstractButton but = rbs.nextElement(); 854 if (but.isSelected()) { 855 selected = (JRadioButton ) 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 text) { 865 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 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 msg = sampleClient.getInterfaces(se); 884 openDialogBox("Interfaces of " + se, msg); 885 } 886 887 public void showError(Throwable e) { 888 String error = ""; 889 for (StackTraceElement 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 msg) { 896 JOptionPane.showMessageDialog(this, msg, "warning", 897 JOptionPane.WARNING_MESSAGE); 898 } 899 } | Popular Tags |