Source Code Cross Referenced for rfq.java in  » J2EE » enhydra » samples » bidbuy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » enhydra » samples.bidbuy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package samples.bidbuy;
002:
003:        import javax.swing.*;
004:        import javax.swing.border.EmptyBorder;
005:        import javax.swing.border.TitledBorder;
006:        import javax.swing.event.TableModelEvent;
007:        import javax.swing.event.TableModelListener;
008:        import javax.swing.table.DefaultTableModel;
009:        import javax.swing.table.TableColumn;
010:        import java.awt.*;
011:        import java.awt.event.ActionEvent;
012:        import java.awt.event.ActionListener;
013:        import java.awt.event.WindowEvent;
014:        import java.io.FileOutputStream;
015:        import java.io.FileReader;
016:        import java.io.LineNumberReader;
017:        import java.io.PrintWriter;
018:        import java.util.Vector;
019:
020:        public class rfq extends JPanel {
021:            private vInterface vv = new v3();
022:
023:            private String regServerURL = null;
024:            private TitledBorder regServerBorder = null;
025:            private JComboBox regServerList = null;
026:            private JButton removeButton = null;
027:            private JTable serverTable = null;
028:            private DefaultTableModel tableModel = null;
029:            private JPanel regListPanel = null;
030:            private JButton refreshButton = null;
031:            private JButton pingButton = null;
032:            private JButton selectAllButton = null;
033:            private JButton deselectAllButton = null;
034:            private JButton requestButton = null;
035:            private JButton registerButton = null;
036:            private JButton addServerButton = null;
037:            private JButton removeServerButton = null;
038:            private JButton unregisterServerButton = null;
039:            private JPanel purchasePanel = null;
040:            private JComboBox buyList = null;
041:            private JTextField tServer, tQuantity, tAddress;
042:            private JComboBox tNumItems;
043:
044:            public boolean doAxis = true;
045:
046:            private static int CHECK_COLUMN = 0;
047:            private static int NAME_COLUMN = 1;
048:            private static int URL_COLUMN = 2;
049:            private static int TYPE_COLUMN = 3;
050:            private static int WSDL_COLUMN = 4;
051:            private static int STATE_COLUMN = 5;
052:            private static int QUOTE_COLUMN = 6;
053:            private static int NUM_COLUMNS = 7;
054:
055:            class MyTableModel extends DefaultTableModel {
056:                public MyTableModel(Object[] obj, int x) {
057:                    super (obj, x);
058:                }
059:
060:                public Class getColumnClass(int col) {
061:                    if (col == CHECK_COLUMN)
062:                        return (Boolean.class);
063:                    return (super .getColumnClass(col));
064:                }
065:            };
066:
067:            public rfq() {
068:                setLayout(new BorderLayout());
069:
070:                // Do the Registration Server list area
071:                //////////////////////////////////////////////////////////////////////////
072:                JPanel regSelectPanel = new JPanel();
073:                regSelectPanel.setLayout(new BoxLayout(regSelectPanel,
074:                        BoxLayout.X_AXIS));
075:                regSelectPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
076:                regSelectPanel.add(new JLabel("Registration Server: "));
077:                regSelectPanel.add(regServerList = new JComboBox());
078:                regSelectPanel.add(Box.createRigidArea(new Dimension(5, 0)));
079:                regSelectPanel.add(removeButton = new JButton("Remove"));
080:
081:                loadRegList();
082:
083:                regServerList.setEditable(true);
084:                regServerList.addActionListener(new ActionListener() {
085:                    public void actionPerformed(ActionEvent event) {
086:                        String act = event.getActionCommand();
087:                        if (act.equals("comboBoxChanged")) {
088:                            String name = (String) regServerList
089:                                    .getSelectedItem();
090:                            if (name != null && !name.equals("")) {
091:                                chooseRegServer(name);
092:                                addRegistrationServer(name);
093:                            } else
094:                                clearTable();
095:                        }
096:                    };
097:                });
098:
099:                removeButton.setEnabled(true);
100:                removeButton.addActionListener(new ActionListener() {
101:                    public void actionPerformed(ActionEvent event) {
102:                        if ("Remove".equals(event.getActionCommand())) {
103:                            String name = (String) regServerList
104:                                    .getSelectedItem();
105:                            regServerList.removeItem(name);
106:                            saveRegList();
107:                        }
108:                    };
109:                });
110:
111:                add(regSelectPanel, BorderLayout.NORTH);
112:
113:                // Do the List Of Registration Servers Table
114:                //////////////////////////////////////////////////////////////////////////
115:                regListPanel = new JPanel();
116:                regListPanel.setLayout(new BorderLayout());
117:                regServerBorder = new TitledBorder(" Product Servers ");
118:                regListPanel.setBorder(regServerBorder);
119:                regListPanel.add(new JLabel(
120:                        "Select the servers you want to request "
121:                                + "a price from:"), BorderLayout.NORTH);
122:
123:                tableModel = new MyTableModel(new Object[] { "", "Name", "URL",
124:                        "Type", "WSDL", "State", "Quote", "" }, 0);
125:                serverTable = new JTable(0, NUM_COLUMNS);
126:                serverTable.setModel(tableModel);
127:                serverTable
128:                        .setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
129:                TableColumn col = serverTable.getColumnModel().getColumn(
130:                        CHECK_COLUMN);
131:                col.setMaxWidth(10);
132:                // col = serverTable.getColumnModel().getColumn(STATE_COLUMN);
133:                // col.setMaxWidth( col.getPreferredWidth()/2 );
134:                // col = serverTable.getColumnModel().getColumn(QUOTE_COLUMN);
135:                // col.setMaxWidth( col.getPreferredWidth()/2 );
136:                col = serverTable.getColumnModel().getColumn(TYPE_COLUMN);
137:                col.setMaxWidth(col.getPreferredWidth() / 2);
138:
139:                tableModel.addTableModelListener(new TableModelListener() {
140:                    public void tableChanged(TableModelEvent event) {
141:                        int type = event.getType();
142:                        if (type == TableModelEvent.UPDATE
143:                                && event.getColumn() == 0)
144:                            enableButtons();
145:                    };
146:                });
147:
148:                regListPanel.add(new JScrollPane(serverTable),
149:                        BorderLayout.CENTER);
150:
151:                JPanel btns = new JPanel();
152:                // btns.setLayout( new BoxLayout( btns, BoxLayout.X_AXIS ) );
153:                btns.setLayout(new GridBagLayout());
154:
155:                GridBagConstraints c = new GridBagConstraints();
156:
157:                c.anchor = GridBagConstraints.WEST;
158:                c.gridwidth = 1;
159:                c.fill = GridBagConstraints.HORIZONTAL;
160:
161:                // row 1
162:                btns.add(refreshButton = new JButton("Refresh List"), c);
163:                btns.add(Box.createRigidArea(new Dimension(5, 0)), c);
164:                btns.add(selectAllButton = new JButton("Select All"), c);
165:                btns.add(Box.createRigidArea(new Dimension(5, 0)), c);
166:                btns.add(requestButton = new JButton("Request RFQs"), c);
167:                c.weightx = 1.0;
168:                btns.add(Box.createHorizontalGlue(), c);
169:                c.weightx = 0.0;
170:                btns.add(registerButton = new JButton("Register Server"), c);
171:                btns.add(Box.createRigidArea(new Dimension(5, 0)), c);
172:                c.gridwidth = GridBagConstraints.REMAINDER;
173:                btns.add(addServerButton = new JButton("Add Bid Server"), c);
174:
175:                // row 2
176:                c.gridwidth = 1;
177:                c.gridx = 2;
178:                btns.add(deselectAllButton = new JButton("Deselect All"), c);
179:                c.gridx = GridBagConstraints.RELATIVE;
180:                btns.add(Box.createRigidArea(new Dimension(5, 0)), c);
181:                btns.add(pingButton = new JButton("Ping"), c);
182:                c.weightx = 1.0;
183:                btns.add(Box.createRigidArea(new Dimension(5, 0)), c);
184:                c.weightx = 0.0;
185:                btns.add(unregisterServerButton = new JButton(
186:                        "Unregister Server"), c);
187:                btns.add(Box.createRigidArea(new Dimension(5, 0)), c);
188:                // btns.add( Box.createRigidArea(new Dimension(5,0)), c );
189:                c.gridwidth = GridBagConstraints.REMAINDER;
190:                btns.add(removeServerButton = new JButton("Remove Server"), c);
191:
192:                regListPanel.add(btns, BorderLayout.SOUTH);
193:
194:                refreshButton.setEnabled(false);
195:                refreshButton.addActionListener(new ActionListener() {
196:                    public void actionPerformed(ActionEvent event) {
197:                        if ("Refresh List".equals(event.getActionCommand())) {
198:                            refreshList();
199:                        }
200:                    };
201:                });
202:
203:                selectAllButton.setEnabled(false);
204:                selectAllButton.addActionListener(new ActionListener() {
205:                    public void actionPerformed(ActionEvent event) {
206:                        if ("Select All".equals(event.getActionCommand())) {
207:                            for (int i = 0; i < tableModel.getRowCount(); i++) {
208:                                tableModel.setValueAt(new Boolean(true), i,
209:                                        CHECK_COLUMN);
210:                            }
211:                        }
212:                    };
213:                });
214:
215:                deselectAllButton.setEnabled(false);
216:                deselectAllButton.addActionListener(new ActionListener() {
217:                    public void actionPerformed(ActionEvent event) {
218:                        if ("Deselect All".equals(event.getActionCommand())) {
219:                            for (int i = 0; i < tableModel.getRowCount(); i++) {
220:                                tableModel.setValueAt(new Boolean(false), i,
221:                                        CHECK_COLUMN);
222:                            }
223:                        }
224:                    };
225:                });
226:
227:                pingButton.setEnabled(false);
228:                pingButton.addActionListener(new ActionListener() {
229:                    public void actionPerformed(ActionEvent event) {
230:                        if ("Ping".equals(event.getActionCommand())) {
231:                            ping();
232:                        }
233:                    };
234:                });
235:
236:                requestButton.setEnabled(false);
237:                requestButton.addActionListener(new ActionListener() {
238:                    public void actionPerformed(ActionEvent event) {
239:                        if ("Request RFQs".equals(event.getActionCommand())) {
240:                            requestRFQs();
241:                        }
242:                    };
243:                });
244:
245:                registerButton.setEnabled(false);
246:                registerButton.addActionListener(new ActionListener() {
247:                    public void actionPerformed(ActionEvent event) {
248:                        if ("Register Server".equals(event.getActionCommand()))
249:                            registerNewServer();
250:                    };
251:                });
252:
253:                addServerButton.setEnabled(true);
254:                addServerButton.addActionListener(new ActionListener() {
255:                    public void actionPerformed(ActionEvent event) {
256:                        if ("Add Bid Server".equals(event.getActionCommand()))
257:                            promptForServer();
258:                    };
259:                });
260:
261:                removeServerButton.setEnabled(false);
262:                removeServerButton.addActionListener(new ActionListener() {
263:                    public void actionPerformed(ActionEvent event) {
264:                        if ("Remove Server".equals(event.getActionCommand()))
265:                            removeServers();
266:                    };
267:                });
268:
269:                unregisterServerButton.setEnabled(false);
270:                unregisterServerButton.addActionListener(new ActionListener() {
271:                    public void actionPerformed(ActionEvent event) {
272:                        if ("Unregister Server"
273:                                .equals(event.getActionCommand()))
274:                            unregisterServer();
275:                    };
276:                });
277:
278:                // Purchase data
279:                //////////////////////////////////////////////////////////////////////////
280:                GridBagLayout layout = new GridBagLayout();
281:                // GridBagConstraints  c             = new GridBagConstraints();
282:                c = new GridBagConstraints();
283:
284:                purchasePanel = new JPanel(layout);
285:                purchasePanel.setBorder(new TitledBorder("Purchase"));
286:
287:                JButton tSimpleBuy;
288:                JButton tPOBuy;
289:
290:                c.anchor = GridBagConstraints.WEST;
291:                c.gridwidth = GridBagConstraints.REMAINDER;
292:                purchasePanel.add(new JLabel(
293:                        "Select the purchase server from the " + "combo box"),
294:                        c);
295:
296:                c.anchor = GridBagConstraints.EAST;
297:                c.gridwidth = 1;
298:                purchasePanel.add(new JLabel("Server:"), c);
299:
300:                c.anchor = GridBagConstraints.WEST;
301:                c.gridwidth = GridBagConstraints.REMAINDER;
302:                purchasePanel.add(buyList = new JComboBox(), c);
303:
304:                c.gridwidth = 1;
305:                c.anchor = GridBagConstraints.EAST;
306:                purchasePanel.add(new JLabel("Quantity:"), c);
307:
308:                c.anchor = GridBagConstraints.WEST;
309:                c.gridwidth = GridBagConstraints.REMAINDER;
310:                purchasePanel.add(tQuantity = new JTextField(6), c);
311:                tQuantity.setText("1");
312:
313:                c.anchor = GridBagConstraints.EAST;
314:                c.gridwidth = 1;
315:                purchasePanel.add(new JLabel("# Line Items:"), c);
316:
317:                c.anchor = GridBagConstraints.WEST;
318:                c.gridwidth = GridBagConstraints.REMAINDER;
319:                purchasePanel.add(tNumItems = new JComboBox(), c);
320:
321:                c.anchor = GridBagConstraints.WEST;
322:                c.gridwidth = 1;
323:                purchasePanel.add(tSimpleBuy = new JButton("Simple Buy"));
324:
325:                c.anchor = GridBagConstraints.WEST;
326:                c.gridwidth = GridBagConstraints.REMAINDER;
327:                purchasePanel.add(tPOBuy = new JButton("PO Buy"));
328:
329:                for (int j = 1; j < 20; j++)
330:                    tNumItems.addItem("" + j);
331:
332:                tSimpleBuy.addActionListener(new ActionListener() {
333:                    public void actionPerformed(ActionEvent event) {
334:                        if ("Simple Buy".equals(event.getActionCommand())) {
335:                            simpleBuy();
336:                        }
337:                    };
338:                });
339:
340:                tPOBuy.addActionListener(new ActionListener() {
341:                    public void actionPerformed(ActionEvent event) {
342:                        if ("PO Buy".equals(event.getActionCommand())) {
343:                            poBuy();
344:                        }
345:                    };
346:                });
347:
348:                JSplitPane splitPane = new JSplitPane(0, regListPanel,
349:                        new JScrollPane(purchasePanel));
350:                add(splitPane, BorderLayout.CENTER);
351:                setSize(getPreferredSize());
352:                splitPane.setDividerLocation(200);
353:                purchasePanel.setEnabled(false);
354:            }
355:
356:            public void addRegistrationServer(String name) {
357:                int count, i;
358:
359:                if (name == null || "".equals(name))
360:                    return;
361:                count = regServerList.getItemCount();
362:                for (i = 0; i < count; i++)
363:                    if (name.equals(regServerList.getItemAt(i)))
364:                        return;
365:                regServerList.addItem(name);
366:                saveRegList();
367:            }
368:
369:            public void chooseRegServer(String name) {
370:                regServerURL = name;
371:                regServerBorder.setTitle(" Product Servers at ' " + name
372:                        + " ' ");
373:                regListPanel.repaint();
374:                refreshList();
375:            }
376:
377:            public void enableButtons() {
378:                boolean flag;
379:                int i;
380:                int total = tableModel.getRowCount();
381:                int count = 0;
382:                for (i = 0; i < total; i++) {
383:                    flag = ((Boolean) tableModel.getValueAt(i, CHECK_COLUMN))
384:                            .booleanValue();
385:                    if (flag)
386:                        count++;
387:                }
388:                selectAllButton.setEnabled(total > 0 && count != total);
389:                deselectAllButton.setEnabled(total > 0 && count > 0);
390:                pingButton.setEnabled(count > 0);
391:                requestButton.setEnabled(count > 0);
392:                removeServerButton.setEnabled(count > 0);
393:                unregisterServerButton.setEnabled(count > 0);
394:            }
395:
396:            public void clearTable() {
397:                while (tableModel.getRowCount() > 0)
398:                    tableModel.removeRow(0);
399:                enableButtons();
400:            }
401:
402:            public void refreshList() {
403:                clearTable();
404:
405:                Vector services = null;
406:
407:                try {
408:                    services = vv.lookupAsString(regServerURL);
409:                } catch (Exception e) {
410:                    System.err
411:                            .println("---------------------------------------------");
412:                    e.printStackTrace();
413:                    JOptionPane.showMessageDialog(this , e.toString(), "Error",
414:                            JOptionPane.INFORMATION_MESSAGE);
415:                }
416:
417:                for (int i = 0; services != null && i < services.size(); i++) {
418:                    Service s = (Service) services.elementAt(i);
419:                    addServer(s);
420:                }
421:
422:                buyList.removeAllItems();
423:                purchasePanel.setEnabled(false);
424:                refreshButton.setEnabled(true);
425:                registerButton.setEnabled(true);
426:                enableButtons();
427:            }
428:
429:            public void ping() {
430:                Boolean flag;
431:                int i;
432:
433:                for (i = 0; i < tableModel.getRowCount(); i++) {
434:                    flag = (Boolean) tableModel.getValueAt(i, CHECK_COLUMN);
435:                    if (flag.booleanValue()) {
436:                        String url = (String) tableModel.getValueAt(i,
437:                                URL_COLUMN);
438:                        Boolean value = new Boolean(false);
439:
440:                        try {
441:                            value = vv.ping(url);
442:
443:                            tableModel.setValueAt(
444:                                    value.booleanValue() ? "Alive" : "Down", i,
445:                                    STATE_COLUMN);
446:                            serverTable.repaint();
447:                        } catch (Exception e) {
448:                            JOptionPane.showMessageDialog(this , e.toString(),
449:                                    "Error", JOptionPane.INFORMATION_MESSAGE);
450:                        }
451:
452:                    }
453:                }
454:            }
455:
456:            public void unregisterServer() {
457:                Boolean flag;
458:                int i;
459:
460:                for (i = 0; i < tableModel.getRowCount(); i++) {
461:                    flag = (Boolean) tableModel.getValueAt(i, CHECK_COLUMN);
462:                    if (flag.booleanValue()) {
463:                        String name = (String) tableModel.getValueAt(i,
464:                                NAME_COLUMN);
465:                        String regServer = (String) regServerList
466:                                .getSelectedItem();
467:                        Boolean value = new Boolean(false);
468:
469:                        try {
470:                            vv.unregister(regServer, name);
471:                        } catch (Exception e) {
472:                            JOptionPane.showMessageDialog(this , e.toString(),
473:                                    "Error", JOptionPane.INFORMATION_MESSAGE);
474:                        }
475:
476:                    }
477:                }
478:                refreshList();
479:            }
480:
481:            public void requestRFQs() {
482:                Boolean flag;
483:                int i, j;
484:
485:                // buyList.removeAllItems();
486:
487:                for (i = 0; i < tableModel.getRowCount(); i++) {
488:                    flag = (Boolean) tableModel.getValueAt(i, CHECK_COLUMN);
489:                    if (flag.booleanValue()) {
490:                        String url = (String) tableModel.getValueAt(i,
491:                                URL_COLUMN);
492:                        double value = 0.0;
493:
494:                        try {
495:                            value = vv.requestForQuote(url);
496:
497:                            tableModel.setValueAt(new Double(value), i,
498:                                    QUOTE_COLUMN);
499:                            serverTable.repaint();
500:
501:                            String str = (String) tableModel.getValueAt(i,
502:                                    NAME_COLUMN);
503:                            for (j = 0; j < buyList.getItemCount(); j++)
504:                                if (((String) buyList.getItemAt(j)).equals(str))
505:                                    break;
506:                            if (j == buyList.getItemCount())
507:                                buyList.addItem(str);
508:                        } catch (Exception e) {
509:                            JOptionPane.showMessageDialog(this , e.toString(),
510:                                    "Error", JOptionPane.INFORMATION_MESSAGE);
511:                        }
512:
513:                    }
514:                }
515:                // buyList.setSelectedIndex(-1);
516:                purchasePanel.setEnabled(true);
517:            }
518:
519:            public void removeServers() {
520:                Boolean flag;
521:                int i, j;
522:
523:                for (i = tableModel.getRowCount() - 1; i >= 0; i--) {
524:                    flag = (Boolean) tableModel.getValueAt(i, CHECK_COLUMN);
525:                    if (flag.booleanValue())
526:                        tableModel.removeRow(i);
527:                }
528:                enableButtons();
529:            }
530:
531:            public void simpleBuy() {
532:                try {
533:                    String url = null;
534:                    int total = tableModel.getRowCount();
535:                    String name = (String) buyList.getSelectedItem();
536:                    for (int i = 0; i < total; i++) {
537:                        String val = (String) tableModel.getValueAt(i,
538:                                NAME_COLUMN);
539:                        if (val.equals(name)) {
540:                            url = (String) tableModel.getValueAt(i, URL_COLUMN);
541:                            break;
542:                        }
543:                    }
544:                    String address = "123 Main Street, Any Town, USA";
545:                    String product = "soap";
546:                    int quantity = Integer.parseInt((String) tQuantity
547:                            .getText());
548:                    String value = null;
549:
550:                    value = vv.simpleBuy(url, quantity);
551:
552:                    JOptionPane.showMessageDialog(this , value, "Receipt",
553:                            JOptionPane.INFORMATION_MESSAGE);
554:                } catch (Exception e) {
555:                    JOptionPane.showMessageDialog(this , e.toString(), "Error",
556:                            JOptionPane.INFORMATION_MESSAGE);
557:                }
558:            }
559:
560:            public void poBuy() {
561:                try {
562:                    String url = null;
563:                    int total = tableModel.getRowCount();
564:                    String name = (String) buyList.getSelectedItem();
565:                    double price = 0;
566:                    for (int i = 0; i < total; i++) {
567:                        String val = (String) tableModel.getValueAt(i,
568:                                NAME_COLUMN);
569:                        Double dval;
570:                        if (val.equals(name)) {
571:                            url = (String) tableModel.getValueAt(i, URL_COLUMN);
572:                            dval = (Double) tableModel.getValueAt(i,
573:                                    QUOTE_COLUMN);
574:                            price = dval.doubleValue();
575:                            break;
576:                        }
577:                    }
578:                    // String address = (String) tAddress.getText();
579:                    String product = "soap";
580:                    int quantity = Integer.parseInt((String) tQuantity
581:                            .getText());
582:                    int numItems = Integer.parseInt((String) tNumItems
583:                            .getSelectedItem());
584:                    String value = null;
585:
586:                    value = vv.buy(url, quantity, numItems, price);
587:
588:                    JOptionPane.showMessageDialog(this , value, "Receipt",
589:                            JOptionPane.INFORMATION_MESSAGE);
590:                } catch (Exception e) {
591:                    e.printStackTrace();
592:                    JOptionPane.showMessageDialog(this , e.toString(), "Error",
593:                            JOptionPane.INFORMATION_MESSAGE);
594:                }
595:            }
596:
597:            public void registerNewServer() {
598:                Component parent = this ;
599:                while (parent != null && !(parent instanceof  JFrame))
600:                    parent = parent.getParent();
601:                final JDialog j = new JDialog((JFrame) parent,
602:                        "Register Server", true);
603:                Container pane = j.getContentPane();
604:                final JTextField fName = new JTextField(20), fURL = new JTextField(
605:                        20), fType = new JTextField(20), fWsdl = new JTextField(
606:                        20);
607:                JButton regButton, cancelButton;
608:
609:                pane.setLayout(new GridBagLayout());
610:                GridBagConstraints c = new GridBagConstraints();
611:
612:                c.anchor = GridBagConstraints.WEST;
613:                c.gridwidth = 1;
614:                pane.add(new JLabel("Service Name"), c);
615:
616:                c.anchor = GridBagConstraints.WEST;
617:                c.gridwidth = GridBagConstraints.REMAINDER;
618:                pane.add(fName, c);
619:
620:                c.anchor = GridBagConstraints.WEST;
621:                c.gridwidth = 1;
622:                pane.add(new JLabel("Service URL"), c);
623:
624:                c.anchor = GridBagConstraints.WEST;
625:                c.gridwidth = GridBagConstraints.REMAINDER;
626:                pane.add(fURL, c);
627:
628:                c.anchor = GridBagConstraints.WEST;
629:                c.gridwidth = 1;
630:                pane.add(new JLabel("Service Type"), c);
631:
632:                c.anchor = GridBagConstraints.WEST;
633:                c.gridwidth = GridBagConstraints.REMAINDER;
634:                pane.add(fType, c);
635:
636:                c.anchor = GridBagConstraints.WEST;
637:                c.gridwidth = 1;
638:                pane.add(new JLabel("WSDL URL"), c);
639:
640:                c.anchor = GridBagConstraints.WEST;
641:                c.gridwidth = GridBagConstraints.REMAINDER;
642:                pane.add(fWsdl, c);
643:
644:                c.anchor = GridBagConstraints.WEST;
645:                c.gridwidth = 1;
646:                pane.add(regButton = new JButton("Register"), c);
647:
648:                c.anchor = GridBagConstraints.WEST;
649:                c.gridwidth = 1;
650:                pane.add(Box.createHorizontalStrut(3), c);
651:
652:                c.anchor = GridBagConstraints.WEST;
653:                c.gridwidth = 1;
654:                pane.add(cancelButton = new JButton("Cancel"), c);
655:
656:                fType.setText("Bid");
657:
658:                regButton.addActionListener(new ActionListener() {
659:                    public void actionPerformed(ActionEvent event) {
660:                        if ("Register".equals(event.getActionCommand())) {
661:                            Service s = new Service();
662:                            s.setServiceName(fName.getText());
663:                            s.setServiceUrl(fURL.getText());
664:                            s.setServiceType(fType.getText());
665:                            s.setServiceWsdl(fWsdl.getText());
666:                            register(s);
667:                            j.dispose();
668:                        }
669:                    };
670:                });
671:
672:                cancelButton.addActionListener(new ActionListener() {
673:                    public void actionPerformed(ActionEvent event) {
674:                        if ("Cancel".equals(event.getActionCommand())) {
675:                            j.dispose();
676:                        }
677:                    };
678:                });
679:
680:                j.pack();
681:                Point p = new Point(parent.getLocation());
682:                Dimension d = parent.getSize();
683:                p.setLocation((int) (p.getX() + d.getWidth() / 2), (int) (p
684:                        .getY() + d.getHeight() / 2));
685:                d = j.getSize();
686:                j.setLocation((int) (p.getX() - d.getWidth() / 2), (int) (p
687:                        .getY() - d.getHeight() / 2));
688:                j.show();
689:            }
690:
691:            public void promptForServer() {
692:                Component parent = this ;
693:                while (parent != null && !(parent instanceof  JFrame))
694:                    parent = parent.getParent();
695:                final JDialog j = new JDialog((JFrame) parent,
696:                        "Add Bid Server", true);
697:                Container pane = j.getContentPane();
698:                final JTextField fName = new JTextField(20), fURL = new JTextField(
699:                        20), fType = new JTextField(20), fWsdl = new JTextField(
700:                        20);
701:                JButton addButton, cancelButton;
702:
703:                pane.setLayout(new GridBagLayout());
704:                GridBagConstraints c = new GridBagConstraints();
705:
706:                c.anchor = GridBagConstraints.WEST;
707:                c.gridwidth = 1;
708:                pane.add(new JLabel("Service Name"), c);
709:
710:                c.anchor = GridBagConstraints.WEST;
711:                c.gridwidth = GridBagConstraints.REMAINDER;
712:                pane.add(fName, c);
713:
714:                c.anchor = GridBagConstraints.WEST;
715:                c.gridwidth = 1;
716:                pane.add(new JLabel("Service URL"), c);
717:
718:                c.anchor = GridBagConstraints.WEST;
719:                c.gridwidth = GridBagConstraints.REMAINDER;
720:                pane.add(fURL, c);
721:
722:                c.anchor = GridBagConstraints.WEST;
723:                c.gridwidth = 1;
724:                pane.add(new JLabel("Service Type"), c);
725:
726:                c.anchor = GridBagConstraints.WEST;
727:                c.gridwidth = GridBagConstraints.REMAINDER;
728:                pane.add(fType, c);
729:
730:                c.anchor = GridBagConstraints.WEST;
731:                c.gridwidth = 1;
732:                pane.add(new JLabel("WSDL URL"), c);
733:
734:                c.anchor = GridBagConstraints.WEST;
735:                c.gridwidth = GridBagConstraints.REMAINDER;
736:                pane.add(fWsdl, c);
737:
738:                c.anchor = GridBagConstraints.WEST;
739:                c.gridwidth = 1;
740:                pane.add(addButton = new JButton("Add"), c);
741:
742:                c.anchor = GridBagConstraints.WEST;
743:                c.gridwidth = 1;
744:                pane.add(Box.createHorizontalStrut(3), c);
745:
746:                c.anchor = GridBagConstraints.WEST;
747:                c.gridwidth = 1;
748:                pane.add(cancelButton = new JButton("Cancel"), c);
749:
750:                fType.setText("Bid");
751:
752:                addButton.addActionListener(new ActionListener() {
753:                    public void actionPerformed(ActionEvent event) {
754:                        if ("Add".equals(event.getActionCommand())) {
755:                            Service s = new Service();
756:                            s.setServiceName(fName.getText());
757:                            s.setServiceUrl(fURL.getText());
758:                            s.setServiceType(fType.getText());
759:                            s.setServiceWsdl(fWsdl.getText());
760:                            addServer(s);
761:                            j.dispose();
762:                        }
763:                    };
764:                });
765:
766:                cancelButton.addActionListener(new ActionListener() {
767:                    public void actionPerformed(ActionEvent event) {
768:                        if ("Cancel".equals(event.getActionCommand())) {
769:                            j.dispose();
770:                        }
771:                    };
772:                });
773:
774:                j.pack();
775:                Point p = new Point(parent.getLocation());
776:                Dimension d = parent.getSize();
777:                p.setLocation((int) (p.getX() + d.getWidth() / 2), (int) (p
778:                        .getY() + d.getHeight() / 2));
779:                d = j.getSize();
780:                j.setLocation((int) (p.getX() - d.getWidth() / 2), (int) (p
781:                        .getY() - d.getHeight() / 2));
782:                j.show();
783:            }
784:
785:            public void addServer(Service s) {
786:                Object[] objs = new Object[NUM_COLUMNS];
787:                objs[0] = new Boolean(false);
788:                objs[1] = s.getServiceName();
789:                objs[2] = s.getServiceUrl();
790:                objs[3] = s.getServiceType();
791:                objs[4] = s.getServiceWsdl();
792:                objs[5] = null;
793:                objs[6] = null;
794:
795:                tableModel.addRow(objs);
796:            }
797:
798:            public void register(Service s) {
799:                try {
800:                    vv.register((String) regServerList.getSelectedItem(), s);
801:                    refreshList();
802:                } catch (Exception e) {
803:                    JOptionPane.showMessageDialog(this , e.toString(), "Error",
804:                            JOptionPane.INFORMATION_MESSAGE);
805:                }
806:            }
807:
808:            public void loadRegList() {
809:                try {
810:                    FileReader fr = new FileReader("reg.lst");
811:                    LineNumberReader lnr = new LineNumberReader(fr);
812:                    String line = null;
813:
814:                    while ((line = lnr.readLine()) != null)
815:                        addRegistrationServer(line);
816:                    fr.close();
817:                } catch (Exception e) {
818:                    e.printStackTrace();
819:                }
820:            }
821:
822:            public void saveRegList() {
823:                try {
824:                    FileOutputStream fos = new FileOutputStream("reg.lst");
825:                    PrintWriter pw = new PrintWriter(fos);
826:                    int count = regServerList.getItemCount();
827:                    int i;
828:
829:                    for (i = 0; i < count; i++)
830:                        pw.println((String) regServerList.getItemAt(i));
831:                    pw.close();
832:
833:                    fos.close();
834:                } catch (Exception e) {
835:                    e.printStackTrace();
836:                }
837:            }
838:
839:            public static void main(String[] args) {
840:                try {
841:                    UIManager.setLookAndFeel(UIManager
842:                            .getSystemLookAndFeelClassName());
843:                    JFrame window = new JFrame("Request For Quote Client") {
844:                        protected void processWindowEvent(WindowEvent event) {
845:                            switch (event.getID()) {
846:                            case WindowEvent.WINDOW_CLOSING:
847:                                exit();
848:                                break;
849:                            default:
850:                                super .processWindowEvent(event);
851:                                break;
852:                            }
853:                        }
854:
855:                        private void exit() {
856:                            System.exit(0);
857:                        }
858:                    };
859:
860:                    window.getContentPane().add(new rfq());
861:                    window.pack();
862:                    window.setSize(new Dimension(800, 500));
863:                    window.setVisible(true);
864:                } catch (Throwable exp) {
865:                    exp.printStackTrace();
866:                }
867:            }
868:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.