source: josm/trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolverTable.java@ 7022

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

see #8465 - enable and fix more warnings

  • 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
15public class TagConflictResolverTable extends JTable implements MultiValueCellEditor.NavigationListener {
16
17 private SelectNextColumnCellAction selectNextColumnCellAction;
18 private SelectPreviousColumnCellAction selectPreviousColumnCellAction;
19
20 public TagConflictResolverTable(TagConflictResolverModel model) {
21 super(model, new TagConflictResolverColumnModel());
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 ((MultiValueCellEditor)getColumnModel().getColumn(2).getCellEditor()).addNavigationListeners(this);
43
44 setRowHeight((int)new JosmComboBox<String>().getPreferredSize().getHeight());
45 }
46
47 /**
48 * Action to be run when the user navigates to the next cell in the table, for instance by
49 * pressing TAB or ENTER. The action alters the standard navigation path from cell to cell: <ul>
50 * <li>it jumps over cells in the first column</li> <li>it automatically add a new empty row
51 * when the user leaves the last cell in the table</li></ul>
52 *
53 *
54 */
55 class SelectNextColumnCellAction extends AbstractAction {
56 @Override
57 public void actionPerformed(ActionEvent e) {
58 run();
59 }
60
61 public void run() {
62 int col = getSelectedColumn();
63 int row = getSelectedRow();
64 if (getCellEditor() != null) {
65 getCellEditor().stopCellEditing();
66 }
67
68 if (col == 2 && row < getRowCount() - 1) {
69 row++;
70 } else if (row < getRowCount() - 1) {
71 col = 2;
72 row++;
73 }
74 changeSelection(row, col, false, false);
75 if (editCellAt(getSelectedRow(), getSelectedColumn())) {
76 getEditorComponent().requestFocusInWindow();
77 }
78 }
79 }
80
81 /**
82 * Action to be run when the user navigates to the previous cell in the table, for instance by
83 * pressing Shift-TAB
84 *
85 */
86 class SelectPreviousColumnCellAction extends AbstractAction {
87
88 @Override
89 public void actionPerformed(ActionEvent e) {
90 run();
91 }
92
93 public void run() {
94 int col = getSelectedColumn();
95 int row = getSelectedRow();
96 if (getCellEditor() != null) {
97 getCellEditor().stopCellEditing();
98 }
99
100 if (col <= 0 && row <= 0) {
101 // change nothing
102 } else if (row > 0) {
103 col = 2;
104 row--;
105 }
106 changeSelection(row, col, false, false);
107 if (editCellAt(getSelectedRow(), getSelectedColumn())) {
108 getEditorComponent().requestFocusInWindow();
109 }
110 }
111 }
112
113 @Override
114 public void gotoNextDecision() {
115 selectNextColumnCellAction.run();
116 }
117
118 @Override
119 public void gotoPreviousDecision() {
120 selectPreviousColumnCellAction.run();
121 }
122}
Note: See TracBrowser for help on using the repository browser.