Changeset 9751 in josm


Ignore:
Timestamp:
2016-02-07T17:06:04+01:00 (3 years ago)
Author:
Don-vip
Message:

see #12462 - Extend Save Layers dialog for more layer types (patch by holgermappt, modified for checkstyle compliance)

Location:
trunk/src/org/openstreetmap/josm
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r9276 r9751  
    10461046            }
    10471047            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()))) {
    10491052                layersWithUnmodifiedChanges.add(odl);
    10501053            }
  • trunk/src/org/openstreetmap/josm/gui/io/ActionFlagsTableCell.java

    r9078 r9751  
    5757        ActionMap am = getActionMap();
    5858        for (final JCheckBox b : checkBoxes) {
    59             add(b, GBC.eol().fill(GBC.HORIZONTAL));
    6059            b.setPreferredSize(new Dimension(b.getPreferredSize().width, 19));
    6160            b.addActionListener(al);
     
    6867            });
    6968        }
    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>"));
    7669    }
    7770
     
    9184    }
    9285
     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
    93107    @Override
    94108    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     109        updatePanel((SaveLayerInfo) value);
    95110        updateCheckboxes(value);
    96111        return this;
     
    138153    @Override
    139154    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
     155        updatePanel((SaveLayerInfo) value);
    140156        updateCheckboxes(value);
    141157        return this;
  • trunk/src/org/openstreetmap/josm/gui/io/LayerNameAndFilePathTableCell.java

    r9246 r9751  
    8181        StringBuilder sb = new StringBuilder();
    8282        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>");
    8890        setToolTipText(sb.toString());
    8991        return this;
     
    99101        StringBuilder sb = new StringBuilder();
    100102        sb.append("<html>")
    101           .append(addLblLayerName(info))
    102           .append("<br/>");
    103 
    104         add(btnFileChooser, GBC.std());
    105         add(tfFilename, GBC.eol().fill(GBC.HORIZONTAL).insets(1, 0, 0, 0));
    106         tfFilename.selectAll();
    107 
    108         sb.append(tfFilename.getToolTipText())
    109           .append("</html>");
     103          .append(addLblLayerName(info));
     104
     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();
     109
     110            sb.append("<br>")
     111              .append(tfFilename.getToolTipText());
     112        }
     113        sb.append("</html>");
    110114        setToolTipText(sb.toString());
    111115        return this;
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayerInfo.java

    r9078 r9751  
    4747
    4848    /**
     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    /**
    4967     * Replies true if preconditions should be checked before saving; false, otherwise
    5068     *
     
    8199     */
    82100    public void setDoSaveToFile(boolean doSaveToFile) {
    83         this.doSaveToFile = doSaveToFile;
     101        this.doSaveToFile = isSavable() ? doSaveToFile : false;
    84102    }
    85103
     
    94112
    95113    /**
    96      * Sets whether this layer should be uploaded to a file
     114     * Sets whether this layer should be uploaded to a server
    97115     *
    98116     * @param doUploadToServer {@code true} to upload; {@code false}, to skip uploading
    99117     */
    100 
    101118    public void setDoUploadToServer(boolean doUploadToServer) {
    102         this.doUploadToServer = doUploadToServer;
     119        this.doUploadToServer = isUploadable() ? doUploadToServer : false;
    103120    }
    104121
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersModel.java

    r9556 r9751  
    103103    @Override
    104104    public void setValueAt(Object value, int row, int column) {
     105        final SaveLayerInfo info = this.layerInfo.get(row);
    105106        switch(column) {
    106107        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            }
    109112            break;
    110113        case columnActions:
    111114            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]);
    114117            break;
    115118        }
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersTableColumnModel.java

    r8960 r9751  
    4747
    4848                } else {
    49                     panel.add(pnlEmpty, defaultCellStyle);
     49                    if (info.isUploadable()) {
     50                        panel.add(pnlEmpty, defaultCellStyle);
     51                    }
    5052                    if (info.getLayer().requiresUploadToServer()) {
    5153                        sb.append(tr("Layer ''{0}'' has modifications which are discouraged to be uploaded.", info.getName()));
     
    6163                            info.getName(), info.getFile().toString()));
    6264                } else {
    63                     panel.add(pnlEmpty, defaultCellStyle);
     65                    if (info.isSavable()) {
     66                        panel.add(pnlEmpty, defaultCellStyle);
     67                    }
    6468                    sb.append(tr("Layer ''{0}'' has no modifications to be saved.", info.getName()));
    6569                }
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractModifiableLayer.java

    r7937 r9751  
    1010 * @since 7358
    1111 */
    12 public abstract class AbstractModifiableLayer extends Layer {
     12public abstract class AbstractModifiableLayer extends Layer implements UploadToServer, SaveToFile {
    1313
    1414    /**
     
    2121
    2222    /**
     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    /**
    2335     * Determines if the data managed by this layer needs to be uploaded to
    2436     * the server because it contains modified data.
     
    2739     * the server because it contains modified data; false, otherwise
    2840     */
     41    @Override
    2942    public boolean requiresUploadToServer() {
    3043        // Override if needed
     
    4053     * @return true if the data managed by this layer needs to be saved to a file
    4154     */
     55    @Override
    4256    public boolean requiresSaveToFile() {
    4357        // Override if needed
     
    5165     * @return true if upload is discouraged for this layer; false, otherwise
    5266     */
     67    @Override
    5368    public boolean isUploadDiscouraged() {
    5469        // Override if needed
     
    6580     * Initializes the layer after a successful save of data to a file.
    6681     */
     82    @Override
    6783    public void onPostSaveToFile() {
    6884        // Override if needed
     
    7288     * Initializes the layer after a successful upload to the server.
    7389     */
     90    @Override
    7491    public void onPostUploadToServer() {
    7592        // Override if needed
     
    8198     * @return a new {@code AbstractIOTask} for uploading data, or {@code null} if not applicable
    8299     */
     100    @Override
    83101    public AbstractIOTask createUploadTask(ProgressMonitor monitor) {
    84102        // Override if needed
     
    90108     * @return the upload dialog for this layer, or {@code null} if not applicable
    91109     */
     110    @Override
    92111    public AbstractUploadDialog getUploadDialog() {
    93112        // Override if needed
  • trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java

    r8846 r9751  
    4848 * @since 7522
    4949 */
    50 public class NoteLayer extends AbstractModifiableLayer implements MouseListener {
     50public class NoteLayer extends AbstractModifiableLayer implements MouseListener, UploadToServer, SaveToFile {
    5151
    5252    private final NoteData noteData;
     
    8383    public boolean isModified() {
    8484        return noteData.isModified();
     85    }
     86
     87    @Override
     88    public boolean isUploadable() {
     89        return true;
    8590    }
    8691
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r9721 r9751  
    109109 * @since 17
    110110 */
    111 public class OsmDataLayer extends AbstractModifiableLayer implements Listener, SelectionChangedListener {
     111public class OsmDataLayer extends AbstractModifiableLayer implements Listener, SelectionChangedListener, UploadToServer, SaveToFile {
    112112    /** Property used to know if this layer has to be saved on disk */
    113113    public static final String REQUIRES_SAVE_TO_DISK_PROP = OsmDataLayer.class.getName() + ".requiresSaveToDisk";
     
    836836
    837837    @Override
     838    public boolean isUploadable() {
     839        return true;
     840    }
     841
     842    @Override
    838843    public boolean requiresUploadToServer() {
    839844        return requiresUploadToServer;
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r9660 r9751  
    6060import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToNextMarker;
    6161import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToPreviousMarker;
     62import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
    6263import org.openstreetmap.josm.gui.layer.Layer;
    6364import org.openstreetmap.josm.gui.util.GuiHelper;
     
    6970 * Layer displaying geottaged pictures.
    7071 */
    71 public class GeoImageLayer extends Layer implements PropertyChangeListener, JumpToMarkerLayer {
     72public class GeoImageLayer extends AbstractModifiableLayer implements PropertyChangeListener, JumpToMarkerLayer {
    7273
    7374    private static List<Action> menuAdditions = new LinkedList<>();
     
    369370    public String getToolTipText() {
    370371        return infoText();
     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     */
     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;
    371389    }
    372390
Note: See TracChangeset for help on using the changeset viewer.