1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
7 |
|
---|
8 | import java.awt.BorderLayout;
|
---|
9 | import java.awt.Color;
|
---|
10 | import java.awt.Point;
|
---|
11 | import java.awt.event.ActionEvent;
|
---|
12 | import java.awt.event.KeyEvent;
|
---|
13 | import java.awt.event.MouseAdapter;
|
---|
14 | import java.awt.event.MouseEvent;
|
---|
15 | import java.util.ArrayList;
|
---|
16 | import java.util.Arrays;
|
---|
17 | import java.util.Collection;
|
---|
18 | import java.util.Collections;
|
---|
19 | import java.util.HashSet;
|
---|
20 | import java.util.Iterator;
|
---|
21 | import java.util.LinkedList;
|
---|
22 | import java.util.List;
|
---|
23 | import java.util.Set;
|
---|
24 |
|
---|
25 | import javax.swing.AbstractAction;
|
---|
26 | import javax.swing.AbstractListModel;
|
---|
27 | import javax.swing.Action;
|
---|
28 | import javax.swing.DefaultListSelectionModel;
|
---|
29 | import javax.swing.JComponent;
|
---|
30 | import javax.swing.JList;
|
---|
31 | import javax.swing.JMenuItem;
|
---|
32 | import javax.swing.JPanel;
|
---|
33 | import javax.swing.JScrollPane;
|
---|
34 | import javax.swing.JTextField;
|
---|
35 | import javax.swing.KeyStroke;
|
---|
36 | import javax.swing.ListSelectionModel;
|
---|
37 | import javax.swing.SwingUtilities;
|
---|
38 | import javax.swing.UIManager;
|
---|
39 | import javax.swing.event.DocumentEvent;
|
---|
40 | import javax.swing.event.DocumentListener;
|
---|
41 | import javax.swing.event.ListSelectionEvent;
|
---|
42 | import javax.swing.event.ListSelectionListener;
|
---|
43 | import javax.swing.event.PopupMenuListener;
|
---|
44 |
|
---|
45 | import org.openstreetmap.josm.Main;
|
---|
46 | import org.openstreetmap.josm.actions.search.SearchCompiler;
|
---|
47 | import org.openstreetmap.josm.command.Command;
|
---|
48 | import org.openstreetmap.josm.command.SequenceCommand;
|
---|
49 | import org.openstreetmap.josm.data.SelectionChangedListener;
|
---|
50 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
51 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
52 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
53 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
54 | import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
|
---|
55 | import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
|
---|
56 | import org.openstreetmap.josm.data.osm.event.DataSetListener;
|
---|
57 | import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
|
---|
58 | import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
|
---|
59 | import org.openstreetmap.josm.data.osm.event.NodeMovedEvent;
|
---|
60 | import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent;
|
---|
61 | import org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent;
|
---|
62 | import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent;
|
---|
63 | import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
|
---|
64 | import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
|
---|
65 | import org.openstreetmap.josm.gui.DefaultNameFormatter;
|
---|
66 | import org.openstreetmap.josm.gui.MapView;
|
---|
67 | import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
|
---|
68 | import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
|
---|
69 | import org.openstreetmap.josm.gui.SideButton;
|
---|
70 | import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
|
---|
71 | import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;
|
---|
72 | import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
|
---|
73 | import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
|
---|
74 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
75 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
76 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
77 | import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField;
|
---|
78 | import org.openstreetmap.josm.gui.widgets.ListPopupMenu;
|
---|
79 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
80 | import org.openstreetmap.josm.tools.InputMapUtils;
|
---|
81 | import org.openstreetmap.josm.tools.Predicate;
|
---|
82 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
83 | import org.openstreetmap.josm.tools.Utils;
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * A dialog showing all known relations, with buttons to add, edit, and
|
---|
87 | * delete them.
|
---|
88 | *
|
---|
89 | * We don't have such dialogs for nodes, segments, and ways, because those
|
---|
90 | * objects are visible on the map and can be selected there. Relations are not.
|
---|
91 | */
|
---|
92 | public class RelationListDialog extends ToggleDialog implements DataSetListener {
|
---|
93 | /** The display list. */
|
---|
94 | private JList displaylist;
|
---|
95 | /** the list model used */
|
---|
96 | private RelationListModel model;
|
---|
97 |
|
---|
98 | /** the edit action */
|
---|
99 | private EditAction editAction;
|
---|
100 | /** the delete action */
|
---|
101 | private DeleteAction deleteAction;
|
---|
102 | private NewAction newAction;
|
---|
103 | private AddToRelation addToRelation;
|
---|
104 | /** the popup menu */
|
---|
105 | private RelationDialogPopupMenu popupMenu;
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * constructor
|
---|
109 | */
|
---|
110 | public RelationListDialog() {
|
---|
111 | super(tr("Relations"), "relationlist", tr("Open a list of all relations."),
|
---|
112 | Shortcut.registerShortcut("subwindow:relations", tr("Toggle: {0}", tr("Relations")),
|
---|
113 | KeyEvent.VK_R, Shortcut.ALT_SHIFT), 150);
|
---|
114 |
|
---|
115 | // create the list of relations
|
---|
116 | //
|
---|
117 | DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
|
---|
118 | model = new RelationListModel(selectionModel);
|
---|
119 | displaylist = new JList(model);
|
---|
120 | displaylist.setSelectionModel(selectionModel);
|
---|
121 | displaylist.setCellRenderer(new OsmPrimitivRenderer() {
|
---|
122 | /**
|
---|
123 | * Don't show the default tooltip in the relation list.
|
---|
124 | */
|
---|
125 | @Override
|
---|
126 | protected String getComponentToolTipText(OsmPrimitive value) {
|
---|
127 | return null;
|
---|
128 | }
|
---|
129 | });
|
---|
130 | displaylist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
---|
131 | displaylist.addMouseListener(new MouseEventHandler());
|
---|
132 |
|
---|
133 | // the new action
|
---|
134 | //
|
---|
135 | newAction = new NewAction();
|
---|
136 |
|
---|
137 | // the edit action
|
---|
138 | //
|
---|
139 | editAction = new EditAction();
|
---|
140 | displaylist.addListSelectionListener(editAction);
|
---|
141 |
|
---|
142 | // the duplicate action
|
---|
143 | //
|
---|
144 | DuplicateAction duplicateAction = new DuplicateAction();
|
---|
145 | displaylist.addListSelectionListener(duplicateAction);
|
---|
146 |
|
---|
147 | // the delete action
|
---|
148 | //
|
---|
149 | deleteAction = new DeleteAction();
|
---|
150 | displaylist.addListSelectionListener(deleteAction);
|
---|
151 |
|
---|
152 | // the select action
|
---|
153 | //
|
---|
154 | SelectAction selectAction = new SelectAction(false);
|
---|
155 | displaylist.addListSelectionListener(selectAction);
|
---|
156 |
|
---|
157 | final JTextField filter = new DisableShortcutsOnFocusGainedTextField();
|
---|
158 | filter.setToolTipText(tr("Relation list filter"));
|
---|
159 | filter.getDocument().addDocumentListener(new DocumentListener() {
|
---|
160 |
|
---|
161 | private void setFilter() {
|
---|
162 | try {
|
---|
163 | filter.setBackground(UIManager.getColor("TextField.background"));
|
---|
164 | filter.setToolTipText(tr("Relation list filter"));
|
---|
165 | model.setFilter(SearchCompiler.compile(filter.getText(), false, false));
|
---|
166 | } catch (SearchCompiler.ParseError ex) {
|
---|
167 | filter.setBackground(new Color(255, 224, 224));
|
---|
168 | filter.setToolTipText(ex.getMessage());
|
---|
169 | model.setFilter(new SearchCompiler.Always());
|
---|
170 | }
|
---|
171 | }
|
---|
172 |
|
---|
173 | @Override
|
---|
174 | public void insertUpdate(DocumentEvent e) {
|
---|
175 | setFilter();
|
---|
176 | }
|
---|
177 |
|
---|
178 | @Override
|
---|
179 | public void removeUpdate(DocumentEvent e) {
|
---|
180 | setFilter();
|
---|
181 | }
|
---|
182 |
|
---|
183 | @Override
|
---|
184 | public void changedUpdate(DocumentEvent e) {
|
---|
185 | setFilter();
|
---|
186 | }
|
---|
187 | });
|
---|
188 |
|
---|
189 | JPanel pane = new JPanel(new BorderLayout());
|
---|
190 | pane.add(filter, BorderLayout.NORTH);
|
---|
191 | pane.add(new JScrollPane(displaylist), BorderLayout.CENTER);
|
---|
192 | createLayout(pane, false, Arrays.asList(new SideButton[]{
|
---|
193 | new SideButton(newAction, false),
|
---|
194 | new SideButton(editAction, false),
|
---|
195 | new SideButton(duplicateAction, false),
|
---|
196 | new SideButton(deleteAction, false),
|
---|
197 | new SideButton(selectAction, false)
|
---|
198 | }));
|
---|
199 |
|
---|
200 | // activate DEL in the list of relations
|
---|
201 | //displaylist.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0), "deleteRelation");
|
---|
202 | //displaylist.getActionMap().put("deleteRelation", deleteAction);
|
---|
203 |
|
---|
204 | InputMapUtils.unassignCtrlShiftUpDown(displaylist, JComponent.WHEN_FOCUSED);
|
---|
205 |
|
---|
206 | // Select relation on Ctrl-Enter
|
---|
207 | InputMapUtils.addEnterAction(displaylist, selectAction);
|
---|
208 |
|
---|
209 | addToRelation = new AddToRelation();
|
---|
210 | popupMenu = new RelationDialogPopupMenu(displaylist);
|
---|
211 |
|
---|
212 | // Edit relation on Ctrl-Enter
|
---|
213 | displaylist.getActionMap().put("edit", editAction);
|
---|
214 | displaylist.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_MASK), "edit");
|
---|
215 | }
|
---|
216 |
|
---|
217 | @Override public void showNotify() {
|
---|
218 | MapView.addLayerChangeListener(newAction);
|
---|
219 | newAction.updateEnabledState();
|
---|
220 | DatasetEventManager.getInstance().addDatasetListener(this, FireMode.IN_EDT);
|
---|
221 | DataSet.addSelectionListener(addToRelation);
|
---|
222 | dataChanged(null);
|
---|
223 | }
|
---|
224 |
|
---|
225 | @Override public void hideNotify() {
|
---|
226 | MapView.removeLayerChangeListener(newAction);
|
---|
227 | DatasetEventManager.getInstance().removeDatasetListener(this);
|
---|
228 | DataSet.removeSelectionListener(addToRelation);
|
---|
229 | }
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * Initializes the relation list dialog from a layer. If <code>layer</code> is null
|
---|
233 | * or if it isn't an {@link OsmDataLayer} the dialog is reset to an empty dialog.
|
---|
234 | * Otherwise it is initialized with the list of non-deleted and visible relations
|
---|
235 | * in the layer's dataset.
|
---|
236 | *
|
---|
237 | * @param layer the layer. May be null.
|
---|
238 | */
|
---|
239 | protected void initFromLayer(Layer layer) {
|
---|
240 | if (layer == null || ! (layer instanceof OsmDataLayer)) {
|
---|
241 | model.setRelations(null);
|
---|
242 | return;
|
---|
243 | }
|
---|
244 | OsmDataLayer l = (OsmDataLayer)layer;
|
---|
245 | model.setRelations(l.data.getRelations());
|
---|
246 | model.updateTitle();
|
---|
247 | }
|
---|
248 |
|
---|
249 | /**
|
---|
250 | * Adds a selection listener to the relation list.
|
---|
251 | *
|
---|
252 | * @param listener the listener to add
|
---|
253 | */
|
---|
254 | public void addListSelectionListener(ListSelectionListener listener) {
|
---|
255 | displaylist.addListSelectionListener(listener);
|
---|
256 | }
|
---|
257 |
|
---|
258 | /**
|
---|
259 | * Removes a selection listener from the relation list.
|
---|
260 | *
|
---|
261 | * @param listener the listener to remove
|
---|
262 | */
|
---|
263 | public void removeListSelectionListener(ListSelectionListener listener) {
|
---|
264 | displaylist.removeListSelectionListener(listener);
|
---|
265 | }
|
---|
266 |
|
---|
267 | /**
|
---|
268 | * @return The selected relation in the list
|
---|
269 | */
|
---|
270 | private Relation getSelected() {
|
---|
271 | if(model.getSize() == 1) {
|
---|
272 | displaylist.setSelectedIndex(0);
|
---|
273 | }
|
---|
274 | return (Relation) displaylist.getSelectedValue();
|
---|
275 | }
|
---|
276 |
|
---|
277 | /**
|
---|
278 | * Selects the relation <code>relation</code> in the list of relations.
|
---|
279 | *
|
---|
280 | * @param relation the relation
|
---|
281 | */
|
---|
282 | public void selectRelation(Relation relation) {
|
---|
283 | selectRelations(Collections.singleton(relation));
|
---|
284 | }
|
---|
285 |
|
---|
286 | /**
|
---|
287 | * Selects the relations in the list of relations.
|
---|
288 | * @param relations the relations to be selected
|
---|
289 | */
|
---|
290 | public void selectRelations(Collection<Relation> relations) {
|
---|
291 | if (relations == null || relations.isEmpty()) {
|
---|
292 | model.setSelectedRelations(null);
|
---|
293 | } else {
|
---|
294 | model.setSelectedRelations(relations);
|
---|
295 | Integer i = model.getRelationIndex(relations.iterator().next());
|
---|
296 | if (i != null) { // Not all relations have to be in the list (for example when the relation list is hidden, it's not updated with new relations)
|
---|
297 | displaylist.scrollRectToVisible(displaylist.getCellBounds(i, i));
|
---|
298 | }
|
---|
299 | }
|
---|
300 | }
|
---|
301 |
|
---|
302 | class MouseEventHandler extends MouseAdapter {
|
---|
303 | protected void setCurrentRelationAsSelection() {
|
---|
304 | Main.main.getCurrentDataSet().setSelected((Relation)displaylist.getSelectedValue());
|
---|
305 | }
|
---|
306 |
|
---|
307 | protected void editCurrentRelation() {
|
---|
308 | new EditAction().launchEditor(getSelected());
|
---|
309 | }
|
---|
310 |
|
---|
311 | @Override public void mouseClicked(MouseEvent e) {
|
---|
312 | if (Main.main.getEditLayer() == null) return;
|
---|
313 | if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
|
---|
314 | if (e.isControlDown()) {
|
---|
315 | editCurrentRelation();
|
---|
316 | } else {
|
---|
317 | setCurrentRelationAsSelection();
|
---|
318 | }
|
---|
319 | }
|
---|
320 | }
|
---|
321 | private void openPopup(MouseEvent e) {
|
---|
322 | Point p = e.getPoint();
|
---|
323 | int index = displaylist.locationToIndex(p);
|
---|
324 | if (index < 0) return;
|
---|
325 | if (!displaylist.getCellBounds(index, index).contains(e.getPoint()))
|
---|
326 | return;
|
---|
327 | if (! displaylist.isSelectedIndex(index)) {
|
---|
328 | displaylist.setSelectedIndex(index);
|
---|
329 | }
|
---|
330 | popupMenu.show(displaylist, p.x, p.y-3);
|
---|
331 | }
|
---|
332 | @Override public void mousePressed(MouseEvent e) {
|
---|
333 | if (Main.main.getEditLayer() == null) return;
|
---|
334 | if (e.isPopupTrigger()) {
|
---|
335 | openPopup(e);
|
---|
336 | }
|
---|
337 | }
|
---|
338 | @Override public void mouseReleased(MouseEvent e) {
|
---|
339 | if (Main.main.getEditLayer() == null) return;
|
---|
340 | if (e.isPopupTrigger()) {
|
---|
341 | openPopup(e);
|
---|
342 | }
|
---|
343 | }
|
---|
344 | }
|
---|
345 |
|
---|
346 | /**
|
---|
347 | * The edit action
|
---|
348 | *
|
---|
349 | */
|
---|
350 | class EditAction extends AbstractAction implements ListSelectionListener{
|
---|
351 | public EditAction() {
|
---|
352 | putValue(SHORT_DESCRIPTION,tr( "Open an editor for the selected relation"));
|
---|
353 | putValue(NAME, tr("Edit"));
|
---|
354 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "edit"));
|
---|
355 | setEnabled(false);
|
---|
356 | }
|
---|
357 | protected Collection<RelationMember> getMembersForCurrentSelection(Relation r) {
|
---|
358 | Collection<RelationMember> members = new HashSet<RelationMember>();
|
---|
359 | Collection<OsmPrimitive> selection = Main.map.mapView.getEditLayer().data.getSelected();
|
---|
360 | for (RelationMember member: r.getMembers()) {
|
---|
361 | if (selection.contains(member.getMember())) {
|
---|
362 | members.add(member);
|
---|
363 | }
|
---|
364 | }
|
---|
365 | return members;
|
---|
366 | }
|
---|
367 |
|
---|
368 | public void launchEditor(Relation toEdit) {
|
---|
369 | if (toEdit == null)
|
---|
370 | return;
|
---|
371 | RelationEditor.getEditor(Main.map.mapView.getEditLayer(),toEdit, getMembersForCurrentSelection(toEdit)).setVisible(true);
|
---|
372 | }
|
---|
373 |
|
---|
374 | public void actionPerformed(ActionEvent e) {
|
---|
375 | if (!isEnabled())
|
---|
376 | return;
|
---|
377 | launchEditor(getSelected());
|
---|
378 | }
|
---|
379 |
|
---|
380 | public void valueChanged(ListSelectionEvent e) {
|
---|
381 | setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length == 1);
|
---|
382 | }
|
---|
383 | }
|
---|
384 |
|
---|
385 | /**
|
---|
386 | * The delete action
|
---|
387 | *
|
---|
388 | */
|
---|
389 | class DeleteAction extends AbstractAction implements ListSelectionListener {
|
---|
390 | class AbortException extends Exception {}
|
---|
391 |
|
---|
392 | public DeleteAction() {
|
---|
393 | putValue(SHORT_DESCRIPTION,tr("Delete the selected relation"));
|
---|
394 | putValue(NAME, tr("Delete"));
|
---|
395 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
|
---|
396 | setEnabled(false);
|
---|
397 | }
|
---|
398 |
|
---|
399 | protected void deleteRelation(Relation toDelete) {
|
---|
400 | if (toDelete == null)
|
---|
401 | return;
|
---|
402 | org.openstreetmap.josm.actions.mapmode.DeleteAction.deleteRelation(
|
---|
403 | Main.main.getEditLayer(),
|
---|
404 | toDelete
|
---|
405 | );
|
---|
406 | }
|
---|
407 |
|
---|
408 | public void actionPerformed(ActionEvent e) {
|
---|
409 | if (!isEnabled())
|
---|
410 | return;
|
---|
411 | List<Relation> toDelete = new LinkedList<Relation>();
|
---|
412 | for (int i : displaylist.getSelectedIndices()) {
|
---|
413 | toDelete.add(model.getVisibleRelation(i));
|
---|
414 | }
|
---|
415 | for (Relation r : toDelete) {
|
---|
416 | deleteRelation(r);
|
---|
417 | }
|
---|
418 | displaylist.clearSelection();
|
---|
419 | }
|
---|
420 |
|
---|
421 | public void valueChanged(ListSelectionEvent e) {
|
---|
422 | setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length > 0);
|
---|
423 | }
|
---|
424 | }
|
---|
425 |
|
---|
426 | /**
|
---|
427 | * The action for creating a new relation
|
---|
428 | *
|
---|
429 | */
|
---|
430 | static class NewAction extends AbstractAction implements LayerChangeListener{
|
---|
431 | public NewAction() {
|
---|
432 | putValue(SHORT_DESCRIPTION,tr("Create a new relation"));
|
---|
433 | putValue(NAME, tr("New"));
|
---|
434 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "addrelation"));
|
---|
435 | updateEnabledState();
|
---|
436 | }
|
---|
437 |
|
---|
438 | public void run() {
|
---|
439 | RelationEditor.getEditor(Main.main.getEditLayer(),null, null).setVisible(true);
|
---|
440 | }
|
---|
441 |
|
---|
442 | public void actionPerformed(ActionEvent e) {
|
---|
443 | run();
|
---|
444 | }
|
---|
445 |
|
---|
446 | protected void updateEnabledState() {
|
---|
447 | setEnabled(Main.main != null && Main.main.getEditLayer() != null);
|
---|
448 | }
|
---|
449 |
|
---|
450 | public void activeLayerChange(Layer oldLayer, Layer newLayer) {
|
---|
451 | updateEnabledState();
|
---|
452 | }
|
---|
453 |
|
---|
454 | public void layerAdded(Layer newLayer) {
|
---|
455 | updateEnabledState();
|
---|
456 | }
|
---|
457 |
|
---|
458 | public void layerRemoved(Layer oldLayer) {
|
---|
459 | updateEnabledState();
|
---|
460 | }
|
---|
461 | }
|
---|
462 |
|
---|
463 | /**
|
---|
464 | * Creates a new relation with a copy of the current editor state
|
---|
465 | *
|
---|
466 | */
|
---|
467 | class DuplicateAction extends AbstractAction implements ListSelectionListener {
|
---|
468 | public DuplicateAction() {
|
---|
469 | putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
|
---|
470 | putValue(SMALL_ICON, ImageProvider.get("duplicate"));
|
---|
471 | putValue(NAME, tr("Duplicate"));
|
---|
472 | updateEnabledState();
|
---|
473 | }
|
---|
474 |
|
---|
475 | public void launchEditorForDuplicate(Relation original) {
|
---|
476 | Relation copy = new Relation(original, true);
|
---|
477 | copy.setModified(true);
|
---|
478 | RelationEditor editor = RelationEditor.getEditor(
|
---|
479 | Main.main.getEditLayer(),
|
---|
480 | copy,
|
---|
481 | null /* no selected members */
|
---|
482 | );
|
---|
483 | editor.setVisible(true);
|
---|
484 | }
|
---|
485 |
|
---|
486 | public void actionPerformed(ActionEvent e) {
|
---|
487 | if (!isEnabled())
|
---|
488 | return;
|
---|
489 | launchEditorForDuplicate(getSelected());
|
---|
490 | }
|
---|
491 |
|
---|
492 | protected void updateEnabledState() {
|
---|
493 | setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length == 1);
|
---|
494 | }
|
---|
495 |
|
---|
496 | public void valueChanged(ListSelectionEvent e) {
|
---|
497 | updateEnabledState();
|
---|
498 | }
|
---|
499 | }
|
---|
500 |
|
---|
501 | /**
|
---|
502 | * Sets the current selection to the list of relations selected in this dialog
|
---|
503 | *
|
---|
504 | */
|
---|
505 | class SelectAction extends AbstractAction implements ListSelectionListener{
|
---|
506 | boolean add;
|
---|
507 | public SelectAction(boolean add) {
|
---|
508 | putValue(SHORT_DESCRIPTION, add ? tr("Add the selected relations to the current selection")
|
---|
509 | : tr("Set the current selection to the list of selected relations"));
|
---|
510 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));
|
---|
511 | putValue(NAME, add ? tr("Select relation (add)") : tr("Select relation"));
|
---|
512 | this.add = add;
|
---|
513 | updateEnabledState();
|
---|
514 | }
|
---|
515 |
|
---|
516 | public void actionPerformed(ActionEvent e) {
|
---|
517 | if (!isEnabled()) return;
|
---|
518 | int [] idx = displaylist.getSelectedIndices();
|
---|
519 | if (idx == null || idx.length == 0) return;
|
---|
520 | ArrayList<OsmPrimitive> selection = new ArrayList<OsmPrimitive>(idx.length);
|
---|
521 | for (int i: idx) {
|
---|
522 | selection.add(model.getVisibleRelation(i));
|
---|
523 | }
|
---|
524 | if(add) {
|
---|
525 | Main.map.mapView.getEditLayer().data.addSelected(selection);
|
---|
526 | } else {
|
---|
527 | Main.map.mapView.getEditLayer().data.setSelected(selection);
|
---|
528 | }
|
---|
529 | }
|
---|
530 |
|
---|
531 | protected void updateEnabledState() {
|
---|
532 | setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length > 0);
|
---|
533 | }
|
---|
534 |
|
---|
535 | public void valueChanged(ListSelectionEvent e) {
|
---|
536 | updateEnabledState();
|
---|
537 | }
|
---|
538 | }
|
---|
539 |
|
---|
540 | /**
|
---|
541 | * Sets the current selection to the list of relations selected in this dialog
|
---|
542 | *
|
---|
543 | */
|
---|
544 | class SelectMembersAction extends AbstractAction implements ListSelectionListener{
|
---|
545 | boolean add;
|
---|
546 | public SelectMembersAction(boolean add) {
|
---|
547 | putValue(SHORT_DESCRIPTION,add ? tr("Add the members of all selected relations to current selection")
|
---|
548 | : tr("Select the members of all selected relations"));
|
---|
549 | putValue(SMALL_ICON, ImageProvider.get("selectall"));
|
---|
550 | putValue(NAME, add ? tr("Select members (add)") : tr("Select members"));
|
---|
551 | this.add = add;
|
---|
552 | updateEnabledState();
|
---|
553 | }
|
---|
554 |
|
---|
555 | public void actionPerformed(ActionEvent e) {
|
---|
556 | if (!isEnabled()) return;
|
---|
557 | List<Relation> relations = model.getSelectedRelations();
|
---|
558 | HashSet<OsmPrimitive> members = new HashSet<OsmPrimitive>();
|
---|
559 | for(Relation r: relations) {
|
---|
560 | members.addAll(r.getMemberPrimitives());
|
---|
561 | }
|
---|
562 | if(add) {
|
---|
563 | Main.map.mapView.getEditLayer().data.addSelected(members);
|
---|
564 | } else {
|
---|
565 | Main.map.mapView.getEditLayer().data.setSelected(members);
|
---|
566 | }
|
---|
567 | }
|
---|
568 |
|
---|
569 | protected void updateEnabledState() {
|
---|
570 | setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length > 0);
|
---|
571 | }
|
---|
572 |
|
---|
573 | public void valueChanged(ListSelectionEvent e) {
|
---|
574 | updateEnabledState();
|
---|
575 | }
|
---|
576 | }
|
---|
577 |
|
---|
578 | /**
|
---|
579 | * The action for downloading members of all selected relations
|
---|
580 | *
|
---|
581 | */
|
---|
582 | class DownloadMembersAction extends AbstractAction implements ListSelectionListener{
|
---|
583 |
|
---|
584 | public DownloadMembersAction() {
|
---|
585 | putValue(SHORT_DESCRIPTION,tr("Download all members of the selected relations"));
|
---|
586 | putValue(NAME, tr("Download members"));
|
---|
587 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "downloadincomplete"));
|
---|
588 | putValue("help", ht("/Dialog/RelationList#DownloadMembers"));
|
---|
589 | updateEnabledState();
|
---|
590 | }
|
---|
591 |
|
---|
592 | protected void updateEnabledState() {
|
---|
593 | setEnabled(! model.getSelectedNonNewRelations().isEmpty());
|
---|
594 | }
|
---|
595 |
|
---|
596 | public void valueChanged(ListSelectionEvent e) {
|
---|
597 | updateEnabledState();
|
---|
598 | }
|
---|
599 |
|
---|
600 | public void actionPerformed(ActionEvent e) {
|
---|
601 | List<Relation> relations = model.getSelectedNonNewRelations();
|
---|
602 | if (relations.isEmpty())
|
---|
603 | return;
|
---|
604 | Main.worker.submit(new DownloadRelationTask(
|
---|
605 | model.getSelectedNonNewRelations(),
|
---|
606 | Main.map.mapView.getEditLayer())
|
---|
607 | );
|
---|
608 | }
|
---|
609 | }
|
---|
610 |
|
---|
611 | /**
|
---|
612 | * Action for downloading incomplete members of selected relations
|
---|
613 | *
|
---|
614 | */
|
---|
615 | class DownloadSelectedIncompleteMembersAction extends AbstractAction implements ListSelectionListener{
|
---|
616 | public DownloadSelectedIncompleteMembersAction() {
|
---|
617 | putValue(SHORT_DESCRIPTION, tr("Download incomplete members of selected relations"));
|
---|
618 | putValue(SMALL_ICON, ImageProvider.get("dialogs/relation", "downloadincompleteselected"));
|
---|
619 | putValue(NAME, tr("Download incomplete members"));
|
---|
620 | updateEnabledState();
|
---|
621 | }
|
---|
622 |
|
---|
623 | public Set<OsmPrimitive> buildSetOfIncompleteMembers(List<Relation> rels) {
|
---|
624 | Set<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
|
---|
625 | for(Relation r: rels) {
|
---|
626 | ret.addAll(r.getIncompleteMembers());
|
---|
627 | }
|
---|
628 | return ret;
|
---|
629 | }
|
---|
630 |
|
---|
631 | public void actionPerformed(ActionEvent e) {
|
---|
632 | if (!isEnabled())
|
---|
633 | return;
|
---|
634 | List<Relation> rels = model.getSelectedRelationsWithIncompleteMembers();
|
---|
635 | if (rels.isEmpty()) return;
|
---|
636 | Main.worker.submit(new DownloadRelationMemberTask(
|
---|
637 | rels,
|
---|
638 | buildSetOfIncompleteMembers(rels),
|
---|
639 | Main.map.mapView.getEditLayer()
|
---|
640 | ));
|
---|
641 | }
|
---|
642 |
|
---|
643 | protected void updateEnabledState() {
|
---|
644 | setEnabled(!model.getSelectedRelationsWithIncompleteMembers().isEmpty());
|
---|
645 | }
|
---|
646 |
|
---|
647 | public void valueChanged(ListSelectionEvent e) {
|
---|
648 | updateEnabledState();
|
---|
649 | }
|
---|
650 | }
|
---|
651 |
|
---|
652 | class AddToRelation extends AbstractAction implements ListSelectionListener, SelectionChangedListener {
|
---|
653 |
|
---|
654 | public AddToRelation() {
|
---|
655 | super("", ImageProvider.get("dialogs/conflict", "copyendright"));
|
---|
656 | putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset after the last member"));
|
---|
657 | setEnabled(false);
|
---|
658 | }
|
---|
659 |
|
---|
660 | @Override
|
---|
661 | public void actionPerformed(ActionEvent e) {
|
---|
662 | Collection<Command> cmds = new LinkedList<Command>();
|
---|
663 | for (Relation orig : getSelectedRelations()) {
|
---|
664 | Command c = GenericRelationEditor.addPrimitivesToRelation(orig, Main.main.getCurrentDataSet().getSelected());
|
---|
665 | if (c != null) {
|
---|
666 | cmds.add(c);
|
---|
667 | }
|
---|
668 | }
|
---|
669 | if (!cmds.isEmpty()) {
|
---|
670 | Main.main.undoRedo.add(new SequenceCommand(tr("Add selection to relation"), cmds));
|
---|
671 | }
|
---|
672 | }
|
---|
673 |
|
---|
674 | @Override
|
---|
675 | public void valueChanged(ListSelectionEvent e) {
|
---|
676 | putValue(NAME, trn("Add selection to {0} relation", "Add selection to {0} relations",
|
---|
677 | getSelectedRelations().size(), getSelectedRelations().size()));
|
---|
678 | }
|
---|
679 |
|
---|
680 | @Override
|
---|
681 | public void selectionChanged(final Collection<? extends OsmPrimitive> newSelection) {
|
---|
682 | GuiHelper.runInEDT(new Runnable() {
|
---|
683 | @Override
|
---|
684 | public void run() {
|
---|
685 | setEnabled(newSelection != null && !newSelection.isEmpty());
|
---|
686 | }
|
---|
687 | });
|
---|
688 | }
|
---|
689 | }
|
---|
690 |
|
---|
691 | /**
|
---|
692 | * The list model for the list of relations displayed in the relation list
|
---|
693 | * dialog.
|
---|
694 | *
|
---|
695 | */
|
---|
696 | private class RelationListModel extends AbstractListModel {
|
---|
697 | private final ArrayList<Relation> relations = new ArrayList<Relation>();
|
---|
698 | private ArrayList<Relation> filteredRelations;
|
---|
699 | private DefaultListSelectionModel selectionModel;
|
---|
700 | private SearchCompiler.Match filter;
|
---|
701 |
|
---|
702 | public RelationListModel(DefaultListSelectionModel selectionModel) {
|
---|
703 | this.selectionModel = selectionModel;
|
---|
704 | }
|
---|
705 |
|
---|
706 | public Relation getRelation(int idx) {
|
---|
707 | return relations.get(idx);
|
---|
708 | }
|
---|
709 |
|
---|
710 | public void sort() {
|
---|
711 | Collections.sort(
|
---|
712 | relations,
|
---|
713 | DefaultNameFormatter.getInstance().getRelationComparator()
|
---|
714 | );
|
---|
715 | }
|
---|
716 |
|
---|
717 | private boolean isValid(Relation r) {
|
---|
718 | return !r.isDeleted() && r.isVisible() && !r.isIncomplete();
|
---|
719 | }
|
---|
720 |
|
---|
721 | public void setRelations(Collection<Relation> relations) {
|
---|
722 | List<Relation> sel = getSelectedRelations();
|
---|
723 | this.relations.clear();
|
---|
724 | this.filteredRelations = null;
|
---|
725 | if (relations == null) {
|
---|
726 | selectionModel.clearSelection();
|
---|
727 | fireContentsChanged(this,0,getSize());
|
---|
728 | return;
|
---|
729 | }
|
---|
730 | for (Relation r: relations) {
|
---|
731 | if (isValid(r)) {
|
---|
732 | this.relations.add(r);
|
---|
733 | }
|
---|
734 | }
|
---|
735 | sort();
|
---|
736 | fireIntervalAdded(this, 0, getSize());
|
---|
737 | setSelectedRelations(sel);
|
---|
738 | updateFilteredRelations();
|
---|
739 | }
|
---|
740 |
|
---|
741 | /**
|
---|
742 | * Add all relations in <code>addedPrimitives</code> to the model for the
|
---|
743 | * relation list dialog
|
---|
744 | *
|
---|
745 | * @param addedPrimitives the collection of added primitives. May include nodes,
|
---|
746 | * ways, and relations.
|
---|
747 | */
|
---|
748 | public void addRelations(Collection<? extends OsmPrimitive> addedPrimitives) {
|
---|
749 | boolean added = false;
|
---|
750 | for (OsmPrimitive p: addedPrimitives) {
|
---|
751 | if (! (p instanceof Relation)) {
|
---|
752 | continue;
|
---|
753 | }
|
---|
754 |
|
---|
755 | Relation r = (Relation)p;
|
---|
756 | if (relations.contains(r)) {
|
---|
757 | continue;
|
---|
758 | }
|
---|
759 | if (isValid(r)) {
|
---|
760 | relations.add(r);
|
---|
761 | added = true;
|
---|
762 | }
|
---|
763 | }
|
---|
764 | if (added) {
|
---|
765 | List<Relation> sel = getSelectedRelations();
|
---|
766 | sort();
|
---|
767 | fireIntervalAdded(this, 0, getSize());
|
---|
768 | setSelectedRelations(sel);
|
---|
769 | updateFilteredRelations();
|
---|
770 | }
|
---|
771 | }
|
---|
772 |
|
---|
773 | /**
|
---|
774 | * Removes all relations in <code>removedPrimitives</code> from the model
|
---|
775 | *
|
---|
776 | * @param removedPrimitives the removed primitives. May include nodes, ways,
|
---|
777 | * and relations
|
---|
778 | */
|
---|
779 | public void removeRelations(Collection<? extends OsmPrimitive> removedPrimitives) {
|
---|
780 | if (removedPrimitives == null) return;
|
---|
781 | // extract the removed relations
|
---|
782 | //
|
---|
783 | Set<Relation> removedRelations = new HashSet<Relation>();
|
---|
784 | for (OsmPrimitive p: removedPrimitives) {
|
---|
785 | if (! (p instanceof Relation)) {
|
---|
786 | continue;
|
---|
787 | }
|
---|
788 | removedRelations.add((Relation)p);
|
---|
789 | }
|
---|
790 | if (removedRelations.isEmpty())
|
---|
791 | return;
|
---|
792 | int size = relations.size();
|
---|
793 | relations.removeAll(removedRelations);
|
---|
794 | if (filteredRelations != null) {
|
---|
795 | filteredRelations.removeAll(removedRelations);
|
---|
796 | }
|
---|
797 | if (size != relations.size()) {
|
---|
798 | List<Relation> sel = getSelectedRelations();
|
---|
799 | sort();
|
---|
800 | fireContentsChanged(this, 0, getSize());
|
---|
801 | setSelectedRelations(sel);
|
---|
802 | }
|
---|
803 | }
|
---|
804 |
|
---|
805 | /**
|
---|
806 | * Replies the list of selected relations with incomplete members
|
---|
807 | *
|
---|
808 | * @return the list of selected relations with incomplete members
|
---|
809 | */
|
---|
810 | public List<Relation> getSelectedRelationsWithIncompleteMembers() {
|
---|
811 | List<Relation> ret = getSelectedNonNewRelations();
|
---|
812 | Iterator<Relation> it = ret.iterator();
|
---|
813 | while(it.hasNext()) {
|
---|
814 | Relation r = it.next();
|
---|
815 | if (!r.hasIncompleteMembers()) {
|
---|
816 | it.remove();
|
---|
817 | }
|
---|
818 | }
|
---|
819 | return ret;
|
---|
820 | }
|
---|
821 |
|
---|
822 | private void updateFilteredRelations() {
|
---|
823 | if (filter != null) {
|
---|
824 | filteredRelations = new ArrayList<Relation>(Utils.filter(relations, new Predicate<Relation>() {
|
---|
825 | @Override
|
---|
826 | public boolean evaluate(Relation r) {
|
---|
827 | return filter.match(r);
|
---|
828 | }
|
---|
829 | }));
|
---|
830 | } else if (filteredRelations != null) {
|
---|
831 | filteredRelations = null;
|
---|
832 | }
|
---|
833 | }
|
---|
834 |
|
---|
835 | public void setFilter(final SearchCompiler.Match filter) {
|
---|
836 | this.filter = filter;
|
---|
837 | updateFilteredRelations();
|
---|
838 | List<Relation> sel = getSelectedRelations();
|
---|
839 | fireContentsChanged(this, 0, getSize());
|
---|
840 | setSelectedRelations(sel);
|
---|
841 | updateTitle();
|
---|
842 | }
|
---|
843 |
|
---|
844 | private List<Relation> getVisibleRelations() {
|
---|
845 | return filteredRelations == null ? relations : filteredRelations;
|
---|
846 | }
|
---|
847 |
|
---|
848 | private Relation getVisibleRelation(int index) {
|
---|
849 | if (index < 0 || index >= getVisibleRelations().size()) return null;
|
---|
850 | return getVisibleRelations().get(index);
|
---|
851 | }
|
---|
852 |
|
---|
853 | @Override
|
---|
854 | public Object getElementAt(int index) {
|
---|
855 | return getVisibleRelation(index);
|
---|
856 | }
|
---|
857 |
|
---|
858 | @Override
|
---|
859 | public int getSize() {
|
---|
860 | return getVisibleRelations().size();
|
---|
861 | }
|
---|
862 |
|
---|
863 | /**
|
---|
864 | * Replies the list of selected, non-new relations. Empty list,
|
---|
865 | * if there are no selected, non-new relations.
|
---|
866 | *
|
---|
867 | * @return the list of selected, non-new relations.
|
---|
868 | */
|
---|
869 | public List<Relation> getSelectedNonNewRelations() {
|
---|
870 | ArrayList<Relation> ret = new ArrayList<Relation>();
|
---|
871 | for (int i=0; i<getSize();i++) {
|
---|
872 | if (!selectionModel.isSelectedIndex(i)) {
|
---|
873 | continue;
|
---|
874 | }
|
---|
875 | if (getVisibleRelation(i).isNew()) {
|
---|
876 | continue;
|
---|
877 | }
|
---|
878 | ret.add(getVisibleRelation(i));
|
---|
879 | }
|
---|
880 | return ret;
|
---|
881 | }
|
---|
882 |
|
---|
883 | /**
|
---|
884 | * Replies the list of selected relations. Empty list,
|
---|
885 | * if there are no selected relations.
|
---|
886 | *
|
---|
887 | * @return the list of selected, non-new relations.
|
---|
888 | */
|
---|
889 | public List<Relation> getSelectedRelations() {
|
---|
890 | ArrayList<Relation> ret = new ArrayList<Relation>();
|
---|
891 | for (int i=0; i<getSize();i++) {
|
---|
892 | if (!selectionModel.isSelectedIndex(i)) {
|
---|
893 | continue;
|
---|
894 | }
|
---|
895 | ret.add(getVisibleRelation(i));
|
---|
896 | }
|
---|
897 | return ret;
|
---|
898 | }
|
---|
899 |
|
---|
900 | /**
|
---|
901 | * Sets the selected relations.
|
---|
902 | *
|
---|
903 | * @param sel the list of selected relations
|
---|
904 | */
|
---|
905 | public void setSelectedRelations(Collection<Relation> sel) {
|
---|
906 | selectionModel.clearSelection();
|
---|
907 | if (sel == null || sel.isEmpty())
|
---|
908 | return;
|
---|
909 | for (Relation r: sel) {
|
---|
910 | int i = relations.indexOf(r);
|
---|
911 | if (i<0) {
|
---|
912 | continue;
|
---|
913 | }
|
---|
914 | selectionModel.addSelectionInterval(i,i);
|
---|
915 | }
|
---|
916 | }
|
---|
917 |
|
---|
918 | /**
|
---|
919 | * Returns the index of the relation
|
---|
920 | * @param rel The relation to look for
|
---|
921 | *
|
---|
922 | * @return index of relation (null if it cannot be found)
|
---|
923 | */
|
---|
924 | public Integer getRelationIndex(Relation rel) {
|
---|
925 | int i = relations.indexOf(rel);
|
---|
926 | if (i<0)
|
---|
927 | return null;
|
---|
928 | return i;
|
---|
929 | }
|
---|
930 |
|
---|
931 | public void updateTitle() {
|
---|
932 | if (relations.size() > 0 && relations.size() != getSize()) {
|
---|
933 | RelationListDialog.this.setTitle(tr("Relations: {0}/{1}", getSize(), relations.size()));
|
---|
934 | } else if (getSize() > 0) {
|
---|
935 | RelationListDialog.this.setTitle(tr("Relations: {0}", getSize()));
|
---|
936 | } else {
|
---|
937 | RelationListDialog.this.setTitle(tr("Relations"));
|
---|
938 | }
|
---|
939 | }
|
---|
940 | }
|
---|
941 |
|
---|
942 | class RelationDialogPopupMenu extends ListPopupMenu {
|
---|
943 |
|
---|
944 | public RelationDialogPopupMenu(JList list) {
|
---|
945 | super(list);
|
---|
946 |
|
---|
947 | // -- download members action
|
---|
948 | add(new DownloadMembersAction());
|
---|
949 |
|
---|
950 | // -- download incomplete members action
|
---|
951 | add(new DownloadSelectedIncompleteMembersAction());
|
---|
952 |
|
---|
953 | addSeparator();
|
---|
954 |
|
---|
955 | // -- select members action
|
---|
956 | add(new SelectMembersAction(false));
|
---|
957 | add(new SelectMembersAction(true));
|
---|
958 |
|
---|
959 | // -- select action
|
---|
960 | add(new SelectAction(false));
|
---|
961 | add(new SelectAction(true));
|
---|
962 |
|
---|
963 | addSeparator();
|
---|
964 |
|
---|
965 | add(addToRelation);
|
---|
966 | }
|
---|
967 | }
|
---|
968 |
|
---|
969 | public void addPopupMenuSeparator() {
|
---|
970 | popupMenu.addSeparator();
|
---|
971 | }
|
---|
972 |
|
---|
973 | public JMenuItem addPopupMenuAction(Action a) {
|
---|
974 | return popupMenu.add(a);
|
---|
975 | }
|
---|
976 |
|
---|
977 | public void addPopupMenuListener(PopupMenuListener l) {
|
---|
978 | popupMenu.addPopupMenuListener(l);
|
---|
979 | }
|
---|
980 |
|
---|
981 | public void removePopupMenuListener(PopupMenuListener l) {
|
---|
982 | popupMenu.addPopupMenuListener(l);
|
---|
983 | }
|
---|
984 |
|
---|
985 | public Collection<Relation> getSelectedRelations() {
|
---|
986 | return model.getSelectedRelations();
|
---|
987 | }
|
---|
988 |
|
---|
989 | /* ---------------------------------------------------------------------------------- */
|
---|
990 | /* DataSetListener */
|
---|
991 | /* ---------------------------------------------------------------------------------- */
|
---|
992 |
|
---|
993 | public void nodeMoved(NodeMovedEvent event) {/* irrelevant in this context */}
|
---|
994 |
|
---|
995 | public void wayNodesChanged(WayNodesChangedEvent event) {/* irrelevant in this context */}
|
---|
996 |
|
---|
997 | public void primitivesAdded(final PrimitivesAddedEvent event) {
|
---|
998 | model.addRelations(event.getPrimitives());
|
---|
999 | model.updateTitle();
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 | public void primitivesRemoved(final PrimitivesRemovedEvent event) {
|
---|
1003 | model.removeRelations(event.getPrimitives());
|
---|
1004 | model.updateTitle();
|
---|
1005 | }
|
---|
1006 |
|
---|
1007 | public void relationMembersChanged(final RelationMembersChangedEvent event) {
|
---|
1008 | List<Relation> sel = model.getSelectedRelations();
|
---|
1009 | model.sort();
|
---|
1010 | model.setSelectedRelations(sel);
|
---|
1011 | displaylist.repaint();
|
---|
1012 | }
|
---|
1013 |
|
---|
1014 | public void tagsChanged(TagsChangedEvent event) {
|
---|
1015 | OsmPrimitive prim = event.getPrimitive();
|
---|
1016 | if (prim == null || ! (prim instanceof Relation))
|
---|
1017 | return;
|
---|
1018 | // trigger a sort of the relation list because the display name may
|
---|
1019 | // have changed
|
---|
1020 | //
|
---|
1021 | List<Relation> sel = model.getSelectedRelations();
|
---|
1022 | model.sort();
|
---|
1023 | model.setSelectedRelations(sel);
|
---|
1024 | displaylist.repaint();
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | public void dataChanged(DataChangedEvent event) {
|
---|
1028 | initFromLayer(Main.main.getEditLayer());
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | public void otherDatasetChange(AbstractDatasetChangedEvent event) {/* ignore */}
|
---|
1032 | }
|
---|