Changeset 9588 in josm for trunk/src/org


Ignore:
Timestamp:
2016-01-23T18:20:46+01:00 (9 years ago)
Author:
Don-vip
Message:

see #12412 - improve support of multipolygon presets type

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
6 edited

Legend:

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

    r9266 r9588  
    3636     * and associates an interaction with (matching) presets via {@code presetHandler}.
    3737     * @param types collection of tagging presets types
    38      * @param tags colelction of tags
     38     * @param tags collection of tags
    3939     * @param presetHandler tagging preset handler
    4040     */
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r9543 r9588  
    165165        // init the various models
    166166        //
    167         memberTableModel = new MemberTableModel(getLayer(), presetHandler);
     167        memberTableModel = new MemberTableModel(relation, getLayer(), presetHandler);
    168168        memberTableModel.register();
    169169        selectionTableModel = new SelectionTableModel(getLayer());
     
    171171        referrerModel = new ReferringRelationsBrowserModel(relation);
    172172
    173         tagEditorPanel = new TagEditorPanel(presetHandler);
     173        tagEditorPanel = new TagEditorPanel(relation, presetHandler);
    174174
    175175        // populate the models
     
    805805        try {
    806806            final Collection<TaggingPreset> presets = TaggingPresets.getMatchingPresets(
    807                     EnumSet.of(TaggingPresetType.RELATION), orig.getKeys(), false);
     807                    EnumSet.of(TaggingPresetType.forPrimitive(orig)), orig.getKeys(), false);
    808808            Relation relation = new Relation(orig);
    809809            boolean modified = false;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r9496 r9588  
    5454    private final transient List<RelationMember> members;
    5555    private transient List<WayConnectionType> connectionType;
     56    private final Relation relation;
    5657
    5758    private DefaultListSelectionModel listSelectionModel;
     
    6566    /**
    6667     * constructor
     68     * @param relation relation
    6769     * @param layer data layer
    6870     * @param presetHandler tagging preset handler
    6971     */
    70     public MemberTableModel(OsmDataLayer layer, TaggingPresetHandler presetHandler) {
    71         members = new ArrayList<>();
    72         listeners = new CopyOnWriteArrayList<>();
     72    public MemberTableModel(Relation relation, OsmDataLayer layer, TaggingPresetHandler presetHandler) {
     73        this.relation = relation;
     74        this.members = new ArrayList<>();
     75        this.listeners = new CopyOnWriteArrayList<>();
    7376        this.layer = layer;
    7477        this.presetHandler = presetHandler;
     
    114117        Collection<RelationMember> sel = getSelectedMembers();
    115118        GuiHelper.runInEDT(new Runnable() {
     119            @Override
    116120            public void run() {
    117121                fireTableDataChanged();
     
    437441
    438442    RelationMember getRelationMemberForPrimitive(final OsmPrimitive primitive) {
    439         final Collection<TaggingPreset> presets = TaggingPresets.getMatchingPresets(EnumSet.of(TaggingPresetType.RELATION),
     443        final Collection<TaggingPreset> presets = TaggingPresets.getMatchingPresets(EnumSet.of(TaggingPresetType.forPrimitive(relation)),
    440444                presetHandler.getSelection().iterator().next().getKeys(), false);
    441445        Collection<String> potentialRoles = new TreeSet<>();
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java

    r9246 r9588  
    99import java.util.Collection;
    1010import java.util.Comparator;
     11import java.util.EnumSet;
    1112import java.util.HashMap;
    1213import java.util.Iterator;
     
    2526import org.openstreetmap.josm.data.osm.TagCollection;
    2627import org.openstreetmap.josm.data.osm.Tagged;
     28import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
    2729import org.openstreetmap.josm.tools.CheckParameterUtil;
    2830
    2931/**
    30  * TagEditorModel is a table model.
    31  *
     32 * TagEditorModel is a table model to use with {@link TagEditorPanel}.
     33 * @since 1762
    3234 */
    3335public class TagEditorModel extends AbstractTableModel {
     
    4345    private final DefaultListSelectionModel rowSelectionModel;
    4446    private final DefaultListSelectionModel colSelectionModel;
     47
     48    private OsmPrimitive primitive;
    4549
    4650    /**
     
    5862     */
    5963    public TagEditorModel() {
    60         this.rowSelectionModel = new DefaultListSelectionModel();
    61         this.colSelectionModel  = new DefaultListSelectionModel();
     64        this(new DefaultListSelectionModel(), new DefaultListSelectionModel());
    6265    }
    6366
     
    7477        CheckParameterUtil.ensureParameterNotNull(colSelectionModel, "colSelectionModel");
    7578        this.rowSelectionModel = rowSelectionModel;
    76         this.colSelectionModel  = colSelectionModel;
     79        this.colSelectionModel = colSelectionModel;
    7780    }
    7881
     
    618621    }
    619622
     623    /**
     624     * Returns the list of tagging presets types to consider when updating the presets list panel.
     625     * By default returns type of associated primitive or empty set.
     626     * @return the list of tagging presets types to consider when updating the presets list panel
     627     * @see #forPrimitive
     628     * @see TaggingPresetType#forPrimitive
     629     * @since 9588
     630     */
     631    public Collection<TaggingPresetType> getTaggingPresetTypes() {
     632        return primitive == null ? EnumSet.noneOf(TaggingPresetType.class) : EnumSet.of(TaggingPresetType.forPrimitive(primitive));
     633    }
     634
     635    /**
     636     * Makes this TagEditorModel specific to a given OSM primitive.
     637     * @param primitive primitive to consider
     638     * @return {@code this}
     639     * @since 9588
     640     */
     641    public TagEditorModel forPrimitive(OsmPrimitive primitive) {
     642        this.primitive = primitive;
     643        return this;
     644    }
     645
    620646    class SelectionStateMemento {
    621647        private final int rowMin;
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java

    r9543 r9588  
    99import java.awt.event.FocusAdapter;
    1010import java.awt.event.FocusEvent;
    11 import java.util.EnumSet;
    1211
    1312import javax.swing.AbstractAction;
     
    1918import javax.swing.event.TableModelListener;
    2019
     20import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2121import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel;
    2222import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    2424import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    2525import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetHandler;
    26 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
    2726import org.openstreetmap.josm.tools.CheckParameterUtil;
    2827
     
    3231 * and tag values. Two action buttons are placed on the left, one for adding
    3332 * a new tag and one for deleting the currently selected tags.
    34  *
     33 * @since 2040
    3534 */
    3635public class TagEditorPanel extends JPanel {
     
    140139
    141140        addFocusListener(new FocusAdapter() {
    142             @Override public void focusGained(FocusEvent e) {
     141            @Override
     142            public void focusGained(FocusEvent e) {
    143143                tagTable.requestFocusInCell(0, 0);
    144144            }
     
    149149     * Creates a new tag editor panel. The editor model is created
    150150     * internally and can be retrieved with {@link #getModel()}.
     151     * @param primitive primitive to consider
    151152     * @param presetHandler tagging preset handler
    152153     */
    153     public TagEditorPanel(TaggingPresetHandler presetHandler) {
    154         this(null, presetHandler, 0);
     154    public TagEditorPanel(OsmPrimitive primitive, TaggingPresetHandler presetHandler) {
     155        this(new TagEditorModel().forPrimitive(primitive), presetHandler, 0);
    155156    }
    156157
     
    198199        editor.setAutoCompletionManager(autocomplete);
    199200        editor.setAutoCompletionList(acList);
    200         editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(1).getCellEditor());
     201        editor = (TagCellEditor) tagTable.getColumnModel().getColumn(1).getCellEditor();
    201202        editor.setAutoCompletionManager(autocomplete);
    202203        editor.setAutoCompletionList(acList);
     
    211212    private void updatePresets() {
    212213        presetListPanel.updatePresets(
    213                 EnumSet.of(TaggingPresetType.RELATION),
     214                model.getTaggingPresetTypes(),
    214215                model.getTags(), presetHandler);
    215216        validate();
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetType.java

    r9574 r9588  
    6666            return CLOSEDWAY;
    6767        if (type == OsmPrimitiveType.MULTIPOLYGON)
    68             return TaggingPresetType.MULTIPOLYGON;
     68            return MULTIPOLYGON;
    6969        if (type == OsmPrimitiveType.RELATION)
    7070            return RELATION;
Note: See TracChangeset for help on using the changeset viewer.