Changeset 9556 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-01-21T01:32:52+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/io
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
r9543 r9556 9 9 import java.awt.Dimension; 10 10 import java.awt.Graphics2D; 11 import java.awt.GraphicsEnvironment; 11 12 import java.awt.GridBagConstraints; 12 13 import java.awt.GridBagLayout; … … 165 166 } 166 167 167 private static class LayerListWarningMessagePanel extends JPanel { 168 private JLabel lblMessage; 169 private JList<SaveLayerInfo> lstLayers; 168 private static class LayerListWarningMessagePanel extends JPanel { 169 private final JLabel lblMessage = new JLabel(); 170 private final JList<SaveLayerInfo> lstLayers = new JList<>(); 171 172 LayerListWarningMessagePanel(String msg, List<SaveLayerInfo> infos) { 173 build(); 174 lblMessage.setText(msg); 175 lstLayers.setListData(infos.toArray(new SaveLayerInfo[0])); 176 } 170 177 171 178 protected void build() { … … 177 184 gc.weightx = 1.0; 178 185 gc.weighty = 0.0; 179 add(lblMessage = new JLabel(), gc);186 add(lblMessage, gc); 180 187 lblMessage.setHorizontalAlignment(JLabel.LEFT); 181 lstLayers = new JList<>();182 188 lstLayers.setCellRenderer( 183 189 new ListCellRenderer<SaveLayerInfo>() { … … 199 205 add(lstLayers, gc); 200 206 } 201 202 LayerListWarningMessagePanel(String msg, List<SaveLayerInfo> infos) { 203 build(); 204 lblMessage.setText(msg); 205 lstLayers.setListData(infos.toArray(new SaveLayerInfo[0])); 206 } 207 } 208 209 protected void warnLayersWithConflictsAndUploadRequest(List<SaveLayerInfo> infos) { 210 String msg = trn("<html>{0} layer has unresolved conflicts.<br>" 207 } 208 209 private static void warn(String msg, List<SaveLayerInfo> infos, String title) { 210 JPanel panel = new LayerListWarningMessagePanel(msg, infos); 211 // For unit test coverage in headless mode 212 if (!GraphicsEnvironment.isHeadless()) { 213 JOptionPane.showConfirmDialog(Main.parent, panel, title, JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE); 214 } 215 } 216 217 protected static void warnLayersWithConflictsAndUploadRequest(List<SaveLayerInfo> infos) { 218 warn(trn("<html>{0} layer has unresolved conflicts.<br>" 211 219 + "Either resolve them first or discard the modifications.<br>" 212 220 + "Layer with conflicts:</html>", … … 215 223 + "Layers with conflicts:</html>", 216 224 infos.size(), 217 infos.size()); 218 JOptionPane.showConfirmDialog( 219 Main.parent, 220 new LayerListWarningMessagePanel(msg, infos), 221 tr("Unsaved data and conflicts"), 222 JOptionPane.DEFAULT_OPTION, 223 JOptionPane.WARNING_MESSAGE 224 ); 225 } 226 227 protected void warnLayersWithoutFilesAndSaveRequest(List<SaveLayerInfo> infos) { 228 String msg = trn("<html>{0} layer needs saving but has no associated file.<br>" 225 infos.size()), 226 infos, tr("Unsaved data and conflicts")); 227 } 228 229 protected static void warnLayersWithoutFilesAndSaveRequest(List<SaveLayerInfo> infos) { 230 warn(trn("<html>{0} layer needs saving but has no associated file.<br>" 229 231 + "Either select a file for this layer or discard the changes.<br>" 230 232 + "Layer without a file:</html>", … … 233 235 + "Layers without a file:</html>", 234 236 infos.size(), 235 infos.size()); 236 JOptionPane.showConfirmDialog( 237 Main.parent, 238 new LayerListWarningMessagePanel(msg, infos), 239 tr("Unsaved data and missing associated file"), 240 JOptionPane.DEFAULT_OPTION, 241 JOptionPane.WARNING_MESSAGE 242 ); 243 } 244 245 protected void warnLayersWithIllegalFilesAndSaveRequest(List<SaveLayerInfo> infos) { 246 String msg = trn("<html>{0} layer needs saving but has an associated file<br>" 237 infos.size()), 238 infos, tr("Unsaved data and missing associated file")); 239 } 240 241 protected static void warnLayersWithIllegalFilesAndSaveRequest(List<SaveLayerInfo> infos) { 242 warn(trn("<html>{0} layer needs saving but has an associated file<br>" 247 243 + "which cannot be written.<br>" 248 244 + "Either select another file for this layer or discard the changes.<br>" … … 253 249 + "Layers with non-writable files:</html>", 254 250 infos.size(), 255 infos.size()); 256 JOptionPane.showConfirmDialog( 257 Main.parent, 258 new LayerListWarningMessagePanel(msg, infos), 259 tr("Unsaved data non-writable files"), 260 JOptionPane.DEFAULT_OPTION, 261 JOptionPane.WARNING_MESSAGE 262 ); 263 } 264 265 protected boolean confirmSaveLayerInfosOK() { 251 infos.size()), 252 infos, tr("Unsaved data non-writable files")); 253 } 254 255 static boolean confirmSaveLayerInfosOK(SaveLayersModel model) { 266 256 List<SaveLayerInfo> layerInfos = model.getLayersWithConflictsAndUploadRequest(); 267 257 if (!layerInfos.isEmpty()) { … … 388 378 389 379 final class SaveAndProceedAction extends AbstractAction implements PropertyChangeListener { 390 private static final int is = 24; // icon size380 private static final int ICON_SIZE = 24; 391 381 private static final String BASE_ICON = "BASE_ICON"; 392 382 private final transient Image save = ImageProvider.get("save").getImage(); 393 383 private final transient Image upld = ImageProvider.get("upload").getImage(); 394 private final transient Image saveDis = new BufferedImage( is, is, BufferedImage.TYPE_4BYTE_ABGR);395 private final transient Image upldDis = new BufferedImage( is, is, BufferedImage.TYPE_4BYTE_ABGR);384 private final transient Image saveDis = new BufferedImage(ICON_SIZE, ICON_SIZE, BufferedImage.TYPE_4BYTE_ABGR); 385 private final transient Image upldDis = new BufferedImage(ICON_SIZE, ICON_SIZE, BufferedImage.TYPE_4BYTE_ABGR); 396 386 397 387 SaveAndProceedAction() { … … 419 409 try { // Can fail if model is not yet setup properly 420 410 Image base = ((ImageIcon) getValue(BASE_ICON)).getImage(); 421 BufferedImage newIco = new BufferedImage( is*3, is, BufferedImage.TYPE_4BYTE_ABGR);411 BufferedImage newIco = new BufferedImage(ICON_SIZE*3, ICON_SIZE, BufferedImage.TYPE_4BYTE_ABGR); 422 412 Graphics2D g = newIco.createGraphics(); 423 g.drawImage(model.getLayersToUpload().isEmpty() ? upldDis : upld, is*0, 0, is, is, null);424 g.drawImage(model.getLayersToSave().isEmpty() ? saveDis : save, is*1, 0, is, is, null);425 g.drawImage(base, is*2, 0, is, is, null);413 g.drawImage(model.getLayersToUpload().isEmpty() ? upldDis : upld, ICON_SIZE*0, 0, ICON_SIZE, ICON_SIZE, null); 414 g.drawImage(model.getLayersToSave().isEmpty() ? saveDis : save, ICON_SIZE*1, 0, ICON_SIZE, ICON_SIZE, null); 415 g.drawImage(base, ICON_SIZE*2, 0, ICON_SIZE, ICON_SIZE, null); 426 416 putValue(SMALL_ICON, new ImageIcon(newIco)); 427 417 } catch (Exception e) { 418 Main.warn(e); 428 419 putValue(SMALL_ICON, getValue(BASE_ICON)); 429 420 } … … 432 423 @Override 433 424 public void actionPerformed(ActionEvent e) { 434 if (!confirmSaveLayerInfosOK( ))425 if (!confirmSaveLayerInfosOK(model)) 435 426 return; 436 427 launchSafeAndUploadTask(); -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersModel.java
r9078 r9556 123 123 public List<SaveLayerInfo> getLayersWithoutFilesAndSaveRequest() { 124 124 List<SaveLayerInfo> ret = new ArrayList<>(); 125 for (SaveLayerInfo info: layerInfo) { 126 if (info.isDoSaveToFile() && info.getFile() == null) { 127 ret.add(info); 125 if (layerInfo != null) { 126 for (SaveLayerInfo info: layerInfo) { 127 if (info.isDoSaveToFile() && info.getFile() == null) { 128 ret.add(info); 129 } 128 130 } 129 131 } … … 133 135 public List<SaveLayerInfo> getLayersWithIllegalFilesAndSaveRequest() { 134 136 List<SaveLayerInfo> ret = new ArrayList<>(); 135 for (SaveLayerInfo info: layerInfo) { 136 if (info.isDoSaveToFile() && info.getFile() != null && info.getFile().exists() && !info.getFile().canWrite()) { 137 ret.add(info); 137 if (layerInfo != null) { 138 for (SaveLayerInfo info: layerInfo) { 139 if (info.isDoSaveToFile() && info.getFile() != null && info.getFile().exists() && !info.getFile().canWrite()) { 140 ret.add(info); 141 } 138 142 } 139 143 } … … 143 147 public List<SaveLayerInfo> getLayersWithConflictsAndUploadRequest() { 144 148 List<SaveLayerInfo> ret = new ArrayList<>(); 145 for (SaveLayerInfo info: layerInfo) { 146 AbstractModifiableLayer l = info.getLayer(); 147 if (info.isDoUploadToServer() && l instanceof OsmDataLayer && !((OsmDataLayer) l).getConflicts().isEmpty()) { 148 ret.add(info); 149 if (layerInfo != null) { 150 for (SaveLayerInfo info: layerInfo) { 151 AbstractModifiableLayer l = info.getLayer(); 152 if (info.isDoUploadToServer() && l instanceof OsmDataLayer && !((OsmDataLayer) l).getConflicts().isEmpty()) { 153 ret.add(info); 154 } 149 155 } 150 156 } … … 154 160 public List<SaveLayerInfo> getLayersToUpload() { 155 161 List<SaveLayerInfo> ret = new ArrayList<>(); 156 for (SaveLayerInfo info: layerInfo) { 157 if (info.isDoUploadToServer()) { 158 ret.add(info); 162 if (layerInfo != null) { 163 for (SaveLayerInfo info: layerInfo) { 164 if (info.isDoUploadToServer()) { 165 ret.add(info); 166 } 159 167 } 160 168 } … … 164 172 public List<SaveLayerInfo> getLayersToSave() { 165 173 List<SaveLayerInfo> ret = new ArrayList<>(); 166 for (SaveLayerInfo info: layerInfo) { 167 if (info.isDoSaveToFile()) { 168 ret.add(info); 174 if (layerInfo != null) { 175 for (SaveLayerInfo info: layerInfo) { 176 if (info.isDoSaveToFile()) { 177 ret.add(info); 178 } 169 179 } 170 180 }
Note:
See TracChangeset
for help on using the changeset viewer.