Changeset 6221 in josm for trunk/src/org/openstreetmap/josm/gui/widgets
- Timestamp:
- 2013-09-07T17:52:27+02:00 (11 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/widgets/QuadStateCheckBox.java
r6219 r6221 1 1 // License: GPL. Copyright 2008 by Frederik Ramm and others 2 package org.openstreetmap.josm.gui; 2 package org.openstreetmap.josm.gui.widgets; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; … … 21 21 import javax.swing.plaf.ActionMapUIResource; 22 22 23 import org.openstreetmap.josm.tools.Utils; 24 25 /** 26 * A four-state checkbox. The states are enumerated in {@link State}. 27 * @since 591 28 */ 23 29 public class QuadStateCheckBox extends JCheckBox { 24 30 25 public enum State { NOT_SELECTED, SELECTED, UNSET, PARTIAL } 31 /** 32 * The 4 possible states of this checkbox. 33 */ 34 public enum State { 35 /** Not selected: the property is explicitly switched off */ 36 NOT_SELECTED, 37 /** Selected: the property is explicitly switched on */ 38 SELECTED, 39 /** Unset: do not set this property on the selected objects */ 40 UNSET, 41 /** Partial: different selected objects have different values, do not change */ 42 PARTIAL 43 } 26 44 27 45 private final QuadStateDecorator model; 28 46 private State[] allowed; 29 47 48 /** 49 * Constructs a new {@code QuadStateCheckBox}. 50 * @param text the text of the check box 51 * @param icon the Icon image to display 52 * @param initial The initial state 53 * @param allowed The allowed states 54 */ 30 55 public QuadStateCheckBox(String text, Icon icon, State initial, State[] allowed) { 31 56 super(text, icon); 32 this.allowed = allowed;57 this.allowed = Utils.copyArray(allowed); 33 58 // Add a listener for when the mouse is pressed 34 59 super.addMouseListener(new MouseAdapter() { … … 54 79 setState(initial); 55 80 } 81 82 /** 83 * Constructs a new {@code QuadStateCheckBox}. 84 * @param text the text of the check box 85 * @param initial The initial state 86 * @param allowed The allowed states 87 */ 56 88 public QuadStateCheckBox(String text, State initial, State[] allowed) { 57 89 this(text, null, initial, allowed); … … 60 92 /** Do not let anyone add mouse listeners */ 61 93 @Override public void addMouseListener(MouseListener l) { } 94 62 95 /** 63 96 * Set the new state. 64 */ 65 public void setState(State state) { model.setState(state); } 66 /** Return the current state, which is determined by the 67 * selection status of the model. */ 68 public State getState() { return model.getState(); } 69 @Override public void setSelected(boolean b) { 97 * @param state The new state 98 */ 99 public void setState(State state) { 100 model.setState(state); 101 } 102 103 /** 104 * Return the current state, which is determined by the selection status of the model. 105 * @return The current state 106 */ 107 public State getState() { 108 return model.getState(); 109 } 110 111 @Override 112 public void setSelected(boolean b) { 70 113 if (b) { 71 114 setState(State.SELECTED); … … 77 120 private class QuadStateDecorator implements ButtonModel { 78 121 private final ButtonModel other; 122 79 123 private QuadStateDecorator(ButtonModel other) { 80 124 this.other = other; 81 125 } 126 82 127 private void setState(State state) { 83 128 if (state == State.NOT_SELECTED) { … … 103 148 } 104 149 } 150 105 151 /** 106 152 * The current state is embedded in the selection / armed … … 139 185 @Override public void setSelected(boolean b) { } 140 186 @Override public void setPressed(boolean b) { } 141 /** We disable focusing on the component when it is not 142 * enabled. */ 187 /** We disable focusing on the component when it is not enabled. */ 143 188 @Override public void setEnabled(boolean b) { 144 189 setFocusable(b);
Note:
See TracChangeset
for help on using the changeset viewer.