|
1 |
| |
|
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 |
| 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 |
3
| public ColorOptionComponent (ColorOption opt, String text, SwingFrame parent) {
|
|
63 |
3
| this(opt, text, parent, false);
|
|
64 |
| } |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
3
| public ColorOptionComponent(ColorOption opt, String text, SwingFrame parent, boolean isBackgroundColor) {
|
|
70 |
3
| this(opt, text, parent, isBackgroundColor, false);
|
|
71 |
| } |
|
72 |
| |
|
73 |
1181
| public ColorOptionComponent(ColorOption opt, String text, SwingFrame parent, boolean isBackgroundColor, boolean isBoldText)
|
|
74 |
| { |
|
75 |
1181
| super(opt, text, parent);
|
|
76 |
1181
| _isBackgroundColor = isBackgroundColor;
|
|
77 |
1181
| _isBoldText = isBoldText;
|
|
78 |
1181
| _button = new JButton();
|
|
79 |
1181
| _button.addActionListener(new ActionListener() {
|
|
80 |
0
| public void actionPerformed(ActionEvent e) { chooseColor(); }
|
|
81 |
| }); |
|
82 |
1181
| _button.setText("...");
|
|
83 |
1181
| _button.setMaximumSize(new Dimension(10,10));
|
|
84 |
1181
| _button.setMinimumSize(new Dimension(10,10));
|
|
85 |
| |
|
86 |
1181
| _colorField = new JTextField();
|
|
87 |
1181
| _colorField.setEditable(false);
|
|
88 |
1181
| _colorField.setHorizontalAlignment(JTextField.CENTER);
|
|
89 |
1181
| _panel = new JPanel(new BorderLayout());
|
|
90 |
1181
| _panel.add(_colorField, BorderLayout.CENTER);
|
|
91 |
1181
| _panel.add(_button, BorderLayout.EAST);
|
|
92 |
1181
| if (_isBackgroundColor) {
|
|
93 |
| |
|
94 |
684
| _colorField.setForeground(DrJava.getConfig().getSetting(OptionConstants.DEFINITIONS_NORMAL_COLOR));
|
|
95 |
684
| DrJava.getConfig().addOptionListener(OptionConstants.DEFINITIONS_NORMAL_COLOR,
|
|
96 |
| new OptionListener<Color>() { |
|
97 |
0
| public void optionChanged(OptionEvent<Color> oe) { _colorField.setForeground(oe.value); }
|
|
98 |
| }); |
|
99 |
| } |
|
100 |
| else { |
|
101 |
| |
|
102 |
497
| _colorField.setBackground(DrJava.getConfig().getSetting(OptionConstants.DEFINITIONS_BACKGROUND_COLOR));
|
|
103 |
497
| DrJava.getConfig().addOptionListener(OptionConstants.DEFINITIONS_BACKGROUND_COLOR,
|
|
104 |
| new OptionListener<Color>() { |
|
105 |
0
| public void optionChanged(OptionEvent<Color> oe) {
|
|
106 |
0
| _colorField.setBackground(oe.value);
|
|
107 |
| } |
|
108 |
| }); |
|
109 |
| } |
|
110 |
1181
| if (_isBoldText) {
|
|
111 |
76
| _colorField.setFont(_colorField.getFont().deriveFont(Font.BOLD));
|
|
112 |
| } |
|
113 |
1181
| _color = DrJava.getConfig().getSetting(_option);
|
|
114 |
1181
| _updateField(_color);
|
|
115 |
1181
| setComponent(_panel);
|
|
116 |
| } |
|
117 |
| |
|
118 |
| |
|
119 |
0
| public ColorOptionComponent(ColorOption opt, String text, SwingFrame parent, String description) {
|
|
120 |
0
| this(opt, text, parent, description, false);
|
|
121 |
| } |
|
122 |
| |
|
123 |
| |
|
124 |
0
| 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 |
| } |
|
129 |
| |
|
130 |
| |
|
131 |
1178
| public ColorOptionComponent(ColorOption opt, String text, SwingFrame parent, String description, boolean isBackgroundColor,
|
|
132 |
| boolean isBoldText) { |
|
133 |
1178
| this(opt, text, parent, isBackgroundColor, isBoldText);
|
|
134 |
1178
| setDescription(description);
|
|
135 |
| } |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
1178
| public void setDescription(String description) {
|
|
141 |
1178
| _panel.setToolTipText(description);
|
|
142 |
1178
| _button.setToolTipText(description);
|
|
143 |
1178
| _colorField.setToolTipText(description);
|
|
144 |
1178
| _label.setToolTipText(description);
|
|
145 |
| } |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
4
| public boolean updateConfig() {
|
|
151 |
3
| if (!_color.equals(DrJava.getConfig().getSetting(_option))) { DrJava.getConfig().setSetting(_option, _color); }
|
|
152 |
4
| return true;
|
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
8
| public void setValue(Color value) {
|
|
158 |
8
| _color = value;
|
|
159 |
8
| _updateField(value);
|
|
160 |
| } |
|
161 |
| |
|
162 |
| |
|
163 |
1189
| private void _updateField(Color c) {
|
|
164 |
684
| if (_isBackgroundColor) _colorField.setBackground(c);
|
|
165 |
505
| else _colorField.setForeground(c);
|
|
166 |
1189
| _colorField.setText(getLabelText() + " (" + _option.format(c) + ")");
|
|
167 |
| } |
|
168 |
| |
|
169 |
| |
|
170 |
0
| 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 |
| } |
|
178 |
| } |