source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java@ 2974

Last change on this file since 2974 was 2974, checked in by Gubaer, 14 years ago

fixed #4506: relation-editor: tag-delete-button does not work
removed duplicated code
fixed selection behaviour for tags tag in RelationEditor and UploadDialog

File size: 4.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging;
3
4import java.awt.BorderLayout;
5import java.awt.GridBagConstraints;
6import java.awt.GridBagLayout;
7import java.awt.Insets;
8import java.util.logging.Logger;
9
10import javax.swing.BoxLayout;
11import javax.swing.DefaultListSelectionModel;
12import javax.swing.JButton;
13import javax.swing.JPanel;
14import javax.swing.JScrollPane;
15
16import org.openstreetmap.josm.gui.layer.OsmDataLayer;
17import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache;
18import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
19
20/**
21 * TagEditorPanel is a {@see JPanel} which can be embedded as UI component in
22 * UIs. It provides a spreadsheet like tabular control for editing tag names
23 * and tag values. Two action buttons are placed on the left, one for adding
24 * a new tag and one for deleting the currently selected tags.
25 *
26 */
27public class TagEditorPanel extends JPanel {
28 static private final Logger logger = Logger.getLogger(TagEditorPanel.class.getName());
29 /** the tag editor model */
30 private TagEditorModel model;
31 /** the tag table */
32 private TagTable tagTable;
33
34 private AutoCompletionCache acCache;
35 private AutoCompletionList acList;
36
37 /**
38 * builds the panel with the table for editing tags
39 *
40 * @return the panel
41 */
42 protected JPanel buildTagTableEditorPanel() {
43
44 JPanel pnl = new JPanel();
45 DefaultListSelectionModel rowSelectionModel = new DefaultListSelectionModel();
46 DefaultListSelectionModel colSelectionModel = new DefaultListSelectionModel();
47
48 model = new TagEditorModel(rowSelectionModel, colSelectionModel);
49 tagTable = new TagTable(model, rowSelectionModel, colSelectionModel);
50
51 pnl.setLayout(new BorderLayout());
52 pnl.add(new JScrollPane(tagTable), BorderLayout.CENTER);
53 return pnl;
54 }
55
56 /**
57 * builds the panel with the button row
58 *
59 * @return the panel
60 */
61 protected JPanel buildButtonsPanel() {
62 JPanel pnl = new JPanel();
63 pnl.setLayout(new BoxLayout(pnl, BoxLayout.Y_AXIS));
64
65 // add action
66 //
67 JButton btn;
68 pnl.add(btn = new JButton(tagTable.getAddAction()));
69 btn.setMargin(new Insets(0,0,0,0));
70 tagTable.addComponentNotStoppingCellEditing(btn);
71
72 // delete action
73 pnl.add(btn = new JButton(tagTable.getDeleteAction()));
74 btn.setMargin(new Insets(0,0,0,0));
75 tagTable.addComponentNotStoppingCellEditing(btn);
76 return pnl;
77 }
78
79 /**
80 * builds the GUI
81 */
82 protected void build() {
83 setLayout(new GridBagLayout());
84 JPanel tablePanel = buildTagTableEditorPanel();
85 JPanel buttonPanel = buildButtonsPanel();
86
87 GridBagConstraints gc = new GridBagConstraints();
88
89 // -- buttons panel
90 //
91 gc.fill = GridBagConstraints.VERTICAL;
92 gc.weightx = 0.0;
93 gc.weighty = 1.0;
94 gc.anchor = GridBagConstraints.NORTHWEST;
95 add(buttonPanel,gc);
96
97 // -- the panel with the editor table
98 //
99 gc.gridx = 1;
100 gc.fill = GridBagConstraints.BOTH;
101 gc.weightx = 1.0;
102 gc.weighty = 1.0;
103 gc.anchor = GridBagConstraints.CENTER;
104 add(tablePanel,gc);
105 }
106
107 /**
108 * constructor
109 */
110 public TagEditorPanel() {
111 build();
112 }
113
114 /**
115 * Replies the tag editor model used by this panel.
116 *
117 * @return the tag editor model used by this panel
118 */
119 public TagEditorModel getModel() {
120 return model;
121 }
122
123 public void initAutoCompletion(OsmDataLayer layer) {
124 // initialize the autocompletion infrastructure
125 //
126 acCache = AutoCompletionCache.getCacheForLayer(layer);
127 acCache.initFromDataSet();
128 acList = new AutoCompletionList();
129
130 TagCellEditor editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(0).getCellEditor());
131 editor.setAutoCompletionCache(acCache);
132 editor.setAutoCompletionList(acList);
133 editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(1).getCellEditor());
134 editor.setAutoCompletionCache(acCache);
135 editor.setAutoCompletionList(acList);
136 }
137
138 @Override
139 public void setEnabled(boolean enabled) {
140 tagTable.setEnabled(enabled);
141 super.setEnabled(enabled);
142 }
143}
Note: See TracBrowser for help on using the repository browser.