Changeset 3518 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
10.09.2010 07:45:16 (17 months ago)
Author:
jttt
Message:
  • add New relation button to Preset dialog
  • add required attribute to tagging preset (allows to specify what tags has to filled for osm primitive to qualify as having preset)
  • show list of preset also in relation dialog
Location:
trunk/src/org/openstreetmap/josm/gui
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r3501 r3518  
    77import java.awt.BorderLayout; 
    88import java.awt.Component; 
    9 import java.awt.Cursor; 
    10 import java.awt.Dialog.ModalityType; 
    11 import java.awt.Dimension; 
    129import java.awt.Font; 
    1310import java.awt.GridBagLayout; 
    1411import java.awt.Point; 
     12import java.awt.Dialog.ModalityType; 
    1513import java.awt.event.ActionEvent; 
    1614import java.awt.event.ActionListener; 
     
    2018import java.awt.event.MouseAdapter; 
    2119import java.awt.event.MouseEvent; 
    22 import java.awt.event.MouseListener; 
    2320import java.util.ArrayList; 
    2421import java.util.Collection; 
     
    6663import org.openstreetmap.josm.data.osm.Relation; 
    6764import org.openstreetmap.josm.data.osm.RelationMember; 
     65import org.openstreetmap.josm.data.osm.Tag; 
    6866import org.openstreetmap.josm.data.osm.Way; 
    6967import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 
     
    7876import org.openstreetmap.josm.gui.SideButton; 
    7977import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 
     78import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler; 
    8079import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 
    8180import org.openstreetmap.josm.gui.layer.OsmDataLayer; 
    82 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference; 
    8381import org.openstreetmap.josm.gui.tagging.TaggingPreset; 
    8482import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox; 
     
    480478    private final SideButton btnEdit; 
    481479    private final SideButton btnDel; 
    482     private final JPanel presets = new JPanel(new GridBagLayout()); 
     480    private final PresetListPanel presets = new PresetListPanel(); 
    483481 
    484482    private final JLabel selectSth = new JLabel("<html><p>" 
     
    716714    } 
    717715 
    718     private void checkPresets(int nodes, int ways, int relations, int closedways) 
    719     { 
    720         /** 
    721          * Small helper class that manages the highlighting of the label on hover as well as opening 
    722          * the corresponding preset when clicked 
    723          */ 
    724         class PresetLabelML implements MouseListener { 
    725             JLabel label; 
    726             Font bold; 
    727             Font normal; 
    728             TaggingPreset tag; 
    729             PresetLabelML(JLabel lbl, TaggingPreset t) { 
    730                 super(); 
    731                 label = lbl; 
    732                 lbl.setCursor(new Cursor(Cursor.HAND_CURSOR)); 
    733                 normal = label.getFont(); 
    734                 bold = normal.deriveFont(normal.getStyle() ^ Font.BOLD); 
    735                 tag = t; 
    736             } 
    737             public void mouseClicked(MouseEvent arg0) { 
    738                 tag.actionPerformed(null); 
    739             } 
    740             public void mouseEntered(MouseEvent arg0) { 
    741                 label.setFont(bold); 
    742             } 
    743             public void mouseExited(MouseEvent arg0) { 
    744                 label.setFont(normal); 
    745             } 
    746             public void mousePressed(MouseEvent arg0) {} 
    747             public void mouseReleased(MouseEvent arg0) {} 
    748         } 
    749  
    750         presets.removeAll(); 
    751         int total = nodes+ways+relations+closedways; 
    752         if(total == 0) { 
    753             presets.setVisible(false); 
    754             return; 
    755         } 
    756  
    757         for(TaggingPreset t : TaggingPresetPreference.taggingPresets) { 
    758             if((t.types == null || !((relations > 0 && !t.types.contains("relation")) && 
    759                     (nodes > 0 && !t.types.contains("node")) && 
    760                     (ways+closedways > 0 && !t.types.contains("way")) && 
    761                     (closedways > 0 && !t.types.contains("closedway")))) && t.isShowable()) 
    762             { 
    763                 int found = 0; 
    764                 for(TaggingPreset.Item i : t.data) { 
    765                     if(!(i instanceof TaggingPreset.Key)) { 
    766                         continue; 
    767                     } 
    768                     String val = ((TaggingPreset.Key)i).value; 
    769                     String key = ((TaggingPreset.Key)i).key; 
    770                     // we subtract 100 if not found and add 1 if found 
    771                     found -= 100; 
    772                     if(key == null || !valueCount.containsKey(key)) { 
    773                         continue; 
    774                     } 
    775  
    776                     Map<String, Integer> v = valueCount.get(key); 
    777                     if(v.size() == 1 && val != null && v.containsKey(val) && v.get(val) == total) { 
    778                         found += 101; 
    779                     } 
    780                 } 
    781  
    782                 if(found <= 0) { 
    783                     continue; 
    784                 } 
    785  
    786                 JLabel lbl = new JLabel(t.getName()); 
    787                 lbl.addMouseListener(new PresetLabelML(lbl, t)); 
    788                 presets.add(lbl, GBC.eol().fill(GBC.HORIZONTAL)); 
    789             } 
    790         } 
    791  
    792         if(presets.getComponentCount() > 0) { 
    793             presets.setVisible(true); 
    794             // This ensures the presets are exactly as high as needed. 
    795             int height = presets.getComponentCount() * presets.getComponent(0).getHeight(); 
    796             Dimension size = new Dimension(presets.getWidth(), height); 
    797             presets.setMaximumSize(size); 
    798             presets.setMinimumSize(size); 
    799         } else { 
    800             presets.setVisible(false); 
    801         } 
    802     } 
    803  
    804716    private int findRow(TableModel model, Object value) { 
    805717        for (int i=0; i<model.getRowCount(); i++) { 
     
    809721        return -1; 
    810722    } 
     723 
     724    private PresetHandler presetHandler = new PresetHandler() { 
     725 
     726        @Override 
     727        public void updateTags(List<Tag> tags) { 
     728            Command command = TaggingPreset.createCommand(getSelection(), tags); 
     729            if (command != null) { 
     730                Main.main.undoRedo.add(command); 
     731            } 
     732        } 
     733 
     734        @Override 
     735        public Collection<OsmPrimitive> getSelection() { 
     736            if (Main.main == null) return null; 
     737            if (Main.main.getCurrentDataSet() == null) return null; 
     738 
     739            return Main.main.getCurrentDataSet().getSelected(); 
     740        } 
     741    }; 
    811742 
    812743    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 
     
    870801            propertyData.addRow(new Object[]{e.getKey(), e.getValue()}); 
    871802        } 
    872  
    873         // re-load membership data 
    874         // this is rather expensive since we have to walk through all members of all existing relationships. 
    875         // could use back references here for speed if necessary. 
    876803 
    877804        membershipData.setRowCount(0); 
     
    913840        } 
    914841 
    915         checkPresets(nodes, ways, relations, closedways); 
     842        presets.updatePresets(nodes, ways, relations, closedways, valueCount, presetHandler); 
    916843 
    917844        membershipTable.getTableHeader().setVisible(membershipData.getRowCount() > 0); 
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r3508 r3518  
    2424import java.util.Collection; 
    2525import java.util.Collections; 
     26import java.util.HashMap; 
    2627import java.util.HashSet; 
    2728import java.util.Iterator; 
    2829import java.util.List; 
     30import java.util.Map; 
    2931import java.util.Set; 
    3032import java.util.logging.Logger; 
     
    6163import org.openstreetmap.josm.data.osm.Relation; 
    6264import org.openstreetmap.josm.data.osm.RelationMember; 
     65import org.openstreetmap.josm.data.osm.Tag; 
    6366import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 
    6467import org.openstreetmap.josm.gui.DefaultNameFormatter; 
     
    6669import org.openstreetmap.josm.gui.SideButton; 
    6770import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 
     71import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler; 
    6872import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction; 
    6973import org.openstreetmap.josm.gui.help.HelpUtil; 
    7074import org.openstreetmap.josm.gui.layer.OsmDataLayer; 
    7175import org.openstreetmap.josm.gui.tagging.TagEditorPanel; 
     76import org.openstreetmap.josm.gui.tagging.TagModel; 
    7277import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; 
    7378import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 
     
    123128        referrerModel = new ReferringRelationsBrowserModel(relation); 
    124129 
    125         tagEditorPanel = new TagEditorPanel(); 
     130        tagEditorPanel = new TagEditorPanel(new PresetHandler() { 
     131 
     132            @Override 
     133            public void updateTags(List<Tag> tags) { 
     134                Map<String, TagModel> modelTags = new HashMap<String, TagModel>(); 
     135                for (int i=0; i<tagEditorPanel.getModel().getRowCount(); i++) { 
     136                    TagModel tagModel = tagEditorPanel.getModel().get(i); 
     137                    modelTags.put(tagModel.getName(), tagModel); 
     138                } 
     139                for (Tag tag: tags) { 
     140                    TagModel existing = modelTags.get(tag.getKey()); 
     141 
     142                    if (tag.getValue().isEmpty()) { 
     143                        if (existing != null) { 
     144                            tagEditorPanel.getModel().delete(tag.getKey()); 
     145                        } 
     146                    } else { 
     147                        if (existing != null) { 
     148                            tagEditorPanel.getModel().updateTagValue(existing, tag.getValue()); 
     149                        } else { 
     150                            tagEditorPanel.getModel().add(tag.getKey(), tag.getValue()); 
     151                        } 
     152                    } 
     153 
     154                } 
     155            } 
     156 
     157            @Override 
     158            public Collection<OsmPrimitive> getSelection() { 
     159                Relation relation = new Relation(); 
     160                tagEditorPanel.getModel().applyToPrimitive(relation); 
     161                return Collections.<OsmPrimitive>singletonList(relation); 
     162            } 
     163        }); 
     164 
    126165        // populate the models 
    127166        // 
  • trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java

    r3133 r3518  
    2727    protected void build() { 
    2828        setLayout(new BorderLayout()); 
    29         add(pnlTagEditor = new TagEditorPanel(), BorderLayout.CENTER); 
     29        add(pnlTagEditor = new TagEditorPanel(null), BorderLayout.CENTER); 
    3030    } 
    3131 
    3232    /** 
    3333     * Creates a new panel 
    34      *  
     34     * 
    3535     * @param changesetCommentModel the changeset comment model. Must not be null. 
    3636     * @throws IllegalArgumentException thrown if {@code changesetCommentModel} is null 
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java

    r3141 r3518  
    5050     * Creates a new tag editor model. Internally allocates two selection models 
    5151     * for row selection and column selection. 
    52      *  
     52     * 
    5353     * To create a {@see JTable} with this model: 
    5454     * <pre> 
     
    5656     *    TagTable tbl  = new TagTabel(model); 
    5757     * </pre> 
    58      *  
     58     * 
    5959     * @see #getRowSelectionModel() 
    6060     * @see #getColumnSelectionModel() 
     
    6666    /** 
    6767     * Creates a new tag editor model. 
    68      *  
     68     * 
    6969     * @param rowSelectionModel the row selection model. Must not be null. 
    7070     * @param colSelectionModel the column selection model. Must not be null. 
     
    8585    /** 
    8686     * Replies the row selection model used by this tag editor model 
    87      *  
     87     * 
    8888     * @return the row selection model used by this tag editor model 
    8989     */ 
     
    9494    /** 
    9595     * Replies the column selection model used by this tag editor model 
    96      *  
     96     * 
    9797     * @return the column selection model used by this tag editor model 
    9898     */ 
     
    355355        tags.add(tag); 
    356356        setDirty(false); 
     357        fireTableDataChanged(); 
    357358    } 
    358359 
     
    441442    /** 
    442443     * Replies the the tags in this tag editor model as {@see TagCollection}. 
    443      *  
     444     * 
    444445     * @return the the tags in this tag editor model as {@see TagCollection} 
    445446     */ 
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java

    r3210 r3518  
    66import java.awt.GridBagLayout; 
    77import java.awt.Insets; 
     8import java.util.HashMap; 
     9import java.util.Map; 
     10import java.util.Map.Entry; 
    811import java.util.logging.Logger; 
    912 
     
    1215import javax.swing.JPanel; 
    1316import javax.swing.JScrollPane; 
     17import javax.swing.event.TableModelEvent; 
     18import javax.swing.event.TableModelListener; 
    1419 
     20import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel; 
     21import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler; 
    1522import org.openstreetmap.josm.gui.layer.OsmDataLayer; 
    1623import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 
     
    3340    private TagTable tagTable; 
    3441 
     42    private PresetListPanel presetListPanel; 
     43    private final PresetHandler presetHandler; 
     44 
    3545    private AutoCompletionManager autocomplete; 
    3646    private AutoCompletionList acList; 
     
    4656        pnl.setLayout(new BorderLayout()); 
    4757        pnl.add(new JScrollPane(tagTable), BorderLayout.CENTER); 
     58        if (presetHandler != null) { 
     59            presetListPanel = new PresetListPanel(); 
     60            pnl.add(presetListPanel, BorderLayout.NORTH); 
     61        } 
    4862        return pnl; 
    4963    } 
     
    98112        gc.anchor = GridBagConstraints.CENTER; 
    99113        add(tablePanel,gc); 
     114 
     115        if (presetHandler != null) { 
     116            model.addTableModelListener(new TableModelListener() { 
     117                @Override 
     118                public void tableChanged(TableModelEvent e) { 
     119                    updatePresets(); 
     120                } 
     121            }); 
     122        } 
    100123    } 
    101124 
     
    104127     * internally and can be retrieved with {@see #getModel()}. 
    105128     */ 
    106     public TagEditorPanel() { 
    107         this(null); 
     129    public TagEditorPanel(PresetHandler presetHandler) { 
     130        this(null, presetHandler); 
    108131    } 
    109132 
     
    111134     * Creates a new tag editor panel with a supplied model. If 
    112135     * {@code model} is null, a new model is created. 
    113      *  
     136     * 
    114137     * @param model the tag editor model 
    115138     */ 
    116     public TagEditorPanel(TagEditorModel model) { 
     139    public TagEditorPanel(TagEditorModel model, PresetHandler presetHandler) { 
    117140        this.model = model; 
     141        this.presetHandler = presetHandler; 
    118142        if (this.model == null) { 
    119143            this.model = new TagEditorModel(); 
     
    135159     * tag editor panel. {@code layer} is the data layer from whose data set 
    136160     * tag values are proposed as auto completion items. 
    137      *  
     161     * 
    138162     * @param layer the data layer. Must not be null. 
    139163     * @throws IllegalArgumentException thrown if {@code layer} is null 
     
    158182        super.setEnabled(enabled); 
    159183    } 
     184 
     185    private void updatePresets() { 
     186        Map<String, Map<String, Integer>> valuesCount = new HashMap<String, Map<String,Integer>>(); 
     187        for (Entry<String, String> entry: model.getTags().entrySet()) { 
     188            Map<String, Integer> values = new HashMap<String, Integer>(); 
     189            values.put(entry.getValue(), 1); 
     190            valuesCount.put(entry.getKey(), values); 
     191        } 
     192        presetListPanel.updatePresets(0, 0, 1, 0, valuesCount, presetHandler); 
     193        validate(); 
     194    } 
    160195} 
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r3486 r3518  
    1919import java.io.Reader; 
    2020import java.io.UnsupportedEncodingException; 
     21import java.util.ArrayList; 
    2122import java.util.Arrays; 
    2223import java.util.Collection; 
     24import java.util.Collections; 
    2325import java.util.EnumSet; 
    2426import java.util.HashMap; 
     
    3739import javax.swing.JPanel; 
    3840import javax.swing.JTextField; 
     41import javax.swing.SwingUtilities; 
    3942import javax.xml.transform.stream.StreamSource; 
    4043 
    4144import org.openstreetmap.josm.Main; 
     45import org.openstreetmap.josm.command.AddCommand; 
    4246import org.openstreetmap.josm.command.ChangePropertyCommand; 
    4347import org.openstreetmap.josm.command.Command; 
     
    4751import org.openstreetmap.josm.data.osm.OsmUtils; 
    4852import org.openstreetmap.josm.data.osm.Relation; 
     53import org.openstreetmap.josm.data.osm.Tag; 
    4954import org.openstreetmap.josm.data.osm.Way; 
    5055import org.openstreetmap.josm.gui.ExtendedDialog; 
     
    8893            return name().toLowerCase(); 
    8994        } 
    90  
    91     } 
     95    } 
     96 
     97    public static final int DIALOG_ANSWER_APPLY = 1; 
     98    public static final int DIALOG_ANSWER_NEW_RELATION = 2; 
     99    public static final int DIALOG_ANSWER_CANCEL = 3; 
    92100 
    93101    public TaggingPresetMenu group = null; 
     
    109117        public boolean focus = false; 
    110118        abstract boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel); 
    111         abstract void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds); 
     119        abstract void addCommands(List<Tag> changedTags); 
    112120        boolean requestFocusInWindow() {return false;} 
    113121    } 
     
    175183        public boolean use_last_as_default = false; 
    176184        public boolean delete_if_empty = false; 
     185        public boolean required = false; 
    177186 
    178187        private JComponent value; 
     
    220229        } 
    221230 
    222         @Override public void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds) { 
     231        @Override public void addCommands(List<Tag> changedTags) { 
    223232 
    224233            // return if unchanged 
     
    235244                        v = null; 
    236245                    } 
    237                     cmds.add(new ChangePropertyCommand(sel, key, v)); 
     246                    changedTags.add(new Tag(key, v)); 
    238247        } 
    239248        @Override boolean requestFocusInWindow() {return value.requestFocusInWindow();} 
     
    250259        public boolean default_ = false; // only used for tagless objects 
    251260        public boolean use_last_as_default = false; 
     261        public boolean required = false; 
    252262 
    253263        private QuadStateCheckBox check; 
     
    312322        } 
    313323 
    314         @Override public void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds) { 
     324        @Override public void addCommands(List<Tag> changedTags) { 
    315325            // if the user hasn't changed anything, don't create a command. 
    316326            if (check.getState() == initialState && !def) return; 
    317327 
    318328            // otherwise change things according to the selected value. 
    319             cmds.add(new ChangePropertyCommand(sel, key, 
     329            changedTags.add(new Tag(key, 
    320330                    check.getState() == QuadStateCheckBox.State.SELECTED ? value_on : 
    321331                        check.getState() == QuadStateCheckBox.State.NOT_SELECTED ? value_off : 
     
    339349        public boolean editable = true; 
    340350        public boolean use_last_as_default = false; 
     351        public boolean required = false; 
    341352 
    342353        private JComboBox combo; 
     
    432443            return true; 
    433444        } 
    434         @Override public void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds) { 
     445        @Override public void addCommands(List<Tag> changedTags) { 
    435446            Object obj = combo.getSelectedItem(); 
    436447            String display = (obj == null) ? null : obj.toString(); 
     
    464475                lastValue.put(key, value); 
    465476            } 
    466             cmds.add(new ChangePropertyCommand(sel, key, value)); 
     477            changedTags.add(new Tag(key, value)); 
    467478        } 
    468479        @Override boolean requestFocusInWindow() {return combo.requestFocusInWindow();} 
     
    485496            return false; 
    486497        } 
    487         @Override public void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds) {} 
     498        @Override public void addCommands(List<Tag> changedTags) {} 
    488499    } 
    489500 
     
    514525            return false; 
    515526        } 
    516         @Override public void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds) {} 
     527        @Override public void addCommands(List<Tag> changedTags) {} 
    517528    } 
    518529 
     
    603614            return false; 
    604615        } 
    605         @Override public void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds) {} 
     616        @Override public void addCommands(List<Tag> changedTags) {} 
    606617    } 
    607618 
     
    614625            return false; 
    615626        } 
    616         @Override public void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds) {} 
     627        @Override public void addCommands(List<Tag> changedTags) {} 
    617628    } 
    618629 
     
    622633            return false; 
    623634        } 
    624         @Override public void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds) {} 
     635        @Override public void addCommands(List<Tag> changedTags) {} 
    625636    } 
    626637 
     
    630641 
    631642        @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { return false; } 
    632         @Override public void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds) { 
    633             cmds.add(new ChangePropertyCommand(sel, key, value != null && !value.equals("") ? value : null)); 
     643        @Override public void addCommands(List<Tag> changedTags) { 
     644            changedTags.add(new Tag(key, value != null && !value.equals("") ? value : null)); 
    634645        } 
    635646    } 
     
    885896        } 
    886897        p.add(items, GBC.eol().fill()); 
    887         if (selected.size() == 0) { 
     898        if (selected.size() == 0 && !supportsRelation()) { 
    888899            setEnabledRec(items, false); 
    889900        } 
     
    924935        if (Main.main == null) return; 
    925936        if (Main.main.getCurrentDataSet() == null) return; 
    926         Collection<OsmPrimitive> sel = createSelection(Main.main.getCurrentDataSet().getSelected()); 
     937 
     938        Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected(); 
     939        int answer = showDialog(sel, supportsRelation()); 
     940 
     941        if (sel.size() != 0 && answer == DIALOG_ANSWER_APPLY) { 
     942            Command cmd = createCommand(sel, getChangedTags()); 
     943            if (cmd != null) { 
     944                Main.main.undoRedo.add(cmd); 
     945            } 
     946        } else if (answer == DIALOG_ANSWER_NEW_RELATION) { 
     947            List<Command> cmds = new ArrayList<Command>(2); 
     948            final Relation r = new Relation(); 
     949            cmds.add(new AddCommand(r)); 
     950            Command cmd = createCommand(Collections.<OsmPrimitive>singletonList(r), getChangedTags()); 
     951            if (cmd != null) { 
     952                cmds.add(cmd); 
     953            } 
     954            Main.main.undoRedo.add(new SequenceCommand(tr("Add relation"), cmds)); 
     955            SwingUtilities.invokeLater(new Runnable() { 
     956                @Override 
     957                public void run() { 
     958                    // Relation list dialog has to be updated first for selectRelation to work 
     959                    Main.map.relationListDialog.selectRelation(r); 
     960                } 
     961            }); 
     962        } 
     963        Main.main.getCurrentDataSet().setSelected(Main.main.getCurrentDataSet().getSelected()); // force update 
     964 
     965    } 
     966 
     967    public int showDialog(Collection<OsmPrimitive> selection, final boolean showNewRelation) { 
     968        Collection<OsmPrimitive> sel = createSelection(selection); 
    927969        PresetPanel p = createPanel(sel); 
    928970        if (p == null) 
    929             return; 
     971            return DIALOG_ANSWER_CANCEL; 
    930972 
    931973        int answer = 1; 
     
    944986                    super(Main.parent, 
    945987                            title, 
    946                             new String[] { tr("Apply Preset"), tr("Cancel") }, 
    947                             true); 
     988                            showNewRelation? 
     989                                    new String[] { tr("Apply Preset"), tr("New relation"), tr("Cancel") }: 
     990                                        new String[] { tr("Apply Preset"), tr("Cancel") }, 
     991                                        true); 
    948992                    contentInsets = new Insets(10,5,0,5); 
    949                     setButtonIcons(new String[] {"ok.png", "cancel.png" }); 
     993                    if (showNewRelation) { 
     994                        setButtonIcons(new String[] {"ok.png", "dialogs/addrelation.png", "cancel.png" }); 
     995                    } else { 
     996                        setButtonIcons(new String[] {"ok.png", "cancel.png" }); 
     997                    } 
    950998                    setContent(content); 
    951999                    setDefaultButton(1); 
     
    9591007            answer = new PresetDialog(p, title, (sel.size() == 0)).getValue(); 
    9601008        } 
    961         if (sel.size() != 0 && answer == 1) { 
    962             Command cmd = createCommand(sel); 
    963             if (cmd != null) { 
    964                 Main.main.undoRedo.add(cmd); 
    965             } 
    966         } 
    967         Main.main.getCurrentDataSet().setSelected(Main.main.getCurrentDataSet().getSelected()); // force update 
     1009        if (!showNewRelation && answer == 2) 
     1010            return DIALOG_ANSWER_CANCEL; 
     1011        else 
     1012            return answer; 
    9681013    } 
    9691014 
     
    10101055    } 
    10111056 
    1012     private Command createCommand(Collection<OsmPrimitive> sel) { 
    1013         List<Command> cmds = new LinkedList<Command>(); 
    1014         for (Item i : data) { 
    1015             i.addCommands(sel, cmds); 
    1016         } 
     1057    public List<Tag> getChangedTags() { 
     1058        List<Tag> result = new ArrayList<Tag>(); 
     1059        for (Item i: data) { 
     1060            i.addCommands(result); 
     1061        } 
     1062        return result; 
     1063    } 
     1064 
     1065    public static Command createCommand(Collection<OsmPrimitive> sel, List<Tag> changedTags) { 
     1066        List<Command> cmds = new ArrayList<Command>(); 
     1067        for (Tag tag: changedTags) { 
     1068            if (!tag.getValue().isEmpty()) { 
     1069                cmds.add(new ChangePropertyCommand(sel, tag.getKey(), tag.getValue())); 
     1070            } 
     1071        } 
     1072 
    10171073        if (cmds.size() == 0) 
    10181074            return null; 
     
    10231079    } 
    10241080 
     1081    private boolean supportsRelation() { 
     1082        return types == null || types.contains(PresetType.RELATION); 
     1083    } 
     1084 
    10251085    protected void updateEnabledState() { 
    10261086        setEnabled(Main.main != null && Main.main.getCurrentDataSet() != null); 
     
    10381098        updateEnabledState(); 
    10391099    } 
     1100 
     1101    @Override 
     1102    public String toString() { 
     1103        return (types == null?"":types) + " " + name; 
     1104    } 
    10401105} 
  • trunk/src/org/openstreetmap/josm/gui/tagging/tagging-preset.xsd

    r3479 r3518  
    105105                <attribute name="delete_if_empty" type="boolean" /> 
    106106                <attribute name="use_last_as_default" type="boolean" /> 
     107                <attribute name="required" type="boolean"/> 
    107108 
    108109                <attribute name="type" use="prohibited"/> 
     
    121122                <attribute name="delete_if_empty" type="boolean" /> 
    122123                <attribute name="display_values" type="string"/> 
     124                <attribute name="required" type="boolean"/> 
    123125 
    124126                <attribute name="type" use="prohibited"/> 
     
    136138                <attribute name="delete_if_empty" type="boolean" /> 
    137139                <attribute name="use_last_as_default" type="boolean" /> 
     140                <attribute name="required" type="boolean"/> 
    138141 
    139142                <attribute name="name" use="prohibited"/> 
Note: See TracChangeset for help on using the changeset viewer.