- Timestamp:
- 2012-02-19T23:17:34+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/io
- Files:
-
- 2 added
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
r4932 r5003 9 9 import java.awt.Dimension; 10 10 import java.awt.FlowLayout; 11 import java.awt.Graphics2D; 11 12 import java.awt.GridBagConstraints; 12 13 import java.awt.GridBagLayout; 14 import java.awt.Image; 13 15 import java.awt.event.ActionEvent; 14 16 import java.awt.event.WindowAdapter; 15 17 import java.awt.event.WindowEvent; 18 import java.awt.image.BufferedImage; 16 19 import java.beans.PropertyChangeEvent; 17 20 import java.beans.PropertyChangeListener; … … 24 27 import javax.swing.AbstractAction; 25 28 import javax.swing.DefaultListCellRenderer; 29 import javax.swing.ImageIcon; 26 30 import javax.swing.JComponent; 27 31 import javax.swing.JDialog; … … 33 37 import javax.swing.KeyStroke; 34 38 import javax.swing.WindowConstants; 39 import javax.swing.event.TableModelEvent; 40 import javax.swing.event.TableModelListener; 35 41 36 42 import org.openstreetmap.josm.Main; … … 45 51 import org.openstreetmap.josm.tools.WindowGeometry; 46 52 47 public class SaveLayersDialog extends JDialog {53 public class SaveLayersDialog extends JDialog implements TableModelListener { 48 54 static public enum UserAction { 49 55 /** … … 76 82 77 83 model = new SaveLayersModel(); 78 SaveLayersTable table ;79 JScrollPane pane = new JScrollPane(table = new SaveLayersTable(model));84 SaveLayersTable table = new SaveLayersTable(model); 85 JScrollPane pane = new JScrollPane(table); 80 86 model.addPropertyChangeListener(table); 87 table.getModel().addTableModelListener(this); 88 81 89 getContentPane().add(pane, BorderLayout.CENTER); 82 90 getContentPane().add(buildButtonRow(), BorderLayout.SOUTH); 83 table.getTableHeader().setPreferredSize(new Dimension(table.getTableHeader().getWidth(), 40));84 91 85 92 addWindowListener(new WindowClosingAdapter()); 86 93 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 87 94 } 95 96 private SideButton saveAndProceedActionButton = null; 88 97 89 98 /** … … 98 107 saveAndProceedAction = new SaveAndProceedAction(); 99 108 model.addPropertyChangeListener(saveAndProceedAction); 100 pnl.add( new SideButton(saveAndProceedAction));109 pnl.add(saveAndProceedActionButton = new SideButton(saveAndProceedAction)); 101 110 102 111 discardAndProceedAction = new DiscardAndProceedAction(); … … 327 336 328 337 public void initForDiscardAndExit() { 329 putValue(NAME, tr(" Discard and Exit"));338 putValue(NAME, tr("Exit now!")); 330 339 putValue(SHORT_DESCRIPTION, tr("Exit JOSM without saving. Unsaved changes are lost.")); 331 340 putValue(SMALL_ICON, ImageProvider.get("exit")); … … 333 342 334 343 public void initForDiscardAndDelete() { 335 putValue(NAME, tr("D iscard and Delete"));344 putValue(NAME, tr("Delete now!")); 336 345 putValue(SHORT_DESCRIPTION, tr("Delete layers without saving. Unsaved changes are lost.")); 337 346 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); … … 353 362 } 354 363 355 class SaveAndProceedAction extends AbstractAction implements PropertyChangeListener { 364 final class SaveAndProceedAction extends AbstractAction implements PropertyChangeListener { 365 private static final int is = 24; // icon size 366 private static final String BASE_ICON = "BASE_ICON"; 367 private final Image save = ImageProvider.get("save").getImage(); 368 private final Image upld = ImageProvider.get("upload").getImage(); 369 private final Image saveDis = new BufferedImage(is, is, BufferedImage.TYPE_4BYTE_ABGR); 370 private final Image upldDis = new BufferedImage(is, is, BufferedImage.TYPE_4BYTE_ABGR); 371 356 372 public SaveAndProceedAction() { 373 // get disabled versions of icons 374 new JLabel(ImageProvider.get("save")).getDisabledIcon().paintIcon(new JPanel(), saveDis.getGraphics(), 0, 0); 375 new JLabel(ImageProvider.get("upload")).getDisabledIcon().paintIcon(new JPanel(), upldDis.getGraphics(), 0, 0); 357 376 initForSaveAndExit(); 358 377 } 359 378 360 379 public void initForSaveAndExit() { 361 putValue(NAME, tr(" Save/Upload and Exit"));380 putValue(NAME, tr("Perform actions before exiting")); 362 381 putValue(SHORT_DESCRIPTION, tr("Exit JOSM with saving. Unsaved changes are uploaded and/or saved.")); 363 putValue(SMALL_ICON, ImageProvider.get("exit")); 382 putValue(BASE_ICON, ImageProvider.get("exit")); 383 redrawIcon(); 364 384 } 365 385 366 386 public void initForSaveAndDelete() { 367 putValue(NAME, tr(" Save/Upload and Delete"));387 putValue(NAME, tr("Perform actions before deleting")); 368 388 putValue(SHORT_DESCRIPTION, tr("Save/Upload layers before deleting. Unsaved changes are not lost.")); 369 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); 389 putValue(BASE_ICON, ImageProvider.get("dialogs", "delete")); 390 redrawIcon(); 391 } 392 393 public void redrawIcon() { 394 try { // Can fail if model is not yet setup properly 395 Image base = ((ImageIcon) getValue(BASE_ICON)).getImage(); 396 BufferedImage newIco = new BufferedImage(is*3, is, BufferedImage.TYPE_4BYTE_ABGR); 397 Graphics2D g = newIco.createGraphics(); 398 g.drawImage(model.getLayersToUpload().isEmpty() ? upldDis : upld, is*0, 0, is, is, null); 399 g.drawImage(model.getLayersToSave().isEmpty() ? saveDis : save, is*1, 0, is, is, null); 400 g.drawImage(base, is*2, 0, is, is, null); 401 putValue(SMALL_ICON, new ImageIcon(newIco)); 402 } catch(Exception e) { 403 putValue(SMALL_ICON, getValue(BASE_ICON)); 404 } 370 405 } 371 406 … … 546 581 } 547 582 } 583 584 @Override 585 public void tableChanged(TableModelEvent arg0) { 586 boolean dis = model.getLayersToSave().isEmpty() && model.getLayersToUpload().isEmpty(); 587 if(saveAndProceedActionButton != null) { 588 saveAndProceedActionButton.setEnabled(!dis); 589 } 590 saveAndProceedAction.redrawIcon(); 591 } 548 592 } -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersModel.java
r4310 r5003 24 24 private Mode mode; 25 25 private PropertyChangeSupport support; 26 27 // keep in sync with how the columns are ordered in SaveLayersTableColumnModel#build 28 private static final int columnFilename = 0; 29 private static final int columnActions = 2; 26 30 27 31 public SaveLayersModel() { … … 83 87 @Override 84 88 public boolean isCellEditable(int row, int column) { 85 return column == 3 || column == 4 || column == 5;89 return column == columnFilename || column == columnActions; 86 90 } 87 91 … … 89 93 public void setValueAt(Object value, int row, int column) { 90 94 switch(column) { 91 case 3 /* file name */: 92 this.layerInfo.get(row).setFile((File)value); 93 this.layerInfo.get(row).setDoSaveToFile(true); 94 break; 95 case 4 /* upload */: this.layerInfo.get(row).setDoUploadToServer((Boolean)value);break; 96 case 5 /* save */: this.layerInfo.get(row).setDoSaveToFile((Boolean)value);break; 95 case columnFilename: 96 this.layerInfo.get(row).setFile((File)value); 97 this.layerInfo.get(row).setDoSaveToFile(true); 98 break; 99 case columnActions: 100 boolean[] values = (boolean[]) value; 101 this.layerInfo.get(row).setDoUploadToServer(values[0]); 102 this.layerInfo.get(row).setDoSaveToFile(values[1]); 103 break; 97 104 } 98 105 fireTableDataChanged(); … … 104 111 105 112 public List<SaveLayerInfo> getLayersWithoutFilesAndSaveRequest() { 106 List<SaveLayerInfo> ret = new ArrayList<SaveLayerInfo>();113 List<SaveLayerInfo> ret = new ArrayList<SaveLayerInfo>(); 107 114 for (SaveLayerInfo info: layerInfo) { 108 115 if (info.isDoSaveToFile() && info.getFile() == null) { … … 215 222 return ret; 216 223 } 217 218 224 } -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersTable.java
r3083 r5003 2 2 package org.openstreetmap.josm.gui.io; 3 3 4 import java.awt.Dimension; 4 5 import java.beans.PropertyChangeEvent; 5 6 import java.beans.PropertyChangeListener; … … 13 14 super(model, new SaveLayersTableColumnModel()); 14 15 putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); 16 super.setRowHeight(39); 17 super.getTableHeader().setPreferredSize(new Dimension(super.getTableHeader().getWidth(), 24)); 18 super.getTableHeader().setReorderingAllowed(false); 15 19 } 16 20 -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersTableColumnModel.java
r3083 r5003 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component; 7 import java.awt.Dimension; 8 import java.awt.GridBagLayout; 9 10 import javax.swing.JLabel; 11 import javax.swing.JPanel; 12 import javax.swing.JTable; 6 13 import javax.swing.table.DefaultTableColumnModel; 7 import javax.swing.table.TableCellEditor;8 14 import javax.swing.table.TableCellRenderer; 9 15 import javax.swing.table.TableColumn; 10 16 17 import org.openstreetmap.josm.tools.GBC; 18 11 19 class SaveLayersTableColumnModel extends DefaultTableColumnModel { 20 /** small renderer class that handles the "should be uploaded/saved" texts. */ 21 private static class RecommendedActionsTableCell extends JPanel implements TableCellRenderer { 22 private final static JPanel pnlEmpty = new JPanel(); 23 private final static JLabel needsUpload = new JLabel(tr("should be uploaded")); 24 private final static JLabel needsSave = new JLabel(tr("should be saved")); 25 private final static GBC defaultCellStyle = GBC.eol().fill(GBC.HORIZONTAL).insets(2, 0, 2, 0); 26 27 public RecommendedActionsTableCell() { 28 setLayout(new GridBagLayout()); 29 pnlEmpty.setPreferredSize(new Dimension(1, 19)); 30 needsUpload.setPreferredSize(new Dimension(needsUpload.getPreferredSize().width, 19)); 31 needsSave.setPreferredSize(new Dimension(needsSave.getPreferredSize().width, 19)); 32 } 33 34 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, 35 boolean hasFocus, int row, int column) { 36 SaveLayerInfo info = (SaveLayerInfo)value; 37 StringBuilder sb = new StringBuilder(); 38 sb.append("<html>"); 39 if (info.getLayer().requiresUploadToServer()) { 40 add(needsUpload, defaultCellStyle); 41 sb.append(tr("Layer ''{0}'' has modifications which should be uploaded to the server.", info.getName())); 42 43 } else { 44 add(pnlEmpty, defaultCellStyle); 45 sb.append(tr("Layer ''{0}'' has no modifications to be uploaded.", info.getName())); 46 } 47 sb.append("<br/>"); 48 49 if (info.getLayer().requiresSaveToFile()) { 50 add(needsSave, defaultCellStyle); 51 sb.append(tr("Layer ''{0}'' has modifications which should be saved to its associated file ''{1}''.", info.getName(), info.getFile().toString())); 52 } else { 53 add(pnlEmpty, defaultCellStyle); 54 sb.append(tr("Layer ''{0}'' has no modifications to be saved.", info.getName())); 55 } 56 sb.append("</html>"); 57 setToolTipText(sb.toString()); 58 return this; 59 } 60 } 61 12 62 protected void build() { 13 63 TableColumn col = null; 14 TableCellRenderer renderer = new SaveLayerInfoCellRenderer();15 TableCellEditor fileNameEditor = new FilenameCellEditor();16 TableCellEditor saveFlagEditor = new SaveFlagCellEditor();17 64 18 // column 0 - Layer 19 col = new TableColumn(0); 20 col.setHeaderValue(tr("Layer")); 65 // column 0 - layer name, save path editor 66 LayerNameAndFilePathTableCell lnafptc = new LayerNameAndFilePathTableCell(); 67 col = new TableColumn(0); // keep in sync with SaveLayersModel#columnFilename 68 col.setHeaderValue(tr("Layer Name and File Path")); 21 69 col.setResizable(true); 22 col.setCellRenderer(renderer); 23 col.setPreferredWidth(100); 70 col.setCellRenderer(lnafptc); 71 col.setCellEditor(lnafptc); 72 col.setPreferredWidth(324); 24 73 addColumn(col); 25 74 26 // column 1 - Uploadrequired75 // column 1 - actions required 27 76 col = new TableColumn(1); 28 col.setHeaderValue(tr(" Should upload?"));77 col.setHeaderValue(tr("Recommended Actions")); 29 78 col.setResizable(true); 30 col.setCellRenderer( renderer);31 col.setPreferredWidth( 50);79 col.setCellRenderer(new RecommendedActionsTableCell()); 80 col.setPreferredWidth(150); 32 81 addColumn(col); 33 82 34 // column 2 - Save to file required 35 col = new TableColumn(2); 36 col.setHeaderValue(tr("Should save?")); 83 // column 2- actions to take 84 ActionFlagsTableCell aftc = new ActionFlagsTableCell(); 85 col = new TableColumn(2); // keep in sync with SaveLayersModel#columnActions 86 col.setHeaderValue(tr("Actions To Take")); 37 87 col.setResizable(true); 38 col.setCellRenderer(renderer); 39 col.setPreferredWidth(50); 40 addColumn(col); 41 42 // column 3 - filename 43 col = new TableColumn(3); 44 col.setHeaderValue(tr("Filename")); 45 col.setResizable(true); 46 col.setCellRenderer(renderer); 47 col.setCellEditor(fileNameEditor); 48 col.setPreferredWidth(200); 49 addColumn(col); 50 51 // column 4 - Upload 52 col = new TableColumn(4); 53 col.setHeaderValue(tr("Upload")); 54 col.setResizable(true); 55 col.setCellRenderer(renderer); 56 col.setCellEditor(saveFlagEditor); 57 col.setPreferredWidth(30); 58 addColumn(col); 59 60 // column 5 - Save 61 col = new TableColumn(5); 62 col.setHeaderValue(tr("Save")); 63 col.setResizable(true); 64 col.setCellRenderer(renderer); 65 col.setCellEditor(saveFlagEditor); 66 col.setPreferredWidth(30); 88 col.setCellRenderer(aftc); 89 col.setCellEditor(aftc); 90 col.setPreferredWidth(100); 67 91 68 92 addColumn(col);
Note:
See TracChangeset
for help on using the changeset viewer.