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 TargetReorderLevelChartDataModel is a ChartDataModel for the
052: * InventoryLevelChart. It calculates the
053: * target and reorder levels for puts them in x and y coordinates.
054: *
055: *
056: * @see InventoryBaseChartDataModel
057: * @see InventoryLevelChartDataModel
058: *
059: **/
060:
061: public class TargetReorderLevelChartDataModel extends
062: InventoryBaseChartDataModel {
063:
064: public static final int REORDER_LEVEL_SERIES_INDEX = 0;
065: public static final int TARGET_LEVEL_SERIES_INDEX = 1;
066:
067: public static final String TARGET_LEVEL_SERIES_LABEL = "Target Level";
068: public static final String REORDER_LEVEL_SERIES_LABEL = "Reorder Level";
069:
070: //public static final String SYMBOL = " Symbol";
071:
072: public static final String TARGET_REORDER_LEVEL_LEGEND = "Target And Reorder Levels";
073:
074: public TargetReorderLevelChartDataModel() {
075: this (null, TARGET_REORDER_LEVEL_LEGEND);
076: }
077:
078: public TargetReorderLevelChartDataModel(String legendTitle) {
079: this (null, legendTitle);
080: }
081:
082: public TargetReorderLevelChartDataModel(InventoryData data,
083: String theLegendTitle) {
084: inventory = data;
085: legendTitle = theLegendTitle;
086: nSeries = 2;
087: seriesLabels = new String[nSeries];
088: seriesLabels[0] = REORDER_LEVEL_SERIES_LABEL;
089: seriesLabels[1] = TARGET_LEVEL_SERIES_LABEL;
090: logger = Logging.getLogger(this );
091: initValues();
092: }
093:
094: public void setValues() {
095: if (valuesSet)
096: return;
097: setInventoryValues();
098: valuesSet = true;
099: }
100:
101: public void setInventoryValues() {
102:
103: if (inventory == null) {
104: xvalues = new double[nSeries][0];
105: yvalues = new double[nSeries][0];
106: return;
107: }
108:
109: InventoryScheduleHeader schedHeader = (InventoryScheduleHeader) inventory
110: .getSchedules()
111: .get(LogisticsInventoryFormatter.INVENTORY_LEVELS_TAG);
112: ArrayList levels = schedHeader.getSchedule();
113:
114: computeCriticalNValues();
115:
116: xvalues = new double[nSeries][];
117: yvalues = new double[nSeries][];
118: //initZeroYVal(nValues);
119: for (int i = 0; i < (nSeries - 1); i++) {
120: xvalues[i] = new double[nValues];
121: yvalues[i] = new double[nValues];
122: for (int j = 0; j < nValues; j++) {
123: xvalues[i][j] = minBucket + (j * bucketDays);
124: yvalues[i][j] = 0;
125: }
126: }
127:
128: ArrayList targetLevels = new ArrayList();
129:
130: //Need to add target level which is a little more complicated
131: //than you think. We don't know how many values there are
132: //in this third series. We have to add them if they are non null
133: //to a vector, allocated the third series same length as the
134: //vector and put them into there. mildly tricky business.
135: for (int i = 0; i < levels.size(); i++) {
136: InventoryLevel level = (InventoryLevel) levels.get(i);
137: long startTime = level.getStartTime();
138: long endTime = level.getEndTime();
139: int startBucket = (int) computeBucketFromTime(startTime);
140: int endBucket = (int) computeBucketFromTime(endTime);
141: double reorderQty = level.getReorderLevel();
142: for (int j = startBucket; j <= endBucket; j += bucketDays) {
143: yvalues[0][(j - minBucket) / bucketDays] = (reorderQty * unitFactor);
144: }
145: if (level.getTargetLevel() != null) {
146: targetLevels.add(level);
147: }
148: }
149:
150: xvalues[1] = new double[targetLevels.size()];
151: yvalues[1] = new double[targetLevels.size()];
152:
153: for (int i = 0; i < targetLevels.size(); i++) {
154: InventoryLevel level = (InventoryLevel) targetLevels.get(i);
155: long startTime = level.getStartTime();
156: int startDay = (int) computeBucketFromTime(startTime);
157: double targetLevel = level.getTargetLevel().doubleValue();
158: xvalues[1][i] = startDay;
159: yvalues[1][i] = (targetLevel * unitFactor);
160: }
161: }
162: }
|