Changeset 14338 in josm for trunk/src/org/openstreetmap/josm/actions/AbstractMergeAction.java
- Timestamp:
- 2018-10-16T00:32:46+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AbstractMergeAction.java
r14336 r14338 9 9 10 10 import javax.swing.DefaultListCellRenderer; 11 import javax.swing.JCheckBox; 11 12 import javax.swing.JLabel; 12 13 import javax.swing.JList; … … 40 41 label.setToolTipText(layer.getToolTipText()); 41 42 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; 42 84 } 43 85 } … … 84 126 */ 85 127 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) { 86 152 return askTargetLayer(targetLayers.toArray(new Layer[0]), 87 tr("Please select the target layer."), 153 tr("Please select the target layer."), checkbox, 88 154 tr("Select target layer"), 89 tr("Merge"), "dialogs/mergedown" );90 } 91 92 /** 93 * Ask s atarget layer.155 tr("Merge"), "dialogs/mergedown", showCheckbox, checkboxDefault); 156 } 157 158 /** 159 * Ask user to choose the target layer. 94 160 * @param <T> type of layer 95 161 * @param targetLayers array of proposed target layers … … 100 166 * @return chosen target layer 101 167 */ 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 */ 102 186 @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) { 104 189 JosmComboBox<T> layerList = new JosmComboBox<>(targetLayers); 105 190 layerList.setRenderer(new LayerListCellRenderer()); … … 109 194 pnl.add(new JLabel(label), GBC.eol()); 110 195 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 } 111 203 112 204 ExtendedDialog ed = new ExtendedDialog(MainApplication.getMainFrame(), title, buttonText, tr("Cancel")); … … 115 207 ed.showDialog(); 116 208 if (ed.getValue() != 1) { 117 return n ull;118 } 119 return (T) layerList.getSelectedItem();209 return new TargetLayerDialogResult<>(); 210 } 211 return new TargetLayerDialogResult<>((T) layerList.getSelectedItem(), cb != null && cb.isSelected()); 120 212 } 121 213
Note:
See TracChangeset
for help on using the changeset viewer.