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: import org.cougaar.logistics.plugin.inventory.LogisticsInventoryFormatter;
042:
043: import org.cougaar.logistics.ui.inventory.data.InventoryData;
044: import org.cougaar.logistics.ui.inventory.data.InventoryLevel;
045: import org.cougaar.logistics.ui.inventory.data.InventoryScheduleHeader;
046: import org.cougaar.logistics.ui.inventory.data.InventoryScheduleElement;
047:
048: /**
049: * <pre>
050: *
051: * The InventoryLevelChartDataModel is a ChartDataModel for the
052: * InventoryLevelChart. It calculates the inventory
053: * levels for puts them in x and y coordinates.
054: *
055: *
056: * @see InventoryBaseChartDataModel
057: * @see TargetReorderLevelChartDataModel
058: *
059: **/
060:
061: public class InventoryLevelChartDataModel extends
062: InventoryBaseChartDataModel {
063:
064: public static final String INVENTORY_LEVEL_SERIES_LABEL = "Inventory Level";
065:
066: public static final String INVENTORY_LEVEL_LEGEND = "Inventory Key Levels";
067:
068: public InventoryLevelChartDataModel() {
069: this (null, INVENTORY_LEVEL_LEGEND);
070: }
071:
072: public InventoryLevelChartDataModel(String legendTitle) {
073: this (null, legendTitle);
074: }
075:
076: public InventoryLevelChartDataModel(InventoryData data,
077: String theLegendTitle) {
078: inventory = data;
079: legendTitle = theLegendTitle;
080: nSeries = 1;
081: seriesLabels = new String[nSeries];
082: seriesLabels[0] = INVENTORY_LEVEL_SERIES_LABEL;
083: logger = Logging.getLogger(this );
084: initValues();
085: }
086:
087: public void setValues() {
088: if (valuesSet)
089: return;
090: setInventoryValues();
091: valuesSet = true;
092: }
093:
094: public void setInventoryValues() {
095:
096: if (inventory == null) {
097: xvalues = new double[nSeries][0];
098: yvalues = new double[nSeries][0];
099: return;
100: }
101:
102: InventoryScheduleHeader schedHeader = (InventoryScheduleHeader) inventory
103: .getSchedules()
104: .get(LogisticsInventoryFormatter.INVENTORY_LEVELS_TAG);
105: ArrayList levels = schedHeader.getSchedule();
106:
107: computeCriticalNValues();
108:
109: xvalues = new double[nSeries][];
110: yvalues = new double[nSeries][];
111: //initZeroYVal(nValues);
112: for (int i = 0; i < nSeries; i++) {
113: xvalues[i] = new double[nValues];
114: yvalues[i] = new double[nValues];
115: for (int j = 0; j < nValues; j++) {
116: xvalues[i][j] = minBucket + (j * bucketDays);
117: yvalues[i][j] = 0;
118: }
119: }
120:
121: ArrayList targetLevels = new ArrayList();
122: ArrayList orgActLevels = new ArrayList();
123:
124: //Need to add target level which is a little more complicated
125: //than you think. We don't know how many values there are
126: //in this third series. We have to add them if they are non null
127: //to a vector, allocated the third series same length as the
128: //vector and put them into there. mildly tricky business.
129: for (int i = 0; i < levels.size(); i++) {
130: InventoryLevel level = (InventoryLevel) levels.get(i);
131: long startTime = level.getStartTime();
132: long endTime = level.getEndTime();
133: int startBucket = (int) computeBucketFromTime(startTime);
134: int endBucket = (int) computeBucketFromTime(endTime);
135: Double invQty = level.getInventoryLevel();
136: for (int j = startBucket; j <= endBucket; j += bucketDays) {
137: if (invQty != null) {
138: try {
139: yvalues[0][(j - minBucket) / bucketDays] = (invQty
140: .doubleValue() * unitFactor);
141: } catch (java.lang.NullPointerException e) {
142: System.out.println("Yikes NPE! " + invQty + " "
143: + invQty.doubleValue()
144: + " unit Factor: " + unitFactor);
145: throw e;
146: }
147: }
148:
149: }
150: }
151: }
152:
153: }
|