Changeset 2005 in josm


Ignore:
Timestamp:
2009-08-29T15:51:00+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #2367: panel will be empty when undocked from minimized state
cleanup in Toggle Dialog
new: toggle dialog remember position when detached
new: title in toggle dialog
NOTE: this changeset probably breaks plugins, in particular the validator plugin

Location:
trunk/src/org/openstreetmap/josm
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r1991 r2005  
    3131import org.openstreetmap.josm.gui.ExceptionDialogUtil;
    3232import org.openstreetmap.josm.gui.ExtendedDialog;
    33 import org.openstreetmap.josm.gui.OptionPaneUtil;
    3433import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    3534import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     
    113112            return;
    114113        if (Main.map == null) {
    115             OptionPaneUtil.showMessageDialog(
     114            JOptionPane.showMessageDialog(
    116115                    Main.parent,
    117116                    tr("Nothing to upload. Get some data first."),
     
    124123        ConflictCollection conflicts = Main.map.mapView.getEditLayer().getConflicts();
    125124        if (conflicts !=null && !conflicts.isEmpty()) {
    126             OptionPaneUtil.showMessageDialog(
     125            JOptionPane.showMessageDialog(
    127126                    Main.parent,
    128127                    tr("There are unresolved conflicts. You have to resolve these first."),
     
    130129                    JOptionPane.WARNING_MESSAGE
    131130            );
    132             Main.map.conflictDialog.action.button.setSelected(true);
    133             Main.map.conflictDialog.action.actionPerformed(null);
     131            Main.map.conflictDialog.showDialog();
    134132            return;
    135133        }
     
    152150
    153151        if (add.isEmpty() && update.isEmpty() && delete.isEmpty()) {
    154             OptionPaneUtil.showMessageDialog(
     152            JOptionPane.showMessageDialog(
    155153                    Main.parent,
    156154                    tr("No changes to upload."),
     
    226224        );
    227225        int optionsType = JOptionPane.YES_NO_CANCEL_OPTION;
    228         int ret = OptionPaneUtil.showOptionDialog(
     226        int ret = JOptionPane.showOptionDialog(
    229227                null,
    230228                msg,
     
    232230                optionsType,
    233231                JOptionPane.ERROR_MESSAGE,
     232                null,
    234233                options,
    235234                defaultOption
     
    265264        );
    266265        int optionsType = JOptionPane.YES_NO_OPTION;
    267         int ret = OptionPaneUtil.showOptionDialog(
     266        int ret = JOptionPane.showOptionDialog(
    268267                null,
    269268                msg,
     
    271270                optionsType,
    272271                JOptionPane.ERROR_MESSAGE,
     272                null,
    273273                options,
    274274                defaultOption
     
    385385                        ex.getDisplayMessage()
    386386                );
    387                 OptionPaneUtil.showMessageDialog(
     387                JOptionPane.showMessageDialog(
    388388                        Main.map,
    389389                        msg,
  • trunk/src/org/openstreetmap/josm/gui/IconToggleButton.java

    r1169 r2005  
    2828
    2929        Object o = action.getValue(Action.SHORT_DESCRIPTION);
    30         if (o != null)
     30        if (o != null) {
    3131            setToolTipText(o.toString());
     32        }
    3233
    3334        action.addPropertyChangeListener(this);
     
    4445            setSelected((Boolean)evt.getNewValue());
    4546            requestFocusInWindow();
     47        } else if (evt.getPropertyName().equals("selected")) {
     48            setSelected((Boolean)evt.getNewValue());
    4649        }
    4750    }
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r1890 r2005  
    7070     * instead of adding directly to this list.
    7171     */
    72     public JPanel toggleDialogs = new JPanel();
    73     public ArrayList<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>();
     72    private JPanel toggleDialogs = new JPanel();
     73    private ArrayList<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>();
    7474
    7575    public final ButtonGroup toolGroup = new ButtonGroup();
     
    135135    public void destroy() {
    136136        for (ToggleDialog t : allDialogs) {
    137             t.close();
     137            t.closeDetachedDialog();
    138138        }
    139139        for (int i = 0; i < toolBarActions.getComponentCount(); ++i)
     
    167167        for (Component c : toggleDialogs.getComponents()) {
    168168            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                }
    172173            }
    173174        }
     
    179180     */
    180181    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);
    184184        toolBarToggle.add(button);
    185185        toggleDialogs.add(dlg);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r1750 r2005  
    6262    private void buildList() {
    6363        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()));
    6565        } else {
    66             setTitle(tr("Command Stack"), false);
     66            setTitle(tr("Command Stack"));
    6767        }
    6868        if (Main.map == null || Main.map.mapView == null || Main.map.mapView.getEditLayer() == null)
  • trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r1990 r2005  
    793793        if(propertyData.getRowCount() != 0 || membershipData.getRowCount() != 0) {
    794794            setTitle(tr("Properties: {0} / Memberships: {1}",
    795                     propertyData.getRowCount(), membershipData.getRowCount()), true);
     795                    propertyData.getRowCount(), membershipData.getRowCount()));
    796796        } else {
    797             setTitle(tr("Properties / Memberships"), false);
     797            setTitle(tr("Properties / Memberships"));
    798798        }
    799799    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r1990 r2005  
    142142        }
    143143        if(getNumRelations() != 0) {
    144             setTitle(tr("Relations: {0}", Main.main.getCurrentDataSet().relations.size()), true);
     144            setTitle(tr("Relations: {0}", Main.main.getCurrentDataSet().relations.size()));
    145145        } else {
    146             setTitle(tr("Relations"), false);
     146            setTitle(tr("Relations"));
    147147        }
    148148        selectRelation(selected);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r1970 r2005  
    290290
    291291        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));
    293293        } else {
    294             setTitle(tr("Selection"), false);
     294            setTitle(tr("Selection"));
    295295        }
    296296    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r1999 r2005  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
    21package org.openstreetmap.josm.gui.dialogs;
    32
     
    54
    65import java.awt.BorderLayout;
     6import java.awt.Component;
    77import java.awt.Dimension;
    88import java.awt.EventQueue;
    99import java.awt.GridBagLayout;
    10 import java.awt.Component;
    1110import java.awt.Image;
    1211import java.awt.event.ActionEvent;
     
    1413import java.awt.event.ComponentAdapter;
    1514import java.awt.event.ComponentEvent;
     15import java.awt.event.MouseAdapter;
    1616import java.awt.event.MouseEvent;
    17 import java.awt.event.MouseListener;
    1817import java.awt.event.WindowAdapter;
    1918import java.awt.event.WindowEvent;
    20 
    21 import javax.swing.AbstractButton;
     19import java.util.logging.Logger;
     20
     21import javax.swing.AbstractAction;
    2222import javax.swing.BorderFactory;
    2323import javax.swing.Box;
     24import javax.swing.ImageIcon;
    2425import javax.swing.JButton;
    2526import javax.swing.JDialog;
    26 import javax.swing.JFrame;
    2727import javax.swing.JLabel;
    2828import javax.swing.JOptionPane;
    2929import javax.swing.JPanel;
    30 import javax.swing.ImageIcon;
    3130
    3231import org.openstreetmap.josm.Main;
     
    3837
    3938/**
    40  * This class is a toggle dialog that can be turned on and off. It is attached
    41  * to a ButtonModel.
     39 * This class is a toggle dialog that can be turned on and off.
     40 *
    4241 *
    43  * @author imi
    4442 */
    4543public 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     */
    4756    public final class ToggleDialogAction extends JosmAction {
    48         public final String prefname;
    49         public AbstractButton button;
    50 
    5157        private ToggleDialogAction(String name, String iconName, String tooltip, Shortcut shortcut, String prefname) {
    5258            super(name, iconName, tooltip, shortcut, false);
    53             this.prefname = prefname;
    5459        }
    5560
    5661        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();
    5970            }
    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);
    71124            }
    72125        }
     
    74127
    75128    /**
    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) {
    94138        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);
    96140        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
    98143        setLayout(new BorderLayout());
    99144
    100145        // 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);
    228148        add(titleBar, BorderLayout.NORTH);
    229         titleBar.setToolTipText(tr("Click to minimize/maximize the panel content"));
    230149
    231150        setVisible(false);
    232151        setBorder(BorderFactory.createEtchedBorder());
    233152
    234         if (!Main.pref.getBoolean(action.prefname+".docked", true)) {
     153        docked = Main.pref.getBoolean(preferencePrefix+".docked", true);
     154        if (!docked) {
    235155            EventQueue.invokeLater(new Runnable(){
    236156                public void run() {
    237                     stickyActionListener.actionPerformed(null);
     157                    detach();
    238158                }
    239159            });
    240160        }
    241         if (Main.pref.getBoolean(action.prefname+".minimized", false)) {
     161        collapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false);
     162        if (collapsed) {
    242163            EventQueue.invokeLater(new Runnable(){
    243164                public void run() {
    244                     titleMouseListener.mouseClicked(null);
     165                    collapse();
    245166                }
    246167            });
     
    248169    }
    249170
    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);
    260228        } 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);
    262344        }
    263345    }
     
    268350        return "Dialog/"+help;
    269351    }
     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    }
    270497}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java

    r1814 r2005  
    121121
    122122        if(ucArr.length != 0) {
    123             setTitle(tr("Authors: {0}", ucArr.length), true);
     123            setTitle(tr("Authors: {0}", ucArr.length));
    124124        } else {
    125             setTitle(tr("Authors"), false);
     125            setTitle(tr("Authors"));
    126126        }
    127127    }
Note: See TracChangeset for help on using the changeset viewer.