private void triggerFakeMouseEvent() { Point pt = gridPanel.getMousePosition(); if (pt != null) { mouseListener.mouseMoved( new MouseEvent( gridPanel, 0, System.currentTimeMillis(), 0, pt.x, pt.y, -1, -1, 0, false, 0)); } }
public void keyPressed(KeyEvent e) { int dx = 0; int dy = 0; if (e.getKeyCode() == KeyEvent.VK_LEFT) { dx = -1; } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { dx = 1; } else if (e.getKeyCode() == KeyEvent.VK_UP) { dy = -1; } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { dy = 1; } int multiplier = 1; if (e.isShiftDown() && e.isAltDown()) { multiplier = 10; } else if (e.isShiftDown() || e.isAltDown()) { multiplier = 5; } if (dx != 0 || dy != 0) { int size = Math.min( MAX_SIZE, Math.min( getWidth() - imagePadding.left - imagePadding.right, getHeight() - imagePadding.top - imagePadding.bottom)); int offsetX = getWidth() / 2 - size / 2; int offsetY = getHeight() / 2 - size / 2; mouseListener.mousePressed( new MouseEvent( ColorPickerPanel.this, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, point.x + multiplier * dx + offsetX, point.y + multiplier * dy + offsetY, 1, false)); } }