Changeset 23968 in osm for applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap
- Timestamp:
- 2010-10-31T17:46:32+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditDialog.java
r23966 r23968 25 25 import java.awt.event.ActionEvent; 26 26 import java.awt.event.ActionListener; 27 import java.util.Collection; 27 import java.awt.event.KeyEvent; 28 import java.awt.event.KeyListener; 28 29 import java.util.List; 29 30 … … 40 41 import javax.swing.event.ListSelectionEvent; 41 42 import javax.swing.event.ListSelectionListener; 43 import javax.swing.table.TableModel; 42 44 43 45 import org.openstreetmap.gui.jmapviewer.JMapViewer; … … 45 47 import org.openstreetmap.josm.Main; 46 48 import org.openstreetmap.josm.data.osm.Node; 47 import org.openstreetmap.josm.data.osm.OsmPrimitive;48 import org.openstreetmap.josm.data.osm.Tag;49 49 import org.openstreetmap.josm.data.osm.Way; 50 50 import org.openstreetmap.josm.gui.SideButton; 51 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler;52 51 import org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer; 53 52 import org.openstreetmap.josm.plugins.fixAddresses.AddressNode; … … 107 106 streetTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 108 107 streetTable.getSelectionModel().addListSelectionListener(this); 108 streetTable.addKeyListener(new JumpToEntryListener(1)); 109 109 110 110 JScrollPane scroll1 = new JScrollPane(streetTable); … … 325 325 } 326 326 327 class IncompleteAddressPresetHandler implements PresetHandler { 328 private List<OsmPrimitive> osmPrimitives; 327 /** 328 * The listener interface for receiving key events of a table. 329 * The class that is interested in processing a jumpToEntry 330 * event implements this interface, and the object created 331 * with that class is registered with a component using the 332 * component's <code>addJumpToEntryListener<code> method. When 333 * the jumpToEntry event occurs, that object's appropriate 334 * method is invoked. 335 * 336 * @see JumpToEntryEvent 337 */ 338 class JumpToEntryListener implements KeyListener { 339 private int column; 329 340 330 341 /** 331 * @param osmPrimitives 342 * Instantiates a new jump-to-entry listener. 343 * @param column the column of the table to use for the comparison 332 344 */ 333 public IncompleteAddressPresetHandler(List<OsmPrimitive> osmPrimitives) {345 public JumpToEntryListener(int column) { 334 346 super(); 335 this. osmPrimitives = osmPrimitives;347 this.column = column; 336 348 } 337 349 338 350 @Override 339 public Collection<OsmPrimitive> getSelection() {351 public void keyPressed(KeyEvent arg0) { 340 352 // TODO Auto-generated method stub 341 return osmPrimitives;353 342 354 } 343 355 344 356 @Override 345 public void updateTags(List<Tag> tags) { 346 347 } 348 357 public void keyReleased(KeyEvent arg0) { 358 // TODO Auto-generated method stub 359 360 } 361 362 @Override 363 public void keyTyped(KeyEvent arg0) { 364 JTable table = (JTable) arg0.getSource(); 365 366 if (table == null) return; 367 368 TableModel model = table.getModel(); 369 370 if (model == null || model.getColumnCount() == 0) { 371 return; 372 } 373 // clip column 374 if (column < 0 || column >= model.getColumnCount()) { 375 column = 0; // use the first column 376 } 377 378 char firstChar = Character.toLowerCase(arg0.getKeyChar()); 379 380 // visit every row and find a matching entry 381 for (int i = 0; i < model.getRowCount(); i++) { 382 Object obj = model.getValueAt(i, column); 383 if (obj != null) { 384 String s = obj.toString(); 385 if (s.length() > 0 && firstChar == Character.toLowerCase(s.charAt(0))) { 386 // select entry and make it visible in the table 387 table.getSelectionModel().setSelectionInterval(i, i); 388 table.scrollRectToVisible(streetTable.getCellRect(i, 0, true)); 389 return; 390 } 391 } 392 } 393 } 349 394 } 350 395 }
Note:
See TracChangeset
for help on using the changeset viewer.