Source Code Cross Referenced for MultiChartPanel.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.Date;
030:        import java.util.Calendar;
031:        import java.util.Iterator;
032:
033:        import java.awt.Event;
034:        import java.awt.event.*;
035:        import java.awt.GridBagLayout;
036:        import java.awt.GridBagConstraints;
037:        import java.awt.Color;
038:        import java.awt.Insets;
039:        import java.awt.Font;
040:        import java.awt.BorderLayout;
041:
042:        import javax.swing.*;
043:
044:        import com.klg.jclass.chart.JCChartListener;
045:        import com.klg.jclass.chart.JCChartEvent;
046:        import com.klg.jclass.chart.JCChart;
047:        import com.klg.jclass.chart.JCAxis;
048:        import com.klg.jclass.chart.JCPickListener;
049:        import com.klg.jclass.chart.JCPickEvent;
050:        import com.klg.jclass.chart.JCDataIndex;
051:        import com.klg.jclass.chart.JCChartUtil;
052:        import com.klg.jclass.chart.ChartDataView;
053:
054:        import org.cougaar.util.log.Logging;
055:        import org.cougaar.util.log.Logger;
056:
057:        import org.cougaar.logistics.plugin.inventory.TimeUtils;
058:        import org.cougaar.logistics.ui.inventory.data.InventoryData;
059:        import org.cougaar.logistics.ui.inventory.data.InventoryPreferenceData;
060:
061:        /**
062:         * <pre>
063:         *
064:         * The MultiChartPanel contains the three InventoryCharts
065:         * to be displayed: the levels, refill, and demand charts.
066:         * Its just a container that measures lays out the
067:         * charts appropriatly.
068:         *
069:         *
070:         * @see InventoryLevelChart
071:         * @see InventoryRefillChart
072:         * @see InventoryDemandChart
073:         *
074:         *
075:         **/
076:
077:        public class MultiChartPanel extends JPanel implements  JCChartListener,
078:                JCPickListener, ItemListener {
079:
080:            protected final static long MILLIS_IN_DAY = TimeUtils.MSEC_PER_DAY;
081:
082:            public final static String INITIAL_POINT_LABEL = "Right click to get quantity at a point; left hold and drag to zoom in.";
083:
084:            public static final String CDAY_MODE = "Cdays";
085:            public static final String CHOUR_MODE = "Chours";
086:            public static final String SHORTFALL_MODE = "Shortfall";
087:            public static final String RESET = "Reset";
088:
089:            protected InventoryLevelChart levelChart;
090:            protected InventoryRefillChart refillChart;
091:            protected InventoryDemandChart demandChart;
092:
093:            protected JPanel mainPanel;
094:
095:            protected InventoryData inventory = null;
096:
097:            protected final static int LEVEL_CHART_INDEX = 0;
098:            protected final static int REFILL_CHART_INDEX = 1;
099:            protected final static int DEMAND_CHART_INDEX = 2;
100:
101:            protected final static Insets BLANK_INSETS = new Insets(0, 0, 0, 0);
102:
103:            protected final static int LEVEL_CHART_HEIGHT = 6;
104:            protected final static int BAR_CHART_HEIGHT = 3;
105:            protected final static int REFILL_CHART_HEIGHT = BAR_CHART_HEIGHT;
106:            protected final static int DEMAND_CHART_HEIGHT = BAR_CHART_HEIGHT;
107:            protected final static GridBagConstraints LEVEL_CHART_CONSTRAINTS = new GridBagConstraints(
108:                    0, GridBagConstraints.RELATIVE, 1, LEVEL_CHART_HEIGHT, 1.0,
109:                    0.6, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
110:                    BLANK_INSETS, 0, 0);
111:
112:            protected final static GridBagConstraints REFILL_CHART_CONSTRAINTS = new GridBagConstraints(
113:                    0, GridBagConstraints.RELATIVE, 1, BAR_CHART_HEIGHT, 1.0,
114:                    0.3, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
115:                    BLANK_INSETS, 0, 0);
116:
117:            protected final static GridBagConstraints DEMAND_CHART_CONSTRAINTS = REFILL_CHART_CONSTRAINTS;
118:
119:            protected MouseAdapter mouseAdapter = new MouseAdapter() {
120:                public void mousePressed(MouseEvent e) {
121:                    levelChartMousePick(e);
122:                }
123:            };
124:
125:            protected JLabel pointLabel;
126:
127:            protected Logger logger;
128:
129:            protected JCheckBox cdaysModeCheck;
130:            protected JCheckBox shortfallModeCheck;
131:            protected JButton resetButton;
132:
133:            protected boolean displayCDay = false;
134:            protected long baseCDayTime = InventoryChartBaseCalendar
135:                    .getBaseTime();
136:
137:            protected long bucketSize = MILLIS_IN_DAY;
138:
139:            protected boolean displayShortfall = false;
140:
141:            protected boolean showInitialShortfall = true;
142:
143:            protected InventoryPreferenceData prefData = null;
144:
145:            public MultiChartPanel() {
146:                super ();
147:                initializeMultiChart();
148:            }
149:
150:            public MultiChartPanel(boolean showInitShortfall,
151:                    boolean initialDisplayCDay, InventoryPreferenceData prefData) {
152:                super ();
153:                this .prefData = prefData;
154:                showInitialShortfall = showInitShortfall;
155:                displayCDay = initialDisplayCDay;
156:                initializeMultiChart();
157:            }
158:
159:            public void initializeMultiChart() {
160:                int gridx = 0;
161:                int gridy = 0;
162:
163:                logger = Logging.getLogger(this );
164:
165:                //    InventoryColorTable colorTable = new InventoryColorTable();
166:
167:                Insets blankInsets = BLANK_INSETS;
168:                levelChart = new InventoryLevelChart(displayCDay, prefData);
169:                refillChart = new InventoryRefillChart(displayCDay, prefData);
170:                demandChart = new InventoryDemandChart(displayCDay, prefData);
171:
172:                pointLabel = new JLabel(INITIAL_POINT_LABEL, JLabel.CENTER);
173:                pointLabel.setBackground(Color.magenta);
174:
175:                cdaysModeCheck = new JCheckBox(CDAY_MODE, displayCDay);
176:                Font newFont = cdaysModeCheck.getFont();
177:                newFont = newFont.deriveFont(newFont.getStyle(), (float) 15);
178:                cdaysModeCheck.setFont(newFont);
179:                cdaysModeCheck.setActionCommand(CDAY_MODE);
180:                cdaysModeCheck.setToolTipText("Display xaxis dates as C-Days");
181:                cdaysModeCheck.addItemListener(this );
182:
183:                resetButton = new JButton(RESET);
184:                resetButton.setFont(newFont);
185:                resetButton.setActionCommand(RESET);
186:                resetButton.setToolTipText("Reset zoom level to original.");
187:                resetButton.addActionListener(new ActionListener() {
188:                    public void actionPerformed(ActionEvent e) {
189:                        removeAllChartListeners();
190:                        //TODO:MWD remove less efficient reset (setDisplayCDay) (takes more time/resources)
191:                        //levelChart.setDisplayCDay(displayCDay);
192:                        //refillChart.setDisplayCDay(displayCDay);
193:                        //demandChart.setDisplayCDay(displayCDay);
194:                        levelChart.getChart().reset();
195:                        levelChart.resetAxes();
196:                        refillChart.getChart().reset();
197:                        refillChart.resetAxes();
198:                        demandChart.getChart().reset();
199:                        demandChart.resetAxes();
200:                        reallignChartsByXAxis();
201:                        pointLabel.setText(INITIAL_POINT_LABEL);
202:                        addAllChartListeners();
203:                    }
204:                });
205:
206:                shortfallModeCheck = new JCheckBox(SHORTFALL_MODE,
207:                        displayShortfall);
208:                shortfallModeCheck.setFont(newFont);
209:                shortfallModeCheck.setActionCommand(SHORTFALL_MODE);
210:                shortfallModeCheck.setToolTipText("Display shortfall plots");
211:                InventoryColorTable colorTable = prefData.getColorTable();
212:                shortfallModeCheck.setForeground(colorTable.get(prefData
213:                        .getColorScheme(),
214:                        ShortfallChartDataModel.SHORTFALL_SERIES_LABEL));
215:                shortfallModeCheck.setEnabled(false);
216:                shortfallModeCheck.addItemListener(this );
217:
218:                addAllChartListeners();
219:                addAllPickListeners();
220:
221:                // set header and legend to black
222:                // set beveled borders around plot area and chart
223:                //((JLabel)chart.getHeader()).setForeground(Color.black);
224:                //chart.setBorder(BorderFactory.createLoweredBevelBorder());
225:                //chart.getChartArea().setBorder(BorderFactory.createLoweredBevelBorder());
226:
227:                // add chart to panel
228:                setLayout(new GridBagLayout());
229:
230:                mainPanel = new JPanel();
231:                mainPanel.setLayout(new GridBagLayout());
232:
233:                int height = 6;
234:                gridy += height;
235:
236:                mainPanel.add(levelChart, LEVEL_CHART_CONSTRAINTS,
237:                        LEVEL_CHART_INDEX);
238:
239:                height = 3;
240:                gridy += height;
241:
242:                mainPanel.add(refillChart, REFILL_CHART_CONSTRAINTS,
243:                        REFILL_CHART_INDEX);
244:
245:                height = 3;
246:                gridy += height;
247:
248:                mainPanel.add(demandChart, DEMAND_CHART_CONSTRAINTS,
249:                        DEMAND_CHART_INDEX);
250:
251:                height = LEVEL_CHART_HEIGHT + REFILL_CHART_HEIGHT
252:                        + DEMAND_CHART_HEIGHT;
253:
254:                add(mainPanel, new GridBagConstraints(gridx,
255:                        GridBagConstraints.RELATIVE, 1, height, 1.0, 1.0,
256:                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
257:                        blankInsets, 0, 0));
258:
259:                JPanel checkBoxPanel = new JPanel();
260:                //    checkBoxPanel.setLayout(new BorderLayout());
261:                //    checkBoxPanel.add(shortfallModeCheck, BorderLayout.WEST);
262:                //    checkBoxPanel.add(Box.createHorizontalStrut(4), BorderLayout.CENTER);
263:                //    checkBoxPanel.add(cdaysModeCheck, BorderLayout.EAST);
264:                checkBoxPanel.add(shortfallModeCheck);
265:                checkBoxPanel.add(cdaysModeCheck);
266:                checkBoxPanel.add(resetButton);
267:
268:                JPanel bottomPanel = new JPanel();
269:                bottomPanel.setLayout(new BorderLayout());
270:                bottomPanel.add(Box.createHorizontalStrut(20),
271:                        BorderLayout.WEST);
272:                bottomPanel.add(pointLabel, BorderLayout.CENTER);
273:                bottomPanel.add(checkBoxPanel, BorderLayout.EAST);
274:
275:                height = 1;
276:                gridy += height;
277:
278:                add(bottomPanel, new GridBagConstraints(gridx,
279:                        GridBagConstraints.RELATIVE, 1, height, 1.0, 0.025,
280:                        GridBagConstraints.CENTER,
281:                        GridBagConstraints.HORIZONTAL, blankInsets, 0, 0));
282:
283:            }
284:
285:            public void showDemandChart(boolean doShow) {
286:                if (doShow) {
287:                    int addIndex = Math.min(DEMAND_CHART_INDEX, mainPanel
288:                            .getComponentCount());
289:                    mainPanel.add(demandChart, DEMAND_CHART_CONSTRAINTS,
290:                            addIndex);
291:                } else {
292:                    mainPanel.remove(demandChart);
293:                }
294:                repaint();
295:            }
296:
297:            public void showRefillChart(boolean doShow) {
298:                if (doShow) {
299:                    int addIndex = Math.min(REFILL_CHART_INDEX, mainPanel
300:                            .getComponentCount());
301:                    mainPanel.add(refillChart, REFILL_CHART_CONSTRAINTS,
302:                            addIndex);
303:                } else {
304:                    mainPanel.remove(refillChart);
305:                }
306:                repaint();
307:            }
308:
309:            public void showInventoryChart(boolean doShow) {
310:                if (doShow) {
311:                    int addIndex = Math.min(LEVEL_CHART_INDEX, mainPanel
312:                            .getComponentCount());
313:                    mainPanel
314:                            .add(levelChart, LEVEL_CHART_CONSTRAINTS, addIndex);
315:                } else {
316:                    mainPanel.remove(levelChart);
317:                }
318:                repaint();
319:            }
320:
321:            public void setData(InventoryData data) {
322:                removeAllChartListeners();
323:                inventory = data;
324:                baseCDayTime = data.getStartCDay();
325:                bucketSize = data.getBucketSize();
326:                if (bucketSize < MILLIS_IN_DAY) {
327:                    cdaysModeCheck.setText(CHOUR_MODE);
328:                } else {
329:                    cdaysModeCheck.setText(CDAY_MODE);
330:                }
331:
332:                levelChart.setData(data);
333:                refillChart.setData(data);
334:                demandChart.setData(data);
335:                JCAxis firstXAxis = getFirstXAxis();
336:                firstXAxis.recalc();
337:                reallignChartsByXAxis(firstXAxis);
338:                pointLabel.setText(INITIAL_POINT_LABEL);
339:                if ((updateShortfallCheckBox()) && (showInitialShortfall)) {
340:                    setDisplayShortfall(true);
341:                    shortfallModeCheck.setSelected(true);
342:                } else {
343:                    shortfallModeCheck.setSelected(false);
344:                }
345:                addAllChartListeners();
346:            }
347:
348:            public void setShowInitialShortfall(boolean showInitShortfall) {
349:                showInitialShortfall = showInitShortfall;
350:                if (showInitialShortfall) {
351:                    boolean yepShortfall = updateShortfallCheckBox();
352:                    //setDisplayShortfall(yepShortfall);
353:                    shortfallModeCheck.setSelected(yepShortfall);
354:                } else {
355:                    shortfallModeCheck.setSelected(false);
356:                }
357:            }
358:
359:            public boolean updateShortfallCheckBox() {
360:                if (refillChart.isShortfall() || demandChart.isShortfall()) {
361:                    shortfallModeCheck.setEnabled(true);
362:                    return true;
363:                } else {
364:                    shortfallModeCheck.setEnabled(false);
365:                    return false;
366:                }
367:            }
368:
369:            public void setDisplayCDay(boolean doUseCDay) {
370:                if (displayCDay != doUseCDay) {
371:                    displayCDay = doUseCDay;
372:                    removeAllChartListeners();
373:                    levelChart.setDisplayCDay(displayCDay);
374:                    refillChart.setDisplayCDay(displayCDay);
375:                    demandChart.setDisplayCDay(displayCDay);
376:                    reallignChartsByXAxis();
377:                    pointLabel.setText(INITIAL_POINT_LABEL);
378:                    addAllChartListeners();
379:                }
380:            }
381:
382:            public void setDisplayShortfall(boolean doDisplayShortfall) {
383:                if (displayShortfall != doDisplayShortfall) {
384:                    displayShortfall = doDisplayShortfall;
385:                    removeAllChartListeners();
386:                    levelChart.setDisplayShortfall(displayShortfall);
387:                    refillChart.setDisplayShortfall(displayShortfall);
388:                    demandChart.setDisplayShortfall(displayShortfall);
389:                    pointLabel.setText(INITIAL_POINT_LABEL);
390:                    addAllChartListeners();
391:                }
392:            }
393:
394:            public void removeAllChartListeners() {
395:                levelChart.removeChartListener(this );
396:                refillChart.removeChartListener(this );
397:                demandChart.removeChartListener(this );
398:            }
399:
400:            public void addAllChartListeners() {
401:                levelChart.addChartListener(this );
402:                refillChart.addChartListener(this );
403:                demandChart.addChartListener(this );
404:            }
405:
406:            public void removeAllPickListeners() {
407:                //levelChart.getChart().removeMouseListener(mouseAdapter);
408:                levelChart.removePickListener(this );
409:                refillChart.removePickListener(this );
410:                demandChart.removePickListener(this );
411:            }
412:
413:            public void addAllPickListeners() {
414:
415:                levelChart.addPickListener(this );
416:                //levelChart.getChart().addMouseListener(mouseAdapter);
417:                refillChart.addPickListener(this );
418:                demandChart.addPickListener(this );
419:            }
420:
421:            //Make all three charts align along the xAxis
422:            //Hand in an xAxis as the reference point
423:            //typically this is xAxis being zoomed in upon
424:            //but also sometimes the level chart xAxis at the
425:            //beginning is the ruler.
426:            //This is should only be called after removing
427:            //All chart listeners.
428:            public void reallignChartsByXAxis(JCAxis xAxis) {
429:                double xStart = xAxis.getMin();
430:                double xEnd = xAxis.getMax();
431:                levelChart.setXZoom(xStart, xEnd);
432:                refillChart.setXZoom(xStart, xEnd);
433:                demandChart.setXZoom(xStart, xEnd);
434:            }
435:
436:            public void reallignChartsByXAxis() {
437:                reallignChartsByXAxis(getFirstXAxis());
438:            }
439:
440:            //Get the defining or limiting first x axis
441:            public JCAxis getFirstXAxis() {
442:                JCAxis xAxis = null;
443:                if (mainPanel.getComponentCount() > 0) {
444:                    InventoryChart chart = (InventoryChart) mainPanel
445:                            .getComponent(0);
446:                    xAxis = chart.getFirstXAxis();
447:                } else {
448:                    xAxis = levelChart.getFirstXAxis();
449:                }
450:                return xAxis;
451:            }
452:
453:            public void changeChart(JCChartEvent jce) {
454:                JCChart source = (JCChart) jce.getSource();
455:                //String headerText =  ((JLabel) source.getHeader()).getText();
456:                JCAxis axis = jce.getModifiedAxis();
457:                if (!axis.isVertical()) {
458:                    removeAllChartListeners();
459:                    reallignChartsByXAxis(axis);
460:                    pointLabel.setText(INITIAL_POINT_LABEL);
461:                    addAllChartListeners();
462:                }
463:            }
464:
465:            public void paintChart(JCChart chart) {
466:            }
467:
468:            public void itemStateChanged(ItemEvent e) {
469:                if (e.getSource() instanceof  JCheckBox) {
470:                    JCheckBox source = (JCheckBox) e.getSource();
471:                    if (source.getActionCommand().equals(CDAY_MODE)) {
472:                        setDisplayCDay(e.getStateChange() == e.SELECTED);
473:                    } else if (source.getActionCommand().equals(SHORTFALL_MODE)) {
474:                        setDisplayShortfall(e.getStateChange() == e.SELECTED);
475:                    }
476:                }
477:            }
478:
479:            /** TODO MWD Special Mouse picker to filter out Org Activity clicks
480:             * Need to do better so instead of always passing to inventoryChartDataView
481:             * We explictly only do this on OrgActivityClicks.
482:             */
483:            public void levelChartMousePick(MouseEvent e) {
484:                if (SwingUtilities.isRightMouseButton(e)) {
485:                    JCChart innerChart = (JCChart) e.getSource();
486:
487:                    ChartDataView invChartDataView = levelChart
488:                            .getInvChartDataView();
489:
490:                    JCDataIndex dataIndex = innerChart.pick(e.getPoint(),
491:                            invChartDataView);
492:                    if (!(dataIndex.getPoint() < 0)
493:                            && !(dataIndex.getSeriesIndex() < 0)) {
494:                        pick(innerChart, dataIndex);
495:                    }
496:                }
497:            }
498:
499:            public void pick(JCPickEvent e) {
500:                JCDataIndex dataIndex = e.getPickResult();
501:                // check for all the possible failures
502:                if (dataIndex == null) {
503:                    logger.warn("WARNING: dataIndex is null");
504:                    return;
505:                }
506:                pick((JCChart) e.getSource(), dataIndex);
507:            }
508:
509:            public void pick(JCChart chart, JCDataIndex dataIndex) {
510:
511:                ChartDataView chartDataView = dataIndex.getDataView();
512:                if (chartDataView == null) {
513:                    logger.warn("WARNING: chartDataView is null");
514:                    return;
515:                }
516:                int seriesIndex = dataIndex.getSeriesIndex();
517:                int pt = dataIndex.getPoint();
518:                if (pt < 0 || seriesIndex < 0) {
519:                    logger.warn("WARNING: series or point index is null");
520:                    return;
521:                }
522:
523:                InventoryBaseChartDataModel dataModel = (InventoryBaseChartDataModel) chartDataView
524:                        .getDataSource();
525:
526:                if (dataModel == null) {
527:                    logger.warn("WARNING: data model is null");
528:                    return;
529:                }
530:
531:                //The OrgActivityChart seems to be stealing picks
532:                //from the InventoryLevelChart data.  Turn about is fair play.
533:                /**  MWD disabled when inventory chart became a bar chart.
534:                if (dataModel instanceof OrgActivityChartDataModel) {
535:                  logger.warn("Still getting events from OrgActivityChartDataModel!");
536:                }
537:                 **/
538:
539:                // user has picked a valid point
540:                double[] x = dataModel.getXSeries(seriesIndex);
541:                double[] y = dataModel.getRealYSeries(seriesIndex);
542:
543:                int cDay;
544:                int dayOfYear;
545:                int daysFromBaseToCDay = (int) ((baseCDayTime - InventoryChartBaseCalendar
546:                        .getBaseTime()) / TimeUtils.MSEC_PER_DAY);
547:
548:                int hourOfDay = 0;
549:                boolean displayHourly = (bucketSize < MILLIS_IN_DAY);
550:
551:                if (displayHourly) {
552:                    if (displayCDay) {
553:                        int cHour = ((int) x[pt]);
554:                        cDay = (cHour / TimeUtils.HOUR_PER_DAY);
555:                        //subtract 1, because in our scale between -1 and 0
556:                        //is CDay -1 and the hour, not C0
557:                        if (cHour < 1) {
558:                            cDay--;
559:                        }
560:                        hourOfDay = cHour % TimeUtils.HOUR_PER_DAY;
561:                        dayOfYear = cDay + daysFromBaseToCDay;
562:                    } else {
563:                        int hourOfYear = ((int) x[pt]);
564:                        dayOfYear = hourOfYear / TimeUtils.HOUR_PER_DAY;
565:                        hourOfDay = hourOfYear % TimeUtils.HOUR_PER_DAY;
566:                        cDay = dayOfYear - daysFromBaseToCDay;
567:                    }
568:                } else {
569:                    if (displayCDay) {
570:                        cDay = ((int) x[pt]);
571:                        dayOfYear = cDay + daysFromBaseToCDay;
572:                    } else {
573:                        dayOfYear = ((int) x[pt]);
574:                        cDay = dayOfYear - daysFromBaseToCDay;
575:                    }
576:                }
577:
578:                InventoryChartBaseCalendar tmpC = new InventoryChartBaseCalendar();
579:                tmpC.set(Calendar.YEAR, InventoryChartBaseCalendar
580:                        .getBaseYear());
581:                // add one because day of year is Zero based.
582:                tmpC.set(Calendar.DAY_OF_YEAR, (dayOfYear + 1));
583:                tmpC.set(Calendar.HOUR_OF_DAY, hourOfDay);
584:                // add 1 to month as it numbers them from 0
585:                int month = tmpC.get(Calendar.MONTH) + 1;
586:
587:                String label;
588:                String valueLabel;
589:
590:                if (prefData.roundToWholes) {
591:                    valueLabel = "Quantity: "
592:                            + JCChartUtil.format(Math.round(y[pt]), 0);
593:                } else {
594:                    valueLabel = "Quantity: " + JCChartUtil.format(y[pt], 2);
595:                }
596:
597:                if (displayHourly) {
598:                    label = "Date: " + month + "/"
599:                            + tmpC.get(Calendar.DAY_OF_MONTH) + "/"
600:                            + tmpC.get(Calendar.YEAR) + " " + "(C" + cDay
601:                            + ") " + tmpC.get(Calendar.HOUR_OF_DAY) + ":00 "
602:                            + valueLabel;
603:
604:                } else {
605:                    label = "Date: " + month + "/"
606:                            + tmpC.get(Calendar.DAY_OF_MONTH) + "/"
607:                            + tmpC.get(Calendar.YEAR) + " " + "(C" + cDay + ")"
608:                            + valueLabel;
609:                }
610:
611:                //System.out.println("Pick Point is: " + label);
612:                pointLabel.setText(label);
613:
614:            }
615:
616:            public void prefDataChanged(InventoryPreferenceData origData,
617:                    InventoryPreferenceData newData) {
618:
619:                levelChart.prefDataChanged(origData, newData);
620:                refillChart.prefDataChanged(origData, newData);
621:                demandChart.prefDataChanged(origData, newData);
622:                if (origData.startupWCDay != newData.startupWCDay) {
623:                    //displayCDay = newData.startupWCDay;
624:                    cdaysModeCheck.setSelected(newData.startupWCDay);
625:                    //setDisplayCDay(newData.startupWCDay);
626:                }
627:                if (origData.displayShortfall != newData.displayShortfall) {
628:                    setShowInitialShortfall(newData.displayShortfall);
629:                }
630:                if (((origData.ammoUnit != newData.ammoUnit) || (origData.waterUnit != newData.waterUnit))
631:                        && (inventory != null)) {
632:                    setData(inventory);
633:                }
634:                prefData = newData;
635:            }
636:
637:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.