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 org.cougaar.logistics.ui.inventory.InventoryUIFrame;
030: import org.cougaar.logistics.ui.inventory.InventoryColorTable;
031: import org.cougaar.logistics.ui.inventory.data.InventoryPreferenceData;
032:
033: import javax.swing.*;
034: import javax.swing.border.EtchedBorder;
035: import java.awt.*;
036: import java.util.Hashtable;
037: import java.util.Set;
038: import java.util.Iterator;
039: import java.util.Enumeration;
040:
041: /**
042: * <pre>
043: *
044: * The InventoryPreferenceTab is an almost abstract superclass that all the tabs
045: * for the InventoryPreferenceDialog inherit from. It basically provides back
046: * pointers and common functionality to all the tabs going into the dialog
047: *
048: * @see InventoryPreferenceDialog
049: * @see org.cougaar.logistics.ui.inventory.data.InventoryPreferenceData
050: *
051: **/
052:
053: public class ColorTab extends PreferenceDialogTab {
054: InventoryColorTable colorTable;
055: ButtonGroup buttonGroup;
056:
057: public ColorTab(InventoryUIFrame invUIFrame,
058: InventoryPreferenceDialog invUIDialog,
059: InventoryPreferenceData prefData) {
060: super (invUIFrame, invUIDialog, prefData);
061: }
062:
063: protected void doTabLayout() {
064: colorTable = prefData.getColorTable();
065: buttonGroup = new ButtonGroup();
066: setLayout(new GridBagLayout());
067: int y = 0;
068: String colorScheme = prefData.getColorScheme();
069: for (int i = 0; i < InventoryPreferenceData.colorSchemes.length; i++) {
070: JRadioButton button = new JRadioButton(
071: InventoryPreferenceData.colorSchemes[i]);
072: if (colorScheme
073: .equals(InventoryPreferenceData.colorSchemes[i]))
074: button.setSelected(true);
075: button.addItemListener(this );
076: buttonGroup.add(button);
077: add(button, new GridBagConstraints(0, y++, 1, 1, 0.0, 0.0,
078: GridBagConstraints.WEST, GridBagConstraints.BOTH,
079: new Insets(10, 0, 0, 0), 0, 0));
080: }
081: // int y = 0;
082: // for (int i = 0; i < InventoryPreferenceData.colorSchemes.length; i++) {
083: // JPanel p = doColorPanelLayout(InventoryPreferenceData.colorSchemes[i]);
084: // add(p, new GridBagConstraints(0, y++, 1, 1, 0.0, 0.0,
085: // GridBagConstraints.WEST, GridBagConstraints.BOTH,
086: // new Insets(10, 0, 0, 0), 0, 0));
087: }
088:
089: // private JPanel doColorPanelLayout(String colorScheme) {
090: // JPanel colorPanel = new JPanel(new GridBagLayout());
091: // JRadioButton button = new JRadioButton(colorScheme);
092: // button.addItemListener(this); // marks preference data as changed
093: // buttonGroup.add(button);
094: // colorPanel.add(button, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
095: // GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
096: // new Insets(0, 0, 0, 0), 0, 0));
097: // colorPanel.setBorder(BorderFactory.createLineBorder(Color.red));
098: // JPanel colorSchemePanel = createColorSchemePanel(colorScheme);
099: // colorPanel.add(colorSchemePanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
100: // GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
101: // new Insets(0, 20, 0, 0), 0, 0));
102: // return colorPanel;
103: // }
104:
105: private JPanel createColorSchemePanel(String colorScheme) {
106: JPanel panel = new JPanel();
107: panel.setBorder(BorderFactory
108: .createEtchedBorder(EtchedBorder.LOWERED));
109: String[] labels = colorTable.getColorLabels();
110: int rows = (labels.length + 1) / 2;
111: panel.setLayout(new GridLayout(rows, 2, 2, 2));
112: for (int i = 0; i < labels.length; i++) {
113: Color color = colorTable.get(colorScheme, labels[i]);
114: Icon icon = new ColoredBox(color, 10);
115: panel.add(new JLabel(labels[i], icon, SwingConstants.LEFT));
116: }
117: return panel;
118: }
119:
120: public void flushValuesToData() {
121: if (prefsChanged()) {
122: Enumeration buttons = buttonGroup.getElements();
123: while (buttons.hasMoreElements()) {
124: JRadioButton button = (JRadioButton) buttons
125: .nextElement();
126: if (button.isSelected()) {
127: prefData.colorScheme = button.getText();
128: return;
129: }
130: }
131: }
132: super.flushValuesToData();
133: }
134:
135: }
|