Changeset 5459 in josm for trunk/src/org
- Timestamp:
- 2012-08-20T01:11:45+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java
r5438 r5459 12 12 import javax.swing.filechooser.FileFilter; 13 13 14 import org.openstreetmap.josm.gui.MapView; 14 15 import org.openstreetmap.josm.io.AllFormatsImporter; 15 16 import org.openstreetmap.josm.io.FileExporter; … … 51 52 "org.openstreetmap.josm.io.OsmBzip2Importer", 52 53 "org.openstreetmap.josm.io.JpgImporter", 54 "org.openstreetmap.josm.io.WMSLayerImporter", 53 55 "org.openstreetmap.josm.io.AllFormatsImporter" 54 56 }; … … 56 58 for (String classname : importerNames) { 57 59 try { 58 Class<?> klass = Class.forName(classname); 59 importers.add((FileImporter) klass.newInstance()); 60 } catch (Exception e) {} 60 FileImporter importer = (FileImporter) Class.forName(classname).newInstance(); 61 importers.add(importer); 62 MapView.addLayerChangeListener(importer); 63 } catch (Throwable t) { } 61 64 } 62 65 … … 69 72 "org.openstreetmap.josm.io.OsmBzip2Exporter", 70 73 "org.openstreetmap.josm.io.GeoJSONExporter", 74 "org.openstreetmap.josm.io.WMSLayerExporter" 71 75 }; 72 76 73 77 for (String classname : exporterNames) { 74 78 try { 75 Class<?> klass = Class.forName(classname); 76 exporters.add((FileExporter)klass.newInstance()); 77 } catch (Exception e) {} 79 FileExporter exporter = (FileExporter)Class.forName(classname).newInstance(); 80 exporters.add(exporter); 81 MapView.addLayerChangeListener(exporter); 82 } catch (Throwable t) { } 78 83 } 79 84 } … … 134 139 135 140 /** 136 * Replies an ordered list of {@link ExtensionFileFilter}s for exporting.141 * Replies an ordered list of enabled {@link ExtensionFileFilter}s for exporting. 137 142 * The list is ordered according to their description, an {@link AllFormatsImporter} 138 143 * is append at the end. 139 144 * 140 * @return an ordered list of {@link ExtensionFileFilter}s for exporting.145 * @return an ordered list of enabled {@link ExtensionFileFilter}s for exporting. 141 146 * @since 2029 142 147 */ … … 144 149 LinkedList<ExtensionFileFilter> filters = new LinkedList<ExtensionFileFilter>(); 145 150 for (FileExporter exporter : exporters) { 146 if (filters.contains(exporter.filter) ) {151 if (filters.contains(exporter.filter) || !exporter.isEnabled()) { 147 152 continue; 148 153 } -
trunk/src/org/openstreetmap/josm/actions/JosmAction.java
r5275 r5459 128 128 } 129 129 130 @Override 130 131 public void destroy() { 131 132 if (sc != null) { -
trunk/src/org/openstreetmap/josm/actions/SaveAction.java
r5014 r5459 36 36 } 37 37 38 39 38 @Override public File getFile(Layer layer) { 40 39 File f = layer.getAssociatedFile(); … … 59 58 } 60 59 } 61 return f == null ? openFileDialog(layer) : f;60 return f == null ? layer.createAndOpenSaveFileChooser() : f; 62 61 } 63 62 } -
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r5457 r5459 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.conflict.ConflictCollection;19 import org.openstreetmap.josm.data.osm.OsmPrimitive;20 18 import org.openstreetmap.josm.gui.ExtendedDialog; 21 import org.openstreetmap.josm.gui.layer.GpxLayer;22 19 import org.openstreetmap.josm.gui.layer.Layer; 23 20 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 24 21 import org.openstreetmap.josm.io.FileExporter; 25 import org.openstreetmap.josm.io.GpxImporter;26 22 import org.openstreetmap.josm.tools.Shortcut; 27 23 … … 44 40 45 41 public boolean doSave() { 46 Layer layer = null; 47 if (Main.isDisplayingMapView() && (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer 48 || Main.map.mapView.getActiveLayer() instanceof GpxLayer)) { 49 layer = Main.map.mapView.getActiveLayer(); 42 if (Main.isDisplayingMapView()) { 43 Layer layer = Main.map.mapView.getActiveLayer(); 44 if (layer != null && layer.isSavable()) { 45 return doSave(layer); 46 } 50 47 } 51 if (layer == null) 52 return false; 53 return doSave(layer); 48 return false; 54 49 } 55 50 56 51 public boolean doSave(Layer layer) { 57 if(! checkSaveConditions(layer))52 if(!layer.checkSaveConditions()) 58 53 return false; 59 54 file = getFile(layer); … … 62 57 63 58 public static boolean doSave(Layer layer, File file) { 64 if(! checkSaveConditions(layer))59 if(!layer.checkSaveConditions()) 65 60 return false; 66 61 return doInternalSave(layer, file); … … 101 96 102 97 /** 103 * Checks whether it is ok to launch a save (whether we have data,104 * there is no conflict etc.)105 * @return <code>true</code>, if it is safe to save.106 */107 public static boolean checkSaveConditions(Layer layer) {108 if (layer instanceof GpxLayer)109 return ((GpxLayer)layer).data != null;110 else if (layer instanceof OsmDataLayer) {111 if (isDataSetEmpty((OsmDataLayer)layer)) {112 ExtendedDialog dialog = new ExtendedDialog(113 Main.parent,114 tr("Empty document"),115 new String[] {tr("Save anyway"), tr("Cancel")}116 );117 dialog.setContent(tr("The document contains no data."));118 dialog.setButtonIcons(new String[] {"save.png", "cancel.png"});119 dialog.showDialog();120 if (dialog.getValue() != 1) return false;121 }122 123 ConflictCollection conflicts = ((OsmDataLayer)layer).getConflicts();124 if (conflicts != null && !conflicts.isEmpty()) {125 ExtendedDialog dialog = new ExtendedDialog(126 Main.parent,127 /* I18N: Display title of the window showing conflicts */128 tr("Conflicts"),129 new String[] {tr("Reject Conflicts and Save"), tr("Cancel")}130 );131 dialog.setContent(tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?"));132 dialog.setButtonIcons(new String[] {"save.png", "cancel.png"});133 dialog.showDialog();134 if (dialog.getValue() != 1) return false;135 }136 return true;137 }138 return false;139 }140 141 public static File openFileDialog(Layer layer) {142 if (layer instanceof OsmDataLayer)143 return createAndOpenSaveFileChooser(tr("Save OSM file"), "osm");144 else if (layer instanceof GpxLayer)145 return createAndOpenSaveFileChooser(tr("Save GPX file"), GpxImporter.FILE_FILTER);146 return createAndOpenSaveFileChooser(tr("Save Layer"), "lay");147 }148 149 /**150 * Check the data set if it would be empty on save. It is empty, if it contains151 * no objects (after all objects that are created and deleted without being152 * transferred to the server have been removed).153 *154 * @return <code>true</code>, if a save result in an empty data set.155 */156 private static boolean isDataSetEmpty(OsmDataLayer layer) {157 for (OsmPrimitive osm : layer.data.allNonDeletedPrimitives())158 if (!osm.isDeleted() || !osm.isNewOrUndeleted())159 return false;160 return true;161 }162 163 /**164 98 * Refreshes the enabled state 165 99 * … … 179 113 } 180 114 Layer layer = Main.map.mapView.getActiveLayer(); 181 setEnabled(layer instanceof OsmDataLayer || layer instanceof GpxLayer);115 setEnabled(layer != null && layer.isSavable()); 182 116 } 183 117 -
trunk/src/org/openstreetmap/josm/actions/SaveAsAction.java
r5048 r5459 21 21 /** 22 22 * Construct the action with "Save" as label. 23 * @param layer Save this layer.24 23 */ 25 24 public SaveAsAction() { … … 35 34 36 35 @Override protected File getFile(Layer layer) { 37 return openFileDialog(layer);36 return layer.createAndOpenSaveFileChooser(); 38 37 } 39 38 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r5382 r5459 2 2 package org.openstreetmap.josm.actions.mapmode; 3 3 4 import java.awt.*;5 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 6 5 import static org.openstreetmap.josm.tools.I18n.marktr; … … 8 7 import static org.openstreetmap.josm.tools.I18n.trn; 9 8 9 import java.awt.AWTEvent; 10 import java.awt.BasicStroke; 11 import java.awt.Color; 12 import java.awt.Component; 13 import java.awt.Cursor; 14 import java.awt.Graphics2D; 15 import java.awt.KeyboardFocusManager; 16 import java.awt.Point; 17 import java.awt.Stroke; 18 import java.awt.Toolkit; 10 19 import java.awt.event.AWTEventListener; 11 20 import java.awt.event.ActionEvent; … … 29 38 import java.util.TreeSet; 30 39 31 import javax.swing.*; 40 import javax.swing.AbstractAction; 41 import javax.swing.JCheckBoxMenuItem; 42 import javax.swing.JFrame; 43 import javax.swing.JMenuItem; 44 import javax.swing.JOptionPane; 45 import javax.swing.JPopupMenu; 46 import javax.swing.SwingUtilities; 47 import javax.swing.Timer; 32 48 33 49 import org.openstreetmap.josm.Main; … … 91 107 private EastNorth currentMouseEastNorth; 92 108 93 private SnapHelper snapHelper = new SnapHelper();109 private final SnapHelper snapHelper = new SnapHelper(); 94 110 95 111 private Shortcut backspaceShortcut; 96 private Shortcut snappingShortcut; 97 98 private JCheckBoxMenuItem snapCheckboxMenuItem; 112 private final Shortcut snappingShortcut; 113 114 private final SnapChangeAction snapChangeAction; 115 private final JCheckBoxMenuItem snapCheckboxMenuItem; 99 116 private boolean useRepeatedShortcut; 100 117 … … 106 123 snappingShortcut = Shortcut.registerShortcut("mapmode:drawanglesnapping", 107 124 tr("Mode: Draw Angle snapping"), KeyEvent.VK_TAB, Shortcut.DIRECT); 108 addMenuItem(); 125 snapChangeAction = new SnapChangeAction(); 126 snapCheckboxMenuItem = addMenuItem(); 109 127 snapHelper.setMenuCheckBox(snapCheckboxMenuItem); 110 128 cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode"); … … 112 130 } 113 131 114 private voidaddMenuItem() {132 private JCheckBoxMenuItem addMenuItem() { 115 133 int n=Main.main.menu.editMenu.getItemCount(); 116 134 for (int i=n-1;i>0;i--) { … … 120 138 } 121 139 } 122 snapCheckboxMenuItem = MainMenu.addWithCheckbox(Main.main.menu.editMenu, new SnapChangeAction(),MainMenu.WINDOW_MENU_GROUP.VOLATILE);140 return MainMenu.addWithCheckbox(Main.main.menu.editMenu, snapChangeAction, MainMenu.WINDOW_MENU_GROUP.VOLATILE); 123 141 } 124 142 … … 1207 1225 public void destroy() { 1208 1226 super.destroy(); 1227 snapChangeAction.destroy(); 1209 1228 } 1210 1229 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java
r4732 r5459 27 27 import org.openstreetmap.josm.data.projection.Projection; 28 28 import org.openstreetmap.josm.data.projection.ProjectionChangeListener; 29 import org.openstreetmap.josm.gui.MapView; 29 30 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 30 31 import org.openstreetmap.josm.gui.NavigatableComponent; … … 49 50 Main.addProjectionChangeListener(this); 50 51 DataSet.addSelectionListener(this); 52 MapView.addLayerChangeListener(this); 51 53 } 52 54 -
trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java
r5390 r5459 24 24 import org.openstreetmap.josm.gui.layer.ImageryLayer; 25 25 import org.openstreetmap.josm.gui.layer.Layer; 26 import org.openstreetmap.josm.gui.layer.WMSLayer;27 26 import org.openstreetmap.josm.tools.ImageProvider; 28 27 … … 69 68 JMenuItem offsetMenuItem = singleOffset; 70 69 Map_Rectifier_WMSmenuAction rectaction = new Map_Rectifier_WMSmenuAction(); 71 JosmAction blankmenu = new JosmAction(72 tr("Blank Layer"), /* ICON */"blankmenu", tr("Open a blank WMS layer to load data from a file"), null, false) {73 @Override74 public void actionPerformed(ActionEvent ev) {75 if (!isEnabled()) return;76 Main.main.addLayer(new WMSLayer());77 }78 79 @Override80 protected void updateEnabledState() {81 setEnabled(Main.map != null && Main.map.mapView != null && !Main.map.mapView.getAllLayers().isEmpty());82 }83 };84 70 int offsPos; 85 71 … … 102 88 offsPos = getMenuComponentCount(); 103 89 add(offsetMenuItem); 104 addSeparator();105 add(new JMenuItem(blankmenu));106 90 } 107 91 -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r5448 r5459 235 235 } 236 236 237 public voidselectDrawTool(boolean onlyIfModeless) {237 public boolean selectDrawTool(boolean onlyIfModeless) { 238 238 if(onlyIfModeless && !Main.pref.getBoolean("modeless", false)) 239 return ;240 241 selectMapMode(mapModeDraw);239 return false; 240 241 return selectMapMode(mapModeDraw); 242 242 } 243 243 -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r5448 r5459 106 106 * the layer listeners 107 107 */ 108 private static final CopyOnWriteArrayList< MapView.LayerChangeListener> layerChangeListeners = new CopyOnWriteArrayList<MapView.LayerChangeListener>();108 private static final CopyOnWriteArrayList<LayerChangeListener> layerChangeListeners = new CopyOnWriteArrayList<LayerChangeListener>(); 109 109 private static final CopyOnWriteArrayList<EditLayerChangeListener> editLayerChangeListeners = new CopyOnWriteArrayList<EditLayerChangeListener>(); 110 110 … … 114 114 * @param listener the listener. Ignored if null or already registered. 115 115 */ 116 public static void removeLayerChangeListener( MapView.LayerChangeListener listener) {116 public static void removeLayerChangeListener(LayerChangeListener listener) { 117 117 layerChangeListeners.remove(listener); 118 118 } … … 127 127 * @param listener the listener. Ignored if null or already registered. 128 128 */ 129 public static void addLayerChangeListener( MapView.LayerChangeListener listener) {129 public static void addLayerChangeListener(LayerChangeListener listener) { 130 130 if (listener != null) { 131 131 layerChangeListeners.addIfAbsent(listener); … … 222 222 public MapView(final JPanel contentPane) { 223 223 Main.pref.addPreferenceChangeListener(this); 224 225 // new MoveAction(MoveAction.Direction.UP);226 // new MoveAction(MoveAction.Direction.DOWN);227 // new MoveAction(MoveAction.Direction.LEFT);228 // new MoveAction(MoveAction.Direction.RIGHT);229 224 230 225 addComponentListener(new ComponentAdapter(){ … … 265 260 } 266 261 }); 267 268 // Add Multipolygon cache to layer listeners269 addLayerChangeListener(MultipolygonCache.getInstance());270 262 } 271 263 -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r5450 r5459 199 199 }; 200 200 201 private DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this); 202 private HelpAction helpAction = new HelpAction(); 203 private CopyValueAction copyValueAction = new CopyValueAction(); 204 private CopyKeyValueAction copyKeyValueAction = new CopyKeyValueAction(); 205 private CopyAllKeyValueAction copyAllKeyValueAction = new CopyAllKeyValueAction(); 206 private SearchAction searchActionSame = new SearchAction(true); 207 private SearchAction searchActionAny = new SearchAction(false); 208 private AddAction addAction = new AddAction(); 209 private EditAction editAction = new EditAction(); 210 private DeleteAction deleteAction = new DeleteAction(); 201 private final DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this); 202 private final HelpAction helpAction = new HelpAction(); 203 private final CopyValueAction copyValueAction = new CopyValueAction(); 204 private final CopyKeyValueAction copyKeyValueAction = new CopyKeyValueAction(); 205 private final CopyAllKeyValueAction copyAllKeyValueAction = new CopyAllKeyValueAction(); 206 private final SearchAction searchActionSame = new SearchAction(true); 207 private final SearchAction searchActionAny = new SearchAction(false); 208 private final AddAction addAction = new AddAction(); 209 private final EditAction editAction = new EditAction(); 210 private final DeleteAction deleteAction = new DeleteAction(); 211 private final JosmAction[] josmActions = new JosmAction[]{addAction, editAction, deleteAction}; 211 212 212 213 @Override … … 215 216 SelectionEventManager.getInstance().addSelectionListener(this, FireMode.IN_EDT_CONSOLIDATED); 216 217 MapView.addEditLayerChangeListener(this); 217 Main.registerActionShortcut(addAction);218 Main.registerActionShortcut(editAction);219 Main.registerActionShortcut(deleteAction);218 for (JosmAction action : josmActions) { 219 Main.registerActionShortcut(action); 220 } 220 221 updateSelection(); 221 222 } … … 226 227 SelectionEventManager.getInstance().removeSelectionListener(this); 227 228 MapView.removeEditLayerChangeListener(this); 228 Main.unregisterActionShortcut(addAction);229 Main.unregisterActionShortcut(editAction);230 Main.unregisterActionShortcut(deleteAction);229 for (JosmAction action : josmActions) { 230 Main.unregisterActionShortcut(action); 231 } 231 232 } 232 233 … … 1670 1671 } 1671 1672 } 1673 1674 @Override 1675 public void destroy() { 1676 super.destroy(); 1677 for (JosmAction action : josmActions) { 1678 action.destroy(); 1679 } 1680 } 1672 1681 } -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r5450 r5459 63 63 import org.openstreetmap.josm.actions.DiskAccessAction; 64 64 import org.openstreetmap.josm.actions.RenameLayerAction; 65 import org.openstreetmap.josm.actions.SaveActionBase; 65 66 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList; 66 67 import org.openstreetmap.josm.data.Bounds; … … 97 98 import org.openstreetmap.josm.gui.widgets.JFileChooserManager; 98 99 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 100 import org.openstreetmap.josm.io.GpxImporter; 99 101 import org.openstreetmap.josm.io.JpgImporter; 100 102 import org.openstreetmap.josm.io.OsmTransferException; … … 2042 2044 } 2043 2045 } 2046 2047 @Override 2048 public boolean isSavable() { 2049 return true; // With GpxExporter 2050 } 2051 2052 @Override 2053 public boolean checkSaveConditions() { 2054 return data != null; 2055 } 2056 2057 @Override 2058 public File createAndOpenSaveFileChooser() { 2059 return SaveActionBase.createAndOpenSaveFileChooser(tr("Save GPX file"), GpxImporter.FILE_FILTER); 2060 } 2044 2061 } -
trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
r5391 r5459 72 72 protected OffsetServerThread offsetServerThread; 73 73 74 private final ImageryAdjustAction adjustAction = new ImageryAdjustAction(this); 75 private final AbstractAction useServerOffsetAction = new AbstractAction(tr("(use server offset)")) { 76 @Override 77 public void actionPerformed(ActionEvent e) { 78 enableOffsetServer(true); 79 } 80 }; 81 74 82 protected OffsetServerThread createoffsetServerThread() { 75 83 return new OffsetServerThread(new OsmosnimkiOffsetServer( … … 179 187 } 180 188 } 181 182 ImageryAdjustAction adjustAction = new ImageryAdjustAction(this);183 AbstractAction useServerOffsetAction = new AbstractAction(tr("(use server offset)")) {184 @Override185 public void actionPerformed(ActionEvent e) {186 enableOffsetServer(true);187 }188 };189 189 190 190 public void enableOffsetServer(boolean enable) { … … 311 311 } 312 312 } 313 314 /* (non-Javadoc) 315 * @see org.openstreetmap.josm.gui.layer.Layer#destroy() 316 */ 317 @Override 318 public void destroy() { 319 adjustAction.destroy(); 320 } 313 321 } -
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r5391 r5459 23 23 import org.openstreetmap.josm.actions.GpxExportAction; 24 24 import org.openstreetmap.josm.actions.SaveAction; 25 import org.openstreetmap.josm.actions.SaveActionBase; 25 26 import org.openstreetmap.josm.actions.SaveAsAction; 26 27 import org.openstreetmap.josm.data.Bounds; … … 427 428 } 428 429 } 430 431 /** 432 * Initializes the layer after a successful load of data from a file 433 * @since 5459 434 */ 435 public void onPostLoadFromFile() { 436 // To be overriden if needed 437 } 438 439 /** 440 * Replies the savable state of this layer (i.e if it can be saved through a "File->Save" dialog). 441 * @return true if this layer can be saved to a file 442 * @since 5459 443 */ 444 public boolean isSavable() { 445 return false; 446 } 447 448 /** 449 * Checks whether it is ok to launch a save (whether we have data, there is no conflict etc.) 450 * @return <code>true</code>, if it is safe to save. 451 * @since 5459 452 */ 453 public boolean checkSaveConditions() { 454 return true; 455 } 456 457 /** 458 * Creates a new "Save" dialog for this layer and makes it visible.<br/> 459 * When the user has chosen a file, checks the file extension, and confirms overwrite if needed. 460 * @return The output {@code File} 461 * @since 5459 462 * @see SaveActionBase#createAndOpenSaveFileChooser 463 */ 464 public File createAndOpenSaveFileChooser() { 465 return SaveActionBase.createAndOpenSaveFileChooser(tr("Save Layer"), "lay"); 466 } 429 467 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r5297 r5459 42 42 import org.openstreetmap.josm.actions.ExpertToggleAction; 43 43 import org.openstreetmap.josm.actions.RenameLayerAction; 44 import org.openstreetmap.josm.actions.SaveActionBase; 44 45 import org.openstreetmap.josm.actions.ToggleUploadDiscouragedLayerAction; 45 46 import org.openstreetmap.josm.data.Bounds; … … 71 72 import org.openstreetmap.josm.data.projection.Projection; 72 73 import org.openstreetmap.josm.data.validation.TestError; 74 import org.openstreetmap.josm.gui.ExtendedDialog; 73 75 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 74 76 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; … … 655 657 } 656 658 657 /** 658 * Initializes the layer after a successful load of OSM data from a file 659 * 660 */ 659 @Override 661 660 public void onPostLoadFromFile() { 662 661 setRequiresSaveToFile(false); … … 745 744 data.setUploadDiscouraged(uploadDiscouraged); 746 745 } 746 747 @Override 748 public boolean isSavable() { 749 return true; // With OsmExporter 750 } 751 752 @Override 753 public boolean checkSaveConditions() { 754 if (isDataSetEmpty()) { 755 ExtendedDialog dialog = new ExtendedDialog( 756 Main.parent, 757 tr("Empty document"), 758 new String[] {tr("Save anyway"), tr("Cancel")} 759 ); 760 dialog.setContent(tr("The document contains no data.")); 761 dialog.setButtonIcons(new String[] {"save.png", "cancel.png"}); 762 dialog.showDialog(); 763 if (dialog.getValue() != 1) return false; 764 } 765 766 ConflictCollection conflicts = getConflicts(); 767 if (conflicts != null && !conflicts.isEmpty()) { 768 ExtendedDialog dialog = new ExtendedDialog( 769 Main.parent, 770 /* I18N: Display title of the window showing conflicts */ 771 tr("Conflicts"), 772 new String[] {tr("Reject Conflicts and Save"), tr("Cancel")} 773 ); 774 dialog.setContent(tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?")); 775 dialog.setButtonIcons(new String[] {"save.png", "cancel.png"}); 776 dialog.showDialog(); 777 if (dialog.getValue() != 1) return false; 778 } 779 return true; 780 } 781 782 /** 783 * Check the data set if it would be empty on save. It is empty, if it contains 784 * no objects (after all objects that are created and deleted without being 785 * transferred to the server have been removed). 786 * 787 * @return <code>true</code>, if a save result in an empty data set. 788 */ 789 private boolean isDataSetEmpty() { 790 if (data != null) { 791 for (OsmPrimitive osm : data.allNonDeletedPrimitives()) 792 if (!osm.isDeleted() || !osm.isNewOrUndeleted()) 793 return false; 794 } 795 return true; 796 } 797 798 @Override 799 public File createAndOpenSaveFileChooser() { 800 return SaveActionBase.createAndOpenSaveFileChooser(tr("Save OSM file"), "osm"); 801 } 747 802 } -
trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
r5457 r5459 33 33 import javax.swing.Action; 34 34 import javax.swing.JCheckBoxMenuItem; 35 import javax.swing.JFileChooser;36 35 import javax.swing.JMenuItem; 37 36 import javax.swing.JOptionPane; … … 39 38 import org.openstreetmap.gui.jmapviewer.AttributionSupport; 40 39 import org.openstreetmap.josm.Main; 41 import org.openstreetmap.josm.actions.DiskAccessAction;42 40 import org.openstreetmap.josm.actions.SaveActionBase; 43 41 import org.openstreetmap.josm.data.Bounds; … … 62 60 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 63 61 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 64 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;65 62 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 66 import org.openstreetmap.josm.io.WMSLayerExporter;67 63 import org.openstreetmap.josm.io.WMSLayerImporter; 68 64 import org.openstreetmap.josm.io.imagery.Grabber; … … 70 66 import org.openstreetmap.josm.io.imagery.WMSGrabber; 71 67 import org.openstreetmap.josm.io.imagery.WMSRequest; 72 import org.openstreetmap.josm.tools.ImageProvider;73 68 74 69 … … 124 119 protected boolean settingsChanged; 125 120 protected ImageryInfo info; 126 protected MapView mv;127 121 public WmsCache cache; 128 122 private AttributionSupport attribution = new AttributionSupport(); … … 178 172 @Override 179 173 public void hookUpMapView() { 180 mv = Main.map.mapView;181 174 if (info.getUrl() != null) { 182 175 for (WMSLayer layer: Main.map.mapView.getLayersOfType(WMSLayer.class)) { … … 194 187 this.info.setPixelPerDegree(getPPD()); 195 188 } 196 resolution = mv.getDist100PixelText();189 resolution = Main.map.mapView.getDist100PixelText(); 197 190 198 191 final MouseAdapter adapter = new MouseAdapter() { … … 484 477 SeparatorLayerAction.INSTANCE, 485 478 new OffsetAction(), 486 new L oadWmsAction(),487 new SaveWmsAction(),479 new LayerSaveAction(this), 480 new LayerSaveAsAction(this), 488 481 new BookmarkWmsAction(), 489 482 SeparatorLayerAction.INSTANCE, … … 523 516 return -1; 524 517 525 EastNorth cursorEastNorth = mv.getEastNorth(mv.lastMEvent.getX(), mv.lastMEvent.getY()); 518 MouseEvent lastMEvent = Main.map.mapView.lastMEvent; 519 EastNorth cursorEastNorth = Main.map.mapView.getEastNorth(lastMEvent.getX(), lastMEvent.getY()); 526 520 int mouseX = getImageXIndex(cursorEastNorth.east()); 527 521 int mouseY = getImageYIndex(cursorEastNorth.north()); … … 605 599 if (request.getState() != null && !request.isPrecacheOnly()) { 606 600 finishedRequests.add(request); 607 mv.repaint();601 Main.map.mapView.repaint(); 608 602 } 609 603 } finally { … … 669 663 ); 670 664 } else { 671 downloadAndPaintVisible( mv.getGraphics(), mv, true);665 downloadAndPaintVisible(Main.map.mapView.getGraphics(), Main.map.mapView, true); 672 666 } 673 667 } … … 680 674 681 675 private void changeResolution(WMSLayer layer) { 682 layer.resolution = layer.mv.getDist100PixelText();676 layer.resolution = Main.map.mapView.getDist100PixelText(); 683 677 layer.info.setPixelPerDegree(layer.getPPD()); 684 678 layer.settingsChanged = true; … … 761 755 } 762 756 } 763 mv.repaint();757 Main.map.mapView.repaint(); 764 758 } 765 759 @Override … … 775 769 } 776 770 777 public class SaveWmsAction extends AbstractAction {778 public SaveWmsAction() {779 super(tr("Save WMS layer to file"), ImageProvider.get("save"));780 }781 @Override782 public void actionPerformed(ActionEvent ev) {783 File f = SaveActionBase.createAndOpenSaveFileChooser(784 tr("Save WMS layer"), WMSLayerImporter.FILE_FILTER);785 try {786 new WMSLayerExporter().exportData(f, WMSLayer.this);787 } catch (Exception ex) {788 ex.printStackTrace(System.out);789 }790 }791 }792 793 public class LoadWmsAction extends AbstractAction {794 public LoadWmsAction() {795 super(tr("Load WMS layer from file"), ImageProvider.get("open"));796 }797 @Override798 public void actionPerformed(ActionEvent ev) {799 JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true,800 false, tr("Load WMS layer"), WMSLayerImporter.FILE_FILTER, JFileChooser.FILES_ONLY, null);801 if (fc == null) return;802 File f = fc.getSelectedFile();803 if (f == null) return;804 try {805 new WMSLayerImporter(WMSLayer.this).importData(f, NullProgressMonitor.INSTANCE);806 } catch (InvalidClassException ex) {807 JOptionPane.showMessageDialog(Main.parent, ex.getMessage(), tr("File Format Error"), JOptionPane.ERROR_MESSAGE);808 return;809 } catch (Exception ex) {810 ex.printStackTrace();811 JOptionPane.showMessageDialog(Main.parent, ex.getMessage(), tr("Error loading file"), JOptionPane.ERROR_MESSAGE);812 return;813 }814 }815 }816 817 771 /** 818 772 * This action will add a WMS layer menu entry with the current WMS layer … … 860 814 } 861 815 } 862 mv.repaint();816 Main.map.mapView.repaint(); 863 817 } 864 818 } … … 952 906 } 953 907 954 protected Grabber getGrabber(boolean localOnly) {955 if (getInfo().getImageryType() == ImageryType.HTML)956 return new HTMLGrabber( mv, this, localOnly);957 else if (getInfo().getImageryType() == ImageryType.WMS)958 return new WMSGrabber( mv, this, localOnly);908 protected Grabber getGrabber(boolean localOnly) { 909 if (getInfo().getImageryType() == ImageryType.HTML) 910 return new HTMLGrabber(Main.map.mapView, this, localOnly); 911 else if (getInfo().getImageryType() == ImageryType.WMS) 912 return new WMSGrabber(Main.map.mapView, this, localOnly); 959 913 else throw new IllegalStateException("getGrabber() called for non-WMS layer type"); 960 914 } … … 1042 996 1043 997 settingsChanged = true; 1044 mv.repaint(); 998 if (Main.isDisplayingMapView()) { 999 Main.map.mapView.repaint(); 1000 } 1045 1001 if (cache != null) { 1046 1002 cache.saveIndex(); 1047 1003 cache = null; 1048 1004 } 1005 } 1006 1007 @Override 1008 public void onPostLoadFromFile() { 1049 1009 if (info.getUrl() != null) { 1050 1010 cache = new WmsCache(info.getUrl(), imageSize); … … 1052 1012 } 1053 1013 } 1014 1015 @Override 1016 public boolean isSavable() { 1017 return true; // With WMSLayerExporter 1018 } 1019 1020 @Override 1021 public File createAndOpenSaveFileChooser() { 1022 return SaveActionBase.createAndOpenSaveFileChooser(tr("Save WMS file"), WMSLayerImporter.FILE_FILTER); 1023 } 1054 1024 } -
trunk/src/org/openstreetmap/josm/io/FileExporter.java
r3083 r5459 8 8 9 9 import org.openstreetmap.josm.actions.ExtensionFileFilter; 10 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 10 11 import org.openstreetmap.josm.gui.layer.Layer; 11 12 12 public abstract class FileExporter { 13 public ExtensionFileFilter filter; 13 public abstract class FileExporter implements LayerChangeListener { 14 15 public final ExtensionFileFilter filter; 16 17 private boolean enabled; 14 18 15 19 public FileExporter(ExtensionFileFilter filter) { 16 20 this.filter = filter; 21 this.enabled = true; 17 22 } 18 23 … … 24 29 throw new IOException(tr("Could not export ''{0}''.", file.getName())); 25 30 } 31 32 /** 33 * Returns the enabled state of this {@code FileExporter}. When enabled, it is listed and usable in "File->Save" dialogs. 34 * @return true if this {@code FileExporter} is enabled 35 * @since 5459 36 */ 37 public final boolean isEnabled() { 38 return enabled; 39 } 40 41 /** 42 * Sets the enabled state of the {@code FileExporter}. When enabled, it is listed and usable in "File->Save" dialogs. 43 * @param enabled true to enable this {@code FileExporter}, false to disable it 44 * @since 5459 45 */ 46 public final void setEnabled(boolean enabled) { 47 this.enabled = enabled; 48 } 49 50 @Override 51 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 52 // To be overriden by subclasses if their enabled state depends of the active layer nature 53 } 54 55 @Override 56 public void layerAdded(Layer newLayer) { 57 // To be overriden by subclasses if needed 58 } 59 60 @Override 61 public void layerRemoved(Layer oldLayer) { 62 // To be overriden by subclasses if needed 63 } 26 64 } -
trunk/src/org/openstreetmap/josm/io/FileImporter.java
r5361 r5459 17 17 import org.openstreetmap.josm.actions.ExtensionFileFilter; 18 18 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 19 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 20 import org.openstreetmap.josm.gui.layer.Layer; 19 21 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 20 22 21 public abstract class FileImporter implements Comparable<FileImporter> {23 public abstract class FileImporter implements Comparable<FileImporter>, LayerChangeListener { 22 24 23 25 public final ExtensionFileFilter filter; 26 27 private boolean enabled; 24 28 25 29 public FileImporter(ExtensionFileFilter filter) { 26 30 this.filter = filter; 31 this.enabled = true; 27 32 } 28 33 … … 122 127 return new GZIPInputStream(in); 123 128 } 129 130 /** 131 * Returns the enabled state of this {@code FileImporter}. When enabled, it is listed and usable in "File->Open" dialog. 132 * @return true if this {@code FileImporter} is enabled 133 * @since 5459 134 */ 135 public final boolean isEnabled() { 136 return enabled; 137 } 138 139 /** 140 * Sets the enabled state of the {@code FileImporter}. When enabled, it is listed and usable in "File->Open" dialog. 141 * @param enabled true to enable this {@code FileImporter}, false to disable it 142 * @since 5459 143 */ 144 public final void setEnabled(boolean enabled) { 145 this.enabled = enabled; 146 } 147 148 @Override 149 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 150 // To be overriden by subclasses if their enabled state depends of the active layer nature 151 } 152 153 @Override 154 public void layerAdded(Layer newLayer) { 155 // To be overriden by subclasses if needed 156 } 157 158 @Override 159 public void layerRemoved(Layer oldLayer) { 160 // To be overriden by subclasses if needed 161 } 124 162 } -
trunk/src/org/openstreetmap/josm/io/WMSLayerExporter.java
r5457 r5459 38 38 } 39 39 } 40 41 @Override 42 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 43 setEnabled(newLayer instanceof WMSLayer); 44 } 40 45 } -
trunk/src/org/openstreetmap/josm/io/WMSLayerImporter.java
r5457 r5459 9 9 import java.io.ObjectInputStream; 10 10 11 import org.openstreetmap.josm.Main; 11 12 import org.openstreetmap.josm.actions.ExtensionFileFilter; 12 13 import org.openstreetmap.josm.gui.layer.WMSLayer; 13 14 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 15 import org.openstreetmap.josm.gui.util.GuiHelper; 14 16 import org.openstreetmap.josm.tools.CheckParameterUtil; 15 17 … … 55 57 ois.close(); 56 58 } 59 60 // FIXME: remove UI stuff from IO subsystem 61 GuiHelper.runInEDT(new Runnable() { 62 @Override 63 public void run() { 64 Main.main.addLayer(wmsLayer); 65 wmsLayer.onPostLoadFromFile(); 66 } 67 }); 57 68 } 58 69
Note:
See TracChangeset
for help on using the changeset viewer.