Changeset 9674 in josm for trunk/src/org
- Timestamp:
- 2016-01-29T21:47:58+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/relation/RecentRelationsAction.java
r9668 r9674 5 5 6 6 import java.awt.Component; 7 import java.awt.Rectangle; 7 8 import java.awt.event.ActionEvent; 8 9 import java.awt.event.ActionListener; 9 10 import java.awt.event.KeyEvent; 10 import java. awt.Rectangle;11 import java.util.Collections; 11 12 import java.util.List; 12 13 … … 19 20 import org.openstreetmap.josm.Main; 20 21 import org.openstreetmap.josm.data.osm.Relation; 21 import org.openstreetmap.josm.gui.layer.Layer;22 import org.openstreetmap.josm.gui.layer.OsmDataLayer;23 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;24 22 import org.openstreetmap.josm.gui.DefaultNameFormatter; 25 23 import org.openstreetmap.josm.gui.MapView; 26 24 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 27 25 import org.openstreetmap.josm.gui.SideButton; 26 import org.openstreetmap.josm.gui.layer.Layer; 27 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 28 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener; 28 29 import org.openstreetmap.josm.tools.Shortcut; 29 30 … … 31 32 * Action for accessing recent relations. 32 33 */ 33 public class RecentRelationsAction implements ActionListener, CommandQueueListener, LayerChangeListener {34 public class RecentRelationsAction implements ActionListener, CommandQueueListener, LayerChangeListener { 34 35 35 36 private final SideButton editButton; … … 39 40 /** 40 41 * Constructs a new <code>RecentRelationsAction</code>. 42 * @param editButton edit button 41 43 */ 42 44 public RecentRelationsAction(SideButton editButton) { … … 61 63 } 62 64 65 /** 66 * Enables arrow button. 67 */ 63 68 public void enableArrow() { 64 69 arrow.setEnabled(getLastRelation() != null); 65 70 } 66 71 72 /** 73 * Returns the last relation. 74 * @return the last relation 75 */ 67 76 public static Relation getLastRelation() { 68 77 List<Relation> recentRelations = getRecentRelationsOnActiveLayer(); 69 if (recentRelations == null || recentRelations.isEmpty()) return null; 78 if (recentRelations == null || recentRelations.isEmpty()) 79 return null; 70 80 for (Relation relation: recentRelations) { 71 if (!isRelationListable(relation)) continue; 81 if (!isRelationListable(relation)) 82 continue; 72 83 return relation; 73 84 } … … 75 86 } 76 87 88 /** 89 * Determines if the given relation is listable in last relations. 90 * @param relation relation 91 * @return {@code true} if relation is non null, not deleted, and in current dataset 92 */ 77 93 public static boolean isRelationListable(Relation relation) { 78 94 return relation != null && … … 106 122 } 107 123 124 /** 125 * Returns the list of recent relations on active layer. 126 * @return the list of recent relations on active layer 127 */ 108 128 public static List<Relation> getRecentRelationsOnActiveLayer() { 109 if (Main.map == null || Main.map.mapView == null) return null; 110 Layer activeLayer = Main.map.mapView.getActiveLayer(); 129 if (!Main.isDisplayingMapView()) 130 return Collections.emptyList(); 131 Layer activeLayer = Main.main.getActiveLayer(); 111 132 if (!(activeLayer instanceof OsmDataLayer)) { 112 return null;133 return Collections.emptyList(); 113 134 } else { 114 135 return ((OsmDataLayer) activeLayer).getRecentRelations(); … … 117 138 118 139 protected static class RecentRelationsPopupMenu extends JPopupMenu { 119 public static void launch(Component parent, KeyStroke keystroke) {120 List<Relation> recentRelations = getRecentRelationsOnActiveLayer();121 JPopupMenu menu = new RecentRelationsPopupMenu(recentRelations, keystroke);122 Rectangle r = parent.getBounds();123 menu.show(parent, r.x, r.y + r.height);124 }125 126 140 /** 127 * Constructs a new {@code SearchPopupMenu}. 141 * Constructs a new {@code RecentRelationsPopupMenu}. 142 * @param recentRelations list of recent relations 143 * @param keystroke key stroke for the first menu item 128 144 */ 129 145 public RecentRelationsPopupMenu(List<Relation> recentRelations, KeyStroke keystroke) { 130 146 boolean first = true; 131 147 for (Relation relation: recentRelations) { 132 if (!isRelationListable(relation)) continue; 148 if (!isRelationListable(relation)) 149 continue; 133 150 JMenuItem menuItem = new RecentRelationsMenuItem(relation); 134 151 if (first) { … … 138 155 add(menuItem); 139 156 } 157 } 158 159 public static void launch(Component parent, KeyStroke keystroke) { 160 Rectangle r = parent.getBounds(); 161 new RecentRelationsPopupMenu(getRecentRelationsOnActiveLayer(), keystroke).show(parent, r.x, r.y + r.height); 140 162 } 141 163 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r9670 r9674 26 26 import java.util.HashSet; 27 27 import java.util.LinkedHashMap; 28 import java.util.LinkedList;29 28 import java.util.List; 30 29 import java.util.Map; … … 426 425 427 426 /** 428 * merges the primitives in dataset <code>from</code> into the dataset of 429 * this layer 427 * merges the primitives in dataset <code>from</code> into the dataset of this layer 430 428 * 431 429 * @param from the source data set … … 437 435 visitor.merge(progressMonitor); 438 436 } catch (DataIntegrityProblemException e) { 437 Main.error(e); 439 438 JOptionPane.showMessageDialog( 440 439 Main.parent, … … 747 746 for (String key : possibleKeys) { 748 747 String value = p.get(key); 749 if (value != null) { 750 // Sanity checks 751 if (!GpxConstants.PT_FIX.equals(gpxKey) || GpxConstants.FIX_VALUES.contains(value)) { 752 wpt.put(gpxKey, value); 753 break; 754 } 748 // Sanity checks 749 if (value != null && (!GpxConstants.PT_FIX.equals(gpxKey) || GpxConstants.FIX_VALUES.contains(value))) { 750 wpt.put(gpxKey, value); 751 break; 755 752 } 756 753 } … … 779 776 @Override 780 777 public void actionPerformed(ActionEvent e) { 781 final GpxData data = toGpxData();782 final GpxLayer gpxLayer = new GpxLayer( data, tr("Converted from: {0}", getName()));778 final GpxData gpxData = toGpxData(); 779 final GpxLayer gpxLayer = new GpxLayer(gpxData, tr("Converted from: {0}", getName())); 783 780 if (getAssociatedFile() != null) { 784 781 final String filename = getAssociatedFile().getName().replaceAll(Pattern.quote(".gpx.osm") + "$", "") + ".gpx"; … … 786 783 } 787 784 Main.main.addLayer(gpxLayer); 788 if (Main.pref.getBoolean("marker.makeautomarkers", true) && ! data.waypoints.isEmpty()) {789 Main.main.addLayer(new MarkerLayer( data, tr("Converted from: {0}", getName()), null, gpxLayer));785 if (Main.pref.getBoolean("marker.makeautomarkers", true) && !gpxData.waypoints.isEmpty()) { 786 Main.main.addLayer(new MarkerLayer(gpxData, tr("Converted from: {0}", getName()), null, gpxLayer)); 790 787 } 791 788 Main.main.removeLayer(OsmDataLayer.this); … … 804 801 return true; 805 802 806 boolean layer _bounds_point = false;803 boolean layerBoundsPoint = false; 807 804 for (DataSource src : this.data.dataSources) { 808 805 if (src.bounds.contains(coor)) { 809 layer _bounds_point = true;806 layerBoundsPoint = true; 810 807 break; 811 808 } 812 809 } 813 return layer _bounds_point;810 return layerBoundsPoint; 814 811 } 815 812 … … 942 939 @Override 943 940 public boolean checkSaveConditions() { 944 if (isDataSetEmpty()) { 945 if (1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() { 946 @Override 947 public Integer call() { 948 ExtendedDialog dialog = new ExtendedDialog( 949 Main.parent, 950 tr("Empty document"), 951 new String[] {tr("Save anyway"), tr("Cancel")} 952 ); 953 dialog.setContent(tr("The document contains no data.")); 954 dialog.setButtonIcons(new String[] {"save", "cancel"}); 955 return dialog.showDialog().getValue(); 956 } 957 })) { 958 return false; 959 } 960 } 961 962 ConflictCollection conflicts = getConflicts(); 963 if (conflicts != null && !conflicts.isEmpty()) { 964 if (1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() { 965 @Override 966 public Integer call() { 967 ExtendedDialog dialog = new ExtendedDialog( 968 Main.parent, 969 /* I18N: Display title of the window showing conflicts */ 970 tr("Conflicts"), 971 new String[] {tr("Reject Conflicts and Save"), tr("Cancel")} 972 ); 973 dialog.setContent( 974 tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?")); 975 dialog.setButtonIcons(new String[] {"save", "cancel"}); 976 return dialog.showDialog().getValue(); 977 } 978 })) { 979 return false; 980 } 941 if (isDataSetEmpty() && 1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() { 942 @Override 943 public Integer call() { 944 ExtendedDialog dialog = new ExtendedDialog( 945 Main.parent, 946 tr("Empty document"), 947 new String[] {tr("Save anyway"), tr("Cancel")} 948 ); 949 dialog.setContent(tr("The document contains no data.")); 950 dialog.setButtonIcons(new String[] {"save", "cancel"}); 951 return dialog.showDialog().getValue(); 952 } 953 })) { 954 return false; 955 } 956 957 ConflictCollection conflictsCol = getConflicts(); 958 if (conflictsCol != null && !conflictsCol.isEmpty() && 1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() { 959 @Override 960 public Integer call() { 961 ExtendedDialog dialog = new ExtendedDialog( 962 Main.parent, 963 /* I18N: Display title of the window showing conflicts */ 964 tr("Conflicts"), 965 new String[] {tr("Reject Conflicts and Save"), tr("Cancel")} 966 ); 967 dialog.setContent( 968 tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?")); 969 dialog.setButtonIcons(new String[] {"save", "cancel"}); 970 return dialog.showDialog().getValue(); 971 } 972 })) { 973 return false; 981 974 } 982 975 return true; … … 1006 999 if (file == null && isRenamed()) { 1007 1000 String filename = Main.pref.get("lastDirectory") + '/' + getName(); 1008 if (!OsmImporter.FILE_FILTER.acceptName(filename)) filename = filename + '.' + extension; 1001 if (!OsmImporter.FILE_FILTER.acceptName(filename)) 1002 filename = filename + '.' + extension; 1009 1003 file = new File(filename); 1010 1004 } -
trunk/src/org/openstreetmap/josm/gui/widgets/FileChooserManager.java
r9670 r9674 284 284 */ 285 285 public FileChooserManager doCreateFileChooser() { 286 File f ile= new File(curDir);286 File f = new File(curDir); 287 287 // Use native dialog is preference is set, unless an unsupported selection mode is specifically wanted 288 288 if (PROP_USE_NATIVE_FILE_DIALOG.get() && NativeFileChooser.supportsSelectionMode(selectionMode)) { 289 fc = new NativeFileChooser(f ile);289 fc = new NativeFileChooser(f); 290 290 } else { 291 fc = new SwingFileChooser(f ile);291 fc = new SwingFileChooser(f); 292 292 } 293 293 … … 332 332 */ 333 333 public AbstractFileChooser openFileChooser(Component parent) { 334 if (fc == null) doCreateFileChooser(); 334 if (fc == null) 335 doCreateFileChooser(); 335 336 336 337 if (parent == null) { … … 347 348 } 348 349 349 if (!open) { 350 File file = fc.getSelectedFile(); 351 if (!SaveActionBase.confirmOverwrite(file)) { 352 return null; 353 } 350 if (!open && !SaveActionBase.confirmOverwrite(fc.getSelectedFile())) { 351 return null; 354 352 } 355 353 return fc; … … 357 355 358 356 /** 359 * Opens the file chooser dialog, then checks if filename has the given extension. If not, adds the extension and asks for overwrite if filename exists. 357 * Opens the file chooser dialog, then checks if filename has the given extension. 358 * If not, adds the extension and asks for overwrite if filename exists. 360 359 * 361 360 * @return the {@code File} or {@code null} if the user cancelled the dialog.
Note:
See TracChangeset
for help on using the changeset viewer.