1 33 34 package edu.rice.cs.drjava.ui.config; 35 36 import javax.swing.*; 37 import edu.rice.cs.drjava.config.*; 38 import edu.rice.cs.drjava.*; 39 import java.awt.*; 40 import java.awt.event.*; 41 42 51 public class ToolbarOptionComponent extends OptionComponent<Boolean > { 52 53 private JRadioButton _noneButton; 54 private JRadioButton _textButton; 55 private JRadioButton _iconsButton; 56 private JRadioButton _textAndIconsButton; 57 private ButtonGroup _group; 58 private JPanel _buttonPanel; 59 60 public static final String NONE = "none"; 62 public static final String TEXT_ONLY = "text only"; 63 public static final String ICONS_ONLY= "icons only"; 64 public static final String TEXT_AND_ICONS = "text and icons"; 65 66 73 public ToolbarOptionComponent(String title, Frame parent) { 74 super(title, parent); 75 76 _noneButton = new JRadioButton(NONE); 77 _noneButton.setActionCommand(NONE); 78 _noneButton.addActionListener(new ActionListener() { 79 public void actionPerformed(ActionEvent e) { notifyChangeListeners(); } 80 }); 81 82 _textButton = new JRadioButton(TEXT_ONLY); 83 _textButton.setActionCommand(TEXT_ONLY); 84 _textButton.addActionListener(new ActionListener() { 85 public void actionPerformed(ActionEvent e) { notifyChangeListeners(); } 86 }); 87 88 _iconsButton = new JRadioButton(ICONS_ONLY); 89 _iconsButton.setActionCommand(ICONS_ONLY); 90 _iconsButton.addActionListener(new ActionListener() { 91 public void actionPerformed(ActionEvent e) { notifyChangeListeners(); } 92 }); 93 94 _textAndIconsButton = new JRadioButton(TEXT_AND_ICONS); 95 _textAndIconsButton.setActionCommand(TEXT_AND_ICONS); 96 _textAndIconsButton.addActionListener(new ActionListener() { 97 public void actionPerformed(ActionEvent e) { notifyChangeListeners(); } 98 }); 99 100 resetToCurrent(); 101 102 _group = new ButtonGroup(); 103 _group.add(_noneButton); 104 _group.add(_textButton); 105 _group.add(_iconsButton); 106 _group.add(_textAndIconsButton); 107 108 _buttonPanel = new JPanel(); 109 _buttonPanel.setLayout(new GridLayout(0,1)); 110 _buttonPanel.setBorder(BorderFactory.createEtchedBorder()); 111 _buttonPanel.add(_noneButton); 112 _buttonPanel.add(_textButton); 113 _buttonPanel.add(_iconsButton); 114 _buttonPanel.add(_textAndIconsButton); 115 116 DrJava.getConfig().addOptionListener(OptionConstants.TOOLBAR_TEXT_ENABLED, 117 new OptionListener<Boolean >() { 118 public void optionChanged(OptionEvent<Boolean > oe) { 119 resetToCurrent(); 120 } 121 }); 122 DrJava.getConfig().addOptionListener(OptionConstants.TOOLBAR_ICONS_ENABLED, 123 new OptionListener<Boolean >() { 124 public void optionChanged(OptionEvent<Boolean > oe) { 125 resetToCurrent(); 126 } 127 }); 128 DrJava.getConfig().addOptionListener(OptionConstants.TOOLBAR_ENABLED, 129 new OptionListener<Boolean >() { 130 public void optionChanged(OptionEvent<Boolean > oe) { 131 resetToCurrent(); 132 } 133 }); 134 135 } 136 137 140 public ToolbarOptionComponent(String title, Frame parent, String description) { 141 this(title, parent); 142 setDescription(description); 143 } 144 145 149 public void setDescription(String description) { 150 _buttonPanel.setToolTipText(description); 151 _noneButton.setToolTipText(description); 152 _textButton.setToolTipText(description); 153 _iconsButton.setToolTipText(description); 154 _textAndIconsButton.setToolTipText(description); 155 _label.setToolTipText(description); 156 } 157 158 161 public void resetToCurrent() { 162 _setSelected(DrJava.getConfig().getSetting(OptionConstants.TOOLBAR_TEXT_ENABLED).booleanValue(), 163 DrJava.getConfig().getSetting(OptionConstants.TOOLBAR_ICONS_ENABLED).booleanValue(), 164 DrJava.getConfig().getSetting(OptionConstants.TOOLBAR_ENABLED).booleanValue()); 165 } 166 167 170 public void resetToDefault() { 171 _setSelected(OptionConstants.TOOLBAR_TEXT_ENABLED.getDefault().booleanValue(), 172 OptionConstants.TOOLBAR_ICONS_ENABLED.getDefault().booleanValue(), 173 OptionConstants.TOOLBAR_ENABLED.getDefault().booleanValue()); 174 } 175 176 181 private void _setSelected(boolean textEnabled, boolean iconsEnabled, boolean isEnabled) { 182 if (! isEnabled) { 183 _noneButton.setSelected(true); 184 } 185 else if (textEnabled && iconsEnabled) { 186 _textAndIconsButton.setSelected(true); 187 } 188 else { 189 if (textEnabled) _textButton.setSelected(true); 190 else if (iconsEnabled) _iconsButton.setSelected(true); 191 } 192 } 193 194 197 public JComponent getComponent() { 198 return _buttonPanel; 199 } 200 201 205 public boolean updateConfig() { 206 String btnIdent = _group.getSelection().getActionCommand(); 207 boolean textWasEnabled = DrJava.getConfig().getSetting(OptionConstants.TOOLBAR_TEXT_ENABLED).booleanValue(); 208 boolean iconsWereEnabled = DrJava.getConfig().getSetting(OptionConstants.TOOLBAR_ICONS_ENABLED).booleanValue(); 209 boolean wasEnabled = DrJava.getConfig().getSetting(OptionConstants.TOOLBAR_ENABLED).booleanValue(); 210 211 if (btnIdent.equals(NONE)) { 212 if (wasEnabled) { 213 DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ENABLED, Boolean.FALSE); 214 } 215 } 216 if (btnIdent.equals(TEXT_ONLY)) { 217 if (!textWasEnabled) { 218 DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_TEXT_ENABLED, Boolean.TRUE); 219 } 220 if (iconsWereEnabled) { 221 DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ICONS_ENABLED, Boolean.FALSE); 222 } 223 if (!wasEnabled) { 224 DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ENABLED, Boolean.TRUE); 225 } 226 } 227 228 if (btnIdent.equals(ICONS_ONLY)) { 229 if (!iconsWereEnabled) { 230 DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ICONS_ENABLED, Boolean.TRUE); 231 } 232 if (textWasEnabled) { 233 DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_TEXT_ENABLED, Boolean.FALSE); 234 } 235 if (!wasEnabled) { 236 DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ENABLED, Boolean.TRUE); 237 } 238 } 239 240 if (btnIdent.equals(TEXT_AND_ICONS)) { 241 if (!textWasEnabled) { 242 DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_TEXT_ENABLED, Boolean.TRUE); 243 } 244 if (!iconsWereEnabled) { 245 DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ICONS_ENABLED, Boolean.TRUE); 246 } 247 if (!wasEnabled) { 248 DrJava.getConfig().setSetting(OptionConstants.TOOLBAR_ENABLED, Boolean.TRUE); 249 } 250 } 251 252 return true; 253 } 254 255 256 259 public void setValue(Boolean value) { 260 resetToCurrent(); 261 } 262 263 } | Popular Tags |