Changeset 15437 in josm for trunk


Ignore:
Timestamp:
2019-10-07T00:45:30+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #13015 - add icons to preset <check>s

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/defaultpresets.xml

    r15434 r15437  
    24982498            <space />
    24992499            <checkgroup columns="2">
    2500                 <check key="bus" text="Bus" />
    2501                 <check key="highway" value_on="bus_stop" value_off="" text="Bus stop (legacy)" />
    2502                 <check key="tram" text="Tram" />
    2503                 <check key="railway" value_on="tram_stop" value_off="" text="Tram stop (legacy)" />
    2504                 <check key="train" text="Train" />
    2505                 <check key="railway" value_on="halt" value_off="" text="Railway halt (legacy)" />
     2500                <check key="bus" text="Bus" icon="presets/transport/bus.svg" />
     2501                <check key="highway" value_on="bus_stop" value_off="" text="Bus stop (legacy)" icon="presets/transport/bus.svg" />
     2502                <check key="tram" text="Tram" icon="presets/transport/railway/tram.svg" />
     2503                <check key="railway" value_on="tram_stop" value_off="" text="Tram stop (legacy)" icon="presets/transport/railway/tram.svg" />
     2504                <check key="train" text="Train" icon="presets/transport/train.svg" />
     2505                <check key="railway" value_on="halt" value_off="" text="Railway halt (legacy)" icon="presets/transport/train.svg" />
    25062506            </checkgroup>
    2507             <check key="trolleybus" text="Trolleybus" />
    2508             <check key="share_taxi" text="Share taxi" />
    2509             <check key="subway" text="Subway" />
    2510             <check key="light_rail" text="Light Rail" />
    2511             <check key="monorail" text="Monorail" />
    2512             <check key="funicular" text="Funicular" />
    2513             <check key="aerialway" text="Aerialway" />
    2514             <check key="ferry" text="Ferry" />
     2507            <check key="trolleybus" text="Trolleybus" icon="presets/transport/trolleybus.svg" />
     2508            <check key="share_taxi" text="Share taxi" icon="presets/transport/share_taxi.svg" />
     2509            <check key="subway" text="Subway" icon="presets/transport/railway/subway.svg" />
     2510            <check key="light_rail" text="Light Rail" icon="presets/transport/railway/light_rail.svg" />
     2511            <check key="monorail" text="Monorail" icon="presets/transport/railway/monorail.svg" />
     2512            <check key="funicular" text="Funicular" icon="presets/transport/railway/funicular.svg" />
     2513            <check key="aerialway" text="Aerialway" icon="presets/transport/aerialway/station.svg" />
     2514            <check key="ferry" text="Ferry" icon="presets/nautical/ferry.svg" />
    25152515        </item> <!-- Stop Position -->
    25162516        <item name="Platform" type="node,way,closedway,multipolygon" icon="presets/transport/platform.svg" preset_name_label="true">
  • trunk/data/tagging-preset.xsd

    r14646 r15437  
    270270        <attribute name="disable_off" type="boolean" />
    271271        <attribute name="match" type="tns:match" />
     272        <attribute name="icon" type="string" />
     273        <attribute name="icon_size" type="integer" />
    272274
    273275        <attribute name="name" use="prohibited" />
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Check.java

    r15072 r15437  
    22package org.openstreetmap.josm.gui.tagging.presets.items;
    33
     4import java.awt.GridBagLayout;
     5import java.awt.event.MouseAdapter;
     6import java.awt.event.MouseEvent;
    47import java.util.ArrayList;
    58import java.util.Arrays;
     
    710import java.util.List;
    811
     12import javax.swing.ImageIcon;
     13import javax.swing.JLabel;
    914import javax.swing.JPanel;
     15import javax.swing.SwingConstants;
    1016
    1117import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1218import org.openstreetmap.josm.data.osm.OsmUtils;
    1319import org.openstreetmap.josm.data.osm.Tag;
     20import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader;
    1421import org.openstreetmap.josm.gui.widgets.QuadStateCheckBox;
    1522import org.openstreetmap.josm.tools.GBC;
     
    3037    /** "on" or "off" or unset (default is unset) */
    3138    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
    3243
    3344    private QuadStateCheckBox check;
     
    8091            allowedStates.add(QuadStateCheckBox.State.NOT_SELECTED);
    8192        allowedStates.add(QuadStateCheckBox.State.UNSET);
    82         check = new QuadStateCheckBox(locale_text, initialState,
     93        check = new QuadStateCheckBox(icon == null ? locale_text : null, initialState,
    8394                allowedStates.toArray(new QuadStateCheckBox.State[0]));
    8495        check.setPropertyText(key);
    8596        check.setState(check.getState()); // to update the tooltip text
    8697
    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
    88112        return true;
    89113    }
     
    106130    }
    107131
     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
    108142    @Override
    109143    public Collection<String> getValues() {
  • trunk/src/org/openstreetmap/josm/gui/widgets/QuadStateCheckBox.java

    r15287 r15437  
    4545    private final transient QuadStateDecorator cbModel;
    4646    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    };
    4754
    4855    /**
     
    5764        this.allowed = Utils.copyArray(allowed);
    5865        // 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);
    6567        // Reset the keyboard action map
    6668        ActionMap map = new ActionMapUIResource();
     
    9496    public synchronized void addMouseListener(MouseListener l) {
    9597        // 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;
    96107    }
    97108
Note: See TracChangeset for help on using the changeset viewer.