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.dialog;
028:
029: import java.util.*;
030:
031: import javax.swing.*;
032: import javax.swing.event.MouseInputAdapter;
033:
034: import java.awt.event.ActionListener;
035: import java.awt.event.ActionEvent;
036: import java.awt.event.WindowEvent;
037: import java.awt.event.WindowAdapter;
038: import java.awt.*;
039: import java.awt.event.MouseEvent;
040: import java.awt.event.MouseListener;
041:
042: import java.io.File;
043: import java.io.FileWriter;
044: import java.io.FileReader;
045: import java.io.BufferedReader;
046: import java.io.IOException;
047:
048: import org.cougaar.util.log.Logging;
049: import org.cougaar.util.log.Logger;
050:
051: import org.cougaar.logistics.ui.inventory.data.InventoryPreferenceData;
052: import org.cougaar.logistics.ui.inventory.InventoryUIFrame;
053: import org.cougaar.logistics.ui.inventory.InventoryMenuEvent;
054:
055: /**
056: * <pre>
057: *
058: * The InventoryPreferenceTab is an almost abstract superclass that all the tabs
059: * for the InventoryPreferenceDialog inherit from. It basically provides back
060: * pointers and common functionality to all the tabs going into the dialog
061: *
062: * @see InventoryPreferenceDialog
063: * @see InventoryPreferenceData
064: *
065: **/
066:
067: public class StartUpTab extends PreferenceDialogTab {
068:
069: public static String CDAY_TIME_SCALE = "C-Days";
070: public static String CALENDAR_TIME_SCALE = "Calendar Days";
071: public static String DISPLAY_SHORTFALL = "Display Shortfall Plot Initially";
072: public static String DONT_DISPLAY_SHORTFALL = "Hide Shortfall Plot Initially";
073:
074: public static String SHOW_INVENTORY_CHART = InventoryMenuEvent.MENU_InventoryChart;
075: public static String SHOW_REFILL_CHART = InventoryMenuEvent.MENU_RefillChart;
076: public static String SHOW_DEMAND_CHART = InventoryMenuEvent.MENU_DemandChart;
077:
078: protected ButtonGroup timeScaleGroup;
079: protected ButtonGroup showShortfallGroup;
080:
081: protected JCheckBox showInventoryCheck;
082: protected JCheckBox showDemandCheck;
083: protected JCheckBox showRefillCheck;
084:
085: public StartUpTab(InventoryUIFrame invUIFrame,
086: InventoryPreferenceDialog invUIDialog,
087: InventoryPreferenceData data) {
088: super (invUIFrame, invUIDialog, data);
089: }
090:
091: protected void doTabLayout() {
092:
093: setLayout(new GridBagLayout());
094:
095: JLabel timeScaleLabel = new JLabel("X-Axis Time Scale: ",
096: JLabel.LEFT);
097: timeScaleGroup = new ButtonGroup();
098: JRadioButton cdayRadio = new JRadioButton(CDAY_TIME_SCALE,
099: prefData.startupWCDay);
100: cdayRadio.setActionCommand(CDAY_TIME_SCALE);
101: cdayRadio.addItemListener(this );
102: JRadioButton calendarRadio = new JRadioButton(
103: CALENDAR_TIME_SCALE, !prefData.startupWCDay);
104: calendarRadio.setActionCommand(CALENDAR_TIME_SCALE);
105: calendarRadio.addItemListener(this );
106:
107: timeScaleGroup.add(cdayRadio);
108: timeScaleGroup.add(calendarRadio);
109:
110: JPanel timeScalePanel = new JPanel();
111: timeScalePanel.setLayout(new GridLayout(2, 1));
112: timeScalePanel.setBorder(BorderFactory.createEmptyBorder(2, 2,
113: 2, 2));
114: timeScalePanel.add(timeScaleLabel);
115: JPanel radioPanel = new JPanel();
116: radioPanel.setLayout(new GridLayout(1, 2));
117: radioPanel.add(cdayRadio);
118: radioPanel.add(calendarRadio);
119: timeScalePanel.add(radioPanel);
120:
121: JLabel initShortfallLabel = new JLabel(
122: "Display shortfall when detected, or only if selected: ",
123: JLabel.LEFT);
124: showShortfallGroup = new ButtonGroup();
125: JRadioButton showShortfallRadio = new JRadioButton(
126: DISPLAY_SHORTFALL, prefData.displayShortfall);
127: showShortfallRadio.setActionCommand(DISPLAY_SHORTFALL);
128: showShortfallRadio.addItemListener(this );
129: JRadioButton noshowShortfallRadio = new JRadioButton(
130: DONT_DISPLAY_SHORTFALL, !prefData.displayShortfall);
131: noshowShortfallRadio.setActionCommand(DONT_DISPLAY_SHORTFALL);
132: noshowShortfallRadio.addItemListener(this );
133:
134: showShortfallGroup.add(showShortfallRadio);
135: showShortfallGroup.add(noshowShortfallRadio);
136:
137: JPanel showShortfallPanel = new JPanel();
138: showShortfallPanel.setLayout(new GridLayout(2, 1));
139: showShortfallPanel.setBorder(BorderFactory.createEmptyBorder(2,
140: 2, 2, 2));
141: showShortfallPanel.add(initShortfallLabel);
142: radioPanel = new JPanel();
143: radioPanel.setLayout(new GridLayout(1, 2));
144: radioPanel.add(showShortfallRadio);
145: radioPanel.add(noshowShortfallRadio);
146: showShortfallPanel.add(radioPanel);
147:
148: JLabel startupChartsLabel = new JLabel(
149: "Select Charts to display:", JLabel.LEFT);
150: showInventoryCheck = new JCheckBox(SHOW_INVENTORY_CHART,
151: prefData.showInventoryChart);
152: showInventoryCheck.setActionCommand(SHOW_INVENTORY_CHART);
153: showInventoryCheck.addItemListener(this );
154: showRefillCheck = new JCheckBox(SHOW_REFILL_CHART,
155: prefData.showRefillChart);
156: showRefillCheck.setActionCommand(SHOW_REFILL_CHART);
157: showRefillCheck.addItemListener(this );
158: showDemandCheck = new JCheckBox(SHOW_DEMAND_CHART,
159: prefData.showDemandChart);
160: showDemandCheck.setActionCommand(SHOW_DEMAND_CHART);
161: showDemandCheck.addItemListener(this );
162:
163: JPanel showChartsPanel = new JPanel();
164: showChartsPanel.setLayout(new GridLayout(2, 1));
165: showChartsPanel.setBorder(BorderFactory.createEmptyBorder(2, 2,
166: 2, 2));
167: showChartsPanel.add(startupChartsLabel);
168: JPanel checkPanel = new JPanel();
169: checkPanel.setLayout(new GridLayout(1, 3));
170: checkPanel.add(showInventoryCheck);
171: checkPanel.add(showRefillCheck);
172: checkPanel.add(showDemandCheck);
173: showChartsPanel.add(checkPanel);
174:
175: int gridx = 0;
176: int gridy = 0;
177: Insets blankInsets = new Insets(5, 10, 5, 10);
178:
179: int height = 1;
180: gridy += height;
181:
182: add(timeScalePanel, new GridBagConstraints(gridx, gridy, 1,
183: height, 1.0, 0.8, GridBagConstraints.WEST,
184: GridBagConstraints.HORIZONTAL, blankInsets, 0, 0));
185:
186: height = 1;
187: gridy += height;
188:
189: add(showShortfallPanel, new GridBagConstraints(gridx, gridy, 1,
190: height, 1.0, 0.8, GridBagConstraints.WEST,
191: GridBagConstraints.HORIZONTAL, blankInsets, 0, 0));
192:
193: height = 1;
194: gridy += height;
195:
196: add(showChartsPanel, new GridBagConstraints(gridx, gridy, 1,
197: height, 1.0, 0.8, GridBagConstraints.WEST,
198: GridBagConstraints.HORIZONTAL, blankInsets, 0, 0));
199:
200: height = 2;
201: gridy += height;
202:
203: JPanel spaceFiller = new JPanel();
204: spaceFiller.add(Box.createVerticalStrut(30));
205:
206: add(spaceFiller, new GridBagConstraints(gridx, gridy, 1,
207: height, 1.0, 1.0, GridBagConstraints.WEST,
208: GridBagConstraints.BOTH, blankInsets, 0, 0));
209:
210: }
211:
212: public void flushValuesToData() {
213: if (prefsChanged()) {
214: prefData.startupWCDay = timeScaleGroup.getSelection()
215: .getActionCommand().equals(CDAY_TIME_SCALE);
216: prefData.displayShortfall = showShortfallGroup
217: .getSelection().getActionCommand().equals(
218: DISPLAY_SHORTFALL);
219: prefData.showInventoryChart = showInventoryCheck
220: .isSelected();
221: prefData.showRefillChart = showRefillCheck.isSelected();
222: prefData.showDemandChart = showDemandCheck.isSelected();
223: }
224: super.flushValuesToData();
225: }
226:
227: }
|