source: josm/trunk/src/org/openstreetmap/josm/gui/io/SaveLayersTableColumnModel.java@ 12542

Last change on this file since 12542 was 12537, checked in by Don-vip, 7 years ago

PMD - VariableNamingConventions

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