Changeset 3598 in josm
- Timestamp:
- 2010-10-10T23:37:19+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r3455 r3598 1 1 // License: GPL. See LICENSE file for details. 2 3 2 package org.openstreetmap.josm.gui; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 5 6 import java.awt.BorderLayout; 6 7 import java.awt.Container; 7 8 import java.awt.Dimension; 9 import java.awt.Font; 10 import java.awt.Rectangle; 11 import java.awt.event.ActionEvent; 8 12 import java.awt.event.KeyEvent; 9 13 import java.awt.event.MouseWheelEvent; … … 15 19 import java.util.concurrent.CopyOnWriteArrayList; 16 20 21 import javax.swing.AbstractAction; 17 22 import javax.swing.AbstractButton; 18 23 import javax.swing.Action; 19 24 import javax.swing.BoxLayout; 20 25 import javax.swing.ButtonGroup; 26 import javax.swing.JButton; 27 import javax.swing.JCheckBoxMenuItem; 21 28 import javax.swing.JComponent; 22 29 import javax.swing.JPanel; 30 import javax.swing.JPopupMenu; 23 31 import javax.swing.JSplitPane; 24 32 import javax.swing.JToolBar; … … 49 57 import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog; 50 58 import org.openstreetmap.josm.gui.layer.Layer; 59 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 51 60 import org.openstreetmap.josm.tools.Destroyable; 52 61 … … 92 101 93 102 public final ButtonGroup toolGroup = new ButtonGroup(); 103 104 public final JButton otherButton = new JButton(new OtherButtonsAction()); 94 105 95 106 /** … … 201 212 MapView.removeLayerChangeListener(this); 202 213 dialogsPanel.destroy(); 203 for (int i = 0; i < toolBarActions.getComponentCount(); ++i) 214 for (int i = 0; i < toolBarActions.getComponentCount(); ++i) { 204 215 if (toolBarActions.getComponent(i) instanceof Destroyable) { 205 216 ((Destroyable)toolBarActions.getComponent(i)).destroy(); 206 217 } 207 for (int i = 0; i < toolBarToggle.getComponentCount(); ++i) 218 } 219 for (int i = 0; i < toolBarToggle.getComponentCount(); ++i) { 208 220 if (toolBarToggle.getComponent(i) instanceof Destroyable) { 209 221 ((Destroyable)toolBarToggle.getComponent(i)).destroy(); 210 222 } 223 } 211 224 212 225 // remove menu entries … … 240 253 * @param dlg The toggle dialog. It must not be in the list already. 241 254 */ 242 public IconToggleButton addToggleDialog( ToggleDialog dlg) {243 IconToggleButton button = new IconToggleButton(dlg.getToggleAction());255 public IconToggleButton addToggleDialog(final ToggleDialog dlg) { 256 final IconToggleButton button = new IconToggleButton(dlg.getToggleAction()); 244 257 toolBarToggle.add(button); 258 button.addMouseListener(new PopupMenuLauncher(new JPopupMenu() { 259 { 260 add(new AbstractAction() { 261 { 262 putValue(NAME, tr("Hide this button")); 263 putValue(SHORT_DESCRIPTION, tr("Click the arrow at the bottom to show it again.")); 264 } 265 266 @Override 267 public void actionPerformed(ActionEvent e) { 268 dlg.hideButton(); 269 } 270 }); 271 } 272 })); 273 dlg.setButton(button); 245 274 allDialogs.add(dlg); 246 275 if (dialogsPanel.initialized) { … … 298 327 JToolBar jb = new JToolBar(JToolBar.VERTICAL); 299 328 jb.setFloatable(false); 329 toolBarActions.setAlignmentX(0.5f); 300 330 jb.add(toolBarActions); 331 301 332 jb.addSeparator(new Dimension(0,10)); 333 toolBarToggle.setAlignmentX(0.5f); 302 334 jb.add(toolBarToggle); 335 otherButton.setAlignmentX(0.5f); 336 otherButton.setBorder(null); 337 otherButton.setFont(otherButton.getFont().deriveFont(Font.PLAIN)); 338 jb.add(otherButton); 339 303 340 if(Main.pref.getBoolean("sidetoolbar.visible", true)) 304 341 { … … 317 354 if (statusLine != null && Main.pref.getBoolean("statusline.visible", true)) { 318 355 panel.add(statusLine, BorderLayout.SOUTH); 356 } 357 } 358 359 class OtherButtonsAction extends AbstractAction { 360 361 public OtherButtonsAction() { 362 putValue(NAME, ">>"); 363 } 364 365 @Override 366 public void actionPerformed(ActionEvent e) { 367 JPopupMenu menu = new JPopupMenu(); 368 for (final ToggleDialog t : allDialogs) { 369 menu.add(new JCheckBoxMenuItem(new AbstractAction() { 370 { 371 putValue(NAME, t.getToggleAction().getValue(NAME)); 372 putValue(SMALL_ICON, t.getToggleAction().getValue(SMALL_ICON)); 373 putValue(SELECTED_KEY, !t.isButtonHidden()); 374 putValue(SHORT_DESCRIPTION, tr("Hide or show this toggle button")); 375 } 376 @Override 377 public void actionPerformed(ActionEvent e) { 378 if ((Boolean) getValue(SELECTED_KEY)) { 379 t.showButton(); 380 } else { 381 t.hideButton(); 382 } 383 } 384 })); 385 } 386 Rectangle bounds = otherButton.getBounds(); 387 menu.show(otherButton, bounds.x+bounds.width, 0); 319 388 } 320 389 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r3502 r3598 31 31 import javax.swing.JOptionPane; 32 32 import javax.swing.JPanel; 33 import javax.swing.JToggleButton; 33 34 34 35 import org.openstreetmap.josm.Main; … … 82 83 protected JDialog detachedDialog; 83 84 85 protected JToggleButton button; 86 protected boolean buttonHidden; 87 84 88 /** 85 89 * Constructor … … 125 129 isDocked = Main.pref.getBoolean(preferencePrefix+".docked", true); 126 130 isCollapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false); 131 132 buttonHidden = Main.pref.getBoolean(preferencePrefix+".button_hidden", false); 127 133 128 134 RedirectInputMap.redirectToMainContentPane(this); … … 187 193 188 194 /** 189 * Changes the state of the dialog such that the user can see the content 190 * and takes care of the panel reconstruction. 191 */ 192 public void unfurlDialog() 193 { 195 * Changes the state of the dialog such that the user can see the content. 196 * (takes care of the panel reconstruction) 197 */ 198 public void unfurlDialog() { 194 199 if (isDialogInDefaultView()) 195 200 return; … … 198 203 dialogsPanel.reconstruct(Action.COLLAPSED_TO_DEFAULT, this); 199 204 } else if (!isDialogShowing()) { 205 if (isButtonHidden()) { 206 showButtonImpl(); 207 } 200 208 showDialog(); 201 209 if (isDocked && isCollapsed) { … … 207 215 showNotify(); 208 216 } 217 } 218 219 public void hideButton() { 220 if (!button.isVisible()) 221 throw new AssertionError(); 222 if ((Boolean) toggleAction.getValue("selected")) { 223 toggleAction.actionPerformed(null); 224 } 225 button.setVisible(false); 226 setButtonHidden(true); 227 } 228 229 public void showButton() { 230 showButtonImpl(); 231 unfurlDialog(); 232 } 233 234 protected void showButtonImpl() { 235 if (button.isVisible()) 236 throw new AssertionError(); 237 button.setVisible(true); 238 setButtonHidden(false); 209 239 } 210 240 … … 569 599 } 570 600 601 public boolean isButtonHidden() { 602 return buttonHidden; 603 } 604 605 protected void setButtonHidden(boolean buttonHidden) { 606 this.buttonHidden = buttonHidden; 607 Main.pref.put(preferencePrefix+".button_hidden", buttonHidden); 608 } 609 610 611 public void setButton(JToggleButton button) { 612 this.button = button; 613 button.setVisible(!buttonHidden); 614 } 615 616 public JToggleButton getButton() { 617 return button; 618 } 619 571 620 /*** 572 621 * The following methods are intended to be overridden, in order to customize
Note:
See TracChangeset
for help on using the changeset viewer.