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


Ignore:
Timestamp:
2019-01-06T12:11:10+01:00 (6 years ago)
Author:
simon04
Message:

Extract PropertiesMembershipChoiceDialog.ExistingBothNew enum

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java

    r14397 r14650  
    3737import org.openstreetmap.josm.gui.Notification;
    3838import org.openstreetmap.josm.gui.dialogs.PropertiesMembershipChoiceDialog;
    39 import org.openstreetmap.josm.gui.dialogs.PropertiesMembershipChoiceDialog.ExistingBothNewChoice;
     39import org.openstreetmap.josm.gui.dialogs.PropertiesMembershipChoiceDialog.ExistingBothNew;
    4040import org.openstreetmap.josm.tools.Logging;
    4141import org.openstreetmap.josm.tools.Shortcut;
     
    180180    }
    181181
    182     private static void updateProperties(ExistingBothNewChoice tags, Node existingNode, Iterable<Node> newNodes, Collection<Command> cmds) {
    183         if (tags != null && tags.newNode.isSelected()) {
     182    private static void updateProperties(ExistingBothNew tags, Node existingNode, Iterable<Node> newNodes, Collection<Command> cmds) {
     183        if (ExistingBothNew.NEW.equals(tags)) {
    184184            final Node newSelectedNode = new Node(existingNode);
    185185            newSelectedNode.removeAll();
    186186            cmds.add(new ChangeCommand(existingNode, newSelectedNode));
    187         } else if (tags != null && tags.oldNode.isSelected()) {
     187        } else if (ExistingBothNew.OLD.equals(tags)) {
    188188            for (Node newNode : newNodes) {
    189189                newNode.removeAll();
     
    192192    }
    193193
    194     private static void updateMemberships(ExistingBothNewChoice memberships, Node existingNode, List<Node> newNodes, Collection<Command> cmds) {
    195         if (memberships != null && memberships.bothNodes.isSelected()) {
     194    private static void updateMemberships(ExistingBothNew memberships, Node existingNode, List<Node> newNodes, Collection<Command> cmds) {
     195        if (ExistingBothNew.BOTH.equals(memberships)) {
    196196            fixRelations(existingNode, cmds, newNodes, false);
    197         } else if (memberships != null && memberships.newNode.isSelected()) {
     197        } else if (ExistingBothNew.NEW.equals(memberships)) {
    198198            fixRelations(existingNode, cmds, newNodes, true);
    199199        }
     
    203203     * Assumes there is one tagged Node stored in selectedNode that it will try to unglue.
    204204     * (i.e. copy node and remove all tags from the old one. Relations will not be removed)
    205      * @param e event that trigerred the action
     205     * @param e event that triggered the action
    206206     */
    207207    private void unglueOneNodeAtMostOneWay(ActionEvent e) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesMembershipChoiceDialog.java

    r14320 r14650  
    3131    private final transient ExistingBothNewChoice memberships;
    3232
     33    public enum ExistingBothNew {
     34        OLD, BOTH, NEW
     35    }
     36
    3337    /**
    3438     * Provides toggle buttons to allow the user choose the existing node, the new nodes, or all of them.
    3539     */
    36     public static class ExistingBothNewChoice {
     40    private static class ExistingBothNewChoice {
    3741        /** The "Existing node" button */
    38         public final AbstractButton oldNode = new JToggleButton(tr("Existing node"), ImageProvider.get("dialogs/conflict/tagkeeptheir"));
     42        final AbstractButton oldNode = new JToggleButton(tr("Existing node"), ImageProvider.get("dialogs/conflict/tagkeeptheir"));
    3943        /** The "Both nodes" button */
    40         public final AbstractButton bothNodes = new JToggleButton(tr("Both nodes"), ImageProvider.get("dialogs/conflict/tagundecide"));
     44        final AbstractButton bothNodes = new JToggleButton(tr("Both nodes"), ImageProvider.get("dialogs/conflict/tagundecide"));
    4145        /** The "New node" button */
    42         public final AbstractButton newNode = new JToggleButton(tr("New node"), ImageProvider.get("dialogs/conflict/tagkeepmine"));
     46        final AbstractButton newNode = new JToggleButton(tr("New node"), ImageProvider.get("dialogs/conflict/tagkeepmine"));
    4347
    4448        ExistingBothNewChoice(final boolean preselectNew) {
     
    4852            tagsGroup.add(newNode);
    4953            tagsGroup.setSelected((preselectNew ? newNode : oldNode).getModel(), true);
     54        }
     55
     56        void add(JPanel content, int gridy) {
     57            content.add(oldNode, GBC.std(1, gridy));
     58            content.add(bothNodes, GBC.std(2, gridy));
     59            content.add(newNode, GBC.std(3, gridy));
     60        }
     61
     62        ExistingBothNew getSelected() {
     63            if (oldNode.isSelected()) {
     64                return ExistingBothNew.OLD;
     65            } else if (bothNodes.isEnabled()) {
     66                return ExistingBothNew.BOTH;
     67            } else if (newNode.isSelected()) {
     68                return ExistingBothNew.NEW;
     69            } else {
     70                throw new IllegalStateException();
     71            }
    5072        }
    5173    }
     
    6082            content.add(new JLabel(tr("Where should the tags of the node be put?")), GBC.std(1, 1).span(3).insets(0, 20, 0, 0));
    6183            tags = new ExistingBothNewChoice(preselectNew);
    62             content.add(tags.oldNode, GBC.std(1, 2));
    63             content.add(tags.bothNodes, GBC.std(2, 2));
    64             content.add(tags.newNode, GBC.std(3, 2));
     84            tags.add(content, 2);
    6585        } else {
    6686            tags = null;
     
    7090            content.add(new JLabel(tr("Where should the memberships of this node be put?")), GBC.std(1, 3).span(3).insets(0, 20, 0, 0));
    7191            memberships = new ExistingBothNewChoice(preselectNew);
    72             content.add(memberships.oldNode, GBC.std(1, 4));
    73             content.add(memberships.bothNodes, GBC.std(2, 4));
    74             content.add(memberships.newNode, GBC.std(3, 4));
     92            memberships.add(content, 4);
    7593        } else {
    7694            memberships = null;
     
    85103     * @return the tags choice (can be null)
    86104     */
    87     public ExistingBothNewChoice getTags() {
    88         return tags;
     105    public ExistingBothNew getTags() {
     106        return tags.getSelected();
    89107    }
    90108
     
    93111     * @return the memberships choice (can be null)
    94112     */
    95     public ExistingBothNewChoice getMemberships() {
    96         return memberships;
     113    public ExistingBothNew getMemberships() {
     114        return memberships.getSelected();
    97115    }
    98116
Note: See TracChangeset for help on using the changeset viewer.