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.ArrayList;
030:
031: import com.klg.jclass.chart.ChartDataModel;
032: import com.klg.jclass.chart.LabelledChartDataModel;
033: import com.klg.jclass.chart.ChartDataSupport;
034: import com.klg.jclass.chart.ChartDataEvent;
035: import com.klg.jclass.chart.ChartDataManageable;
036: import com.klg.jclass.chart.ChartDataManager;
037:
038: import org.cougaar.util.log.Logging;
039: import org.cougaar.util.log.Logger;
040:
041: /**
042: * <pre>
043: *
044: * The ShortfallChartDataModel is the ChartDataModel for the
045: * calculation of shortfall lines from chartdatamodels that
046: * contain requested and allocation results displayed in their
047: * y coordinates.
048: *
049: * @see InventoryBaseChartDataModel
050: * @see RequisitionsChartDataModel
051: * @see ProjectionsChartDataModel
052: *
053: **/
054:
055: public class ShortfallChartDataModel extends
056: InventoryBaseChartDataModel {
057:
058: protected RequisitionsChartDataModel reqModel;
059: protected ProjectionsChartDataModel projModel;
060: protected boolean shortfallExists;
061:
062: public static final String SHORTFALL_SERIES_LABEL = "Shortfall";
063: public static final String SHORTFALL_LEGEND = "";
064:
065: public static final int REQUESTED_SERIES_INDEX = 0;
066: public static final int ACTUAL_SERIES_INDEX = 1;
067:
068: public ShortfallChartDataModel() {
069: inventory = null;
070: logger = Logging.getLogger(this );
071: }
072:
073: public ShortfallChartDataModel(RequisitionsChartDataModel reqDM,
074: ProjectionsChartDataModel projDM) {
075: this (SHORTFALL_LEGEND, reqDM, projDM);
076: }
077:
078: public ShortfallChartDataModel(String theLegendTitle,
079: RequisitionsChartDataModel reqDM,
080: ProjectionsChartDataModel projDM) {
081: inventory = null;
082: legendTitle = theLegendTitle;
083: reqModel = reqDM;
084: projModel = projDM;
085: nSeries = 1;
086: seriesLabels = new String[nSeries];
087: seriesLabels[0] = SHORTFALL_SERIES_LABEL;
088: logger = Logging.getLogger(this );
089: initValues();
090: }
091:
092: public boolean isShortfall() {
093: return shortfallExists;
094: }
095:
096: public void setValues() {
097: if (valuesSet)
098: return;
099: setShortfallValues();
100: valuesSet = true;
101: }
102:
103: public void setShortfallValues() {
104: shortfallExists = false;
105: if ((reqModel.getNumSeries() == 0)
106: || (projModel.getNumSeries() == 0)) {
107: return;
108: }
109: nValues = reqModel.getXSeries(0).length;
110: if (nValues != projModel.getXSeries(0).length) {
111: return;
112: }
113:
114: xvalues = new double[nSeries][];
115: yvalues = new double[nSeries][nValues];
116:
117: xvalues[0] = reqModel.getXSeries(0);
118:
119: if (nValues == 0) {
120: return;
121: }
122:
123: yvalues[0][0] = ((reqModel.getYSeries(REQUESTED_SERIES_INDEX)[0] - reqModel
124: .getYSeries(ACTUAL_SERIES_INDEX)[0]) + (projModel
125: .getYSeries(REQUESTED_SERIES_INDEX)[0] - projModel
126: .getYSeries(ACTUAL_SERIES_INDEX)[0]));
127: int i;
128:
129: for (i = 1; i < nValues; i++) {
130: yvalues[0][i] = (((reqModel
131: .getYSeries(REQUESTED_SERIES_INDEX)[i] - reqModel
132: .getYSeries(ACTUAL_SERIES_INDEX)[i]) + (projModel
133: .getRealYSeries(REQUESTED_SERIES_INDEX)[i] - projModel
134: .getRealYSeries(ACTUAL_SERIES_INDEX)[i])) + yvalues[0][i - 1]);
135: if (yvalues[0][i] > 0) {
136: shortfallExists = true;
137: }
138: //get rid of negative shortfall
139: else if (yvalues[0][i - 1] < 0) {
140: //yvalues[0][i-1] = 0;
141: }
142: }
143:
144: if ((nValues > 1) && (yvalues[0][nValues - 1] < 0)) {
145: yvalues[0][nValues - 1] = 0;
146: }
147:
148: }
149:
150: public void setDisplayCDay(boolean doUseCDay) {
151: if (doUseCDay != useCDay) {
152: useCDay = doUseCDay;
153: reqModel.setDisplayCDay(useCDay);
154: projModel.setDisplayCDay(useCDay);
155: if (inventory != null) {
156: resetInventory(inventory);
157: }
158: }
159: }
160:
161: }
|