Changeset 6623 in josm for trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java
- Timestamp:
- 2014-01-04T06:39:00+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java
r6622 r6623 61 61 /** 62 62 * Constructs a new {@code CreateMultipolygonAction}. 63 * @param update {@code true} if the multipolygon must be updated, {@code false} if it must be created 63 64 */ 64 65 public CreateMultipolygonAction(final boolean update) { 65 66 super(getName(update), "multipoly_create", getName(update), 66 update 67 ? null 67 update ? null 68 68 : Shortcut.registerShortcut("tools:multipoly", tr("Tool: {0}", getName(false)), KeyEvent.VK_A, Shortcut.ALT_CTRL), 69 69 true, update ? "multipoly_update" : "multipoly_create", true); … … 73 73 private static String getName(boolean update) { 74 74 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 } 75 123 } 76 124 … … 109 157 : null; 110 158 111 // runnable to create/update multipolygon relation112 final Runnable createOrUpdateMultipolygonTask = new Runnable() {113 @Override114 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 violations124 SwingUtilities.invokeLater(new Runnable() {125 @Override126 public void run() {127 Main.main.undoRedo.add(command);128 }129 });130 131 // Use 'SwingUtilities.invokeLater' to make sure the relationListDialog132 // knows about the new relation before we try to select it.133 // (Yes, we are already in event dispatch thread. But DatasetEventManager134 // uses 'SwingUtilities.invokeLater' to fire events so we have to do135 // the same.)136 SwingUtilities.invokeLater(new Runnable() {137 @Override138 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 preferences142 RelationEditor editor = RelationEditor.getEditor(Main.main.getEditLayer(), relation, null);143 144 editor.setModal(true);145 editor.setVisible(true);146 }147 }148 });149 }150 };151 152 159 // download incomplete relation if necessary 153 160 if (multipolygonRelation != null && (multipolygonRelation.isIncomplete() || multipolygonRelation.hasIncompleteMembers())) { … … 155 162 } 156 163 // create/update multipolygon relation 157 Main.worker.submit( createOrUpdateMultipolygonTask);164 Main.worker.submit(new CreateUpdateMultipolygonTask(selectedWays, multipolygonRelation)); 158 165 159 166 } … … 181 188 182 189 // 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); 187 194 if (polygon == null) { 188 195 return null; //could not make multipolygon. … … 206 213 207 214 /** 208 * Returns a pairof 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}. 209 216 */ 210 217 public static Pair<SequenceCommand, Relation> createMultipolygonCommand(Collection<Way> selectedWays, Relation selectedMultipolygonRelation) { … … 309 316 } 310 317 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"}); 312 319 313 320 /**
Note:
See TracChangeset
for help on using the changeset viewer.