source: josm/trunk/src/org/openstreetmap/josm/actions/ZoomToAction.java@ 5310

Last change on this file since 5310 was 5310, checked in by Don-vip, 12 years ago

fix #7750 - Conflict dialog: Really selects id:0 primitives without zooming

File size: 4.1 KB
Line 
1package org.openstreetmap.josm.actions;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.event.ActionEvent;
6
7import javax.swing.AbstractAction;
8import javax.swing.event.ListSelectionEvent;
9import javax.swing.event.ListSelectionListener;
10
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
14import org.openstreetmap.josm.gui.conflict.pair.nodes.NodeListTable;
15import org.openstreetmap.josm.gui.conflict.pair.relation.RelationMemberTable;
16import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
17import org.openstreetmap.josm.gui.layer.Layer;
18import org.openstreetmap.josm.gui.layer.OsmDataLayer;
19import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTable;
20import org.openstreetmap.josm.tools.CheckParameterUtil;
21
22public class ZoomToAction extends AbstractAction implements LayerChangeListener, ListSelectionListener {
23
24 private final OsmPrimitivesTable table;
25
26 private final String descriptionNominal;
27 private final String descriptionInactiveLayer;
28 private final String descriptionNoSelection;
29
30 public ZoomToAction(OsmPrimitivesTable table, String descriptionNominal, String descriptionInactiveLayer, String descriptionNoSelection) {
31 CheckParameterUtil.ensureParameterNotNull(table);
32 this.table = table;
33 this.descriptionNominal = descriptionNominal;
34 this.descriptionInactiveLayer = descriptionInactiveLayer;
35 this.descriptionNoSelection = descriptionNoSelection;
36 putValue(NAME, tr("Zoom to"));
37 putValue(SHORT_DESCRIPTION, descriptionNominal);
38 updateEnabledState();
39 }
40
41 public ZoomToAction(MemberTable table) {
42 this(table,
43 tr("Zoom to the object the first selected member refers to"),
44 tr("Zooming disabled because layer of this relation is not active"),
45 tr("Zooming disabled because there is no selected member"));
46 }
47
48 public ZoomToAction(RelationMemberTable table) {
49 this(table,
50 tr("Zoom to the object the first selected member refers to"),
51 tr("Zooming disabled because layer of this relation is not active"),
52 tr("Zooming disabled because there is no selected member"));
53 }
54
55 public ZoomToAction(NodeListTable table) {
56 this(table,
57 tr("Zoom to the first selected node"),
58 tr("Zooming disabled because layer of this way is not active"),
59 tr("Zooming disabled because there is no selected node"));
60 }
61
62 public void actionPerformed(ActionEvent e) {
63 if (! isEnabled())
64 return;
65 int rows[] = this.table.getSelectedRows();
66 if (rows == null || rows.length == 0)
67 return;
68 int row = rows[0];
69 OsmDataLayer layer = this.table.getLayer();
70 OsmPrimitive primitive = this.table.getPrimitiveInLayer(row, layer);
71 if (layer != null && primitive != null) {
72 layer.data.setSelected(primitive);
73 AutoScaleAction.autoScale("selection");
74 }
75 }
76
77 protected void updateEnabledState() {
78 if (Main.main == null || Main.main.getEditLayer() != this.table.getLayer()) {
79 setEnabled(false);
80 putValue(SHORT_DESCRIPTION, descriptionInactiveLayer);
81 return;
82 }
83 if (this.table.getSelectedRowCount() == 0) {
84 setEnabled(false);
85 putValue(SHORT_DESCRIPTION, descriptionNoSelection);
86 return;
87 }
88 setEnabled(true);
89 putValue(SHORT_DESCRIPTION, descriptionNominal);
90 }
91
92 public void valueChanged(ListSelectionEvent e) {
93 updateEnabledState();
94 }
95
96 public void activeLayerChange(Layer oldLayer, Layer newLayer) {
97 updateEnabledState();
98 }
99
100 public void layerAdded(Layer newLayer) {
101 updateEnabledState();
102 }
103
104 public void layerRemoved(Layer oldLayer) {
105 updateEnabledState();
106 }
107}
Note: See TracBrowser for help on using the repository browser.