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

Last change on this file since 11606 was 8510, checked in by Don-vip, 9 years ago

checkstyle: enable relevant whitespace checks and fix them

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