Exemple #1
0
 /**
  * Changes the frame's location to a more central screen location
  *
  * @param frame the frame to be moved
  * @param X how far right to move the frame
  * @param Y how far down to move the frame
  */
 public static void changeFrameLocation(Component frame, int X, int Y) {
   Point location = frame.getLocation(); // the window's current location
   // move the window over and down a certain amount of pixels
   location.translate(X, Y);
   // set the location
   frame.setLocation(location);
 }
  public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new NimbusLookAndFeel());

    Robot robot = new Robot();
    robot.setAutoDelay(50);

    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            createAndShowGUI();
          }
        });

    toolkit.realSync();

    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            Component previewPanel =
                Util.findSubComponent(cc, "javax.swing.colorchooser.DefaultPreviewPanel");
            point = previewPanel.getLocationOnScreen();
          }
        });

    point.translate(5, 5);

    robot.mouseMove(point.x, point.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
  }
Exemple #3
0
 public Element getLineAtPoint(MouseEvent me) {
   Point p = me.getLocationOnScreen();
   Point pp = getLocationOnScreen();
   p.translate(-pp.x, -pp.y);
   int pos = viewToModel(p);
   Element root = getDocument().getDefaultRootElement();
   int e = root.getElementIndex(pos);
   if (e == -1) {
     return null;
   }
   return root.getElement(e);
 }
  static Point getLocationInQueryTextArea(Component childComp) {
    Point ret = new Point(0, 0);

    Component comp = childComp;

    while (false == comp instanceof QueryTextArea) {
      ret.translate(comp.getX(), comp.getY());
      comp = comp.getParent();
    }

    return ret;
  }
Exemple #5
0
        public void mousePressed(MouseEvent e) {
          requestFocus();
          Point p = e.getPoint();
          int size =
              Math.min(
                  MAX_SIZE,
                  Math.min(
                      getWidth() - imagePadding.left - imagePadding.right,
                      getHeight() - imagePadding.top - imagePadding.bottom));
          p.translate(-(getWidth() / 2 - size / 2), -(getHeight() / 2 - size / 2));
          if (mode == ColorPicker.BRI || mode == ColorPicker.SAT) {
            // the two circular views:
            double radius = ((double) size) / 2.0;
            double x = p.getX() - size / 2.0;
            double y = p.getY() - size / 2.0;
            double r = Math.sqrt(x * x + y * y) / radius;
            double theta = Math.atan2(y, x) / (Math.PI * 2.0);

            if (r > 1) r = 1;

            if (mode == ColorPicker.BRI) {
              setHSB((float) (theta + .25f), (float) (r), bri);
            } else {
              setHSB((float) (theta + .25f), sat, (float) (r));
            }
          } else if (mode == ColorPicker.HUE) {
            float s = ((float) p.x) / ((float) size);
            float b = ((float) p.y) / ((float) size);
            if (s < 0) s = 0;
            if (s > 1) s = 1;
            if (b < 0) b = 0;
            if (b > 1) b = 1;
            setHSB(hue, s, b);
          } else {
            int x2 = p.x * 255 / size;
            int y2 = p.y * 255 / size;
            if (x2 < 0) x2 = 0;
            if (x2 > 255) x2 = 255;
            if (y2 < 0) y2 = 0;
            if (y2 > 255) y2 = 255;

            if (mode == ColorPicker.RED) {
              setRGB(red, x2, y2);
            } else if (mode == ColorPicker.GREEN) {
              setRGB(x2, green, y2);
            } else {
              setRGB(x2, y2, blue);
            }
          }
        }
 private static JButton getButton(JList<String> list, Point pt, int index) {
   Component c =
       list.getCellRenderer().getListCellRendererComponent(list, "", index, false, false);
   Rectangle r = list.getCellBounds(index, index);
   c.setBounds(r);
   // c.doLayout(); //may be needed for mone LayoutManager
   pt.translate(-r.x, -r.y);
   Component b = SwingUtilities.getDeepestComponentAt(c, pt.x, pt.y);
   if (b instanceof JButton) {
     return (JButton) b;
   } else {
     return null;
   }
 }
  /**
   * Show the window.
   *
   * @param container - Window of JFrame to show
   */
  private void showPopup(Window container) {
    if (visibleComponent.isEnabled()) {
      Point pt = visibleComponent.getLocationOnScreen();
      pt.translate(0, visibleComponent.getHeight());
      container.setLocation(pt);
      container.toFront();

      ApplicationManager.setCurrentlySelectedField(fieldName);
      if (container instanceof OntologySelector) {
        ((OntologySelector) container).makeVisible();
      } else {
        container.setVisible(true);
        container.requestFocusInWindow();
      }
    }
  }
Exemple #8
0
 public void run() {
   while (running) {
     try {
       Thread.sleep(SPEED);
     } catch (InterruptedException e) {
     }
     synchronized (pos) {
       pos.translate(dx, dy);
     }
     if (pos.x < 0 || pos.x > Cwiczenie5_4.SIZE.width - SIZE) dx = -dx;
     if (dy > 0 && bar.bump(pos)) dy = -dy;
     if (pos.y < 0) dy = -dy;
     if (pos.y > Cwiczenie5_4.SIZE.height - SIZE) {
       running = false;
     }
   }
 }
  /**
   * Copies a parentally closed selection of session nodes in the frontmost session editor to the
   * clipboard.
   */
  public void actionPerformed(ActionEvent e) {
    Transferable transferable = InternalClipboard.getInstance().getContents(null);

    if (!(transferable instanceof SubgraphSelection)) {
      return;
    }

    SubgraphSelection selection = (SubgraphSelection) transferable;
    DataFlavor flavor = new DataFlavor(SubgraphSelection.class, "Subgraph Selection");

    try {
      List modelList = (List) selection.getTransferData(flavor);
      Point point = EditorUtils.getTopLeftPoint(modelList);
      point.translate(50, 50);
      graphEditor().pasteSubsession(modelList, point);
    } catch (Exception e1) {
      throw new RuntimeException(e1);
    }
  }
  /** Used internally */
  public void addNotify() {
    // Record the size of the window prior to calling parents addNotify.
    Dimension d = getSize();

    super.addNotify();

    if (fComponentsAdjusted) return;

    // Adjust components according to the insets
    Insets ins = getInsets();
    setSize(ins.left + ins.right + d.width, ins.top + ins.bottom + d.height);
    Component components[] = getContentPane().getComponents();
    for (int i = 0; i < components.length; i++) {
      Point p = components[i].getLocation();
      p.translate(ins.left, ins.top);
      components[i].setLocation(p);
    }
    fComponentsAdjusted = true;
  }
 private void dispatchEvent(MouseEvent me) {
   if (rect != null && rect.contains(me.getX(), me.getY())) {
     Point pt = me.getPoint();
     pt.translate(-offset, 0);
     comp.setBounds(rect);
     comp.dispatchEvent(
         new MouseEvent(
             comp,
             me.getID(),
             me.getWhen(),
             me.getModifiers(),
             pt.x,
             pt.y,
             me.getClickCount(),
             me.isPopupTrigger(),
             me.getButton()));
     if (!comp.isValid()) container.repaint();
   }
 }
Exemple #12
0
  /**
   * The code in this method is copy and pasted from source code to the same method in
   * javax.swing.JTable, except for one value change on one line. If you'd like to see the change,
   * please read the source code below.
   *
   * @param event the mouse event we're reacting to
   */
  public String getToolTipText(MouseEvent event) {
    String tip = null;
    Point p = event.getPoint();

    // Locate the renderer under the event location
    int hitColumnIndex = columnAtPoint(p);
    int hitRowIndex = rowAtPoint(p);

    if ((hitColumnIndex != -1) && (hitRowIndex != -1)) {
      TableCellRenderer renderer = getCellRenderer(hitRowIndex, hitColumnIndex);
      Component component = prepareRenderer(renderer, hitRowIndex, hitColumnIndex);

      // Now have to see if the component is a JComponent before
      // getting the tip
      if (component instanceof JComponent) {
        // Convert the event to the renderer's coordinate system
        Rectangle cellRect = getCellRect(hitRowIndex, hitColumnIndex, false);
        // HERE IS THE MODIFICATION FROM javax.swing.JTable:
        // p.translate(-cellRect.x, -cellRect.y);
        p.translate(-cellRect.x, 0);

        // END OF MODIFICATION
        MouseEvent newEvent =
            new MouseEvent(
                component,
                event.getID(),
                event.getWhen(),
                event.getModifiers(),
                p.x,
                p.y,
                event.getClickCount(),
                event.isPopupTrigger());

        tip = ((JComponent) component).getToolTipText(newEvent);
      }
    }

    // No tip from the renderer get our own tip
    if (tip == null) tip = getToolTipText();

    return tip;
  }
Exemple #13
0
 public void setIntermediate(Point p, ONLGraphic c) {
   if (ltool.isEnabled()) {
     if (linkGraphic != null) {
       Point pnt = new Point(p);
       // System.out.println("LinkTool::setIntermediate (" + pnt.getX() + ", " + pnt.getY() +
       // ")");
       if (c != null) {
         // System.out.println("                         translated by (" + c.getScreenX()+ ", "
         // + c.getScreenY() + ")");
         pnt.translate(
             (c.getScreenX() + HardwareGraphic.OFFSET),
             (c.getScreenY() + HardwareGraphic.D_OFFSET));
         // System.out.println("                          (" + pnt.getX() + ", " + pnt.getY() +
         // ")");
       }
       linkGraphic.setIntermediate(pnt);
       linkGraphic.revalidate();
       linkGraphic.repaint();
     }
   }
 }
  public static void main(String[] args) throws Exception {

    if (!OS.contains("mac")) {
      System.out.println("The test is applicable only to Mac OS X. Passed");
      return;
    }

    // Move the mouse out, because it could interfere with the test.
    Robot r = Util.createRobot();
    Util.waitForIdle(r);
    r.mouseMove(0, 0);
    Util.waitForIdle(r);

    SwingUtilities.invokeAndWait(
        new Runnable() {
          @Override
          public void run() {
            createAndShowGUI();
          }
        });

    // Move the mouse away from the frame and check the View-base full screen mode
    Util.waitForIdle(r);
    r.mouseMove(500, 500);
    Util.waitForIdle(r);
    mouseEnterCount = 0;
    SwingUtilities.invokeAndWait(
        new Runnable() {
          @Override
          public void run() {
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice()
                .setFullScreenWindow(frame);
          }
        });
    Util.waitForIdle(r);
    if (mouseEnterCount != 1) {
      throw new RuntimeException("No MouseEntered event for view-base full screen. Failed.");
    }
    SwingUtilities.invokeAndWait(
        new Runnable() {
          @Override
          public void run() {
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice()
                .setFullScreenWindow(null);
          }
        });

    // Test native full screen support
    Util.waitForIdle(r);
    Point fullScreenButtonPos = frame.getLocation();
    fullScreenButtonPos.translate(frame.getWidth() - 10, 10);
    r.mouseMove(fullScreenButtonPos.x, fullScreenButtonPos.y);
    mouseEnterCount = 0;

    // Cant use waitForIdle for full screen transition.
    int waitCount = 0;
    while (!windowEnteringFullScreen) {
      r.mousePress(InputEvent.BUTTON1_MASK);
      r.mouseRelease(InputEvent.BUTTON1_MASK);
      Thread.sleep(100);
      if (waitCount++ > 10) throw new RuntimeException("Can't enter full screen mode. Failed");
    }

    waitCount = 0;
    while (!windowEnteredFullScreen) {
      Thread.sleep(200);
      if (waitCount++ > 10) throw new RuntimeException("Can't enter full screen mode. Failed");
    }

    if (mouseEnterCount != 1) {
      throw new RuntimeException("No MouseEntered event for native full screen. Failed.");
    }
  }
 public Point mouseToScreenCoords(Point p) {
   Point tp = new Point(p);
   Insets i = getInsets();
   tp.translate(-i.left, -i.top);
   return tp;
 }