public void checkDrag() {
    Land land = (Land) getWorld();
    if (Greenfoot.mouseDragged(this)) {
      MouseInfo mouse = Greenfoot.getMouseInfo();
      if (cost <= land.getMoneyAmount()) {
        if (hasTurret == false) {
          land.removeObjects(land.getObjects(Radius.class));

          machineGun = new MachineGun_Turret();
          getWorld().addObject(machineGun, mouse.getX(), mouse.getY());
          hasTurret = true;
          land.setMoneyCounter(-cost);
        }
      }
      if (hasTurret == true) machineGun.setLocation(mouse.getX(), mouse.getY());
    }
    if ((Greenfoot.mouseDragEnded(null)) && (machineGun != null)) {
      grid();
      if (machineGun.checkLocation()) {
        machineGun.placed = true;
        hasTurret = false;
        machineGun = null;
      } else {
        land.removeObject(machineGun);
        machineGun = null;
        land.setMoneyCounter(cost);
        hasTurret = false;
      }
    }
  }
Esempio n. 2
0
  public void act() {
    int mouseX, mouseY;

    if (Greenfoot.mouseDragged(this)) {
      MouseInfo mouse = Greenfoot.getMouseInfo();
      mouseX = mouse.getX();
      mouseY = mouse.getY();
      setLocation(mouseX, mouseY);
    }
  }
Esempio n. 3
0
 public void action() {
   MouseInfo mouse = Greenfoot.getMouseInfo();
   if (!clickingInventory()) {
     if (mouse != null) {
       if (mouse.getButton() == 1) {
         toolbar.action(getX(), getY());
       }
       if (mouse.getButton() == 3) {
         toolbar.altAction(getX(), getY());
       }
     }
   }
 }
    private static Point fixPopupLocation(final Component contents, final int x, final int y) {
      if (!(contents instanceof JToolTip)) return new Point(x, y);

      final PointerInfo info;
      try {
        info = MouseInfo.getPointerInfo();
      } catch (InternalError e) {
        // http://www.jetbrains.net/jira/browse/IDEADEV-21390
        // may happen under Mac OSX 10.5
        return new Point(x, y);
      }
      int deltaY = 0;

      if (info != null) {
        final Point mouse = info.getLocation();
        deltaY = mouse.y - y;
      }

      final Dimension size = contents.getPreferredSize();
      final Rectangle rec = new Rectangle(new Point(x, y), size);
      ScreenUtil.moveRectangleToFitTheScreen(rec);

      if (rec.y < y) {
        rec.y += deltaY;
      }

      return rec.getLocation();
    }
Esempio n. 5
0
 @Override
 public void mouseClicked(MouseEvent mouseEvent) {
   Board b = bgui.getGridView();
   if (b.getAction() == Board.Action.ADD && bgui.getSelectedComponent().equals("Gizmo")) {
     String gizmoShape = bgui.getGizmoShape();
     Point mouseP = MouseInfo.getPointerInfo().getLocation();
     Point gridP = b.getLocationOnScreen();
     int x = mouseP.x - gridP.x;
     int y = mouseP.y - gridP.y;
     boolean added = false;
     switch (gizmoShape) {
       case "Circle":
         added = m.addCircularBumper(x, y, 0, "circle");
         break;
       case "Triangle":
         added = m.addTriangularBumper(x, y, 0, "triangle");
         break;
       case "Square":
         added = m.addSquareBumper(x, y, 0, "square");
         break;
       case "Teleporter":
         added = m.addTeleporterBumper(x, y, 0, "teleporter");
         break;
       default:
     }
     if (added) {
       bgui.setMessageColor(Color.GREEN);
       bgui.setMessage(gizmoShape + " added!");
     } else {
       bgui.setMessageColor(Color.RED);
       bgui.setMessage("That space is occupied, " + gizmoShape + " cannot be added");
     }
   }
 }
Esempio n. 6
0
  public static void requestFocus(Project project, final boolean useRobot) {
    JFrame frame = WindowManager.getInstance().getFrame(project);

    // the only reliable way I found to bring it to the top
    boolean aot = frame.isAlwaysOnTop();
    frame.setAlwaysOnTop(true);
    frame.setAlwaysOnTop(aot);

    int frameState = frame.getExtendedState();
    if ((frameState & Frame.ICONIFIED) == Frame.ICONIFIED) {
      // restore the frame if it is minimized
      frame.setExtendedState(frameState ^ Frame.ICONIFIED);
    }
    frame.toFront();
    frame.requestFocus();
    if (useRobot && runningOnWindows7()) {
      try {
        // remember the last location of mouse
        final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation();

        // simulate a mouse click on title bar of window
        Robot robot = new Robot();
        robot.mouseMove(frame.getX(), frame.getY());
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

        // move mouse to old location
        robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY());
      } catch (Exception ex) {
        // just ignore exception, or you can handle it as you want
      } finally {
        frame.setAlwaysOnTop(false);
      }
    }
  }
 /**
  * Act - do whatever the Desicion wants to do. This method is called whenever the 'Act' or 'Run'
  * button gets pressed in the environment.
  */
 public void act() {
   MouseInfo mouse = Greenfoot.getMouseInfo();
   if (Greenfoot.mouseClicked(this)) {
     if (mouse.getButton() == 3) // right-click
     {
       construyeDialogo();
     } else {
       if (((WActividades) getWorld()).mousePresionado) {
         ((WActividades) getWorld()).agregaPunto(getX(), getY(), true);
         ((WActividades) getWorld()).mousePresionado = false;
       }
     }
   } else if (Greenfoot.mousePressed(this)) {
     ((WActividades) getWorld()).agregaPunto(getX(), getY(), false);
     ((WActividades) getWorld()).mousePresionado = true;
   }
 }
Esempio n. 8
0
  @Override
  protected void paintChildren(Graphics g) {

    autoscale();

    super.paintChildren(g);
    if (IGV.getInstance().isRulerEnabled()) {
      int start = MouseInfo.getPointerInfo().getLocation().x - getLocationOnScreen().x;
      g.setColor(Color.BLACK);
      g.drawLine(start, 0, start, getHeight());
    }
  }
Esempio n. 9
0
 @Override
 public void dragGestureRecognized(DragGestureEvent dge) {
   Cursor cursor = null;
   BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
   paint(bi.getGraphics());
   ImageMover.start(bi, MouseInfo.getPointerInfo().getLocation());
   String s = "[ANDITEM]";
   if (dge.getDragAction() == DnDConstants.ACTION_COPY) {
     cursor = DragSource.DefaultCopyDrop;
   }
   dge.startDrag(
       cursor, new SimpleDragObject.TransferableSimpleDragObject(new SimpleDragObject(s)));
 }
 @Override
 public void mouseClicked(MouseEvent mouseEvent) {
   Board b = bgui.getGridView();
   if (b.getAction() == Board.Action.KEY_DISCONNECT) {
     Point mouseP = MouseInfo.getPointerInfo().getLocation();
     Point gridP = b.getLocationOnScreen();
     int x = mouseP.x - gridP.x;
     int y = mouseP.y - gridP.y;
     x -= x % 20;
     y -= y % 20;
     f = m.findFlipper(x, y);
     String keys = "";
     if (f != null) {
       for (KeyConnectionFlipper kcf : m.getKeyConnectionsFlipper()) {
         if (kcf.getFlipper().equals(f)) {
           keys += ("'" + KeyEvent.getKeyText(kcf.getKeyID()) + "', ");
         }
       }
       if (keys.length() > 2) {
         keys = keys.substring(0, keys.length() - 2);
       }
       abs = null;
       b.requestFocus();
       bgui.setMessageColor(Color.BLACK);
       bgui.setMessage(
           "This flipper is connected to keys "
               + keys
               + ". Press key to remove connection to it.");
     } else if (m.getAbsorber() != null
         && x <= m.getAbsorber().getXBottomRight()
         && x >= m.getAbsorber().getXTopLeft()
         && y <= m.getAbsorber().getYBottomRight()
         && y >= m.getAbsorber().getYTopLeft()) {
       for (KeyConnectionAbs kca : m.getKeyConnectionsAbs()) {
         keys += ("'" + KeyEvent.getKeyText(kca.getKeyID()) + "', ");
       }
       if (keys.length() > 2) {
         keys = keys.substring(0, keys.length() - 2);
       }
       abs = m.getAbsorber();
       b.requestFocus();
       bgui.setMessageColor(Color.BLACK);
       bgui.setMessage(
           "This absorber is connected to keys "
               + keys
               + ". Press key to remove connection to it.");
     }
   }
 }
Esempio n. 11
0
  @SuppressWarnings("NestedAssignment")
  public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    int steps = 3;

    while (true) {
      Point p = MouseInfo.getPointerInfo().getLocation();

      move(robot, p.x += steps, p.y);

      // update the pointer location, else you block the user's movement
      // (the pointer would move to the initial location instead of following the user's movement)
      p = MouseInfo.getPointerInfo().getLocation();
      move(robot, p.x, p.y += steps);

      p = MouseInfo.getPointerInfo().getLocation();
      move(robot, p.x -= steps, p.y);

      p = MouseInfo.getPointerInfo().getLocation();
      move(robot, p.x, p.y -= steps);

      LockSupport.parkNanos(TimeUnit.MINUTES.toNanos(2));
    }
  }
 protected static void processMagnification(IdeFrame frame, double magnification) {
   Point mouse = MouseInfo.getPointerInfo().getLocation();
   SwingUtilities.convertPointFromScreen(mouse, frame.getComponent());
   Component componentAt =
       SwingUtilities.getDeepestComponentAt(frame.getComponent(), mouse.x, mouse.y);
   if (componentAt != null) {
     Editor editor =
         PlatformDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext(componentAt));
     if (editor != null) {
       double currentSize = editor.getColorsScheme().getEditorFontSize();
       int defaultFontSize =
           EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize();
       ((EditorEx) editor)
           .setFontSize((int) (Math.max(currentSize + magnification * 3, defaultFontSize)));
     }
   }
 }
Esempio n. 13
0
  @Override
  public void mouseClicked(MouseEvent e) {

    indexOfLabelPressed = -1;

    for (int i = 0; i < orderLabel.length; i++) {
      if (e.getSource() == orderLabel[i]) {
        indexOfLabelPressed = i;
        PointerInfo a = MouseInfo.getPointerInfo();
        Point b = a.getLocation();
        int x = (int) b.getX();
        int y = (int) b.getY();
        popup.setLocation(x, y);
        popup.setInvoker(popup);
        popup.setVisible(true);
        revalidate();
        repaint();
      }
    }

    if (e.getSource() == topPanelLabel) {
      indexOfLabelPressed = -2;
    }

    if (indexOfLabelPressed == -1) {
      okDiscountButton.setText("Deduct");
      discountPopup.setLocation(700, 220);
      discountPopup.setInvoker(discountPopup);
      discountPopup.setVisible(true);
      itemDiscountPopupLabel.setText(
          "$"
              + finalModifier
              + " off with "
              + menuPanel.df.format((1 - finalPercentModifier) * 100)
              + "%"
              + " discount");
    } else if (indexOfLabelPressed == -2) {
      // TODO
      resetAll();
    }
  }
  public static void main(String[] args) throws Exception {
    DatagramSocket serverSocket = new DatagramSocket(8083);
    int count = 0;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int middleOfScreenX = (int) Math.round(screenSize.getWidth() / 2);
    int middleOfScreenY = (int) Math.round(screenSize.getHeight() / 2);

    System.out.println("Server started");
    byte[] receiveData = new byte[128];
    Robot robot = new Robot();
    while (true) {
      DatagramPacket receivedPacket = new DatagramPacket(receiveData, receiveData.length);
      serverSocket.receive(receivedPacket);

      SenderObject senderObject = SenderObject.parseFrom(receivedPacket.getData());
      float y = senderObject.getY();
      float x = senderObject.getX();
      int type = senderObject.getType();
      System.out.println(senderObject.toString());
      // Get the current pointer location.
      Point mousePointer = MouseInfo.getPointerInfo().getLocation();

      // Check if the type is mouse click.
      if (type == 2) {
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
      }
      // otherwise move the mouse pointer by subtracting to current
      // coordinates. Subtraction, because of the flipped right and left.
      else {
        float curX = mousePointer.x - x;
        float curY = mousePointer.y - y;
        robot.mouseMove(Math.round(curX), Math.round(curY));
      }
    }
  }
Esempio n. 15
0
 public Object run() throws HeadlessException {
   return MouseInfo.getPointerInfo().getLocation();
 }
Esempio n. 16
0
 @Override
 protected void paintComponent(Graphics graphics) {
   BufferedImage backImage =
       new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics2D backGraphics = backImage.createGraphics();
   BufferedImage frontImage =
       new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics2D frontGraphics = frontImage.createGraphics();
   BufferedImage particleImage =
       new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics2D particleGraphics = particleImage.createGraphics();
   Graphics2D graphics2D = (Graphics2D) graphics;
   graphics.setColor(Color.BLACK);
   graphics.fillRect(0, 0, getWidth(), getHeight());
   graphics2D.translate(-cameraX, -cameraY);
   backGraphics.translate(-cameraX, -cameraY);
   frontGraphics.translate(-cameraX, -cameraY);
   particleGraphics.translate(-cameraX, -cameraY);
   for (int y = cameraY / 64; y < (cameraY / 64) + (getHeight() / 64) + 2; y++) {
     for (int x = cameraX / 64; x < (cameraX / 64) + (getWidth() / 64) + 2; x++) {
       Tile tile = world.getTileAt(x, y);
       if (tile != null) {
         backGraphics.drawImage(
             client.getTextureManager().getTexture("grass"), x * 64, y * 64, null);
         Unit unit = tile.getUnit();
         if (unit != null) {
           if (unit instanceof Dragon) {
             BufferedImage texture;
             if (unit.getDX() > 0) {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_right_1")
                       : client.getTextureManager().getTexture("dragon_right_2");
             } else if (unit.getDX() < 0) {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_left_1")
                       : client.getTextureManager().getTexture("dragon_left_2");
             } else if (unit.getDY() > 0) {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_down_1")
                       : client.getTextureManager().getTexture("dragon_down_2");
             } else if (unit.getDY() < 0) {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_up_1")
                       : client.getTextureManager().getTexture("dragon_up_2");
             } else {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_down_1")
                       : client.getTextureManager().getTexture("dragon_down_2");
             }
             frontGraphics.drawImage(
                 texture, (x * 64) + unit.getXOffset(), (y * 64) + unit.getYOffset(), null);
             particleGraphics.setColor(Color.BLACK);
             if (unit.getAttackTarget() != null
                 && ((abs(unit.getAttackTarget().getTile().getX() - unit.getTile().getX()) == 1
                         && unit.getAttackTarget().getTile().getY() == unit.getTile().getY())
                     || (abs(unit.getAttackTarget().getTile().getY() - unit.getTile().getY()) == 1
                         && unit.getAttackTarget().getTile().getX() == unit.getTile().getX()))) {
               int xStart = min(unit.getTile().getX(), unit.getAttackTarget().getTile().getX());
               int xEnd = max(unit.getTile().getX(), unit.getAttackTarget().getTile().getX());
               int yStart = min(unit.getTile().getY(), unit.getAttackTarget().getTile().getY());
               int yEnd = max(unit.getTile().getY(), unit.getAttackTarget().getTile().getY());
               Random random = new Random();
               for (int pX = (xStart * 64) + 28; pX < (xEnd * 64) + 34; pX++) {
                 for (int pY = (yStart * 64) + 28; pY < (yEnd * 64) + 34; pY++) {
                   switch (random.nextInt(3)) {
                     case 0:
                       particleGraphics.setColor(Color.RED);
                       break;
                     case 1:
                       particleGraphics.setColor(Color.ORANGE);
                       break;
                     case 2:
                       particleGraphics.setColor(Color.YELLOW);
                       break;
                   }
                   particleGraphics.fillOval(
                       pX - 3 + random.nextInt(3), pY - 3 + random.nextInt(3), 4, 4);
                 }
               }
             }
           } else if (unit instanceof Wall) {
             TextureManager textureManager = client.getTextureManager();
             BufferedImage texture = textureManager.getTexture("tower");
             int offset = 128;
             Tile upTile = unit.getTile().getAdjacent(0, -1);
             boolean up =
                 upTile != null
                     && upTile.getUnit() != null
                     && upTile.getUnit() instanceof Wall
                     && upTile.getUnit().isComplete();
             Tile downTile = unit.getTile().getAdjacent(0, 1);
             boolean down =
                 downTile != null
                     && downTile.getUnit() != null
                     && downTile.getUnit() instanceof Wall
                     && downTile.getUnit().isComplete();
             Tile leftTile = unit.getTile().getAdjacent(-1, 0);
             boolean left =
                 leftTile != null
                     && leftTile.getUnit() != null
                     && leftTile.getUnit() instanceof Wall
                     && leftTile.getUnit().isComplete();
             Tile rightTile = unit.getTile().getAdjacent(1, 0);
             boolean right =
                 rightTile != null
                     && rightTile.getUnit() != null
                     && rightTile.getUnit() instanceof Wall
                     && rightTile.getUnit().isComplete();
             if (unit.isComplete()) {
               if (up) {
                 if (down) {
                   if (left) {
                     if (right) {
                       texture = textureManager.getTexture("tower_wall_up_down_left_right");
                     } else {
                       texture = textureManager.getTexture("tower_wall_up_down_left");
                     }
                   } else if (right) {
                     texture = textureManager.getTexture("tower_wall_up_down_right");
                   } else {
                     texture = textureManager.getTexture("wall_ver");
                     offset = 64;
                   }
                 } else if (left) {
                   if (right) {
                     texture = textureManager.getTexture("tower_wall_up_left_right");
                   } else {
                     texture = textureManager.getTexture("tower_wall_up_left");
                   }
                 } else if (right) {
                   texture = textureManager.getTexture("tower_wall_up_right");
                 } else {
                   texture = textureManager.getTexture("tower_wall_up");
                 }
               } else if (down) {
                 if (left) {
                   if (right) {
                     texture = textureManager.getTexture("tower_wall_down_left_right");
                   } else {
                     texture = textureManager.getTexture("tower_wall_down_left");
                   }
                 } else if (right) {
                   texture = textureManager.getTexture("tower_wall_down_right");
                 } else {
                   texture = textureManager.getTexture("tower_wall_down");
                 }
               } else if (left) {
                 if (right) {
                   texture = textureManager.getTexture("wall_hor");
                   offset = 64;
                 } else {
                   texture = textureManager.getTexture("tower_wall_left");
                 }
               } else if (right) {
                 texture = textureManager.getTexture("tower_wall_right");
               }
             } else {
               texture = textureManager.getTexture("wall_in_progress");
               offset = 64;
             }
             frontGraphics.drawImage(
                 texture,
                 (x * 64) + unit.getXOffset(),
                 (y * 64) + unit.getYOffset() - offset,
                 null);
           } else if (unit instanceof Flag) {
             BufferedImage texture = null;
             if (currentFlagFrame == 0) texture = client.getTextureManager().getTexture("flag_1");
             else if (currentFlagFrame == 1)
               texture = client.getTextureManager().getTexture("flag_2");
             else if (currentFlagFrame == 2)
               texture = client.getTextureManager().getTexture("flag_3");
             else if (currentFlagFrame == 3)
               texture = client.getTextureManager().getTexture("flag_4");
             if (texture != null) frontGraphics.drawImage(texture, (x * 64), (y * 64) - 64, null);
           }
         }
       }
     }
   }
   int mouseTileX =
       ((cameraX
               - (int) getLocationOnScreen().getX()
               + (int) MouseInfo.getPointerInfo().getLocation().getX())
           / 64);
   int mouseTileY =
       ((cameraY
               - (int) getLocationOnScreen().getY()
               + (int) MouseInfo.getPointerInfo().getLocation().getY())
           / 64);
   Tile mouseTile = getWorld().getTileAt(mouseTileX, mouseTileY);
   if (mouseTile != null) {
     if (mouseTile.getUnit() == null) {
       if (client.getShopPanel().getSelectedItem() == null) {
         backGraphics.setColor(new Color(0F, 1F, 0F, 0.5F));
       } else {
         backGraphics.setColor(new Color(0F, 0F, 1F, 0.5F));
       }
     } else {
       backGraphics.setColor(new Color(1F, 0F, 0F, 0.5F));
     }
     backGraphics.fillRect(mouseTileX * 64, mouseTileY * 64, 64, 64);
     if (mouseTile.getUnit() == null) {
       if (client.getShopPanel().getSelectedItem() == null) {
         backGraphics.setColor(Color.GREEN);
       } else {
         backGraphics.setColor(Color.BLUE);
       }
     } else {
       backGraphics.setColor(Color.RED);
     }
     backGraphics.drawRect(
         ((cameraX
                     - (int) getLocationOnScreen().getX()
                     + (int) MouseInfo.getPointerInfo().getLocation().getX())
                 / 64)
             * 64,
         ((cameraY
                     - (int) getLocationOnScreen().getY()
                     + (int) MouseInfo.getPointerInfo().getLocation().getY())
                 / 64)
             * 64,
         64,
         64);
   }
   graphics2D.translate(cameraX, cameraY);
   backGraphics.translate(cameraX, cameraY);
   frontGraphics.translate(cameraX, cameraY);
   particleGraphics.translate(cameraX, cameraY);
   graphics.drawImage(backImage, 0, 0, null);
   graphics.drawImage(frontImage, 0, 0, null);
   graphics.drawImage(particleImage, 0, 0, null);
   backGraphics.dispose();
   frontGraphics.dispose();
   particleGraphics.dispose();
   backImage.flush();
   frontImage.flush();
   particleImage.flush();
 }
  public void init() {
    try {
      robot = new Robot();
    } catch (AWTException ex) {
      ex.printStackTrace();
      throw new RuntimeException(ex);
    }
    this.setLayout(new BorderLayout());

    target.setBackground(Color.green);
    target.setName("GreenBox"); // for the ease of debug
    target.setPreferredSize(new Dimension(100, 100));
    String toolkit = Toolkit.getDefaultToolkit().getClass().getName();

    // on X systems two buttons are reserved for wheel though they are countable by MouseInfo.
    int buttonsNumber =
        toolkit.equals("sun.awt.windows.WToolkit")
            ? MouseInfo.getNumberOfButtons()
            : MouseInfo.getNumberOfButtons() - 2;

    for (int i = 0; i < 8; i++) {
      buttonNumber.add("BUTTON" + (i + 1) + "_MASK");
    }

    pressOn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.out.println("Now pressing : " + (buttonNumber.getSelectedIndex() + 1));

            Timer timer = new Timer();
            TimerTask robotInteraction =
                new TimerTask() {
                  public void run() {
                    robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y);
                    robot.mousePress(getMask(buttonNumber.getSelectedIndex() + 1));
                  }
                };
            timer.schedule(robotInteraction, SEND_DELAY);
          }
        });

    releaseOn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.out.println("Now releasing : " + (buttonNumber.getSelectedIndex() + 1));
            Timer timer = new Timer();
            TimerTask robotInteraction =
                new TimerTask() {
                  public void run() {
                    robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y);
                    robot.mouseRelease(getMask(buttonNumber.getSelectedIndex() + 1));
                  }
                };
            timer.schedule(robotInteraction, SEND_DELAY);
          }
        });

    clickOn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.out.println("Now clicking : " + (buttonNumber.getSelectedIndex() + 1));
            Timer timer = new Timer();
            TimerTask robotInteraction =
                new TimerTask() {
                  public void run() {
                    robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y);
                    robot.mousePress(getMask(buttonNumber.getSelectedIndex() + 1));
                    robot.mouseRelease(getMask(buttonNumber.getSelectedIndex() + 1));
                  }
                };
            timer.schedule(robotInteraction, SEND_DELAY);
          }
        });
    target.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            Sysout.println("" + e);
          }

          public void mouseReleased(MouseEvent e) {
            Sysout.println("" + e);
          }

          public void mouseClicked(MouseEvent e) {
            Sysout.println("" + e);
          }
        });

    String[] instructions = {
      "Do provide an instruction to the robot by",
      "choosing the button number to act and ",
      "pressing appropriate java.awt.Button on the left.",
      "Inspect an output in the TextArea below.",
      "Please don't generate non-natural sequences like Release-Release, etc.",
      "If you use keyboard be sure that you released the keyboard shortly.",
      "If events are generated well press Pass, otherwise Fail."
    };
    Sysout.createDialogWithInstructions(instructions);
  } // End  init()
Esempio n. 18
0
  /**
   * Update the lastState property. Should ideally be called on each World.act(), or at least before
   * getState() in a frame where mouse info is wanted.
   */
  public void act() {
    MouseInfo mouseinfo = Greenfoot.getMouseInfo();

    /* To-be properties of MouseState */
    boolean held = lastState.held;
    boolean down = false;
    boolean up = false;
    boolean moved;
    Vector position;

    if (mouseinfo != null) {
      /* Get the new mouse position */
      position = new Vector(mouseinfo.getX(), mouseinfo.getY());
      /* We have moved if there is a difference between this mouse position and
       * the previous mouse position. */
      moved = lastState.position == null || position.subtract(lastState.position).length() > 0.5;

    } else {
      /* mouseinfo == null */

      /* Use the previous mouse position */
      position = lastState.position;
      /* We haven't moved the mouse pointer. */
      moved = false;
    }

    if (lastState.held) {
      /* Figure out if the mouse has been released. This has to be done
       * differently on Mac OS X, as MouseInfo contains different info in case
       * of mouse release on that platform. */
      if (System.getProperty("os.name").equals("Mac OS X")) {
        if (Greenfoot.mouseClicked(null)
            || mouseinfo != null
                && (mouseinfo.getActor() != concerning || mouseinfo.getButton() != 1)) {
          up = true;
          held = false;
        }
      } else {
        /* TODO: Check if this behaves correctly in Windows */
        if (Greenfoot.mouseClicked(concerning)
            || mouseinfo != null
                && (mouseinfo.getActor() != concerning || mouseinfo.getButton() != 0)) {
          up = true;
          held = false;
        }
      }

    } else {
      /* !lastState.held */

      /* Figure out if mouse has been pressed. This is thankfully
       * cross-platform consistent. */
      if (Greenfoot.mousePressed(concerning)) {
        down = true;
        held = true;
      }
    }

    /* Store the state in the lastState property. */
    lastState = new MouseState(held, down, up, moved, position);
  }
Esempio n. 19
0
 public Point getLocation() {
   return MouseInfo.getPointerInfo().getLocation();
 }
Esempio n. 20
0
 static {
   defaultInstance = new MouseInfo(true);
   com.opera.core.systems.scope.protos.SystemInputProtos.internalForceInit();
   defaultInstance.initFields();
 }
 public void SaveMouseLocation(ActionEvent actionEvent) {
   var_coordX = MouseInfo.getPointerInfo().getLocation().x;
   var_coordY = MouseInfo.getPointerInfo().getLocation().y;
   scene_XCoord.setText(String.valueOf(var_coordX));
   scene_YCoord.setText(String.valueOf(var_coordY));
 }