[2512] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.gui.io;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
[5003] | 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;
|
---|
[2512] | 13 | import javax.swing.table.DefaultTableColumnModel;
|
---|
| 14 | import javax.swing.table.TableCellRenderer;
|
---|
| 15 | import javax.swing.table.TableColumn;
|
---|
| 16 |
|
---|
[5003] | 17 | import org.openstreetmap.josm.tools.GBC;
|
---|
| 18 |
|
---|
[2512] | 19 | class SaveLayersTableColumnModel extends DefaultTableColumnModel {
|
---|
[5003] | 20 | /** small renderer class that handles the "should be uploaded/saved" texts. */
|
---|
[5283] | 21 | private static class RecommendedActionsTableCell implements TableCellRenderer {
|
---|
[5463] | 22 | private final JPanel pnlEmpty = new JPanel();
|
---|
| 23 | private final JLabel needsUpload = new JLabel(tr("should be uploaded"));
|
---|
| 24 | private final JLabel needsSave = new JLabel(tr("should be saved"));
|
---|
[6889] | 25 | private static final GBC defaultCellStyle = GBC.eol().fill(GBC.HORIZONTAL).insets(2, 0, 2, 0);
|
---|
[5003] | 26 |
|
---|
[8426] | 27 | /**
|
---|
| 28 | * Constructs a new {@code RecommendedActionsTableCell}.
|
---|
| 29 | */
|
---|
[8836] | 30 | RecommendedActionsTableCell() {
|
---|
[5003] | 31 | pnlEmpty.setPreferredSize(new Dimension(1, 19));
|
---|
| 32 | needsUpload.setPreferredSize(new Dimension(needsUpload.getPreferredSize().width, 19));
|
---|
| 33 | needsSave.setPreferredSize(new Dimension(needsSave.getPreferredSize().width, 19));
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[6084] | 36 | @Override
|
---|
[5003] | 37 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
|
---|
| 38 | boolean hasFocus, int row, int column) {
|
---|
[5283] | 39 | JPanel panel = new JPanel(new GridBagLayout());
|
---|
[8510] | 40 | SaveLayerInfo info = (SaveLayerInfo) value;
|
---|
[8426] | 41 | StringBuilder sb = new StringBuilder(24);
|
---|
[5003] | 42 | sb.append("<html>");
|
---|
[8960] | 43 | if (info != null) {
|
---|
| 44 | if (info.getLayer().requiresUploadToServer() && !info.getLayer().isUploadDiscouraged()) {
|
---|
| 45 | panel.add(needsUpload, defaultCellStyle);
|
---|
| 46 | sb.append(tr("Layer ''{0}'' has modifications which should be uploaded to the server.", info.getName()));
|
---|
[5003] | 47 |
|
---|
[5233] | 48 | } else {
|
---|
[9751] | 49 | if (info.isUploadable()) {
|
---|
| 50 | panel.add(pnlEmpty, defaultCellStyle);
|
---|
| 51 | }
|
---|
[8960] | 52 | if (info.getLayer().requiresUploadToServer()) {
|
---|
| 53 | sb.append(tr("Layer ''{0}'' has modifications which are discouraged to be uploaded.", info.getName()));
|
---|
| 54 | } else {
|
---|
| 55 | sb.append(tr("Layer ''{0}'' has no modifications to be uploaded.", info.getName()));
|
---|
| 56 | }
|
---|
[5233] | 57 | }
|
---|
[8960] | 58 | sb.append("<br/>");
|
---|
[5003] | 59 |
|
---|
[8960] | 60 | if (info.getLayer().requiresSaveToFile()) {
|
---|
| 61 | panel.add(needsSave, defaultCellStyle);
|
---|
| 62 | sb.append(tr("Layer ''{0}'' has modifications which should be saved to its associated file ''{1}''.",
|
---|
| 63 | info.getName(), info.getFile().toString()));
|
---|
| 64 | } else {
|
---|
[9751] | 65 | if (info.isSavable()) {
|
---|
| 66 | panel.add(pnlEmpty, defaultCellStyle);
|
---|
| 67 | }
|
---|
[8960] | 68 | sb.append(tr("Layer ''{0}'' has no modifications to be saved.", info.getName()));
|
---|
| 69 | }
|
---|
[5003] | 70 | }
|
---|
| 71 | sb.append("</html>");
|
---|
[5283] | 72 | panel.setToolTipText(sb.toString());
|
---|
| 73 | return panel;
|
---|
[5003] | 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[8426] | 77 | /**
|
---|
| 78 | * Constructs a new {@code SaveLayersTableColumnModel}.
|
---|
| 79 | */
|
---|
[8836] | 80 | SaveLayersTableColumnModel() {
|
---|
[8426] | 81 | build();
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[2512] | 84 | protected void build() {
|
---|
[5003] | 85 | // column 0 - layer name, save path editor
|
---|
[9754] | 86 | LayerNameAndFilePathTableCell lnfpRenderer = new LayerNameAndFilePathTableCell();
|
---|
| 87 | LayerNameAndFilePathTableCell lnfpEditor = new LayerNameAndFilePathTableCell();
|
---|
[10308] | 88 | TableColumn col = new TableColumn(0); // keep in sync with SaveLayersModel#columnFilename
|
---|
[5003] | 89 | col.setHeaderValue(tr("Layer Name and File Path"));
|
---|
[2512] | 90 | col.setResizable(true);
|
---|
[9754] | 91 | col.setCellRenderer(lnfpRenderer);
|
---|
| 92 | col.setCellEditor(lnfpEditor);
|
---|
[5003] | 93 | col.setPreferredWidth(324);
|
---|
[2512] | 94 | addColumn(col);
|
---|
| 95 |
|
---|
[5003] | 96 | // column 1 - actions required
|
---|
[2512] | 97 | col = new TableColumn(1);
|
---|
[5003] | 98 | col.setHeaderValue(tr("Recommended Actions"));
|
---|
[2512] | 99 | col.setResizable(true);
|
---|
[5003] | 100 | col.setCellRenderer(new RecommendedActionsTableCell());
|
---|
| 101 | col.setPreferredWidth(150);
|
---|
[2512] | 102 | addColumn(col);
|
---|
| 103 |
|
---|
[5003] | 104 | // column 2- actions to take
|
---|
| 105 | ActionFlagsTableCell aftc = new ActionFlagsTableCell();
|
---|
| 106 | col = new TableColumn(2); // keep in sync with SaveLayersModel#columnActions
|
---|
| 107 | col.setHeaderValue(tr("Actions To Take"));
|
---|
[2512] | 108 | col.setResizable(true);
|
---|
[5003] | 109 | col.setCellRenderer(aftc);
|
---|
| 110 | col.setCellEditor(aftc);
|
---|
| 111 | col.setPreferredWidth(100);
|
---|
[2512] | 112 |
|
---|
| 113 | addColumn(col);
|
---|
| 114 | }
|
---|
| 115 | }
|
---|