Changeset 2111 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-09-13T11:17:48+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r2021 r2111 8 8 import java.awt.GridBagLayout; 9 9 import java.awt.Image; 10 import java.awt.Rectangle; 10 11 import java.awt.event.ActionEvent; 11 12 import java.awt.event.ActionListener; … … 41 42 */ 42 43 public class ToggleDialog extends JPanel implements Helpful { 43 private static final Logger logger = Logger.getLogger(ToggleDialog.class.getName());44 // private static final Logger logger = Logger.getLogger(ToggleDialog.class.getName()); 44 45 45 46 /** … … 81 82 private String title; 82 83 83 /** indicates whether the dialog is currently minimized or not */ 84 private boolean collapsed; 85 /** indicates whether the dialog is docked or not */ 86 private boolean docked; 87 /** indicates whether the dialog is showing or not */ 84 /** 85 * Indicates whether the dialog is showing or not. 86 */ 88 87 private boolean isShowing; 89 88 /** 89 * If isShowing is true, indicates whether the dialog is docked or not, e. g. 90 * shown as part of the main window or as a seperate dialog window. 91 */ 92 private boolean isDocked; 93 /** 94 * If isShowing and isDocked are true, indicates whether the dialog is 95 * currently minimized or not. 96 */ 97 private boolean isCollapsed; 98 99 /** the preferred width of all docked toggle dialogs */ 100 final private int TOGGLE_DIALOG_WIDTH = 330; 90 101 /** the preferred height if the toggle dialog is expanded */ 91 102 private int preferredHeight; … … 95 106 private JDialog detachedDialog; 96 107 97 98 108 /** 99 109 * Constructor … … 109 119 this.preferencePrefix = iconName; 110 120 init(name, iconName, tooltip, shortcut, preferredHeight); 121 } 122 123 /** 124 * Initializes the toggle dialog 125 * 126 * @param name 127 * @param iconName 128 * @param tooltip 129 * @param shortcut 130 * @param preferredHeight 131 */ 132 private void init(String name, String iconName, String tooltip, Shortcut shortcut, final int preferredHeight) { 133 setPreferredSize(new Dimension(TOGGLE_DIALOG_WIDTH, preferredHeight)); 134 this.preferredHeight = preferredHeight; 135 toggleAction = new ToggleDialogAction(name, "dialogs/"+iconName, tooltip, shortcut, iconName); 136 String helpId = "Dialog/"+getClass().getName().substring(getClass().getName().lastIndexOf('.')+1); 137 toggleAction.putValue("help", helpId.substring(0, helpId.length()-6)); 138 139 setLayout(new BorderLayout()); 140 141 // show the minimize button 142 lblMinimized = new JLabel(ImageProvider.get("misc", "normal")); 143 titleBar = new TitleBar(name, iconName); 144 add(titleBar, BorderLayout.NORTH); 145 146 setVisible(false); 147 setBorder(BorderFactory.createEtchedBorder()); 148 149 isDocked = Main.pref.getBoolean(preferencePrefix+".docked", true); 150 isCollapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false); 111 151 } 112 152 … … 126 166 127 167 /** 128 * Initializes the toggle dialog 129 * 130 * @param name 131 * @param iconName 132 * @param tooltip 133 * @param shortcut 134 * @param preferredHeight 135 */ 136 private void init(String name, String iconName, String tooltip, Shortcut shortcut, final int preferredHeight) { 137 setPreferredSize(new Dimension(330,preferredHeight)); 138 toggleAction = new ToggleDialogAction(name, "dialogs/"+iconName, tooltip, shortcut, iconName); 139 String helpId = "Dialog/"+getClass().getName().substring(getClass().getName().lastIndexOf('.')+1); 140 toggleAction.putValue("help", helpId.substring(0, helpId.length()-6)); 141 142 setLayout(new BorderLayout()); 143 144 // show the minimize button 145 lblMinimized = new JLabel(ImageProvider.get("misc", "normal")); 146 titleBar = new TitleBar(name, iconName); 147 add(titleBar, BorderLayout.NORTH); 148 149 setVisible(false); 150 setBorder(BorderFactory.createEtchedBorder()); 151 152 docked = Main.pref.getBoolean(preferencePrefix+".docked", true); 153 collapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false); 168 * Toggles between collapsed and expanded state 169 * 170 */ 171 protected void toggleExpandedState() { 172 if (isCollapsed) { 173 expand(); 174 } else { 175 collapse(); 176 } 154 177 } 155 178 … … 160 183 protected void collapse() { 161 184 setContentVisible(false); 162 this.collapsed = true;185 isCollapsed = true; 163 186 Main.pref.put(preferencePrefix+".minimized", true); 164 setPreferredSize(new Dimension( 330,20));165 setMaximumSize(new Dimension( 330,20));187 setPreferredSize(new Dimension(TOGGLE_DIALOG_WIDTH,20)); 188 setMaximumSize(new Dimension(TOGGLE_DIALOG_WIDTH,20)); 166 189 lblMinimized.setIcon(ImageProvider.get("misc", "minimized")); 167 190 refreshToggleDialogsView(); … … 173 196 protected void expand() { 174 197 setContentVisible(true); 175 this.collapsed = false;198 isCollapsed = false; 176 199 Main.pref.put(preferencePrefix+".minimized", false); 177 setPreferredSize(new Dimension( 330,preferredHeight));200 setPreferredSize(new Dimension(TOGGLE_DIALOG_WIDTH,preferredHeight)); 178 201 setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); 179 202 lblMinimized.setIcon(ImageProvider.get("misc", "normal")); … … 228 251 } 229 252 titleBar.setVisible(true); 230 collapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false);231 if ( collapsed) {253 isCollapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false); 254 if (isCollapsed) { 232 255 collapse(); 233 256 } else { 234 257 expand(); 235 258 } 236 docked = true;237 Main.pref.put(preferencePrefix+".docked", docked);259 isDocked = true; 260 Main.pref.put(preferencePrefix+".docked", isDocked); 238 261 } 239 262 … … 245 268 setContentVisible(true); 246 269 setVisible(true); 247 248 270 // replace the toggle dialog by an invisible place holder. Makes sure 249 271 // we can place the toggle dialog where it was when it becomes docked … … 260 282 parent.remove(ToggleDialog.this); 261 283 } 284 262 285 263 286 titleBar.setVisible(false); … … 265 288 detachedDialog.setVisible(true); 266 289 refreshToggleDialogsView(); 267 docked = false;268 Main.pref.put(preferencePrefix+".docked", docked);290 isDocked = false; 291 Main.pref.put(preferencePrefix+".docked", isDocked); 269 292 } 270 293 … … 273 296 */ 274 297 public void hideDialog() { 275 if (detachedDialog != null) { 276 detachedDialog.setVisible(false); 277 detachedDialog.getContentPane().removeAll(); 278 detachedDialog.dispose(); 279 } 298 closeDetachedDialog(); 280 299 setVisible(false); 281 300 isShowing = false; … … 296 315 */ 297 316 public void showDialog() { 298 if (! docked) {317 if (!isDocked) { 299 318 detach(); 300 319 } else { 301 320 dock(); 302 if (! collapsed) {321 if (!isCollapsed) { 303 322 expand(); 304 323 setVisible(true); … … 311 330 isShowing = true; 312 331 // toggling the selected value in order to enforce PropertyChangeEvents 313 //314 332 toggleAction.putValue("selected", false); 315 333 toggleAction.putValue("selected", true); … … 318 336 319 337 /** 320 * Toggles between collapsed and expanded state321 *322 */323 protected void toggleExpandedState() {324 if (this.collapsed) {325 expand();326 } else {327 collapse();328 }329 }330 331 /**332 338 * Refreshes the layout of the parent toggle dialog view 333 339 * … … 347 353 if (detachedDialog != null) { 348 354 detachedDialog.setVisible(false); 349 detachedDialog. removeAll();355 detachedDialog.getContentPane().removeAll(); 350 356 detachedDialog.dispose(); 351 357 } … … 387 393 /** 388 394 * Replies the name of this toggle dialog 395 * 389 396 */ 390 397 @Override … … 474 481 private class DetachedDialog extends JDialog { 475 482 public DetachedDialog() { 476 super(JOptionPane.getFrameForComponent(Main.parent) ,false /* not modal*/);483 super(JOptionPane.getFrameForComponent(Main.parent)); 477 484 getContentPane().add(ToggleDialog.this); 478 485 addWindowListener(new WindowAdapter(){ 479 486 @Override public void windowClosing(WindowEvent e) { 487 rememberGeometry(); 480 488 getContentPane().removeAll(); 481 489 dispose(); … … 483 491 } 484 492 }); 485 addComponentListener(new ComponentAdapter(){486 @Override public void componentMoved(ComponentEvent e) {487 rememberGeometry();488 }489 });490 493 String bounds = Main.pref.get(preferencePrefix+".bounds",null); 491 494 if (bounds != null) { 492 495 String[] b = bounds.split(","); 493 setBounds(Integer.parseInt(b[0]),Integer.parseInt(b[1]),Integer.parseInt(b[2]),Integer.parseInt(b[3])); 496 setBounds(getDetachedGeometry(new Rectangle( 497 Integer.parseInt(b[0]),Integer.parseInt(b[1]),Integer.parseInt(b[2]),Integer.parseInt(b[3])))); 494 498 } else { 499 ToggleDialog.this.setPreferredSize(ToggleDialog.this.getDefaultDetachedSize()); 495 500 pack(); 496 501 setLocationRelativeTo(Main.parent); 497 502 } 498 503 setTitle(titleBar.getTitle()); … … 503 508 } 504 509 } 510 511 /** 512 * Change the Geometry of the detached dialog to better fit the content. 513 * Overrride this to make it useful. 514 */ 515 protected Rectangle getDetachedGeometry(Rectangle last) { 516 return last; 517 } 518 519 /** 520 * Default size of the detached dialog. 521 * Override this method to customize the initial dialog size. 522 */ 523 protected Dimension getDefaultDetachedSize() { 524 return new Dimension(TOGGLE_DIALOG_WIDTH, preferredHeight); 525 } 505 526 }
Note:
See TracChangeset
for help on using the changeset viewer.