Changeset 29758 in osm for applications/editors/josm


Ignore:
Timestamp:
2013-07-17T06:51:58+02:00 (11 years ago)
Author:
akks
Message:

'[josm_tagging_preset_tester] fix #josm8879: make all panels active by default and use current selection'

Location:
applications/editors/josm/plugins/tagging-preset-tester
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/tagging-preset-tester/build.xml

    r29435 r29758  
    2626-->
    2727<project name="tagging-preset-tester" default="dist" basedir=".">
    28     <property name="commit.message" value="fix shortcuts conflict"/>
     28    <property name="commit.message" value="[josm_tagging_preset_tester] fix #josm8879: make all panels active by default and use current selection"/>
    2929    <property name="plugin.main.version" value="4980"/>
    3030    <property name="josm" location="../../core/dist/josm-custom.jar"/>
  • applications/editors/josm/plugins/tagging-preset-tester/src/org/openstreetmap/josm/plugins/taggingpresettester/TaggingPresetTester.java

    r29748 r29758  
    1919import javax.swing.JPanel;
    2020
     21import org.openstreetmap.josm.Main;
     22import org.openstreetmap.josm.data.coor.LatLon;
     23import org.openstreetmap.josm.data.osm.Node;
    2124import org.openstreetmap.josm.data.osm.OsmPrimitive;
     25import org.openstreetmap.josm.data.osm.Relation;
     26import org.openstreetmap.josm.data.osm.Way;
    2227import org.openstreetmap.josm.gui.tagging.TaggingPreset;
    2328
     
    3237    private JPanel panel = new JPanel(new BorderLayout());
    3338
    34     public void reload() {
     39    public final void reload() {
    3540        Vector<TaggingPreset> allPresets = new Vector<TaggingPreset>(TaggingPreset.readAll(Arrays.asList(args), true));
    3641        taggingPresets.setModel(new DefaultComboBoxModel(allPresets));
    3742    }
    3843
    39     public void reselect() {
     44    public final void reselect() {
    4045        taggingPresetPanel.removeAll();
    4146        TaggingPreset preset = (TaggingPreset)taggingPresets.getSelectedItem();
    4247        if (preset == null)
    4348            return;
    44         Collection<OsmPrimitive> x = Collections.emptySet();
     49        Collection<OsmPrimitive> x;
     50        if (Main.main.hasEditLayer()) {
     51            x = Main.main.getCurrentDataSet().getSelected();
     52        } else {
     53            x = makeFakeSuitablePrimitive(preset);
     54        }
    4555        JPanel p = preset.createPanel(x);
    46         p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    47         if (p != null)
     56        if (p != null) {
     57            p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    4858            taggingPresetPanel.add(p, BorderLayout.NORTH);
     59        }
    4960        panel.validate();
    5061        panel.repaint();
     
    6172        panel.add(taggingPresetPanel, BorderLayout.CENTER);
    6273        taggingPresets.addActionListener(new ActionListener(){
     74            @Override
    6375            public void actionPerformed(ActionEvent e) {
    6476                reselect();
     
    6981        JButton b = new JButton(tr("Reload"));
    7082        b.addActionListener(new ActionListener(){
     83            @Override
    7184            public void actionPerformed(ActionEvent e) {
    7285                int i = taggingPresets.getSelectedIndex();
     
    8194        setContentPane(panel);
    8295        setSize(300,500);
    83         setVisible(true);
    8496    }
    8597
     
    94106        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    95107    }
     108
     109    private Collection<OsmPrimitive> makeFakeSuitablePrimitive(TaggingPreset preset) {
     110        if (preset.typeMatches(Collections.singleton(TaggingPreset.PresetType.NODE))) {
     111            return Collections.<OsmPrimitive>singleton(new Node());
     112        } else if (preset.typeMatches(Collections.singleton(TaggingPreset.PresetType.WAY))) {
     113            return Collections.<OsmPrimitive>singleton(new Way());
     114        } else if (preset.typeMatches(Collections.singleton(TaggingPreset.PresetType.RELATION))) {
     115            return Collections.<OsmPrimitive>singleton(new Relation());
     116        } else if (preset.typeMatches(Collections.singleton(TaggingPreset.PresetType.CLOSEDWAY))) {
     117            Way w = new Way();
     118            w.addNode(new Node(new LatLon(0,0)));
     119            w.addNode(new Node(new LatLon(0,1)));
     120            w.addNode(new Node(new LatLon(1,1)));
     121            w.addNode(new Node(new LatLon(0,0)));
     122            return Collections.<OsmPrimitive>singleton(w);
     123        } else {
     124            return Collections.emptySet();
     125        }
     126    }
    96127}
  • applications/editors/josm/plugins/tagging-preset-tester/src/org/openstreetmap/josm/plugins/taggingpresettester/TaggingPresetTesterAction.java

    r29748 r29758  
    3636    }
    3737
     38    @Override
    3839    public void actionPerformed(ActionEvent e) {
    3940        Collection<String> coll = TaggingPreset.getPresetSources();
    4041
    41         if (coll.size() == 0) {
     42        if (coll.isEmpty()) {
    4243            JOptionPane.showMessageDialog(Main.parent, tr("You have to specify tagging preset sources in the preferences first."));
    4344            return;
     
    4647        String[] taggingPresetSources = new String [coll.size()];
    4748        coll.toArray(taggingPresetSources);
    48         new TaggingPresetTester(taggingPresetSources);
     49        new TaggingPresetTester(taggingPresetSources).setVisible(true);
    4950    }
    5051}
Note: See TracChangeset for help on using the changeset viewer.