Changeset 15437 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2019-10-07T00:45:30+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Check.java
r15072 r15437 2 2 package org.openstreetmap.josm.gui.tagging.presets.items; 3 3 4 import java.awt.GridBagLayout; 5 import java.awt.event.MouseAdapter; 6 import java.awt.event.MouseEvent; 4 7 import java.util.ArrayList; 5 8 import java.util.Arrays; … … 7 10 import java.util.List; 8 11 12 import javax.swing.ImageIcon; 13 import javax.swing.JLabel; 9 14 import javax.swing.JPanel; 15 import javax.swing.SwingConstants; 10 16 11 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 18 import org.openstreetmap.josm.data.osm.OsmUtils; 13 19 import org.openstreetmap.josm.data.osm.Tag; 20 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader; 14 21 import org.openstreetmap.josm.gui.widgets.QuadStateCheckBox; 15 22 import org.openstreetmap.josm.tools.GBC; … … 30 37 /** "on" or "off" or unset (default is unset) */ 31 38 public String default_; // only used for tagless objects // NOSONAR 39 /** The location of icon file to display */ 40 public String icon; // NOSONAR 41 /** The size of displayed icon. If not set, default is 16px */ 42 public String icon_size; // NOSONAR 32 43 33 44 private QuadStateCheckBox check; … … 80 91 allowedStates.add(QuadStateCheckBox.State.NOT_SELECTED); 81 92 allowedStates.add(QuadStateCheckBox.State.UNSET); 82 check = new QuadStateCheckBox( locale_text, initialState,93 check = new QuadStateCheckBox(icon == null ? locale_text : null, initialState, 83 94 allowedStates.toArray(new QuadStateCheckBox.State[0])); 84 95 check.setPropertyText(key); 85 96 check.setState(check.getState()); // to update the tooltip text 86 97 87 p.add(check, GBC.eol()); // Do not fill, see #15104 98 JPanel checkPanel = new JPanel(new GridBagLayout()); 99 checkPanel.add(check, GBC.std()); 100 if (icon != null) { 101 JLabel label = new JLabel(locale_text, getIcon(), SwingConstants.LEFT); 102 label.addMouseListener(new MouseAdapter() { 103 @Override 104 public void mousePressed(MouseEvent e) { 105 check.getMouseAdapter().mousePressed(e); 106 } 107 }); 108 checkPanel.add(label); 109 checkPanel.add(new JLabel(), GBC.eol().fill()); 110 } 111 p.add(checkPanel, GBC.eol()); // Do not fill, see #15104 88 112 return true; 89 113 } … … 106 130 } 107 131 132 /** 133 * Returns the entry icon, if any. 134 * @return the entry icon, or {@code null} 135 * @since 15437 136 */ 137 public ImageIcon getIcon() { 138 Integer size = parseInteger(icon_size); 139 return icon == null ? null : loadImageIcon(icon, TaggingPresetReader.getZipIcons(), size != null ? size : 16); 140 } 141 108 142 @Override 109 143 public Collection<String> getValues() { -
trunk/src/org/openstreetmap/josm/gui/widgets/QuadStateCheckBox.java
r15287 r15437 45 45 private final transient QuadStateDecorator cbModel; 46 46 private State[] allowed; 47 private final MouseListener mouseAdapter = new MouseAdapter() { 48 @Override 49 public void mousePressed(MouseEvent e) { 50 grabFocus(); 51 cbModel.nextState(); 52 } 53 }; 47 54 48 55 /** … … 57 64 this.allowed = Utils.copyArray(allowed); 58 65 // Add a listener for when the mouse is pressed 59 super.addMouseListener(new MouseAdapter() { 60 @Override public void mousePressed(MouseEvent e) { 61 grabFocus(); 62 cbModel.nextState(); 63 } 64 }); 66 super.addMouseListener(mouseAdapter); 65 67 // Reset the keyboard action map 66 68 ActionMap map = new ActionMapUIResource(); … … 94 96 public synchronized void addMouseListener(MouseListener l) { 95 97 // Do nothing 98 } 99 100 /** 101 * Returns the internal mouse listener. 102 * @return the internal mouse listener 103 * @since 15437 104 */ 105 public MouseListener getMouseAdapter() { 106 return mouseAdapter; 96 107 } 97 108
Note:
See TracChangeset
for help on using the changeset viewer.