source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberRoleCellEditor.java@ 13675

Last change on this file since 13675 was 13675, checked in by Don-vip, 6 years ago

rework constructors of MemberRoleCellEditor / MemberTableColumnModel

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.relation;
3
4import java.awt.Component;
5
6import javax.swing.AbstractCellEditor;
7import javax.swing.BorderFactory;
8import javax.swing.CellEditor;
9import javax.swing.JTable;
10import javax.swing.table.TableCellEditor;
11
12import org.openstreetmap.josm.data.osm.Relation;
13import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
14import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
15import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
16
17/**
18 * The {@link CellEditor} for the role cell in the table. Supports autocompletion.
19 */
20public class MemberRoleCellEditor extends AbstractCellEditor implements TableCellEditor {
21 private final AutoCompletingTextField editor;
22 private final AutoCompletionManager autoCompletionManager;
23 private final transient Relation relation;
24
25 /** user input is matched against this list of auto completion items */
26 private final AutoCompletionList autoCompletionList;
27
28 /**
29 * Constructs a new {@code MemberRoleCellEditor}.
30 * @param autoCompletionManager the auto completion manager. Must not be null
31 * @param relation the relation. Can be null
32 * @since 13675
33 */
34 public MemberRoleCellEditor(AutoCompletionManager autoCompletionManager, Relation relation) {
35 this.autoCompletionManager = autoCompletionManager;
36 this.relation = relation;
37 editor = new AutoCompletingTextField(0, false);
38 editor.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
39 autoCompletionList = new AutoCompletionList();
40 editor.setAutoCompletionList(autoCompletionList);
41 }
42
43 @Override
44 public Component getTableCellEditorComponent(JTable table,
45 Object value, boolean isSelected, int row, int column) {
46
47 String role = (String) value;
48 editor.setText(role);
49 autoCompletionList.clear();
50 autoCompletionManager.populateWithMemberRoles(autoCompletionList, relation);
51 return editor;
52 }
53
54 @Override
55 public Object getCellEditorValue() {
56 return editor.getText();
57 }
58
59 /**
60 * Returns the edit field for this cell editor.
61 * @return the edit field for this cell editor
62 */
63 public AutoCompletingTextField getEditor() {
64 return editor;
65 }
66}
Note: See TracBrowser for help on using the repository browser.