Ignore:
Timestamp:
2013-02-12T11:32:16+01:00 (11 years ago)
Author:
akks
Message:

remote control load_and_zoom+addtags improvemens, allow to delete tags (by setting empty value)
trim spaces from key/value, allow "=" in value

Location:
trunk/src/org/openstreetmap/josm/io/remotecontrol
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java

    r3851 r5706  
    1010import java.awt.GridBagLayout;
    1111import java.awt.event.ActionEvent;
     12import java.awt.event.KeyEvent;
    1213import java.util.Collection;
     14import javax.swing.AbstractAction;
    1315
    1416import javax.swing.JPanel;
    1517import javax.swing.JTable;
     18import javax.swing.KeyStroke;
    1619import javax.swing.table.DefaultTableModel;
    1720import javax.swing.table.TableCellRenderer;
     
    4043    private final JTable propertyTable;
    4144    private Collection<? extends OsmPrimitive> sel;
    42     boolean[] existing;
     45    int[] count;
    4346
     47    static class DeleteTagMarker {
     48        int num;
     49        public DeleteTagMarker(int num) {
     50            this.num = num;
     51        }
     52        public String toString() {
     53            return tr("<delete from {0} objects>", num);
     54        }
     55    }
     56   
     57           
    4458    public AddTagsDialog(String[][] tags) {
    45         super(Main.parent, tr("Add tags to selected objects"), new String[] { tr("Add tags"), tr("Cancel")},
     59        super(Main.parent, tr("Add tags to selected objects"), new String[] { tr("Add selected tags"), tr("Add all tags"), tr("Cancel")},
    4660                false,
    4761                true);
    48 
     62        setToolTipTexts(new String[]{tr("Add checked tags to selected objects"), tr("Shift+Enter: Add all tags to selected objects"), ""});
     63     
    4964        DataSet.addSelectionListener(this);
    5065
     
    5974
    6075        sel = Main.main.getCurrentDataSet().getSelected();
    61         existing = new boolean[tags.length];
    62 
     76        count = new int[tags.length];
     77       
    6378        for (int i = 0; i<tags.length; i++) {
    64             existing[i] = false;
     79            count[i] = 0;
    6580            String key = tags[i][0];
    6681            Boolean b = Boolean.TRUE;
     
    6883                if (osm.keySet().contains(key)) {
    6984                    b = Boolean.FALSE;
    70                     existing[i]=true;
     85                    count[i]++;
    7186                    break;
    7287                }
     
    7489            tm.setValueAt(b, i, 0);
    7590            tm.setValueAt(tags[i][0], i, 1);
    76             tm.setValueAt(tags[i][1], i, 2);
     91            tm.setValueAt(tags[i][1].isEmpty() ? new DeleteTagMarker(count[i]) : tags[i][1], i, 2);
    7792        }
    7893
     
    8499            public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
    85100                Component c = super.prepareRenderer(renderer, row, column);
    86                 if (existing[row]) {
     101                if (count[row]>0) {
    87102                    c.setFont(c.getFont().deriveFont(Font.ITALIC));
    88103                    c.setForeground(new Color(100, 100, 100));
     
    94109            }
    95110        };
    96 
     111       
    97112        // a checkbox has a size of 15 px
    98113        propertyTable.getColumnModel().getColumn(0).setMaxWidth(15);
    99114        // get edit results if the table looses the focus, for example if a user clicks "add tags"
    100115        propertyTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
     116        propertyTable.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_MASK), "shiftenter");
     117        propertyTable.getActionMap().put("shiftenter", new AbstractAction() {
     118            @Override  public void actionPerformed(ActionEvent e) {
     119                buttonAction(1, e); // add all tags on Shift-Enter
     120            }
     121        });
    101122
    102123        // set the content of this AddTagsDialog consisting of the tableHeader and the table itself.
     
    106127        tablePanel.add(propertyTable, GBC.eol().fill(GBC.BOTH));
    107128        setContent(tablePanel);
    108 
     129        setDefaultButton(2);
    109130        // set the default Dimensions and show the dialog
    110131        setPreferredSize(new Dimension(400,tablePanel.getPreferredSize().height+100));
     
    119140        for (int i=0; i<tm.getRowCount(); i++) {
    120141            String key = (String)tm.getValueAt(i, 1);
    121             existing[i] = false;
     142            count[i] = 0;
    122143            for (OsmPrimitive osm : sel) {
    123144                if (osm.keySet().contains(key)) {
    124                     existing[i] = true;
     145                    count[i]++;
    125146                    break;
    126147                }
     
    136157    @Override
    137158    protected void buttonAction(int buttonIndex, ActionEvent evt) {
    138         if (buttonIndex == 0) {
     159        if (buttonIndex != 2) {
    139160            TableModel tm = propertyTable.getModel();
    140161            for (int i=0; i<tm.getRowCount(); i++) {
    141                 if ((Boolean)tm.getValueAt(i, 0)) {
    142                     Main.main.undoRedo.add(new ChangePropertyCommand(sel, (String)tm.getValueAt(i, 1), (String)tm.getValueAt(i, 2)));
     162                if (buttonIndex==1 || (Boolean)tm.getValueAt(i, 0)) {
     163                    String key =(String)tm.getValueAt(i, 1);
     164                    Object value = tm.getValueAt(i, 2);
     165                    Main.main.undoRedo.add(new ChangePropertyCommand(sel,
     166                            key, value instanceof String ? (String) value : ""));
    143167                }
    144168            }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

    r5680 r5706  
    218218                        int i = 0;
    219219                        for (String tag : tagSet) {
    220                             keyValue[i++] = tag.split("=");
     220                            // support a  =   b===c as "a"="b===c"
     221                            String [] pair = tag.split("\\s*=\\s*",2);
     222                            keyValue[i][0] = pair[0];
     223                            keyValue[i][1] = pair.length<2 ? "": pair[1];
     224                            i++;
    221225                        }
    222226   
Note: See TracChangeset for help on using the changeset viewer.