Changeset 4355 in josm


Ignore:
Timestamp:
2011-08-27T15:50:37+02:00 (13 years ago)
Author:
stoecker
Message:

see #6731 - add dynamic button visibility (needs dialog.dynamic.buttons=true)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r4354 r4355  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.AWTEvent;
    67import java.awt.BorderLayout;
    78import java.awt.Component;
     
    1213import java.awt.GridLayout;
    1314import java.awt.Image;
     15import java.awt.Point;
    1416import java.awt.Rectangle;
     17import java.awt.Toolkit;
     18import java.awt.event.AWTEventListener;
    1519import java.awt.event.ActionEvent;
    1620import java.awt.event.ActionListener;
     
    5155 *
    5256 */
    53 public class ToggleDialog extends JPanel implements Helpful {
     57public class ToggleDialog extends JPanel implements Helpful, AWTEventListener {
    5458
    5559    /** The action to toggle this dialog */
     
    8993    protected JToggleButton button;
    9094    protected boolean buttonHidden;
     95    private JPanel buttonsPanel;
    9196
    9297    /**
     
    671676            add(data, BorderLayout.CENTER);
    672677        if(buttons != null && buttons.size() != 0) {
    673             JPanel buttonsPanel = new JPanel(Main.pref.getBoolean("dialog.align.left", false)
     678            buttonsPanel = new JPanel(Main.pref.getBoolean("dialog.align.left", false)
    674679                ? new FlowLayout(FlowLayout.LEFT) : new GridLayout(1,buttons.size()));
    675680            for(SideButton button : buttons)
    676681                buttonsPanel.add(button);
    677682            add(buttonsPanel, BorderLayout.SOUTH);
     683            if(Main.pref.getBoolean("dialog.dynamic.buttons", false)) {
     684                Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_MOTION_EVENT_MASK);
     685                buttonsPanel.setVisible(false);
     686            }
     687        }
     688    }
     689
     690    @Override
     691    public void eventDispatched(AWTEvent event) {
     692        if(isShowing()) {
     693            Rectangle b = this.getBounds();
     694            b.setLocation(getLocationOnScreen());
     695            if (b.contains(((MouseEvent)event).getLocationOnScreen())) {
     696                if(!buttonsPanel.isVisible()) {
     697                    buttonsPanel.setVisible(true);
     698                }
     699            } else if (buttonsPanel.isVisible()) {
     700                buttonsPanel.setVisible(false);
     701            }
    678702        }
    679703    }
Note: See TracChangeset for help on using the changeset viewer.