|
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 |
| |
|
43 |
| import edu.rice.cs.drjava.*; |
|
44 |
| import edu.rice.cs.drjava.config.*; |
|
45 |
| import edu.rice.cs.util.swing.SwingFrame; |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| public class ToolbarOptionComponent extends OptionComponent<Boolean,JComponent> { |
|
57 |
| |
|
58 |
| private JRadioButton _noneButton; |
|
59 |
| private JRadioButton _textButton; |
|
60 |
| private JRadioButton _iconsButton; |
|
61 |
| private JRadioButton _textAndIconsButton; |
|
62 |
| private ButtonGroup _group; |
|
63 |
| private JPanel _buttonPanel; |
|
64 |
| |
|
65 |
| |
|
66 |
| public static final String NONE = "none"; |
|
67 |
| public static final String TEXT_ONLY = "text only"; |
|
68 |
| public static final String ICONS_ONLY= "icons only"; |
|
69 |
| public static final String TEXT_AND_ICONS = "text and icons"; |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
38
| public ToolbarOptionComponent(String title, SwingFrame parent) {
|
|
78 |
38
| super(title, parent);
|
|
79 |
| |
|
80 |
38
| _noneButton = new JRadioButton(NONE);
|
|
81 |
38
| _noneButton.setActionCommand(NONE);
|
|
82 |
38
| _noneButton.addActionListener(new ActionListener() {
|
|
83 |
0
| public void actionPerformed(ActionEvent e) { notifyChangeListeners(); }
|
|
84 |
| }); |
|
85 |
| |
|
86 |
38
| _textButton = new JRadioButton(TEXT_ONLY);
|
|
87 |
38
| _textButton.setActionCommand(TEXT_ONLY);
|
|
88 |
38
| _textButton.addActionListener(new ActionListener() {
|
|
89 |
0
| public void actionPerformed(ActionEvent e) { notifyChangeListeners(); }
|
|
90 |
| }); |
|
91 |
| |
|
92 |
38
| _iconsButton = new JRadioButton(ICONS_ONLY);
|
|
93 |
38
| _iconsButton.setActionCommand(ICONS_ONLY);
|
|
94 |
38
| _iconsButton.addActionListener(new ActionListener() {
|
|
95 |
0
| public void actionPerformed(ActionEvent e) { notifyChangeListeners(); }
|
|
96 |
| }); |
|
97 |
| |
|
98 |
38
| _textAndIconsButton = new JRadioButton(TEXT_AND_ICONS);
|
|
99 |
38
| _textAndIconsButton.setActionCommand(TEXT_AND_ICONS);
|
|
100 |
38
| _textAndIconsButton.addActionListener(new ActionListener() {
|
|
101 |
0
| public void actionPerformed(ActionEvent e) { notifyChangeListeners(); }
|
|
102 |
| }); |
|
103 |
| |
|
104 |
38
| resetToCurrent();
|
|
105 |
| |
|
106 |
38
| _group = new ButtonGroup();
|
|
107 |
38
| _group.add(_noneButton);
|
|
108 |
38
| _group.add(_textButton);
|
|
109 |
38
| _group.add(_iconsButton);
|
|
110 |
38
| _group.add(_textAndIconsButton);
|
|
111 |
| |
|
112 |
38
| _buttonPanel = new JPanel();
|
|
113 |
38
| _buttonPanel.setLayout(new GridLayout(0,1));
|
|
114 |
38
| _buttonPanel.setBorder(BorderFactory.createEtchedBorder());
|
|
115 |
38
| _buttonPanel.add(_noneButton);
|
|
116 |
38
| _buttonPanel.add(_textButton);
|
|
117 |
38
| _buttonPanel.add(_iconsButton);
|
|
118 |
38
| _buttonPanel.add(_textAndIconsButton);
|
|
119 |
| |
|
120 |
38
| DrJava.getConfig().addOptionListener(OptionConstants.TOOLBAR_TEXT_ENABLED,
|
|
121 |
| new OptionListener<Boolean>() { |
|
122 |
0
| public void optionChanged(OptionEvent<Boolean> oe) { resetToCurrent(); }
|
|
123 |
| }); |
|
124 |
38
| DrJava.getConfig().addOptionListener(OptionConstants.TOOLBAR_ICONS_ENABLED,
|
|
125 |
| new OptionListener<Boolean>() { |
|
126 |
0
| public void optionChanged(OptionEvent<Boolean> oe) { resetToCurrent(); }
|
|
127 |
| }); |
|
128 |
38
| DrJava.getConfig().addOptionListener(OptionConstants.TOOLBAR_ENABLED,
|
|
129 |
| new OptionListener<Boolean>() { |
|
130 |
0
| public void optionChanged(OptionEvent<Boolean> oe) { resetToCurrent(); }
|
|
131 |
| }); |
|
132 |
| |
|
133 |
38
| setComponent(_buttonPanel);
|
|
134 |
| } |
|
135 |
| |
|
136 |
| |
|
137 |
38
| public ToolbarOptionComponent(String title, SwingFrame parent, String description) {
|
|
138 |
38
| this(title, parent);
|
|
139 |
38
| setDescription(description);
|
|
140 |
| } |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
38
| public void setDescription(String description) {
|
|
146 |
38
| _buttonPanel.setToolTipText(description);
|
|
147 |
38
| _noneButton.setToolTipText(description);
|
|
148 |
38
| _textButton.setToolTipText(description);
|
|
149 |
38
| _iconsButton.setToolTipText(description);
|
|
150 |
38
| _textAndIconsButton.setToolTipText(description);
|
|
151 |
38
| _label.setToolTipText(description);
|
|
152 |
| } |
|
153 |
| |
|
154 |
| |
|
155 |
38
| public void resetToCurrent() {
|
|
156 |
38
| _setSelected(DrJava.getConfig().getSetting(OptionConstants.TOOLBAR_TEXT_ENABLED).booleanValue(),
|
|
157 |
| DrJava.getConfig().getSetting(OptionConstants.TOOLBAR_ICONS_ENABLED).booleanValue(), |
|
158 |
| DrJava.getConfig().getSetting(OptionConstants.TOOLBAR_ENABLED).booleanValue()); |
|
159 |
| } |
|
160 |
| |
|
161 |
| |
|
162 |
0
| public void resetToDefault() {
|
|
163 |
0
| _setSelected(OptionConstants.TOOLBAR_TEXT_ENABLED.getDefault().booleanValue(),
|
|
164 |
| OptionConstants.TOOLBAR_ICONS_ENABLED.getDefault().booleanValue(), |
|
165 |
| OptionConstants.TOOLBAR_ENABLED.getDefault().booleanValue()); |
|
166 |
| } |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
| |
|
171 |
| |
|
172 |
38
| private void _setSelected(boolean textEnabled, boolean iconsEnabled, boolean isEnabled) {
|
|
173 |
0
| if (! isEnabled) { _noneButton.setSelected(true); }
|
|
174 |
38
| else if (textEnabled && iconsEnabled) { _textAndIconsButton.setSelected(true); }
|
|
175 |
| else { |
|
176 |
0
| if (textEnabled) _textButton.setSelected(true);
|
|
177 |
0
| else if (iconsEnabled) _iconsButton.setSelected(true);
|
|
178 |
| } |
|
179 |
| } |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
0
| public boolean updateConfig() {
|
|
185 |
0
| String btnIdent = _group.getSelection().getActionCommand();
|
|
186 |
0
| boolean textWasEnabled = DrJava.getConfig().getSetting(OptionConstants.TOOLBAR_TEXT_ENABLED).booleanValue();
|
|
187 |
0
| boolean iconsWereEnabled = DrJava.getConfig().getSetting(OptionConstants.TOOLBAR_ICONS_ENABLED).booleanValue();
|
|
188 |
0
| boolean wasEnabled = DrJava.getConfig().getSetting(OptionConstants.TOOLBAR_ENABLED).booleanValue();
|
|
189 |
| |
|
190 |
0
| if (btnIdent.equals(NONE)) {
|
|
191 |
0
| if (wasEnabled) { DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ENABLED, Boolean.FALSE); }
|
|
192 |
| } |
|
193 |
0
| if (btnIdent.equals(TEXT_ONLY)) {
|
|
194 |
0
| if (! textWasEnabled) { DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_TEXT_ENABLED, Boolean.TRUE); }
|
|
195 |
0
| if (iconsWereEnabled) { DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ICONS_ENABLED, Boolean.FALSE); }
|
|
196 |
0
| if (! wasEnabled) { DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ENABLED, Boolean.TRUE); }
|
|
197 |
| } |
|
198 |
| |
|
199 |
0
| if (btnIdent.equals(ICONS_ONLY)) {
|
|
200 |
0
| if (! iconsWereEnabled) { DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ICONS_ENABLED, Boolean.TRUE); }
|
|
201 |
0
| if (textWasEnabled) { DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_TEXT_ENABLED, Boolean.FALSE); }
|
|
202 |
0
| if (! wasEnabled) { DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ENABLED, Boolean.TRUE); }
|
|
203 |
| } |
|
204 |
| |
|
205 |
0
| if (btnIdent.equals(TEXT_AND_ICONS)) {
|
|
206 |
0
| if (! textWasEnabled) { DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_TEXT_ENABLED, Boolean.TRUE); }
|
|
207 |
0
| if (! iconsWereEnabled) { DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ICONS_ENABLED, Boolean.TRUE); }
|
|
208 |
0
| if (! wasEnabled) { DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ENABLED, Boolean.TRUE); }
|
|
209 |
| } |
|
210 |
| |
|
211 |
0
| return true;
|
|
212 |
| } |
|
213 |
| |
|
214 |
| |
|
215 |
| |
|
216 |
| |
|
217 |
0
| public void setValue(Boolean value) {
|
|
218 |
0
| resetToCurrent();
|
|
219 |
| } |
|
220 |
| |
|
221 |
| |
|
222 |
| |
|
223 |
38
| public void setComponent(JComponent component) {
|
|
224 |
38
| _guiComponent = component;
|
|
225 |
38
| if (_guiComponent!=null) {
|
|
226 |
38
| boolean wasEditable = DrJava.getConfig().isEditable(OptionConstants.TOOLBAR_TEXT_ENABLED);
|
|
227 |
38
| wasEditable = wasEditable && DrJava.getConfig().isEditable(OptionConstants.TOOLBAR_ICONS_ENABLED);
|
|
228 |
38
| wasEditable = wasEditable && DrJava.getConfig().isEditable(OptionConstants.TOOLBAR_ENABLED);
|
|
229 |
| |
|
230 |
38
| _guiComponent.setEnabled(wasEditable);
|
|
231 |
| |
|
232 |
38
| for (Component subComponent: _guiComponent.getComponents()) {
|
|
233 |
152
| subComponent.setEnabled(wasEditable);
|
|
234 |
| } |
|
235 |
| } |
|
236 |
| } |
|
237 |
| } |