Changeset 2387 in josm for trunk


Ignore:
Timestamp:
2009-11-02T19:26:51+01:00 (14 years ago)
Author:
Gubaer
Message:

More and improved context sensitive help, see #2882

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

Legend:

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

    r2289 r2387  
    22package org.openstreetmap.josm.gui;
    33
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56
     
    3637     */
    3738    public static void explainOsmApiInitializationException(OsmApiInitializationException e) {
    38         JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainOsmApiInitializationException(e), tr("Error"),
    39                 JOptionPane.ERROR_MESSAGE);
     39        HelpAwareOptionPane.showOptionDialog(
     40                Main.parent,
     41                ExceptionUtil.explainOsmApiInitializationException(e),
     42                tr("Error"),
     43                JOptionPane.ERROR_MESSAGE,
     44                ht("/ErrorMessages#OsmApiInitializationException")
     45        );
    4046    }
    4147
     
    4652     */
    4753    public static void explainOsmChangesetCloseException(OsmChangesetCloseException e) {
    48         JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainOsmChangesetCloseException(e), tr("Error"),
    49                 JOptionPane.ERROR_MESSAGE);
     54        HelpAwareOptionPane.showOptionDialog(
     55                Main.parent,
     56                ExceptionUtil.explainOsmChangesetCloseException(e),
     57                tr("Error"),
     58                JOptionPane.ERROR_MESSAGE,
     59                ht("/ErrorMessages#OsmChangesetCloseException")
     60        );
    5061    }
    5162
     
    5667     */
    5768    public static void explainPreconditionFailed(OsmApiException e) {
    58         JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainPreconditionFailed(e),
    59                 tr("Precondition violation"), JOptionPane.ERROR_MESSAGE);
     69        HelpAwareOptionPane.showOptionDialog(
     70                Main.parent,
     71                ExceptionUtil.explainPreconditionFailed(e),
     72                tr("Precondition violation"),
     73                JOptionPane.ERROR_MESSAGE,
     74                ht("/ErrorMessages#OsmApiException")
     75        );
    6076    }
    6177
     
    6682     */
    6783    public static void explainGeneric(Exception e) {
    68         JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainGeneric(e), tr("Error"),
    69                 JOptionPane.ERROR_MESSAGE);
     84        HelpAwareOptionPane.showOptionDialog(
     85                Main.parent,
     86                ExceptionUtil.explainGeneric(e),
     87                tr("Error"),
     88                JOptionPane.ERROR_MESSAGE,
     89                ht("/ErrorMessages#GenericException")
     90        );
    7091    }
    7192
     
    79100
    80101    public static void explainSecurityException(OsmTransferException e) {
    81         JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainSecurityException(e), tr("Security exception"),
    82                 JOptionPane.ERROR_MESSAGE);
     102        HelpAwareOptionPane.showOptionDialog(
     103                Main.parent,
     104                ExceptionUtil.explainSecurityException(e),
     105                tr("Security exception"),
     106                JOptionPane.ERROR_MESSAGE,
     107                ht("/ErrorMessages#SecurityException")
     108        );
    83109    }
    84110
     
    92118
    93119    public static void explainNestedSocketException(OsmTransferException e) {
    94         JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainNestedSocketException(e),
    95                 tr("Network exception"), JOptionPane.ERROR_MESSAGE);
     120        HelpAwareOptionPane.showOptionDialog(
     121                Main.parent,
     122                ExceptionUtil.explainNestedSocketException(e),
     123                tr("Network exception"),
     124                JOptionPane.ERROR_MESSAGE,
     125                ht("/ErrorMessages#NestedSocketException")
     126        );
    96127    }
    97128
     
    105136
    106137    public static void explainNestedIOException(OsmTransferException e) {
    107         JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainNestedIOException(e), tr("IO Exception"),
    108                 JOptionPane.ERROR_MESSAGE);
     138        HelpAwareOptionPane.showOptionDialog(
     139                Main.parent,
     140                ExceptionUtil.explainNestedIOException(e),
     141                tr("IO Exception"),
     142                JOptionPane.ERROR_MESSAGE,
     143                ht("/ErrorMessages#NestedIOException")
     144        );
    109145    }
    110146
     
    117153
    118154    public static void explainInternalServerError(OsmTransferException e) {
    119         JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainInternalServerError(e),
    120                 tr("Internal Server Error"), JOptionPane.ERROR_MESSAGE);
     155        HelpAwareOptionPane.showOptionDialog(
     156                Main.parent,
     157                ExceptionUtil.explainInternalServerError(e),
     158                tr("Internal Server Error"),
     159                JOptionPane.ERROR_MESSAGE,
     160                ht("/ErrorMessages#InternalServerError")
     161        );
    121162    }
    122163
     
    128169     */
    129170    public static void explainBadRequest(OsmApiException e) {
    130         JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainBadRequest(e), tr("Bad Request"),
    131                 JOptionPane.ERROR_MESSAGE);
     171        HelpAwareOptionPane.showOptionDialog(
     172                Main.parent,
     173                ExceptionUtil.explainBadRequest(e),
     174                tr("Bad Request"),
     175                JOptionPane.ERROR_MESSAGE,
     176                ht("/ErrorMessages#BadRequest")
     177        );
    132178    }
    133179
     
    139185     */
    140186    public static void explainNotFound(OsmApiException e) {
    141         JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainNotFound(e), tr("Not Found"),
    142                 JOptionPane.ERROR_MESSAGE);
     187        HelpAwareOptionPane.showOptionDialog(
     188                Main.parent,
     189                ExceptionUtil.explainNotFound(e),
     190                tr("Not Found"),
     191                JOptionPane.ERROR_MESSAGE,
     192                ht("/ErrorMessages#NotFound")
     193        );
    143194    }
    144195
     
    149200     */
    150201    public static void explainConflict(OsmApiException e) {
    151         JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainConflict(e), tr("Conflict"),
    152                 JOptionPane.ERROR_MESSAGE);
     202        HelpAwareOptionPane.showOptionDialog(
     203                Main.parent,
     204                ExceptionUtil.explainConflict(e),
     205                tr("Conflict"),
     206                JOptionPane.ERROR_MESSAGE,
     207                ht("/ErrorMessages#Conflict")
     208        );
    153209    }
    154210
     
    162218
    163219    public static void explainNestedUnkonwnHostException(OsmTransferException e) {
    164         JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainNestedUnkonwnHostException(e),
    165                 tr("Unknown host"), JOptionPane.ERROR_MESSAGE);
     220        HelpAwareOptionPane.showOptionDialog(
     221                Main.parent,
     222                ExceptionUtil.explainNestedUnkonwnHostException(e),
     223                tr("Unknown host"),
     224                JOptionPane.ERROR_MESSAGE,
     225                ht("/ErrorMessages#UnknownHost")
     226        );
    166227    }
    167228
     
    258319     */
    259320    public static void explainGoneForUnknownPrimitive(OsmApiException e) {
    260         JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainGoneForUnknownPrimitive(e),
    261                 tr("Object deleted"), JOptionPane.ERROR_MESSAGE);
    262 
     321        HelpAwareOptionPane.showOptionDialog(
     322                Main.parent,
     323                ExceptionUtil.explainGoneForUnknownPrimitive(e),
     324                tr("Object deleted"),
     325                JOptionPane.ERROR_MESSAGE,
     326                ht("/ErrorMessages#GoneForUnknownPrimitive")
     327        );
    263328    }
    264329
  • trunk/src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java

    r2315 r2387  
    66import java.awt.Component;
    77import java.awt.event.ActionEvent;
    8 import java.awt.event.ActionListener;
    98import java.awt.event.KeyEvent;
    109import java.awt.event.WindowAdapter;
     
    1413
    1514import javax.swing.AbstractAction;
     15import javax.swing.Action;
    1616import javax.swing.Icon;
    1717import javax.swing.JButton;
     18import javax.swing.JComponent;
    1819import javax.swing.JDialog;
    1920import javax.swing.JLabel;
     
    108109        b.setToolTipText(tr("Show help information"));
    109110        HelpUtil.setHelpContext(b, helpTopic);
    110         b.addActionListener(
    111                 new ActionListener() {
    112                     public void actionPerformed(ActionEvent e) {
    113                         HelpBrowserProxy.getInstance().setUrlForHelpTopic(helpTopic);
    114                     }
    115                 }
    116         );
     111        Action a = new AbstractAction() {
     112            public void actionPerformed(ActionEvent e) {
     113                HelpBrowserProxy.getInstance().setUrlForHelpTopic(helpTopic);
     114            }
     115        };
     116        b.addActionListener(a);
     117        b.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "enter");
     118        b.getActionMap().put("enter", a);
    117119        return b;
    118120    }
     
    126128     * <code>helpTopic</code> is the trailing part of a JOSM online help URL, i.e. the part after the leading
    127129     * <code>http://josm.openstreetmap.de/wiki/Help</code>. It should start with a leading '/' and it
    128      * may include and anchor after a '#'.
     130     * may include an anchor after a '#'.
    129131     *
    130132     * <strong>Examples</strong>
     
    210212                }
    211213        );
     214        dialog.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0), "close");
     215        dialog.getRootPane().getActionMap().put("close", new AbstractAction() {
     216            public void actionPerformed(ActionEvent e) {
     217                pane.setValue(JOptionPane.CLOSED_OPTION);
     218                dialog.setVisible(false);
     219            }}
     220        );
     221
    212222        if (options != null) {
    213223            for (int i=0; i < options.length;i++) {
    214224                final DefaultAction action = new DefaultAction(dialog, pane, i);
    215225                buttons.get(i).addActionListener(action);
    216                 buttons.get(i).getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "enter");
     226                buttons.get(i).getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "enter");
    217227                buttons.get(i).getActionMap().put("enter", action);
    218228            }
     
    220230            final DefaultAction action = new DefaultAction(dialog, pane, 0);
    221231            buttons.get(0).addActionListener(action);
    222             buttons.get(0).getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "enter");
     232            buttons.get(0).getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "enter");
    223233            buttons.get(0).getActionMap().put("enter", action);
    224234        }
     
    232242        return (Integer)pane.getValue();
    233243    }
     244
     245    /**
     246     *
     247     * @param parentComponent
     248     * @param msg
     249     * @param title
     250     * @param messageType
     251     * @param helpTopic
     252     * @return
     253     * @see #showOptionDialog(Component, Object, String, int, Icon, ButtonSpec[], ButtonSpec, String)
     254     */
     255    static public int showOptionDialog(Component parentComponent, Object msg, String title, int messageType,final String helpTopic)  {
     256        return showOptionDialog(parentComponent, msg, title, messageType, null,null,null, helpTopic);
     257    }
    234258}
  • trunk/src/org/openstreetmap/josm/gui/download/BookmarkSelection.java

    r2344 r2387  
    6161        pnl.setLayout(new GridBagLayout());
    6262        GridBagConstraints gc = new GridBagConstraints();
    63 //        gc.fill = GridBagConstraints.HORIZONTAL;
    64 //        gc.weightx = 1.0;
    65 //        gc.weighty = 0.0;
    66 //        pnl.add(new JButton(actAdd = new AddAction()), gc);
    67 
    6863        gc.gridy = 0;
    6964        RemoveAction removeAction = new RemoveAction();
  • trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java

    r2289 r2387  
    1818
    1919import org.openstreetmap.josm.Main;
    20 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
    21 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    2220import org.openstreetmap.josm.io.OsmApi;
    2321import org.openstreetmap.josm.io.OsmApiException;
     
    144142            msg = tr(
    145143                    "<html>The server reported that it has detected a conflict.<br>" +
    146                     "Error message (untranslated):<br>" +
    147                     "{0}",
     144                    "Error message (untranslated):<br>{0}</html>",
    148145                    msg
    149146            );
Note: See TracChangeset for help on using the changeset viewer.