Ticket #12462: ExtendedSaveLayersDialog.patch
| File ExtendedSaveLayersDialog.patch, 19.7 KB (added by , 10 years ago) |
|---|
-
src/org/openstreetmap/josm/Main.java
1045 1045 continue; 1046 1046 } 1047 1047 AbstractModifiableLayer odl = (AbstractModifiableLayer) l; 1048 if ((odl.requiresSaveToFile() || (odl.requiresUploadToServer() && !odl.isUploadDiscouraged())) && odl.isModified()) { 1048 if (odl.isModified() && 1049 ((!odl.isSavable() && !odl.isUploadable()) || 1050 odl.requiresSaveToFile() || 1051 (odl.requiresUploadToServer() && !odl.isUploadDiscouraged()))) { 1049 1052 layersWithUnmodifiedChanges.add(odl); 1050 1053 } 1051 1054 } -
src/org/openstreetmap/josm/gui/io/ActionFlagsTableCell.java
56 56 57 57 ActionMap am = getActionMap(); 58 58 for (final JCheckBox b : checkBoxes) { 59 add(b, GBC.eol().fill(GBC.HORIZONTAL));60 59 b.setPreferredSize(new Dimension(b.getPreferredSize().width, 19)); 61 60 b.addActionListener(al); 62 61 am.put(b.getText(), new AbstractAction() { … … 67 66 } 68 67 }); 69 68 } 70 71 setToolTipText(tr("<html>"+72 "Select which actions to perform for this layer, if you click the leftmost button.<br/>"+73 "Check \"upload\" to upload the changes to the OSM server.<br/>"+74 "Check \"Save\" to save the layer to the file specified on the left."+75 "</html>"));76 69 } 77 70 78 71 protected void updateCheckboxes(Object v) { … … 90 83 } 91 84 } 92 85 86 private void updatePanel(SaveLayerInfo info) { 87 StringBuilder sb = new StringBuilder(); 88 sb.append("<html>"); 89 sb.append(tr("Select which actions to perform for this layer, if you click the leftmost button.")); 90 removeAll(); 91 if (info != null) { 92 if (info.isUploadable()) { 93 sb.append("<br/>"); 94 sb.append(tr("Check \"Upload\" to upload the changes to the OSM server.")); 95 add(checkBoxes[0], GBC.eol().fill(GBC.HORIZONTAL)); 96 } 97 if (info.isSavable()) { 98 sb.append("<br/>"); 99 sb.append(tr("Check \"Save\" to save the layer to the file specified on the left.")); 100 add(checkBoxes[1], GBC.eol().fill(GBC.HORIZONTAL)); 101 } 102 } 103 sb.append("</html>"); 104 setToolTipText(sb.toString()); 105 } 106 93 107 @Override 94 108 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 109 updatePanel((SaveLayerInfo) value); 95 110 updateCheckboxes(value); 96 111 return this; 97 112 } … … 137 152 138 153 @Override 139 154 public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { 155 updatePanel((SaveLayerInfo) value); 140 156 updateCheckboxes(value); 141 157 return this; 142 158 } -
src/org/openstreetmap/josm/gui/io/LayerNameAndFilePathTableCell.java
80 80 SaveLayerInfo info = (SaveLayerInfo) value; 81 81 StringBuilder sb = new StringBuilder(); 82 82 sb.append("<html>") 83 .append(addLblLayerName(info)) 84 .append("<br>"); 85 add(btnFileChooser, GBC.std()); 86 sb.append(addLblFilename(info)) 87 .append("</html>"); 83 .append(addLblLayerName(info)); 84 if (info.isSavable()) { 85 add(btnFileChooser, GBC.std()); 86 sb.append("<br>") 87 .append(addLblFilename(info)); 88 } 89 sb.append("</html>"); 88 90 setToolTipText(sb.toString()); 89 91 return this; 90 92 } … … 98 100 99 101 StringBuilder sb = new StringBuilder(); 100 102 sb.append("<html>") 101 .append(addLblLayerName(info)) 102 .append("<br/>"); 103 .append(addLblLayerName(info)); 103 104 104 add(btnFileChooser, GBC.std()); 105 add(tfFilename, GBC.eol().fill(GBC.HORIZONTAL).insets(1, 0, 0, 0)); 106 tfFilename.selectAll(); 105 if (info.isSavable()) { 106 add(btnFileChooser, GBC.std()); 107 add(tfFilename, GBC.eol().fill(GBC.HORIZONTAL).insets(1, 0, 0, 0)); 108 tfFilename.selectAll(); 107 109 108 sb.append(tfFilename.getToolTipText()) 109 .append("</html>"); 110 sb.append("<br>") 111 .append(tfFilename.getToolTipText()); 112 } 113 sb.append("</html>"); 110 114 setToolTipText(sb.toString()); 111 115 return this; 112 116 } -
src/org/openstreetmap/josm/gui/io/SaveLayerInfo.java
46 46 } 47 47 48 48 /** 49 * Replies true if the layer can be saved to a file 50 * 51 * @return {@code true} if the layer can be saved to a file; {@code false} otherwise 52 */ 53 public boolean isSavable() { 54 return layer.isSavable(); 55 } 56 57 /** 58 * Replies true if the layer can be uploaded to a server 59 * 60 * @return {@code true} if the layer can be uploaded to a server; {@code false} otherwise 61 */ 62 public boolean isUploadable() { 63 return layer.isUploadable(); 64 } 65 66 /** 49 67 * Replies true if preconditions should be checked before saving; false, otherwise 50 68 * 51 69 * @return true if preconditions should be checked before saving; false, otherwise … … 80 98 * @param doSaveToFile true to save; false, to skip saving 81 99 */ 82 100 public void setDoSaveToFile(boolean doSaveToFile) { 83 this.doSaveToFile = doSaveToFile;101 this.doSaveToFile = isSavable() ? doSaveToFile : false; 84 102 } 85 103 86 104 /** … … 93 111 } 94 112 95 113 /** 96 * Sets whether this layer should be uploaded to a file114 * Sets whether this layer should be uploaded to a server 97 115 * 98 116 * @param doUploadToServer {@code true} to upload; {@code false}, to skip uploading 99 117 */ 100 101 118 public void setDoUploadToServer(boolean doUploadToServer) { 102 this.doUploadToServer = doUploadToServer;119 this.doUploadToServer = isUploadable() ? doUploadToServer : false; 103 120 } 104 121 105 122 /** -
src/org/openstreetmap/josm/gui/io/SaveLayersModel.java
102 102 103 103 @Override 104 104 public void setValueAt(Object value, int row, int column) { 105 final SaveLayerInfo info = this.layerInfo.get(row); 105 106 switch(column) { 106 107 case columnFilename: 107 this.layerInfo.get(row).setFile((File) value); 108 this.layerInfo.get(row).setDoSaveToFile(true); 108 info.setFile((File) value); 109 if (info.isSavable()) { 110 info.setDoSaveToFile(true); 111 } 109 112 break; 110 113 case columnActions: 111 114 boolean[] values = (boolean[]) value; 112 this.layerInfo.get(row).setDoUploadToServer(values[0]);113 this.layerInfo.get(row).setDoSaveToFile(values[1]);115 info.setDoUploadToServer(values[0]); 116 info.setDoSaveToFile(values[1]); 114 117 break; 115 118 } 116 119 fireTableDataChanged(); -
src/org/openstreetmap/josm/gui/io/SaveLayersTableColumnModel.java
46 46 sb.append(tr("Layer ''{0}'' has modifications which should be uploaded to the server.", info.getName())); 47 47 48 48 } else { 49 panel.add(pnlEmpty, defaultCellStyle); 49 if (info.isUploadable()) { 50 panel.add(pnlEmpty, defaultCellStyle); 51 } 50 52 if (info.getLayer().requiresUploadToServer()) { 51 53 sb.append(tr("Layer ''{0}'' has modifications which are discouraged to be uploaded.", info.getName())); 52 54 } else { … … 53 55 sb.append(tr("Layer ''{0}'' has no modifications to be uploaded.", info.getName())); 54 56 } 55 57 } 58 56 59 sb.append("<br/>"); 57 58 60 if (info.getLayer().requiresSaveToFile()) { 59 61 panel.add(needsSave, defaultCellStyle); 60 62 sb.append(tr("Layer ''{0}'' has modifications which should be saved to its associated file ''{1}''.", 61 63 info.getName(), info.getFile().toString())); 62 64 } else { 63 panel.add(pnlEmpty, defaultCellStyle); 65 if (info.isSavable()) { 66 panel.add(pnlEmpty, defaultCellStyle); 67 } 64 68 sb.append(tr("Layer ''{0}'' has no modifications to be saved.", info.getName())); 65 69 } 66 70 } -
src/org/openstreetmap/josm/gui/layer/AbstractModifiableLayer.java
9 9 * A modifiable layer. 10 10 * @since 7358 11 11 */ 12 public abstract class AbstractModifiableLayer extends Layer {12 public abstract class AbstractModifiableLayer extends Layer implements UploadToServer, SaveToFile { 13 13 14 14 /** 15 15 * Constructs a new {@code ModifiableLayer}. … … 20 20 } 21 21 22 22 /** 23 * Determines if the layer is able to upload data and implements the 24 * {@code UploadToServer} interface. 25 * 26 * @return true if the layer is able to upload data; false, otherwise 27 */ 28 @Override 29 public boolean isUploadable() { 30 // Override if needed 31 return false; 32 } 33 34 /** 23 35 * Determines if the data managed by this layer needs to be uploaded to 24 36 * the server because it contains modified data. 25 37 * … … 26 38 * @return true if the data managed by this layer needs to be uploaded to 27 39 * the server because it contains modified data; false, otherwise 28 40 */ 41 @Override 29 42 public boolean requiresUploadToServer() { 30 43 // Override if needed 31 44 return false; … … 39 52 * 40 53 * @return true if the data managed by this layer needs to be saved to a file 41 54 */ 55 @Override 42 56 public boolean requiresSaveToFile() { 43 57 // Override if needed 44 58 return false; … … 50 64 * 51 65 * @return true if upload is discouraged for this layer; false, otherwise 52 66 */ 67 @Override 53 68 public boolean isUploadDiscouraged() { 54 69 // Override if needed 55 70 return false; … … 64 79 /** 65 80 * Initializes the layer after a successful save of data to a file. 66 81 */ 82 @Override 67 83 public void onPostSaveToFile() { 68 84 // Override if needed 69 85 } … … 71 87 /** 72 88 * Initializes the layer after a successful upload to the server. 73 89 */ 90 @Override 74 91 public void onPostUploadToServer() { 75 92 // Override if needed 76 93 } … … 80 97 * @param monitor The progress monitor 81 98 * @return a new {@code AbstractIOTask} for uploading data, or {@code null} if not applicable 82 99 */ 100 @Override 83 101 public AbstractIOTask createUploadTask(ProgressMonitor monitor) { 84 102 // Override if needed 85 103 return null; … … 89 107 * Returns the upload dialog for this layer. 90 108 * @return the upload dialog for this layer, or {@code null} if not applicable 91 109 */ 110 @Override 92 111 public AbstractUploadDialog getUploadDialog() { 93 112 // Override if needed 94 113 return null; -
src/org/openstreetmap/josm/gui/layer/NoteLayer.java
47 47 * A layer to hold Note objects. 48 48 * @since 7522 49 49 */ 50 public class NoteLayer extends AbstractModifiableLayer implements MouseListener {50 public class NoteLayer extends AbstractModifiableLayer implements MouseListener, UploadToServer, SaveToFile { 51 51 52 52 private final NoteData noteData; 53 53 … … 85 85 } 86 86 87 87 @Override 88 public boolean isUploadable() { 89 return true; 90 } 91 92 @Override 88 93 public boolean requiresUploadToServer() { 89 94 return isModified(); 90 95 } -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
107 107 * @author imi 108 108 * @since 17 109 109 */ 110 public class OsmDataLayer extends AbstractModifiableLayer implements Listener, SelectionChangedListener {110 public class OsmDataLayer extends AbstractModifiableLayer implements Listener, SelectionChangedListener, UploadToServer, SaveToFile { 111 111 /** Property used to know if this layer has to be saved on disk */ 112 112 public static final String REQUIRES_SAVE_TO_DISK_PROP = OsmDataLayer.class.getName() + ".requiresSaveToDisk"; 113 113 /** Property used to know if this layer has to be uploaded */ … … 832 832 } 833 833 834 834 @Override 835 public boolean isUploadable() { 836 return true; 837 } 838 839 @Override 835 840 public boolean requiresUploadToServer() { 836 841 return requiresUploadToServer; 837 842 } -
src/org/openstreetmap/josm/gui/layer/SaveToFile.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.layer; 3 4 /** 5 * Interface for layers that can save data to a file. 6 */ 7 public interface SaveToFile { 8 9 /** 10 * Replies the savable state of the layer (i.e. if it can be saved through 11 * a "File->Save" dialog). A layer that implements the 12 * {@code SaveToFile} interface must return {@code true}. 13 * 14 * @return {@code true} if the layer can be saved to a file; {@code false}, otherwise 15 */ 16 public boolean isSavable(); 17 18 /** 19 * Determines if the data managed by this layer needs to be saved to 20 * a file. Only replies true if a file is assigned to this layer and 21 * if the data managed by this layer has been modified since the last 22 * save operation to the file. 23 * 24 * @return {@code true} if the data managed by this layer needs to be saved to a file; {@code false}, otherwise 25 */ 26 public boolean requiresSaveToFile(); 27 28 /** 29 * Initializes the layer after a successful save of data to a file. 30 */ 31 public void onPostSaveToFile(); 32 } -
src/org/openstreetmap/josm/gui/layer/UploadToServer.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.layer; 3 4 import org.openstreetmap.josm.gui.io.AbstractIOTask; 5 import org.openstreetmap.josm.gui.io.AbstractUploadDialog; 6 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 7 8 /** 9 * Interface for layers that can upload data. 10 */ 11 public interface UploadToServer { 12 13 /** 14 * Determines if the layer is able to upload data and implements the 15 * {@code UploadToServer} interface. A layer that implements the 16 * {@code UploadToServer} interface must return {@code true}. 17 * 18 * @return {@code true} if the layer is able to upload data; {@code false}, otherwise 19 */ 20 public boolean isUploadable(); 21 22 /** 23 * Determines if the data managed by this layer needs to be uploaded to 24 * the server because it contains modified data. 25 * 26 * @return {@code true} if the data managed by this layer needs to be 27 * uploaded to the server because it contains modified data; 28 * {@code false}, otherwise 29 */ 30 public boolean requiresUploadToServer(); 31 32 /** 33 * Determines if upload of data managed by this layer is discouraged. 34 * This feature allows to use "private" data layers. 35 * 36 * @return {@code true} if upload is discouraged for this layer; {@code false}, otherwise 37 */ 38 public boolean isUploadDiscouraged(); 39 40 /** 41 * Initializes the layer after a successful upload to the server. 42 */ 43 public void onPostUploadToServer(); 44 45 /** 46 * Creates a new {@code AbstractIOTask} for uploading data. 47 * @param monitor The progress monitor 48 * @return a new {@code AbstractIOTask} for uploading data, or {@code null} if not applicable 49 */ 50 public AbstractIOTask createUploadTask(ProgressMonitor monitor); 51 52 /** 53 * Returns the upload dialog for this layer. 54 * @return the upload dialog for this layer, or {@code null} if not applicable 55 */ 56 public AbstractUploadDialog getUploadDialog(); 57 } -
src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
59 59 import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToMarkerLayer; 60 60 import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToNextMarker; 61 61 import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToPreviousMarker; 62 import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer; 62 63 import org.openstreetmap.josm.gui.layer.Layer; 63 64 import org.openstreetmap.josm.gui.util.GuiHelper; 64 65 import org.openstreetmap.josm.io.JpgImporter; … … 68 69 /** 69 70 * Layer displaying geottaged pictures. 70 71 */ 71 public class GeoImageLayer extends Layer implements PropertyChangeListener, JumpToMarkerLayer {72 public class GeoImageLayer extends AbstractModifiableLayer implements PropertyChangeListener, JumpToMarkerLayer { 72 73 73 74 private static List<Action> menuAdditions = new LinkedList<>(); 74 75 … … 370 371 return infoText(); 371 372 } 372 373 374 /** 375 * Determines if data managed by this layer has been modified. That is 376 * the case if one image has modified GPS data. 377 * @return {@code true} if data has been modified; {@code false}, otherwise 378 */ 373 379 @Override 380 public boolean isModified() { 381 if (data != null) { 382 for (ImageEntry e : data) { 383 if (e.hasNewGpsData()) { 384 return true; 385 } 386 } 387 } 388 return false; 389 } 390 391 @Override 374 392 public boolean isMergable(Layer other) { 375 393 return other instanceof GeoImageLayer; 376 394 }
