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:
054: /**
055: * <pre>
056: *
057: * The InventoryPreferenceTab is an almost abstract superclass that all the tabs
058: * for the InventoryPreferenceDialog inherit from. It basically provides back
059: * pointers and common functionality to all the tabs going into the dialog
060: *
061: * @see InventoryPreferenceDialog
062: * @see InventoryPreferenceData
063: *
064: **/
065:
066: public class UnitPrefTab extends PreferenceDialogTab {
067:
068: public static final String LITERS_LABEL = InventoryPreferenceData.LITERS_LABEL;
069: public static final String CASES_LABEL = InventoryPreferenceData.CASES_LABEL;
070: public static final String BOTTLES_LABEL = InventoryPreferenceData.BOTTLES_LABEL;
071: public static final String TONS_LABEL = InventoryPreferenceData.TONS_LABEL;
072: public static final String ROUNDS_LABEL = InventoryPreferenceData.ROUNDS_LABEL;
073:
074: public static final String ROUND_UNITS_CHECK_LABEL = "Round Units to the nearest whole number";
075:
076: protected ButtonGroup ammoUnitGroup;
077: protected ButtonGroup waterUnitGroup;
078:
079: protected JCheckBox roundUnitsCheck;
080:
081: public UnitPrefTab(InventoryUIFrame invUIFrame,
082: InventoryPreferenceDialog invUIDialog,
083: InventoryPreferenceData data) {
084: super (invUIFrame, invUIDialog, data);
085: }
086:
087: protected void doTabLayout() {
088:
089: setLayout(new GridBagLayout());
090:
091: JLabel ammoUnitLabel = new JLabel("Preferred Ammo Unit: ",
092: JLabel.LEFT);
093: ammoUnitGroup = new ButtonGroup();
094: JRadioButton tonsRadio = new JRadioButton(TONS_LABEL,
095: prefData.ammoUnit == prefData.getUnit(TONS_LABEL));
096: tonsRadio.setActionCommand(TONS_LABEL);
097: tonsRadio.addItemListener(this );
098: JRadioButton roundsRadio = new JRadioButton(ROUNDS_LABEL,
099: prefData.ammoUnit == prefData.getUnit(ROUNDS_LABEL));
100: roundsRadio.setActionCommand(ROUNDS_LABEL);
101: roundsRadio.addItemListener(this );
102:
103: ammoUnitGroup.add(tonsRadio);
104: ammoUnitGroup.add(roundsRadio);
105:
106: JPanel ammoUnitPanel = new JPanel();
107: ammoUnitPanel.setLayout(new GridLayout(2, 1));
108: ammoUnitPanel.setBorder(BorderFactory.createEmptyBorder(2, 2,
109: 2, 2));
110: ammoUnitPanel.add(ammoUnitLabel);
111: JPanel radioPanel = new JPanel();
112: radioPanel.setLayout(new GridLayout(1, 2));
113: radioPanel.add(tonsRadio);
114: radioPanel.add(roundsRadio);
115: ammoUnitPanel.add(radioPanel);
116:
117: JLabel waterUnitLabel = new JLabel("Preferred Water Unit: ",
118: JLabel.LEFT);
119: waterUnitGroup = new ButtonGroup();
120: JRadioButton casesRadio = new JRadioButton(CASES_LABEL,
121: prefData.waterUnit == prefData.getUnit(CASES_LABEL));
122: casesRadio.setActionCommand(CASES_LABEL);
123: casesRadio.addItemListener(this );
124: JRadioButton bottlesRadio = new JRadioButton(BOTTLES_LABEL,
125: prefData.waterUnit == prefData.getUnit(BOTTLES_LABEL));
126: bottlesRadio.setActionCommand(BOTTLES_LABEL);
127: bottlesRadio.addItemListener(this );
128: JRadioButton litersRadio = new JRadioButton(LITERS_LABEL,
129: prefData.waterUnit == prefData.getUnit(LITERS_LABEL));
130: litersRadio.setActionCommand(LITERS_LABEL);
131: litersRadio.addItemListener(this );
132:
133: waterUnitGroup.add(casesRadio);
134: waterUnitGroup.add(bottlesRadio);
135: waterUnitGroup.add(litersRadio);
136:
137: JPanel waterUnitPanel = new JPanel();
138: waterUnitPanel.setLayout(new GridLayout(2, 1));
139: waterUnitPanel.setBorder(BorderFactory.createEmptyBorder(2, 2,
140: 2, 2));
141: waterUnitPanel.add(waterUnitLabel);
142: radioPanel = new JPanel();
143: radioPanel.setLayout(new GridLayout(1, 3));
144: radioPanel.add(casesRadio);
145: radioPanel.add(bottlesRadio);
146: radioPanel.add(litersRadio);
147: waterUnitPanel.add(radioPanel);
148:
149: roundUnitsCheck = new JCheckBox(ROUND_UNITS_CHECK_LABEL,
150: prefData.roundToWholes);
151: roundUnitsCheck.setActionCommand(ROUND_UNITS_CHECK_LABEL);
152: roundUnitsCheck.addItemListener(this );
153:
154: JPanel roundUnitsPanel = new JPanel();
155: roundUnitsPanel.setLayout(new GridLayout(1, 1));
156: roundUnitsPanel.setBorder(BorderFactory.createEmptyBorder(2, 2,
157: 2, 2));
158:
159: roundUnitsPanel.add(roundUnitsCheck);
160:
161: int gridx = 0;
162: int gridy = 0;
163: Insets blankInsets = new Insets(5, 10, 5, 10);
164:
165: int height = 1;
166: gridy += height;
167:
168: add(ammoUnitPanel, new GridBagConstraints(gridx, gridy, 1,
169: height, 1.0, 0.9, GridBagConstraints.WEST,
170: GridBagConstraints.HORIZONTAL, blankInsets, 0, 0));
171:
172: height = 1;
173: gridy += height;
174:
175: add(waterUnitPanel, new GridBagConstraints(gridx, gridy, 1,
176: height, 1.0, 0.8, GridBagConstraints.WEST,
177: GridBagConstraints.HORIZONTAL, blankInsets, 0, 0));
178:
179: height = 1;
180: gridy += height;
181:
182: add(roundUnitsPanel, new GridBagConstraints(gridx, gridy, 1,
183: height, 1.0, 0.8, GridBagConstraints.WEST,
184: GridBagConstraints.HORIZONTAL, blankInsets, 0, 0));
185:
186: height = 2;
187: gridy += height;
188:
189: JPanel spaceFiller = new JPanel();
190: spaceFiller.add(Box.createVerticalStrut(30));
191:
192: add(spaceFiller, new GridBagConstraints(gridx, gridy, 1,
193: height, 1.0, 1.0, GridBagConstraints.WEST,
194: GridBagConstraints.BOTH, blankInsets, 0, 0));
195:
196: }
197:
198: public void flushValuesToData() {
199: if (prefsChanged()) {
200: prefData.ammoUnit = prefData.getUnit(ammoUnitGroup
201: .getSelection().getActionCommand());
202: prefData.waterUnit = prefData.getUnit(waterUnitGroup
203: .getSelection().getActionCommand());
204: prefData.roundToWholes = roundUnitsCheck.isSelected();
205: }
206: super.flushValuesToData();
207: }
208:
209: }
|