Ignore:
Timestamp:
09/27/18 17:05:54 (6 years ago)
Author:
bln4
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gio/swing/SwingInputManager.java

    r1144 r1169  
    3636import org.expeditee.items.widgets.Widget;
    3737
    38 public class SwingInputManager extends InputManager
    39 implements      ComponentListener,
    40                         WindowListener,
    41                         WindowStateListener,
    42                         KeyListener,
    43                         MouseListener,
    44                         MouseMotionListener,
    45                         MouseWheelListener
    46 {
     38public class SwingInputManager extends InputManager implements ComponentListener, WindowListener, WindowStateListener,
     39                KeyListener, MouseListener, MouseMotionListener, MouseWheelListener {
    4740        /** Singleton instance. */
    4841        private static SwingInputManager _instance;
    49        
     42
    5043        /** Singleton constructor. */
    51         public static SwingInputManager getInstance()
    52         {
     44        public static SwingInputManager getInstance() {
    5345                if (_instance == null) {
    5446                        try {
     
    6456                        }
    6557                }
    66                
     58
    6759                return _instance;
    6860        }
    69        
     61
    7062        /** TODO: What functionality does this object provide? */
    7163        private MouseEventRouter _mouseEventRouter;
    72        
     64
    7365        /** For robotically controlling the mouse position. */
    74         //private Robot _robot;
     66        // private Robot _robot;
    7567        private MouseCorrectRobot _robot;
    76        
    77         private SwingInputManager()
    78         {
     68
     69        private SwingInputManager() {
    7970                SwingInputManager swingInputManager = this;
    80                
     71
    8172                // Sign up to receive input as events
    8273                SwingGraphicsManager graphicsManager = SwingMiscManager.getIfUsingSwingGraphicsManager();
     
    8778                        graphicsManager.addKeyListener(swingInputManager); // TODO: ...both of these? cts16
    8879                        graphicsManager.addComponentListener(swingInputManager);
    89                        
     80
    9081                        // Sign up to receive mouse events, from the SwingGraphicsManager
    9182                        // TODO: Decide if we will keep using MouseEventRouter. cts16
     
    9485                        _mouseEventRouter.addExpediteeMouseMotionListener(swingInputManager);
    9586                        _mouseEventRouter.addExpediteeMouseWheelListener(swingInputManager);
    96                        
     87
    9788                        // enable the glasspane-for capturing all mouse events
    9889                        graphicsManager.setGlassPane(_mouseEventRouter);
     
    10192                        graphicsManager.getContentPane().setFocusTraversalKeysEnabled(false);
    10293                }
    103                
     94
    10495                // Set up the robot (for controlling the mouse)
    10596                // TODO: What to do if robot throws exception??? cts16
     
    109100                        e.printStackTrace();
    110101                }
    111                
     102
    112103                // Create the timer for firing timeout events
    113104                Timer.setLogTimers(false);
     
    120111                _timer.setRepeats(false);
    121112        }
    122        
    123         @Override
    124         protected Point getRealCursorPosition()
    125         {
     113
     114        @Override
     115        protected Point getRealCursorPosition() {
    126116                Point mouseScreenPos = SwingConversions.fromSwingPoint(MouseInfo.getPointerInfo().getLocation());
    127117                return screenToWindowPosition(mouseScreenPos);
     
    129119
    130120        @Override
    131         public void setCursorPosition(Point position)
    132         {
    133                 //System.err.println("Move to position; Moving to: " + position);
     121        public void setCursorPosition(Point position) {
     122                // System.err.println("Move to position; Moving to: " + position);
    134123                Point screenPosition = windowToScreenPosition(position);
    135                 //System.err.println("Move to position: window adjusted; Moving to: " + screenPosition);
    136                 //_robot.mouseMove(screenPosition.x, screenPosition.y);
     124                // System.err.println("Move to position: window adjusted; Moving to: " +
     125                // screenPosition);
     126                // _robot.mouseMove(screenPosition.x, screenPosition.y);
    137127                final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    138                 _robot.MoveMouseControlled(screenPosition.getX() / screenSize.getWidth(), screenPosition.getY() / screenSize.getHeight());
     128                _robot.MoveMouseControlled(screenPosition.getX() / screenSize.getWidth(),
     129                                screenPosition.getY() / screenSize.getHeight());
    139130                updateCursorPosition(position.getX(), position.getY());
    140131        }
    141132
    142133        @Override
    143         public void windowStateChanged(WindowEvent e)
    144         {
    145                 // Does nothing. cts16
    146         }
    147 
    148         @Override
    149         public void windowOpened(WindowEvent e)
    150         {
    151                 // Does nothing. cts16
    152         }
    153 
    154         @Override
    155         public void windowClosing(WindowEvent e)
    156         {
    157                 // Does nothing. cts16
    158         }
    159 
    160         @Override
    161         public void windowClosed(WindowEvent e)
    162         {
     134        public void windowStateChanged(WindowEvent e) {
     135                // Does nothing. cts16
     136        }
     137
     138        @Override
     139        public void windowOpened(WindowEvent e) {
     140                // Does nothing. cts16
     141        }
     142
     143        @Override
     144        public void windowClosing(WindowEvent e) {
     145                // Does nothing. cts16
     146        }
     147
     148        @Override
     149        public void windowClosed(WindowEvent e) {
    163150                SwingGraphicsManager g = SwingMiscManager.getIfUsingSwingGraphicsManager();
    164                
     151
    165152                if (g == null || !g.isFullscreenTransitionPending()) {
    166153                        distributeWindowEvent(WindowEventType.WINDOW_CLOSED);
     
    169156
    170157        @Override
    171         public void windowIconified(WindowEvent e)
    172         {
    173                 // Does nothing. cts16
    174         }
    175 
    176         @Override
    177         public void windowDeiconified(WindowEvent e)
    178         {
    179                 // Does nothing. cts16
    180         }
    181 
    182         @Override
    183         public void windowActivated(WindowEvent e)
    184         {
    185                 // Does nothing. cts16
    186         }
    187 
    188         @Override
    189         public void windowDeactivated(WindowEvent e)
    190         {
    191                 // Does nothing. cts16
    192         }
    193 
    194         @Override
    195         public void componentResized(ComponentEvent e)
    196         {
     158        public void windowIconified(WindowEvent e) {
     159                // Does nothing. cts16
     160        }
     161
     162        @Override
     163        public void windowDeiconified(WindowEvent e) {
     164                // Does nothing. cts16
     165        }
     166
     167        @Override
     168        public void windowActivated(WindowEvent e) {
     169                // Does nothing. cts16
     170        }
     171
     172        @Override
     173        public void windowDeactivated(WindowEvent e) {
     174                // Does nothing. cts16
     175        }
     176
     177        @Override
     178        public void componentResized(ComponentEvent e) {
    197179                SwingGraphicsManager g = SwingMiscManager.getIfUsingSwingGraphicsManager();
    198                 if (g != null) g.refreshRootSurface();
    199                
     180                if (g != null) {
     181                        g.refreshRootSurface();
     182                }
     183
    200184                distributeWindowEvent(WindowEventType.WINDOW_RESIZED);
    201185        }
    202186
    203187        @Override
    204         public void componentMoved(ComponentEvent e)
    205         {
    206                 // Does nothing. cts16
    207                
    208         }
    209 
    210         @Override
    211         public void componentShown(ComponentEvent e)
    212         {
     188        public void componentMoved(ComponentEvent e) {
     189                // Does nothing. cts16
     190
     191        }
     192
     193        @Override
     194        public void componentShown(ComponentEvent e) {
    213195                SwingGraphicsManager g = SwingMiscManager.getIfUsingSwingGraphicsManager();
    214                
    215                 if (g != null) g.finishFullscreenTransition();
    216         }
    217 
    218         @Override
    219         public void componentHidden(ComponentEvent e)
    220         {
    221                 // Does nothing. cts16
    222         }
    223        
     196
     197                if (g != null) {
     198                        g.finishFullscreenTransition();
     199                }
     200        }
     201
     202        @Override
     203        public void componentHidden(ComponentEvent e) {
     204                // Does nothing. cts16
     205        }
     206
    224207        /** Converts a location given in screen-space to window-space. */
    225         private Point screenToWindowPosition(Point screenPosition)
    226         {
     208        private Point screenToWindowPosition(Point screenPosition) {
    227209                Point windowTopLeft = EcosystemManager.getGraphicsManager().getWindowLocation();
    228                
     210
    229211                return Point.difference(screenPosition, windowTopLeft);
    230212        }
    231213
    232214        /** Converts a location given in window-space to screen-space. */
    233         private Point windowToScreenPosition(Point windowPosition)
    234         {
     215        private Point windowToScreenPosition(Point windowPosition) {
    235216                Point windowTopLeft = EcosystemManager.getGraphicsManager().getWindowLocation();
    236                
     217
    237218                return windowPosition.clone().add(windowTopLeft);
    238219        }
    239220
    240221        @Override
    241         public void mouseWheelMoved(MouseWheelEvent e)
    242         {
     222        public void mouseWheelMoved(MouseWheelEvent e) {
    243223                // Give widgets first whack at input
    244224                distributeNativeInput(e);
    245                 if (e.isConsumed()) return;
    246                
     225                if (e.isConsumed()) {
     226                        return;
     227                }
     228
    247229                try {
    248230                        // Create an input event
    249231                        Integer rotation = new Integer(e.getWheelRotation());
    250232                        InputEvent event = new KBMInputEvent(KBMInputEvent.EventType.MOUSE_WHEEL_SCROLL, rotation);
    251                        
     233
    252234                        // Translate and perform the input
    253235                        distributeInputEvent(event);
     
    258240
    259241        @Override
    260         public void mouseDragged(MouseEvent e)
    261         {
     242        public void mouseDragged(MouseEvent e) {
    262243                mouseMoved(e);
    263244        }
    264245
    265246        @Override
    266         public void mouseMoved(MouseEvent e)
    267         {
     247        public void mouseMoved(MouseEvent e) {
    268248                // Update the cursor position
    269249                updateCursorPosition(e.getX(), e.getY());
    270                
     250
    271251                // Give widgets first whack at input
    272252                distributeNativeInput(e);
    273                 if (e.isConsumed()) return;
    274                
     253                if (e.isConsumed()) {
     254                        return;
     255                }
     256
    275257                try {
    276258                        // Create an input event
     
    278260                        Point movedTo = new Point(e.getX(), e.getY());
    279261                        InputEvent event = new KBMInputEvent(KBMInputEvent.EventType.MOUSE_MOVE, new Line(movedFrom, movedTo));
    280                        
     262
    281263                        // Translate and perform the input
    282264                        distributeInputEvent(event);
     
    287269
    288270        @Override
    289         public void mouseClicked(MouseEvent e)
    290         {
     271        public void mouseClicked(MouseEvent e) {
    291272                // Give widgets first whack at input
    292273                distributeNativeInput(e);
    293                 if (e.isConsumed()) return;
    294                
     274                if (e.isConsumed()) {
     275                        return;
     276                }
     277
    295278                // Do nothing else (handled by mousePressed and mouseReleased)
    296279        }
    297280
    298281        @Override
    299         public void mousePressed(MouseEvent e)
    300         {
     282        public void mousePressed(MouseEvent e) {
    301283                mouseAction(e, true);
    302284        }
    303285
    304286        @Override
    305         public void mouseReleased(MouseEvent e)
    306         {
     287        public void mouseReleased(MouseEvent e) {
    307288                mouseAction(e, false);
    308289        }
    309        
     290
    310291        /** Handles mouse pressed/released events. */
    311         private void mouseAction(MouseEvent e, boolean down)
    312         {
     292        private void mouseAction(MouseEvent e, boolean down) {
    313293                // Give widgets first whack at input
    314294                distributeNativeInput(e);
    315                 if (e.isConsumed()) return;
    316                
     295                if (e.isConsumed()) {
     296                        return;
     297                }
     298
    317299                // Work out which button was pressed
    318300                KBMInputEvent.MouseButton button;
    319301                switch (e.getButton()) {
    320                         case MouseEvent.BUTTON1:
    321                                 button = KBMInputEvent.MouseButton.LEFT;
    322                                 break;
    323                         case MouseEvent.BUTTON2:
    324                                 button = KBMInputEvent.MouseButton.MIDDLE;
    325                                 break;
    326                         case MouseEvent.BUTTON3:
    327                                 button = KBMInputEvent.MouseButton.RIGHT;
    328                                 break;
    329                         default:
    330                                 return;
    331                 }
    332                
     302                case MouseEvent.BUTTON1:
     303                        button = KBMInputEvent.MouseButton.LEFT;
     304                        break;
     305                case MouseEvent.BUTTON2:
     306                        button = KBMInputEvent.MouseButton.MIDDLE;
     307                        break;
     308                case MouseEvent.BUTTON3:
     309                        button = KBMInputEvent.MouseButton.RIGHT;
     310                        break;
     311                default:
     312                        return;
     313                }
     314
    333315                try {
    334316                        // Create an input event
    335                         KBMInputEvent.EventType type = down ? KBMInputEvent.EventType.MOUSE_BUTTON_DOWN : KBMInputEvent.EventType.MOUSE_BUTTON_UP;
     317                        KBMInputEvent.EventType type = down ? KBMInputEvent.EventType.MOUSE_BUTTON_DOWN
     318                                        : KBMInputEvent.EventType.MOUSE_BUTTON_UP;
    336319                        InputEvent event = new KBMInputEvent(type, button);
    337                        
     320
    338321                        // Translate and perform the input
    339322                        distributeInputEvent(event);
     
    343326        }
    344327
    345         /** Prevents forwarding mouse-entered-window events when coming back from a widget. */
     328        /**
     329         * Prevents forwarding mouse-entered-window events when coming back from a
     330         * widget.
     331         */
    346332        private boolean _inWindow = false;
    347        
    348         @Override
    349         public void mouseEntered(MouseEvent e)
    350         {
     333
     334        @Override
     335        public void mouseEntered(MouseEvent e) {
    351336                if (!_inWindow) {
    352337                        _inWindow = true;
     
    356341
    357342        @Override
    358         public void mouseExited(MouseEvent e)
    359         {
     343        public void mouseExited(MouseEvent e) {
    360344                _inWindow = false;
    361345                distributeWindowEvent(WindowEventType.MOUSE_EXITED_WINDOW);
     
    363347
    364348        @Override
    365         public void keyTyped(KeyEvent e)
    366         {
     349        public void keyTyped(KeyEvent e) {
    367350                // Give widgets first whack at input
    368351                distributeNativeInput(e);
    369                 if (e.isConsumed()) return;
    370                
     352                if (e.isConsumed()) {
     353                        return;
     354                }
     355
    371356                try {
    372357                        // Ignore escape character and control characters
    373                         if (e.getKeyChar() == KeyEvent.VK_ESCAPE || e.isControlDown() || e.isAltDown()) return;
    374                        
     358                        if (e.getKeyChar() == KeyEvent.VK_ESCAPE || e.isControlDown() || e.isAltDown()) {
     359                                return;
     360                        }
     361
    375362                        // Create an input event
    376363                        Character character = new Character(e.getKeyChar());
    377364                        InputEvent event = new KBMInputEvent(KBMInputEvent.EventType.CHAR_TYPED, character);
    378                        
     365
    379366                        // Translate and perform the input
    380367                        distributeInputEvent(event);
     
    385372
    386373        @Override
    387         public void keyPressed(KeyEvent e)
    388         {
     374        public void keyPressed(KeyEvent e) {
    389375                keyAction(e, true);
    390376        }
    391377
    392378        @Override
    393         public void keyReleased(KeyEvent e)
    394         {
     379        public void keyReleased(KeyEvent e) {
    395380                keyAction(e, false);
    396381        }
    397        
     382
    398383        /** Handles key pressed/released events. */
    399         private void keyAction(KeyEvent e, boolean down)
    400         {
     384        private void keyAction(KeyEvent e, boolean down) {
    401385                // Give widgets first whack at input
    402386                distributeNativeInput(e);
    403                 if (e.isConsumed()) return;
    404                
     387                if (e.isConsumed()) {
     388                        return;
     389                }
     390
    405391                KBMInputEvent.Key key = SwingConversions.fromSwingVirtualKey(e.getKeyCode());
    406                 if (key == null) return;
    407                
     392                if (key == null) {
     393                        return;
     394                }
     395
    408396                try {
    409397                        // Create an input event
    410398                        KBMInputEvent.EventType type = down ? KBMInputEvent.EventType.KEY_DOWN : KBMInputEvent.EventType.KEY_UP;
    411399                        InputEvent event = new KBMInputEvent(type, key);
    412                        
     400
    413401                        // Translate and perform the input
    414402                        distributeInputEvent(event);
     
    417405                }
    418406        }
    419        
    420         @Override
    421         protected final boolean isInputTypeSupported(InputType type)
    422         {
     407
     408        @Override
     409        protected final boolean isInputTypeSupported(InputType type) {
    423410                // Only keyboard/mouse input is currently supported
    424                 if (type == InputEvent.InputType.KBM) return true;
    425                
     411                if (type == InputEvent.InputType.KBM) {
     412                        return true;
     413                }
     414
    426415                return false;
    427416        }
    428        
     417
    429418        /** Forwards the given input event to the listener if it is listening for it. */
    430         private void forwardNativeInputToListener(Object listener, java.awt.event.InputEvent event)
    431         {
    432                 if (listener == null || event == null) return;
    433                
     419        private void forwardNativeInputToListener(Object listener, java.awt.event.InputEvent event) {
     420                if (listener == null || event == null) {
     421                        return;
     422                }
     423
    434424                if (listener instanceof KeyListener && event instanceof KeyEvent) {
    435                        
     425
    436426                        KeyListener keyListener = (KeyListener) listener;
    437427                        KeyEvent ke = (KeyEvent) event;
    438                        
     428
    439429                        switch (event.getID()) {
    440                                 case KeyEvent.KEY_PRESSED:
    441                                         keyListener.keyPressed(ke);
    442                                         return;
    443                                 case KeyEvent.KEY_RELEASED:
    444                                         keyListener.keyReleased(ke);
    445                                         return;
    446                                 case KeyEvent.KEY_TYPED:
    447                                         keyListener.keyTyped(ke);
    448                                         return;
    449                         }
    450                        
     430                        case KeyEvent.KEY_PRESSED:
     431                                keyListener.keyPressed(ke);
     432                                return;
     433                        case KeyEvent.KEY_RELEASED:
     434                                keyListener.keyReleased(ke);
     435                                return;
     436                        case KeyEvent.KEY_TYPED:
     437                                keyListener.keyTyped(ke);
     438                                return;
     439                        }
     440
    451441                } else if (event instanceof MouseEvent) {
    452                        
     442
    453443                        MouseEvent me = (MouseEvent) event;
    454                        
     444
    455445                        if (listener instanceof MouseListener) {
    456446                                MouseListener mouseListener = (MouseListener) listener;
    457447                                switch (event.getID()) {
    458                                         case MouseEvent.MOUSE_CLICKED:
    459                                                 mouseListener.mouseClicked(me);
    460                                                 return;
    461                                         case MouseEvent.MOUSE_PRESSED:
    462                                                 mouseListener.mousePressed(me);
    463                                                 return;
    464                                         case MouseEvent.MOUSE_RELEASED:
    465                                                 mouseListener.mouseReleased(me);
    466                                                 return;
    467                                         case MouseEvent.MOUSE_ENTERED:
    468                                                 mouseListener.mouseEntered(me);
    469                                                 return;
    470                                         case MouseEvent.MOUSE_EXITED:
    471                                                 mouseListener.mouseExited(me);
    472                                                 return;
     448                                case MouseEvent.MOUSE_CLICKED:
     449                                        mouseListener.mouseClicked(me);
     450                                        return;
     451                                case MouseEvent.MOUSE_PRESSED:
     452                                        mouseListener.mousePressed(me);
     453                                        return;
     454                                case MouseEvent.MOUSE_RELEASED:
     455                                        mouseListener.mouseReleased(me);
     456                                        return;
     457                                case MouseEvent.MOUSE_ENTERED:
     458                                        mouseListener.mouseEntered(me);
     459                                        return;
     460                                case MouseEvent.MOUSE_EXITED:
     461                                        mouseListener.mouseExited(me);
     462                                        return;
    473463                                }
    474464                        }
    475                        
     465
    476466                        if (listener instanceof MouseMotionListener) {
    477467                                MouseMotionListener motionListener = (MouseMotionListener) listener;
    478468                                switch (event.getID()) {
    479                                         case MouseEvent.MOUSE_MOVED:
    480                                                 motionListener.mouseMoved(me);
    481                                                 return;
    482                                         case MouseEvent.MOUSE_DRAGGED:
    483                                                 motionListener.mouseDragged(me);
    484                                                 return;
     469                                case MouseEvent.MOUSE_MOVED:
     470                                        motionListener.mouseMoved(me);
     471                                        return;
     472                                case MouseEvent.MOUSE_DRAGGED:
     473                                        motionListener.mouseDragged(me);
     474                                        return;
    485475                                }
    486476                        }
    487                        
     477
    488478                        if (listener instanceof MouseWheelListener && me instanceof MouseWheelEvent) {
    489479                                MouseWheelListener wheelListener = (MouseWheelListener) listener;
    490480                                MouseWheelEvent mwe = (MouseWheelEvent) me;
    491481                                switch (event.getID()) {
    492                                         case MouseEvent.MOUSE_WHEEL:
    493                                                 wheelListener.mouseWheelMoved(mwe);
    494                                                 return;
     482                                case MouseEvent.MOUSE_WHEEL:
     483                                        wheelListener.mouseWheelMoved(mwe);
     484                                        return;
    495485                                }
    496486                        }
    497487                }
    498488        }
    499        
     489
    500490        /** Distributes the native input to all pop-ups and widgets. */
    501         private void distributeNativeInput(java.awt.event.InputEvent event)
    502         {
     491        private void distributeNativeInput(java.awt.event.InputEvent event) {
    503492                // Distribute to pop-ups first
    504493                distributeNativeInputToPopups(event);
    505                 if (event.isConsumed()) return;
    506                
     494                if (event.isConsumed()) {
     495                        return;
     496                }
     497
    507498                // Then distribute to widgets
    508499                distributeNativeInputToWidgets(event);
    509500        }
    510        
     501
    511502        /** Distributes the input event to registered widgets. */
    512         private void distributeNativeInputToPopups(java.awt.event.InputEvent event)
    513         {
    514                 if (event == null) return;
    515                
     503        private void distributeNativeInputToPopups(java.awt.event.InputEvent event) {
     504                if (event == null) {
     505                        return;
     506                }
     507
    516508                for (Popup popup : PopupManager.getInstance().getPopups()) {
    517509                        forwardNativeInputToListener(popup, event);
    518                        
    519                         if (event.isConsumed()) return;
    520                 }
    521         }
    522        
     510
     511                        if (event.isConsumed()) {
     512                                return;
     513                        }
     514                }
     515        }
     516
    523517        /** Distributes the input event to registered widgets. */
    524         private void distributeNativeInputToWidgets(java.awt.event.InputEvent event)
    525         {
    526                 if (event == null) return;
    527                
     518        private void distributeNativeInputToWidgets(java.awt.event.InputEvent event) {
     519                if (event == null) {
     520                        return;
     521                }
     522
    528523                for (Widget iw : _widgets) {
    529524                        java.awt.event.InputEvent e = respecInputEventForWidget(event, iw);
    530525                       
    531526                        forwardNativeInputToListener(iw, e);
    532                        
    533                         if (e != event && e.isConsumed()) event.consume();
    534                        
    535                         if (event.isConsumed()) return;
    536                 }
    537         }
    538        
     527
     528                        if (e != event && e.isConsumed()) {
     529                                event.consume();
     530                        }
     531
     532                        if (event.isConsumed()) {
     533                                return;
     534                        }
     535                }
     536        }
     537
    539538        /** Modifies the event so that it is relative to the given widget. */
    540         private java.awt.event.InputEvent respecInputEventForWidget(java.awt.event.InputEvent event, Widget iw)
    541         {
     539        private java.awt.event.InputEvent respecInputEventForWidget(java.awt.event.InputEvent event, Widget iw) {
    542540                // TODO: Complete. cts16
    543541                return event;
     
    546544        /** The timer which fires timeout events for the Swing input manager. */
    547545        private Timer _timer;
    548        
    549         @Override
    550         protected void updateTimer(long nextTimeout)
    551         {
    552                 if (nextTimeout < 0) nextTimeout = 0;
     546
     547        @Override
     548        protected void updateTimer(long nextTimeout) {
     549                if (nextTimeout < 0) {
     550                        nextTimeout = 0;
     551                }
    553552                _timer.stop();
    554553                _timer.setInitialDelay((int) nextTimeout);
    555554                _timer.start();
    556                
    557         }
    558        
     555
     556        }
     557
    559558        /**
    560          * Obtained from stackoverflow.  https://stackoverflow.com/questions/48799393/robot-mousemove-not-moving-to-specified-location-properly
    561          * Fixes a (hopefully temporary) issue with the java.awt.Robot class on some specific systems (such as David's laptop) wherein
    562          * the mouseMove function would move the mouse to odd locations.
     559         * Obtained from stackoverflow.
     560         * https://stackoverflow.com/questions/48799393/robot-mousemove-not-moving-to-specified-location-properly
     561         * Fixes a (hopefully temporary) issue with the java.awt.Robot class on some
     562         * specific systems (such as David's laptop) wherein the mouseMove function
     563         * would move the mouse to odd locations.
     564         *
    563565         * @author bln4
    564566         *
     
    573575
    574576                private double getTav(java.awt.Point a, java.awt.Point b) {
    575                         return Math.sqrt((double) ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)));
    576                 }
    577 
    578                 public void MoveMouseControlled(double xbe, double ybe)// Position of the cursor in [0,1] ranges. (0,0) is the upper
     577                        return Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
     578                }
     579
     580                public void MoveMouseControlled(double xbe, double ybe)// Position of the cursor in [0,1] ranges. (0,0) is the
     581                                                                                                                                // upper
    579582                                                                                                                                // left corner
    580583                {
     
    596599                        while ((mert.x != xbepix || mert.y != ybepix) && i < LepesLimit && UgyanAztMeri < UgyanAZtMeriLimit) {
    597600                                ++i;
    598                                 if (mert.x < xbepix)
     601                                if (mert.x < xbepix) {
    599602                                        ++x;
    600                                 else
     603                                } else {
    601604                                        --x;
    602                                 if (mert.y < ybepix)
     605                                }
     606                                if (mert.y < ybepix) {
    603607                                        ++y;
    604                                 else
     608                                } else {
    605609                                        --y;
     610                                }
    606611                                mouseMove(x, y);
    607612
    608613                                mert = MouseInfo.getPointerInfo().getLocation();
    609614
    610                                 if (getTav(ElozoInitPont, mert) < 5)
     615                                if (getTav(ElozoInitPont, mert) < 5) {
    611616                                        ++UgyanAztMeri;
    612                                 else {
     617                                } else {
    613618                                        UgyanAztMeri = 0;
    614619                                        ElozoInitPont.x = mert.x;
Note: See TracChangeset for help on using the changeset viewer.