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