source: josm/trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverTable.java@ 12660

Last change on this file since 12660 was 12660, checked in by michael2402, 7 years ago

See #14794: Add javadoc for gui/conflict/tags package.

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.conflict.tags;
3
4import java.awt.event.ActionEvent;
5import java.awt.event.KeyEvent;
6
7import javax.swing.AbstractAction;
8import javax.swing.JComponent;
9import javax.swing.JTable;
10import javax.swing.KeyStroke;
11import javax.swing.ListSelectionModel;
12
13import org.openstreetmap.josm.gui.widgets.JosmComboBox;
14
15/**
16 * The main table displayed in the {@link RelationMemberConflictResolver}
17 *
18 * @see RelationMemberConflictResolverColumnModel
19 */
20public class RelationMemberConflictResolverTable extends JTable implements MultiValueCellEditor.NavigationListener {
21
22 private SelectNextColumnCellAction selectNextColumnCellAction;
23 private SelectPreviousColumnCellAction selectPreviousColumnCellAction;
24
25 public RelationMemberConflictResolverTable(RelationMemberConflictResolverModel model) {
26 super(model, new RelationMemberConflictResolverColumnModel());
27 build();
28 }
29
30 protected final void build() {
31 setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
32 setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
33 putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
34
35 // make ENTER behave like TAB
36 //
37 getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
38 KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), "selectNextColumnCell");
39
40 // install custom navigation actions
41 //
42 selectNextColumnCellAction = new SelectNextColumnCellAction();
43 selectPreviousColumnCellAction = new SelectPreviousColumnCellAction();
44 getActionMap().put("selectNextColumnCell", selectNextColumnCellAction);
45 getActionMap().put("selectPreviousColumnCell", selectPreviousColumnCellAction);
46
47 setRowHeight((int) new JosmComboBox<String>().getPreferredSize().getHeight());
48 }
49
50 /**
51 * Action to be run when the user navigates to the next cell in the table, for instance by
52 * pressing TAB or ENTER. The action alters the standard navigation path from cell to cell: <ul>
53 * <li>it jumps over cells in the first column</li> <li>it automatically add a new empty row
54 * when the user leaves the last cell in the table</li></ul>
55 *
56 *
57 */
58 class SelectNextColumnCellAction extends AbstractAction {
59 @Override
60 public void actionPerformed(ActionEvent e) {
61 run();
62 }
63
64 public void run() {
65 int col = getSelectedColumn();
66 int row = getSelectedRow();
67 if (getCellEditor() != null) {
68 getCellEditor().stopCellEditing();
69 }
70
71 if (col == 2 && row < getRowCount() - 1) {
72 row++;
73 } else if (row < getRowCount() - 1) {
74 col = 2;
75 row++;
76 }
77 changeSelection(row, col, false, false);
78 editCellAt(getSelectedRow(), getSelectedColumn());
79 getEditorComponent().requestFocusInWindow();
80 }
81 }
82
83 /**
84 * Action to be run when the user navigates to the previous cell in the table, for instance by
85 * pressing Shift-TAB
86 *
87 */
88 class SelectPreviousColumnCellAction extends AbstractAction {
89
90 @Override
91 public void actionPerformed(ActionEvent e) {
92 run();
93 }
94
95 public void run() {
96 int col = getSelectedColumn();
97 int row = getSelectedRow();
98 if (getCellEditor() != null) {
99 getCellEditor().stopCellEditing();
100 }
101
102 if (col <= 0 && row <= 0) {
103 // change nothing
104 } else if (row > 0) {
105 col = 2;
106 row--;
107 }
108 changeSelection(row, col, false, false);
109 editCellAt(getSelectedRow(), getSelectedColumn());
110 getEditorComponent().requestFocusInWindow();
111 }
112 }
113
114 @Override
115 public void gotoNextDecision() {
116 selectNextColumnCellAction.run();
117 }
118
119 @Override
120 public void gotoPreviousDecision() {
121 selectPreviousColumnCellAction.run();
122 }
123}
Note: See TracBrowser for help on using the repository browser.