Changeset 1838 in josm
- Timestamp:
- 2009-07-25T16:34:55+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r1820 r1838 22 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 23 import org.openstreetmap.josm.data.osm.Way; 24 import org.openstreetmap.josm. tools.DontShowAgainInfo;24 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 25 25 import org.openstreetmap.josm.tools.Shortcut; 26 26 … … 99 99 "to undesirable results when doing rectangular alignments.<br>" + 100 100 "Change your projection to get rid of this warning.<br>" + 101 "Do you want to continue?"); 102 103 if (!DontShowAgainInfo.show("align_rectangular_4326", msg, false)) 101 "Do you want to continue?</html>"); 102 if (!ConditionalOptionPaneUtil.showConfirmationDialog( 103 "align_rectangular_4326", 104 Main.parent, 105 msg, 106 tr("Warning"), 107 JOptionPane.YES_NO_OPTION, 108 JOptionPane.QUESTION_MESSAGE, 109 JOptionPane.YES_OPTION)) 104 110 return; 105 111 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r1823 r1838 499 499 extendedWay = true; 500 500 getCurrentDataSet().setSelected(way); 501 DataSet.fireSelectionChanged(getCurrentDataSet().getSelected()); 501 502 } 502 503 } … … 515 516 } 516 517 getCurrentDataSet().setSelected(n); 518 DataSet.fireSelectionChanged(getCurrentDataSet().getSelected()); 517 519 } else if (!newNode) { 518 520 title = tr("Connect existing way to node"); … … 557 559 (posn0 < selectedWay.nodes.size()-1) && targetNode.equals(selectedWay.nodes.get(posn0+1))) { // next node 558 560 getCurrentDataSet().setSelected(targetNode); 561 DataSet.fireSelectionChanged(getCurrentDataSet().getSelected()); 559 562 lastUsedNode = targetNode; 560 563 return true; -
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r1826 r1838 31 31 import org.openstreetmap.josm.data.osm.WaySegment; 32 32 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 33 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 33 34 import org.openstreetmap.josm.gui.ExtendedDialog; 34 35 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 35 import org.openstreetmap.josm.tools.DontShowAgainInfo;36 36 import org.openstreetmap.josm.tools.ImageProvider; 37 37 … … 391 391 "<br>" + 392 392 "Do you really want to delete?") + "</html>")); 393 return DontShowAgainInfo.show("delete_outside_nodes", msg, false, JOptionPane.YES_NO_OPTION, JOptionPane.YES_OPTION); 393 return ConditionalOptionPaneUtil.showConfirmationDialog( 394 "delete_outside_nodes", 395 Main.parent, 396 msg, 397 tr("Delete confirmation"), 398 JOptionPane.YES_NO_OPTION, 399 JOptionPane.QUESTION_MESSAGE, 400 JOptionPane.YES_OPTION 401 ); 394 402 } 395 396 403 } 397 404 } -
trunk/src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java
r1835 r1838 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 package org.openstreetmap.josm. tools;2 package org.openstreetmap.josm.gui; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Co ntainer;6 import java.awt.Component; 7 7 import java.awt.GridBagLayout; 8 import java.awt.HeadlessException; 8 9 9 10 import javax.swing.JCheckBox; … … 13 14 14 15 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.tools.GBC; 15 17 16 public class DontShowAgainInfo {17 18 18 public static boolean show(String prefKey, String msg) { 19 return show(prefKey, new JLabel(msg), false, JOptionPane.OK_CANCEL_OPTION, JOptionPane.OK_OPTION); 19 /** 20 * ConditionalOptionPaneUtil provides static utility methods for displaying modal message dialogs 21 * which can be enabled/disabled by the user. 22 * 23 * They wrap the methods provided by {@see JOptionPane}. Within JOSM you should use these 24 * methods rather than the bare methods from {@see JOptionPane} because the methods provided 25 * by ConditionalOptionPaneUtil ensure that a dialog window is always on top and isn't hidden by one of the 26 * JOSM windows for detached dialogs, relation editors, history browser and the like. 27 * 28 */ 29 public class ConditionalOptionPaneUtil { 30 31 /** 32 * this is a static utility class only 33 */ 34 private ConditionalOptionPaneUtil() {} 35 36 /** 37 * Replies the preference value for the preference key "message." + <code>prefKey</code>. 38 * The default value if the preference key is missing is true. 39 * 40 * @param the preference key 41 * @return prefKey the preference value for the preference key "message." + <code>prefKey</code> 42 */ 43 public static boolean getDialogShowingEnabled(String prefKey) { 44 return Main.pref.getBoolean("message."+prefKey, true); 20 45 } 21 46 22 public static boolean show(String prefKey, String msg, Boolean state) { 23 return show(prefKey, new JLabel(msg), state, JOptionPane.OK_CANCEL_OPTION, JOptionPane.OK_OPTION); 47 /** 48 * sets the value for the preference key "message." + <code>prefKey</code>. 49 * 50 * @param prefKey the key 51 * @param enabled the value 52 */ 53 public static void setDialogShowingEnabled(String prefKey, boolean enabled) { 54 Main.pref.put("message."+prefKey, enabled); 24 55 } 25 56 26 public static boolean show(String prefKey, Container msg) { 27 return show(prefKey, msg, false, JOptionPane.OK_CANCEL_OPTION, JOptionPane.OK_OPTION); 57 58 /** 59 * Displays an confirmation dialog with some option buttons given by <code>optionType</code>. 60 * It is always on top even if there are other open windows like detached dialogs, 61 * relation editors, history browsers and the like. 62 * 63 * Set <code>optionType</code> to {@see JOptionPane#YES_NO_OPTION} for a dialog with a YES and 64 * a NO button. 65 66 * Set <code>optionType</code> to {@see JOptionPane#YES_NO_CANCEL_OPTION} for a dialog with a YES, 67 * a NO and a CANCEL button 68 * 69 * Replies true, if the selected option is equal to <code>trueOption</code>, otherwise false. 70 * Replies true, if the dialog is not displayed because the respective preference option 71 * <code>preferenceKey</code> is set to false. 72 * 73 * @param preferenceKey the preference key 74 * @param parent the parent component 75 * @param message the message 76 * @param title the title 77 * @param optionType the option type 78 * @param messageType the message type 79 * @param trueOption if this option is selected the method replies true 80 * 81 * 82 * @return true, if the selected option is equal to <code>trueOption</code>, otherwise false. 83 * 84 * @see JOptionPane#INFORMATION_MESSAGE 85 * @see JOptionPane#WARNING_MESSAGE 86 * @see JOptionPane#ERROR_MESSAGE 87 */ 88 static public boolean showConfirmationDialog(String preferenceKey, Component parent, Object message, String title, int optionType, int messageType, int trueOption) throws HeadlessException { 89 if (!getDialogShowingEnabled(preferenceKey)) 90 return true; 91 MessagePanel pnl = new MessagePanel(preferenceKey, message); 92 boolean ret = OptionPaneUtil.showConfirmationDialog(parent, message, title, optionType, messageType, trueOption); 93 pnl.remeberDialogShowingEnabled(); 94 return ret; 28 95 } 29 96 30 public static boolean show(String prefKey, Container msg, Boolean state, int options, int true_option) { 31 if (!Main.pref.getBoolean("message."+prefKey, state)) { 32 JCheckBox dontshowagain = new JCheckBox(tr("Do not show again")); 33 dontshowagain.setSelected(Main.pref.getBoolean("message."+prefKey, state)); 34 JPanel all = new JPanel(new GridBagLayout()); 35 all.add(msg, GBC.eop()); 36 all.add(dontshowagain, GBC.eol()); 37 int answer = JOptionPane.showConfirmDialog(Main.parent, all, tr("Information"), options); 38 if (answer != true_option) 39 return false; 40 Main.pref.put("message."+prefKey, dontshowagain.isSelected()); 97 /** 98 * Displays an message in modal dialog with an OK button. Makes sure the dialog 99 * is always on top even if there are other open windows like detached dialogs, 100 * relation editors, history browsers and the like. 101 * 102 * If there is a preference with key <code>preferenceKey</code> and value <code>false</code> 103 * the dialog is not show. 104 * 105 * @param preferenceKey the preference key 106 * @param parent the parent component 107 * @param message the message 108 * @param title the title 109 * @param messageType the message type 110 * 111 * @see JOptionPane#INFORMATION_MESSAGE 112 * @see JOptionPane#WARNING_MESSAGE 113 * @see JOptionPane#ERROR_MESSAGE 114 */ 115 static public void showMessageDialog(String preferenceKey, Component parent, Object message, String title,int messageType) { 116 if (!getDialogShowingEnabled(preferenceKey)) 117 return; 118 MessagePanel pnl = new MessagePanel(preferenceKey, message); 119 OptionPaneUtil.showMessageDialog(parent, pnl, title, messageType); 120 pnl.remeberDialogShowingEnabled(); 121 } 122 123 /** 124 * This is a message panel used in dialogs which can be enabled/disabled with a preference 125 * setting. 126 * In addition to the normal message any {@see JOptionPane} would display it includes 127 * a checkbox for enabling/disabling this particular dialog. 128 * 129 */ 130 private static class MessagePanel extends JPanel { 131 JCheckBox cbShowDialog; 132 String preferenceKey; 133 134 public MessagePanel(String preferenceKey, Object message) { 135 this.preferenceKey = preferenceKey; 136 cbShowDialog = new JCheckBox(tr("Do not show again")); 137 cbShowDialog.setSelected(!ConditionalOptionPaneUtil.getDialogShowingEnabled(preferenceKey)); 138 setLayout(new GridBagLayout()); 139 140 if (message instanceof Component) { 141 add((Component)message, GBC.eop()); 142 } else { 143 add(new JLabel(message.toString()),GBC.eop()); 144 } 145 add(cbShowDialog, GBC.eol()); 41 146 } 42 return true; 147 148 public boolean getDialogShowingEnabled() { 149 return cbShowDialog.isSelected(); 150 } 151 152 public void remeberDialogShowingEnabled() { 153 ConditionalOptionPaneUtil.setDialogShowingEnabled(preferenceKey, !getDialogShowingEnabled()); 154 } 43 155 } 44 156 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r1677 r1838 22 22 import javax.swing.JLabel; 23 23 import javax.swing.JList; 24 import javax.swing.JOptionPane; 24 25 import javax.swing.JPanel; 25 26 import javax.swing.JScrollPane; … … 30 31 31 32 import org.openstreetmap.josm.Main; 33 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 32 34 import org.openstreetmap.josm.gui.ExtendedDialog; 33 35 import org.openstreetmap.josm.gui.MapFrame; … … 37 39 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 38 40 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 39 import org.openstreetmap.josm.tools.DontShowAgainInfo;40 41 import org.openstreetmap.josm.tools.ImageProvider; 41 42 import org.openstreetmap.josm.tools.ImageProvider.OverlayPosition; … … 78 79 { 79 80 int result = new ExtendedDialog(Main.parent, tr("Unsaved Changes"), 80 tr("There are unsaved changes. Delete the layer anwyay?"), 81 new String[] {tr("Delete Layer"), tr("Cancel")}, 82 new String[] {"dialogs/delete.png", "cancel.png"}).getValue(); 81 tr("There are unsaved changes. Delete the layer anwyay?"), 82 new String[] {tr("Delete Layer"), tr("Cancel")}, 83 new String[] {"dialogs/delete.png", "cancel.png"}).getValue(); 83 84 84 85 if(result != 1) return; 85 86 } 86 else if(!DontShowAgainInfo.show("delete_layer", tr("Do you really want to delete the whole layer?"), false)) 87 else if (!ConditionalOptionPaneUtil.showConfirmationDialog( 88 "delete_layer", 89 Main.parent, 90 tr("Do you really want to delete the whole layer?"), 91 tr("Confirmation"), 92 JOptionPane.YES_NO_OPTION, 93 JOptionPane.QUESTION_MESSAGE, 94 JOptionPane.YES_OPTION)) 87 95 return; 88 96 } 89 97 Main.main.removeLayer(l); 90 if (sel >= instance.getModel().getSize()) 98 if (sel >= instance.getModel().getSize()) { 91 99 sel = instance.getModel().getSize()-1; 92 if (instance.getSelectedValue() == null) 100 } 101 if (instance.getSelectedValue() == null) { 93 102 instance.setSelectedIndex(sel); 94 if (Main.map != null) 103 } 104 if (Main.map != null) { 95 105 Main.map.mapView.setActiveLayer((Layer)instance.getSelectedValue()); 106 } 96 107 } 97 108 } … … 163 174 public LayerListDialog(MapFrame mapFrame) { 164 175 super(tr("Layers"), "layerlist", tr("Open a list of all loaded layers."), 165 Shortcut.registerShortcut("subwindow:layers", tr("Toggle: {0}", tr("Layers")), KeyEvent.VK_L, Shortcut.GROUP_LAYER), 100); 176 Shortcut.registerShortcut("subwindow:layers", tr("Toggle: {0}", tr("Layers")), KeyEvent.VK_L, Shortcut.GROUP_LAYER), 100); 166 177 instance = new JList(model); 167 178 listScrollPane = new JScrollPane(instance); … … 174 185 layer.name, index, isSelected, cellHasFocus); 175 186 Icon icon = layer.getIcon(); 176 if (!layer.visible) 187 if (!layer.visible) { 177 188 icon = ImageProvider.overlay(icon, "overlay/invisible", OverlayPosition.SOUTHEAST); 189 } 178 190 label.setIcon(icon); 179 191 label.setToolTipText(layer.getToolTipText()); … … 185 197 186 198 Collection<Layer> data = mapView.getAllLayers(); 187 for (Layer l : data) 199 for (Layer l : data) { 188 200 model.addElement(l); 201 } 189 202 190 203 instance.setSelectedValue(mapView.getActiveLayer(), true); … … 194 207 if (instance.getModel().getSize() == 0) 195 208 return; 196 if (instance.getSelectedIndex() == -1) 209 if (instance.getSelectedIndex() == -1) { 197 210 instance.setSelectedIndex(e.getFirstIndex()); 211 } 198 212 mapView.setActiveLayer((Layer)instance.getSelectedValue()); 199 213 } … … 210 224 } 211 225 @Override public void mousePressed(MouseEvent e) { 212 if (e.isPopupTrigger()) 226 if (e.isPopupTrigger()) { 213 227 openPopup(e); 228 } 214 229 } 215 230 @Override public void mouseReleased(MouseEvent e) { 216 if (e.isPopupTrigger()) 231 if (e.isPopupTrigger()) { 217 232 openPopup(e); 233 } 218 234 } 219 235 @Override public void mouseClicked(MouseEvent e) { … … 258 274 259 275 mergeButton = new SideButton("mergedown", "LayerList", tr("Merge the layer directly below into the selected layer."), 260 new ActionListener(){ 276 new ActionListener(){ 261 277 public void actionPerformed(ActionEvent e) { 262 278 Layer lTo = (Layer)instance.getSelectedValue(); … … 311 327 return; 312 328 } 313 if (instance.getSelectedIndex() == -1) 329 if (instance.getSelectedIndex() == -1) { 314 330 instance.setSelectedIndex(0); 331 } 315 332 updateButtonEnabled(); 316 333 } … … 320 337 */ 321 338 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 322 if (newLayer != instance.getSelectedValue()) 339 if (newLayer != instance.getSelectedValue()) { 323 340 instance.setSelectedValue(newLayer, true); 341 } 324 342 updateButtonEnabled(); 325 343 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r1833 r1838 16 16 import javax.swing.DefaultListModel; 17 17 import javax.swing.JList; 18 import javax.swing.JOptionPane; 18 19 import javax.swing.JPanel; 19 20 import javax.swing.JScrollPane; … … 27 28 import org.openstreetmap.josm.data.osm.OsmPrimitive; 28 29 import org.openstreetmap.josm.data.osm.Relation; 30 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 31 import org.openstreetmap.josm.gui.OptionPaneUtil; 29 32 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 30 33 import org.openstreetmap.josm.gui.SideButton; -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r1811 r1838 57 57 import org.openstreetmap.josm.data.osm.Way; 58 58 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 59 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 59 60 import org.openstreetmap.josm.gui.MapView; 60 61 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; … … 65 66 import org.openstreetmap.josm.tools.AudioUtil; 66 67 import org.openstreetmap.josm.tools.DateUtils; 67 import org.openstreetmap.josm.tools.DontShowAgainInfo;68 68 import org.openstreetmap.josm.tools.GBC; 69 69 import org.openstreetmap.josm.tools.ImageProvider; … … 687 687 msg.add(new JLabel(tr("<html>Upload of unprocessed GPS data as map data is considered harmful.<br>If you want to upload traces, look here:")), GBC.eol()); 688 688 msg.add(new UrlLabel(tr("http://www.openstreetmap.org/traces")), GBC.eop()); 689 if (!DontShowAgainInfo.show("convert_to_data", msg)) 689 if (!ConditionalOptionPaneUtil.showConfirmationDialog( 690 "convert_to_data", 691 Main.parent, 692 msg, 693 tr("Warning"), 694 JOptionPane.OK_CANCEL_OPTION, 695 JOptionPane.WARNING_MESSAGE, 696 JOptionPane.OK_OPTION)) 690 697 return; 691 698 DataSet ds = new DataSet(); -
trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java
r1808 r1838 45 45 import org.openstreetmap.josm.data.osm.Way; 46 46 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 47 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 47 48 import org.openstreetmap.josm.gui.MapView; 48 49 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 49 50 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 50 51 import org.openstreetmap.josm.io.MultiPartFormOutputStream; 51 import org.openstreetmap.josm.tools.DontShowAgainInfo;52 52 import org.openstreetmap.josm.tools.GBC; 53 53 import org.openstreetmap.josm.tools.ImageProvider; … … 70 70 msg.add(new JLabel(tr("<html>Upload of unprocessed GPS data as map data is considered harmful.<br>If you want to upload traces, look here:")), GBC.eol()); 71 71 msg.add(new UrlLabel(tr("http://www.openstreetmap.org/traces")), GBC.eop()); 72 if (!DontShowAgainInfo.show("convert_to_data", msg)) 72 if (!ConditionalOptionPaneUtil.showConfirmationDialog( 73 "convert_to_data", 74 Main.parent, 75 msg, 76 tr("Warning"), 77 JOptionPane.OK_CANCEL_OPTION, 78 JOptionPane.WARNING_MESSAGE, 79 JOptionPane.OK_OPTION)) 73 80 return; 74 81 DataSet ds = new DataSet();
Note:
See TracChangeset
for help on using the changeset viewer.