Changeset 6051 in josm for trunk/src/org
- Timestamp:
- 2013-07-06T16:07:02+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java
r6040 r6051 11 11 import java.awt.event.WindowEvent; 12 12 import java.util.ArrayList; 13 import java.util.Collection; 14 import java.util.HashSet; 13 15 import java.util.List; 14 16 … … 21 23 import javax.swing.JOptionPane; 22 24 import javax.swing.KeyStroke; 25 import javax.swing.event.ChangeEvent; 26 import javax.swing.event.ChangeListener; 23 27 24 28 import org.openstreetmap.josm.gui.help.HelpBrowser; … … 37 41 public final String tooltipText; 38 42 public final String helpTopic; 39 public final boolean enabled; 43 private boolean enabled; 44 45 private final Collection<ChangeListener> listeners = new HashSet<ChangeListener>(); 40 46 41 47 /** … … 64 70 this.tooltipText = tooltipText; 65 71 this.helpTopic = helpTopic; 66 this.enabled = enabled; 72 setEnabled(enabled); 73 } 74 75 /** 76 * Determines if this button spec is enabled 77 * @return {@code true} if this button spec is enabled, {@code false} otherwise 78 * @since 6051 79 */ 80 public final boolean isEnabled() { 81 return enabled; 82 } 83 84 /** 85 * Enables or disables this button spec, depending on the value of the parameter {@code b}. 86 * @param enabled if {@code true}, this button spec is enabled; otherwise this button spec is disabled 87 * @since 6051 88 */ 89 public final void setEnabled(boolean enabled) { 90 if (this.enabled != enabled) { 91 this.enabled = enabled; 92 ChangeEvent event = new ChangeEvent(this); 93 for (ChangeListener listener : listeners) { 94 listener.stateChanged(event); 95 } 96 } 97 } 98 99 private final boolean addChangeListener(ChangeListener listener) { 100 return listener != null ? listeners.add(listener) : false; 67 101 } 68 102 } … … 102 136 buttons.add(b); 103 137 } else { 104 for ( ButtonSpec spec: options) {105 JButton b = new JButton(spec.text);138 for (final ButtonSpec spec: options) { 139 final JButton b = new JButton(spec.text); 106 140 b.setIcon(spec.icon); 107 141 b.setToolTipText(spec.tooltipText == null? "" : spec.tooltipText); … … 110 144 } 111 145 b.setFocusable(true); 112 b.setEnabled(spec.enabled); 146 b.setEnabled(spec.isEnabled()); 147 spec.addChangeListener(new ChangeListener() { 148 @Override public void stateChanged(ChangeEvent e) { 149 b.setEnabled(spec.isEnabled()); 150 } 151 }); 113 152 buttons.add(b); 114 153 }
Note:
See TracChangeset
for help on using the changeset viewer.