| 1 | 181102 | |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
package edu.rice.cs.drjava.ui.config; |
| 38 | |
|
| 39 | |
import java.awt.*; |
| 40 | |
import java.awt.event.*; |
| 41 | |
import javax.swing.*; |
| 42 | |
import edu.rice.cs.drjava.config.*; |
| 43 | |
import edu.rice.cs.drjava.*; |
| 44 | |
import edu.rice.cs.util.swing.SwingFrame; |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
public class ColorOptionComponent extends OptionComponent<Color,JPanel> { |
| 50 | |
private JButton _button; |
| 51 | 0 | private JTextField _colorField; |
| 52 | |
private JPanel _panel; |
| 53 | |
private Color _color; |
| 54 | |
private boolean _isBackgroundColor; |
| 55 | |
private boolean _isBoldText; |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
public ColorOptionComponent (ColorOption opt, String text, SwingFrame parent) { |
| 63 | 0 | this(opt, text, parent, false); |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
public ColorOptionComponent(ColorOption opt, String text, SwingFrame parent, boolean isBackgroundColor) { |
| 70 | 0 | this(opt, text, parent, isBackgroundColor, false); |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
public ColorOptionComponent(ColorOption opt, String text, SwingFrame parent, boolean isBackgroundColor, boolean isBoldText) |
| 74 | |
{ |
| 75 | 181102 | super(opt, text, parent); |
| 76 | 181102 | _isBackgroundColor = isBackgroundColor; |
| 77 | 181102 | _isBoldText = isBoldText; |
| 78 | 181102 | _button = new JButton(); |
| 79 | 181102 | _button.addActionListener(new ActionListener() { |
| 80 | 0 | public void actionPerformed(ActionEvent e) { chooseColor(); } |
| 81 | |
}); |
| 82 | 181102 | _button.setText("..."); |
| 83 | 181102 | _button.setMaximumSize(new Dimension(10,10)); |
| 84 | 181102 | _button.setMinimumSize(new Dimension(10,10)); |
| 85 | |
|
| 86 | 181102 | _colorField = new JTextField(); |
| 87 | 181102 | _colorField.setEditable(false); |
| 88 | 181102 | _colorField.setHorizontalAlignment(JTextField.CENTER); |
| 89 | 181102 | _panel = new JPanel(new BorderLayout()); |
| 90 | 181102 | _panel.add(_colorField, BorderLayout.CENTER); |
| 91 | 181102 | _panel.add(_button, BorderLayout.EAST); |
| 92 | 181102 | if (_isBackgroundColor) { |
| 93 | |
|
| 94 | 105156 | _colorField.setForeground(DrJava.getConfig().getSetting(OptionConstants.DEFINITIONS_NORMAL_COLOR)); |
| 95 | 210312 | DrJava.getConfig().addOptionListener(OptionConstants.DEFINITIONS_NORMAL_COLOR, |
| 96 | 105156 | new OptionListener<Color>() { |
| 97 | 0 | public void optionChanged(OptionEvent<Color> oe) { _colorField.setForeground(oe.value); } |
| 98 | |
}); |
| 99 | |
} |
| 100 | |
else { |
| 101 | |
|
| 102 | 75946 | _colorField.setBackground(DrJava.getConfig().getSetting(OptionConstants.DEFINITIONS_BACKGROUND_COLOR)); |
| 103 | 151892 | DrJava.getConfig().addOptionListener(OptionConstants.DEFINITIONS_BACKGROUND_COLOR, |
| 104 | 75946 | new OptionListener<Color>() { |
| 105 | |
public void optionChanged(OptionEvent<Color> oe) { |
| 106 | 0 | _colorField.setBackground(oe.value); |
| 107 | 0 | } |
| 108 | |
}); |
| 109 | |
} |
| 110 | 181102 | if (_isBoldText) { |
| 111 | 11684 | _colorField.setFont(_colorField.getFont().deriveFont(Font.BOLD)); |
| 112 | |
} |
| 113 | 181102 | _color = DrJava.getConfig().getSetting(_option); |
| 114 | 181102 | _updateField(_color); |
| 115 | 181102 | setComponent(_panel); |
| 116 | 181102 | } |
| 117 | |
|
| 118 | |
|
| 119 | |
public ColorOptionComponent(ColorOption opt, String text, SwingFrame parent, String description) { |
| 120 | 0 | this(opt, text, parent, description, false); |
| 121 | 0 | } |
| 122 | |
|
| 123 | |
|
| 124 | |
public ColorOptionComponent(ColorOption opt, String text, SwingFrame parent, String description, boolean isBackgroundColor) |
| 125 | |
{ |
| 126 | 0 | this(opt, text, parent, isBackgroundColor); |
| 127 | 0 | setDescription(description); |
| 128 | 0 | } |
| 129 | |
|
| 130 | |
|
| 131 | |
public ColorOptionComponent(ColorOption opt, String text, SwingFrame parent, String description, boolean isBackgroundColor, |
| 132 | |
boolean isBoldText) { |
| 133 | 181102 | this(opt, text, parent, isBackgroundColor, isBoldText); |
| 134 | 181102 | setDescription(description); |
| 135 | 181102 | } |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
public void setDescription(String description) { |
| 141 | 181102 | _panel.setToolTipText(description); |
| 142 | 181102 | _button.setToolTipText(description); |
| 143 | 181102 | _colorField.setToolTipText(description); |
| 144 | 181102 | _label.setToolTipText(description); |
| 145 | 181102 | } |
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
public boolean updateConfig() { |
| 151 | 2449 | if (!_color.equals(DrJava.getConfig().getSetting(_option))) { DrJava.getConfig().setSetting(_option, _color); } |
| 152 | 2449 | return true; |
| 153 | |
} |
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
public void setValue(Color value) { |
| 158 | 22196 | _color = value; |
| 159 | 22196 | _updateField(value); |
| 160 | 22196 | } |
| 161 | |
|
| 162 | |
|
| 163 | |
private void _updateField(Color c) { |
| 164 | 203298 | if (_isBackgroundColor) _colorField.setBackground(c); |
| 165 | 85254 | else _colorField.setForeground(c); |
| 166 | 203298 | _colorField.setText(getLabelText() + " (" + _option.format(c) + ")"); |
| 167 | 203298 | } |
| 168 | |
|
| 169 | |
|
| 170 | |
public void chooseColor() { |
| 171 | 0 | Color c = JColorChooser.showDialog(_parent, "Choose '" + getLabelText() + "'", _color); |
| 172 | 0 | if (c != null) { |
| 173 | 0 | _color = c; |
| 174 | 0 | notifyChangeListeners(); |
| 175 | 0 | _updateField(c); |
| 176 | |
} |
| 177 | 0 | } |
| 178 | |
} |