Changeset 5965 in josm
- Timestamp:
- 2013-05-17T20:45:17+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JumpToAction.java
r5886 r5965 26 26 import org.openstreetmap.josm.gui.widgets.JosmTextField; 27 27 28 public class JumpToAction extends JosmAction implements MouseListener{28 public class JumpToAction extends JosmAction { 29 29 /** 30 30 * Constructs a new {@code JumpToAction}. … … 67 67 68 68 class osmURLListener implements DocumentListener { 69 public void changedUpdate(DocumentEvent e) { parseURL(); }70 public void insertUpdate(DocumentEvent e) { parseURL(); }71 public void removeUpdate(DocumentEvent e) { parseURL(); }69 @Override public void changedUpdate(DocumentEvent e) { parseURL(); } 70 @Override public void insertUpdate(DocumentEvent e) { parseURL(); } 71 @Override public void removeUpdate(DocumentEvent e) { parseURL(); } 72 72 } 73 73 74 74 class osmLonLatListener implements DocumentListener { 75 public void changedUpdate(DocumentEvent e) { updateUrl(false); }76 public void insertUpdate(DocumentEvent e) { updateUrl(false); }77 public void removeUpdate(DocumentEvent e) { updateUrl(false); }75 @Override public void changedUpdate(DocumentEvent e) { updateUrl(false); } 76 @Override public void insertUpdate(DocumentEvent e) { updateUrl(false); } 77 @Override public void removeUpdate(DocumentEvent e) { updateUrl(false); } 78 78 } 79 79 … … 172 172 showJumpToDialog(); 173 173 } 174 175 public void mousePressed(MouseEvent e) {}176 177 public void mouseReleased(MouseEvent e) {}178 179 public void mouseEntered(MouseEvent e) {}180 181 public void mouseExited(MouseEvent e) {}182 183 public void mouseClicked(MouseEvent e) {184 showJumpToDialog();185 }186 174 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r5922 r5965 1724 1724 add(repeatedCb); 1725 1725 add(helperCb); 1726 add(projectionCb); ;1726 add(projectionCb); 1727 1727 add(new AbstractAction(tr("Disable")) { 1728 1728 @Override public void actionPerformed(ActionEvent e) { -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r5958 r5965 36 36 import org.openstreetmap.josm.actions.CreateMultipolygonAction; 37 37 import org.openstreetmap.josm.actions.DeleteAction; 38 import org.openstreetmap.josm.actions.DialogsToggleAction; 38 39 import org.openstreetmap.josm.actions.DistributeAction; 39 40 import org.openstreetmap.josm.actions.DownloadAction; … … 65 66 import org.openstreetmap.josm.actions.OpenLocationAction; 66 67 import org.openstreetmap.josm.actions.OrthogonalizeAction; 68 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo; 67 69 import org.openstreetmap.josm.actions.PasteAction; 68 70 import org.openstreetmap.josm.actions.PasteTagsAction; 71 import org.openstreetmap.josm.actions.PreferenceToggleAction; 69 72 import org.openstreetmap.josm.actions.PreferencesAction; 70 73 import org.openstreetmap.josm.actions.PurgeAction; … … 93 96 import org.openstreetmap.josm.actions.ZoomInAction; 94 97 import org.openstreetmap.josm.actions.ZoomOutAction; 95 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;96 import org.openstreetmap.josm.actions.PreferenceToggleAction;97 98 import org.openstreetmap.josm.actions.audio.AudioBackAction; 98 99 import org.openstreetmap.josm.actions.audio.AudioFasterAction; … … 233 234 234 235 public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction(); 236 public final DialogsToggleAction dialogsToggleAction = new DialogsToggleAction(); 235 237 public FullscreenToggleAction fullscreenToggleAction = null; 236 238 … … 519 521 fullscreenToggleAction.addButtonModel(fullscreen.getModel()); 520 522 } 523 524 // -- dialogs panel toggle action 525 final JCheckBoxMenuItem dialogsToggle = new JCheckBoxMenuItem(dialogsToggleAction); 526 dialogsToggle.setAccelerator(dialogsToggleAction.getShortcut().getKeyStroke()); 527 dialogsToggleAction.addButtonModel(dialogsToggle.getModel()); 528 viewMenu.add(dialogsToggle); 529 521 530 viewMenu.addSeparator(); 522 531 add(viewMenu, info); … … 627 636 } 628 637 638 @Override 629 639 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 630 640 refreshEnabled(); 631 641 } 632 642 643 @Override 633 644 public void layerAdded(Layer newLayer) { 634 645 refreshEnabled(); 635 646 } 636 647 648 @Override 637 649 public void layerRemoved(Layer oldLayer) { 638 650 refreshEnabled(); -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r5909 r5965 10 10 import java.awt.Font; 11 11 import java.awt.GridBagLayout; 12 import java.awt.KeyboardFocusManager; 12 13 import java.awt.Rectangle; 13 14 import java.awt.event.ActionEvent; … … 18 19 import java.util.Collection; 19 20 import java.util.HashMap; 21 import java.util.HashSet; 20 22 import java.util.List; 21 23 import java.util.Map; … … 37 39 import javax.swing.SwingUtilities; 38 40 import javax.swing.border.Border; 41 import javax.swing.event.PopupMenuEvent; 42 import javax.swing.event.PopupMenuListener; 39 43 import javax.swing.plaf.basic.BasicSplitPaneDivider; 40 44 import javax.swing.plaf.basic.BasicSplitPaneUI; … … 70 74 import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog; 71 75 import org.openstreetmap.josm.gui.layer.Layer; 72 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;73 76 import org.openstreetmap.josm.tools.Destroyable; 74 77 import org.openstreetmap.josm.tools.GBC; 78 75 79 76 80 /** … … 87 91 public MapMode mapMode; 88 92 93 /** 94 * The view control displayed. 95 */ 96 public final MapView mapView; 97 98 /** 99 * The toolbar with the action icons. To add new toggle dialog buttons, 100 * use addToggleDialog, to add a new map mode button use addMapMode. 101 */ 102 private JComponent sideToolBar = new JToolBar(JToolBar.VERTICAL); 103 private final ButtonGroup toolBarActionsGroup = new ButtonGroup(); 104 private final JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL); 105 private final JToolBar toolBarToggle = new JToolBar(JToolBar.VERTICAL); 106 107 private final List<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>(); 89 108 private final List<MapMode> mapModes = new ArrayList<MapMode>(); 90 /** 91 * The view control displayed. 92 */ 93 public final MapView mapView; 94 /** 95 * The toolbar with the action icons. To add new toggle dialog actions, use addToggleDialog 96 * instead of adding directly to this list. To add a new mode use addMapMode. 97 */ 98 private JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL); 99 private JToolBar toolBarToggle = new JToolBar(JToolBar.VERTICAL); 100 /** 101 * The status line below the map 102 */ 103 public MapStatus statusLine; 109 private final List<IconToggleButton> allDialogButtons = new ArrayList<IconToggleButton>(); 110 public final List<IconToggleButton> allMapModeButtons = new ArrayList<IconToggleButton>(); 111 112 private final ListAllButtonsAction listAllDialogsAction = new ListAllButtonsAction(allDialogButtons); 113 private final ListAllButtonsAction listAllMapModesAction = new ListAllButtonsAction(allMapModeButtons); 114 private final JButton listAllToggleDialogsButton = new JButton(listAllDialogsAction); 115 private final JButton listAllMapModesButton = new JButton(listAllMapModesAction); 116 { 117 listAllDialogsAction.setButton(listAllToggleDialogsButton); 118 listAllMapModesAction.setButton(listAllMapModesButton); 119 } 104 120 105 121 // Toggle dialogs … … 113 129 // Map modes 114 130 public final SelectAction mapModeSelect; 131 private final Map<Layer, MapMode> lastMapMode = new HashMap<Layer, MapMode>(); 115 132 private final MapMode mapModeDraw; 116 133 private final MapMode mapModeZoom; 117 134 118 135 /** 119 * The panel list of all toggle dialog icons. To add new toggle dialog actions, use addToggleDialog 120 * instead of adding directly to this list. 121 */ 122 private List<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>(); 136 * The status line below the map 137 */ 138 public MapStatus statusLine; 139 140 /** 141 * The split pane with the mapview (leftPanel) and toggle dialogs (dialogsPanel). 142 */ 143 private final JSplitPane splitPane; 123 144 private final JPanel leftPanel; 124 145 private final DialogsPanel dialogsPanel; 125 146 126 public final ButtonGroup toolGroup = new ButtonGroup();127 128 private List<IconToggleButton> allDialogButtons = new ArrayList<IconToggleButton>();129 private List<IconToggleButton> allMapModeButtons = new ArrayList<IconToggleButton>();130 131 private final ListAllButtonsAction listAllDialogsAction = new ListAllButtonsAction(allDialogButtons);132 private final ListAllButtonsAction listAllMapModesAction = new ListAllButtonsAction(allMapModeButtons);133 private final JButton listAllToggleDialogsButton = new JButton(listAllDialogsAction);134 private final JButton listAllMapModesButton = new JButton(listAllMapModesAction);135 {136 listAllDialogsAction.setButton(listAllToggleDialogsButton);137 listAllMapModesAction.setButton(listAllMapModesButton);138 }139 140 147 /** 141 148 * Default width of the toggle dialog area. 142 149 */ 143 150 public static final int DEF_TOGGLE_DLG_WIDTH = 330; 144 145 private final Map<Layer, MapMode> lastMapMode = new HashMap<Layer, MapMode>();146 151 147 152 /** … … 157 162 158 163 mapView = new MapView(contentPane, viewportData); 159 160 164 new FileDrop(mapView); 165 166 splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true); 161 167 162 168 leftPanel = new JPanel(); 163 169 leftPanel.setLayout(new GridBagLayout()); 164 165 170 leftPanel.add(mapView, GBC.std().fill()); 166 167 // toolbar 168 toolBarActions.setFloatable(false); 169 addMapMode(new IconToggleButton(mapModeSelect = new SelectAction(this))); 170 addMapMode(new IconToggleButton(new LassoModeAction(), true)); 171 addMapMode(new IconToggleButton(mapModeDraw = new DrawAction(this))); 172 addMapMode(new IconToggleButton(mapModeZoom = new ZoomAction(this))); 173 addMapMode(new IconToggleButton(new DeleteAction(this), true)); 174 addMapMode(new IconToggleButton(new ParallelWayAction(this), true)); 175 addMapMode(new IconToggleButton(new ExtrudeAction(this), true)); 176 addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(Main.map), true)); 177 178 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true); 179 180 JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true); 171 splitPane.setLeftComponent(leftPanel); 172 181 173 dialogsPanel = new DialogsPanel(splitPane); 182 splitPane.setLeftComponent(leftPanel);183 174 splitPane.setRightComponent(dialogsPanel); 184 175 … … 212 203 dialogsPanel.setLayout(new BoxLayout(dialogsPanel, BoxLayout.Y_AXIS)); 213 204 dialogsPanel.setPreferredSize(new Dimension(Main.pref.getInteger("toggleDialogs.width",DEF_TOGGLE_DLG_WIDTH), 0)); 214 215 205 dialogsPanel.setMinimumSize(new Dimension(24, 0)); 216 206 mapView.setMinimumSize(new Dimension(10,0)); 217 207 218 toolBarToggle.setFloatable(false); 208 // toolBarActions, map mode buttons 209 addMapMode(new IconToggleButton(mapModeSelect = new SelectAction(this))); 210 addMapMode(new IconToggleButton(new LassoModeAction(), true)); 211 addMapMode(new IconToggleButton(mapModeDraw = new DrawAction(this))); 212 addMapMode(new IconToggleButton(mapModeZoom = new ZoomAction(this))); 213 addMapMode(new IconToggleButton(new DeleteAction(this), true)); 214 addMapMode(new IconToggleButton(new ParallelWayAction(this), true)); 215 addMapMode(new IconToggleButton(new ExtrudeAction(this), true)); 216 addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(Main.map), true)); 217 toolBarActionsGroup.setSelected(allMapModeButtons.get(0).getModel(), true); 218 toolBarActions.setFloatable(false); 219 220 // toolBarToggles, toggle dialog buttons 219 221 LayerListDialog.createInstance(this); 220 222 addToggleDialog(LayerListDialog.getInstance()); … … 230 232 addToggleDialog(new ChangesetDialog(this), true); 231 233 addToggleDialog(new MapPaintDialog()); 234 toolBarToggle.setFloatable(false); 232 235 233 236 // status line below the map … … 261 264 * Delegates the call to all Destroyables within this component (e.g. MapModes) 262 265 */ 266 @Override 263 267 public void destroy() { 264 268 MapView.removeLayerChangeListener(this); … … 310 314 final IconToggleButton button = new IconToggleButton(dlg.getToggleAction(), isExpert); 311 315 button.setShowHideButtonListener(dlg); 312 addHideContextMenu(button);316 button.setInheritsPopupMenu(true); 313 317 dlg.setButton(button); 314 318 toolBarToggle.add(button); … … 325 329 326 330 public void addMapMode(IconToggleButton b) { 327 toolBarActions.add(b);328 toolGroup.add(b);329 allMapModeButtons.add(b);330 331 if (b.getAction() instanceof MapMode) { 331 332 mapModes.add((MapMode) b.getAction()); 332 333 } else 333 334 throw new IllegalArgumentException("MapMode action must be subclass of MapMode"); 334 addHideContextMenu(b); 335 allMapModeButtons.add(b); 336 toolBarActionsGroup.add(b); 337 toolBarActions.add(b); 335 338 b.applyButtonHiddenPreferences(); 339 b.setInheritsPopupMenu(true); 336 340 } 337 341 … … 392 396 public void fillPanel(Container panel) { 393 397 panel.add(this, BorderLayout.CENTER); 394 JToolBar jb = new JToolBar(JToolBar.VERTICAL); 395 jb.setFloatable(false); 398 399 /** 400 * sideToolBar: add map modes icons 401 */ 402 if(Main.pref.getBoolean("sidetoolbar.mapmodes.visible", true)) { 396 403 toolBarActions.setAlignmentX(0.5f); 397 jb.add(toolBarActions); 404 toolBarActions.setInheritsPopupMenu(true); 405 sideToolBar.add(toolBarActions); 398 406 listAllMapModesButton.setAlignmentX(0.5f); 399 407 listAllMapModesButton.setBorder(null); 400 408 listAllMapModesButton.setFont(listAllMapModesButton.getFont().deriveFont(Font.PLAIN)); 401 jb.add(listAllMapModesButton); 402 403 if(Main.pref.getBoolean("sidetoolbar.togglevisible", true)) { 404 jb.addSeparator(new Dimension(0,18)); 409 listAllMapModesButton.setInheritsPopupMenu(true); 410 sideToolBar.add(listAllMapModesButton); 411 } 412 413 /** 414 * sideToolBar: add toggle dialogs icons 415 */ 416 if(Main.pref.getBoolean("sidetoolbar.toggledialogs.visible", true)) { 417 ((JToolBar)sideToolBar).addSeparator(new Dimension(0,18)); 405 418 toolBarToggle.setAlignmentX(0.5f); 406 jb.add(toolBarToggle); 419 toolBarToggle.setInheritsPopupMenu(true); 420 sideToolBar.add(toolBarToggle); 407 421 listAllToggleDialogsButton.setAlignmentX(0.5f); 408 422 listAllToggleDialogsButton.setBorder(null); 409 423 listAllToggleDialogsButton.setFont(listAllToggleDialogsButton.getFont().deriveFont(Font.PLAIN)); 410 jb.add(listAllToggleDialogsButton); 411 } 412 413 final Component toToggle; 414 if (Main.pref.getBoolean("sidetoolbar.scrollable", true)) { 415 final ScrollViewport svp = new ScrollViewport(jb, ScrollViewport.VERTICAL_DIRECTION); 416 toToggle = svp; 417 panel.add(svp, BorderLayout.WEST); 418 jb.addMouseWheelListener(new MouseWheelListener() { 419 420 public void mouseWheelMoved(MouseWheelEvent e) { 421 svp.scroll(0, e.getUnitsToScroll() * 5); 424 listAllToggleDialogsButton.setInheritsPopupMenu(true); 425 sideToolBar.add(listAllToggleDialogsButton); 426 } 427 428 /** 429 * sideToolBar: add dynamic popup menu 430 */ 431 sideToolBar.setComponentPopupMenu(new JPopupMenu() { 432 final int staticMenuEntryCount = 2; 433 JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("Do not hide toolbar")) { 434 @Override 435 public void actionPerformed(ActionEvent e) { 436 boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState(); 437 Main.pref.put("sidetoolbar.always-visible", sel); 422 438 } 423 439 }); 424 } else {425 toToggle = jb;426 panel.add(jb, BorderLayout.WEST);427 }428 toToggle.setVisible(Main.pref.getBoolean("sidetoolbar.visible", true));429 430 jb.addMouseListener(new PopupMenuLauncher(new JPopupMenu() {431 432 440 { 441 addPopupMenuListener(new PopupMenuListener() { 442 @Override 443 public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 444 final Object src = ((JPopupMenu)e.getSource()).getInvoker(); 445 if (src instanceof IconToggleButton) { 446 insert(new Separator(), 0); 447 insert(new AbstractAction() { 448 { 449 putValue(NAME, tr("Hide this button")); 450 putValue(SHORT_DESCRIPTION, tr("Click the arrow at the bottom to show it again.")); 451 } 452 @Override 453 public void actionPerformed(ActionEvent e) { 454 ((IconToggleButton)src).setButtonHidden(true); 455 validateToolBarsVisibility(); 456 } 457 }, 0); 458 } 459 doNotHide.setSelected(Main.pref.getBoolean("sidetoolbar.always-visible", true)); 460 } 461 @Override 462 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { 463 while (getComponentCount() > staticMenuEntryCount) { 464 remove(0); 465 } 466 } 467 @Override 468 public void popupMenuCanceled(PopupMenuEvent e) {} 469 }); 470 433 471 add(new AbstractAction(tr("Hide edit toolbar")) { 434 435 472 @Override 436 473 public void actionPerformed(ActionEvent e) { … … 438 475 } 439 476 }); 440 } 441 })); 442 477 add(doNotHide); 478 } 479 }); 480 ((JToolBar)sideToolBar).setFloatable(false); 481 482 /** 483 * sideToolBar: decide scroll- and visibility 484 */ 485 if(Main.pref.getBoolean("sidetoolbar.scrollable", true)) { 486 final ScrollViewport svp = new ScrollViewport(sideToolBar, ScrollViewport.VERTICAL_DIRECTION); 487 svp.addMouseWheelListener(new MouseWheelListener() { 488 @Override 489 public void mouseWheelMoved(MouseWheelEvent e) { 490 svp.scroll(0, e.getUnitsToScroll() * 5); 491 } 492 }); 493 sideToolBar = svp; 494 } 495 sideToolBar.setVisible(Main.pref.getBoolean("sidetoolbar.visible", true)); 443 496 sidetoolbarPreferencesChangedListener = new Preferences.PreferenceChangedListener() { 444 445 497 @Override 446 498 public void preferenceChanged(PreferenceChangeEvent e) { 447 499 if ("sidetoolbar.visible".equals(e.getKey())) { 448 toToggle.setVisible(Main.pref.getBoolean("sidetoolbar.visible"));500 sideToolBar.setVisible(Main.pref.getBoolean("sidetoolbar.visible")); 449 501 } 450 502 } … … 452 504 Main.pref.addPreferenceChangeListener(sidetoolbarPreferencesChangedListener); 453 505 506 /** 507 * sideToolBar: add it to the panel 508 */ 509 panel.add(sideToolBar, BorderLayout.WEST); 510 511 /** 512 * statusLine: add to panel 513 */ 454 514 if (statusLine != null && Main.pref.getBoolean("statusline.visible", true)) { 455 515 panel.add(statusLine, BorderLayout.SOUTH); 456 516 } 457 }458 459 private void addHideContextMenu(final IconToggleButton b) {460 //context menu461 b.addMouseListener(new PopupMenuLauncher(new JPopupMenu() {462 {463 add(new AbstractAction() {464 {465 putValue(NAME, tr("Hide this button"));466 putValue(SHORT_DESCRIPTION, tr("Click the arrow at the bottom to show it again."));467 }468 @Override469 public void actionPerformed(ActionEvent e) {470 b.setButtonHidden(true);471 validateToolBarsVisibility();472 }473 });474 }475 }));476 517 } 477 518 … … 544 585 } 545 586 587 public void setDialogsPanelVisible(boolean visible) { 588 rememberToggleDialogWidth(); 589 dialogsPanel.setVisible(visible); 590 splitPane.setDividerLocation(visible?splitPane.getWidth()-Main.pref.getInteger("toggleDialogs.width",DEF_TOGGLE_DLG_WIDTH):0); 591 splitPane.setDividerSize(visible?5:0); 592 } 593 546 594 /** 547 595 * Remember the current width of the (possibly resized) toggle dialog area 548 596 */ 549 597 public void rememberToggleDialogWidth() { 550 Main.pref.putInteger("toggleDialogs.width", dialogsPanel.getWidth()); 598 if (dialogsPanel.isVisible()) { 599 Main.pref.putInteger("toggleDialogs.width", splitPane.getWidth()-splitPane.getDividerLocation()); 600 } 551 601 } 552 602 553 603 /* 554 * Remove panel from top of MapView by class 555 */ 604 * Remove panel from top of MapView by class */ 556 605 public void removeTopPanel(Class<?> type) { 557 606 int n = leftPanel.getComponentCount(); … … 653 702 // and possibly need to be hidden/shown. 654 703 SwingUtilities.invokeLater(new Runnable() { 655 public void run() {704 @Override public void run() { 656 705 validateToolBarsVisibility(); 657 706 } -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r5909 r5965 6 6 7 7 import java.awt.AWTEvent; 8 import java.awt.Color;9 8 import java.awt.Component; 10 9 import java.awt.Cursor; … … 17 16 import java.awt.Toolkit; 18 17 import java.awt.event.AWTEventListener; 18 import java.awt.event.ActionEvent; 19 19 import java.awt.event.InputEvent; 20 20 import java.awt.event.KeyAdapter; … … 29 29 import java.util.List; 30 30 31 import javax.swing.AbstractAction; 31 32 import javax.swing.BorderFactory; 33 import javax.swing.JButton; 34 import javax.swing.JCheckBoxMenuItem; 32 35 import javax.swing.JLabel; 36 import javax.swing.JMenuItem; 33 37 import javax.swing.JPanel; 38 import javax.swing.JPopupMenu; 34 39 import javax.swing.JProgressBar; 35 40 import javax.swing.JScrollPane; … … 37 42 import javax.swing.PopupFactory; 38 43 import javax.swing.UIManager; 44 import javax.swing.event.PopupMenuEvent; 45 import javax.swing.event.PopupMenuListener; 39 46 40 47 import org.openstreetmap.josm.Main; … … 47 54 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor.ProgressMonitorDialog; 48 55 import org.openstreetmap.josm.gui.util.GuiHelper; 56 import org.openstreetmap.josm.gui.widgets.ImageLabel; 57 import org.openstreetmap.josm.gui.widgets.JosmTextField; 49 58 import org.openstreetmap.josm.tools.GBC; 50 59 import org.openstreetmap.josm.tools.ImageProvider; 51 import org.openstreetmap.josm.gui.widgets.JosmTextField;52 60 53 61 /** … … 72 80 final Collector collector; 73 81 74 /**75 * A small user interface component that consists of an image label and76 * a fixed text content to the right of the image.77 */78 static class ImageLabel extends JPanel {79 static Color backColor = Color.decode("#b8cfe5");80 static Color backColorActive = Color.decode("#aaff5e");81 82 private JLabel tf;83 private int chars;84 public ImageLabel(String img, String tooltip, int chars) {85 super();86 setLayout(new GridBagLayout());87 setBackground(backColor);88 add(new JLabel(ImageProvider.get("statusline/"+img+".png")), GBC.std().anchor(GBC.WEST).insets(0,1,1,0));89 add(tf = new JLabel(), GBC.std().fill(GBC.BOTH).anchor(GBC.WEST).insets(2,1,1,0));90 setToolTipText(tooltip);91 this.chars = chars;92 }93 public void setText(String t) {94 tf.setText(t);95 }96 @Override public Dimension getPreferredSize() {97 return new Dimension(25 + chars*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getPreferredSize().height);98 }99 @Override public Dimension getMinimumSize() {100 return new Dimension(25 + chars*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getMinimumSize().height);101 }102 }103 104 82 public class BackgroundProgressMonitor implements ProgressMonitorDialog { 105 83 … … 115 93 } 116 94 95 @Override 117 96 public void setVisible(boolean visible) { 118 97 progressBar.setVisible(visible); 119 98 } 120 99 100 @Override 121 101 public void updateProgress(int progress) { 122 102 progressBar.setValue(progress); … … 125 105 } 126 106 107 @Override 127 108 public void setCustomText(String text) { 128 109 this.customText = text; … … 130 111 } 131 112 113 @Override 132 114 public void setCurrentAction(String text) { 133 115 this.title = text; … … 135 117 } 136 118 119 @Override 137 120 public void setIndeterminate(boolean newValue) { 138 121 UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100); … … 218 201 * Execution function for the Collector. 219 202 */ 203 @Override 220 204 public void run() { 221 205 registerListeners(); … … 281 265 // Set the text label in the bottom status bar 282 266 // "if mouse moved only" was added to stop heap growing 283 if (!mouseNotMoved) statusBarElementUpdate(ms); 267 if (!mouseNotMoved) { 268 statusBarElementUpdate(ms); 269 } 284 270 285 271 … … 363 349 * @return popup 364 350 */ 365 private finalPopup popupCreatePopup(Component content, MouseState ms) {351 private Popup popupCreatePopup(Component content, MouseState ms) { 366 352 Point p = mv.getLocationOnScreen(); 367 353 Dimension scrn = Toolkit.getDefaultToolkit().getScreenSize(); … … 399 385 * @param ms 400 386 */ 401 private finalvoid statusBarElementUpdate(MouseState ms) {387 private void statusBarElementUpdate(MouseState ms) { 402 388 final OsmPrimitive osmNearest = mv.getNearestNodeOrWay(ms.mousePos, OsmPrimitive.isUsablePredicate, false); 403 389 if (osmNearest != null) { … … 414 400 * @param mods modifiers (i.e. control keys) 415 401 */ 416 private finalvoid popupCycleSelection(Collection<OsmPrimitive> osms, int mods) {402 private void popupCycleSelection(Collection<OsmPrimitive> osms, int mods) { 417 403 DataSet ds = Main.main.getCurrentDataSet(); 418 404 // Find some items that are required for cycling through … … 453 439 * Tries to hide the given popup 454 440 */ 455 private finalvoid popupHidePopup() {441 private void popupHidePopup() { 456 442 popupLabels = null; 457 443 if(popup == null) … … 460 446 popup = null; 461 447 EventQueue.invokeLater(new Runnable(){ 462 public void run() { staticPopup.hide(); }}); 448 public void run() { 449 staticPopup.hide(); 450 }}); 463 451 } 464 452 … … 469 457 * @param lbls lables to show (see {@link #popupLabels}) 470 458 */ 471 private finalvoid popupShowPopup(Popup newPopup, List<JLabel> lbls) {459 private void popupShowPopup(Popup newPopup, List<JLabel> lbls) { 472 460 final Popup staticPopup = newPopup; 473 461 if(this.popup != null) { … … 476 464 final Popup staticOldPopup = this.popup; 477 465 EventQueue.invokeLater(new Runnable(){ 478 public void run() {466 @Override public void run() { 479 467 staticPopup.show(); 480 468 staticOldPopup.hide(); … … 484 472 // There is no old popup 485 473 EventQueue.invokeLater(new Runnable(){ 486 public void run() { staticPopup.show(); }});474 @Override public void run() { staticPopup.show(); }}); 487 475 } 488 476 this.popupLabels = lbls; … … 495 483 * user clicks on the map instead of the popup. 496 484 */ 497 private finalvoid popupUpdateLabels() {485 private void popupUpdateLabels() { 498 486 if(this.popup == null || this.popupLabels == null) 499 487 return; … … 510 498 * @param osm The primitive to derive the colors from 511 499 */ 512 private finalvoid popupSetLabelColors(JLabel lbl, OsmPrimitive osm) {500 private void popupSetLabelColors(JLabel lbl, OsmPrimitive osm) { 513 501 DataSet ds = Main.main.getCurrentDataSet(); 514 502 if(ds.isSelected(osm)) { … … 527 515 * @return labels for info popup 528 516 */ 529 private finalJLabel popupBuildPrimitiveLabels(final OsmPrimitive osm) {517 private JLabel popupBuildPrimitiveLabels(final OsmPrimitive osm) { 530 518 final StringBuilder text = new StringBuilder(); 531 519 String name = osm.getDisplayName(DefaultNameFormatter.getInstance()); … … 587 575 // can correct this defect. 588 576 l.addMouseMotionListener(new MouseMotionListener() { 589 public void mouseMoved(MouseEvent e) {577 @Override public void mouseMoved(MouseEvent e) { 590 578 l.setBackground(SystemColor.info); 591 579 l.setForeground(SystemColor.infoText); 592 580 } 593 public void mouseDragged(MouseEvent e) {581 @Override public void mouseDragged(MouseEvent e) { 594 582 l.setBackground(SystemColor.info); 595 583 l.setForeground(SystemColor.infoText); … … 614 602 615 603 private AWTEventListener awtListener = new AWTEventListener() { 616 public void eventDispatched(AWTEvent event) { 604 @Override 605 public void eventDispatched(AWTEvent event) { 617 606 if (event instanceof InputEvent && 618 607 ((InputEvent)event).getComponent() == mv) { … … 629 618 630 619 private MouseMotionListener mouseMotionListener = new MouseMotionListener() { 620 @Override 631 621 public void mouseMoved(MouseEvent e) { 632 622 synchronized (collector) { … … 637 627 } 638 628 629 @Override 639 630 public void mouseDragged(MouseEvent e) { 640 631 mouseMoved(e); … … 686 677 this.collector = new Collector(mapFrame); 687 678 688 lonText.addMouseListener(Main.main.menu.jumpToAct); 689 latText.addMouseListener(Main.main.menu.jumpToAct); 690 679 // Context menu of status bar 680 setComponentPopupMenu(new JPopupMenu() { 681 JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("Do not hide status bar")) { 682 @Override public void actionPerformed(ActionEvent e) { 683 boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState(); 684 Main.pref.put("statusbar.always-visible", sel); 685 } 686 }); 687 JMenuItem jumpButton; 688 { 689 jumpButton = add(Main.main.menu.jumpToAct); 690 addPopupMenuListener(new PopupMenuListener() { 691 @Override 692 public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 693 Component invoker = ((JPopupMenu)e.getSource()).getInvoker(); 694 jumpButton.setVisible(invoker == latText || invoker == lonText); 695 doNotHide.setSelected(Main.pref.getBoolean("statusbar.always-visible", true)); 696 } 697 @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} 698 @Override public void popupMenuCanceled(PopupMenuEvent e) {} 699 }); 700 add(doNotHide); 701 } 702 }); 703 691 704 // Listen for mouse movements and set the position text field 692 705 mv.addMouseMotionListener(new MouseMotionListener(){ 706 @Override 693 707 public void mouseDragged(MouseEvent e) { 694 708 mouseMoved(e); 695 709 } 710 @Override 696 711 public void mouseMoved(MouseEvent e) { 697 712 if (mv.center == null) … … 709 724 setLayout(new GridBagLayout()); 710 725 setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 726 727 latText.setInheritsPopupMenu(true); 728 lonText.setInheritsPopupMenu(true); 729 headingText.setInheritsPopupMenu(true); 730 //angleText.setInheritsPopupMenu(true); 731 distText.setInheritsPopupMenu(true); 732 nameText.setInheritsPopupMenu(true); 733 //helpText.setInheritsPopupMenu(true); 734 //progressBar.setInheritsPopupMenu(true); 711 735 712 736 add(latText, GBC.std()); … … 745 769 } 746 770 771 @Override 747 772 public String helpTopic() { 748 773 return ht("/Statusline"); -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r5670 r5965 23 23 import java.util.Collections; 24 24 import java.util.Comparator; 25 import java.util.Enumeration;26 25 import java.util.LinkedList; 27 26 import java.util.List; … … 261 260 //store the last mouse action 262 261 this.addMouseMotionListener(new MouseMotionListener() { 263 public void mouseDragged(MouseEvent e) {262 @Override public void mouseDragged(MouseEvent e) { 264 263 mouseMoved(e); 265 264 } 266 public void mouseMoved(MouseEvent e) {265 @Override public void mouseMoved(MouseEvent e) { 267 266 lastMEvent = e; 268 267 } … … 483 482 ret, 484 483 new Comparator<Layer>() { 485 public int compare(Layer l1, Layer l2) {484 @Override public int compare(Layer l1, Layer l2) { 486 485 if (l1 instanceof OsmDataLayer && l2 instanceof OsmDataLayer) { 487 486 if (l1 == getActiveLayer()) return -1; … … 780 779 * that I switch layers and actions at the same time and it was annoying to mind the 781 780 * order. This way it works as visual clue for new users */ 782 for (Enumeration<AbstractButton> e = Main.map.toolGroup.getElements() ; e.hasMoreElements() ;) { 783 AbstractButton button = e.nextElement(); 784 MapMode mode = (MapMode)button.getAction(); 785 boolean isLayerSupported = mode.layerIsSupported(layer); 786 button.setEnabled(isLayerSupported); 787 // Also update associated shortcut (fix #6876) 788 if (isLayerSupported) { 789 Main.registerActionShortcut(mode, mode.getShortcut()); 781 for (AbstractButton b: Main.map.allMapModeButtons) { 782 MapMode mode = (MapMode)b.getAction(); 783 if (mode.layerIsSupported(layer)) { 784 Main.registerActionShortcut(mode, mode.getShortcut()); //fix #6876 785 b.setEnabled(true); 790 786 } else { 791 787 Main.unregisterShortcut(mode.getShortcut()); 788 b.setEnabled(false); 792 789 } 793 790 } … … 859 856 } 860 857 858 @Override 861 859 public void propertyChange(PropertyChangeEvent evt) { 862 860 if (evt.getPropertyName().equals(Layer.VISIBLE_PROP)) { … … 894 892 895 893 private SelectionChangedListener repaintSelectionChangedListener = new SelectionChangedListener(){ 896 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {894 @Override public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 897 895 repaint(); 898 896 } -
trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java
r5954 r5965 30 30 import java.util.Map; 31 31 32 import javax.swing.AbstractAction; 32 33 import javax.swing.Action; 33 34 import javax.swing.DefaultListCellRenderer; … … 36 37 import javax.swing.ImageIcon; 37 38 import javax.swing.JButton; 39 import javax.swing.JCheckBoxMenuItem; 38 40 import javax.swing.JComponent; 39 41 import javax.swing.JLabel; … … 51 53 import javax.swing.event.ListSelectionEvent; 52 54 import javax.swing.event.ListSelectionListener; 55 import javax.swing.event.PopupMenuEvent; 56 import javax.swing.event.PopupMenuListener; 53 57 import javax.swing.event.TreeSelectionEvent; 54 58 import javax.swing.event.TreeSelectionListener; … … 66 70 import org.openstreetmap.josm.actions.ParameterizedActionDecorator; 67 71 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 68 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;69 72 import org.openstreetmap.josm.tools.GBC; 70 73 import org.openstreetmap.josm.tools.ImageProvider; … … 72 75 73 76 public class ToolbarPreferences implements PreferenceSettingFactory { 74 75 77 76 78 private static final String EMPTY_TOOLBAR_MARKER = "<!-empty-!>"; … … 228 230 skip('='); 229 231 String paramValue = readTillChar(',','}'); 230 if ("icon".equals(paramName) && paramValue.length() > 0) 232 if ("icon".equals(paramName) && paramValue.length() > 0) { 231 233 result.setIcon(paramValue); 232 else if("name".equals(paramName) && paramValue.length() > 0)234 } else if("name".equals(paramName) && paramValue.length() > 0) { 233 235 result.setName(paramValue); 236 } 234 237 skip(','); 235 238 } … … 294 297 first = false; 295 298 } 296 if(!first) 299 if(!first) { 297 300 result.append('}'); 301 } 298 302 } 299 303 … … 339 343 return null; 340 344 } 341 } else 345 } else { 342 346 rowIndex -= 2; 347 } 343 348 } 344 349 ActionParameter<Object> param = getParam(rowIndex); … … 368 373 currentAction.setIcon((String)aValue); 369 374 return; 370 } else 375 } else { 371 376 rowIndex -= 2; 377 } 372 378 } 373 379 ActionParameter<Object> param = getParam(rowIndex); … … 383 389 } 384 390 385 private static class ToolbarPopupMenu extends JPopupMenu { 386 public ToolbarPopupMenu(final ActionDefinition action) { 387 388 if(action != null) { 389 add(tr("Remove from toolbar",action.getDisplayName())) 390 .addActionListener(new ActionListener() { 391 @Override public void actionPerformed(ActionEvent e) { 391 private class ToolbarPopupMenu extends JPopupMenu { 392 ActionDefinition act; 393 394 private void setActionAndAdapt(ActionDefinition action) { 395 this.act = action; 396 doNotHide.setSelected(Main.pref.getBoolean("toolbar.always-visible", true)); 397 remove.setVisible(act!=null); 398 shortcutEdit.setVisible(act!=null); 399 } 400 401 JMenuItem remove = new JMenuItem(new AbstractAction(tr("Remove from toolbar")) { 402 @Override 403 public void actionPerformed(ActionEvent e) { 392 404 Collection<String> t = new LinkedList<String>(getToolString()); 393 405 ActionParser parser = new ActionParser(null); 394 406 // get text definition of current action 395 String res = parser.saveAction(action);407 String res = parser.saveAction(act); 396 408 // remove the button from toolbar preferences 397 409 t.remove( res ); … … 400 412 } 401 413 }); 402 }403 414 404 add(tr("Configure toolbar")).addActionListener(new ActionListener() { 405 @Override public void actionPerformed(ActionEvent e) { 415 JMenuItem configure = new JMenuItem(new AbstractAction(tr("Configure toolbar")) { 416 @Override 417 public void actionPerformed(ActionEvent e) { 406 418 final PreferenceDialog p =new PreferenceDialog(Main.parent); 407 419 p.selectPreferencesTabByName("toolbar"); … … 410 422 }); 411 423 412 add(tr("Edit shortcut")).addActionListener(new ActionListener() { 413 @Override public void actionPerformed(ActionEvent e) { 424 JMenuItem shortcutEdit = new JMenuItem(new AbstractAction(tr("Edit shortcut")) { 425 @Override 426 public void actionPerformed(ActionEvent e) { 414 427 final PreferenceDialog p =new PreferenceDialog(Main.parent); 415 p.getTabbedPane().getShortcutPreference().setDefaultFilter(action.getDisplayName());428 p.getTabbedPane().getShortcutPreference().setDefaultFilter(act.getDisplayName()); 416 429 p.selectPreferencesTabByName("shortcuts"); 417 430 p.setVisible(true); 418 // refresh toolbar to accept changes ofshortcuts without restart431 // refresh toolbar to try using changed shortcuts without restart 419 432 Main.toolbar.refreshToolbarControl(); 420 433 } 421 434 }); 422 } 423 } 435 436 JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("getSt hide toolbar and menu")) { 437 @Override 438 public void actionPerformed(ActionEvent e) { 439 boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState(); 440 Main.pref.put("toolbar.always-visible", sel); 441 Main.pref.put("menu.always-visible", sel); 442 } 443 }); 444 { 445 addPopupMenuListener(new PopupMenuListener() { 446 @Override 447 public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 448 setActionAndAdapt(buttonActions.get( 449 ((JPopupMenu)e.getSource()).getInvoker() 450 )); 451 } 452 @Override 453 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} 454 455 @Override 456 public void popupMenuCanceled(PopupMenuEvent e) {} 457 }); 458 add(remove); 459 add(configure); 460 add(shortcutEdit); 461 add(doNotHide); 462 } 463 } 464 465 private ToolbarPopupMenu popupMenu = new ToolbarPopupMenu(); 424 466 425 467 /** … … 433 475 434 476 public JToolBar control = new JToolBar(); 477 private HashMap<Object, ActionDefinition> buttonActions = new HashMap<Object, ActionDefinition>(30); 435 478 436 479 @Override … … 826 869 } else { 827 870 String res = parser.saveAction(action); 828 if(res != null) 871 if(res != null) { 829 872 t.add(res); 830 873 } 874 } 831 875 } 832 876 if (t.isEmpty()) { … … 842 886 public ToolbarPreferences() { 843 887 control.setFloatable(false); 844 control. addMouseListener(new PopupMenuLauncher(new ToolbarPopupMenu(null)));888 control.setComponentPopupMenu(popupMenu); 845 889 } 846 890 … … 979 1023 public void refreshToolbarControl() { 980 1024 control.removeAll(); 1025 buttonActions.clear(); 981 1026 982 1027 for (ActionDefinition action : getDefinedActions()) { … … 985 1030 } else { 986 1031 final JButton b = addButtonAndShortcut(action); 1032 buttonActions.put(b, action); 987 1033 988 1034 Icon i = action.getDisplayIcon(); … … 1001 1047 }); 1002 1048 } 1003 b. addMouseListener(new PopupMenuLauncher( new ToolbarPopupMenu(action)));1049 b.setInheritsPopupMenu(true); 1004 1050 } 1005 1051 } … … 1014 1060 if (action.getAction() instanceof JosmAction) { 1015 1061 sc = ((JosmAction) action.getAction()).getShortcut(); 1016 if (sc.getAssignedKey() == KeyEvent.CHAR_UNDEFINED) sc = null; 1062 if (sc.getAssignedKey() == KeyEvent.CHAR_UNDEFINED) { 1063 sc = null; 1064 } 1017 1065 } 1018 1066 … … 1023 1071 1024 1072 String tt = action.getDisplayTooltip(); 1025 if (tt==null) tt=""; 1073 if (tt==null) { 1074 tt=""; 1075 } 1026 1076 1027 1077 if (sc == null || paramCode != 0) { 1028 1078 String name = (String) action.getAction().getValue("toolbar"); 1029 if (name==null) name=action.getDisplayName(); 1030 if (paramCode!=0) name = name+paramCode; 1079 if (name==null) { 1080 name=action.getDisplayName(); 1081 } 1082 if (paramCode!=0) { 1083 name = name+paramCode; 1084 } 1031 1085 String desc = action.getDisplayName() + ((paramCode==0)?"":action.parameters.toString()); 1032 1086 sc = Shortcut.registerShortcut("toolbar:"+name, tr("Toolbar: {0}", desc), … … 1044 1098 } 1045 1099 1046 if (!tt.isEmpty()) b.setToolTipText(tt); 1100 if (!tt.isEmpty()) { 1101 b.setToolTipText(tt); 1102 } 1047 1103 return b; 1048 1104 }
Note:
See TracChangeset
for help on using the changeset viewer.