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.Color;
032: import java.awt.Insets;
033:
034: import com.klg.jclass.chart.JCChart;
035: import com.klg.jclass.chart.data.JCDefaultDataSource;
036: import com.klg.jclass.util.swing.JCExitFrame;
037: import com.klg.jclass.chart.JCSymbolStyle;
038:
039: import com.klg.jclass.chart.ChartDataView;
040: import com.klg.jclass.chart.ChartDataViewSeries;
041: import com.klg.jclass.chart.ChartDataModel;
042: import com.klg.jclass.chart.ChartDataEvent;
043: import com.klg.jclass.chart.JCFillStyle;
044:
045: import org.cougaar.logistics.plugin.inventory.LogisticsInventoryFormatter;
046: import org.cougaar.logistics.plugin.inventory.TimeUtils;
047:
048: import org.cougaar.logistics.ui.inventory.data.InventoryData;
049: import org.cougaar.logistics.ui.inventory.data.InventoryPreferenceData;
050:
051: /**
052: * <pre>
053: *
054: * The InventoryShortfallChart class is an abstract class that
055: * captures common behavior between the
056: * all charts that display shortfall.
057: *
058: * @see InventoryChart
059: * @see InventoryDemandChart
060: * @see InventoryRefillChart
061: *
062: *
063: **/
064:
065: public abstract class InventoryShortfallChart extends InventoryChart {
066:
067: protected RequisitionsChartDataModel reqDM;
068: protected ProjectionsChartDataModel projDM;
069: protected ChartDataView shortfallChartDataView;
070:
071: protected ShortfallChartDataModel shortfallDM;
072:
073: protected boolean displayShortfall = false;
074:
075: public InventoryShortfallChart(InventoryPreferenceData prefData) {
076: super (prefData);
077: }
078:
079: public void setData(InventoryData data) {
080: inventory = data;
081: if (data.getBucketSize() != currBucketSize) {
082: resetAxes();
083: }
084: java.util.List viewList = chart.getDataView();
085: for (int i = 0; i < viewList.size(); i++) {
086: ChartDataView chartDataView = (ChartDataView) viewList
087: .get(i);
088: InventoryBaseChartDataModel dataModel = (InventoryBaseChartDataModel) chartDataView
089: .getDataSource();
090: dataModel.resetInventory(data);
091: }
092: updateShortfall();
093: myYAxisTitle = (conversionTable.getConversionForData(data,
094: prefData)).getUnit();
095: chart.reset();
096: resetAxes();
097:
098: }
099:
100: public void updateShortfall() {
101: if (isShortfall()) {
102: shortfallChartDataView.setVisible(displayShortfall);
103: } else {
104: shortfallChartDataView.setVisible(false);
105: }
106: }
107:
108: public boolean isShortfall() {
109: if (shortfallDM == null) {
110: return false;
111: }
112: return shortfallDM.isShortfall();
113: }
114:
115: public void setDisplayShortfall(boolean doDisplayShortfall) {
116: if (doDisplayShortfall != displayShortfall) {
117: displayShortfall = doDisplayShortfall;
118: updateShortfall();
119: }
120: }
121:
122: protected void setShortfallChartColors(String colorScheme) {
123: if (shortfallChartDataView != null) {
124: for (int j = 0; j < shortfallChartDataView.getNumSeries(); j++) {
125: ChartDataViewSeries series = shortfallChartDataView
126: .getSeries(j);
127: series.getStyle().setLineWidth(2);
128: series.getStyle().setSymbolShape(JCSymbolStyle.NONE);
129: // System.out.println("InventoryShortfallChart: setting shortfall colors for: " + series.getLabel());
130: setSeriesColor(series, colorTable.get(colorScheme,
131: series.getLabel()));
132: int width = colorTable.getLineWidth(colorScheme, series
133: .getLabel());
134: series.getStyle().setLineWidth(width);
135: }
136: }
137: }
138:
139: protected void setBarChartColors(String colorScheme) {
140: java.util.List viewList = chart.getDataView();
141: for (int i = 0; i < viewList.size(); i++) {
142: ChartDataView chartDataView = (ChartDataView) viewList
143: .get(i);
144: if (chartDataView.getChartType() == JCChart.BAR) {
145: chartDataView.setOutlineColor(Color.black);
146: for (int j = 0; j < chartDataView.getNumSeries(); j++) {
147: ChartDataViewSeries series = chartDataView
148: .getSeries(j);
149: // System.out.println("InventoryShortfallChart setting bar chart colors for: " + series.getLabel());
150: setSeriesColor(series, colorTable.get(colorScheme,
151: series.getLabel()));
152: int pattern = colorTable.getFillPattern(
153: colorScheme, series.getLabel());
154: series.getStyle().setFillPattern(pattern);
155: if (pattern != JCFillStyle.SOLID)
156: series.getStyle()
157: .setFillBackground(
158: colorTable.getBackgroundColor(
159: colorScheme, series
160: .getLabel()));
161: int symbolStyle = colorTable.getSymbolShape(
162: colorScheme, series.getLabel());
163: if (symbolStyle != JCSymbolStyle.NONE) {
164: series.getStyle().setSymbolShape(symbolStyle);
165: series.getStyle().setSymbolColor(
166: colorTable.getSymbolColor(colorScheme,
167: series.getLabel()));
168: series.getStyle().setSymbolSize(
169: colorTable.getSymbolSize(colorScheme,
170: series.getLabel()));
171: }
172: }
173: }
174: }
175: }
176:
177: public void prefDataChanged(InventoryPreferenceData oldData,
178: InventoryPreferenceData newData) {
179: super .prefDataChanged(oldData, newData);
180: String colorScheme = newData.getColorScheme();
181: if (!colorScheme.equals(oldData.getColorScheme())) {
182: setShortfallChartColors(colorScheme);
183: setBarChartColors(colorScheme);
184: }
185: }
186:
187: }
|