Ignore:
Timestamp:
2014-01-04T06:39:00+01:00 (10 years ago)
Author:
Don-vip
Message:

fix Sonar issues

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
3 edited

Legend:

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

    r6608 r6623  
    211211                return null;
    212212            // try to zoom to the first selected layer
    213             //
    214213            Layer l = getFirstSelectedLayer();
    215214            if (l == null) return null;
     
    245244            // ensure reasonable zoom level when zooming onto single nodes.
    246245            v.enlargeToMinDegrees(0.0005);
    247         }
    248         else if (mode.equals("download")) {
     246        } else if (mode.equals("download")) {
    249247            Bounds bounds = DownloadDialog.getSavedDownloadBounds();
    250248            if (bounds != null) {
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r6622 r6623  
    6161    /**
    6262     * Constructs a new {@code CreateMultipolygonAction}.
     63     * @param update {@code true} if the multipolygon must be updated, {@code false} if it must be created
    6364     */
    6465    public CreateMultipolygonAction(final boolean update) {
    6566        super(getName(update), "multipoly_create", getName(update),
    66                 update
    67                         ? null
     67                update  ? null
    6868                        : Shortcut.registerShortcut("tools:multipoly", tr("Tool: {0}", getName(false)), KeyEvent.VK_A, Shortcut.ALT_CTRL),
    6969                true, update ? "multipoly_update" : "multipoly_create", true);
     
    7373    private static String getName(boolean update) {
    7474        return update ? tr("Update multipolygon") : tr("Create multipolygon");
     75    }
     76   
     77    private class CreateUpdateMultipolygonTask implements Runnable {
     78        private final Collection<Way> selectedWays;
     79        private final Relation multipolygonRelation;
     80
     81        public CreateUpdateMultipolygonTask(Collection<Way> selectedWays, Relation multipolygonRelation) {
     82            this.selectedWays = selectedWays;
     83            this.multipolygonRelation = multipolygonRelation;
     84        }
     85
     86        @Override
     87        public void run() {
     88            final Pair<SequenceCommand, Relation> commandAndRelation = createMultipolygonCommand(selectedWays, multipolygonRelation);
     89            if (commandAndRelation == null) {
     90                return;
     91            }
     92            final Command command = commandAndRelation.a;
     93            final Relation relation = commandAndRelation.b;
     94
     95
     96            // to avoid EDT violations
     97            SwingUtilities.invokeLater(new Runnable() {
     98                @Override
     99                public void run() {
     100                    Main.main.undoRedo.add(command);
     101                }
     102            });
     103
     104            // Use 'SwingUtilities.invokeLater' to make sure the relationListDialog
     105            // knows about the new relation before we try to select it.
     106            // (Yes, we are already in event dispatch thread. But DatasetEventManager
     107            // uses 'SwingUtilities.invokeLater' to fire events so we have to do
     108            // the same.)
     109            SwingUtilities.invokeLater(new Runnable() {
     110                @Override
     111                public void run() {
     112                    Main.map.relationListDialog.selectRelation(relation);
     113                    if (Main.pref.getBoolean("multipoly.show-relation-editor", false)) {
     114                        //Open relation edit window, if set up in preferences
     115                        RelationEditor editor = RelationEditor.getEditor(Main.main.getEditLayer(), relation, null);
     116
     117                        editor.setModal(true);
     118                        editor.setVisible(true);
     119                    }
     120                }
     121            });
     122        }
    75123    }
    76124
     
    109157                : null;
    110158
    111         // runnable to create/update multipolygon relation
    112         final Runnable createOrUpdateMultipolygonTask = new Runnable() {
    113             @Override
    114             public void run() {
    115                 final Pair<SequenceCommand, Relation> commandAndRelation = createMultipolygonCommand(selectedWays, multipolygonRelation);
    116                 if (commandAndRelation == null) {
    117                     return;
    118                 }
    119                 final Command command = commandAndRelation.a;
    120                 final Relation relation = commandAndRelation.b;
    121 
    122 
    123                 // to avoid EDT violations
    124                 SwingUtilities.invokeLater(new Runnable() {
    125                     @Override
    126                     public void run() {
    127                         Main.main.undoRedo.add(command);
    128                     }
    129                 });
    130 
    131                 // Use 'SwingUtilities.invokeLater' to make sure the relationListDialog
    132                 // knows about the new relation before we try to select it.
    133                 // (Yes, we are already in event dispatch thread. But DatasetEventManager
    134                 // uses 'SwingUtilities.invokeLater' to fire events so we have to do
    135                 // the same.)
    136                 SwingUtilities.invokeLater(new Runnable() {
    137                     @Override
    138                     public void run() {
    139                         Main.map.relationListDialog.selectRelation(relation);
    140                         if (Main.pref.getBoolean("multipoly.show-relation-editor", false)) {
    141                             //Open relation edit window, if set up in preferences
    142                             RelationEditor editor = RelationEditor.getEditor(Main.main.getEditLayer(), relation, null);
    143 
    144                             editor.setModal(true);
    145                             editor.setVisible(true);
    146                         }
    147                     }
    148                 });
    149             }
    150         };
    151 
    152159        // download incomplete relation if necessary
    153160        if (multipolygonRelation != null && (multipolygonRelation.isIncomplete() || multipolygonRelation.hasIncompleteMembers())) {
     
    155162        }
    156163        // create/update multipolygon relation
    157         Main.worker.submit(createOrUpdateMultipolygonTask);
     164        Main.worker.submit(new CreateUpdateMultipolygonTask(selectedWays, multipolygonRelation));
    158165
    159166    }
     
    181188
    182189        // add ways of existing relation to include them in polygon analysis
    183         selectedWays = new HashSet<Way>(selectedWays);
    184         selectedWays.addAll(selectedMultipolygonRelation.getMemberPrimitives(Way.class));
    185 
    186         final MultipolygonCreate polygon = analyzeWays(selectedWays, true);
     190        Set<Way> ways = new HashSet<Way>(selectedWays);
     191        ways.addAll(selectedMultipolygonRelation.getMemberPrimitives(Way.class));
     192
     193        final MultipolygonCreate polygon = analyzeWays(ways, true);
    187194        if (polygon == null) {
    188195            return null; //could not make multipolygon.
     
    206213
    207214    /**
    208      * Returns a pair of a multipolygon creating/modifying {@link Command} as well as the multipolygon {@link Relation}.
     215     * Returns a {@link Pair} of a multipolygon creating/modifying {@link Command} as well as the multipolygon {@link Relation}.
    209216     */
    210217    public static Pair<SequenceCommand, Relation> createMultipolygonCommand(Collection<Way> selectedWays, Relation selectedMultipolygonRelation) {
     
    309316    }
    310317
    311     static public final List<String> DEFAULT_LINEAR_TAGS = Arrays.asList(new String[] {"barrier", "source"});
     318    public static final List<String> DEFAULT_LINEAR_TAGS = Arrays.asList(new String[] {"barrier", "source"});
    312319
    313320    /**
  • trunk/src/org/openstreetmap/josm/actions/SelectNonBranchingWaySequences.java

    r6603 r6623  
    44import java.util.Collection;
    55import java.util.LinkedList;
     6import java.util.Set;
    67import java.util.TreeSet;
    78
     
    2021     * outer endpoints of selected ways
    2122     */
    22     TreeSet<Node> outerNodes;
     23    Set<Node> outerNodes;
    2324    /**
    2425     * endpoints of selected ways
    2526     */
    26     TreeSet<Node> nodes;
     27    Set<Node> nodes;
    2728
    2829    /**
Note: See TracChangeset for help on using the changeset viewer.