Changeset 6063 in josm for trunk/src


Ignore:
Timestamp:
2013-07-12T13:34:05+02:00 (11 years ago)
Author:
akks
Message:

fix #8551: JOSM Relation Editor was resetting mouse speed on Windows
(please check for tab-switching bug of older JVMs in Relation Editor - the workaround was removed)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagTable.java

    r5266 r6063  
    55
    66import java.applet.Applet;
    7 import java.awt.AWTException;
    87import java.awt.Component;
    98import java.awt.Container;
    109import java.awt.Dimension;
    1110import java.awt.KeyboardFocusManager;
    12 import java.awt.MouseInfo;
    13 import java.awt.Point;
    14 import java.awt.Rectangle;
    15 import java.awt.Robot;
    1611import java.awt.Window;
    1712import java.awt.event.ActionEvent;
    18 import java.awt.event.InputEvent;
    1913import java.awt.event.KeyEvent;
    2014import java.awt.event.KeyListener;
     
    3731import javax.swing.table.DefaultTableColumnModel;
    3832import javax.swing.table.TableColumn;
     33import javax.swing.text.JTextComponent;
    3934
    4035import org.openstreetmap.josm.gui.dialogs.relation.RunnableAction;
     
    132127    class SelectPreviousColumnCellAction extends AbstractAction  {
    133128
     129        @Override
    134130        public void actionPerformed(ActionEvent e) {
    135131            int col = getSelectedColumn();
     
    244240         * listens to the table selection model
    245241         */
     242        @Override
    246243        public void valueChanged(ListSelectionEvent e) {
    247244            updateEnabledState();
     
    289286        }
    290287
     288        @Override
    291289        public void propertyChange(PropertyChangeEvent evt) {
    292290            updateEnabledState();
     
    447445
    448446    public void requestFocusInCell(final int row, final int col) {
    449 
    450         // the following code doesn't work reliably. If a table cell
    451         // gains focus using editCellAt() and requestFocusInWindow()
    452         // it isn't possible to tab to the next table cell using TAB or
    453         // ENTER. Don't know why.
    454         //
    455         // tblTagEditor.editCellAt(row, col);
    456         // if (tblTagEditor.getEditorComponent() != null) {
    457         //  tblTagEditor.getEditorComponent().requestFocusInWindow();
    458         // }
    459 
    460         // this is a workaround. We move the focus to the respective cell
    461         // using a simulated mouse click. In this case one can tab out of
    462         // the cell using TAB and ENTER.
    463         //
    464         Rectangle r = getCellRect(row,col, false);
    465         Point p = new Point(r.x + r.width/2, r.y + r.height/2);
    466         SwingUtilities.convertPointToScreen(p, this);
    467         Point before = MouseInfo.getPointerInfo().getLocation();
    468 
    469         try {
    470             Robot robot = new Robot();
    471             robot.mouseMove(p.x,p.y);
    472             robot.mousePress(InputEvent.BUTTON1_MASK);
    473             robot.mouseRelease(InputEvent.BUTTON1_MASK);
    474             robot.mouseMove(before.x, before.y);
    475         } catch(AWTException e) {
    476             System.out.println("Failed to simulate mouse click event at (" + r.x + "," + r.y + "). Exception: " + e.toString());
    477             return;
    478         }
     447        editCellAt(row, col);
     448        Component c = getEditorComponent();
     449        if (c!=null) {
     450            c.requestFocusInWindow();
     451            if ( c instanceof JTextComponent ) {
     452                 ( (JTextComponent)c ).selectAll();
     453            }
     454        }
     455        // there was a bug here - on older 1.6 Java versions Tab was not working
     456        // after such activation. In 1.7 it works OK,
     457        // previous solution of usint awt.Robot was resetting mouse speed on Windows
    479458    }
    480459
     
    553532        }
    554533
     534        @Override
    555535        public void propertyChange(PropertyChangeEvent ev) {
    556536            if (!isEditing())
Note: See TracChangeset for help on using the changeset viewer.