001: /*
002: * <copyright>
003: *
004: * Copyright 2001-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.glm.execution.eg;
027:
028: import org.cougaar.util.OptionPane;
029: import org.cougaar.util.Random;
030: import org.cougaar.glm.execution.common.FailureConsumptionRate;
031:
032: import java.util.Enumeration;
033: import java.util.Hashtable;
034: import java.util.Properties;
035: import java.util.StringTokenizer;
036:
037: import java.awt.GridBagConstraints;
038: import java.awt.GridBagLayout;
039: import java.awt.event.ActionEvent;
040: import java.awt.event.ActionListener;
041:
042: import javax.swing.JComboBox;
043: import javax.swing.JComponent;
044: import javax.swing.JLabel;
045: import javax.swing.JPanel;
046: import javax.swing.JTextField;
047:
048: /**
049: * Example F/C plugin illustrating how one might write a plugin that
050: * applies to a certain class of supply and how to use the GUI
051: * configuration features. Consult the default plugin for more mundane
052: * matters.
053: **/
054: public class POL2Plugin extends TripletFCPlugin {
055: private String prefix = "POL";
056: private static String[] valueLabels = { "Start Time", "End Time",
057: "Multiplier" };
058: private static Class[] valueClasses = { EGDate.class, EGDate.class,
059: Double.class };
060:
061: protected class TripletValueImpl implements TripletValue {
062: private long startDate;
063: private long endDate;
064: private double multiplier;
065:
066: public TripletValueImpl(long start, long end, double mult) {
067: startDate = start;
068: endDate = end;
069: multiplier = mult;
070: }
071:
072: public long getStartDate() {
073: return startDate;
074: }
075:
076: public long getEndDate() {
077: return endDate;
078: }
079:
080: public AnnotatedDouble getMultiplier() {
081: return new AnnotatedDouble(multiplier);
082: }
083:
084: public int getFieldCount() {
085: return 3;
086: }
087:
088: public Object getFieldValue(int ix) {
089: switch (ix) {
090: case 0:
091: return new EGDate(startDate);
092: case 1:
093: return new EGDate(endDate);
094: case 2:
095: return new Double(multiplier);
096: default:
097: return "";
098: }
099: }
100:
101: public Object getDefaultFieldValue(int ix) {
102: switch (ix) {
103: case 0:
104: return new EGDate(theEventGenerator.getExecutionTime());
105: case 1:
106: return new EGDate(theEventGenerator.getExecutionTime()
107: + 1800L * ONE_DAY);
108: case 2:
109: return new Double(1.0);
110: default:
111: return "";
112: }
113: }
114:
115: public String toString() {
116: return new StringBuffer().append(getFieldValue(0)).append(
117: ",").append(getFieldValue(1)).append(",").append(
118: getFieldValue(2)).toString();
119: }
120: }
121:
122: protected TripletValue createTripletValue(String[] args) {
123: long guiStart = new EGDate(args[0]).getTime();
124: long guiEnd = new EGDate(args[1]).getTime();
125: double multiplier = Double.parseDouble(args[2]);
126: return new TripletValueImpl(guiStart, guiEnd, multiplier);
127: }
128:
129: protected String[] getTripletValueNames() {
130: return valueLabels;
131: }
132:
133: protected Class[] getTripletValueClasses() {
134: return valueClasses;
135: }
136:
137: protected Object[] getTripletDefaultValues() {
138: Object[] result = {
139: new EGDate(theEventGenerator.getExecutionTime()),
140: new EGDate(theEventGenerator.getExecutionTime() + 1800L
141: * ONE_DAY), new Double(1.0), };
142: return result;
143: }
144:
145: /**
146: * @return the name of this plugin
147: **/
148: public String getPluginName() {
149: return "POL Special";
150: }
151:
152: public String getDescription() {
153: return "Special plugin for POL items that uses a fixed rate";
154: }
155:
156: public void setParameter(String parameter) {
157: prefix = parameter; // parameter is item prefix.
158: }
159:
160: /**
161: * Create a FailureConsumptionItem for this plugin to handle a
162: * particular FailureConsumptionRate. If the consumable is a
163: * suitable item (POL NSN), use the base class method, else return
164: * null.
165: **/
166: public FailureConsumptionPluginItem createFailureConsumptionItem(
167: FailureConsumptionRate aRate,
168: FailureConsumptionSegment aSegment, long theExecutionTime,
169: FailureConsumptionPluginItem aFailureConsumptionPluginItem) {
170:
171: // Check if it's fuel (by FSC)
172: // NOTE: We may need to check by the NSN if the FSC doesn't work
173: if ((aRate.theItemIdentification.startsWith("NSN/9130"))
174: || (aRate.theItemIdentification.startsWith("NSN/9140"))) {
175: System.out.println("Adding " + aRate.theItemIdentification);
176: return super .createFailureConsumptionItem(aRate, aSegment,
177: theExecutionTime, aFailureConsumptionPluginItem);
178: } else {
179: System.out.println("Ignoring "
180: + aRate.theItemIdentification);
181: }
182: return null;
183: }
184: }
|