001: /*
002: * Created on Oct 23, 2004
003: *
004: * @author ctaylor
005: *
006: */
007: package com.pk.preferences;
008:
009: import java.awt.GridBagConstraints;
010: import java.awt.GridBagLayout;
011: import java.awt.Insets;
012: import java.awt.event.ActionListener;
013:
014: import javax.swing.JComboBox;
015: import javax.swing.JLabel;
016: import javax.swing.JPanel;
017: import javax.swing.LookAndFeel;
018:
019: import com.pk.Config;
020:
021: /**
022: * @author ctaylor
023: *
024: */
025: public class GeneralPanel extends JPanel {
026: /**
027: *
028: */
029: private static final long serialVersionUID = 5037263415761414357L;
030:
031: private class HistoryModeDisplay {
032:
033: String displayString = "";
034: Integer value = null;
035:
036: public HistoryModeDisplay(String argDisplayString,
037: Integer argValue) {
038: displayString = argDisplayString;
039: value = argValue;
040:
041: }
042:
043: /* (non-Javadoc)
044: * @see java.lang.Object#toString()
045: */
046: public String toString() {
047: return displayString;
048: }
049: }
050:
051: private JComboBox lookAndFeelComboBox = null;
052: private JComboBox historyModeComboBox = null;
053:
054: public GeneralPanel(ActionListener argActionListener) {
055: JLabel label = new JLabel();
056: this .setLayout(new GridBagLayout());
057: GridBagConstraints gbc = new GridBagConstraints();
058: gbc.anchor = GridBagConstraints.WEST;
059: gbc.insets = new Insets(6, 15, 6, 15);
060:
061: gbc.gridx = 0;
062: gbc.gridy = 0;
063: label = new JLabel("Look and Feel:", JLabel.LEFT);
064: this .add(label, gbc);
065:
066: gbc.gridx++;
067:
068: lookAndFeelComboBox = new JComboBox();
069: //lookAndFeelComboBox.setEditable(true);
070: this .add(lookAndFeelComboBox, gbc);
071:
072: gbc.gridx = 0;
073: gbc.gridy = 1;
074: label = new JLabel("History Mode:", JLabel.LEFT);
075: this .add(label, gbc);
076:
077: gbc.gridx++;
078:
079: historyModeComboBox = new JComboBox();
080: //lookAndFeelComboBox.setEditable(true);
081: this .add(historyModeComboBox, gbc);
082: }
083:
084: public void setLookandFeels(Config argConfig) {
085: if (argConfig != null && lookAndFeelComboBox != null) {
086: int size = argConfig.getLookandFeels().size();
087: for (int x = 0; x < size; x++) {
088: lookAndFeelComboBox.addItem(((LookAndFeel) argConfig
089: .getLookandFeels().get(x)).getName());
090: }
091: lookAndFeelComboBox.setSelectedItem(argConfig
092: .getSelectedLookAndFeel().getName());
093: }
094: }
095:
096: public void setSelectedHistoryMode(int argSelectedMode) {
097: if (historyModeComboBox.getItemCount() == 0) {
098: historyModeComboBox.addItem(new HistoryModeDisplay(
099: "Unique", new Integer(Config.HISTORY_MODE_UNIQUE)));
100: historyModeComboBox.addItem(new HistoryModeDisplay(
101: "Different From Last Run", new Integer(
102: Config.HISTORY_MODE_DIFF_FROM_LAST)));
103: historyModeComboBox.addItem(new HistoryModeDisplay("All",
104: new Integer(Config.HISTORY_MODE_ALL)));
105: }
106: if (argSelectedMode == Config.HISTORY_MODE_UNIQUE) {
107: historyModeComboBox.setSelectedIndex(0);
108: } else if (argSelectedMode == Config.HISTORY_MODE_DIFF_FROM_LAST) {
109: historyModeComboBox.setSelectedIndex(1);
110: } else if (argSelectedMode == Config.HISTORY_MODE_ALL) {
111: historyModeComboBox.setSelectedIndex(2);
112: }
113: }
114:
115: public int getSelectedHistoryMode() {
116: if (historyModeComboBox != null) {
117: return ((HistoryModeDisplay) historyModeComboBox
118: .getSelectedItem()).value.intValue();
119: }
120: return Config.HISTORY_MODE_ALL;
121: }
122:
123: /**
124: * @return Returns the lookAndFeelComboBox.
125: */
126: public JComboBox getLookAndFeelComboBox() {
127: return lookAndFeelComboBox;
128: }
129: }
|