Ignore:
Timestamp:
2009-10-13T20:34:11+02:00 (15 years ago)
Author:
Gubaer
Message:

Improved Download Location Dialog and created help page.
ExtendedDialog now supports context sensitive help including a help button.
ExtendedDialog now supports tooltip texts for buttons in the button row.

File:
1 edited

Legend:

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

    r2168 r2285  
    2323
    2424import org.openstreetmap.josm.Main;
     25import org.openstreetmap.josm.gui.help.HelpBrowserProxy;
     26import org.openstreetmap.josm.gui.help.HelpBuilder;
    2527import org.openstreetmap.josm.tools.GBC;
    2628import org.openstreetmap.josm.tools.ImageProvider;
     
    4143    private Component content;
    4244    private final String[] bTexts;
     45    private String[] bToolTipTexts;
    4346    private String[] bIcons;
     47
     48    /** true, if the dialog should include a help button */
     49    private boolean showHelpButton;
     50    /** the help topic */
     51    private String helpTopic;
     52
    4453    /**
    4554     * set to true if the content of the extended dialog should
     
    99108
    100109    /**
     110     * Allows decorating the buttons with tooltips. Expects an String[] with translated
     111     * tooltip texts.
     112     *
     113     * @param toolTipTexts the tool tip texts. Ignored, if null.
     114     */
     115    public void setToolTipTexts(String[] toolTipTexts) {
     116        this.bToolTipTexts = toolTipTexts;
     117    }
     118
     119    /**
    101120     * Sets the content that will be displayed in the message dialog.
    102121     *
     
    187206                button.setIcon(ImageProvider.get(bIcons[i]));
    188207            }
     208            if (bToolTipTexts != null && i < bToolTipTexts.length && bToolTipTexts[i] != null) {
     209                button.setToolTipText(bToolTipTexts[i]);
     210            }
    189211
    190212            if(i == 0) {
     
    193215            buttonsPanel.add(button, GBC.std().insets(2,2,2,2));
    194216            buttons.add(button);
     217        }
     218        if (showHelpButton) {
     219            buttonsPanel.add(new JButton(new HelpAction()), GBC.std().insets(2,2,2,2));
     220            HelpBuilder.setHelpContext(getRootPane(),helpTopic);
    195221        }
    196222
     
    396422        return lbl;
    397423    }
     424
     425    /**
     426     * Configures how this dialog support for context sensitive help.
     427     * <ul>
     428     *  <li>if helpTopic is null, the dialog doesn't provide context sensitive help</li>
     429     *  <li>if helpTopic != null, the dialog redirect user to the help page for this helpTopic when
     430     *  the user clicks F1 in the dialog</li>
     431     *  <li>if showHelpButton is true, the dialog displays "Help" button (rightmost button in
     432     *  the button row)</li>
     433     * </ul>
     434     *
     435     * @param helpTopic the help topic
     436     * @param showHelpButton true, if the dialog displays a help button
     437     */
     438    public void configureContextsensitiveHelp(String helpTopic, boolean showHelpButton) {
     439        this.helpTopic = helpTopic;
     440        this.showHelpButton = showHelpButton;
     441    }
     442
     443
     444    class HelpAction extends AbstractAction {
     445        public HelpAction() {
     446            putValue(SHORT_DESCRIPTION, tr("Show help information"));
     447            putValue(NAME, tr("Help"));
     448            putValue(SMALL_ICON, ImageProvider.get("help"));
     449        }
     450
     451        public void actionPerformed(ActionEvent e) {
     452            HelpBrowserProxy.getInstance().setUrlForHelpTopic(helpTopic);
     453        }
     454    }
    398455}
Note: See TracChangeset for help on using the changeset viewer.