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:
031: import java.awt.*;
032:
033: import javax.swing.JPanel;
034: import javax.swing.BorderFactory;
035: import javax.swing.JLabel;
036:
037: import com.klg.jclass.chart.data.JCDefaultDataSource;
038: import com.klg.jclass.util.swing.JCExitFrame;
039:
040: import com.klg.jclass.chart.*;
041:
042: import org.cougaar.logistics.plugin.inventory.TimeUtils;
043:
044: import org.cougaar.logistics.ui.inventory.data.InventoryData;
045: import org.cougaar.logistics.ui.inventory.data.InventoryPreferenceData;
046:
047: /**
048: * <pre>
049: *
050: * The InventoryChart class is the base class for all Inventory
051: * charts displayed in the GUI. It contains all the shared
052: * behavior of all charts in the GUI.
053: *
054: *
055: *
056: **/
057:
058: public class InventoryLevelChart extends InventoryShortfallChart {
059:
060: protected OrgActivityChartDataModel orgActDM;
061:
062: protected ChartDataView invChartDataView;
063: protected ChartDataView targetReorderChartDataView;
064: protected ChartDataView orgChartDataView;
065:
066: protected boolean displayOrgActivities = true;
067:
068: public InventoryLevelChart(boolean initialDisplayCDay,
069: InventoryPreferenceData prefData) {
070: super (prefData);
071: initialize("Inventory", initialDisplayCDay);
072: }
073:
074: public ChartDataView getInvChartDataView() {
075: return invChartDataView;
076: }
077:
078: public ChartDataView getOrgChartDataView() {
079: return orgChartDataView;
080: }
081:
082: public void initialize(String title, boolean initialDisplayCDay) {
083: super .initialize(title, initialDisplayCDay);
084: chart.getLegend().setPreferredSize(new Dimension(148, 160));
085: }
086:
087: public void initializeChart() {
088:
089: reqDM = new RequisitionsChartDataModel("",
090: InventoryDemandChart.DEMAND_TASKS,
091: InventoryDemandChart.DEMAND_ARS);
092:
093: projDM = new ProjectionsChartDataModel("Demand from Customers",
094: InventoryDemandChart.DEMAND_PROJ_TASKS,
095: InventoryDemandChart.DEMAND_PROJ_ARS,
096: InventoryDemandChart.DEMAND_TASKS, reqDM, false);
097:
098: InventoryLevelChartDataModel idm = new InventoryLevelChartDataModel();
099: TargetReorderLevelChartDataModel trdm = new TargetReorderLevelChartDataModel(
100: "");
101:
102: orgActDM = new OrgActivityChartDataModel();
103:
104: shortfallDM = new InventoryShortfallChartDataModel("", idm,
105: reqDM, projDM);
106:
107: //These are never viewed, but should but are added to get all
108: // the axis et al information.
109: ChartDataView reqView = addChartView(JCChart.BAR, reqDM);
110: ChartDataView projView = addChartView(JCChart.BAR, projDM);
111: reqView.setVisible(false);
112: projView.setVisible(false);
113:
114: orgChartDataView = addChartView(JCChart.BAR, orgActDM);
115: orgChartDataView.setVisible(false);
116:
117: invChartDataView = addChartView(JCChart.BAR, idm);
118: shortfallChartDataView = addChartView(JCChart.BAR, shortfallDM);
119: //belowZeroDataView = addChartView(JCChart.BAR, belowZeroDM);
120: targetReorderChartDataView = addChartView(JCChart.PLOT, trdm);
121:
122: String colorScheme = prefData.getColorScheme();
123: setShortfallChartColors(colorScheme);
124: setInventoryBarChartColors(colorScheme, orgChartDataView);
125: //setBelowZeroChartColors(colorScheme);
126:
127: setInventoryBarChartColors(colorScheme, invChartDataView);
128: setLineChartDataViewColors(targetReorderChartDataView);
129:
130: displayShortfall = false;
131: updateShortfall();
132: updateOrgActivities();
133:
134: }
135:
136: protected boolean setYAxisMinToZero() {
137: return !displayShortfall;
138: }
139:
140: public void setDisplayShortfall(boolean doDisplayShortfall) {
141: if (doDisplayShortfall != displayShortfall) {
142: super .setDisplayShortfall(doDisplayShortfall);
143: resetYMin();
144: //chart.reset();
145: }
146: }
147:
148: public boolean hasOrgActivities() {
149: return orgActDM.hasOrgActivities();
150: }
151:
152: public void updateOrgActivities() {
153: if (hasOrgActivities()) {
154: orgChartDataView.setVisible(displayOrgActivities);
155: orgChartDataView
156: .setName(InventoryLevelChartDataModel.INVENTORY_LEVEL_LEGEND);
157: invChartDataView.setName("");
158: } else {
159: orgChartDataView.setVisible(false);
160: orgChartDataView.setName("");
161: invChartDataView
162: .setName(InventoryLevelChartDataModel.INVENTORY_LEVEL_LEGEND);
163: }
164: }
165:
166: public void setData(InventoryData data) {
167: super .setData(data);
168: updateOrgActivities();
169: }
170:
171: protected void setInventoryBarChartColors(String colorScheme,
172: ChartDataView theView) {
173: JCBarChartFormat format = (JCBarChartFormat) theView
174: .getChartFormat();
175: format.setClusterWidth(100);
176: format.setClusterOverlap(100);
177:
178: theView.setOutlineColor(colorTable.getOutlineColor(colorScheme,
179: theView));
180:
181: //chartDataView.setOutlineColor(Color.black);
182: for (int j = 0; j < theView.getNumSeries(); j++) {
183: ChartDataViewSeries series = theView.getSeries(j);
184: // System.out.println("InventoryLevelChart setting bar chart colors for: " + series.getLabel());
185: setSeriesColor(series, colorTable.get(colorScheme, series
186: .getLabel()));
187: int symbolStyle = colorTable.getSymbolShape(colorScheme,
188: series.getLabel());
189: if (symbolStyle != JCSymbolStyle.NONE) {
190: series.getStyle().setSymbolShape(symbolStyle);
191: series.getStyle().setSymbolColor(
192: colorTable.getSymbolColor(colorScheme, series
193: .getLabel()));
194: series.getStyle().setSymbolSize(
195: colorTable.getSymbolSize(colorScheme, series
196: .getLabel()));
197: }
198: }
199: }
200:
201: protected void setShortfallChartColors(String colorScheme) {
202: if (shortfallChartDataView != null) {
203: setInventoryBarChartColors(colorScheme,
204: shortfallChartDataView);
205: }
206: }
207:
208: public void prefDataChanged(InventoryPreferenceData oldData,
209: InventoryPreferenceData newData) {
210: super .prefDataChanged(oldData, newData);
211: String colorScheme = newData.getColorScheme();
212: if (!colorScheme.equals(oldData.getColorScheme())) {
213: setInventoryBarChartColors(colorScheme, orgChartDataView);
214: setInventoryBarChartColors(colorScheme, invChartDataView);
215: setLineChartDataViewColors(targetReorderChartDataView);
216: }
217: }
218:
219: protected void setLineChartDataViewColors(
220: ChartDataView chartDataView) {
221: // set line width and colors
222: for (int j = 0; j < chartDataView.getNumSeries(); j++) {
223: ChartDataViewSeries series = chartDataView.getSeries(j);
224: series.getStyle().setLineWidth(2);
225: series.getStyle().setSymbolShape(JCSymbolStyle.NONE);
226: setSeriesColor(series, colorTable.get(colorScheme, series
227: .getLabel()));
228: int width = colorTable.getLineWidth(colorScheme, series
229: .getLabel());
230: series.getStyle().setLineWidth(width);
231: int symbolStyle = colorTable.getSymbolShape(colorScheme,
232: series.getLabel());
233: if (symbolStyle != JCSymbolStyle.NONE) {
234: series.getStyle().setSymbolShape(symbolStyle);
235: series.getStyle().setSymbolColor(
236: colorTable.getSymbolColor(colorScheme, series
237: .getLabel()));
238: series.getStyle().setSymbolSize(
239: colorTable.getSymbolSize(colorScheme, series
240: .getLabel()));
241: }
242: }
243:
244: }
245: }
|