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 |
|
---|
10 | import javax.swing.JLabel;
|
---|
11 | import javax.swing.JPanel;
|
---|
12 | import javax.swing.JTable;
|
---|
13 | import javax.swing.table.DefaultTableColumnModel;
|
---|
14 | import javax.swing.table.TableCellRenderer;
|
---|
15 | import javax.swing.table.TableColumn;
|
---|
16 |
|
---|
17 | import org.openstreetmap.josm.tools.GBC;
|
---|
18 |
|
---|
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 |
|
---|
62 | protected void build() {
|
---|
63 | TableColumn col = null;
|
---|
64 |
|
---|
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"));
|
---|
69 | col.setResizable(true);
|
---|
70 | col.setCellRenderer(lnafptc);
|
---|
71 | col.setCellEditor(lnafptc);
|
---|
72 | col.setPreferredWidth(324);
|
---|
73 | addColumn(col);
|
---|
74 |
|
---|
75 | // column 1 - actions required
|
---|
76 | col = new TableColumn(1);
|
---|
77 | col.setHeaderValue(tr("Recommended Actions"));
|
---|
78 | col.setResizable(true);
|
---|
79 | col.setCellRenderer(new RecommendedActionsTableCell());
|
---|
80 | col.setPreferredWidth(150);
|
---|
81 | addColumn(col);
|
---|
82 |
|
---|
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"));
|
---|
87 | col.setResizable(true);
|
---|
88 | col.setCellRenderer(aftc);
|
---|
89 | col.setCellEditor(aftc);
|
---|
90 | col.setPreferredWidth(100);
|
---|
91 |
|
---|
92 | addColumn(col);
|
---|
93 | }
|
---|
94 |
|
---|
95 | public SaveLayersTableColumnModel() {
|
---|
96 | build();
|
---|
97 | }
|
---|
98 | }
|
---|