Changeset 6131 in josm for trunk/src


Ignore:
Timestamp:
2013-08-10T14:34:47+02:00 (11 years ago)
Author:
bastiK
Message:

see #6963 - optional help button for notifications; use notifications in Simplify Way action

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

Legend:

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

    r6084 r6131  
    2828import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    2929import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
     30import org.openstreetmap.josm.gui.Notification;
    3031import org.openstreetmap.josm.gui.help.HelpUtil;
    3132import org.openstreetmap.josm.tools.ImageProvider;
     
    4546
    4647    protected void alertSelectAtLeastOneWay() {
    47         HelpAwareOptionPane.showOptionDialog(
    48                 Main.parent,
    49                 tr("Please select at least one way to simplify."),
    50                 tr("Warning"),
    51                 JOptionPane.WARNING_MESSAGE,
    52                 HelpUtil.ht("/Action/SimplifyWay#SelectAWayToSimplify")
    53                 );
     48        new Notification(
     49                tr("Please select at least one way to simplify."))
     50                .setIcon(JOptionPane.WARNING_MESSAGE)
     51                .setDuration(Notification.TIME_SHORT)
     52                .setHelpTopic(HelpUtil.ht("/Action/SimplifyWay#SelectAWayToSimplify"))
     53                .show();
    5454    }
    5555
  • trunk/src/org/openstreetmap/josm/gui/Notification.java

    r6130 r6131  
    2222 * <pre>
    2323 *      Notification note = new Notification("Hi there!");
    24  *      note.setDuration(4000); // optional
    2524 *      note.setIcon(JOptionPane.INFORMATION_MESSAGE); // optional
     25 *      note.setDuration(Notification.TIME_SHORT); // optional
    2626 *      note.show();
    2727 * </pre>
     
    5252    public final static int TIME_VERY_LONG = Main.pref.getInteger("notification-time-very_long-ms", 20000);
    5353
     54    private Component content;
     55    private int duration;
    5456    private Icon icon;
    55     private int duration;
    56     private Component content;
     57    private String helpTopic;
    5758
    5859    public Notification() {
     
    8182     * Set the notification text. (Convenience method)
    8283     *
    83      * @param msg the message String
     84     * @param msg the message String. Will be wrapped in &lt;html&gt;, so
     85     * you can use &lt;br&gt; and other markup directly.
    8486     *
    8587     * @see #Notification(java.lang.String)
     
    9799     *
    98100     * @param duration the time (in milliseconds)
     101     * Preset values {@link #TIME_SHORT}, {@link #TIME_DEFAULT}, {@link #TIME_LONG}
     102     * and {@link #TIME_VERY_LONG} can be used.
    99103     * @return the current Object, for convenience
    100104     */
     
    141145    }
    142146
     147    /**
     148     * Display a help button at the bottom of the notification window.
     149     * @param helpTopic the help topic
     150     * @return the current Object, for convenience
     151     */
     152    public Notification setHelpTopic(String helpTopic) {
     153        this.helpTopic = helpTopic;
     154        return this;
     155    }
     156
    143157    public Component getContent() {
    144158        return content;
     
    153167    }
    154168
     169    public String getHelpTopic() {
     170        return helpTopic;
     171    }
     172
    155173    /**
    156174     * Display the notification.
  • trunk/src/org/openstreetmap/josm/gui/NotificationManager.java

    r6124 r6131  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import java.awt.BasicStroke;
     
    2325
    2426import javax.swing.AbstractAction;
     27import javax.swing.Action;
    2528import javax.swing.BorderFactory;
    2629import javax.swing.GroupLayout;
     
    3538
    3639import org.openstreetmap.josm.Main;
     40import org.openstreetmap.josm.gui.help.HelpBrowser;
     41import org.openstreetmap.josm.gui.help.HelpUtil;
    3742import org.openstreetmap.josm.tools.ImageProvider;
    3843
     
    187192        }
    188193
    189         private void build(Notification note) {
    190             JButton close = new JButton(new HideAction());
    191             close.setPreferredSize(new Dimension(50, 50));
     194        private void build(final Notification note) {
     195            JButton btnClose = new JButton(new HideAction());
     196            btnClose.setPreferredSize(new Dimension(50, 50));
     197            btnClose.setMargin(new Insets(0, 0, 1, 1));
     198            btnClose.setContentAreaFilled(false);
     199            // put it in JToolBar to get a better appearance
    192200            JToolBar tbClose = new JToolBar();
    193             close.setMargin(new Insets(0, 0, 1, 1));
    194             close.setContentAreaFilled(false);
    195 
    196201            tbClose.setFloatable(false);
    197202            tbClose.setBorderPainted(false);
    198203            tbClose.setOpaque(false);
    199             tbClose.add(close);
     204            tbClose.add(btnClose);
     205
     206            JToolBar tbHelp = null;
     207            if (note.getHelpTopic() != null) {
     208                JButton btnHelp = new JButton(tr("Help"));
     209                btnHelp.setIcon(ImageProvider.get("help"));
     210                btnHelp.setToolTipText(tr("Show help information"));
     211                HelpUtil.setHelpContext(btnHelp, note.getHelpTopic());
     212                btnHelp.addActionListener(new AbstractAction() {
     213                    @Override
     214                    public void actionPerformed(ActionEvent e) {
     215                        SwingUtilities.invokeLater(new Runnable() {
     216                            @Override
     217                            public void run() {
     218                                HelpBrowser.setUrlForHelpTopic(note.getHelpTopic());
     219                            }
     220                        });
     221                    }
     222                });
     223                btnHelp.setOpaque(false);
     224                tbHelp = new JToolBar();
     225                tbHelp.setFloatable(false);
     226                tbHelp.setBorderPainted(false);
     227                tbHelp.setOpaque(false);
     228                tbHelp.add(btnHelp);
     229            }
    200230
    201231            setOpaque(false);
     
    221251                hgroup.addComponent(icon);
    222252            }
    223             hgroup.addComponent(content).addComponent(tbClose);
     253            if (tbHelp != null) {
     254                hgroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
     255                        .addComponent(content)
     256                        .addComponent(tbHelp)
     257                );
     258            } else {
     259                hgroup.addComponent(content);
     260            }
     261            hgroup.addComponent(tbClose);
    224262            GroupLayout.ParallelGroup vgroup = layout.createParallelGroup();
    225263            if (icon != null) {
    226264                vgroup.addComponent(icon);
    227265            }
    228             vgroup.addComponent(content).addComponent(tbClose);
     266            vgroup.addComponent(content);
     267            vgroup.addComponent(tbClose);
    229268            layout.setHorizontalGroup(hgroup);
    230             layout.setVerticalGroup(vgroup);
     269
     270            if (tbHelp != null) {
     271                layout.setVerticalGroup(layout.createSequentialGroup()
     272                        .addGroup(vgroup)
     273                        .addComponent(tbHelp)
     274                );
     275            } else {
     276                layout.setVerticalGroup(vgroup);
     277            }
    231278
    232279            /*
Note: See TracChangeset for help on using the changeset viewer.