Ignore:
Timestamp:
2018-10-16T00:32:46+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #16755 - Cut overlapping GPX layers when merging (patch by Bjoeni, modified)

File:
1 edited

Legend:

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

    r14336 r14338  
    99
    1010import javax.swing.DefaultListCellRenderer;
     11import javax.swing.JCheckBox;
    1112import javax.swing.JLabel;
    1213import javax.swing.JList;
     
    4041            label.setToolTipText(layer.getToolTipText());
    4142            return label;
     43        }
     44    }
     45
     46    /**
     47     * <code>TargetLayerDialogResult</code> returned by {@link #askTargetLayer(List, String, boolean)}
     48     * containing the selectedTargetLayer and whether the checkbox is ticked
     49     * @param <T> type of layer
     50     * @since 14338
     51     */
     52    public static class TargetLayerDialogResult<T extends Layer> {
     53        /**
     54         * The selected target layer of type T
     55         */
     56        public T selectedTargetLayer;
     57        /**
     58         * Whether the checkbox is ticked
     59         */
     60        public boolean checkboxTicked = false;
     61
     62        /**
     63         * Constructs a new {@link TargetLayerDialogResult}
     64         */
     65        public TargetLayerDialogResult() {
     66        }
     67
     68        /**
     69         * Constructs a new {@link TargetLayerDialogResult}
     70         * @param sel the selected target layer of type T
     71         */
     72        public TargetLayerDialogResult(T sel) {
     73            selectedTargetLayer = sel;
     74        }
     75
     76        /**
     77         * Constructs a new {@link TargetLayerDialogResult}
     78         * @param sel the selected target layer of type T
     79         * @param ch whether the checkbox was ticked
     80         */
     81        public TargetLayerDialogResult(T sel, boolean ch) {
     82            selectedTargetLayer = sel;
     83            checkboxTicked = ch;
    4284        }
    4385    }
     
    84126     */
    85127    protected static Layer askTargetLayer(List<Layer> targetLayers) {
     128        return askTargetLayer(targetLayers, false, null, false).selectedTargetLayer;
     129    }
     130
     131    /**
     132     * Ask user to choose the target layer and shows a checkbox.
     133     * @param targetLayers list of candidate target layers.
     134     * @param checkbox The text of the checkbox shown to the user.
     135     * @param checkboxDefault whether the checkbox is ticked by default
     136     * @return The {@link TargetLayerDialogResult} containing the chosen target layer and the state of the checkbox
     137     */
     138    protected static TargetLayerDialogResult<Layer> askTargetLayer(List<Layer> targetLayers, String checkbox, boolean checkboxDefault) {
     139        return askTargetLayer(targetLayers, true, checkbox, checkboxDefault);
     140    }
     141
     142    /**
     143     * Ask user to choose the target layer and shows a checkbox.
     144     * @param targetLayers list of candidate target layers.
     145     * @param showCheckbox whether the checkbox is shown
     146     * @param checkbox The text of the checkbox shown to the user.
     147     * @param checkboxDefault whether the checkbox is ticked by default
     148     * @return The {@link TargetLayerDialogResult} containing the chosen target layer and the state of the checkbox
     149     */
     150    protected static TargetLayerDialogResult<Layer> askTargetLayer(List<Layer> targetLayers, boolean showCheckbox,
     151            String checkbox, boolean checkboxDefault) {
    86152        return askTargetLayer(targetLayers.toArray(new Layer[0]),
    87                 tr("Please select the target layer."),
     153                tr("Please select the target layer."), checkbox,
    88154                tr("Select target layer"),
    89                 tr("Merge"), "dialogs/mergedown");
    90     }
    91 
    92     /**
    93      * Asks a target layer.
     155                tr("Merge"), "dialogs/mergedown", showCheckbox, checkboxDefault);
     156    }
     157
     158    /**
     159     * Ask user to choose the target layer.
    94160     * @param <T> type of layer
    95161     * @param targetLayers array of proposed target layers
     
    100166     * @return chosen target layer
    101167     */
     168    public static <T extends Layer> T askTargetLayer(T[] targetLayers, String label, String title, String buttonText, String buttonIcon) {
     169        return askTargetLayer(targetLayers, label, null, title, buttonText, buttonIcon, false, false).selectedTargetLayer;
     170    }
     171
     172    /**
     173     * Ask user to choose the target layer. Can show a checkbox.
     174     * @param <T> type of layer
     175     * @param targetLayers array of proposed target layers
     176     * @param label label displayed in dialog
     177     * @param checkbox text of the checkbox displayed
     178     * @param title title of dialog
     179     * @param buttonText text of button used to select target layer
     180     * @param buttonIcon icon name of button used to select target layer
     181     * @param showCheckbox whether the checkbox is shown
     182     * @param checkboxDefault whether the checkbox is ticked by default
     183     * @return The {@link TargetLayerDialogResult} containing the chosen target layer and the state of the checkbox
     184     * @since 14338
     185     */
    102186    @SuppressWarnings("unchecked")
    103     public static <T extends Layer> T askTargetLayer(T[] targetLayers, String label, String title, String buttonText, String buttonIcon) {
     187    public static <T extends Layer> TargetLayerDialogResult<T> askTargetLayer(T[] targetLayers, String label, String checkbox, String title,
     188            String buttonText, String buttonIcon, boolean showCheckbox, boolean checkboxDefault) {
    104189        JosmComboBox<T> layerList = new JosmComboBox<>(targetLayers);
    105190        layerList.setRenderer(new LayerListCellRenderer());
     
    109194        pnl.add(new JLabel(label), GBC.eol());
    110195        pnl.add(layerList, GBC.eol().fill(GBC.HORIZONTAL));
     196
     197        JCheckBox cb = null;
     198        if (showCheckbox) {
     199            cb = new JCheckBox(checkbox);
     200            cb.setSelected(checkboxDefault);
     201            pnl.add(cb, GBC.eol());
     202        }
    111203
    112204        ExtendedDialog ed = new ExtendedDialog(MainApplication.getMainFrame(), title, buttonText, tr("Cancel"));
     
    115207        ed.showDialog();
    116208        if (ed.getValue() != 1) {
    117             return null;
    118         }
    119         return (T) layerList.getSelectedItem();
     209            return new TargetLayerDialogResult<>();
     210        }
     211        return new TargetLayerDialogResult<>((T) layerList.getSelectedItem(), cb != null && cb.isSelected());
    120212    }
    121213
Note: See TracChangeset for help on using the changeset viewer.