- Timestamp:
- 2009-10-25T13:58:47+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
r2273 r2315 5 5 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.completeTagCollectionForEditing; 6 6 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing; 7 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 7 8 import static org.openstreetmap.josm.tools.I18n.tr; 8 9 … … 29 30 import org.openstreetmap.josm.data.osm.Way; 30 31 import org.openstreetmap.josm.data.osm.BackreferencedDataSet.RelationToChildReference; 32 import org.openstreetmap.josm.gui.DefaultNameFormatter; 33 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 34 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 31 35 import org.openstreetmap.josm.gui.conflict.tags.CombinePrimitiveResolverDialog; 32 36 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 37 import org.openstreetmap.josm.tools.ImageProvider; 33 38 import org.openstreetmap.josm.tools.Shortcut; 34 35 36 39 /** 37 40 * Merges a collection of nodes into one node. … … 161 164 waysToDelete.add(w); 162 165 } else { 163 JOptionPane.showMessageDialog( 166 ButtonSpec[] options = new ButtonSpec[] { 167 new ButtonSpec( 168 tr("Abort Merging"), 169 ImageProvider.get("cancel"), 170 tr("Click to abort merging nodes"), 171 null /* no special help topic */ 172 ) 173 }; 174 HelpAwareOptionPane.showOptionDialog( 164 175 Main.parent, 165 tr("Cannot merge nodes: " + 166 "Would have to delete a way that is still used."), 176 tr( 177 "Cannot merge nodes: Would have to delete way ''{0}'' which is still used.", 178 w.getDisplayName(DefaultNameFormatter.getInstance()) 179 ), 167 180 tr("Warning"), 168 JOptionPane.WARNING_MESSAGE 181 JOptionPane.WARNING_MESSAGE, 182 null, /* no icon */ 183 options, 184 options[0], 185 ht("/Action/MergeNodes#WaysToDeleteStillInUse") 169 186 ); 170 187 return null; … … 178 195 } 179 196 } 197 cmds.add(new DeleteCommand(waysToDelete)); 180 198 return cmds; 181 199 } -
trunk/src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java
r2303 r2315 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.ActionListener; 9 import java.awt.event.KeyEvent; 9 10 import java.awt.event.WindowAdapter; 10 11 import java.awt.event.WindowEvent; … … 12 13 import java.util.List; 13 14 15 import javax.swing.AbstractAction; 14 16 import javax.swing.Icon; 15 17 import javax.swing.JButton; … … 17 19 import javax.swing.JLabel; 18 20 import javax.swing.JOptionPane; 19 20 import org.openstreetmap.josm.gui.help.HelpBrowser; 21 import javax.swing.KeyStroke; 22 21 23 import org.openstreetmap.josm.gui.help.HelpBrowserProxy; 22 24 import org.openstreetmap.josm.gui.help.HelpUtil; … … 47 49 } 48 50 49 static private class DefaultAction implements ActionListener{51 static private class DefaultAction extends AbstractAction { 50 52 private JDialog dialog; 51 53 private JOptionPane pane; … … 57 59 this.value = value; 58 60 } 61 59 62 public void actionPerformed(ActionEvent e) { 60 63 pane.setValue(value); … … 63 66 } 64 67 68 /** 69 * Creates the list buttons to be displayed in the option pane dialog. 70 * 71 * @param options the option. If null, just creates an OK button and a help button 72 * @param helpTopic the help topic. The context sensitive help of all buttons is equal 73 * to the context sensitive help of the whole dialog 74 * @return the list of buttons 75 */ 65 76 static private List<JButton> createOptionButtons(ButtonSpec[] options, String helpTopic) { 66 77 List<JButton> buttons = new ArrayList<JButton>(); 67 78 if (options == null) { 68 buttons.add(new JButton(tr("OK"))); 79 JButton b = new JButton(tr("OK")); 80 b.setIcon(ImageProvider.get("ok")); 81 b.setToolTipText(tr("Click to close the dialog")); 82 b.setFocusable(true); 83 buttons.add(b); 69 84 } else { 70 85 for (ButtonSpec spec: options) { … … 77 92 b.setFocusable(true); 78 93 buttons.add(b); 79 80 94 } 81 95 } … … 83 97 } 84 98 99 /** 100 * Creates the help button 101 * 102 * @param helpTopic the help topic 103 * @return the help button 104 */ 85 105 static private JButton createHelpButton(final String helpTopic) { 86 106 JButton b = new JButton(tr("Help")); … … 91 111 new ActionListener() { 92 112 public void actionPerformed(ActionEvent e) { 93 HelpBrowserProxy.getInstance().setUrlForHelpTopic( completeHelpTopic(helpTopic));113 HelpBrowserProxy.getInstance().setUrlForHelpTopic(helpTopic); 94 114 } 95 115 } 96 116 ); 97 117 return b; 98 }99 100 static private String completeHelpTopic(String helpTopic) {101 if (helpTopic == null) return null;102 if (! helpTopic.startsWith("/")) {103 helpTopic = "/" + helpTopic;104 }105 return "Help" + helpTopic;106 118 } 107 119 … … 172 184 dialog.addWindowListener( 173 185 new WindowAdapter() { 186 174 187 @Override 175 188 public void windowClosing(WindowEvent e) { … … 187 200 } 188 201 } 189 if (i >= options.length) return; // default option not an option? 190 202 if (i >= options.length) { 203 buttons.get(0).requestFocusInWindow(); 204 } 191 205 buttons.get(i).requestFocusInWindow(); 206 } else { 207 buttons.get(0).requestFocusInWindow(); 192 208 } 193 209 } … … 196 212 if (options != null) { 197 213 for (int i=0; i < options.length;i++) { 198 buttons.get(i).addActionListener(new DefaultAction(dialog, pane, i)); 214 final DefaultAction action = new DefaultAction(dialog, pane, i); 215 buttons.get(i).addActionListener(action); 216 buttons.get(i).getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "enter"); 217 buttons.get(i).getActionMap().put("enter", action); 199 218 } 200 } 219 } else { 220 final DefaultAction action = new DefaultAction(dialog, pane, 0); 221 buttons.get(0).addActionListener(action); 222 buttons.get(0).getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "enter"); 223 buttons.get(0).getActionMap().put("enter", action); 224 } 225 201 226 dialog.pack(); 202 227 WindowGeometry.centerOnScreen(dialog.getSize()).applySafe(dialog);
Note:
See TracChangeset
for help on using the changeset viewer.