@SuppressWarnings({"boxing"})
 public void show(Point point, Vehicle vehicle) {
   final String exitString;
   if (vehicle.exitRoadSegmentId() == Vehicle.ROAD_SEGMENT_ID_NOT_SET) {
     exitString = this.trafficCanvas.popupStringExitEndRoad;
   } else {
     exitString = this.trafficCanvas.roadNetwork.findById(vehicle.exitRoadSegmentId()).userId();
   }
   final PhysicalQuantities vehiclePhysical = vehicle.physicalQuantities();
   final String string =
       String.format(
           this.trafficCanvas.popupString,
           vehicle.getId(),
           vehicle.getLabel(),
           vehicle.lane(),
           vehiclePhysical.getFrontPosition(),
           vehiclePhysical.getSpeed() * Units.MS_TO_KMH,
           vehiclePhysical.getAcc(),
           vehicle.totalTravelDistance(),
           exitString);
   final Label label = new Label(string, Label.LEFT);
   label.setBackground(new Color(200, 220, 240));
   removeAll();
   add(label);
   pack();
   final Point screenLocation = owner.getLocationOnScreen();
   setLocation(point.x + screenLocation.x + 15, point.y + screenLocation.y + 90);
   currentPopupId = vehicle.getId();
   setVisible(true);
   final PopupTimer popupTimer = new PopupTimer();
   popupTimer.start(currentPopupId);
 }
 private void zentriere(java.awt.Frame hf) {
   java.awt.Point OL = hf.getLocationOnScreen();
   OL.translate(hf.getWidth() / 2, hf.getHeight() / 2);
   OL.translate(-this.getWidth() / 2, -this.getHeight() / 2);
   if (OL.getX() < 0) OL.setLocation(0, OL.getY());
   if (OL.getY() < 0) OL.setLocation(OL.getX(), 0);
   this.setLocation(OL);
 }
  public static void main(String s[]) {
    initParams(s);
    initAdapters();
    f = new Frame();
    final int[] modifiers = {InputEvent.SHIFT_MASK, InputEvent.CTRL_MASK};
    final String[] modifierNames = {"InputEvent.SHIFT_MASK", "InputEvent.CTRL_MASK"};
    f.setLayout(new FlowLayout());
    f.addMouseWheelListener(
        new MouseWheelListener() {
          public void mouseWheelMoved(MouseWheelEvent e) {
            System.out.println("WHEEL " + e);
          }
        });
    f.setSize(300, 300);
    f.setVisible(true);

    try {
      robot = new Robot();
      robot.delay(500);
      robot.mouseMove(
          f.getLocationOnScreen().x + f.getWidth() / 2,
          f.getLocationOnScreen().y + f.getHeight() / 2);
      if (autorun) {
        // testing buttons 1, 2, 3 only
        testPlainButtons();
        robot.delay(500);

        // testing buttons 1, 2, 3 with SHIFT, CTRL, ALT keyboard modifiers
        testButtonsWithShift();
        robot.delay(500);

        testButtonsWithControl();
        robot.delay(500);

        testButtonsWithAlt();
        robot.delay(500);
      } else {
        switch (testModifier) {
          case SHIFT:
            f.addMouseListener(adapterTest2);
            break;
          case CTRL:
            f.addMouseListener(adapterTest3);
            break;
          case ALT:
            f.addMouseListener(adapterTest4);
            break;
          default: // NONE inclusive
            f.addMouseListener(adapterTest1);
        }
      }
    } catch (Exception e) {
      throw new RuntimeException("Test failed.");
    }
  }
 public static DateChooserDialog show(Frame owner, Date date) {
   DateChooserDialog dialog = new DateChooserDialog(owner, date);
   dialog.setSize(width, height);
   dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
   dialog.pack();
   Point p = owner.getLocationOnScreen();
   p.y = p.y + 30;
   dialog.setLocation(getAppropriateLocation(owner, p));
   dialog.setVisible(true);
   return dialog;
 }
Beispiel #5
0
 private void centerOnScreen(Frame frame) {
   Point point = frame.getLocationOnScreen();
   Dimension dimension = frame.getSize();
   Dimension dimension1 = getSize();
   point.x += (dimension.width - dimension1.width) / 2;
   point.y += (dimension.height - dimension1.height) / 2;
   Dimension dimension2 = Toolkit.getDefaultToolkit().getScreenSize();
   if (point.x < 0
       || point.y < 0
       || point.x + dimension1.width > dimension2.width
       || point.y + dimension1.height > dimension2.height) {
     point.x = (dimension2.width - dimension1.width) / 2;
     point.y = (dimension2.height - dimension1.height) / 2;
   }
   setLocation(point.x, point.y);
 }
Beispiel #6
0
  public void start() {
    frame.setSize(480, 300);
    frame.setVisible(true);
    try {
      robot = new Robot();
    } catch (AWTException e) {
      throw new RuntimeException(e);
    }

    Util.waitForIdle(robot); // a time to show Frame

    fp = frame.getLocationOnScreen();

    for (int i = 0; i < TRIALS; i++) {
      checkClicked();
      clearFlags();
    }

    for (int i = 0; i < TRIALS; i++) {
      oneDrag(2);
      clearFlags();
    }

    for (int i = 0; i < TRIALS; i++) {
      oneDrag(5);
      clearFlags();
    }

    for (int i = 0; i < TRIALS; i++) {
      oneDrag(70);
      clearFlags();
    }

    // Check that no Drag event occur in the SMUDGE area
    String sToolkit = Toolkit.getDefaultToolkit().getClass().getName();
    System.out.println("Toolkit == " + sToolkit);
    if ("sun.awt.windows.WToolkit".equals(sToolkit)) {
      int dragWidth =
          ((Integer) Toolkit.getDefaultToolkit().getDesktopProperty("win.drag.width")).intValue();
      int dragHeight =
          ((Integer) Toolkit.getDefaultToolkit().getDesktopProperty("win.drag.height")).intValue();
      System.out.println("dragWidth==" + dragWidth + ":: dragHeight==" + dragHeight);
      // DragWidth and dragHeight may be equal to 1. In that case the SMUDGE rectangle
      // narrowed into 1x1 pixel and we can't drag a mouse in it.
      // In that case we may skip following testcase but I'd prefer if we move mouse on 1 pixel
      // only.
      // And that should pass as well.
      dragWidth = dragWidth > 1 ? dragWidth / 2 : 1;
      dragHeight = dragHeight > 1 ? dragHeight / 2 : 1;
      for (int i = 0; i < TRIALS; i++) {
        smallWin32Drag(dragWidth, dragHeight);
        clearFlags();
      }
    } else if ("sun.lwawt.macosx.LWCToolkit".equals(sToolkit)) {
      // On MacOS X every mouse move event is MOUSE_DRAGGED event and
      // MOUSE_DRAGGED is sent back form the Native code to the java code
      // for every mouse move. Therefore 'smallDrag test should be
      // disabled for toolkit 'sun.lwawt.macosx.LWCToolkit'.
    } else {
      for (int i = 0; i < TRIALS; i++) {
        smallDrag(
            SMUDGE_WIDTH - 1, SMUDGE_HEIGHT - 1); // on Motif and XAWT SMUDGE area is 4-pixels wide
        clearFlags();
      }
    }
    System.out.println("Test passed.");
  } // start()