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

Last change on this file since 6050 was 5857, checked in by Don-vip, 11 years ago

fix #8561 - Integrate restart plugin into core. Asks for restart when needed.

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