Source Code Cross Referenced for InventoryUIFrame.java in  » Science » Cougaar12_4 » org » cougaar » logistics » ui » inventory » 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 » Science » Cougaar12_4 » org.cougaar.logistics.ui.inventory 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <Copyright>
003:         *  
004:         *  Copyright 1997-2004 BBNT Solutions, LLC
005:         *  under sponsorship of the Defense Advanced Research Projects
006:         *  Agency (DARPA).
007:         * 
008:         *  You can redistribute this software and/or modify it under the
009:         *  terms of the Cougaar Open Source License as published on the
010:         *  Cougaar Open Source Website (www.cougaar.org).
011:         * 
012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023:         *  
024:         * </copyright>
025:         */
026:
027:        package org.cougaar.logistics.ui.inventory;
028:
029:        import java.util.*;
030:
031:        import javax.swing.*;
032:        import javax.swing.event.MouseInputAdapter;
033:
034:        import java.awt.Container;
035:        import java.awt.BorderLayout;
036:        import java.awt.Dimension;
037:        import java.awt.Toolkit;
038:        import java.awt.FlowLayout;
039:        import java.awt.Cursor;
040:        import java.awt.Component;
041:        import java.awt.event.*;
042:
043:        import java.io.File;
044:        import java.io.FileWriter;
045:        import java.io.FileReader;
046:        import java.io.BufferedReader;
047:        import java.io.IOException;
048:        import java.io.StringWriter;
049:
050:        import org.cougaar.util.log.Logging;
051:        import org.cougaar.util.log.Logger;
052:
053:        import org.cougaar.logistics.ui.inventory.data.InventoryData;
054:        import org.cougaar.logistics.ui.inventory.data.InventoryPreferenceData;
055:        import org.cougaar.logistics.ui.inventory.data.BlankInventoryData;
056:        import org.cougaar.logistics.ui.inventory.dialog.InventoryPreferenceDialog;
057:
058:        /**
059:         * <pre>
060:         *
061:         * The InventoryUIFrame is the root object that maintains the primary
062:         * window where the inventory charts are displayed.
063:         *
064:         * @see InventoryConnectionManager
065:         * @see InventoryDataSource
066:         * @see MultiChartPanel
067:         * @see InventoryDemandChart
068:         * @see InventoryRefillChart
069:         * @see InventoryLevelChart
070:         *
071:         **/
072:
073:        public class InventoryUIFrame extends JFrame implements  ActionListener,
074:                ItemListener, InventorySelectionListener {
075:
076:            static final Cursor waitCursor = Cursor
077:                    .getPredefinedCursor(Cursor.WAIT_CURSOR);
078:            static final Cursor defaultCursor = Cursor
079:                    .getPredefinedCursor(Cursor.DEFAULT_CURSOR);
080:
081:            public static final String SHOW_INIT_SHORTFALL = "SHOW_INIT_SHORTFALL";
082:            public static final String SHOW_INIT_CDAY = "SHOW_INIT_CDAY";
083:
084:            public static final String INVENTORY_PREF_FILE_NAME = "InventoryPreferences.txt";
085:
086:            protected InventoryDataSource dataSource;
087:            protected Container contentPane;
088:
089:            protected JTextArea editPane;
090:            protected JFileChooser fileChooser;
091:
092:            protected JCheckBoxMenuItem showInventoryChart;
093:            protected JCheckBoxMenuItem showDemandChart;
094:            protected JCheckBoxMenuItem showRefillChart;
095:
096:            protected MultiChartPanel multiChart;
097:            protected InventoryData inventory;
098:
099:            protected Logger logger;
100:
101:            protected String cip;
102:            protected String defaultSaveCSVPath;
103:            protected String defaultOpenCSVPath;
104:            protected String defaultPrefsPath;
105:            protected String helpFileStr;
106:
107:            protected InventorySelectionPanel selector;
108:            protected InventoryXMLParser parser;
109:
110:            protected InventoryPreferenceData prefData;
111:            protected InventoryPreferenceDialog prefDialog = null;
112:
113:            protected boolean showInitialShortfall = true;
114:            protected boolean initialDisplayCDay = true;
115:
116:            public InventoryUIFrame(HashMap params) {
117:                super ("Inventory GUI");
118:                initializeUIFrame(params);
119:            }
120:
121:            public InventoryUIFrame() {
122:                super ("Inventory GUI");
123:                initializeUIFrame(new HashMap());
124:            }
125:
126:            public InventoryUIFrame(String frameTitle) {
127:                super (frameTitle);
128:                initializeUIFrame(new HashMap());
129:            }
130:
131:            public InventoryUIFrame(String[] args) {
132:                super ("Inventory GUI");
133:                initializeUIFrame(readParameters(args));
134:            }
135:
136:            public InventoryUIFrame(String[] args, String frameTitle) {
137:                super (frameTitle);
138:                //initializeUIFrame(readParameters(args));
139:            }
140:
141:            protected void initializeUIFrame(HashMap params) {
142:                addWindowListener(new WindowAdapter() {
143:                    public void windowClosing(WindowEvent e) {
144:                        System.exit(0);
145:                    }
146:                });
147:
148:                logger = Logging.getLogger(this );
149:                parser = new InventoryXMLParser();
150:
151:                readParameters(params);
152:
153:                contentPane = getRootPane().getContentPane();
154:
155:                cip = System.getProperty("org.cougaar.install.path");
156:
157:                if ((cip == null) || (cip.trim().equals(""))) {
158:                    logger
159:                            .error("org.cougaar.install.path is not defined in Command line");
160:                } else {
161:                    helpFileStr = cip + File.separator + "albbn"
162:                            + File.separator + "doc" + File.separator
163:                            + "alinvgui" + File.separator + "index.htm";
164:                }
165:
166:                String baseDir = System.getProperty("org.cougaar.workspace");
167:                if ((baseDir == null) || (baseDir.trim().equals(""))) {
168:                    baseDir = cip + File.separator + "workspace";
169:                }
170:                defaultOpenCSVPath = baseDir + File.separator + "INVGUICSV";
171:                defaultPrefsPath = baseDir + File.separator + "INVGUIPREFS";
172:                defaultSaveCSVPath = defaultOpenCSVPath + File.separator
173:                        + formatTimeStamp(new Date(), false) + File.separator;
174:                File pathDirs = new File(defaultOpenCSVPath);
175:
176:                fileChooser = new JFileChooser(pathDirs);
177:
178:                String invDataPath = cip + File.separator + "data"
179:                        + File.separator + "ui" + File.separator + "inventory"
180:                        + File.separator;
181:
182:                InventoryUnitConversionTable conversionTable = new InventoryUnitConversionTable();
183:                conversionTable.parseAndAddFile(invDataPath
184:                        + "ammo-conversion.csv");
185:                InventoryChart.setConversionTable(conversionTable);
186:
187:                //Setup prefs and pref dialog
188:                prefData = openPrefData();
189:
190:                // fills frame
191:                doMyLayout();
192:                dataSource = null;
193:                pack();
194:                setSize(800, 600);
195:                Dimension screenSize = Toolkit.getDefaultToolkit()
196:                        .getScreenSize();
197:                // set location to middle of the screen
198:                setLocation(screenSize.width / 2
199:                        - (int) this .getSize().getWidth() / 2,
200:                        screenSize.height / 2
201:                                - (int) this .getSize().getHeight() / 2);
202:                setVisible(true);
203:            }
204:
205:            protected void doMyLayout() {
206:                getRootPane().setJMenuBar(makeMenus());
207:
208:                JTabbedPane tabs = new JTabbedPane();
209:
210:                contentPane.add(tabs, BorderLayout.CENTER);
211:
212:                JPanel editPanel = new JPanel();
213:                editPanel.setLayout(new BorderLayout());
214:
215:                //Create a text area.
216:                editPane = new JTextArea();
217:                editPane.setLineWrap(true);
218:                editPane.setWrapStyleWord(true);
219:                JScrollPane areaScrollPane = new JScrollPane(editPane);
220:                areaScrollPane
221:                        .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
222:                areaScrollPane.setPreferredSize(new Dimension(700, 500));
223:                areaScrollPane.setBorder(BorderFactory.createCompoundBorder(
224:                        BorderFactory.createCompoundBorder(BorderFactory
225:                                .createTitledBorder("XML"), BorderFactory
226:                                .createEmptyBorder(5, 5, 5, 5)), areaScrollPane
227:                                .getBorder()));
228:
229:                JButton parseButton = new JButton("Parse");
230:                JButton dataButton = new JButton("Data");
231:                parseButton.addActionListener(this );
232:                dataButton.addActionListener(this );
233:
234:                JPanel buttonPanel = new JPanel();
235:                buttonPanel.setLayout(new FlowLayout());
236:                buttonPanel.add(dataButton);
237:                buttonPanel.add(Box.createHorizontalStrut(60));
238:                buttonPanel.add(parseButton);
239:
240:                editPanel.add(buttonPanel, BorderLayout.NORTH);
241:                editPanel.add(areaScrollPane, BorderLayout.CENTER);
242:
243:                multiChart = new MultiChartPanel(showInitialShortfall,
244:                        initialDisplayCDay, prefData);
245:                multiChart.setPreferredSize(new Dimension(700, 250));
246:
247:                prefDataChanged(new InventoryPreferenceData(), prefData);
248:
249:                tabs.add("InventoryChart", multiChart);
250:                tabs.add("XML", editPanel);
251:
252:                selector = new InventorySelectionPanel(this );
253:                selector.addInventorySelectionListener(this );
254:
255:                contentPane.add(selector, BorderLayout.SOUTH);
256:            }
257:
258:            public void setMultiChart(MultiChartPanel mcp) {
259:                multiChart = mcp;
260:            }
261:
262:            public void setParser(InventoryXMLParser myParser) {
263:                parser = myParser;
264:            }
265:
266:            protected JMenuBar makeMenus() {
267:                JMenuBar retval = new JMenuBar();
268:
269:                JMenu file = new JMenu("File");
270:                JMenuItem quit = new JMenuItem(InventoryMenuEvent.MENU_Exit);
271:                JMenuItem save = new JMenuItem(InventoryMenuEvent.MENU_SaveXML);
272:                JMenuItem open = new JMenuItem(InventoryMenuEvent.MENU_OpenXML);
273:                quit.addActionListener(this );
274:                save.addActionListener(this );
275:                open.addActionListener(this );
276:                file.add(open);
277:                file.add(save);
278:                file.add(quit);
279:                retval.add(file);
280:
281:                JMenu edit = new JMenu("Edit");
282:                JMenuItem pref = new JMenuItem(InventoryMenuEvent.MENU_Pref);
283:                pref.addActionListener(this );
284:                edit.add(pref);
285:                retval.add(edit);
286:
287:                JMenu connection = new JMenu("Connection");
288:                JMenuItem connect = new JMenuItem(
289:                        InventoryMenuEvent.MENU_Connect);
290:                connect.addActionListener(this );
291:                connection.add(connect);
292:                retval.add(connection);
293:
294:                JMenu view = new JMenu("View");
295:                showRefillChart = new JCheckBoxMenuItem(
296:                        InventoryMenuEvent.MENU_RefillChart, true);
297:                showDemandChart = new JCheckBoxMenuItem(
298:                        InventoryMenuEvent.MENU_DemandChart, true);
299:                showInventoryChart = new JCheckBoxMenuItem(
300:                        InventoryMenuEvent.MENU_InventoryChart, true);
301:                showDemandChart.addItemListener(this );
302:                showRefillChart.addItemListener(this );
303:                showInventoryChart.addItemListener(this );
304:                view.add(showInventoryChart);
305:                view.add(showRefillChart);
306:                view.add(showDemandChart);
307:                retval.add(view);
308:
309:                JMenu helpMenu = new JMenu("Help");
310:                JMenuItem helpItem = new JMenuItem(InventoryMenuEvent.MENU_Help);
311:                helpItem.addActionListener(this );
312:                helpMenu.add(helpItem);
313:                //Help popup is not done yet.
314:                //retval.add(helpMenu);
315:
316:                return retval;
317:            }
318:
319:            public void itemStateChanged(ItemEvent e) {
320:                if (((JCheckBoxMenuItem) e.getItem()) == showRefillChart) {
321:                    multiChart
322:                            .showRefillChart(e.getStateChange() == e.SELECTED);
323:                } else if (((JCheckBoxMenuItem) e.getItem()).getText().equals(
324:                        InventoryMenuEvent.MENU_DemandChart)) {
325:                    multiChart
326:                            .showDemandChart(e.getStateChange() == e.SELECTED);
327:                } else if (((JCheckBoxMenuItem) e.getItem()) == showInventoryChart) {
328:                    multiChart
329:                            .showInventoryChart(e.getStateChange() == e.SELECTED);
330:                }
331:
332:            }
333:
334:            public void actionPerformed(ActionEvent e) {
335:                if (e.getActionCommand().equals(InventoryMenuEvent.MENU_Exit)) {
336:                    System.exit(0);
337:                } else if (e.getActionCommand().equals(
338:                        InventoryMenuEvent.MENU_Connect)) {
339:                    connectToServlet();
340:                } else if (e.getActionCommand().equals(
341:                        InventoryMenuEvent.MENU_SaveXML)) {
342:                    saveXML();
343:                } else if (e.getActionCommand().equals(
344:                        InventoryMenuEvent.MENU_OpenXML)) {
345:                    openXML();
346:                } else if (e.getActionCommand().equals(
347:                        InventoryMenuEvent.MENU_Help)) {
348:                    popupHelpPage();
349:                } else if (e.getActionCommand().equals(
350:                        InventoryMenuEvent.MENU_Pref)) {
351:                    popupPrefsDialog();
352:                } else if (e.getActionCommand().equals("Parse")) {
353:                    logger.info("Parsing");
354:                    inventory = parser.parseString(dataSource
355:                            .getCurrentInventoryData());
356:                    multiChart.setData(inventory);
357:                } else if (e.getActionCommand().equals("Data")) {
358:                    editPane.setText(dataSource.getCurrentInventoryData());
359:                }
360:            }
361:
362:            protected void popupHelpPage() {
363:
364:            }
365:
366:            protected void popupPrefsDialog() {
367:                if (prefDialog == null) {
368:                    prefDialog = new InventoryPreferenceDialog(this , prefData);
369:                }
370:                prefDialog.setVisible(true);
371:                //    System.out.println("About to exit popupPrefsDialog");
372:            }
373:
374:            public void prefDataChanged(InventoryPreferenceData origData,
375:                    InventoryPreferenceData newData) {
376:                if (origData.startupWCDay != newData.startupWCDay) {
377:                    initialDisplayCDay = newData.startupWCDay;
378:                }
379:                if (origData.displayShortfall != newData.displayShortfall) {
380:                    showInitialShortfall = newData.displayShortfall;
381:                }
382:                if ((origData.showInventoryChart != newData.showInventoryChart)
383:                        || (origData.showDemandChart != newData.showDemandChart)
384:                        || (origData.showRefillChart != newData.showRefillChart)) {
385:                    showDemandChart.setState(newData.showDemandChart);
386:                    showInventoryChart.setState(newData.showInventoryChart);
387:                    showRefillChart.setState(newData.showRefillChart);
388:                }
389:
390:                multiChart.prefDataChanged(origData, newData);
391:
392:                prefData = newData;
393:            }
394:
395:            protected void saveXML() {
396:                File pathDirs = new File(defaultSaveCSVPath);
397:                try {
398:                    if (!pathDirs.exists()) {
399:                        pathDirs.mkdirs();
400:                    }
401:                } catch (Exception ex) {
402:                    logger.error("Error creating default directory "
403:                            + defaultSaveCSVPath, ex);
404:                }
405:                if (inventory != null) {
406:                    String fileID = defaultSaveCSVPath
407:                            + inventory.getOrg()
408:                            + "-"
409:                            + (inventory.getItem().replaceAll("/", "-"))
410:                                    .replaceAll(":", "-") + "-"
411:                            + formatTimeStamp(new Date(), false) + ".csv";
412:                    System.out.println("Save to file: " + fileID);
413:                    fileChooser.setSelectedFile(new File(fileID));
414:                }
415:                int retval = fileChooser.showSaveDialog(this );
416:                if (retval == fileChooser.APPROVE_OPTION) {
417:                    File saveFile = fileChooser.getSelectedFile();
418:                    try {
419:                        FileWriter fw = new FileWriter(saveFile);
420:                        fw.write(inventory.getXML());
421:                        fw.flush();
422:                        fw.close();
423:                    } catch (IOException ioe) {
424:                        throw new RuntimeException(ioe);
425:                    }
426:                }
427:            }
428:
429:            public void savePrefData(InventoryPreferenceData savePrefData) {
430:                File pathDirs = new File(defaultPrefsPath);
431:                try {
432:                    if (!pathDirs.exists()) {
433:                        pathDirs.mkdirs();
434:                    }
435:                } catch (Exception ex) {
436:                    logger.error("Error creating default directory "
437:                            + defaultOpenCSVPath, ex);
438:                    displayErrorString("Could not write prefs file! Could not create default directory.");
439:                }
440:
441:                File saveFile = new File(defaultPrefsPath + File.separator
442:                        + INVENTORY_PREF_FILE_NAME);
443:                try {
444:                    FileWriter fw = new FileWriter(saveFile);
445:                    fw.write(savePrefData.toXMLString());
446:                    fw.flush();
447:                    fw.close();
448:                } catch (IOException ioe) {
449:                    throw new RuntimeException(ioe);
450:                }
451:            }
452:
453:            protected InventoryPreferenceData openPrefData() {
454:                File prefFile = new File(defaultPrefsPath + File.separator
455:                        + INVENTORY_PREF_FILE_NAME);
456:                if (!prefFile.exists()) {
457:                    return new InventoryPreferenceData();
458:                }
459:                String prefXML = "";
460:                try {
461:                    BufferedReader br = new BufferedReader(new FileReader(
462:                            prefFile));
463:
464:                    String nextLine = br.readLine();
465:                    while (nextLine != null) {
466:                        prefXML = prefXML + nextLine + "\n";
467:                        nextLine = br.readLine();
468:                    }
469:                    br.close();
470:                } catch (IOException ioe) {
471:                    throw new RuntimeException(ioe);
472:                }
473:                InventoryPreferenceData savedPrefs = new InventoryPreferenceData();
474:                try {
475:                    savedPrefs.parseValuesFromXMLString(prefXML);
476:                } catch (Exception e) {
477:                    logger.error("Error parsing " + prefFile + "!", e);
478:                    return new InventoryPreferenceData();
479:                }
480:                return savedPrefs;
481:            }
482:
483:            protected void openXML() {
484:                /**
485:                 if(inventory != null) {
486:                 String fileID = defaultOpenCSVPath;
487:                 System.out.println("Open file at path: " + fileID);
488:                 fileChooser.setSelectedFile(new File(fileID));
489:                 }
490:                 */
491:                fileChooser.setMultiSelectionEnabled(true);
492:                int retval = fileChooser.showOpenDialog(this );
493:                if (retval == fileChooser.APPROVE_OPTION) {
494:                    File[] openFiles = fileChooser.getSelectedFiles();
495:                    timeConsumingTaskStart(this );
496:                    try {
497:                        Thread openXMLThread = new Thread(new OpenXMLRunnable(
498:                                openFiles));
499:                        openXMLThread.start();
500:                    } catch (Exception e) {
501:                        e.printStackTrace();
502:                    }
503:                }
504:            }
505:
506:            public void doOpenXML(File[] openFiles) {
507:                InventoryFileManager fm = null;
508:                String invXML = "";
509:
510:                try {
511:                    SwingUtilities.invokeAndWait(new TaskStartRunnable(this ));
512:                } catch (Exception e) {
513:                    e.printStackTrace();
514:                }
515:
516:                if (openFiles.length > 0) {
517:                    if (dataSource instanceof  InventoryFileManager) {
518:                        fm = (InventoryFileManager) dataSource;
519:                    } else {
520:                        fm = new InventoryFileManager(this );
521:                        dataSource = fm;
522:                    }
523:                }
524:                String lastGoodXML = null;
525:                for (int i = 0; i < openFiles.length; i++) {
526:                    File openFile = openFiles[i];
527:                    StringWriter writer = new StringWriter(
528:                            InventoryConnectionManager.INITIAL_XML_SIZE);
529:                    invXML = "";
530:                    try {
531:                        BufferedReader br = new BufferedReader(new FileReader(
532:                                openFile));
533:
534:                        String nextLine = br.readLine();
535:                        while (nextLine != null) {
536:                            if (!nextLine.trim().equals("")) {
537:                                writer.write(nextLine + "\n");
538:                            }
539:                            nextLine = br.readLine();
540:
541:                        }
542:                        br.close();
543:                        writer.flush();
544:                        invXML = writer.toString();
545:                    } catch (IOException ioe) {
546:                        throw new RuntimeException(ioe);
547:                    }
548:
549:                    if (invXML.trim().equals("")) {
550:                        displayErrorString("Empty File!", "File "
551:                                + openFile.getName() + " has no contents!");
552:                        if (lastGoodXML != null) {
553:                            invXML = lastGoodXML;
554:                            inventory = parser.parseString(invXML);
555:                        } else {
556:                            inventory = null;
557:                        }
558:                    } else {
559:                        inventory = parser.parseString(invXML);
560:                        fm.addItem(inventory, invXML);
561:                        lastGoodXML = invXML;
562:                    }
563:                }
564:                try {
565:                    SwingUtilities.invokeAndWait(new FlushXMLToScreenRunnable(
566:                            invXML, openFiles, fm));
567:                } catch (Exception e) {
568:                    e.printStackTrace();
569:                }
570:                fileChooser.setMultiSelectionEnabled(false);
571:            }
572:
573:            public void flushXMLToScreen(String invXML, File[] openFiles,
574:                    InventoryFileManager fm) {
575:                if ((openFiles.length > 0) && (inventory != null)) {
576:                    editPane.setText(invXML);
577:                    Vector orgs = dataSource.getOrgNames(".", selector
578:                            .getSelectedOrgPopMethod());
579:                    String[] fileType = dataSource.getSupplyTypes();
580:                    selector.initializeComboBoxes(orgs, fileType);
581:                    Vector assetNames = dataSource.getAssetNames(inventory
582:                            .getOrg(), fileType[0]);
583:                    selector.setAssetNames(assetNames);
584:                    selector.setSelectedOrgAsset(inventory.getOrg(), fm
585:                            .getFullItemName(inventory));
586:                    multiChart.setData(inventory);
587:                }
588:                timeConsumingTaskEnd(this );
589:            }
590:
591:            protected void readParameters(HashMap map) {
592:                String showShortfall = (String) map.get(SHOW_INIT_SHORTFALL);
593:                if ((showShortfall != null)
594:                        && (!showShortfall.trim().equals(""))) {
595:                    showInitialShortfall = (!(showShortfall.trim()
596:                            .toLowerCase().equals("false")));
597:                }
598:                String displayCDay = (String) map.get(SHOW_INIT_CDAY);
599:                if ((displayCDay != null) && (!displayCDay.trim().equals(""))) {
600:                    initialDisplayCDay = (displayCDay.trim().toLowerCase()
601:                            .equals("true"));
602:                }
603:            }
604:
605:            public static HashMap readParameters(String[] args) {
606:                HashMap params = new HashMap();
607:                for (int i = 0; i < args.length; i++) {
608:                    String[] keyAndValue = args[i].split("[=]");
609:                    String key = keyAndValue[0];
610:                    String value = keyAndValue[1];
611:                    params.put(key, value);
612:                }
613:                return params;
614:            }
615:
616:            public static void timeConsumingTaskStart(Component c) {
617:                JFrame frame = null;
618:                if (c != null)
619:                    frame = (JFrame) SwingUtilities.getRoot(c);
620:                if (frame == null)
621:                    return;
622:                timeConsumingTaskStart(frame);
623:            }
624:
625:            public static void timeConsumingTaskStart(JFrame frame) {
626:                Component glass = frame.getGlassPane();
627:                glass.setCursor(waitCursor);
628:                glass.addMouseListener(new DoNothingMouseListener());
629:                glass.setVisible(true);
630:            }
631:
632:            public static void timeConsumingTaskEnd(Component c) {
633:                JFrame frame = null;
634:                if (c != null)
635:                    frame = (JFrame) SwingUtilities.getRoot(c);
636:                if (frame == null)
637:                    return;
638:                timeConsumingTaskEnd(frame);
639:            }
640:
641:            public static void timeConsumingTaskEnd(JFrame frame) {
642:                Component glass = frame.getGlassPane();
643:                MouseListener[] mls = (MouseListener[]) glass
644:                        .getListeners(MouseListener.class);
645:                for (int i = 0; i < mls.length; i++)
646:                    if (mls[i] instanceof  DoNothingMouseListener)
647:                        glass.removeMouseListener(mls[i]);
648:                glass.setCursor(defaultCursor);
649:                glass.setVisible(false);
650:            }
651:
652:            protected void connectToServlet() {
653:                dataSource = InventoryConnectionManager.queryUserForConnection(
654:                        this , dataSource);
655:                if (dataSource == null) {
656:                    displayErrorString("Was unable to connect to servlet.");
657:                    return;
658:                }
659:                Vector orgs = dataSource.getOrgNames(".", selector
660:                        .getSelectedOrgPopMethod());
661:                if (orgs == null) {
662:                    displayErrorString("Error. Was unable to retrieve orgs.");
663:                } else {
664:                    String[] supplyTypes = dataSource.getSupplyTypes();
665:                    selector.initializeComboBoxes(orgs, supplyTypes);
666:                }
667:            }
668:
669:            protected static void displayErrorString(String reply) {
670:                displayErrorString(reply, reply);
671:            }
672:
673:            protected static void displayErrorString(String title, String reply) {
674:                JOptionPane.showMessageDialog(null, reply, title,
675:                        JOptionPane.ERROR_MESSAGE);
676:            }
677:
678:            protected static void displayWarnString(String title, String reply) {
679:                JOptionPane.showMessageDialog(null, reply, title,
680:                        JOptionPane.WARNING_MESSAGE);
681:            }
682:
683:            public void selectionChanged(InventorySelectionEvent e) {
684:                Vector assetNames = null;
685:                Vector newOrgs;
686:                if (e.getID() == InventorySelectionEvent.ORG_SELECT) {
687:                    if (e.getOrg() == null) {
688:                        newOrgs = dataSource.getOrgNames(".", e
689:                                .getOrgPopMethod());
690:                    } else {
691:                        newOrgs = dataSource.getOrgNames(e.getOrg(), e
692:                                .getOrgPopMethod());
693:                    }
694:                    if (newOrgs != null) {
695:                        selector.reinitializeOrgBox(newOrgs);
696:                    } else {
697:                        System.out
698:                                .println("InventoryUIFrame: newOrgs is null.");
699:                    }
700:                    if ((e.getOrg() != null) && !(e.getOrg().startsWith("."))) {
701:                        assetNames = dataSource.getAssetNames(e.getOrg(), e
702:                                .getSupplyType());
703:                    }
704:                    if (assetNames == null) {
705:                        assetNames = new Vector();
706:                    }
707:                    selector.setAssetNames(assetNames);
708:
709:                } else if (e.getID() == InventorySelectionEvent.ORG_POP_SELECT) {
710:
711:                    if (dataSource == null) {
712:                        connectToServlet();
713:                    }
714:
715:                    newOrgs = dataSource.getOrgNames(e.getOrg(), e
716:                            .getOrgPopMethod());
717:                    if (newOrgs != null) {
718:                        selector.reinitializeOrgBox(newOrgs);
719:                    }
720:                    /*** MWD remove - badly place functionality
721:                    if(!(selector.getSelectedOrg().equals(e.getOrg()))) {
722:                      if(!(e.getOrg().startsWith("."))) {
723:                        assetNames = dataSource.getAssetNames(e.getSelectedOrg(),
724:                    					  e.getSupplyType());
725:                      }
726:                      if(assetNames == null) {
727:                        assetNames = new Vector();
728:                      }
729:                      selector.setAssetNames(assetNames);
730:                    }
731:                     ***/
732:                } else if (e.getID() == InventorySelectionEvent.INVENTORY_SELECT) {
733:                    String invXML = null;
734:                    if ((e.getOrg().trim().equals(""))
735:                            || (e.getOrg().trim().startsWith("."))) {
736:                        displayErrorString("Submit",
737:                                "Not a legal org to submit for inventory asset");
738:
739:                    }
740:
741:                    else if ((e.getAssetName() == null)
742:                            || (e.getAssetName().trim().equals(""))) {
743:                        displayErrorString("Submit", "No Asset Picked!");
744:
745:                    } else {
746:
747:                        invXML = dataSource.getInventoryData(e.getOrg(), e
748:                                .getAssetName());
749:                    }
750:
751:                    if ((invXML != null) && (!(invXML.trim().equals("")))) {
752:                        editPane.setText(invXML);
753:                        inventory = parser.parseString(invXML);
754:                        multiChart.setData(inventory);
755:                    } else {
756:                        inventory = new BlankInventoryData(e.getOrg(), e
757:                                .getAssetName());
758:                        editPane.setText("Null XML");
759:                        multiChart.setData(inventory);
760:                    }
761:                }
762:            }
763:
764:            public static String formatTimeStamp(Date dateToFormat,
765:                    boolean includeSeconds) {
766:
767:                String datestamp;
768:                TimeZone gmt = TimeZone.getDefault();
769:                GregorianCalendar now = new GregorianCalendar(gmt);
770:                now.setTime(dateToFormat);
771:                datestamp = "" + now.get(Calendar.YEAR);
772:                datestamp += prependSingle(now.get(Calendar.MONTH) + 1);
773:                datestamp += prependSingle(now.get(Calendar.DAY_OF_MONTH));
774:                datestamp += prependSingle(now.get(Calendar.HOUR_OF_DAY));
775:                datestamp += prependSingle(now.get(Calendar.MINUTE));
776:                if (includeSeconds) {
777:                    datestamp += prependSingle(now.get(Calendar.SECOND));
778:                }
779:                return datestamp;
780:            }
781:
782:            protected static String prependSingle(int digit) {
783:                if (digit < 10) {
784:                    return "0" + digit;
785:                } else {
786:                    return "" + digit;
787:                }
788:            }
789:
790:            protected class HelpDialog extends JDialog {
791:
792:                protected String helpFileURLStr;
793:
794:                public HelpDialog(JFrame owner, String aHelpFileURLStr) {
795:                    super (owner, "Inventory GUI Help", false);
796:                    helpFileURLStr = aHelpFileURLStr;
797:                    setupAndLayout();
798:                }
799:
800:                protected void setupAndLayout() {
801:
802:                }
803:
804:            }
805:
806:            protected class OpenXMLRunnable implements  Runnable {
807:
808:                protected File[] openFiles;
809:
810:                public OpenXMLRunnable(File[] filesToOpen) {
811:                    openFiles = filesToOpen;
812:                }
813:
814:                public void run() {
815:                    doOpenXML(openFiles);
816:                }
817:            }
818:
819:            protected class TaskStartRunnable implements  Runnable {
820:
821:                InventoryUIFrame frame;
822:
823:                public TaskStartRunnable(InventoryUIFrame aFrame) {
824:                    frame = aFrame;
825:                }
826:
827:                public void run() {
828:                    timeConsumingTaskStart(frame);
829:                }
830:            }
831:
832:            protected class FlushXMLToScreenRunnable implements  Runnable {
833:
834:                protected File[] openFiles;
835:                protected String invXML;
836:                protected InventoryFileManager fm;
837:
838:                public FlushXMLToScreenRunnable(String xmlStr,
839:                        File[] filesToOpen, InventoryFileManager fileMgr) {
840:                    invXML = xmlStr;
841:                    openFiles = filesToOpen;
842:                    fm = fileMgr;
843:                }
844:
845:                public void run() {
846:                    flushXMLToScreen(invXML, openFiles, fm);
847:                }
848:            }
849:
850:            static class DoNothingMouseListener extends MouseInputAdapter {
851:                public void mouseClicked(MouseEvent e) {
852:                    e.consume();
853:                }
854:
855:                public void mouseDragged(MouseEvent e) {
856:                    e.consume();
857:                }
858:
859:                public void mouseEntered(MouseEvent e) {
860:                    e.consume();
861:                }
862:
863:                public void mouseExited(MouseEvent e) {
864:                    e.consume();
865:                }
866:
867:                public void mouseMoved(MouseEvent e) {
868:                    e.consume();
869:                }
870:
871:                public void mousePressed(MouseEvent e) {
872:                    e.consume();
873:                }
874:
875:                public void mouseReleased(MouseEvent e) {
876:                    e.consume();
877:                }
878:            }
879:
880:            public static void main(String[] args) {
881:                InventoryUIFrame frame = new InventoryUIFrame(args);
882:            }
883:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.