KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > bidbuy > rfq


1 package samples.bidbuy ;
2
3 import javax.swing.*;
4 import javax.swing.border.EmptyBorder JavaDoc;
5 import javax.swing.border.TitledBorder JavaDoc;
6 import javax.swing.event.TableModelEvent JavaDoc;
7 import javax.swing.event.TableModelListener JavaDoc;
8 import javax.swing.table.DefaultTableModel JavaDoc;
9 import javax.swing.table.TableColumn JavaDoc;
10 import java.awt.*;
11 import java.awt.event.ActionEvent JavaDoc;
12 import java.awt.event.ActionListener JavaDoc;
13 import java.awt.event.WindowEvent JavaDoc;
14 import java.io.FileOutputStream JavaDoc;
15 import java.io.FileReader JavaDoc;
16 import java.io.LineNumberReader JavaDoc;
17 import java.io.PrintWriter JavaDoc;
18 import java.util.Vector JavaDoc;
19
20 public class rfq extends JPanel {
21   private vInterface vv = new v3();
22
23   private String JavaDoc regServerURL = null ;
24   private TitledBorder JavaDoc regServerBorder = null ;
25   private JComboBox regServerList = null ;
26   private JButton removeButton = null ;
27   private JTable serverTable = null ;
28   private DefaultTableModel JavaDoc tableModel = null ;
29   private JPanel regListPanel = null ;
30   private JButton refreshButton = null ;
31   private JButton pingButton = null ;
32   private JButton selectAllButton = null ;
33   private JButton deselectAllButton = null ;
34   private JButton requestButton = null ;
35   private JButton registerButton = null ;
36   private JButton addServerButton = null ;
37   private JButton removeServerButton = null ;
38   private JButton unregisterServerButton = null ;
39   private JPanel purchasePanel = null ;
40   private JComboBox buyList = null ;
41   private JTextField tServer, tQuantity, tAddress ;
42   private JComboBox tNumItems ;
43
44   public boolean doAxis = true ;
45
46   private static int CHECK_COLUMN = 0 ;
47   private static int NAME_COLUMN = 1 ;
48   private static int URL_COLUMN = 2 ;
49   private static int TYPE_COLUMN = 3 ;
50   private static int WSDL_COLUMN = 4 ;
51   private static int STATE_COLUMN = 5 ;
52   private static int QUOTE_COLUMN = 6 ;
53   private static int NUM_COLUMNS = 7 ;
54
55   class MyTableModel extends DefaultTableModel JavaDoc {
56     public MyTableModel(Object JavaDoc[] obj, int x) { super( obj, x); }
57     public Class JavaDoc getColumnClass(int col) {
58       if ( col == CHECK_COLUMN ) return( Boolean JavaDoc.class );
59       return( super.getColumnClass(col) );
60     }
61   };
62
63   public rfq() {
64     setLayout( new BorderLayout() );
65
66     // Do the Registration Server list area
67
//////////////////////////////////////////////////////////////////////////
68
JPanel regSelectPanel = new JPanel();
69     regSelectPanel.setLayout( new BoxLayout(regSelectPanel, BoxLayout.X_AXIS) );
70     regSelectPanel.setBorder( new EmptyBorder JavaDoc(5,5,5,5) );
71     regSelectPanel.add( new JLabel( "Registration Server: " ) );
72     regSelectPanel.add( regServerList = new JComboBox() );
73     regSelectPanel.add( Box.createRigidArea(new Dimension(5,0)) );
74     regSelectPanel.add( removeButton = new JButton("Remove") );
75
76     loadRegList();
77
78     regServerList.setEditable( true );
79     regServerList.addActionListener( new ActionListener JavaDoc() {
80         public void actionPerformed(ActionEvent JavaDoc event) {
81           String JavaDoc act = event.getActionCommand();
82           if ( act.equals( "comboBoxChanged" ) ) {
83             String JavaDoc name = (String JavaDoc) regServerList.getSelectedItem();
84             if ( name != null && !name.equals("") ) {
85               chooseRegServer( name );
86               addRegistrationServer( name );
87             }
88             else
89               clearTable();
90           }
91         };
92       });
93
94     removeButton.setEnabled( true );
95     removeButton.addActionListener( new ActionListener JavaDoc() {
96         public void actionPerformed(ActionEvent JavaDoc event) {
97           if ( "Remove".equals(event.getActionCommand()) ) {
98             String JavaDoc name = (String JavaDoc) regServerList.getSelectedItem();
99             regServerList.removeItem( name );
100             saveRegList();
101           }
102         };
103       });
104
105     add( regSelectPanel, BorderLayout.NORTH );
106
107     // Do the List Of Registration Servers Table
108
//////////////////////////////////////////////////////////////////////////
109
regListPanel = new JPanel();
110     regListPanel.setLayout( new BorderLayout() );
111     regServerBorder = new TitledBorder JavaDoc(" Product Servers ");
112     regListPanel.setBorder( regServerBorder );
113     regListPanel.add( new JLabel( "Select the servers you want to request " +
114                                   "a price from:"), BorderLayout.NORTH );
115                 
116     tableModel = new MyTableModel( new Object JavaDoc[] {"", "Name", "URL", "Type",
117                                                  "WSDL", "State", "Quote",
118                                                  ""}, 0 );
119     serverTable = new JTable( 0, NUM_COLUMNS );
120     serverTable.setModel( tableModel );
121     serverTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
122     TableColumn JavaDoc col = serverTable.getColumnModel().getColumn(CHECK_COLUMN);
123     col.setMaxWidth( 10 );
124     // col = serverTable.getColumnModel().getColumn(STATE_COLUMN);
125
// col.setMaxWidth( col.getPreferredWidth()/2 );
126
// col = serverTable.getColumnModel().getColumn(QUOTE_COLUMN);
127
// col.setMaxWidth( col.getPreferredWidth()/2 );
128
col = serverTable.getColumnModel().getColumn(TYPE_COLUMN);
129     col.setMaxWidth( col.getPreferredWidth()/2 );
130
131     tableModel.addTableModelListener( new TableModelListener JavaDoc() {
132         public void tableChanged(TableModelEvent JavaDoc event) {
133           int type = event.getType();
134           if ( type == TableModelEvent.UPDATE && event.getColumn() == 0 )
135             enableButtons();
136         };
137       });
138
139     regListPanel.add( new JScrollPane(serverTable), BorderLayout.CENTER );
140
141     JPanel btns = new JPanel();
142     // btns.setLayout( new BoxLayout( btns, BoxLayout.X_AXIS ) );
143
btns.setLayout( new GridBagLayout() );
144
145     GridBagConstraints c = new GridBagConstraints();
146
147     c.anchor = GridBagConstraints.WEST ;
148     c.gridwidth = 1 ;
149     c.fill = GridBagConstraints.HORIZONTAL ;
150
151     // row 1
152
btns.add( refreshButton = new JButton( "Refresh List" ), c );
153     btns.add( Box.createRigidArea(new Dimension(5,0)), c );
154     btns.add( selectAllButton = new JButton( "Select All" ), c );
155     btns.add( Box.createRigidArea(new Dimension(5,0)), c );
156     btns.add( requestButton = new JButton( "Request RFQs" ), c );
157     c.weightx = 1.0 ;
158     btns.add( Box.createHorizontalGlue(), c );
159     c.weightx = 0.0 ;
160     btns.add( registerButton = new JButton( "Register Server" ), c );
161     btns.add( Box.createRigidArea(new Dimension(5,0)), c );
162     c.gridwidth = GridBagConstraints.REMAINDER ;
163     btns.add( addServerButton = new JButton( "Add Bid Server" ), c );
164
165     // row 2
166
c.gridwidth = 1 ;
167     c.gridx = 2 ;
168     btns.add( deselectAllButton = new JButton( "Deselect All" ), c );
169     c.gridx = GridBagConstraints.RELATIVE ;
170     btns.add( Box.createRigidArea(new Dimension(5,0)), c );
171     btns.add( pingButton = new JButton( "Ping" ), c );
172     c.weightx = 1.0 ;
173     btns.add( Box.createRigidArea(new Dimension(5,0)), c );
174     c.weightx = 0.0 ;
175     btns.add( unregisterServerButton = new JButton( "Unregister Server" ), c );
176     btns.add( Box.createRigidArea(new Dimension(5,0)), c );
177     // btns.add( Box.createRigidArea(new Dimension(5,0)), c );
178
c.gridwidth = GridBagConstraints.REMAINDER ;
179     btns.add( removeServerButton = new JButton( "Remove Server" ), c );
180
181     regListPanel.add( btns, BorderLayout.SOUTH );
182
183     refreshButton.setEnabled( false );
184     refreshButton.addActionListener( new ActionListener JavaDoc() {
185         public void actionPerformed(ActionEvent JavaDoc event) {
186           if ( "Refresh List".equals(event.getActionCommand()) ) {
187             refreshList();
188           }
189         };
190       });
191
192     selectAllButton.setEnabled( false );
193     selectAllButton.addActionListener( new ActionListener JavaDoc() {
194         public void actionPerformed(ActionEvent JavaDoc event) {
195           if ( "Select All".equals(event.getActionCommand()) ) {
196             for ( int i = 0 ; i < tableModel.getRowCount() ; i++ ){
197               tableModel.setValueAt(new Boolean JavaDoc(true),i,CHECK_COLUMN);
198             }
199           }
200         };
201       });
202
203     deselectAllButton.setEnabled( false );
204     deselectAllButton.addActionListener( new ActionListener JavaDoc() {
205         public void actionPerformed(ActionEvent JavaDoc event) {
206           if ( "Deselect All".equals(event.getActionCommand()) ) {
207             for ( int i = 0 ; i < tableModel.getRowCount() ; i++ ){
208               tableModel.setValueAt(new Boolean JavaDoc(false),i,CHECK_COLUMN);
209             }
210           }
211         };
212       });
213
214     pingButton.setEnabled( false );
215     pingButton.addActionListener( new ActionListener JavaDoc() {
216         public void actionPerformed(ActionEvent JavaDoc event) {
217           if ( "Ping".equals(event.getActionCommand()) ) {
218             ping();
219           }
220         };
221       });
222
223     requestButton.setEnabled( false );
224     requestButton.addActionListener( new ActionListener JavaDoc() {
225         public void actionPerformed(ActionEvent JavaDoc event) {
226           if ( "Request RFQs".equals(event.getActionCommand()) ) {
227             requestRFQs();
228           }
229         };
230       });
231
232     registerButton.setEnabled( false );
233     registerButton.addActionListener( new ActionListener JavaDoc() {
234         public void actionPerformed(ActionEvent JavaDoc event) {
235           if ( "Register Server".equals(event.getActionCommand()) )
236             registerNewServer();
237         };
238       });
239
240     addServerButton.setEnabled( true );
241     addServerButton.addActionListener( new ActionListener JavaDoc() {
242         public void actionPerformed(ActionEvent JavaDoc event) {
243           if ( "Add Bid Server".equals(event.getActionCommand()) )
244             promptForServer();
245         };
246       });
247
248     removeServerButton.setEnabled( false );
249     removeServerButton.addActionListener( new ActionListener JavaDoc() {
250         public void actionPerformed(ActionEvent JavaDoc event) {
251           if ( "Remove Server".equals(event.getActionCommand()) )
252             removeServers();
253         };
254       });
255
256     unregisterServerButton.setEnabled( false );
257     unregisterServerButton.addActionListener( new ActionListener JavaDoc() {
258         public void actionPerformed(ActionEvent JavaDoc event) {
259           if ( "Unregister Server".equals(event.getActionCommand()) )
260             unregisterServer();
261         };
262       });
263
264
265     // Purchase data
266
//////////////////////////////////////////////////////////////////////////
267
GridBagLayout layout = new GridBagLayout();
268     // GridBagConstraints c = new GridBagConstraints();
269
c = new GridBagConstraints();
270
271     purchasePanel = new JPanel(layout);
272     purchasePanel.setBorder( new TitledBorder JavaDoc("Purchase") );
273
274     JButton tSimpleBuy ;
275     JButton tPOBuy ;
276
277     c.anchor = GridBagConstraints.WEST ;
278     c.gridwidth = GridBagConstraints.REMAINDER ;
279     purchasePanel.add( new JLabel("Select the purchase server from the " +
280                                   "combo box" ),c );
281
282     c.anchor = GridBagConstraints.EAST ;
283     c.gridwidth = 1 ;
284     purchasePanel.add( new JLabel("Server:"), c );
285
286     c.anchor = GridBagConstraints.WEST ;
287     c.gridwidth = GridBagConstraints.REMAINDER ;
288     purchasePanel.add( buyList = new JComboBox(), c );
289
290     c.gridwidth = 1 ;
291     c.anchor = GridBagConstraints.EAST ;
292     purchasePanel.add( new JLabel("Quantity:"),c );
293
294     c.anchor = GridBagConstraints.WEST ;
295     c.gridwidth = GridBagConstraints.REMAINDER ;
296     purchasePanel.add( tQuantity = new JTextField(6), c );
297     tQuantity.setText("1");
298
299     c.anchor = GridBagConstraints.EAST ;
300     c.gridwidth = 1 ;
301     purchasePanel.add( new JLabel("# Line Items:"),c );
302
303     c.anchor = GridBagConstraints.WEST ;
304     c.gridwidth = GridBagConstraints.REMAINDER ;
305     purchasePanel.add( tNumItems = new JComboBox(), c );
306
307     c.anchor = GridBagConstraints.WEST ;
308     c.gridwidth = 1 ;
309     purchasePanel.add( tSimpleBuy = new JButton( "Simple Buy" ) );
310
311     c.anchor = GridBagConstraints.WEST ;
312     c.gridwidth = GridBagConstraints.REMAINDER ;
313     purchasePanel.add( tPOBuy = new JButton( "PO Buy" ) );
314
315     for ( int j = 1 ; j < 20 ; j++ )
316       tNumItems.addItem( ""+j );
317
318     tSimpleBuy.addActionListener( new ActionListener JavaDoc() {
319         public void actionPerformed(ActionEvent JavaDoc event) {
320           if ( "Simple Buy".equals(event.getActionCommand()) ) {
321             simpleBuy();
322           }
323         };
324       });
325
326     tPOBuy.addActionListener( new ActionListener JavaDoc() {
327         public void actionPerformed(ActionEvent JavaDoc event) {
328           if ( "PO Buy".equals(event.getActionCommand()) ) {
329             poBuy();
330           }
331         };
332       });
333
334     JSplitPane splitPane = new JSplitPane( 0, regListPanel,
335                                                new JScrollPane(purchasePanel));
336     add( splitPane, BorderLayout.CENTER );
337     setSize(getPreferredSize());
338     splitPane.setDividerLocation( 200 );
339     purchasePanel.setEnabled( false );
340   }
341
342   public void addRegistrationServer( String JavaDoc name ) {
343     int count, i ;
344
345     if ( name == null || "".equals(name) ) return ;
346     count = regServerList.getItemCount();
347     for ( i = 0 ; i < count ; i++ )
348       if ( name.equals( regServerList.getItemAt(i) ) ) return ;
349     regServerList.addItem( name );
350     saveRegList();
351   }
352
353   public void chooseRegServer(String JavaDoc name) {
354     regServerURL = name ;
355     regServerBorder.setTitle( " Product Servers at ' " + name + " ' " );
356     regListPanel.repaint();
357     refreshList();
358   }
359
360   public void enableButtons() {
361     boolean flag ;
362     int i ;
363     int total = tableModel.getRowCount();
364     int count = 0 ;
365     for ( i = 0 ; i < total ; i++ ) {
366       flag = ((Boolean JavaDoc)tableModel.getValueAt(i,CHECK_COLUMN)).booleanValue();
367       if ( flag ) count++ ;
368     }
369     selectAllButton.setEnabled( total > 0 && count != total );
370     deselectAllButton.setEnabled( total > 0 && count > 0 );
371     pingButton.setEnabled( count > 0 );
372     requestButton.setEnabled( count > 0 );
373     removeServerButton.setEnabled( count > 0 );
374     unregisterServerButton.setEnabled( count > 0 );
375   }
376
377   public void clearTable() {
378     while ( tableModel.getRowCount() > 0 )
379       tableModel.removeRow(0);
380     enableButtons();
381   }
382
383   public void refreshList() {
384     clearTable();
385
386     Vector JavaDoc services = null ;
387
388     try {
389       services = vv.lookupAsString(regServerURL);
390     }
391     catch( Exception JavaDoc e ) {
392       System.err.println("---------------------------------------------");
393       e.printStackTrace();
394       JOptionPane.showMessageDialog(this, e.toString(), "Error",
395                                     JOptionPane.INFORMATION_MESSAGE );
396     }
397
398     for ( int i = 0 ; services != null && i < services.size() ; i++ ) {
399       Service s = (Service) services.elementAt(i);
400       addServer( s );
401     }
402
403     buyList.removeAllItems();
404     purchasePanel.setEnabled( false );
405     refreshButton.setEnabled( true );
406     registerButton.setEnabled( true );
407     enableButtons();
408   }
409
410   public void ping() {
411     Boolean JavaDoc flag ;
412     int i;
413
414     for ( i = 0 ; i < tableModel.getRowCount() ; i++ ) {
415       flag = (Boolean JavaDoc) tableModel.getValueAt( i, CHECK_COLUMN );
416       if ( flag.booleanValue() ) {
417         String JavaDoc url = (String JavaDoc) tableModel.getValueAt( i, URL_COLUMN );
418         Boolean JavaDoc value = new Boolean JavaDoc(false);
419
420         try {
421           value = vv.ping( url );
422
423           tableModel.setValueAt( value.booleanValue() ? "Alive" : "Down",
424                                  i, STATE_COLUMN );
425           serverTable.repaint();
426         }
427         catch( Exception JavaDoc e ) {
428           JOptionPane.showMessageDialog(this, e.toString(), "Error",
429                                         JOptionPane.INFORMATION_MESSAGE );
430         }
431
432       }
433     }
434   }
435
436   public void unregisterServer() {
437     Boolean JavaDoc flag ;
438     int i;
439
440     for ( i = 0 ; i < tableModel.getRowCount() ; i++ ) {
441       flag = (Boolean JavaDoc) tableModel.getValueAt( i, CHECK_COLUMN );
442       if ( flag.booleanValue() ) {
443         String JavaDoc name = (String JavaDoc) tableModel.getValueAt( i, NAME_COLUMN );
444         String JavaDoc regServer = (String JavaDoc) regServerList.getSelectedItem() ;
445         Boolean JavaDoc value = new Boolean JavaDoc(false);
446
447         try {
448           vv.unregister( regServer, name);
449         }
450         catch( Exception JavaDoc e ) {
451           JOptionPane.showMessageDialog(this, e.toString(), "Error",
452                                         JOptionPane.INFORMATION_MESSAGE );
453         }
454
455       }
456     }
457     refreshList();
458   }
459
460   public void requestRFQs() {
461     Boolean JavaDoc flag ;
462     int i, j;
463
464     // buyList.removeAllItems();
465

466     for ( i = 0 ; i < tableModel.getRowCount() ; i++ ) {
467       flag = (Boolean JavaDoc) tableModel.getValueAt( i, CHECK_COLUMN );
468       if ( flag.booleanValue() ) {
469         String JavaDoc url = (String JavaDoc) tableModel.getValueAt( i, URL_COLUMN );
470         double value = 0.0 ;
471
472         try {
473           value = vv.requestForQuote( url );
474
475           tableModel.setValueAt( new Double JavaDoc(value), i, QUOTE_COLUMN );
476           serverTable.repaint();
477
478           String JavaDoc str = (String JavaDoc) tableModel.getValueAt(i, NAME_COLUMN);
479           for ( j = 0 ; j < buyList.getItemCount(); j++ )
480             if ( ((String JavaDoc)buyList.getItemAt(j)).equals(str) ) break ;
481           if ( j == buyList.getItemCount() )
482             buyList.addItem( str );
483         }
484         catch( Exception JavaDoc e ) {
485           JOptionPane.showMessageDialog(this, e.toString(), "Error",
486                                         JOptionPane.INFORMATION_MESSAGE );
487         }
488
489       }
490     }
491     // buyList.setSelectedIndex(-1);
492
purchasePanel.setEnabled( true );
493   }
494
495   public void removeServers() {
496     Boolean JavaDoc flag ;
497     int i, j;
498
499     for ( i = tableModel.getRowCount()-1 ; i >= 0 ; i-- ) {
500       flag = (Boolean JavaDoc) tableModel.getValueAt( i, CHECK_COLUMN );
501       if ( flag.booleanValue() )
502         tableModel.removeRow( i );
503     }
504     enableButtons();
505   }
506
507   public void simpleBuy() {
508     try {
509       String JavaDoc url = null ;
510       int total = tableModel.getRowCount();
511       String JavaDoc name = (String JavaDoc) buyList.getSelectedItem();
512       for ( int i = 0 ; i < total ; i++ ) {
513         String JavaDoc val = (String JavaDoc) tableModel.getValueAt(i, NAME_COLUMN) ;
514         if ( val.equals(name) ) {
515           url = (String JavaDoc) tableModel.getValueAt(i, URL_COLUMN);
516           break ;
517         }
518       }
519       String JavaDoc address = "123 Main Street, Any Town, USA" ;
520       String JavaDoc product = "soap" ;
521       int quantity = Integer.parseInt((String JavaDoc) tQuantity.getText());
522       String JavaDoc value = null ;
523
524       value = vv.simpleBuy( url, quantity );
525
526       JOptionPane.showMessageDialog(this, value, "Receipt",
527                                     JOptionPane.INFORMATION_MESSAGE );
528     }
529     catch( Exception JavaDoc e ) {
530       JOptionPane.showMessageDialog(this, e.toString(), "Error",
531                                     JOptionPane.INFORMATION_MESSAGE );
532     }
533   }
534
535   public void poBuy() {
536     try {
537       String JavaDoc url = null ;
538       int total = tableModel.getRowCount();
539       String JavaDoc name = (String JavaDoc) buyList.getSelectedItem();
540       double price = 0 ;
541       for ( int i = 0 ; i < total ; i++ ) {
542         String JavaDoc val = (String JavaDoc) tableModel.getValueAt(i, NAME_COLUMN) ;
543         Double JavaDoc dval ;
544         if ( val.equals(name) ) {
545           url = (String JavaDoc) tableModel.getValueAt(i, URL_COLUMN);
546           dval = (Double JavaDoc) tableModel.getValueAt(i, QUOTE_COLUMN);
547           price = dval.doubleValue();
548           break ;
549         }
550       }
551       // String address = (String) tAddress.getText();
552
String JavaDoc product = "soap" ;
553       int quantity = Integer.parseInt((String JavaDoc) tQuantity.getText());
554       int numItems = Integer.parseInt((String JavaDoc) tNumItems.getSelectedItem());
555       String JavaDoc value = null ;
556
557       value = vv.buy( url, quantity, numItems, price );
558
559       JOptionPane.showMessageDialog(this, value, "Receipt",
560                                     JOptionPane.INFORMATION_MESSAGE );
561     }
562     catch( Exception JavaDoc e ) {
563       e.printStackTrace();
564       JOptionPane.showMessageDialog(this, e.toString(), "Error",
565                                     JOptionPane.INFORMATION_MESSAGE );
566     }
567   }
568
569   public void registerNewServer() {
570     Component parent = this ;
571     while ( parent != null && !(parent instanceof JFrame) )
572       parent = parent.getParent();
573     final JDialog j = new JDialog((JFrame)parent, "Register Server", true );
574     Container pane = j.getContentPane();
575     final JTextField fName = new JTextField(20),
576                       fURL = new JTextField(20),
577                       fType = new JTextField(20),
578                       fWsdl = new JTextField(20);
579     JButton regButton, cancelButton ;
580
581     pane.setLayout( new GridBagLayout() );
582     GridBagConstraints c = new GridBagConstraints();
583
584     c.anchor = GridBagConstraints.WEST ;
585     c.gridwidth = 1 ;
586     pane.add( new JLabel( "Service Name" ), c );
587
588     c.anchor = GridBagConstraints.WEST ;
589     c.gridwidth = GridBagConstraints.REMAINDER ;
590     pane.add( fName, c );
591
592     c.anchor = GridBagConstraints.WEST ;
593     c.gridwidth = 1 ;
594     pane.add( new JLabel( "Service URL" ), c );
595
596     c.anchor = GridBagConstraints.WEST ;
597     c.gridwidth = GridBagConstraints.REMAINDER ;
598     pane.add( fURL, c );
599
600     c.anchor = GridBagConstraints.WEST ;
601     c.gridwidth = 1 ;
602     pane.add( new JLabel( "Service Type" ), c );
603
604     c.anchor = GridBagConstraints.WEST ;
605     c.gridwidth = GridBagConstraints.REMAINDER ;
606     pane.add( fType, c );
607
608     c.anchor = GridBagConstraints.WEST ;
609     c.gridwidth = 1 ;
610     pane.add( new JLabel( "WSDL URL" ), c );
611
612     c.anchor = GridBagConstraints.WEST ;
613     c.gridwidth = GridBagConstraints.REMAINDER ;
614     pane.add( fWsdl, c );
615
616     c.anchor = GridBagConstraints.WEST ;
617     c.gridwidth = 1 ;
618     pane.add( regButton = new JButton( "Register" ), c );
619
620     c.anchor = GridBagConstraints.WEST ;
621     c.gridwidth = 1 ;
622     pane.add( Box.createHorizontalStrut(3), c );
623
624     c.anchor = GridBagConstraints.WEST ;
625     c.gridwidth = 1 ;
626     pane.add( cancelButton = new JButton( "Cancel" ), c );
627
628     fType.setText( "Bid" );
629
630     regButton.addActionListener( new ActionListener JavaDoc() {
631         public void actionPerformed(ActionEvent JavaDoc event) {
632           if ( "Register".equals(event.getActionCommand()) ) {
633             Service s = new Service();
634             s.setServiceName( fName.getText() );
635             s.setServiceUrl( fURL.getText() );
636             s.setServiceType( fType.getText() );
637             s.setServiceWsdl( fWsdl.getText() );
638             register( s );
639             j.dispose();
640           }
641         };
642       });
643
644     cancelButton.addActionListener( new ActionListener JavaDoc() {
645         public void actionPerformed(ActionEvent JavaDoc event) {
646           if ( "Cancel".equals(event.getActionCommand()) ) {
647             j.dispose();
648           }
649         };
650       });
651
652     j.pack();
653     Point p = new Point( parent.getLocation() );
654     Dimension d = parent.getSize();
655     p.setLocation( (int)(p.getX() + d.getWidth()/2),
656                    (int)(p.getY() + d.getHeight()/2) );
657     d = j.getSize();
658     j.setLocation( (int)(p.getX() - d.getWidth()/2),
659                    (int)(p.getY() - d.getHeight()/2) );
660     j.show();
661   }
662
663
664   public void promptForServer() {
665     Component parent = this ;
666     while ( parent != null && !(parent instanceof JFrame) )
667       parent = parent.getParent();
668     final JDialog j = new JDialog((JFrame)parent, "Add Bid Server", true );
669     Container pane = j.getContentPane();
670     final JTextField fName = new JTextField(20),
671                       fURL = new JTextField(20),
672                       fType = new JTextField(20),
673                       fWsdl = new JTextField(20);
674     JButton addButton, cancelButton ;
675
676     pane.setLayout( new GridBagLayout() );
677     GridBagConstraints c = new GridBagConstraints();
678
679     c.anchor = GridBagConstraints.WEST ;
680     c.gridwidth = 1 ;
681     pane.add( new JLabel( "Service Name" ), c );
682
683     c.anchor = GridBagConstraints.WEST ;
684     c.gridwidth = GridBagConstraints.REMAINDER ;
685     pane.add( fName, c );
686
687     c.anchor = GridBagConstraints.WEST ;
688     c.gridwidth = 1 ;
689     pane.add( new JLabel( "Service URL" ), c );
690
691     c.anchor = GridBagConstraints.WEST ;
692     c.gridwidth = GridBagConstraints.REMAINDER ;
693     pane.add( fURL, c );
694
695     c.anchor = GridBagConstraints.WEST ;
696     c.gridwidth = 1 ;
697     pane.add( new JLabel( "Service Type" ), c );
698
699     c.anchor = GridBagConstraints.WEST ;
700     c.gridwidth = GridBagConstraints.REMAINDER ;
701     pane.add( fType, c );
702
703     c.anchor = GridBagConstraints.WEST ;
704     c.gridwidth = 1 ;
705     pane.add( new JLabel( "WSDL URL" ), c );
706
707     c.anchor = GridBagConstraints.WEST ;
708     c.gridwidth = GridBagConstraints.REMAINDER ;
709     pane.add( fWsdl, c );
710
711     c.anchor = GridBagConstraints.WEST ;
712     c.gridwidth = 1 ;
713     pane.add( addButton = new JButton( "Add" ), c );
714
715     c.anchor = GridBagConstraints.WEST ;
716     c.gridwidth = 1 ;
717     pane.add( Box.createHorizontalStrut(3), c );
718
719     c.anchor = GridBagConstraints.WEST ;
720     c.gridwidth = 1 ;
721     pane.add( cancelButton = new JButton( "Cancel" ), c );
722
723     fType.setText( "Bid" );
724
725     addButton.addActionListener( new ActionListener JavaDoc() {
726         public void actionPerformed(ActionEvent JavaDoc event) {
727           if ( "Add".equals(event.getActionCommand()) ) {
728             Service s = new Service();
729             s.setServiceName( fName.getText() );
730             s.setServiceUrl( fURL.getText() );
731             s.setServiceType( fType.getText() );
732             s.setServiceWsdl( fWsdl.getText() );
733             addServer( s );
734             j.dispose();
735           }
736         };
737       });
738
739     cancelButton.addActionListener( new ActionListener JavaDoc() {
740         public void actionPerformed(ActionEvent JavaDoc event) {
741           if ( "Cancel".equals(event.getActionCommand()) ) {
742             j.dispose();
743           }
744         };
745       });
746
747     j.pack();
748     Point p = new Point( parent.getLocation() );
749     Dimension d = parent.getSize();
750     p.setLocation( (int)(p.getX() + d.getWidth()/2),
751                    (int)(p.getY() + d.getHeight()/2) );
752     d = j.getSize();
753     j.setLocation( (int)(p.getX() - d.getWidth()/2),
754                    (int)(p.getY() - d.getHeight()/2) );
755     j.show();
756   }
757
758   public void addServer(Service s) {
759     Object JavaDoc[] objs = new Object JavaDoc[NUM_COLUMNS] ;
760     objs[0] = new Boolean JavaDoc(false);
761     objs[1] = s.getServiceName();
762     objs[2] = s.getServiceUrl();
763     objs[3] = s.getServiceType();
764     objs[4] = s.getServiceWsdl();
765     objs[5] = null ;
766     objs[6] = null ;
767
768     tableModel.addRow( objs );
769   }
770
771   public void register(Service s) {
772     try {
773       vv.register( (String JavaDoc) regServerList.getSelectedItem(), s );
774       refreshList();
775     }
776     catch( Exception JavaDoc e ) {
777       JOptionPane.showMessageDialog(this, e.toString(), "Error",
778                                     JOptionPane.INFORMATION_MESSAGE );
779     }
780   }
781
782   public void loadRegList() {
783     try {
784       FileReader JavaDoc fr = new FileReader JavaDoc( "reg.lst" );
785       LineNumberReader JavaDoc lnr = new LineNumberReader JavaDoc( fr );
786       String JavaDoc line = null ;
787
788       while ( (line = lnr.readLine()) != null )
789         addRegistrationServer( line );
790       fr.close();
791     }
792     catch( Exception JavaDoc e ) {
793       e.printStackTrace();
794     }
795   }
796
797   public void saveRegList() {
798     try {
799       FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc( "reg.lst" );
800       PrintWriter JavaDoc pw = new PrintWriter JavaDoc( fos );
801       int count = regServerList.getItemCount();
802       int i ;
803
804       for ( i = 0 ; i < count ; i++ )
805         pw.println( (String JavaDoc) regServerList.getItemAt(i) );
806       pw.close();
807
808       fos.close();
809     }
810     catch( Exception JavaDoc e ) {
811       e.printStackTrace();
812     }
813   }
814
815   public static void main(String JavaDoc[] args) {
816     try {
817       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
818       JFrame window = new JFrame("Request For Quote Client") {
819           protected void processWindowEvent(WindowEvent JavaDoc event) {
820             switch( event.getID() ) {
821               case WindowEvent.WINDOW_CLOSING: exit();
822                                                break ;
823               default: super.processWindowEvent(event);
824                        break ;
825             }
826           }
827           private void exit() {
828             System.exit(0);
829           }
830         };
831
832       window.getContentPane().add( new rfq() );
833       window.pack();
834       window.setSize( new Dimension(800, 500) );
835       window.setVisible( true );
836     }
837     catch( Throwable JavaDoc exp ) {
838       exp.printStackTrace();
839     }
840   }
841 }
842
Popular Tags