Changeset 2005 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-08-29T15:51:00+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r1991 r2005 31 31 import org.openstreetmap.josm.gui.ExceptionDialogUtil; 32 32 import org.openstreetmap.josm.gui.ExtendedDialog; 33 import org.openstreetmap.josm.gui.OptionPaneUtil;34 33 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 35 34 import org.openstreetmap.josm.gui.PleaseWaitRunnable; … … 113 112 return; 114 113 if (Main.map == null) { 115 OptionPaneUtil.showMessageDialog(114 JOptionPane.showMessageDialog( 116 115 Main.parent, 117 116 tr("Nothing to upload. Get some data first."), … … 124 123 ConflictCollection conflicts = Main.map.mapView.getEditLayer().getConflicts(); 125 124 if (conflicts !=null && !conflicts.isEmpty()) { 126 OptionPaneUtil.showMessageDialog(125 JOptionPane.showMessageDialog( 127 126 Main.parent, 128 127 tr("There are unresolved conflicts. You have to resolve these first."), … … 130 129 JOptionPane.WARNING_MESSAGE 131 130 ); 132 Main.map.conflictDialog.action.button.setSelected(true); 133 Main.map.conflictDialog.action.actionPerformed(null); 131 Main.map.conflictDialog.showDialog(); 134 132 return; 135 133 } … … 152 150 153 151 if (add.isEmpty() && update.isEmpty() && delete.isEmpty()) { 154 OptionPaneUtil.showMessageDialog(152 JOptionPane.showMessageDialog( 155 153 Main.parent, 156 154 tr("No changes to upload."), … … 226 224 ); 227 225 int optionsType = JOptionPane.YES_NO_CANCEL_OPTION; 228 int ret = OptionPaneUtil.showOptionDialog(226 int ret = JOptionPane.showOptionDialog( 229 227 null, 230 228 msg, … … 232 230 optionsType, 233 231 JOptionPane.ERROR_MESSAGE, 232 null, 234 233 options, 235 234 defaultOption … … 265 264 ); 266 265 int optionsType = JOptionPane.YES_NO_OPTION; 267 int ret = OptionPaneUtil.showOptionDialog(266 int ret = JOptionPane.showOptionDialog( 268 267 null, 269 268 msg, … … 271 270 optionsType, 272 271 JOptionPane.ERROR_MESSAGE, 272 null, 273 273 options, 274 274 defaultOption … … 385 385 ex.getDisplayMessage() 386 386 ); 387 OptionPaneUtil.showMessageDialog(387 JOptionPane.showMessageDialog( 388 388 Main.map, 389 389 msg, -
trunk/src/org/openstreetmap/josm/gui/IconToggleButton.java
r1169 r2005 28 28 29 29 Object o = action.getValue(Action.SHORT_DESCRIPTION); 30 if (o != null) 30 if (o != null) { 31 31 setToolTipText(o.toString()); 32 } 32 33 33 34 action.addPropertyChangeListener(this); … … 44 45 setSelected((Boolean)evt.getNewValue()); 45 46 requestFocusInWindow(); 47 } else if (evt.getPropertyName().equals("selected")) { 48 setSelected((Boolean)evt.getNewValue()); 46 49 } 47 50 } -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r1890 r2005 70 70 * instead of adding directly to this list. 71 71 */ 72 p ublicJPanel toggleDialogs = new JPanel();73 p ublicArrayList<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>();72 private JPanel toggleDialogs = new JPanel(); 73 private ArrayList<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>(); 74 74 75 75 public final ButtonGroup toolGroup = new ButtonGroup(); … … 135 135 public void destroy() { 136 136 for (ToggleDialog t : allDialogs) { 137 t.close ();137 t.closeDetachedDialog(); 138 138 } 139 139 for (int i = 0; i < toolBarActions.getComponentCount(); ++i) … … 167 167 for (Component c : toggleDialogs.getComponents()) { 168 168 if (c instanceof ToggleDialog) { 169 boolean sel = Main.pref.getBoolean(((ToggleDialog)c).prefName+".visible"); 170 ((ToggleDialog)c).action.button.setSelected(sel); 171 c.setVisible(sel); 169 ToggleDialog td = (ToggleDialog)c; 170 if (Main.pref.getBoolean(td.getPreferencePrefix()+".visible")) { 171 td.showDialog(); 172 } 172 173 } 173 174 } … … 179 180 */ 180 181 public IconToggleButton addToggleDialog(ToggleDialog dlg) { 181 IconToggleButton button = new IconToggleButton(dlg.action); 182 dlg.action.button = button; 183 dlg.parent = toggleDialogs; 182 IconToggleButton button = new IconToggleButton(dlg.getToggleAction()); 183 dlg.setParent(toggleDialogs); 184 184 toolBarToggle.add(button); 185 185 toggleDialogs.add(dlg); -
trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
r1750 r2005 62 62 private void buildList() { 63 63 if(Main.main.undoRedo.commands.size() != 0) { 64 setTitle(tr("Command Stack: {0}", Main.main.undoRedo.commands.size()) , true);64 setTitle(tr("Command Stack: {0}", Main.main.undoRedo.commands.size())); 65 65 } else { 66 setTitle(tr("Command Stack") , false);66 setTitle(tr("Command Stack")); 67 67 } 68 68 if (Main.map == null || Main.map.mapView == null || Main.map.mapView.getEditLayer() == null) -
trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r1990 r2005 793 793 if(propertyData.getRowCount() != 0 || membershipData.getRowCount() != 0) { 794 794 setTitle(tr("Properties: {0} / Memberships: {1}", 795 propertyData.getRowCount(), membershipData.getRowCount()) , true);795 propertyData.getRowCount(), membershipData.getRowCount())); 796 796 } else { 797 setTitle(tr("Properties / Memberships") , false);797 setTitle(tr("Properties / Memberships")); 798 798 } 799 799 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r1990 r2005 142 142 } 143 143 if(getNumRelations() != 0) { 144 setTitle(tr("Relations: {0}", Main.main.getCurrentDataSet().relations.size()) , true);144 setTitle(tr("Relations: {0}", Main.main.getCurrentDataSet().relations.size())); 145 145 } else { 146 setTitle(tr("Relations") , false);146 setTitle(tr("Relations")); 147 147 } 148 148 selectRelation(selected); -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r1970 r2005 290 290 291 291 if( (nodes+ways+relations) != 0) { 292 setTitle(tr("Sel.: Rel.:{0} / Ways:{1} / Nodes:{2}", relations, ways, nodes) , true);292 setTitle(tr("Sel.: Rel.:{0} / Ways:{1} / Nodes:{2}", relations, ways, nodes)); 293 293 } else { 294 setTitle(tr("Selection") , false);294 setTitle(tr("Selection")); 295 295 } 296 296 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r1999 r2005 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others2 1 package org.openstreetmap.josm.gui.dialogs; 3 2 … … 5 4 6 5 import java.awt.BorderLayout; 6 import java.awt.Component; 7 7 import java.awt.Dimension; 8 8 import java.awt.EventQueue; 9 9 import java.awt.GridBagLayout; 10 import java.awt.Component;11 10 import java.awt.Image; 12 11 import java.awt.event.ActionEvent; … … 14 13 import java.awt.event.ComponentAdapter; 15 14 import java.awt.event.ComponentEvent; 15 import java.awt.event.MouseAdapter; 16 16 import java.awt.event.MouseEvent; 17 import java.awt.event.MouseListener;18 17 import java.awt.event.WindowAdapter; 19 18 import java.awt.event.WindowEvent; 20 21 import javax.swing.AbstractButton; 19 import java.util.logging.Logger; 20 21 import javax.swing.AbstractAction; 22 22 import javax.swing.BorderFactory; 23 23 import javax.swing.Box; 24 import javax.swing.ImageIcon; 24 25 import javax.swing.JButton; 25 26 import javax.swing.JDialog; 26 import javax.swing.JFrame;27 27 import javax.swing.JLabel; 28 28 import javax.swing.JOptionPane; 29 29 import javax.swing.JPanel; 30 import javax.swing.ImageIcon;31 30 32 31 import org.openstreetmap.josm.Main; … … 38 37 39 38 /** 40 * This class is a toggle dialog that can be turned on and off. It is attached41 * to a ButtonModel.39 * This class is a toggle dialog that can be turned on and off. 40 * 42 41 * 43 * @author imi44 42 */ 45 43 public class ToggleDialog extends JPanel implements Helpful { 46 44 private static final Logger logger = Logger.getLogger(ToggleDialog.class.getName()); 45 46 /** 47 * The action to toggle the visibility state of this toggle dialog. 48 * 49 * Emits {@see PropertyChangeEvent}s for the property <tt>selected</tt>: 50 * <ul> 51 * <li>true, if the dialog is currently visible</li> 52 * <li>false, if the dialog is currently invisible</li> 53 * </ul> 54 * 55 */ 47 56 public final class ToggleDialogAction extends JosmAction { 48 public final String prefname;49 public AbstractButton button;50 51 57 private ToggleDialogAction(String name, String iconName, String tooltip, Shortcut shortcut, String prefname) { 52 58 super(name, iconName, tooltip, shortcut, false); 53 this.prefname = prefname;54 59 } 55 60 56 61 public void actionPerformed(ActionEvent e) { 57 if (e != null && !(e.getSource() instanceof AbstractButton)) { 58 button.setSelected(!button.isSelected()); 62 toggleVisibility(); 63 } 64 65 public void toggleVisibility() { 66 if (isShowing) { 67 hideDialog(); 68 } else { 69 showDialog(); 59 70 } 60 Boolean selected = button.isSelected(); 61 setVisible(selected); 62 Main.pref.put(prefname+".visible", selected); 63 if(!selected && winadapter != null) { 64 winadapter.windowClosing(null); 65 } else if (!Main.pref.getBoolean(action.prefname+".docked", true)) { 66 EventQueue.invokeLater(new Runnable(){ 67 public void run() { 68 stickyActionListener.actionPerformed(null); 69 } 70 }); 71 } 72 } 73 74 /** 75 * The action to toggle this dialog. 76 */ 77 private ToggleDialogAction toggleAction; 78 private String preferencePrefix; 79 80 private JPanel parent; 81 private TitleBar titleBar; 82 private String title; 83 84 /** indicates whether the dialog is currently minimized or not */ 85 private boolean collapsed; 86 /** indicates whether the dialog is docked or not */ 87 private boolean docked; 88 /** indicates whether the dialog is showing or not */ 89 private boolean isShowing; 90 91 /** the preferred height if the toggle dialog is expanded */ 92 private int preferredHeight; 93 /** the label in the title bar which shows whether the toggle dialog is expanded or collapsed */ 94 private JLabel lblMinimized; 95 /** the JDialog displaying the toggle dialog as undocked dialog */ 96 private JDialog detachedDialog; 97 98 99 /** 100 * Constructor 101 * 102 * @param name the name of the dialog 103 * @param iconName the name of the icon to be displayed 104 * @param tooltip the tool tip 105 * @param shortcut the shortcut 106 * @param preferredHeight the preferred height for the dialog 107 */ 108 public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight) { 109 super(new BorderLayout()); 110 this.preferencePrefix = iconName; 111 init(name, iconName, tooltip, shortcut, preferredHeight); 112 } 113 114 /** 115 * Sets the visibility of all components in this toggle dialog, except the title bar 116 * 117 * @param visible true, if the components should be visible; false otherwise 118 */ 119 protected void setContentVisible(boolean visible) { 120 Component comps[] = getComponents(); 121 for(int i=0; i<comps.length; i++) { 122 if(comps[i] != titleBar) { 123 comps[i].setVisible(visible); 71 124 } 72 125 } … … 74 127 75 128 /** 76 * The action to toggle this dialog. 77 */ 78 public ToggleDialogAction action; 79 public final String prefName; 80 81 public JPanel parent; 82 WindowAdapter winadapter; 83 private ActionListener stickyActionListener; 84 private final JPanel titleBar = new JPanel(new GridBagLayout()); 85 public JLabel label = new JLabel(); 86 87 public ToggleDialog(final String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight) { 88 super(new BorderLayout()); 89 this.prefName = iconName; 90 ToggleDialogInit(name, iconName, tooltip, shortcut, preferredHeight); 91 } 92 93 private void ToggleDialogInit(final String name, String iconName, String tooltip, Shortcut shortcut, final int preferredHeight) { 129 * Initializes the toggle dialog 130 * 131 * @param name 132 * @param iconName 133 * @param tooltip 134 * @param shortcut 135 * @param preferredHeight 136 */ 137 private void init(String name, String iconName, String tooltip, Shortcut shortcut, final int preferredHeight) { 94 138 setPreferredSize(new Dimension(330,preferredHeight)); 95 action = new ToggleDialogAction(name, "dialogs/"+iconName, tooltip, shortcut, iconName);139 toggleAction = new ToggleDialogAction(name, "dialogs/"+iconName, tooltip, shortcut, iconName); 96 140 String helpId = "Dialog/"+getClass().getName().substring(getClass().getName().lastIndexOf('.')+1); 97 action.putValue("help", helpId.substring(0, helpId.length()-6)); 141 toggleAction.putValue("help", helpId.substring(0, helpId.length()-6)); 142 98 143 setLayout(new BorderLayout()); 99 144 100 145 // show the minimize button 101 final JLabel minimize = new JLabel(ImageProvider.get("misc", "normal")); 102 titleBar.add(minimize); 103 104 // scale down the dialog icon 105 ImageIcon inIcon = ImageProvider.get("dialogs", iconName); 106 ImageIcon smallIcon = new ImageIcon(inIcon.getImage().getScaledInstance(16 , 16, Image.SCALE_SMOOTH)); 107 JLabel firstPart = new JLabel(name, smallIcon, JLabel.TRAILING); 108 firstPart.setIconTextGap(8); 109 titleBar.add(firstPart, GBC.std()); 110 titleBar.add(Box.createHorizontalGlue(),GBC.std().fill(GBC.HORIZONTAL)); 111 112 final ActionListener hideActionListener = new ActionListener(){ 113 public void actionPerformed(ActionEvent e) { 114 boolean nowVisible = false; 115 Component comps[] = getComponents(); 116 for(int i=0; i<comps.length; i++) 117 { 118 if(comps[i] != titleBar) 119 { 120 if(comps[i].isVisible()) { 121 comps[i].setVisible(false); 122 } else { 123 comps[i].setVisible(true); 124 nowVisible = true; 125 } 126 } 127 } 128 129 Main.pref.put(action.prefname+".minimized", !nowVisible); 130 if(nowVisible == true) { 131 setPreferredSize(new Dimension(330,preferredHeight)); 132 setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); 133 minimize.setIcon(ImageProvider.get("misc", "normal")); 134 } else { 135 setPreferredSize(new Dimension(330,20)); 136 setMaximumSize(new Dimension(330,20)); 137 minimize.setIcon(ImageProvider.get("misc", "minimized")); 138 } 139 if(parent != null) 140 { 141 // doLayout() - workaround 142 parent.setVisible(false); 143 parent.setVisible(true); 144 } 145 } 146 }; 147 //hide.addActionListener(hideActionListener); 148 149 final MouseListener titleMouseListener = new MouseListener(){ 150 public void mouseClicked(MouseEvent e) { 151 hideActionListener.actionPerformed(null); 152 } 153 public void mouseEntered(MouseEvent e) {} 154 public void mouseExited(MouseEvent e) {} 155 public void mousePressed(MouseEvent e) {} 156 public void mouseReleased(MouseEvent e) {} 157 }; 158 titleBar.addMouseListener(titleMouseListener); 159 160 // show the sticky button 161 JButton sticky = new JButton(ImageProvider.get("misc", "sticky")); 162 sticky.setToolTipText(tr("Undock the panel")); 163 sticky.setBorder(BorderFactory.createEmptyBorder()); 164 stickyActionListener = new ActionListener(){ 165 public void actionPerformed(ActionEvent e) { 166 final JDialog f = new JDialog(JOptionPane.getFrameForComponent(Main.parent),false /* not modal*/); 167 if (parent != null) { 168 parent.remove(ToggleDialog.this); 169 } 170 f.getContentPane().add(ToggleDialog.this); 171 f.addWindowListener((winadapter = new WindowAdapter(){ 172 @Override public void windowClosing(WindowEvent e) { 173 f.getContentPane().removeAll(); 174 f.dispose(); 175 winadapter = null; 176 177 // doLayout() - workaround 178 setVisible(false); 179 parent.add(ToggleDialog.this); 180 if(Main.pref.getBoolean(action.prefname+".visible")) { 181 setVisible(true); 182 } 183 titleBar.setVisible(true); 184 if(e != null) { 185 Main.pref.put(action.prefname+".docked", true); 186 } 187 } 188 })); 189 f.addComponentListener(new ComponentAdapter(){ 190 @Override public void componentMoved(ComponentEvent e) { 191 Main.pref.put(action.prefname+".bounds", f.getX()+","+f.getY()+","+f.getWidth()+","+f.getHeight()); 192 } 193 }); 194 String bounds = Main.pref.get(action.prefname+".bounds",null); 195 if (bounds != null) { 196 String[] b = bounds.split(","); 197 f.setBounds(Integer.parseInt(b[0]),Integer.parseInt(b[1]),Integer.parseInt(b[2]),Integer.parseInt(b[3])); 198 } else { 199 f.pack(); 200 } 201 Main.pref.put(action.prefname+".docked", false); 202 f.setVisible(true); 203 titleBar.setVisible(false); 204 205 if (parent != null) { 206 // doLayout() - workaround 207 parent.setVisible(false); 208 parent.setVisible(true); 209 } 210 } 211 }; 212 sticky.addActionListener(stickyActionListener); 213 titleBar.add(sticky); 214 215 // show the close button 216 JButton close = new JButton(ImageProvider.get("misc", "close")); 217 close.setToolTipText(tr("Close this panel. You can reopen it with the buttons in the left toolbar.")); 218 close.setBorder(BorderFactory.createEmptyBorder()); 219 final ActionListener closeActionListener = new ActionListener(){ 220 public void actionPerformed(ActionEvent e) { 221 // fake an event to toggle dialog 222 action.actionPerformed(new ActionEvent(titleBar, 0, "")); 223 } 224 }; 225 close.addActionListener(closeActionListener); 226 titleBar.add(close); 227 146 lblMinimized = new JLabel(ImageProvider.get("misc", "normal")); 147 titleBar = new TitleBar(name, iconName); 228 148 add(titleBar, BorderLayout.NORTH); 229 titleBar.setToolTipText(tr("Click to minimize/maximize the panel content"));230 149 231 150 setVisible(false); 232 151 setBorder(BorderFactory.createEtchedBorder()); 233 152 234 if (!Main.pref.getBoolean(action.prefname+".docked", true)) { 153 docked = Main.pref.getBoolean(preferencePrefix+".docked", true); 154 if (!docked) { 235 155 EventQueue.invokeLater(new Runnable(){ 236 156 public void run() { 237 stickyActionListener.actionPerformed(null);157 detach(); 238 158 } 239 159 }); 240 160 } 241 if (Main.pref.getBoolean(action.prefname+".minimized", false)) { 161 collapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false); 162 if (collapsed) { 242 163 EventQueue.invokeLater(new Runnable(){ 243 164 public void run() { 244 titleMouseListener.mouseClicked(null);165 collapse(); 245 166 } 246 167 }); … … 248 169 } 249 170 250 public void close() 251 { 252 if(winadapter != null) { 253 winadapter.windowClosing(null); 254 } 255 } 256 257 public void setTitle(String title, boolean active) { 258 if(active) { 259 label.setText("<html><b>" + title + "</b>"); 171 /** 172 * Collapses the toggle dialog to the title bar only 173 * 174 */ 175 protected void collapse() { 176 setContentVisible(false); 177 this.collapsed = true; 178 Main.pref.put(preferencePrefix+".minimized", true); 179 setPreferredSize(new Dimension(330,20)); 180 setMaximumSize(new Dimension(330,20)); 181 lblMinimized.setIcon(ImageProvider.get("misc", "minimized")); 182 refreshToggleDialogsView(); 183 } 184 185 /** 186 * Expands the toggle dialog 187 */ 188 protected void expand() { 189 setContentVisible(true); 190 this.collapsed = false; 191 Main.pref.put(preferencePrefix+".minimized", false); 192 setPreferredSize(new Dimension(330,preferredHeight)); 193 setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); 194 lblMinimized.setIcon(ImageProvider.get("misc", "normal")); 195 refreshToggleDialogsView(); 196 } 197 198 /** 199 * Replies the index of this toggle dialog in the view of 200 * toggle dialog. 201 * 202 * @return 203 */ 204 protected int getDialogPosition() { 205 for (int i=0; i< parent.getComponentCount(); i++) { 206 String name = parent.getComponent(i).getName(); 207 if (name != null && name.equals(this.getName())) 208 return i; 209 } 210 return -1; 211 } 212 213 /** 214 * Displays the toggle dialog in the toggle dialog view on the right 215 * of the main map window. 216 * 217 */ 218 protected void dock() { 219 detachedDialog = null; 220 221 // check whether the toggle dialog view contains a placeholder 222 // for this toggle dialog. If so, replace it with this dialog. 223 // 224 int idx = getDialogPosition(); 225 if (idx > -1) { 226 parent.remove(idx); 227 parent.add(ToggleDialog.this,idx); 260 228 } else { 261 label.setText(title); 229 parent.add(ToggleDialog.this); 230 } 231 232 if(Main.pref.getBoolean(preferencePrefix+".visible")) { 233 setVisible(true); 234 } else { 235 setVisible(false); 236 } 237 titleBar.setVisible(true); 238 collapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false); 239 if (collapsed) { 240 collapse(); 241 } else { 242 expand(); 243 } 244 docked = true; 245 Main.pref.put(preferencePrefix+".docked", docked); 246 } 247 248 /** 249 * Display the dialog in a detached window. 250 * 251 */ 252 protected void detach() { 253 setContentVisible(true); 254 setVisible(true); 255 256 // replace the toggle dialog by an invisible place holder. Makes sure 257 // we can place the toggle dialog where it was when it becomes docked 258 // again. 259 // 260 if (parent != null) { 261 int idx = getDialogPosition(); 262 if (idx > -1) { 263 JPanel placeHolder = new JPanel(); 264 placeHolder.setName(this.getName()); 265 placeHolder.setVisible(false); 266 parent.add(placeHolder,idx); 267 } 268 parent.remove(ToggleDialog.this); 269 } 270 271 titleBar.setVisible(false); 272 detachedDialog = new DetachedDialog(); 273 detachedDialog.setVisible(true); 274 refreshToggleDialogsView(); 275 docked = false; 276 Main.pref.put(preferencePrefix+".docked", docked); 277 } 278 279 /** 280 * Hides the dialog 281 */ 282 public void hideDialog() { 283 if (!isShowing) return; 284 if (detachedDialog != null) { 285 detachedDialog.setVisible(false); 286 detachedDialog.getContentPane().removeAll(); 287 detachedDialog.dispose(); 288 } 289 setVisible(false); 290 isShowing = false; 291 refreshToggleDialogsView(); 292 toggleAction.putValue("selected", false); 293 } 294 295 /** 296 * Shows the dialog 297 */ 298 public void showDialog() { 299 if (isShowing) return; 300 if (!docked) { 301 detach(); 302 } else if (!collapsed) { 303 expand(); 304 setVisible(true); 305 refreshToggleDialogsView(); 306 } else { 307 setVisible(true); 308 refreshToggleDialogsView(); 309 } 310 isShowing = true; 311 toggleAction.putValue("selected", true); 312 } 313 314 /** 315 * Toggles between collapsed and expanded state 316 * 317 */ 318 protected void toggleExpandedState() { 319 if (this.collapsed) { 320 expand(); 321 } else { 322 collapse(); 323 } 324 } 325 326 /** 327 * Refreshes the layout of the parent toggle dialog view 328 * 329 */ 330 protected void refreshToggleDialogsView() { 331 if(parent != null){ 332 parent.validate(); 333 } 334 } 335 336 /** 337 * Closes the the detached dialog if this toggle dialog is currently displayed 338 * in a detached dialog. 339 * 340 */ 341 public void closeDetachedDialog() { 342 if (detachedDialog != null) { 343 detachedDialog.setVisible(false); 262 344 } 263 345 } … … 268 350 return "Dialog/"+help; 269 351 } 352 353 /** 354 * Replies the action to toggle the visible state of this toggle dialog 355 * 356 * @return the action to toggle the visible state of this toggle dialog 357 */ 358 public AbstractAction getToggleAction() { 359 return toggleAction; 360 } 361 362 /** 363 * Replies the prefix for the preference settings of this dialog. 364 * 365 * @return the prefix for the preference settings of this dialog. 366 */ 367 public String getPreferencePrefix() { 368 return preferencePrefix; 369 } 370 371 /** 372 * Sets the parent displaying all toggle dialogs 373 * 374 * @param parent the parent 375 */ 376 public void setParent(JPanel parent) { 377 this.parent = parent; 378 } 379 380 /** 381 * Replies the name of this toggle dialog 382 */ 383 @Override 384 public String getName() { 385 return "toggleDialog." + preferencePrefix; 386 } 387 388 /** 389 * Sets the title 390 * 391 * @param title the title 392 */ 393 public void setTitle(String title) { 394 titleBar.setTitle(title); 395 } 396 397 /** 398 * The title bar displayed in docked mode 399 * 400 */ 401 private class TitleBar extends JPanel { 402 private JLabel leftPart; 403 404 public TitleBar(String toggleDialogName, String iconName) { 405 setLayout(new GridBagLayout()); 406 lblMinimized = new JLabel(ImageProvider.get("misc", "normal")); 407 add(lblMinimized); 408 409 // scale down the dialog icon 410 ImageIcon inIcon = ImageProvider.get("dialogs", iconName); 411 ImageIcon smallIcon = new ImageIcon(inIcon.getImage().getScaledInstance(16 , 16, Image.SCALE_SMOOTH)); 412 leftPart = new JLabel("",smallIcon, JLabel.TRAILING); 413 leftPart.setIconTextGap(8); 414 add(leftPart, GBC.std()); 415 add(Box.createHorizontalGlue(),GBC.std().fill(GBC.HORIZONTAL)); 416 addMouseListener( 417 new MouseAdapter() { 418 @Override 419 public void mouseClicked(MouseEvent e) { 420 toggleExpandedState(); 421 } 422 } 423 ); 424 425 // show the sticky button 426 JButton sticky = new JButton(ImageProvider.get("misc", "sticky")); 427 sticky.setToolTipText(tr("Undock the panel")); 428 sticky.setBorder(BorderFactory.createEmptyBorder()); 429 sticky.addActionListener( 430 new ActionListener(){ 431 public void actionPerformed(ActionEvent e) { 432 detach(); 433 } 434 } 435 ); 436 add(sticky); 437 438 // show the close button 439 JButton close = new JButton(ImageProvider.get("misc", "close")); 440 close.setToolTipText(tr("Close this panel. You can reopen it with the buttons in the left toolbar.")); 441 close.setBorder(BorderFactory.createEmptyBorder()); 442 close.addActionListener( 443 new ActionListener(){ 444 public void actionPerformed(ActionEvent e) { 445 hideDialog(); 446 } 447 } 448 ); 449 add(close); 450 setToolTipText(tr("Click to minimize/maximize the panel content")); 451 setTitle(toggleDialogName); 452 } 453 454 public void setTitle(String title) { 455 leftPart.setText(title); 456 } 457 458 public String getTitle() { 459 return leftPart.getText(); 460 } 461 } 462 463 /** 464 * The dialog class used to display toggle dialogs in a detached window. 465 * 466 */ 467 private class DetachedDialog extends JDialog { 468 public DetachedDialog() { 469 super(JOptionPane.getFrameForComponent(Main.parent),false /* not modal*/); 470 getContentPane().add(ToggleDialog.this); 471 addWindowListener(new WindowAdapter(){ 472 @Override public void windowClosing(WindowEvent e) { 473 getContentPane().removeAll(); 474 dispose(); 475 dock(); 476 } 477 }); 478 addComponentListener(new ComponentAdapter(){ 479 @Override public void componentMoved(ComponentEvent e) { 480 rememberGeometry(); 481 } 482 }); 483 String bounds = Main.pref.get(preferencePrefix+".bounds",null); 484 if (bounds != null) { 485 String[] b = bounds.split(","); 486 setBounds(Integer.parseInt(b[0]),Integer.parseInt(b[1]),Integer.parseInt(b[2]),Integer.parseInt(b[3])); 487 } else { 488 pack(); 489 } 490 setTitle(titleBar.getTitle()); 491 } 492 493 protected void rememberGeometry() { 494 Main.pref.put(preferencePrefix+".bounds", detachedDialog.getX()+","+detachedDialog.getY()+","+detachedDialog.getWidth()+","+detachedDialog.getHeight()); 495 } 496 } 270 497 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java
r1814 r2005 121 121 122 122 if(ucArr.length != 0) { 123 setTitle(tr("Authors: {0}", ucArr.length) , true);123 setTitle(tr("Authors: {0}", ucArr.length)); 124 124 } else { 125 setTitle(tr("Authors") , false);125 setTitle(tr("Authors")); 126 126 } 127 127 }
Note:
See TracChangeset
for help on using the changeset viewer.