Ignore:
Timestamp:
2014-04-09T19:31:36+02:00 (11 years ago)
Author:
akks
Message:

[josm_utilsplugin2]: search parents:/children:; multitagger: select, sync

Location:
applications/editors/josm/plugins/utilsplugin2
Files:
6 edited
2 copied

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/build.xml

    r30384 r30389  
    33
    44    <!-- enter the SVN commit message -->
    5     <property name="commit.message" value="[josm_utilsplugin2]: usedinways/usedinrealtions; multitagger: center on double-click"/>
     5    <property name="commit.message" value="[josm_utilsplugin2]: search parents:/children:; multitagger: select, sync"/>
    66    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    77    <property name="plugin.main.version" value="6317"/>
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTagDialog.java

    r30384 r30389  
    3030import javax.swing.KeyStroke;
    3131import javax.swing.ListSelectionModel;
    32 import javax.swing.SwingUtilities;
    3332import javax.swing.event.ListSelectionEvent;
    3433import javax.swing.event.ListSelectionListener;
     
    4039import org.openstreetmap.josm.data.osm.OsmPrimitive;
    4140import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    42 import org.openstreetmap.josm.data.preferences.StringProperty;
    4341import org.openstreetmap.josm.gui.ExtendedDialog;
    4442import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    45 import org.openstreetmap.josm.gui.tagging.TagCellEditor;
    4643import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    4744import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
    4845import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    49 import org.openstreetmap.josm.gui.util.GuiHelper;
    5046import org.openstreetmap.josm.gui.util.HighlightHelper;
    5147import org.openstreetmap.josm.gui.util.TableHelper;
     
    8884        pnl.add(cbTagSet,GBC.std().fill(GBC.HORIZONTAL));
    8985        pnl.add(new JButton(new DeleteFromHistoryAction()),GBC.std());
    90         pnl.add(new JButton(new FindMatchingAction()),GBC.eol());
     86        pnl.add(new JButton(new FindMatchingAction()),GBC.std());
     87        final JToggleButton jt = new JToggleButton("", ImageProvider.get("restart"), true);
     88        jt.setToolTipText(tr("Sync with JOSM selection"));
     89        jt.addActionListener(new ActionListener(){
     90            @Override public void actionPerformed(ActionEvent e) {
     91                tableModel.setWatchSelection(jt.isSelected());
     92            };
     93        });
     94        pnl.add(jt,GBC.eol());
     95       
     96
    9197        pnl.add(createTypeFilterPanel(), GBC.eol().fill(GBC.HORIZONTAL));
    9298        pnl.add(tbl.getTableHeader(),GBC.eop().fill(GBC.HORIZONTAL));
     
    103109    private JTable createTable() {
    104110        JTable t = new JTable(tableModel);
     111        tableModel.setTable(t);
    105112        t.setFillsViewportHeight(true);
    106         t.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     113        t.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    107114        t.addMouseListener(tableMouseAdapter);
    108115        t.setRowSelectionAllowed(true);
    109116        t.setColumnSelectionAllowed(true);
    110117        t.setDefaultRenderer(OsmPrimitiveType.class, new PrimitiveTypeIconRenderer());
    111         t.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    112118        t.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    113119        t.getSelectionModel().addListSelectionListener(selectionListener);
     
    216222                    AutoScaleAction.zoomTo(currentSelection);
    217223                }
     224            }
     225        });
     226        menu.add(new AbstractAction(tr("Select"), ImageProvider.get("dialogs", "select")) {
     227            @Override
     228            public void actionPerformed(ActionEvent e) {
     229                Main.main.getCurrentDataSet().setSelected(getSelectedPrimitives());
    218230            }
    219231        });
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTaggerTableModel.java

    r30370 r30389  
    1010import java.util.List;
    1111import java.util.Set;
     12import javax.swing.JTable;
    1213import javax.swing.table.AbstractTableModel;
     14import javax.swing.table.TableCellEditor;
    1315import org.openstreetmap.josm.Main;
    1416import org.openstreetmap.josm.command.ChangePropertyCommand;
     
    3234    private boolean autoCommit = true;
    3335    List<Command> cmds = new ArrayList<Command>();
     36    private boolean watchSelection = true;
     37    private JTable table;
    3438
    3539    public MultiTaggerTableModel() {
     
    4751    }
    4852
     53    public void setWatchSelection(boolean watchSelection) {
     54        this.watchSelection = watchSelection;
     55        if (watchSelection && Main.main.hasEditLayer()) selectionChanged(Main.main.getCurrentDataSet().getSelected());
     56    }
     57   
    4958    @Override
    5059    public Object getValueAt(int rowIndex, int columnIndex) {
     
    8695    @Override
    8796    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    88         updateData(newSelection);
     97        if (watchSelection)
     98            updateData(newSelection);
    8999    }
    90100
     
    164174
    165175    void updateData(Collection<? extends OsmPrimitive> sel) {
    166         list.clear();
     176       if (table.isEditing()) table.getCellEditor().stopCellEditing();
     177       
     178       list.clear();
    167179        for (OsmPrimitive p : sel) {
    168180            if (shownTypes.contains(p.getDisplayType())) {
     
    181193        cmds.clear();
    182194    }
     195
     196    void setTable(JTable t) {
     197        table = t;
     198    }
    183199}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ChildrenMatch.java

    r30387 r30389  
    44import org.openstreetmap.josm.actions.search.PushbackTokenizer;
    55import org.openstreetmap.josm.actions.search.SearchCompiler;
    6 import org.openstreetmap.josm.data.osm.Changeset;
    7 import org.openstreetmap.josm.data.osm.Node;
    86import org.openstreetmap.josm.data.osm.OsmPrimitive;
    97import org.openstreetmap.josm.data.osm.Relation;
    108import org.openstreetmap.josm.data.osm.Way;
    11 import org.openstreetmap.josm.data.osm.visitor.Visitor;
    129import static org.openstreetmap.josm.tools.I18n.tr;
    1310
    1411/**
    15  * Matches objects with a version number in the given range.
     12 * Matches objects with a number of child primitives in the given range.
    1613 */
    17 public class UsedInWaysMatch extends RangeMatch {
    18     public UsedInWaysMatch(PushbackTokenizer.Range range) {super(range);}
    19     public UsedInWaysMatch(PushbackTokenizer tokenizer) throws SearchCompiler.ParseError {
    20         this(tokenizer.readRange(tr("Range of attached way cuunt")));
     14public class ChildrenMatch extends RangeMatch {
     15    public ChildrenMatch(PushbackTokenizer.Range range) {super(range);}
     16    public ChildrenMatch(PushbackTokenizer tokenizer) throws SearchCompiler.ParseError {
     17        this(tokenizer.readRange(tr("Range of child primitives count")));
    2118    }
    22     private class WayCounter implements Visitor {
    23         int count;
    24         @Override
    25         public void visit(Way w) { count++; }
    26         @Override   public void visit(Node n) { }
    27         @Override   public void visit(Relation r) {   }
    28         @Override   public void visit(Changeset cs) {   }
     19
     20    @Override
     21    protected Long getNumber(OsmPrimitive osm) {
     22        if (osm instanceof Way) {
     23            return (long) ((Way)osm).getNodesCount();
     24        } else if (osm instanceof Relation) {
     25            return (long) ((Relation)osm).getMembersCount();
     26        } else {
     27            return null;
     28        }
    2929    }
    30     WayCounter counter = new WayCounter();
    3130
    32 @Override protected Long getNumber(OsmPrimitive osm) {
    33         if (osm instanceof Node) {
    34             counter.count=0;
    35             osm.visitReferrers(counter);
    36             return new Long(counter.count);
    37         } else return null;
    38     }
    39     @Override protected String getString() {
    40         return "wayrefs";
     31    @Override
     32    protected String getString() {
     33        return "children";
    4134    }
    4235}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ParentsMatch.java

    r30387 r30389  
    44import org.openstreetmap.josm.actions.search.PushbackTokenizer;
    55import org.openstreetmap.josm.actions.search.SearchCompiler;
    6 import org.openstreetmap.josm.data.osm.Changeset;
    7 import org.openstreetmap.josm.data.osm.Node;
    86import org.openstreetmap.josm.data.osm.OsmPrimitive;
    9 import org.openstreetmap.josm.data.osm.Relation;
    10 import org.openstreetmap.josm.data.osm.Way;
    11 import org.openstreetmap.josm.data.osm.visitor.Visitor;
    127import static org.openstreetmap.josm.tools.I18n.tr;
    138
    149/**
    15  * Matches objects with a version number in the given range.
     10 * Matches objects with a number of parent primitives in the given range.
    1611 */
    17 public class UsedInWaysMatch extends RangeMatch {
    18     public UsedInWaysMatch(PushbackTokenizer.Range range) {super(range);}
    19     public UsedInWaysMatch(PushbackTokenizer tokenizer) throws SearchCompiler.ParseError {
    20         this(tokenizer.readRange(tr("Range of attached way cuunt")));
     12public class ParentsMatch extends RangeMatch {
     13    public ParentsMatch(PushbackTokenizer.Range range) {super(range);}
     14    public ParentsMatch(PushbackTokenizer tokenizer) throws SearchCompiler.ParseError {
     15        this(tokenizer.readRange(tr("Range of parent primitives count")));
    2116    }
    22     private class WayCounter implements Visitor {
    23         int count;
    24         @Override
    25         public void visit(Way w) { count++; }
    26         @Override   public void visit(Node n) { }
    27         @Override   public void visit(Relation r) {   }
    28         @Override   public void visit(Changeset cs) {   }
     17    @Override
     18    protected Long getNumber(OsmPrimitive osm) {
     19        return new Long(osm.getReferrers().size());
    2920    }
    30     WayCounter counter = new WayCounter();
    31 
    32 @Override protected Long getNumber(OsmPrimitive osm) {
    33         if (osm instanceof Node) {
    34             counter.count=0;
    35             osm.visitReferrers(counter);
    36             return new Long(counter.count);
    37         } else return null;
    38     }
    39     @Override protected String getString() {
    40         return "wayrefs";
     21    @Override
     22    protected String getString() {
     23        return "parents";
    4124    }
    4225}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UsedInRelationsMatch.java

    r30384 r30389  
    3030    RelationCounter counter = new RelationCounter();
    3131
    32     @Override protected Long getNumber(OsmPrimitive osm) {
     32    @Override
     33    protected Long getNumber(OsmPrimitive osm) {
    3334        counter.count=0;
    3435        osm.visitReferrers(counter);
    3536        return new Long(counter.count);
    3637    }
    37     @Override protected String getString() {
     38    @Override
     39    protected String getString() {
    3840        return "usedinrelations";
    3941    }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UsedInWaysMatch.java

    r30384 r30389  
    1313
    1414/**
    15  * Matches objects with a version number in the given range.
     15 * Matches nodes that are attached to given range of ways
    1616 */
    1717public class UsedInWaysMatch extends RangeMatch {
    1818    public UsedInWaysMatch(PushbackTokenizer.Range range) {super(range);}
    1919    public UsedInWaysMatch(PushbackTokenizer tokenizer) throws SearchCompiler.ParseError {
    20         this(tokenizer.readRange(tr("Range of attached way cuunt")));
     20        this(tokenizer.readRange(tr("Range of attached ways count")));
    2121    }
    2222    private class WayCounter implements Visitor {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UtilsSimpleMatchFactory.java

    r30384 r30389  
    99public class UtilsSimpleMatchFactory implements SimpleMatchFactory {
    1010   
    11     private static Collection<String> keywords = Arrays.asList("usedinways", "usedinrelations");
     11    private static Collection<String> keywords = Arrays.asList("usedinways", "usedinrelations", "parents", "children");
    1212
    1313    @Override
     
    2424            return new UsedInRelationsMatch(tokenizer);
    2525        } else
     26        if ("parents".equals(keyword)) {
     27            return new ParentsMatch(tokenizer);
     28        } else
     29        if ("children".equals(keyword)) {
     30            return new ChildrenMatch(tokenizer);
     31        } else
    2632            return null;
    2733    };
Note: See TracChangeset for help on using the changeset viewer.