Changeset 5958 in josm
- Timestamp:
- 2013-05-13T03:10:05+02:00 (12 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
r5460 r5958 13 13 14 14 import javax.swing.JOptionPane; 15 import javax.swing.event.ListSelectionEvent; 16 import javax.swing.event.ListSelectionListener; 17 import javax.swing.event.TreeSelectionEvent; 18 import javax.swing.event.TreeSelectionListener; 15 19 16 20 import org.openstreetmap.josm.Main; … … 19 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 24 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 25 import org.openstreetmap.josm.data.validation.TestError; 26 import org.openstreetmap.josm.gui.MapFrame; 27 import org.openstreetmap.josm.gui.MapFrameListener; 21 28 import org.openstreetmap.josm.gui.MapView; 22 29 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 30 import org.openstreetmap.josm.gui.dialogs.ValidatorDialog.ValidatorBoundingXYVisitor; 23 31 import org.openstreetmap.josm.gui.layer.Layer; 24 32 import org.openstreetmap.josm.tools.Shortcut; … … 36 44 marktr("conflict"), 37 45 marktr("download"), 46 marktr("problem"), 38 47 marktr("previous"), 39 48 marktr("next")}; 49 50 private final String mode; 51 52 protected ZoomChangeAdapter zoomChangeAdapter; 53 protected MapFrameAdapter mapFrameAdapter; 40 54 41 55 /** … … 77 91 } 78 92 79 private final String mode;80 81 93 private static int getModeShortcut(String mode) { 82 94 int shortcut = -1; … … 88 100 else if (mode.equals("conflict")) { shortcut = KeyEvent.VK_4; } 89 101 else if (mode.equals("download")) { shortcut = KeyEvent.VK_5; } 102 else if (mode.equals("problem")) { shortcut = KeyEvent.VK_6; } 90 103 else if (mode.equals("previous")) { shortcut = KeyEvent.VK_8; } 91 104 else if (mode.equals("next")) { shortcut = KeyEvent.VK_9; } … … 95 108 96 109 /** 97 * 98 * @param mode 110 * Constructs a new {@code AutoScaleAction}. 111 * @param mode The autoscale mode (one of {@link AutoScaleAction#MODES}) 99 112 * @param marker Used only to differentiate from default constructor 100 113 */ … … 104 117 } 105 118 106 107 public AutoScaleAction(String mode) { 119 /** 120 * Constructs a new {@code AutoScaleAction}. 121 * @param mode The autoscale mode (one of {@link AutoScaleAction#MODES}) 122 */ 123 public AutoScaleAction(final String mode) { 108 124 super(tr("Zoom to {0}", tr(mode)), "dialogs/autoscale/" + mode, tr("Zoom the view to {0}.", tr(mode)), 109 Shortcut.registerShortcut("view:zoom"+mode, tr("View: {0}", tr("Zoom to {0}", tr(mode))), getModeShortcut(mode), Shortcut.DIRECT), true); 125 Shortcut.registerShortcut("view:zoom"+mode, tr("View: {0}", tr("Zoom to {0}", tr(mode))), getModeShortcut(mode), Shortcut.DIRECT), 126 true, null, false); 110 127 String modeHelp = Character.toUpperCase(mode.charAt(0)) + mode.substring(1); 111 128 putValue("help", "Action/AutoScale/" + modeHelp); … … 119 136 } else if (mode.equals("conflict")) { 120 137 putValue("help", ht("/Action/ZoomToConflict")); 138 } else if (mode.equals("problem")) { 139 putValue("help", ht("/Action/ZoomToProblem")); 121 140 } else if (mode.equals("download")) { 122 141 putValue("help", ht("/Action/ZoomToDownload")); … … 125 144 } else if (mode.equals("next")) { 126 145 putValue("help", ht("/Action/ZoomToNext")); 127 } 146 } else { 147 throw new IllegalArgumentException("Unknown mode: "+mode); 148 } 149 installAdapters(); 128 150 } 129 151 … … 171 193 172 194 private BoundingXYVisitor getBoundingBox() { 173 BoundingXYVisitor v = new BoundingXYVisitor(); 174 if (mode.equals("data")) { 195 BoundingXYVisitor v = mode.equals("problem") ? new ValidatorBoundingXYVisitor() : new BoundingXYVisitor(); 196 197 if (mode.equals("problem")) { 198 TestError error = Main.map.validatorDialog.getSelectedError(); 199 if (error == null) return null; 200 ((ValidatorBoundingXYVisitor) v).visit(error); 201 if (v.getBounds() == null) return null; 202 v.enlargeBoundingBox(Main.pref.getDouble("validator.zoom-enlarge-bbox", 0.0002)); 203 } else if (mode.equals("data")) { 175 204 for (Layer l : Main.map.mapView.getAllLayers()) { 176 205 l.visitBoundingBox(v); … … 236 265 setEnabled(true); 237 266 } 267 } else if ("conflict".equals(mode)) { 268 setEnabled(Main.map != null && Main.map.conflictDialog.getSelectedConflict() != null); 269 } else if ("problem".equals(mode)) { 270 setEnabled(Main.map != null && Main.map.validatorDialog.getSelectedError() != null); 238 271 } else if ("previous".equals(mode)) { 239 272 setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasZoomUndoEntries()); … … 258 291 protected void installAdapters() { 259 292 super.installAdapters(); 260 // make this action listen to zoom change events293 // make this action listen to zoom and mapframe change events 261 294 // 262 zoomChangeAdapter = new ZoomChangeAdapter();263 Ma pView.addZoomChangeListener(zoomChangeAdapter);295 MapView.addZoomChangeListener(zoomChangeAdapter = new ZoomChangeAdapter()); 296 Main.addMapFrameListener(mapFrameAdapter = new MapFrameAdapter()); 264 297 initEnabledState(); 265 298 } 266 299 267 300 /** 268 * Adapter for selection change events 269 * 301 * Adapter for zoom change events 270 302 */ 271 303 private class ZoomChangeAdapter implements MapView.ZoomChangeListener { … … 275 307 } 276 308 277 private ZoomChangeAdapter zoomChangeAdapter; 309 /** 310 * Adapter for MapFrame change events 311 */ 312 private class MapFrameAdapter implements MapFrameListener { 313 private ListSelectionListener conflictSelectionListener; 314 private TreeSelectionListener validatorSelectionListener; 315 316 public MapFrameAdapter() { 317 if (mode.equals("conflict")) { 318 conflictSelectionListener = new ListSelectionListener() { 319 @Override public void valueChanged(ListSelectionEvent e) { 320 updateEnabledState(); 321 } 322 }; 323 } else if (mode.equals("problem")) { 324 validatorSelectionListener = new TreeSelectionListener() { 325 @Override public void valueChanged(TreeSelectionEvent e) { 326 updateEnabledState(); 327 } 328 }; 329 } 330 } 331 332 @Override public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 333 if (conflictSelectionListener != null) { 334 if (newFrame != null) { 335 newFrame.conflictDialog.addListSelectionListener(conflictSelectionListener); 336 } else if (oldFrame != null) { 337 oldFrame.conflictDialog.removeListSelectionListener(conflictSelectionListener); 338 } 339 } else if (validatorSelectionListener != null) { 340 if (newFrame != null) { 341 newFrame.validatorDialog.addTreeSelectionListener(validatorSelectionListener); 342 } else if (oldFrame != null) { 343 oldFrame.validatorDialog.removeTreeSelectionListener(validatorSelectionListener); 344 } 345 } 346 } 347 } 278 348 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r5857 r5958 9 9 import java.awt.Toolkit; 10 10 import java.awt.event.KeyEvent; 11 import java.util.HashMap; 12 import java.util.Map; 11 13 12 14 import javax.swing.JCheckBoxMenuItem; … … 166 168 public final HistoryInfoAction historyinfo = new HistoryInfoAction(); 167 169 public final HistoryInfoWebAction historyinfoweb = new HistoryInfoWebAction(); 170 public final Map<String, AutoScaleAction> autoScaleActions = new HashMap<String, AutoScaleAction>(); 168 171 169 172 /* Tools menu */ … … 494 497 viewMenu.addSeparator(); 495 498 for (String mode : AutoScaleAction.MODES) { 496 JosmAction autoScaleAction = new AutoScaleAction(mode); 499 AutoScaleAction autoScaleAction = new AutoScaleAction(mode); 500 autoScaleActions.put(mode, autoScaleAction); 497 501 add(viewMenu, autoScaleAction); 498 502 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java
r5360 r5958 107 107 lstInSelection.addMouseListener(dblClickHandler); 108 108 lstInActiveDataLayer.addMouseListener(dblClickHandler); 109 110 ChangesetPopupMenuLauncher popupMenuLauncher = new ChangesetPopupMenuLauncher();111 lstInSelection.addMouseListener(popupMenuLauncher);112 lstInActiveDataLayer.addMouseListener(popupMenuLauncher);113 109 } 114 110 … … 211 207 popupMenu = new ChangesetDialogPopup(lstInActiveDataLayer, lstInSelection); 212 208 209 PopupMenuLauncher popupMenuLauncher = new PopupMenuLauncher(popupMenu); 210 lstInSelection.addMouseListener(popupMenuLauncher); 211 lstInActiveDataLayer.addMouseListener(popupMenuLauncher); 212 213 213 createLayout(pnl, false, Arrays.asList(new SideButton[] { 214 214 new SideButton(selectObjectsAction, false), … … 522 522 } 523 523 524 class ChangesetPopupMenuLauncher extends PopupMenuLauncher {525 @Override526 public void launch(MouseEvent evt) {527 JList lst = getCurrentChangesetList();528 if (lst.getSelectedIndices().length == 0) {529 int idx = lst.locationToIndex(evt.getPoint());530 if (idx >=0) {531 lst.getSelectionModel().addSelectionInterval(idx, idx);532 }533 }534 popupMenu.show(lst, evt.getX(), evt.getY());535 }536 }537 538 524 class ChangesetDialogPopup extends ListPopupMenu { 539 525 public ChangesetDialogPopup(JList ... lists) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
r5926 r5958 7 7 import java.awt.Dimension; 8 8 import java.awt.GridBagLayout; 9 import java.awt.Point;10 9 import java.awt.event.ActionEvent; 11 10 import java.awt.event.KeyEvent; … … 81 80 Shortcut.registerShortcut("subwindow:commandstack", tr("Toggle: {0}", 82 81 tr("Command Stack")), KeyEvent.VK_O, Shortcut.ALT_SHIFT), 100, true); 83 undoTree.addMouseListener(new PopupMenuHandler());82 undoTree.addMouseListener(new MouseEventHandler()); 84 83 undoTree.setRootVisible(false); 85 84 undoTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); … … 91 90 InputMapUtils.unassignCtrlShiftUpDown(undoTree, JComponent.WHEN_FOCUSED); 92 91 93 redoTree.addMouseListener(new PopupMenuHandler());92 redoTree.addMouseListener(new MouseEventHandler()); 94 93 redoTree.setRootVisible(false); 95 94 redoTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); … … 382 381 * undo / redo switch to reduce duplicate code 383 382 */ 384 protected enum UndoRedoType {UNDO, REDO} ;383 protected enum UndoRedoType {UNDO, REDO} 385 384 386 385 /** … … 444 443 } 445 444 446 class PopupMenuHandler extends PopupMenuLauncher { 445 class MouseEventHandler extends PopupMenuLauncher { 446 447 public MouseEventHandler() { 448 super(new CommandStackPopup()); 449 } 447 450 448 451 @Override 449 452 public void mouseClicked(MouseEvent evt) { 450 super.mouseClicked(evt); 451 if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount()>1) { 453 if (isDoubleClick(evt)) { 452 454 selectAndZoomAction.actionPerformed(null); 453 455 } 454 456 } 455 456 @Override 457 public void launch(MouseEvent evt) { 458 Point p = evt.getPoint(); 459 JTree tree = (JTree) evt.getSource(); 460 int row = tree.getRowForLocation(p.x, p.y); 461 if (row != -1) { 462 TreePath path = tree.getPathForLocation(p.x, p.y); 463 // right click on unselected element -> select it first 464 if (!tree.isPathSelected(path)) { 465 tree.setSelectionPath(path); 466 } 467 TreePath[] selPaths = tree.getSelectionPaths(); 468 469 CommandStackPopup menu = new CommandStackPopup(); 470 menu.show(tree, p.x, p.y-3); 471 } 472 } 473 } 474 457 } 475 458 476 459 private class CommandStackPopup extends JPopupMenu { -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r5775 r5958 12 12 import java.awt.event.ActionEvent; 13 13 import java.awt.event.KeyEvent; 14 import java.awt.event.MouseAdapter;15 14 import java.awt.event.MouseEvent; 16 15 import java.util.Arrays; … … 25 24 import javax.swing.JList; 26 25 import javax.swing.JOptionPane; 26 import javax.swing.JPopupMenu; 27 27 import javax.swing.ListModel; 28 28 import javax.swing.ListSelectionModel; … … 46 46 import org.openstreetmap.josm.data.osm.visitor.Visitor; 47 47 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 48 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 48 49 import org.openstreetmap.josm.gui.MapView; 49 50 import org.openstreetmap.josm.gui.NavigatableComponent; 50 51 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 52 import org.openstreetmap.josm.gui.PopupMenuHandler; 51 53 import org.openstreetmap.josm.gui.SideButton; 52 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;53 54 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 54 55 import org.openstreetmap.josm.gui.util.GuiHelper; 56 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 55 57 import org.openstreetmap.josm.tools.ImageProvider; 56 58 import org.openstreetmap.josm.tools.Shortcut; … … 81 83 /** the list widget for the list of conflicts */ 82 84 private JList lstConflicts; 85 86 private final JPopupMenu popupMenu = new JPopupMenu(); 87 private final PopupMenuHandler popupMenuHandler = new PopupMenuHandler(popupMenu); 83 88 84 89 private ResolveAction actResolve; … … 94 99 lstConflicts.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 95 100 lstConflicts.setCellRenderer(new OsmPrimitivRenderer()); 96 lstConflicts.addMouseListener(new MouseAdapter(){ 97 @Override public void mouseClicked(MouseEvent e) { 98 if (e.getClickCount() >= 2) { 99 resolve(); 100 } 101 } 102 }); 103 lstConflicts.getSelectionModel().addListSelectionListener(new ListSelectionListener(){ 101 lstConflicts.addMouseListener(new MouseEventHandler()); 102 addListSelectionListener(new ListSelectionListener(){ 104 103 public void valueChanged(ListSelectionEvent e) { 105 104 Main.map.mapView.repaint(); … … 108 107 109 108 SideButton btnResolve = new SideButton(actResolve = new ResolveAction()); 110 lstConflicts.getSelectionModel().addListSelectionListener(actResolve);109 addListSelectionListener(actResolve); 111 110 112 111 SideButton btnSelect = new SideButton(actSelect = new SelectAction()); 113 lstConflicts.getSelectionModel().addListSelectionListener(actSelect);112 addListSelectionListener(actSelect); 114 113 115 114 createLayout(lstConflicts, true, Arrays.asList(new SideButton[] { 116 115 btnResolve, btnSelect 117 116 })); 117 118 popupMenuHandler.addAction(Main.main.menu.autoScaleActions.get("conflict")); 118 119 } 119 120 … … 141 142 MapView.removeEditLayerChangeListener(this); 142 143 DataSet.removeSelectionListener(this); 144 } 145 146 /** 147 * Add a list selection listener to the conflicts list. 148 * @param listener the ListSelectionListener 149 * @since 5958 150 */ 151 public void addListSelectionListener(ListSelectionListener listener) { 152 lstConflicts.getSelectionModel().addListSelectionListener(listener); 153 } 154 155 /** 156 * Remove the given list selection listener from the conflicts list. 157 * @param listener the ListSelectionListener 158 * @since 5958 159 */ 160 public void removeListSelectionListener(ListSelectionListener listener) { 161 lstConflicts.getSelectionModel().removeListSelectionListener(listener); 162 } 163 164 /** 165 * Replies the popup menu handler. 166 * @return The popup menu handler 167 * @since 5958 168 */ 169 public PopupMenuHandler getPopupMenuHandler() { 170 return popupMenuHandler; 143 171 } 144 172 … … 302 330 public String helpTopic() { 303 331 return ht("/Dialog/ConflictList"); 332 } 333 334 class MouseEventHandler extends PopupMenuLauncher { 335 public MouseEventHandler() { 336 super(popupMenu); 337 } 338 @Override public void mouseClicked(MouseEvent e) { 339 if (isDoubleClick(e)) { 340 resolve(); 341 } 342 } 304 343 } 305 344 -
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r5897 r5958 1020 1020 1021 1021 class PopupMenuHandler extends PopupMenuLauncher { 1022 @Override 1023 public void launch(MouseEvent evt) { 1024 Point p = evt.getPoint(); 1025 int index = layerList.rowAtPoint(p); 1026 if (index < 0) return; 1027 if (!layerList.getCellRect(index, 2, false).contains(evt.getPoint())) 1028 return; 1029 if (!layerList.isRowSelected(index)) { 1030 layerList.setRowSelectionInterval(index, index); 1031 } 1032 Layer layer = model.getLayer(index); 1033 LayerListPopup menu = new LayerListPopup(getModel().getSelectedLayers(), layer); 1034 menu.show(layerList, p.x, p.y-3); 1022 @Override public void launch(MouseEvent evt) { 1023 Layer layer = getModel().getLayer(layerList.getSelectedRow()); 1024 menu = new LayerListPopup(getModel().getSelectedLayers(), layer); 1025 super.launch(evt); 1035 1026 } 1036 1027 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r5886 r5958 694 694 if (cbWireframe.isSelected()) 695 695 return; 696 Point p = evt.getPoint();697 int index = tblStyles.rowAtPoint(p);698 if (index < 0) return; 699 if (!tblStyles.getCellRect(index, 1, false).contains(evt.getPoint()))700 return;701 if (!tblStyles.isRowSelected(index)) {702 tblStyles.setRowSelectionInterval(index, index);703 704 MapPaintPopup menu = new MapPaintPopup();705 menu.show(tblStyles, p.x, p.y); 706 }707 }708 696 super.launch(evt); 697 } 698 699 @Override 700 protected void showMenu(MouseEvent evt) { 701 menu = new MapPaintPopup(); 702 super.showMenu(evt); 703 } 704 } 705 706 /** 707 * The popup menu displayed when right-clicking a map paint entry 708 */ 709 709 public class MapPaintPopup extends JPopupMenu { 710 710 /** -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r5886 r5958 6 6 import java.awt.BorderLayout; 7 7 import java.awt.Color; 8 import java.awt.Point;9 8 import java.awt.event.ActionEvent; 10 9 import java.awt.event.KeyEvent; 11 import java.awt.event.MouseAdapter;12 10 import java.awt.event.MouseEvent; 13 11 import java.util.ArrayList; … … 29 27 import javax.swing.KeyStroke; 30 28 import javax.swing.ListSelectionModel; 31 import javax.swing.SwingUtilities;32 29 import javax.swing.UIManager; 33 30 import javax.swing.event.DocumentEvent; … … 70 67 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 71 68 import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField; 69 import org.openstreetmap.josm.gui.widgets.JosmTextField; 70 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 72 71 import org.openstreetmap.josm.tools.ImageProvider; 73 72 import org.openstreetmap.josm.tools.InputMapUtils; … … 75 74 import org.openstreetmap.josm.tools.Shortcut; 76 75 import org.openstreetmap.josm.tools.Utils; 77 import org.openstreetmap.josm.gui.widgets.JosmTextField;78 76 79 77 /** … … 295 293 } 296 294 297 class MouseEventHandler extends MouseAdapter { 295 class MouseEventHandler extends PopupMenuLauncher { 296 297 public MouseEventHandler() { 298 super(popupMenu); 299 } 300 298 301 protected void setCurrentRelationAsSelection() { 299 302 Main.main.getCurrentDataSet().setSelected((Relation)displaylist.getSelectedValue()); … … 306 309 @Override public void mouseClicked(MouseEvent e) { 307 310 if (Main.main.getEditLayer() == null) return; 308 if ( e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {311 if (isDoubleClick(e)) { 309 312 if (e.isControlDown()) { 310 313 editCurrentRelation(); … … 312 315 setCurrentRelationAsSelection(); 313 316 } 314 }315 }316 private void openPopup(MouseEvent e) {317 Point p = e.getPoint();318 int index = displaylist.locationToIndex(p);319 if (index < 0) return;320 if (!displaylist.getCellBounds(index, index).contains(e.getPoint()))321 return;322 if (! displaylist.isSelectedIndex(index)) {323 displaylist.setSelectedIndex(index);324 }325 popupMenu.show(displaylist, p.x, p.y-3);326 }327 @Override public void mousePressed(MouseEvent e) {328 if (Main.main.getEditLayer() == null) return;329 if (e.isPopupTrigger()) {330 openPopup(e);331 }332 }333 @Override public void mouseReleased(MouseEvent e) {334 if (Main.main.getEditLayer() == null) return;335 if (e.isPopupTrigger()) {336 openPopup(e);337 317 } 338 318 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r5903 r5958 10 10 import java.awt.event.ActionListener; 11 11 import java.awt.event.KeyEvent; 12 import java.awt.event.MouseAdapter;13 12 import java.awt.event.MouseEvent; 14 13 import java.util.ArrayList; … … 29 28 import javax.swing.JPopupMenu; 30 29 import javax.swing.ListSelectionModel; 31 import javax.swing.SwingUtilities;32 30 import javax.swing.event.ListDataEvent; 33 31 import javax.swing.event.ListDataListener; … … 153 151 }); 154 152 155 lstPrimitives.addMouseListener(new SelectionPopupMenuLauncher()); 156 lstPrimitives.addMouseListener(new DblClickHandler()); 153 lstPrimitives.addMouseListener(new MouseEventHandler()); 157 154 158 155 InputMapUtils.addEnterAction(lstPrimitives, actZoomToListSelection); … … 182 179 183 180 /** 184 * Responds to double clicks on the list of selected objects 185 */ 186 class DblClickHandler extends MouseAdapter { 181 * Responds to double clicks on the list of selected objects and launches the popup menu 182 */ 183 class MouseEventHandler extends PopupMenuLauncher { 184 185 public MouseEventHandler() { 186 super(popupMenu); 187 } 188 187 189 @Override 188 190 public void mouseClicked(MouseEvent e) { 189 if (e.getClickCount() < 2 || ! SwingUtilities.isLeftMouseButton(e)) return; 190 int idx = lstPrimitives.locationToIndex(e.getPoint()); 191 if (idx < 0) return; 192 OsmDataLayer layer = Main.main.getEditLayer(); 193 if(layer == null) return; 194 layer.data.setSelected(Collections.singleton((OsmPrimitive)model.getElementAt(idx))); 195 } 196 } 197 198 /** 199 * The popup menu launcher 200 */ 201 class SelectionPopupMenuLauncher extends PopupMenuLauncher { 202 203 @Override 204 public void launch(MouseEvent evt) { 205 if (model.getSelected().isEmpty()) { 206 int idx = lstPrimitives.locationToIndex(evt.getPoint()); 191 if (isDoubleClick(e)) { 192 int idx = lstPrimitives.locationToIndex(e.getPoint()); 207 193 if (idx < 0) return; 208 model.setSelected(Collections.singleton((OsmPrimitive)model.getElementAt(idx))); 209 } 210 popupMenu.show(lstPrimitives, evt.getX(), evt.getY()); 194 OsmDataLayer layer = Main.main.getEditLayer(); 195 if (layer == null) return; 196 layer.data.setSelected(Collections.singleton((OsmPrimitive)model.getElementAt(idx))); 197 } 211 198 } 212 199 } … … 758 745 759 746 /** 760 * The popup menue for the JOSM selection history entries 761 * 747 * The popup menu for the JOSM selection history entries 762 748 */ 763 749 protected static class SelectionHistoryPopup extends JPopupMenu { -
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r5718 r5958 21 21 import java.awt.event.ComponentAdapter; 22 22 import java.awt.event.ComponentEvent; 23 import java.awt.event.MouseAdapter;24 23 import java.awt.event.MouseEvent; 25 24 import java.awt.event.WindowAdapter; … … 47 46 import javax.swing.JScrollPane; 48 47 import javax.swing.JToggleButton; 48 import javax.swing.SwingUtilities; 49 49 50 50 import org.openstreetmap.josm.Main; … … 61 61 import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 62 62 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 63 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 63 64 import org.openstreetmap.josm.tools.Destroyable; 64 65 import org.openstreetmap.josm.tools.GBC; … … 477 478 add(lblTitle_weak, GBC.std().fill(GBC.HORIZONTAL)); 478 479 479 addMouseListener( 480 new MouseAdapter() { 481 @Override 482 public void mouseClicked(MouseEvent e) { 483 if (isCollapsed) { 484 expand(); 485 dialogsPanel.reconstruct(Action.COLLAPSED_TO_DEFAULT, ToggleDialog.this); 486 } else { 487 collapse(); 488 dialogsPanel.reconstruct(Action.ELEMENT_SHRINKS, null); 489 } 490 } 491 492 private void maybeShowPopup(MouseEvent e) { 493 if (e.isPopupTrigger()) { 494 JPopupMenu menu = new JPopupMenu(); 495 JMenu buttonHidingMenu = new JMenu(tr("Side buttons")); 496 JRadioButtonMenuItem alwaysShown = new JRadioButtonMenuItem(new AbstractAction(tr("Always shown")) { 497 @Override 498 public void actionPerformed(ActionEvent e) { 499 setIsButtonHiding(ButtonHiddingType.ALWAYS_SHOWN); 500 } 501 }); 502 JRadioButtonMenuItem dynamic = new JRadioButtonMenuItem(new AbstractAction(tr("Dynamic")) { 503 @Override 504 public void actionPerformed(ActionEvent e) { 505 setIsButtonHiding(ButtonHiddingType.DYNAMIC); 506 } 507 }); 508 JRadioButtonMenuItem alwaysHidden = new JRadioButtonMenuItem(new AbstractAction(tr("Always hidden")) { 509 @Override 510 public void actionPerformed(ActionEvent e) { 511 setIsButtonHiding(ButtonHiddingType.ALWAYS_HIDDEN); 512 } 513 }); 514 alwaysShown.setSelected(buttonHiding == ButtonHiddingType.ALWAYS_SHOWN); 515 dynamic.setSelected(buttonHiding == ButtonHiddingType.DYNAMIC); 516 alwaysHidden.setSelected(buttonHiding == ButtonHiddingType.ALWAYS_HIDDEN); 517 buttonHidingMenu.add(alwaysShown); 518 buttonHidingMenu.add(dynamic); 519 buttonHidingMenu.add(alwaysHidden); 520 menu.add(buttonHidingMenu); 521 for (javax.swing.Action action: buttonActions) { 522 menu.add(action); 523 } 524 menu.show(TitleBar.this, e.getX(), e.getY()); 525 } 526 } 527 528 @Override 529 public void mousePressed(MouseEvent e) { 530 maybeShowPopup(e); 531 } 532 533 @Override 534 public void mouseReleased(MouseEvent e) { 535 maybeShowPopup(e); 536 } 537 } 538 ); 480 addMouseListener(new MouseEventHandler()); 539 481 540 482 if(Main.pref.getBoolean("dialog.dynamic.buttons", true)) { … … 616 558 return lblTitle.getText(); 617 559 } 560 561 public class DialogPopupMenu extends JPopupMenu { 562 public final JMenu buttonHidingMenu = new JMenu(tr("Side buttons")); 563 public final JRadioButtonMenuItem alwaysShown = new JRadioButtonMenuItem(new AbstractAction(tr("Always shown")) { 564 @Override public void actionPerformed(ActionEvent e) { 565 setIsButtonHiding(ButtonHiddingType.ALWAYS_SHOWN); 566 } 567 }); 568 public final JRadioButtonMenuItem dynamic = new JRadioButtonMenuItem(new AbstractAction(tr("Dynamic")) { 569 @Override public void actionPerformed(ActionEvent e) { 570 setIsButtonHiding(ButtonHiddingType.DYNAMIC); 571 } 572 }); 573 public final JRadioButtonMenuItem alwaysHidden = new JRadioButtonMenuItem(new AbstractAction(tr("Always hidden")) { 574 @Override public void actionPerformed(ActionEvent e) { 575 setIsButtonHiding(ButtonHiddingType.ALWAYS_HIDDEN); 576 } 577 }); 578 public DialogPopupMenu() { 579 alwaysShown.setSelected(buttonHiding == ButtonHiddingType.ALWAYS_SHOWN); 580 dynamic.setSelected(buttonHiding == ButtonHiddingType.DYNAMIC); 581 alwaysHidden.setSelected(buttonHiding == ButtonHiddingType.ALWAYS_HIDDEN); 582 buttonHidingMenu.add(alwaysShown); 583 buttonHidingMenu.add(dynamic); 584 buttonHidingMenu.add(alwaysHidden); 585 add(buttonHidingMenu); 586 for (javax.swing.Action action: buttonActions) { 587 add(action); 588 } 589 } 590 } 591 592 class MouseEventHandler extends PopupMenuLauncher { 593 public MouseEventHandler() { 594 super(new DialogPopupMenu()); 595 } 596 @Override public void mouseClicked(MouseEvent e) { 597 if (SwingUtilities.isLeftMouseButton(e)) { 598 if (isCollapsed) { 599 expand(); 600 dialogsPanel.reconstruct(Action.COLLAPSED_TO_DEFAULT, ToggleDialog.this); 601 } else { 602 collapse(); 603 dialogsPanel.reconstruct(Action.ELEMENT_SHRINKS, null); 604 } 605 } 606 } 607 } 618 608 } 619 609 -
trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
r5673 r5958 5 5 6 6 import java.awt.event.ActionEvent; 7 import java.awt.event.ActionListener;8 7 import java.awt.event.KeyEvent; 9 import java.awt.event.MouseAdapter;10 8 import java.awt.event.MouseEvent; 11 9 import java.io.IOException; … … 21 19 import javax.swing.AbstractAction; 22 20 import javax.swing.JComponent; 23 import javax.swing.JMenuItem;24 21 import javax.swing.JOptionPane; 25 22 import javax.swing.JPopupMenu; … … 45 42 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 46 43 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 44 import org.openstreetmap.josm.gui.PopupMenuHandler; 47 45 import org.openstreetmap.josm.gui.SideButton; 48 46 import org.openstreetmap.josm.gui.dialogs.validator.ValidatorTreePanel; … … 51 49 import org.openstreetmap.josm.gui.preferences.ValidatorPreference; 52 50 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 51 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 53 52 import org.openstreetmap.josm.io.OsmTransferException; 54 53 import org.openstreetmap.josm.tools.ImageProvider; … … 65 64 */ 66 65 public class ValidatorDialog extends ToggleDialog implements SelectionChangedListener, LayerChangeListener { 67 /** Serializable ID */68 private static final long serialVersionUID = 2952292777351992696L;69 66 70 67 /** The display tree */ … … 78 75 private SideButton selectButton; 79 76 80 private JPopupMenu popupMenu;81 private TestError popupMenuError = null;82 77 private final JPopupMenu popupMenu = new JPopupMenu(); 78 private final PopupMenuHandler popupMenuHandler = new PopupMenuHandler(popupMenu); 79 83 80 /** Last selected element */ 84 81 private DefaultMutableTreeNode lastSelectedNode = null; … … 94 91 KeyEvent.VK_V, Shortcut.ALT_SHIFT), 150, false, ValidatorPreference.class); 95 92 96 popupMenu = new JPopupMenu(); 97 98 JMenuItem zoomTo = new JMenuItem(tr("Zoom to problem")); 99 zoomTo.addActionListener(new ActionListener() { 100 @Override 101 public void actionPerformed(ActionEvent e) { 102 zoomToProblem(); 103 } 104 }); 105 popupMenu.add(zoomTo); 93 popupMenuHandler.addAction(Main.main.menu.autoScaleActions.get("problem")); 106 94 107 95 tree = new ValidatorTreePanel(); 108 tree.addMouseListener(new ClickWatch());109 tree.addTreeSelectionListener(new SelectionWatch());96 tree.addMouseListener(new MouseEventHandler()); 97 addTreeSelectionListener(new SelectionWatch()); 110 98 InputMapUtils.unassignCtrlShiftUpDown(tree, JComponent.WHEN_FOCUSED); 111 99 … … 317 305 } 318 306 319 private void showPopupMenu(MouseEvent e) {320 if (!e.isPopupTrigger())321 return;322 popupMenuError = null;323 TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());324 if (selPath == null)325 return;326 DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath.getPathComponent(selPath.getPathCount() - 1);327 if (!(node.getUserObject() instanceof TestError))328 return;329 popupMenuError = (TestError) node.getUserObject();330 popupMenu.show(e.getComponent(), e.getX(), e.getY());331 }332 333 private void zoomToProblem() {334 if (popupMenuError == null)335 return;336 ValidatorBoundingXYVisitor bbox = new ValidatorBoundingXYVisitor();337 bbox.visit(popupMenuError);338 if (bbox.getBounds() == null)339 return;340 bbox.enlargeBoundingBox(Main.pref.getDouble("validator.zoom-enlarge-bbox", 0.0002));341 Main.map.mapView.recalculateCenterScale(bbox);342 }343 344 307 /** 345 308 * Sets the selection of the map to the current selected items. … … 447 410 448 411 /** 449 * Watches for clicks. 450 */ 451 public class ClickWatch extends MouseAdapter { 412 * Add a tree selection listener to the validator tree. 413 * @param listener the TreeSelectionListener 414 * @since 5958 415 */ 416 public void addTreeSelectionListener(TreeSelectionListener listener) { 417 tree.addTreeSelectionListener(listener); 418 } 419 420 /** 421 * Remove the given tree selection listener from the validator tree. 422 * @param listener the TreeSelectionListener 423 * @since 5958 424 */ 425 public void removeTreeSelectionListener(TreeSelectionListener listener) { 426 tree.removeTreeSelectionListener(listener); 427 } 428 429 /** 430 * Replies the popup menu handler. 431 * @return The popup menu handler 432 * @since 5958 433 */ 434 public PopupMenuHandler getPopupMenuHandler() { 435 return popupMenuHandler; 436 } 437 438 /** 439 * Replies the currently selected error, or {@code null}. 440 * @return The selected error, if any. 441 * @since 5958 442 */ 443 public TestError getSelectedError() { 444 Object comp = tree.getLastSelectedPathComponent(); 445 if (comp instanceof DefaultMutableTreeNode) { 446 Object object = ((DefaultMutableTreeNode)comp).getUserObject(); 447 if (object instanceof TestError) { 448 return (TestError) object; 449 } 450 } 451 return null; 452 } 453 454 /** 455 * Watches for double clicks and launches the popup menu. 456 */ 457 class MouseEventHandler extends PopupMenuLauncher { 458 459 public MouseEventHandler() { 460 super(popupMenu); 461 } 462 452 463 @Override 453 464 public void mouseClicked(MouseEvent e) { … … 458 469 selectButton.setEnabled(false); 459 470 460 boolean isDblClick = e.getClickCount() > 1;471 boolean isDblClick = isDoubleClick(e); 461 472 462 473 Collection<OsmPrimitive> sel = isDblClick ? new HashSet<OsmPrimitive>(40) : null; … … 467 478 if (isDblClick) { 468 479 Main.main.getCurrentDataSet().setSelected(sel); 469 if (Main.pref.getBoolean("validator.autozoom", false)) {480 if (Main.pref.getBoolean("validator.autozoom", false)) { 470 481 AutoScaleAction.zoomTo(sel); 471 482 } 472 483 } 473 484 } 474 475 @Override 476 public void mousePressed(MouseEvent e) {477 showPopupMenu(e);478 }479 480 @Override481 public void mouseReleased(MouseEvent e) {482 s howPopupMenu(e);485 486 @Override public void launch(MouseEvent e) { 487 TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); 488 if (selPath == null) 489 return; 490 DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath.getPathComponent(selPath.getPathCount() - 1); 491 if (!(node.getUserObject() instanceof TestError)) 492 return; 493 super.launch(e); 483 494 } 484 495 -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java
r5903 r5958 10 10 import java.awt.event.ActionEvent; 11 11 import java.awt.event.KeyEvent; 12 import java.awt.event.MouseAdapter;13 12 import java.awt.event.MouseEvent; 14 13 import java.awt.event.WindowAdapter; … … 33 32 import javax.swing.KeyStroke; 34 33 import javax.swing.ListSelectionModel; 35 import javax.swing.SwingUtilities;36 34 import javax.swing.event.ListSelectionEvent; 37 35 import javax.swing.event.ListSelectionListener; … … 249 247 model.getSelectionModel() 250 248 ); 251 tblChangesets.addMouseListener(new ChangesetTablePopupMenuLauncher()); 252 tblChangesets.addMouseListener(new DblClickHandler()); 249 tblChangesets.addMouseListener(new MouseEventHandler()); 253 250 tblChangesets.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "showDetails"); 254 251 tblChangesets.getActionMap().put("showDetails", new ShowDetailAction()); … … 559 556 } 560 557 561 class DblClickHandler extends MouseAdapter { 558 class MouseEventHandler extends PopupMenuLauncher { 559 560 public MouseEventHandler() { 561 super(new ChangesetTablePopupMenu()); 562 } 563 562 564 @Override 563 565 public void mouseClicked(MouseEvent evt) { 564 if (! SwingUtilities.isLeftMouseButton(evt) || evt.getClickCount()<2) 565 return; 566 new ShowDetailAction().showDetails(); 567 } 568 } 569 570 class ChangesetTablePopupMenuLauncher extends PopupMenuLauncher { 571 ChangesetTablePopupMenu menu = new ChangesetTablePopupMenu(); 572 @Override 573 public void launch(MouseEvent evt) { 574 if (! model.hasSelectedChangesets()) { 575 int row = tblChangesets.rowAtPoint(evt.getPoint()); 576 if (row >= 0) { 577 model.setSelectedByIdx(row); 578 } 579 } 580 menu.show(tblChangesets, evt.getPoint().x, evt.getPoint().y); 566 if (isDoubleClick(evt)) { 567 new ShowDetailAction().showDetails(); 568 } 581 569 } 582 570 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManagerModel.java
r5890 r5958 19 19 import org.openstreetmap.josm.data.osm.ChangesetCacheEvent; 20 20 import org.openstreetmap.josm.data.osm.ChangesetCacheListener; 21 import org.openstreetmap.josm.gui.util.GuiHelper; 21 22 22 23 /** … … 104 105 */ 105 106 public void setSelectedChangesets(Collection<Changeset> selected) { 106 selectionModel.clearSelection(); 107 GuiHelper.runInEDTAndWait(new Runnable() { 108 @Override public void run() { 109 selectionModel.clearSelection(); 110 } 111 }); 107 112 if (selected == null || selected.isEmpty()) 108 113 return; 109 114 for (Changeset cs: selected) { 110 int idx = data.indexOf(cs);115 final int idx = data.indexOf(cs); 111 116 if (idx >= 0) { 112 selectionModel.addSelectionInterval(idx,idx); 117 GuiHelper.runInEDTAndWait(new Runnable() { 118 @Override public void run() { 119 selectionModel.addSelectionInterval(idx,idx); 120 } 121 }); 113 122 } 114 123 } 115 }116 117 /**118 * Selects the changeset displayed at row <code>row</code>119 *120 * @param row the row. Ignored if < 0 or >= {@link #getRowCount()}121 */122 public void setSelectedByIdx(int row) {123 if (row < 0 || row >= getRowCount()) return;124 selectionModel.setSelectionInterval(row, row);125 124 } 126 125 -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java
r5495 r5958 10 10 import java.awt.event.ComponentAdapter; 11 11 import java.awt.event.ComponentEvent; 12 import java.awt.event.MouseAdapter;13 import java.awt.event.MouseEvent;14 12 import java.beans.PropertyChangeEvent; 15 13 import java.beans.PropertyChangeListener; … … 31 29 import javax.swing.JTable; 32 30 import javax.swing.JToolBar; 33 import javax.swing.SwingUtilities;34 31 import javax.swing.event.ListSelectionEvent; 35 32 import javax.swing.event.ListSelectionListener; … … 50 47 import org.openstreetmap.josm.gui.history.HistoryLoadTask; 51 48 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 49 import org.openstreetmap.josm.gui.util.GuiHelper; 50 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 52 51 import org.openstreetmap.josm.tools.BugReportExceptionHandler; 53 52 import org.openstreetmap.josm.tools.ImageProvider; … … 109 108 model.getSelectionModel() 110 109 ); 111 tblContent.addMouseListener(new ChangesetContentTablePopupMenuLauncher());110 tblContent.addMouseListener(new PopupMenuLauncher(new ChangesetContentTablePopupMenu())); 112 111 pnl.add(new JScrollPane(tblContent), BorderLayout.CENTER); 113 112 return pnl; … … 139 138 } 140 139 140 /** 141 * Constructs a new {@code ChangesetContentPanel}. 142 */ 141 143 public ChangesetContentPanel() { 142 144 build(); 143 145 } 144 146 147 /** 148 * Replies the changeset content model 149 * @return The model 150 */ 145 151 public ChangesetContentTableModel getModel() { 146 152 return model; … … 204 210 } 205 211 206 class ChangesetContentTablePopupMenuLauncher extends MouseAdapter {207 ChangesetContentTablePopupMenu menu = new ChangesetContentTablePopupMenu();208 209 protected void launch(MouseEvent evt) {210 if (! evt.isPopupTrigger()) return;211 if (! model.hasSelectedPrimitives()) {212 int row = tblContent.rowAtPoint(evt.getPoint());213 if (row >= 0) {214 model.setSelectedByIdx(row);215 }216 }217 menu.show(tblContent, evt.getPoint().x, evt.getPoint().y);218 }219 220 @Override221 public void mouseClicked(MouseEvent evt) {222 launch(evt);223 }224 225 @Override226 public void mousePressed(MouseEvent evt) {227 launch(evt);228 }229 230 @Override231 public void mouseReleased(MouseEvent evt) {232 launch(evt);233 }234 }235 236 212 class ChangesetContentTablePopupMenu extends JPopupMenu { 237 213 public ChangesetContentTablePopupMenu() { … … 277 253 try { 278 254 for (HistoryOsmPrimitive p : primitives) { 279 History h = HistoryDataSet.getInstance().getHistory(p.getPrimitiveId());255 final History h = HistoryDataSet.getInstance().getHistory(p.getPrimitiveId()); 280 256 if (h == null) { 281 257 continue; 282 258 } 283 HistoryBrowserDialogManager.getInstance().show(h); 259 GuiHelper.runInEDT(new Runnable() { 260 @Override public void run() { 261 HistoryBrowserDialogManager.getInstance().show(h); 262 } 263 }); 284 264 } 285 265 } catch (final Exception e) { 286 SwingUtilities.invokeLater(new Runnable() {266 GuiHelper.runInEDT(new Runnable() { 287 267 public void run() { 288 268 BugReportExceptionHandler.handleException(e); -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r5854 r5958 395 395 membershipMenu.add(helpAction); 396 396 397 membershipTable.addMouseListener(new PopupMenuLauncher( ) {397 membershipTable.addMouseListener(new PopupMenuLauncher(membershipMenu) { 398 398 @Override 399 public void launch(MouseEvent evt) { 400 Point p = evt.getPoint(); 401 int row = membershipTable.rowAtPoint(p); 402 int idx[] = membershipTable.getSelectedRows(); 403 // if nothing or one row is selected, select row under mouse instead 404 if (idx.length<2 && row>-1) { 405 membershipTable.changeSelection(row, 0, false, false); 406 idx = new int[]{row}; 407 } 399 protected int checkTableSelection(JTable table, Point p) { 400 int row = super.checkTableSelection(table, p); 408 401 List<Relation> rels = new ArrayList<Relation>(); 409 for (int i: idx) { 410 Relation r = (Relation) (membershipData.getValueAt(i, 0)); 411 rels.add(r); 402 for (int i: table.getSelectedRows()) { 403 rels.add((Relation) table.getValueAt(i, 0)); 412 404 } 413 405 membershipMenuHandler.setPrimitives(rels); 414 membershipMenu.show(membershipTable, p.x, p.y-3);406 return row; 415 407 } 416 408 }); … … 430 422 propertyMenu.addSeparator(); 431 423 propertyMenu.add(helpAction); 432 propertyTable.addMouseListener(new PopupMenuLauncher() { 433 @Override 434 public void launch(MouseEvent evt) { 435 Point p = evt.getPoint(); 436 int row = propertyTable.rowAtPoint(p); 437 int selectedCount = propertyTable.getSelectedRowCount(); 438 // if nothing or one row is selected, select row under mouse instead 439 if (selectedCount<2 && row>-1) { 440 propertyTable.changeSelection(row, 0, false, false); 441 } 442 if (selectedCount>=2 || row>-1) { 443 propertyMenu.show(propertyTable, p.x, p.y-3); 444 } 445 } 446 }); 424 propertyTable.addMouseListener(new PopupMenuLauncher(propertyMenu)); 447 425 } 448 426 -
trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java
r5886 r5958 7 7 import java.awt.Dimension; 8 8 import java.awt.GridBagLayout; 9 import java.awt.Toolkit;10 import java.awt.datatransfer.FlavorEvent;11 import java.awt.datatransfer.FlavorListener;12 9 import java.awt.event.ActionEvent; 13 10 import java.awt.event.ActionListener; … … 17 14 import java.awt.event.MouseEvent; 18 15 19 import javax.swing.AbstractAction;20 16 import javax.swing.BorderFactory; 21 17 import javax.swing.JButton; 22 18 import javax.swing.JLabel; 23 19 import javax.swing.JPanel; 24 import javax.swing.JPopupMenu;25 20 import javax.swing.UIManager; 26 21 import javax.swing.border.Border; … … 35 30 import org.openstreetmap.josm.gui.widgets.JosmTextField; 36 31 import org.openstreetmap.josm.tools.GBC; 37 import org.openstreetmap.josm.tools.ImageProvider;38 32 import org.openstreetmap.josm.tools.OsmUrlToBounds; 39 import org.openstreetmap.josm.tools.Utils;40 33 41 34 /** … … 121 114 dlg.add(new JLabel(tr("URL from www.openstreetmap.org (you can paste an URL here to download the area)")), GBC.eol().insets(10,5,5,0)); 122 115 dlg.add(tfOsmUrl, GBC.eop().insets(10,0,5,0).fill()); 123 tfOsmUrl.addMouseListener(124 new MouseAdapter() {125 @Override126 public void mousePressed(MouseEvent e) {127 checkPopup(e);128 }129 130 @Override131 public void mouseClicked(MouseEvent e) {132 checkPopup(e);133 }134 135 @Override136 public void mouseReleased(MouseEvent e) {137 checkPopup(e);138 }139 140 private void checkPopup(MouseEvent e) {141 if (e.isPopupTrigger()) {142 OsmUrlPopup popup = new OsmUrlPopup();143 popup.show(tfOsmUrl, e.getX(), e.getY());144 }145 }146 }147 );148 116 dlg.add(showUrl, GBC.eop().insets(10,0,5,5)); 149 117 showUrl.setEditable(false); … … 299 267 } 300 268 301 class PasteUrlAction extends AbstractAction implements FlavorListener {302 303 public PasteUrlAction() {304 putValue(NAME, tr("Paste"));305 putValue(SMALL_ICON, ImageProvider.get("paste"));306 putValue(SHORT_DESCRIPTION, tr("Paste URL from clipboard"));307 Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(this);308 }309 310 public void actionPerformed(ActionEvent e) {311 String content = Utils.getClipboardContent();312 if (content != null) {313 tfOsmUrl.setText(content);314 }315 }316 317 protected void updateEnabledState() {318 setEnabled(Utils.getClipboardContent() != null);319 }320 321 public void flavorsChanged(FlavorEvent e) {322 updateEnabledState();323 }324 }325 326 class OsmUrlPopup extends JPopupMenu {327 public OsmUrlPopup() {328 add(new PasteUrlAction());329 }330 }331 332 269 class BoundingBoxBuilder extends FocusAdapter implements ActionListener { 333 270 protected Bounds build() { -
trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java
r5266 r5958 29 29 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; 30 30 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 31 import org.openstreetmap.josm.gui.util.GuiHelper; 32 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 31 33 import org.openstreetmap.josm.tools.ImageProvider; 32 34 … … 66 68 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 67 69 selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel()); 68 table.addMouseListener(new PopupMenuLauncher(table));70 table.addMouseListener(new InternalPopupMenuLauncher()); 69 71 table.addMouseListener(new DoubleClickAdapter(table)); 70 72 return table; … … 79 81 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 80 82 selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel()); 81 table.addMouseListener(new PopupMenuLauncher(table));83 table.addMouseListener(new InternalPopupMenuLauncher()); 82 84 table.addMouseListener(new DoubleClickAdapter(table)); 83 85 return table; … … 115 117 selectionSynchronizer = new SelectionSynchronizer(); 116 118 119 popupMenu = new NodeListPopupMenu(); 120 117 121 // --------------------------- 118 122 gc.gridx = 0; … … 135 139 gc.anchor = GridBagConstraints.NORTHWEST; 136 140 add(embeddInScrollPane(buildCurrentNodeListTable()),gc); 137 138 popupMenu = new NodeListPopupMenu();139 141 } 140 142 … … 172 174 173 175 static class NodeListPopupMenu extends JPopupMenu { 174 private ZoomToNodeAction zoomToNodeAction;175 private ShowHistoryAction showHistoryAction;176 private final ZoomToNodeAction zoomToNodeAction; 177 private final ShowHistoryAction showHistoryAction; 176 178 177 179 public NodeListPopupMenu() { … … 262 264 Runnable r = new Runnable() { 263 265 public void run() { 264 History h = HistoryDataSet.getInstance().getHistory(primitiveId);266 final History h = HistoryDataSet.getInstance().getHistory(primitiveId); 265 267 if (h == null) 266 268 return; 267 HistoryBrowserDialogManager.getInstance().show(h); 269 GuiHelper.runInEDT(new Runnable() { 270 @Override public void run() { 271 HistoryBrowserDialogManager.getInstance().show(h); 272 } 273 }); 268 274 } 269 275 }; … … 283 289 } 284 290 285 class PopupMenuLauncher extends MouseAdapter { 286 private JTable table; 287 288 public PopupMenuLauncher(JTable table) { 289 this.table = table; 290 } 291 292 @Override 293 public void mousePressed(MouseEvent e) { 294 showPopup(e); 295 } 296 297 @Override 298 public void mouseReleased(MouseEvent e) { 299 showPopup(e); 300 } 301 302 private void showPopup(MouseEvent e) { 303 if (!e.isPopupTrigger()) return; 304 Point p = e.getPoint(); 305 int row = table.rowAtPoint(p); 306 307 PrimitiveId pid = primitiveIdAtRow(table.getModel(), row); 308 if (pid == null) 309 return; 310 popupMenu.prepare(pid); 311 popupMenu.show(e.getComponent(), e.getX(), e.getY()); 291 class InternalPopupMenuLauncher extends PopupMenuLauncher { 292 public InternalPopupMenuLauncher() { 293 super(popupMenu); 294 } 295 296 @Override protected int checkTableSelection(JTable table, Point p) { 297 int row = super.checkTableSelection(table, p); 298 popupMenu.prepare(primitiveIdAtRow(table.getModel(), row)); 299 return row; 312 300 } 313 301 } -
trunk/src/org/openstreetmap/josm/gui/history/VersionTable.java
r5622 r5958 6 6 import java.awt.Component; 7 7 import java.awt.Dimension; 8 import java.awt.Point; 8 9 import java.awt.Rectangle; 9 10 import java.awt.event.ActionEvent; 10 11 import java.awt.event.ItemEvent; 11 12 import java.awt.event.ItemListener; 12 import java.awt.event.MouseAdapter;13 13 import java.awt.event.MouseEvent; 14 14 import java.util.Observable; … … 30 30 import org.openstreetmap.josm.actions.AbstractInfoAction; 31 31 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 32 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 32 33 import org.openstreetmap.josm.tools.ImageProvider; 33 34 … … 85 86 } 86 87 87 protected void showPopupMenu(MouseEvent evt) { 88 HistoryBrowserModel.VersionTableModel model = getVersionTableModel(); 89 int row = rowAtPoint(evt.getPoint()); 90 if (row > -1 && !model.isLatest(row)) { 91 HistoryOsmPrimitive primitive = model.getPrimitive(row); 92 popupMenu.prepare(primitive); 93 popupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); 94 } 95 } 96 97 class MouseListener extends MouseAdapter { 88 class MouseListener extends PopupMenuLauncher { 89 public MouseListener() { 90 super(popupMenu); 91 } 98 92 @Override 99 93 public void mousePressed(MouseEvent e) { 100 if (!showPopup(e) && e.getButton() == MouseEvent.BUTTON1) { 94 super.mousePressed(e); 95 if (!e.isPopupTrigger() && e.getButton() == MouseEvent.BUTTON1) { 101 96 int row = rowAtPoint(e.getPoint()); 102 97 int col = columnAtPoint(e.getPoint()); … … 108 103 } 109 104 @Override 110 public void mouseReleased(MouseEvent e) { 111 showPopup(e); 112 } 113 private boolean showPopup(MouseEvent e) { 114 if (e.isPopupTrigger()) { 115 showPopupMenu(e); 116 return true; 105 protected int checkTableSelection(JTable table, Point p) { 106 HistoryBrowserModel.VersionTableModel model = getVersionTableModel(); 107 int row = rowAtPoint(p); 108 if (row > -1 && !model.isLatest(row)) { 109 popupMenu.prepare(model.getPrimitive(row)); 117 110 } 118 return false;111 return row; 119 112 } 120 113 } -
trunk/src/org/openstreetmap/josm/gui/widgets/BoundingBoxSelectionPanel.java
r5886 r5958 8 8 import java.awt.GridBagLayout; 9 9 import java.awt.Insets; 10 import java.awt.Toolkit; 11 import java.awt.datatransfer.FlavorEvent; 12 import java.awt.datatransfer.FlavorListener; 13 import java.awt.event.ActionEvent; 14 import java.awt.event.MouseEvent; 15 16 import javax.swing.AbstractAction; 10 17 11 import javax.swing.BorderFactory; 18 12 import javax.swing.JLabel; 19 13 import javax.swing.JPanel; 20 import javax.swing.JPopupMenu;21 14 import javax.swing.event.DocumentEvent; 22 15 import javax.swing.event.DocumentListener; … … 28 21 import org.openstreetmap.josm.gui.JMultilineLabel; 29 22 import org.openstreetmap.josm.tools.GBC; 30 import org.openstreetmap.josm.tools.ImageProvider;31 23 import org.openstreetmap.josm.tools.OsmUrlToBounds; 32 import org.openstreetmap.josm.tools.Utils;33 import org.openstreetmap.josm.gui.widgets.JosmTextField;34 24 35 25 /** … … 87 77 gc.insets = new Insets(3,0,0,3); 88 78 add(tfOsmUrl, gc); 89 tfOsmUrl.addMouseListener(new PopupMenuLauncher() {90 @Override91 public void launch(MouseEvent e) {92 OsmUrlPopup popup = new OsmUrlPopup();93 popup.show(tfOsmUrl, e.getX(), e.getY());94 }95 });96 79 } 97 80 … … 224 207 public void removeUpdate(DocumentEvent e) { parseURL(); } 225 208 } 226 227 class PasteUrlAction extends AbstractAction implements FlavorListener {228 229 public PasteUrlAction() {230 putValue(NAME, tr("Paste"));231 putValue(SMALL_ICON, ImageProvider.get("paste"));232 putValue(SHORT_DESCRIPTION, tr("Paste URL from clipboard"));233 Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(this);234 }235 236 public void actionPerformed(ActionEvent e) {237 String content = Utils.getClipboardContent();238 if (content != null) {239 tfOsmUrl.setText(content);240 }241 }242 243 protected void updateEnabledState() {244 setEnabled(Utils.getClipboardContent() != null);245 }246 247 public void flavorsChanged(FlavorEvent e) {248 updateEnabledState();249 }250 }251 252 class OsmUrlPopup extends JPopupMenu {253 public OsmUrlPopup() {254 add(new PasteUrlAction());255 }256 }257 209 } -
trunk/src/org/openstreetmap/josm/gui/widgets/OsmPrimitivesTable.java
r5310 r5958 37 37 public OsmPrimitivesTable(OsmPrimitivesTableModel dm, TableColumnModel cm, ListSelectionModel sm) { 38 38 super(dm, cm, sm); 39 addMouseListener(new Popup Listener());39 addMouseListener(new PopupMenuLauncher(getPopUpMenu())); 40 40 addMouseListener(new DblClickHandler()); 41 41 } … … 76 76 } 77 77 78 protected class PopupListener extends MouseAdapter {79 @Override80 public void mousePressed(MouseEvent e) {81 showPopup(e);82 }83 84 @Override85 public void mouseReleased(MouseEvent e) {86 showPopup(e);87 }88 89 private void showPopup(MouseEvent e) {90 if (e.isPopupTrigger()) {91 getPopUpMenu().show(e.getComponent(), e.getX(), e.getY());92 }93 }94 }95 96 78 protected class DblClickHandler extends MouseAdapter { 97 79 -
trunk/src/org/openstreetmap/josm/gui/widgets/PopupMenuLauncher.java
r5887 r5958 3 3 4 4 import java.awt.Component; 5 import java.awt.Point; 5 6 import java.awt.event.FocusEvent; 6 7 import java.awt.event.FocusListener; … … 8 9 import java.awt.event.MouseEvent; 9 10 11 import javax.swing.JList; 10 12 import javax.swing.JPopupMenu; 13 import javax.swing.JTable; 14 import javax.swing.JTree; 15 import javax.swing.SwingUtilities; 16 import javax.swing.tree.TreePath; 11 17 12 18 /** … … 15 21 */ 16 22 public class PopupMenuLauncher extends MouseAdapter { 17 pr ivate finalJPopupMenu menu;23 protected JPopupMenu menu; 18 24 private final boolean checkEnabled; 19 25 … … 47 53 48 54 @Override public void mousePressed(MouseEvent e) { processEvent(e); } 49 @Override public void mouseClicked(MouseEvent e) { processEvent(e);}55 @Override public void mouseClicked(MouseEvent e) {} 50 56 @Override public void mouseReleased(MouseEvent e) { processEvent(e); } 51 57 … … 62 68 */ 63 69 public void launch(final MouseEvent evt) { 64 if ( menu!= null) {70 if (evt != null) { 65 71 final Component component = evt.getComponent(); 66 if (component != null && component.isFocusable() && !component.hasFocus() && component.requestFocusInWindow()) { 67 component.addFocusListener(new FocusListener() { 68 @Override public void focusLost(FocusEvent e) {} 69 @Override public void focusGained(FocusEvent e) { 70 menu.show(component, evt.getX(), evt.getY()); 71 component.removeFocusListener(this); 72 } 73 }); 74 } else { 75 menu.show(component, evt.getX(), evt.getY()); 72 if (checkSelection(component, evt.getPoint())) { 73 checkFocusAndShowMenu(component, evt); 76 74 } 77 75 } 76 } 77 78 protected boolean checkSelection(Component component, Point p) { 79 if (component instanceof JList) { 80 return checkListSelection((JList) component, p) > -1; 81 } else if (component instanceof JTable) { 82 return checkTableSelection((JTable) component, p) > -1; 83 } else if (component instanceof JTree) { 84 return checkTreeSelection((JTree) component, p) != null; 85 } 86 return true; 87 } 88 89 protected void checkFocusAndShowMenu(final Component component, final MouseEvent evt) { 90 if (component != null && component.isFocusable() && !component.hasFocus() && component.requestFocusInWindow()) { 91 component.addFocusListener(new FocusListener() { 92 @Override public void focusLost(FocusEvent e) {} 93 @Override public void focusGained(FocusEvent e) { 94 showMenu(evt); 95 component.removeFocusListener(this); 96 } 97 }); 98 } else { 99 showMenu(evt); 100 } 101 } 102 103 protected void showMenu(MouseEvent evt) { 104 if (menu != null && evt != null) { 105 menu.show(evt.getComponent(), evt.getX(), evt.getY()); 106 } 107 } 108 109 protected int checkListSelection(JList list, Point p) { 110 int idx = list.locationToIndex(p); 111 if (idx >= 0 && idx < list.getModel().getSize() && list.getSelectedIndices().length < 2 && !list.isSelectedIndex(idx)) { 112 list.setSelectedIndex(idx); 113 } 114 return idx; 115 } 116 117 protected int checkTableSelection(JTable table, Point p) { 118 int row = table.rowAtPoint(p); 119 if (row >= 0 && row < table.getRowCount() && table.getSelectedRowCount() < 2 && table.getSelectedRow() != row) { 120 table.getSelectionModel().setSelectionInterval(row, row); 121 } 122 return row; 123 } 124 125 protected TreePath checkTreeSelection(JTree tree, Point p) { 126 TreePath path = tree.getPathForLocation(p.x, p.y); 127 if (path != null && tree.getSelectionCount() < 2 && !tree.isPathSelected(path)) { 128 tree.setSelectionPath(path); 129 } 130 return path; 131 } 132 133 protected static boolean isDoubleClick(MouseEvent e) { 134 return e != null && SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2; 78 135 } 79 136
Note:
See TracChangeset
for help on using the changeset viewer.