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: package org.cougaar.logistics.ui.inventory;
027:
028: import org.cougaar.logistics.ui.inventory.data.InventoryPreferenceData;
029:
030: import java.awt.Color;
031: import java.util.Hashtable;
032:
033: import com.klg.jclass.chart.JCFillStyle;
034: import com.klg.jclass.chart.JCLineStyle;
035: import com.klg.jclass.chart.ChartDataView;
036: import com.klg.jclass.chart.JCSymbolStyle;
037:
038: public class InventoryColorTable {
039: private static final String BACKGROUND = "Background";
040: private static final String FILL_PATTERN = "Fill Pattern";
041: private static final String LINE_WIDTH = "Line Width";
042: private static final String OUTLINE = "Outline";
043: private static final String SYMBOL = "Symbol";
044: private static final String SYMBOL_COLOR = "Symbol Color";
045: private static final String SYMBOL_SIZE = "Symbol Size";
046:
047: private Hashtable colorTables; // maps color schemes (Strings) to color tables (hashtables)
048:
049: // this specifies the order in which the labels appear in the gui
050: private static final String[] labels = {
051: InventoryLevelChartDataModel.INVENTORY_LEVEL_SERIES_LABEL,
052: TargetReorderLevelChartDataModel.REORDER_LEVEL_SERIES_LABEL,
053: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL,
054: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL
055: + SYMBOL,
056: OrgActivityChartDataModel.OFFENSIVE_SERIES_LABEL,
057: OrgActivityChartDataModel.DEFENSIVE_SERIES_LABEL,
058: RequisitionsChartDataModel.REQUISITION_SERIES_LABEL,
059: RequisitionsChartDataModel.REQUISITION_ALLOCATION_SERIES_LABEL,
060: ProjectionsChartDataModel.PROJECTION_SERIES_LABEL,
061: ProjectionsChartDataModel.PROJECTION_ALLOCATION_SERIES_LABEL,
062: ShortfallChartDataModel.SHORTFALL_SERIES_LABEL
063: //TODO: Remove all references to BelowZeroHighlightChartDataModel
064: // BelowZeroHighlightChartDataModel.BELOW_ZERO_SERIES_LABEL
065: };
066:
067: // TODO: this should create all of the color schemes that we define
068: // then the get color method could either take a color scheme argument
069: // or we could define a global color scheme
070: public InventoryColorTable() {
071: colorTables = new Hashtable();
072:
073: colorTables.put(InventoryPreferenceData.COLOR_SCHEME_NORMAL,
074: initNormalColorTable());
075: // colorTables.put(InventoryPreferenceData.COLOR_SCHEME_RG_COLORBLIND, initRGColorBlindColorTable());
076: colorTables.put(InventoryPreferenceData.COLOR_SCHEME_BW,
077: initBWColorTable());
078: }
079:
080: private Hashtable initNormalColorTable() {
081: Hashtable colorTable = new Hashtable();
082: colorTable
083: .put(
084: InventoryLevelChartDataModel.INVENTORY_LEVEL_SERIES_LABEL,
085: new Color(51, 153, 0));
086: colorTable
087: .put(
088: TargetReorderLevelChartDataModel.REORDER_LEVEL_SERIES_LABEL,
089: Color.black);
090: colorTable
091: .put(
092: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL,
093: Color.yellow);
094:
095: colorTable.put(InventoryLevelChartDataModel.class.getName()
096: + OUTLINE, new Color(51, 102, 0));
097: colorTable.put(InventoryShortfallChartDataModel.class.getName()
098: + OUTLINE, new Color(153, 0, 0));
099: colorTable.put(OrgActivityChartDataModel.class.getName()
100: + OUTLINE, Color.gray);
101:
102: colorTable
103: .put(
104: InventoryLevelChartDataModel.INVENTORY_LEVEL_SERIES_LABEL
105: + LINE_WIDTH, new Integer(2));
106: colorTable
107: .put(
108: TargetReorderLevelChartDataModel.REORDER_LEVEL_SERIES_LABEL
109: + LINE_WIDTH, new Integer(2));
110: colorTable
111: .put(
112: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL
113: + LINE_WIDTH, new Integer(2));
114:
115: colorTable.put(
116: OrgActivityChartDataModel.ORG_ACTIVITY_SERIES_LABEL,
117: Color.white); // not used
118: colorTable.put(
119: OrgActivityChartDataModel.OFFENSIVE_SERIES_LABEL,
120: Color.white);
121: colorTable.put(
122: OrgActivityChartDataModel.DEFENSIVE_SERIES_LABEL,
123: Color.lightGray);
124: colorTable.put(ShortfallChartDataModel.SHORTFALL_SERIES_LABEL,
125: new Color(255, 0, 0)); //red?
126: colorTable.put(
127: RequisitionsChartDataModel.REQUISITION_SERIES_LABEL,
128: new Color(0, 230, 0)); //green?
129: colorTable
130: .put(
131: RequisitionsChartDataModel.REQUISITION_ALLOCATION_SERIES_LABEL,
132: new Color(200, 255, 200)); //light green?
133: colorTable.put(
134: ProjectionsChartDataModel.PROJECTION_SERIES_LABEL,
135: new Color(0, 0, 255)); //blue
136: colorTable
137: .put(
138: ProjectionsChartDataModel.PROJECTION_ALLOCATION_SERIES_LABEL,
139: new Color(170, 170, 255)); //light blue?
140: /** TODO remove BelowZeroHighlightChartDataModel refs
141: colorTable.put(BelowZeroHighlightChartDataModel.BELOW_ZERO_SERIES_LABEL,
142: new Color(255, 255, 240)); // light yellow
143: */
144:
145: colorTable
146: .put(
147: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL
148: + SYMBOL, new Integer(
149: JCSymbolStyle.VERT_LINE));
150: colorTable
151: .put(
152: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL
153: + SYMBOL_COLOR, Color.blue);
154: colorTable
155: .put(
156: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL
157: + SYMBOL_SIZE, new Integer(4));
158:
159: return colorTable;
160: }
161:
162: // for debugging, use arbitrary different colors, so we can distinguish which color table is in use
163: private Hashtable initRGColorBlindColorTable() {
164: Hashtable colorTable = new Hashtable();
165: colorTable
166: .put(
167: InventoryLevelChartDataModel.INVENTORY_LEVEL_SERIES_LABEL,
168: Color.orange);
169: colorTable
170: .put(
171: TargetReorderLevelChartDataModel.REORDER_LEVEL_SERIES_LABEL,
172: Color.green);
173: colorTable
174: .put(
175: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL,
176: Color.cyan);
177:
178: colorTable.put(OrgActivityChartDataModel.class.getName()
179: + OUTLINE, Color.gray);
180:
181: colorTable.put(
182: OrgActivityChartDataModel.ORG_ACTIVITY_SERIES_LABEL,
183: Color.white); // not used
184: colorTable.put(
185: OrgActivityChartDataModel.OFFENSIVE_SERIES_LABEL,
186: Color.blue);
187: colorTable.put(
188: OrgActivityChartDataModel.DEFENSIVE_SERIES_LABEL,
189: Color.green);
190: colorTable.put(ShortfallChartDataModel.SHORTFALL_SERIES_LABEL,
191: Color.orange); //red?
192: colorTable.put(
193: RequisitionsChartDataModel.REQUISITION_SERIES_LABEL,
194: Color.green); //green?
195: colorTable
196: .put(
197: RequisitionsChartDataModel.REQUISITION_ALLOCATION_SERIES_LABEL,
198: Color.red); //light green?
199: colorTable.put(
200: ProjectionsChartDataModel.PROJECTION_SERIES_LABEL,
201: Color.cyan); //blue
202: colorTable
203: .put(
204: ProjectionsChartDataModel.PROJECTION_ALLOCATION_SERIES_LABEL,
205: Color.orange); //light blue?
206: /** TODO remove BelowZeroHighlightChartDataModel refs
207: colorTable.put(BelowZeroHighlightChartDataModel.BELOW_ZERO_SERIES_LABEL,
208: Color.green); // light yellow
209: */
210:
211: colorTable
212: .put(
213: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL
214: + SYMBOL,
215: new Integer(JCSymbolStyle.DOT));
216: colorTable
217: .put(
218: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL
219: + SYMBOL_COLOR, Color.magenta);
220: colorTable
221: .put(
222: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL
223: + SYMBOL_SIZE, new Integer(4));
224:
225: return colorTable;
226: }
227:
228: private Hashtable initBWColorTable() {
229: Hashtable colorTable = new Hashtable();
230:
231: // these are represented as lines
232: colorTable
233: .put(
234: InventoryLevelChartDataModel.INVENTORY_LEVEL_SERIES_LABEL,
235: Color.black);
236: colorTable
237: .put(
238: TargetReorderLevelChartDataModel.REORDER_LEVEL_SERIES_LABEL,
239: Color.black);
240: colorTable
241: .put(
242: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL,
243: Color.black);
244: colorTable.put(ShortfallChartDataModel.SHORTFALL_SERIES_LABEL,
245: Color.black); //red
246:
247: colorTable
248: .put(
249: InventoryLevelChartDataModel.INVENTORY_LEVEL_SERIES_LABEL
250: + LINE_WIDTH, new Integer(4));
251: colorTable
252: .put(
253: TargetReorderLevelChartDataModel.REORDER_LEVEL_SERIES_LABEL
254: + LINE_WIDTH, new Integer(2));
255: colorTable
256: .put(
257: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL
258: + LINE_WIDTH, new Integer(1));
259:
260: colorTable.put(OrgActivityChartDataModel.class.getName()
261: + OUTLINE, Color.gray);
262:
263: colorTable.put(
264: OrgActivityChartDataModel.ORG_ACTIVITY_SERIES_LABEL,
265: Color.white); // not used
266: colorTable.put(
267: OrgActivityChartDataModel.OFFENSIVE_SERIES_LABEL,
268: Color.white);
269: colorTable.put(
270: OrgActivityChartDataModel.DEFENSIVE_SERIES_LABEL,
271: Color.lightGray);
272:
273: /** TODO remove BelowZeroHighlightChartDataModel refs
274: colorTable.put(BelowZeroHighlightChartDataModel.BELOW_ZERO_SERIES_LABEL,
275: new Color(255, 255, 240)); // light yellow
276: */
277:
278: // these are represented as bar charts
279: colorTable.put(
280: RequisitionsChartDataModel.REQUISITION_SERIES_LABEL,
281: Color.black);
282: colorTable
283: .put(
284: RequisitionsChartDataModel.REQUISITION_ALLOCATION_SERIES_LABEL,
285: Color.black);
286: colorTable.put(
287: ProjectionsChartDataModel.PROJECTION_SERIES_LABEL,
288: Color.black);
289: colorTable
290: .put(
291: ProjectionsChartDataModel.PROJECTION_ALLOCATION_SERIES_LABEL,
292: Color.black);
293:
294: colorTable.put(
295: RequisitionsChartDataModel.REQUISITION_SERIES_LABEL
296: + BACKGROUND, Color.white);
297: colorTable
298: .put(
299: RequisitionsChartDataModel.REQUISITION_ALLOCATION_SERIES_LABEL
300: + BACKGROUND, Color.white);
301: colorTable.put(
302: ProjectionsChartDataModel.PROJECTION_SERIES_LABEL
303: + BACKGROUND, Color.white);
304: colorTable
305: .put(
306: ProjectionsChartDataModel.PROJECTION_ALLOCATION_SERIES_LABEL
307: + BACKGROUND, Color.white);
308:
309: colorTable.put(
310: RequisitionsChartDataModel.REQUISITION_SERIES_LABEL
311: + FILL_PATTERN, new Integer(
312: JCFillStyle.STRIPE_45));
313: colorTable
314: .put(
315: RequisitionsChartDataModel.REQUISITION_ALLOCATION_SERIES_LABEL
316: + FILL_PATTERN, new Integer(
317: JCFillStyle.STRIPE_135));
318: colorTable
319: .put(ProjectionsChartDataModel.PROJECTION_SERIES_LABEL
320: + FILL_PATTERN, new Integer(JCFillStyle.PER_75));
321: colorTable
322: .put(
323: ProjectionsChartDataModel.PROJECTION_ALLOCATION_SERIES_LABEL
324: + FILL_PATTERN, new Integer(
325: JCFillStyle.PER_25));
326: colorTable
327: .put(
328: InventoryLevelChartDataModel.INVENTORY_LEVEL_SERIES_LABEL
329: + FILL_PATTERN, new Integer(
330: JCFillStyle.PER_25));
331:
332: colorTable
333: .put(
334: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL
335: + SYMBOL,
336: new Integer(JCSymbolStyle.DOT));
337: colorTable
338: .put(
339: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL
340: + SYMBOL_COLOR, Color.black);
341: colorTable
342: .put(
343: TargetReorderLevelChartDataModel.TARGET_LEVEL_SERIES_LABEL
344: + SYMBOL_SIZE, new Integer(5));
345:
346: return colorTable;
347: }
348:
349: /**
350: * Get the color to use in a chart.
351: * @param colorScheme the color scheme in use; see InventoryPreferenceData for definitions
352: * @param s the series or symbol name; one of the labels above
353: * @return color to use
354: */
355: public Color get(String colorScheme, String s) {
356: Hashtable colorTable = (Hashtable) colorTables.get(colorScheme);
357: return (Color) colorTable.get(s);
358: }
359:
360: /**
361: * Get the color to use in a chart.
362: * @param colorScheme the color scheme in use; see InventoryPreferenceData for definitions
363: * @param view the chart data view ; the data model class name is used to diff on outline
364: * @return color to use
365: */
366: public Color getOutlineColor(String colorScheme, ChartDataView view) {
367: Hashtable colorTable = (Hashtable) colorTables.get(colorScheme);
368: Color outlineColor = (Color) colorTable.get(view
369: .getDataSource().getClass().getName()
370: + OUTLINE);
371: if (outlineColor == null) {
372: return Color.black;
373: }
374: return outlineColor;
375: }
376:
377: /**
378: * Get the background color to use, if the fill pattern is not solid.
379: * @param colorScheme the color scheme in use; see InventoryPreferenceData for definitions
380: * @param s the series or symbol name; one of the labels above
381: * @return color to use
382: */
383: public Color getBackgroundColor(String colorScheme, String s) {
384: Hashtable colorTable = (Hashtable) colorTables.get(colorScheme);
385: return (Color) colorTable.get(s + BACKGROUND);
386: }
387:
388: /**
389: * Get the fill pattern to use.
390: * @param colorScheme the color scheme in use; see InventoryPreferenceData for definitions
391: * @param s the series or symbol name; one of the labels above
392: * @return color to use
393: */
394: public int getFillPattern(String colorScheme, String s) {
395: Hashtable colorTable = (Hashtable) colorTables.get(colorScheme);
396: Integer fillPattern = (Integer) colorTable
397: .get(s + FILL_PATTERN);
398: if (fillPattern == null)
399: return JCFillStyle.SOLID; // default
400: return fillPattern.intValue();
401: }
402:
403: public int getLineWidth(String colorScheme, String s) {
404: Hashtable colorTable = (Hashtable) colorTables.get(colorScheme);
405: Integer lineWidth = (Integer) colorTable.get(s + LINE_WIDTH);
406: if (lineWidth == null)
407: return 1; // default
408: return lineWidth.intValue();
409: }
410:
411: public int getSymbolShape(String colorScheme, String s) {
412: Hashtable colorTable = (Hashtable) colorTables.get(colorScheme);
413: Integer symbolStyle = (Integer) colorTable.get(s + SYMBOL);
414: if (symbolStyle == null) {
415: return JCSymbolStyle.NONE;
416: }
417: return symbolStyle.intValue();
418: }
419:
420: public int getSymbolSize(String colorScheme, String s) {
421: Hashtable colorTable = (Hashtable) colorTables.get(colorScheme);
422: Integer symbolSize = (Integer) colorTable.get(s + SYMBOL_SIZE);
423: if (symbolSize == null) {
424: return 4;
425: }
426: return symbolSize.intValue();
427: }
428:
429: public Color getSymbolColor(String colorScheme, String s) {
430: Hashtable colorTable = (Hashtable) colorTables.get(colorScheme);
431: Color symColor = (Color) colorTable.get(s + SYMBOL_COLOR);
432: if (symColor == null) {
433: return symColor.black;
434: }
435: return symColor;
436: }
437:
438: public String[] getColorLabels() {
439: return labels;
440: }
441:
442: }
|