Ignore:
Timestamp:
2012-12-25T23:43:22+01:00 (13 years ago)
Author:
Don-vip
Message:

Allow to access directly to validator preferences from validator dialog with a small preferences button left to pin button.
Generic approach in order to be reused by plugins using dialogs.
This leads to some changes in preferences settings system, but without any break in compatibility.
The only impact is the deprecation of some public JTabbedPane fields, that will be removed mid-2013.

File:
1 edited

Legend:

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

    r5463 r5631  
    5757import org.openstreetmap.josm.gui.help.HelpUtil;
    5858import org.openstreetmap.josm.gui.help.Helpful;
     59import org.openstreetmap.josm.gui.preferences.PreferenceDialog;
     60import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
     61import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
     62import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
    5963import org.openstreetmap.josm.tools.Destroyable;
    6064import org.openstreetmap.josm.tools.GBC;
     
    139143     */
    140144    protected JCheckBoxMenuItem windowMenuItem;
     145   
     146    /**
     147     * The linked preferences class (optional). If set, accessible from the title bar with a dedicated button
     148     */
     149    protected Class<? extends PreferenceSetting> preferenceClass;
    141150
    142151    /**
     
    146155    public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight) {
    147156        this(name, iconName, tooltip, shortcut, preferredHeight, false);
     157    }
     158    /**
     159     * Constructor
     160     * (see below)
     161     */
     162    public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight, boolean defShow) {
     163        this(name, iconName, tooltip, shortcut, preferredHeight, defShow, null);
    148164    }
    149165    /**
     
    156172     * @param preferredHeight the preferred height for the dialog
    157173     * @param defShow if the dialog should be shown by default, if there is no preference
    158      */
    159     public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight, boolean defShow) {
     174     * @param prefClass the preferences settings class, or null if not applicable
     175     */
     176    public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight, boolean defShow, Class<? extends PreferenceSetting> prefClass) {
    160177        super(new BorderLayout());
    161178        this.preferencePrefix = iconName;
    162179        this.name = name;
     180        this.preferenceClass = prefClass;
    163181
    164182        /** Use the full width of the parent element */
     
    522540                add(buttonsHide);
    523541            }
     542           
     543            // show the pref button if applicable
     544            if (preferenceClass != null) {
     545                inIcon = ImageProvider.get("preference");
     546                smallIcon = new ImageIcon(inIcon.getImage().getScaledInstance(16 , 16, Image.SCALE_SMOOTH));
     547                JButton pref = new JButton(smallIcon);
     548                pref.setToolTipText(tr("Open preferences for this panel"));
     549                pref.setBorder(BorderFactory.createEmptyBorder());
     550                pref.addActionListener(
     551                        new ActionListener(){
     552                            @SuppressWarnings("unchecked")
     553                            public void actionPerformed(ActionEvent e) {
     554                                final PreferenceDialog p = new PreferenceDialog(Main.parent);
     555                                if (TabPreferenceSetting.class.isAssignableFrom(preferenceClass)) {
     556                                    p.selectPreferencesTabByClass((Class<? extends TabPreferenceSetting>) preferenceClass);
     557                                } else if (SubPreferenceSetting.class.isAssignableFrom(preferenceClass)) {
     558                                    p.selectSubPreferencesTabByClass((Class<? extends SubPreferenceSetting>) preferenceClass);
     559                                }
     560                                p.setVisible(true);
     561                            }
     562                        }
     563                        );
     564                add(pref);
     565            }
    524566
    525567            // show the sticky button
Note: See TracChangeset for help on using the changeset viewer.