Changeset 16473 in josm for trunk/src/org/openstreetmap/josm/gui
- Timestamp:
- 2020-05-23T08:08:11+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/history
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/history/HistoryViewerPanel.java
r15772 r16473 4 4 import java.awt.GridBagConstraints; 5 5 import java.awt.Insets; 6 import java.awt.event.ActionEvent; 6 7 8 import javax.swing.AbstractAction; 9 import javax.swing.JPopupMenu; 7 10 import javax.swing.JScrollPane; 8 11 import javax.swing.JTable; 9 12 13 import org.openstreetmap.josm.actions.AutoScaleAction; 14 import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode; 15 import org.openstreetmap.josm.data.osm.IPrimitive; 16 import org.openstreetmap.josm.data.osm.OsmData; 17 import org.openstreetmap.josm.data.osm.PrimitiveId; 18 import org.openstreetmap.josm.gui.MainApplication; 10 19 import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer; 20 import org.openstreetmap.josm.tools.ImageProvider; 11 21 12 22 /** … … 83 93 add(embedInScrollPane(buildTable(PointInTimeType.CURRENT_POINT_IN_TIME)), gc); 84 94 } 95 96 static class ListPopupMenu extends JPopupMenu { 97 private final ZoomToObjectAction zoomToObjectAction; 98 private final ShowHistoryAction showHistoryAction; 99 100 ListPopupMenu(String name, String shortDescription) { 101 zoomToObjectAction = new ZoomToObjectAction(name, shortDescription); 102 add(zoomToObjectAction); 103 showHistoryAction = new ShowHistoryAction(); 104 add(showHistoryAction); 105 } 106 107 void prepare(PrimitiveId pid) { 108 zoomToObjectAction.setPrimitiveId(pid); 109 zoomToObjectAction.updateEnabledState(); 110 111 showHistoryAction.setPrimitiveId(pid); 112 showHistoryAction.updateEnabledState(); 113 } 114 } 115 116 static class ZoomToObjectAction extends AbstractAction { 117 private transient PrimitiveId primitiveId; 118 119 /** 120 * Constructs a new {@code ZoomToObjectAction}. 121 * @param name name for the action 122 * @param shortDescription The key used for storing a short <code>String</code> description for the action, used for tooltip text. 123 */ 124 ZoomToObjectAction(String name, String shortDescription) { 125 putValue(NAME, name); 126 putValue(SHORT_DESCRIPTION, shortDescription); 127 new ImageProvider("dialogs", "zoomin").getResource().attachImageIcon(this, true); 128 } 129 130 @Override 131 public void actionPerformed(ActionEvent e) { 132 if (!isEnabled()) 133 return; 134 IPrimitive p = getPrimitiveToZoom(); 135 if (p != null && p.isSelectable()) { 136 p.getDataSet().setSelected(p); 137 AutoScaleAction.autoScale(AutoScaleMode.SELECTION); 138 } 139 } 140 141 public void setPrimitiveId(PrimitiveId pid) { 142 this.primitiveId = pid; 143 updateEnabledState(); 144 } 145 146 protected IPrimitive getPrimitiveToZoom() { 147 if (primitiveId == null) 148 return null; 149 OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData(); 150 if (ds == null) 151 return null; 152 return ds.getPrimitiveById(primitiveId); 153 } 154 155 public void updateEnabledState() { 156 setEnabled(MainApplication.getLayerManager().getActiveData() != null && getPrimitiveToZoom() != null); 157 } 158 } 85 159 } -
trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java
r16465 r16473 5 5 6 6 import java.awt.Point; 7 import java.awt.event.ActionEvent;8 7 9 import javax.swing.AbstractAction;10 import javax.swing.JPopupMenu;11 8 import javax.swing.JTable; 12 9 import javax.swing.ListSelectionModel; 13 10 14 import org.openstreetmap.josm.actions.AutoScaleAction;15 import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode;16 import org.openstreetmap.josm.data.osm.IPrimitive;17 import org.openstreetmap.josm.data.osm.OsmData;18 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 12 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 21 14 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 22 15 import org.openstreetmap.josm.data.osm.history.History; 23 import org.openstreetmap.josm.gui.MainApplication;24 16 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 25 import org.openstreetmap.josm.tools.ImageProvider;26 17 27 18 /** … … 56 47 table.addMouseListener(new ShowHistoryAction.DoubleClickAdapter(e -> { 57 48 int row = table.rowAtPoint(e.getPoint()); 58 return row < 0 ? null :primitiveIdAtRow(tableModel, row);49 return primitiveIdAtRow(tableModel, row); 59 50 })); 60 51 return table; 61 52 } 62 53 63 static class NodeListPopupMenu extends JPopupMenu {64 private final ZoomToNodeAction zoomToNodeAction;65 private final ShowHistoryAction showHistoryAction;66 67 NodeListPopupMenu() {68 zoomToNodeAction = new ZoomToNodeAction();69 add(zoomToNodeAction);70 showHistoryAction = new ShowHistoryAction();71 add(showHistoryAction);72 }73 74 void prepare(PrimitiveId pid) {75 zoomToNodeAction.setPrimitiveId(pid);76 zoomToNodeAction.updateEnabledState();77 78 showHistoryAction.setPrimitiveId(pid);79 showHistoryAction.updateEnabledState();80 }81 }82 83 static class ZoomToNodeAction extends AbstractAction {84 private transient PrimitiveId primitiveId;85 86 /**87 * Constructs a new {@code ZoomToNodeAction}.88 */89 ZoomToNodeAction() {90 putValue(NAME, tr("Zoom to node"));91 putValue(SHORT_DESCRIPTION, tr("Zoom to this node in the current data layer"));92 new ImageProvider("dialogs", "zoomin").getResource().attachImageIcon(this, true);93 }94 95 @Override96 public void actionPerformed(ActionEvent e) {97 if (!isEnabled())98 return;99 IPrimitive p = getPrimitiveToZoom();100 if (p != null && p.isSelectable()) {101 p.getDataSet().setSelected(p);102 AutoScaleAction.autoScale(AutoScaleMode.SELECTION);103 }104 }105 106 public void setPrimitiveId(PrimitiveId pid) {107 this.primitiveId = pid;108 updateEnabledState();109 }110 111 protected IPrimitive getPrimitiveToZoom() {112 if (primitiveId == null)113 return null;114 OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();115 if (ds == null)116 return null;117 return ds.getPrimitiveById(primitiveId);118 }119 120 public void updateEnabledState() {121 setEnabled(MainApplication.getLayerManager().getActiveData() != null && getPrimitiveToZoom() != null);122 }123 }124 125 54 private static PrimitiveId primitiveIdAtRow(DiffTableModel model, int row) { 55 if (row < 0) 56 return null; 126 57 Long id = (Long) model.getValueAt(row, 0).value; 127 58 return id == null ? null : new SimplePrimitiveId(id, OsmPrimitiveType.NODE); … … 130 61 static class InternalPopupMenuLauncher extends PopupMenuLauncher { 131 62 InternalPopupMenuLauncher() { 132 super(new NodeListPopupMenu());63 super(new ListPopupMenu(tr("Zoom to node"), tr("Zoom to this node in the current data layer"))); 133 64 } 134 65 … … 136 67 protected int checkTableSelection(JTable table, Point p) { 137 68 int row = super.checkTableSelection(table, p); 138 (( NodeListPopupMenu) menu).prepare(primitiveIdAtRow((DiffTableModel) table.getModel(), row));69 ((ListPopupMenu) menu).prepare(primitiveIdAtRow((DiffTableModel) table.getModel(), row)); 139 70 return row; 140 71 } -
trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListViewer.java
r16460 r16473 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Point; 6 7 import java.awt.Rectangle; 7 8 … … 9 10 import javax.swing.ListSelectionModel; 10 11 12 import org.openstreetmap.josm.data.osm.PrimitiveId; 11 13 import org.openstreetmap.josm.data.osm.RelationMemberData; 14 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 15 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 12 16 13 17 /** … … 25 29 @Override 26 30 protected JTable buildTable(PointInTimeType pointInTimeType) { 27 DiffTableModel tableModel = model.getRelationMemberTableModel(pointInTimeType);28 RelationMemberTableColumnModel columnModel = new RelationMemberTableColumnModel();29 JTable table = new JTable(tableModel, columnModel);31 final DiffTableModel tableModel = model.getRelationMemberTableModel(pointInTimeType); 32 final RelationMemberTableColumnModel columnModel = new RelationMemberTableColumnModel(); 33 final JTable table = new JTable(tableModel, columnModel); 30 34 tableModel.addTableModelListener(new ReversedChangeListener( 31 35 table, columnModel, tr("The members of this relation are in reverse order"))); 32 36 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 33 37 selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel()); 38 table.addMouseListener(new InternalPopupMenuLauncher()); 34 39 table.getModel().addTableModelListener(e -> { 35 40 Rectangle rect = table.getCellRect(((DiffTableModel) e.getSource()).getFirstChange(), 0, true); … … 38 43 table.addMouseListener(new ShowHistoryAction.DoubleClickAdapter(e -> { 39 44 int row = table.rowAtPoint(e.getPoint()); 40 return row < 0 ? null : (RelationMemberData) tableModel.getValueAt(row, 0).value;45 return primitiveIdAtRow(tableModel, row); 41 46 })); 42 47 return table; … … 50 55 super(model); 51 56 } 57 58 private static PrimitiveId primitiveIdAtRow(DiffTableModel model, int row) { 59 if (row < 0) 60 return null; 61 RelationMemberData rm = (RelationMemberData) model.getValueAt(row, 0).value; 62 if (rm == null) 63 return null; 64 return new SimplePrimitiveId(rm.getUniqueId(), rm.getType()); 65 } 66 67 static class InternalPopupMenuLauncher extends PopupMenuLauncher { 68 InternalPopupMenuLauncher() { 69 super(new ListPopupMenu(tr("Zoom to member"), tr("Zoom to this member in the current data layer"))); 70 71 } 72 73 @Override 74 protected int checkTableSelection(JTable table, Point p) { 75 int row = super.checkTableSelection(table, p); 76 ((ListPopupMenu) menu).prepare(primitiveIdAtRow((DiffTableModel) table.getModel(), row)); 77 return row; 78 } 79 } 80 52 81 }
Note:
See TracChangeset
for help on using the changeset viewer.