Ticket #7429: singleton.patch
| File singleton.patch, 6.6 KB (added by , 14 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/SaveAction.java
1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;6 6 7 7 import java.awt.event.KeyEvent; 8 8 import java.io.File; … … 19 19 * @author imi 20 20 */ 21 21 public class SaveAction extends SaveActionBase { 22 private static SaveAction instance = new SaveAction(); 22 23 23 24 /** 24 25 * Construct the action with "Save" as label. 25 26 * @param layer Save this layer. 26 27 */ 27 p ublicSaveAction() {28 private SaveAction() { 28 29 super(tr("Save"), "save", tr("Save the current data."), 29 30 Shortcut.registerShortcut("system:save", tr("File: {0}", tr("Save")), KeyEvent.VK_S, Shortcut.CTRL)); 30 31 putValue("help", ht("/Action/Save")); 31 32 } 32 33 34 public static SaveAction getInstance() { 35 return instance; 36 } 37 38 33 39 @Override public File getFile(Layer layer) { 34 40 File f = layer.getAssociatedFile(); 35 41 if(f != null && ! f.exists()) { -
src/org/openstreetmap/josm/actions/SaveActionBase.java
9 9 import java.util.Collection; 10 10 import java.util.LinkedList; 11 11 import java.util.List; 12 12 13 import javax.swing.JFileChooser; 13 14 import javax.swing.JOptionPane; 14 15 import javax.swing.filechooser.FileFilter; … … 32 33 33 34 @Override 34 35 public void actionPerformed(ActionEvent e) { 35 if (!isEnabled()) {36 if (!isEnabled()) 36 37 return; 37 }38 38 boolean saved = doSave(); 39 39 if (saved) { 40 40 addToFileOpenHistory(); … … 59 59 return doInternalSave(layer, file); 60 60 } 61 61 62 public boolean doSave(Layer layer, File file) {62 public static boolean doSave(Layer layer, File file) { 63 63 if(!checkSaveConditions(layer)) 64 64 return false; 65 65 return doInternalSave(layer, file); 66 66 } 67 67 68 private boolean doInternalSave(Layer layer, File file) {68 private static boolean doInternalSave(Layer layer, File file) { 69 69 if (file == null) 70 70 return false; 71 71 … … 103 103 * there is no conflict etc.) 104 104 * @return <code>true</code>, if it is safe to save. 105 105 */ 106 public boolean checkSaveConditions(Layer layer) {106 public static boolean checkSaveConditions(Layer layer) { 107 107 if (layer instanceof GpxLayer) 108 108 return ((GpxLayer)layer).data != null; 109 109 else if (layer instanceof OsmDataLayer) { … … 152 152 * 153 153 * @return <code>true</code>, if a save result in an empty data set. 154 154 */ 155 private boolean isDataSetEmpty(OsmDataLayer layer) {155 private static boolean isDataSetEmpty(OsmDataLayer layer) { 156 156 for (OsmPrimitive osm : layer.data.allNonDeletedPrimitives()) 157 157 if (!osm.isDeleted() || !osm.isNewOrUndeleted()) 158 158 return false; -
src/org/openstreetmap/josm/gui/MainMenu.java
119 119 public final OpenFileAction openFile = new OpenFileAction(); 120 120 public final RecentlyOpenedFilesMenu recentlyOpened = new RecentlyOpenedFilesMenu(); 121 121 public final OpenLocationAction openLocation = new OpenLocationAction(); 122 public final JosmAction save = new SaveAction();122 public final JosmAction save = SaveAction.getInstance(); 123 123 public final JosmAction saveAs = new SaveAsAction(); 124 124 public JosmAction sessionLoad; 125 125 public JosmAction sessionSaveAs; -
src/org/openstreetmap/josm/gui/layer/Layer.java
365 365 } 366 366 367 367 public void actionPerformed(ActionEvent e) { 368 new SaveAction().doSave(layer);368 SaveAction.getInstance().doSave(layer); 369 369 } 370 370 } 371 371 -
src/org/openstreetmap/josm/gui/io/SaveLayerTask.java
47 47 public void run() { 48 48 try { 49 49 parentMonitor.subTask(tr("Saving layer to ''{0}'' ...", layerInfo.getFile().toString())); 50 if (! new SaveAction().doSave(layerInfo.getLayer(), layerInfo.getFile())) {50 if (!SaveAction.doSave(layerInfo.getLayer(), layerInfo.getFile())) { 51 51 setFailed(true); 52 52 return; 53 53 } -
src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java
18 18 import java.io.PrintWriter; 19 19 import java.io.UnsupportedEncodingException; 20 20 import java.io.Writer; 21 import java.net.MalformedURLException; 21 22 import java.net.URI; 22 23 import java.net.URL; 23 import java.net.MalformedURLException;24 24 import java.util.Collection; 25 25 import java.util.Collections; 26 26 … … 34 34 import javax.swing.JTextField; 35 35 import javax.swing.SwingConstants; 36 36 37 import org.w3c.dom.Element;38 39 37 import org.openstreetmap.josm.actions.SaveAction; 40 38 import org.openstreetmap.josm.gui.layer.Layer; 41 39 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 45 43 import org.openstreetmap.josm.io.session.SessionWriter.ExportSupport; 46 44 import org.openstreetmap.josm.tools.GBC; 47 45 import org.openstreetmap.josm.tools.ImageProvider; 46 import org.w3c.dom.Element; 48 47 49 48 public class OsmDataSessionExporter implements SessionLayerExporter { 50 49 … … 74 73 } 75 74 76 75 public void actionPerformed(ActionEvent e) { 77 new SaveAction().doSave(layer);76 SaveAction.getInstance().doSave(layer); 78 77 updateEnabledState(); 79 78 } 80 79
