Changeset 9497 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-01-17T04:02:53+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolverTable.java
r8510 r9497 2 2 package org.openstreetmap.josm.gui.conflict.tags; 3 3 4 import java.awt.event.ActionEvent;5 import java.awt.event.KeyEvent;6 7 import javax.swing.AbstractAction;8 import javax.swing.JComponent;9 4 import javax.swing.JTable; 10 import javax.swing.KeyStroke;11 5 import javax.swing.ListSelectionModel; 12 6 13 7 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 8 import org.openstreetmap.josm.gui.widgets.JosmTable; 14 9 15 public class TagConflictResolverTable extends J Table implements MultiValueCellEditor.NavigationListener {10 public class TagConflictResolverTable extends JosmTable implements MultiValueCellEditor.NavigationListener { 16 11 17 private SelectNextColumnCellAction selectNextColumnCellAction; 18 private SelectPreviousColumnCellAction selectPreviousColumnCellAction; 19 12 /** 13 * Constructs a new {@code TagConflictResolverTable}. 14 * @param model table model 15 */ 20 16 public TagConflictResolverTable(TagConflictResolverModel model) { 21 17 super(model, new TagConflictResolverColumnModel()); 22 build();23 }24 18 25 protected final void build() {26 19 setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); 27 20 setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 28 21 putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); 29 22 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); 23 installCustomNavigation(2); 41 24 42 25 ((MultiValueCellEditor) getColumnModel().getColumn(2).getCellEditor()).addNavigationListener(this); … … 45 28 } 46 29 47 /**48 * Action to be run when the user navigates to the next cell in the table, for instance by49 * 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 row51 * when the user leaves the last cell in the table</li></ul>52 *53 *54 */55 class SelectNextColumnCellAction extends AbstractAction {56 @Override57 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 by83 * pressing Shift-TAB84 *85 */86 class SelectPreviousColumnCellAction extends AbstractAction {87 88 @Override89 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 nothing102 } 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 30 @Override 114 31 public void gotoNextDecision() { 115 selectNextColumnCellAction. run();32 selectNextColumnCellAction.actionPerformed(null); 116 33 } 117 34 118 35 @Override 119 36 public void gotoPreviousDecision() { 120 selectPreviousColumnCellAction. run();37 selectPreviousColumnCellAction.actionPerformed(null); 121 38 } 122 39 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java
r9376 r9497 7 7 import java.awt.Dimension; 8 8 import java.awt.GraphicsEnvironment; 9 import java.awt.KeyboardFocusManager;10 9 import java.awt.event.ActionEvent; 11 import java.awt.event.KeyEvent;12 10 import java.util.ArrayList; 13 11 import java.util.Arrays; … … 17 15 import javax.swing.AbstractAction; 18 16 import javax.swing.DropMode; 19 import javax.swing.JComponent;20 17 import javax.swing.JPopupMenu; 21 18 import javax.swing.JTable; 22 19 import javax.swing.JViewport; 23 import javax.swing.KeyStroke;24 20 import javax.swing.ListSelectionModel; 25 21 import javax.swing.SwingUtilities; … … 61 57 setLayer(layer); 62 58 model.addMemberModelListener(this); 63 init(); 64 } 65 66 /** 67 * initialize the table 68 */ 69 protected void init() { 59 70 60 MemberRoleCellEditor ce = (MemberRoleCellEditor) getColumnModel().getColumn(0).getCellEditor(); 71 61 setRowHeight(ce.getEditor().getPreferredSize().height); … … 74 64 putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); 75 65 76 // make ENTER behave like TAB 77 // 78 getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( 79 KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), "selectNextColumnCell"); 80 66 installCustomNavigation(0); 81 67 initHighlighting(); 82 83 // install custom navigation actions84 //85 getActionMap().put("selectNextColumnCell", new SelectNextColumnCellAction());86 getActionMap().put("selectPreviousColumnCell", new SelectPreviousColumnCellAction());87 68 88 69 if (!GraphicsEnvironment.isHeadless()) { … … 164 145 } 165 146 166 /**167 * Action to be run when the user navigates to the next cell in the table, for instance by168 * pressing TAB or ENTER. The action alters the standard navigation path from cell to cell: <ul>169 * <li>it jumps over cells in the first column</li> <li>it automatically add a new empty row170 * when the user leaves the last cell in the table</li></ul>171 */172 class SelectNextColumnCellAction extends AbstractAction {173 @Override174 public void actionPerformed(ActionEvent e) {175 run();176 }177 178 public void run() {179 int col = getSelectedColumn();180 int row = getSelectedRow();181 if (getCellEditor() != null) {182 getCellEditor().stopCellEditing();183 }184 185 if (col == 0 && row < getRowCount() - 1) {186 row++;187 } else if (row < getRowCount() - 1) {188 col = 0;189 row++;190 } else {191 // go to next component, no more rows in this table192 KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();193 manager.focusNextComponent();194 return;195 }196 changeSelection(row, col, false, false);197 }198 }199 200 /**201 * Action to be run when the user navigates to the previous cell in the table, for instance by202 * pressing Shift-TAB203 */204 private class SelectPreviousColumnCellAction extends AbstractAction {205 206 @Override207 public void actionPerformed(ActionEvent e) {208 int col = getSelectedColumn();209 int row = getSelectedRow();210 if (getCellEditor() != null) {211 getCellEditor().stopCellEditing();212 }213 214 if (col <= 0 && row <= 0) {215 // change nothing216 } else if (row > 0) {217 col = 0;218 row--;219 }220 changeSelection(row, col, false, false);221 }222 }223 224 147 @Override 225 148 public void unlinkAsListener() { -
trunk/src/org/openstreetmap/josm/gui/widgets/OsmPrimitivesTable.java
r8308 r9497 6 6 7 7 import javax.swing.JPopupMenu; 8 import javax.swing.JTable;9 8 import javax.swing.ListSelectionModel; 10 9 import javax.swing.SwingUtilities; … … 16 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 16 18 public abstract class OsmPrimitivesTable extends JTable { 17 /** 18 * Table displaying OSM primitives. 19 * @since 5297 20 */ 21 public abstract class OsmPrimitivesTable extends JosmTable { 19 22 20 23 /** … … 27 30 private ZoomToAction zoomToAction; 28 31 29 public final OsmDataLayer getLayer() { 30 return layer; 31 } 32 33 public final void setLayer(OsmDataLayer layer) { 34 this.layer = layer; 35 } 36 32 /** 33 * Constructs a new {@code OsmPrimitivesTable}. 34 * @param dm table model 35 * @param cm column model 36 * @param sm selection model 37 */ 37 38 public OsmPrimitivesTable(OsmPrimitivesTableModel dm, TableColumnModel cm, ListSelectionModel sm) { 38 39 super(dm, cm, sm); … … 41 42 } 42 43 44 /** 45 * Returns the table model. 46 * @return the table model 47 */ 43 48 public OsmPrimitivesTableModel getOsmPrimitivesTableModel() { 44 49 return (OsmPrimitivesTableModel) getModel(); 50 } 51 52 /** 53 * Returns the data layer. 54 * @return the data layer 55 */ 56 public final OsmDataLayer getLayer() { 57 return layer; 58 } 59 60 /** 61 * Sets the data layer. 62 * @param layer the data layer 63 */ 64 public final void setLayer(OsmDataLayer layer) { 65 this.layer = layer; 45 66 } 46 67 … … 72 93 } 73 94 95 /** 96 * Returns primitive at the specified row. 97 * @param row table row 98 * @param layer unused in this implementation, can be useful for subclasses 99 * @return primitive at the specified row 100 */ 74 101 public OsmPrimitive getPrimitiveInLayer(int row, OsmDataLayer layer) { 75 102 return getOsmPrimitivesTableModel().getReferredPrimitive(row);
Note:
See TracChangeset
for help on using the changeset viewer.