Changeset 2255 in josm


Ignore:
Timestamp:
2009-10-07T21:25:15+02:00 (15 years ago)
Author:
Gubaer
Message:

New utility class for help context aware option dialogs
Improved context sensitive help in the context of conflict resolution, see also Conflict List Dialog

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

Legend:

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

    r2253 r2255  
    3535import org.openstreetmap.josm.gui.DefaultNameFormatter;
    3636import org.openstreetmap.josm.gui.ExceptionDialogUtil;
     37import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    3738import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     39import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    3840import org.openstreetmap.josm.gui.help.HelpBrowser;
    3941import org.openstreetmap.josm.gui.help.HelpBuilder;
     
    230232     */
    231233    protected void handleUploadConflictForKnownConflict(final OsmPrimitiveType primitiveType, final long id, String serverVersion, String myVersion) {
    232         JButton[] options = new JButton[] {
    233                 new JButton(tr("Synchronize {0} {1} only", tr(primitiveType.getAPIName()), id)),
    234                 new JButton(tr("Synchronize entire dataset")),
    235                 new JButton(tr("Cancel")),
    236                 new JButton(tr("Help"))
     234        String lbl = "";
     235        switch(primitiveType) {
     236            case NODE: lbl =  tr("Synchronize node {0} only", id); break;
     237            case WAY: lbl =  tr("Synchronize way {0} only", id); break;
     238            case RELATION: lbl =  tr("Synchronize relation {0} only", id); break;
     239        }
     240        ButtonSpec[] spec = new ButtonSpec[] {
     241                new ButtonSpec(
     242                        lbl,
     243                        ImageProvider.get("updatedata"),
     244                        null,
     245                        null
     246                ),
     247                new ButtonSpec(
     248                        tr("Synchronize entire dataset"),
     249                        ImageProvider.get("updatedata"),
     250                        null,
     251                        null
     252                ),
     253                new ButtonSpec(
     254                        tr("Cancel"),
     255                        ImageProvider.get("cancel"),
     256                        null,
     257                        null
     258                )
    237259        };
    238         options[0].setIcon(ImageProvider.get("updatedata"));
    239         options[1].setIcon(ImageProvider.get("updatedata"));
    240         options[2].setIcon(ImageProvider.get("cancel"));
    241         options[3].setIcon(ImageProvider.get("help"));
    242260        String msg =  tr("<html>Uploading <strong>failed</strong> because the server has a newer version of one<br>"
    243261                + "of your nodes, ways, or relations.<br>"
     
    249267                + "Click <strong>{6}</strong> to abort and continue editing.<br></html>",
    250268                tr(primitiveType.getAPIName()), id, serverVersion, myVersion,
    251                 options[0].getText(), options[1].getText(), options[2].getText()
     269                spec[0].text, spec[1].text, spec[2].text
    252270        );
    253         final JOptionPane pane = new JOptionPane(
     271        int ret = HelpAwareOptionPane.showOptionDialog(
     272                Main.parent,
    254273                msg,
     274                tr("Conflicts detected"),
    255275                JOptionPane.ERROR_MESSAGE,
    256                 JOptionPane.DEFAULT_OPTION,
    257276                null,
    258                 options,
    259                 options[0]
     277                spec,
     278                spec[0],
     279                "Concepts/Conflict"
    260280        );
    261         final JDialog dialog = new JDialog(
    262                 JOptionPane.getFrameForComponent(Main.parent),
    263                 tr("Conflicts detected"),
    264                 true);
    265         options[0].addActionListener(
    266                 new ActionListener() {
    267                     public void actionPerformed(ActionEvent e) {
    268                         dialog.setVisible(false);
    269                         synchronizePrimitive(primitiveType, id);
    270                     }
    271                 }
    272         );
    273         options[1].addActionListener(
    274                 new ActionListener() {
    275                     public void actionPerformed(ActionEvent e) {
    276                         dialog.setVisible(false);
    277                         synchronizeDataSet();
    278                     }
    279                 }
    280         );
    281         options[2].addActionListener(
    282                 new ActionListener() {
    283                     public void actionPerformed(ActionEvent e) {
    284                         dialog.setVisible(false);
    285                     }
    286                 }
    287         );
    288         options[3].addActionListener(
    289                 new ActionListener() {
    290                     public void actionPerformed(ActionEvent e) {
    291                         HelpBrowser b = new HelpBrowser();
    292                         b.setUrlForHelpTopic("Help/Concepts/Conflict");
    293                         b.setVisible(true);
    294                     }
    295                 }
    296         );
    297         dialog.setContentPane(pane);
    298         dialog.pack();
    299         HelpBuilder.setHelpContext(dialog.getRootPane(), "Concepts/Conflict");
    300         WindowGeometry.centerOnScreen(dialog.getSize()).applySafe(dialog);
    301         dialog.setVisible(true);
     281        switch(ret) {
     282            case 0: synchronizePrimitive(primitiveType, id); break;
     283            case 1: synchronizeDataSet(); break;
     284            default: return;
     285        }
    302286    }
    303287
     
    308292     */
    309293    protected void handleUploadConflictForUnknownConflict() {
    310         JButton[] options = new JButton[] {
    311                 new JButton(tr("Synchronize entire dataset")),
    312                 new JButton(tr("Cancel")),
    313                 new JButton(tr("Help"))
     294        ButtonSpec[] spec = new ButtonSpec[] {
     295                new ButtonSpec(
     296                        tr("Synchronize entire dataset"),
     297                        ImageProvider.get("updatedata"),
     298                        null,
     299                        null
     300                ),
     301                new ButtonSpec(
     302                        tr("Cancel"),
     303                        ImageProvider.get("cancel"),
     304                        null,
     305                        null
     306                )
    314307        };
    315         Object defaultOption = options[0];
    316308        String msg =  tr("<html>Uploading <strong>failed</strong> because the server has a newer version of one<br>"
    317309                + "of your nodes, ways, or relations.<br>"
     
    319311                + "Click <strong>{0}</strong> to synchronize the entire local dataset with the server.<br>"
    320312                + "Click <strong>{1}</strong> to abort and continue editing.<br></html>",
    321                 options[0].getText(), options[1].getText()
     313                spec[0].text, spec[1].text
    322314        );
    323         final JOptionPane pane = new JOptionPane(
     315        int ret = HelpAwareOptionPane.showOptionDialog(
     316                Main.parent,
    324317                msg,
     318                tr("Conflicts detected"),
    325319                JOptionPane.ERROR_MESSAGE,
    326                 JOptionPane.DEFAULT_OPTION,
    327320                null,
    328                 options,
    329                 options[0]
     321                spec,
     322                spec[0],
     323                "Concepts/Conflict"
    330324        );
    331         final JDialog dialog = new JDialog(
    332                 JOptionPane.getFrameForComponent(Main.parent),
    333                 tr("Conflicts detected"),
    334                 true);
    335 
    336         options[0].addActionListener(
    337                 new ActionListener() {
    338                     public void actionPerformed(ActionEvent e) {
    339                         dialog.setVisible(false);
    340                         synchronizeDataSet();
    341                     }
    342                 }
    343         );
    344         options[1].addActionListener(
    345                 new ActionListener() {
    346                     public void actionPerformed(ActionEvent e) {
    347                         dialog.setVisible(false);
    348                     }
    349                 }
    350         );
    351         options[2].addActionListener(
    352                 new ActionListener() {
    353                     public void actionPerformed(ActionEvent e) {
    354                         HelpBrowser b = new HelpBrowser();
    355                         b.setUrlForHelpTopic("Help/Concepts/Conflict");
    356                         b.setVisible(true);
    357                     }
    358                 }
    359         );
    360         dialog.setContentPane(pane);
    361         dialog.pack();
    362         HelpBuilder.setHelpContext(dialog.getRootPane(), "Concepts/Conflict");
    363         WindowGeometry.centerOnScreen(dialog.getSize()).applySafe(dialog);
    364         dialog.setVisible(true);
     325        if (ret == 0) {
     326            synchronizeDataSet();
     327        }
    365328    }
    366329
     
    533496            } catch (Exception sxe) {
    534497                if (uploadCancelled) {
    535                     System.out.println("Ignoring exception caught because upload is cancelled. Exception is: " + sxe.toString());
     498                    System.out.println("Ignoring exception caught because upload is canceled. Exception is: " + sxe.toString());
    536499                    return;
    537500                }
  • trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java

    r2253 r2255  
    4646                tr("Upload selection"),
    4747                "uploadselection",
    48                 tr("Upload all changes in the current current selection to the OSM server."),
     48                tr("Upload all changes in the current selection to the OSM server."),
    4949                null, /* no shortcut */
    5050                true);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r2252 r2255  
    118118     */
    119119    public ConflictDialog() {
    120         super(tr("Conflict"), "conflict", tr("Merging conflicts."),
     120        super(tr("Conflict"), "conflict", tr("Resolve conflicts."),
    121121                Shortcut.registerShortcut("subwindow:conflict", tr("Toggle: {0}", tr("Conflict")), KeyEvent.VK_C, Shortcut.GROUP_LAYER), 100);
    122122
     
    144144            return;
    145145        int row = selectedRows[0];
    146         Conflict c = conflicts.get(row);
     146        Conflict<?> c = conflicts.get(row);
    147147        OsmPrimitive my = c.getMy();
    148148        OsmPrimitive their = c.getTheir();
     
    262262    }
    263263
     264    @Override
     265    public String helpTopic() {
     266        return "Dialogs/ConflictListDialog";
     267    }
     268
    264269    /**
    265270     * The {@see ListModel} for conflicts
     
    328333            putValue(SHORT_DESCRIPTION,  tr("Open a merge dialog of all selected items in the list above."));
    329334            putValue(SMALL_ICON, ImageProvider.get("dialogs", "conflict"));
     335            putValue("help", "Dialogs/ConflictListDialog#ResolveAction");
    330336        }
    331337
     
    347353            putValue(SHORT_DESCRIPTION,  tr("Set the selected elements on the map to the selected items in the list above."));
    348354            putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));
     355            putValue("help", "Dialogs/ConflictListDialog#SelectAction");
    349356        }
    350357
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r2252 r2255  
    1212import java.awt.event.ActionEvent;
    1313import java.awt.event.ActionListener;
    14 import java.awt.event.ComponentAdapter;
    15 import java.awt.event.ComponentEvent;
    1614import java.awt.event.MouseAdapter;
    1715import java.awt.event.MouseEvent;
    1816import java.awt.event.WindowAdapter;
    1917import java.awt.event.WindowEvent;
    20 import java.util.logging.Logger;
    2118
    2219import javax.swing.AbstractAction;
    2320import javax.swing.BorderFactory;
    24 import javax.swing.Box;
    2521import javax.swing.ImageIcon;
    2622import javax.swing.JButton;
     
    3430import org.openstreetmap.josm.actions.JosmAction;
    3531import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action;
     32import org.openstreetmap.josm.gui.help.HelpBuilder;
    3633import org.openstreetmap.josm.gui.help.Helpful;
    3734import org.openstreetmap.josm.tools.GBC;
     
    348345     *
    349346     */
    350     private class DetachedDialog extends JDialog {
     347    private class DetachedDialog extends JDialog{
    351348        public DetachedDialog() {
    352349            super(JOptionPane.getFrameForComponent(Main.parent));
     
    362359                }
    363360            });
     361            addMouseListener(
     362                    new MouseAdapter() {
     363                        @Override
     364                        public void mouseEntered(MouseEvent e) {
     365                            super.mouseEntered(e);
     366                            System.out.println("requesting focus ...");
     367                            requestFocusInWindow();
     368                        }
     369                    }
     370            );
     371
    364372            String bounds = Main.pref.get(preferencePrefix+".bounds",null);
    365373            if (bounds != null) {
     
    373381            }
    374382            setTitle(titleBar.getTitle());
     383            HelpBuilder.setHelpContext(getRootPane(), helpTopic());
    375384        }
    376385
Note: See TracChangeset for help on using the changeset viewer.