Example #1
0
  public CreInvChecker(Component parent) {
    typeButtons = new JCheckBox[CHECKTYPES.length];
    JPanel boxPanel = new JPanel(new GridLayout(0, 1));
    for (int i = 0; i < typeButtons.length; i++) {
      typeButtons[i] = new JCheckBox(CHECKTYPES[i], true);
      boxPanel.add(typeButtons[i]);
    }
    bstart.setMnemonic('s');
    bcancel.setMnemonic('c');
    bstart.addActionListener(this);
    bcancel.addActionListener(this);
    selectframe.getRootPane().setDefaultButton(bstart);
    selectframe.setIconImage(Icons.getIcon("Find16.gif").getImage());
    boxPanel.setBorder(BorderFactory.createTitledBorder("Select test to check:"));

    JPanel bpanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    bpanel.add(bstart);
    bpanel.add(bcancel);

    JPanel mainpanel = new JPanel(new BorderLayout());
    mainpanel.add(boxPanel, BorderLayout.CENTER);
    mainpanel.add(bpanel, BorderLayout.SOUTH);
    mainpanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

    JPanel pane = (JPanel) selectframe.getContentPane();
    pane.setLayout(new BorderLayout());
    pane.add(mainpanel, BorderLayout.CENTER);

    selectframe.pack();
    Center.center(selectframe, parent.getBounds());
    selectframe.setVisible(true);
  }
  private boolean is(boolean first) {
    Container parent = getParent();
    if (parent == null) return false;

    int max = first ? Integer.MAX_VALUE : 0;
    ToolWindowAnchor anchor = getAnchor();
    Component c = null;
    int count = parent.getComponentCount();
    for (int i = 0; i < count; i++) {
      Component component = parent.getComponent(i);
      if (!component.isVisible()) continue;
      Rectangle r = component.getBounds();
      if (anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT) {
        if (first && (max > r.y) || (!first && max < r.y)) {
          max = r.y;
          c = component;
        }
      } else {
        if (first && (max > r.x) || (!first && max < r.x)) {
          max = r.x;
          c = component;
        }
      }
    }

    return c == this;
  }
  @Override
  public void mousePressed(MouseEvent e) {
    //	The mouseMoved event continually updates this variable

    if (direction == 0) return;

    //  Setup for resizing. All future dragging calculations are done based
    //  on the original bounds of the component and mouse pressed location.

    resizing = true;

    Component source = e.getComponent();
    pressed = e.getPoint();
    SwingUtilities.convertPointToScreen(pressed, source);
    bounds = source.getBounds();

    //  Making sure autoscrolls is false will allow for smoother resizing
    //  of components

    if (source instanceof JComponent) {
      JComponent jc = (JComponent) source;
      autoscrolls = jc.getAutoscrolls();
      jc.setAutoscrolls(false);
    }
  }
  protected Rectangle getTextComponentBound() {
    Rectangle ownerRec = myOwner == null ? new Rectangle(0, 0, 0, 0) : myOwner.getBounds();

    Dimension size = myComponent.getPreferredSize();
    int x = (ownerRec.width - size.width) / 2;
    int y = (ownerRec.height - size.height) / 3;
    return new Rectangle(x, y, size.width, size.height);
  }
Example #5
0
 /*
  *  Create a BufferedImage for AWT components.
  *
  *  @param	 component AWT component to create image from
  *  @param	 fileName name of file to be created or null
  *  @return	image the image for the given region
  *  @exception AWTException see Robot class constructors
  *  @exception IOException if an error occurs during writing
  */
 public static BufferedImage createImage(Component component, String fileName)
     throws AWTException, IOException {
   Point p = new Point(0, 0);
   SwingUtilities.convertPointToScreen(p, component);
   Rectangle region = component.getBounds();
   region.x = p.x;
   region.y = p.y;
   return ScreenCapture.createImage(region, fileName);
 }
  /**
   * Returns the component in the currently selected path which contains sourcePoint.
   *
   * @param source The component in whose coordinate space sourcePoint is given
   * @param sourcePoint The point which is being tested
   * @return The component in the currently selected path which contains sourcePoint (relative to
   *     the source component's coordinate space. If sourcePoint is not inside a component on the
   *     currently selected path, null is returned.
   */
  public Component componentForPoint(Component source, Point sourcePoint) {
    int screenX, screenY;
    Point p = sourcePoint;
    int i, c, j, d;
    Component mc;
    Rectangle r2;
    int cWidth, cHeight;
    MenuElement menuElement;
    MenuElement subElements[];
    Vector<MenuElement> tmp;
    int selectionSize;

    SwingUtilities.convertPointToScreen(p, source);

    screenX = p.x;
    screenY = p.y;

    tmp = (Vector<MenuElement>) selection.clone();
    selectionSize = tmp.size();
    for (i = selectionSize - 1; i >= 0; i--) {
      menuElement = (MenuElement) tmp.elementAt(i);
      subElements = menuElement.getSubElements();

      for (j = 0, d = subElements.length; j < d; j++) {
        if (subElements[j] == null) continue;
        mc = subElements[j].getComponent();
        if (!mc.isShowing()) continue;
        if (mc instanceof JComponent) {
          cWidth = mc.getWidth();
          cHeight = mc.getHeight();
        } else {
          r2 = mc.getBounds();
          cWidth = r2.width;
          cHeight = r2.height;
        }
        p.x = screenX;
        p.y = screenY;
        SwingUtilities.convertPointFromScreen(p, mc);

        /**
         * Return the deepest component on the selection path in whose bounds the event's point
         * occurs
         */
        if (p.x >= 0 && p.x < cWidth && p.y >= 0 && p.y < cHeight) {
          return mc;
        }
      }
    }
    return null;
  }
Example #7
0
  /** Processes the data and renders it to a component */
  public synchronized int process(Buffer buffer) {
    if (component == null) return BUFFER_PROCESSED_FAILED;

    Format inf = buffer.getFormat();
    if (inf == null) return BUFFER_PROCESSED_FAILED;

    if (inf != inputFormat || !buffer.getFormat().equals(inputFormat)) {
      if (setInputFormat(inf) != null) return BUFFER_PROCESSED_FAILED;
    }

    Object data = buffer.getData();
    if (!(data instanceof int[])) return BUFFER_PROCESSED_FAILED;

    if (lastBuffer != buffer) {
      lastBuffer = buffer;
      newImage(buffer);
    }

    sourceImage.newPixels(0, 0, inWidth, inHeight);

    Graphics g = component.getGraphics();
    if (g != null) {
      if (reqBounds == null) {
        bounds = component.getBounds();
        bounds.x = 0;
        bounds.y = 0;
      } else bounds = reqBounds;
      g.drawImage(
          destImage,
          bounds.x,
          bounds.y,
          bounds.width,
          bounds.height,
          0,
          0,
          inWidth,
          inHeight,
          component);
    }

    return BUFFER_PROCESSED_OK;
  }
  /**
   * When a MenuElement receives an event from a MouseListener, it should never process the event
   * directly. Instead all MenuElements should call this method with the event.
   *
   * @param event a MouseEvent object
   */
  public void processMouseEvent(MouseEvent event) {
    int screenX, screenY;
    Point p;
    int i, c, j, d;
    Component mc;
    Rectangle r2;
    int cWidth, cHeight;
    MenuElement menuElement;
    MenuElement subElements[];
    MenuElement path[];
    Vector<MenuElement> tmp;
    int selectionSize;
    p = event.getPoint();

    Component source = event.getComponent();

    if ((source != null) && !source.isShowing()) {
      // This can happen if a mouseReleased removes the
      // containing component -- bug 4146684
      return;
    }

    int type = event.getID();
    int modifiers = event.getModifiers();
    // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2
    if ((type == MouseEvent.MOUSE_ENTERED || type == MouseEvent.MOUSE_EXITED)
        && ((modifiers
                & (InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK))
            != 0)) {
      return;
    }

    if (source != null) {
      SwingUtilities.convertPointToScreen(p, source);
    }

    screenX = p.x;
    screenY = p.y;

    tmp = (Vector<MenuElement>) selection.clone();
    selectionSize = tmp.size();
    boolean success = false;
    for (i = selectionSize - 1; i >= 0 && success == false; i--) {
      menuElement = (MenuElement) tmp.elementAt(i);
      subElements = menuElement.getSubElements();

      path = null;
      for (j = 0, d = subElements.length; j < d && success == false; j++) {
        if (subElements[j] == null) continue;
        mc = subElements[j].getComponent();
        if (!mc.isShowing()) continue;
        if (mc instanceof JComponent) {
          cWidth = mc.getWidth();
          cHeight = mc.getHeight();
        } else {
          r2 = mc.getBounds();
          cWidth = r2.width;
          cHeight = r2.height;
        }
        p.x = screenX;
        p.y = screenY;
        SwingUtilities.convertPointFromScreen(p, mc);

        /**
         * Send the event to visible menu element if menu element currently in the selected path or
         * contains the event location
         */
        if ((p.x >= 0 && p.x < cWidth && p.y >= 0 && p.y < cHeight)) {
          int k;
          if (path == null) {
            path = new MenuElement[i + 2];
            for (k = 0; k <= i; k++) path[k] = (MenuElement) tmp.elementAt(k);
          }
          path[i + 1] = subElements[j];
          MenuElement currentSelection[] = getSelectedPath();

          // Enter/exit detection -- needs tuning...
          if (currentSelection[currentSelection.length - 1] != path[i + 1]
              && (currentSelection.length < 2
                  || currentSelection[currentSelection.length - 2] != path[i + 1])) {
            Component oldMC = currentSelection[currentSelection.length - 1].getComponent();

            MouseEvent exitEvent =
                new MouseEvent(
                    oldMC,
                    MouseEvent.MOUSE_EXITED,
                    event.getWhen(),
                    event.getModifiers(),
                    p.x,
                    p.y,
                    event.getXOnScreen(),
                    event.getYOnScreen(),
                    event.getClickCount(),
                    event.isPopupTrigger(),
                    MouseEvent.NOBUTTON);
            currentSelection[currentSelection.length - 1].processMouseEvent(exitEvent, path, this);

            MouseEvent enterEvent =
                new MouseEvent(
                    mc,
                    MouseEvent.MOUSE_ENTERED,
                    event.getWhen(),
                    event.getModifiers(),
                    p.x,
                    p.y,
                    event.getXOnScreen(),
                    event.getYOnScreen(),
                    event.getClickCount(),
                    event.isPopupTrigger(),
                    MouseEvent.NOBUTTON);
            subElements[j].processMouseEvent(enterEvent, path, this);
          }
          MouseEvent mouseEvent =
              new MouseEvent(
                  mc,
                  event.getID(),
                  event.getWhen(),
                  event.getModifiers(),
                  p.x,
                  p.y,
                  event.getXOnScreen(),
                  event.getYOnScreen(),
                  event.getClickCount(),
                  event.isPopupTrigger(),
                  MouseEvent.NOBUTTON);
          subElements[j].processMouseEvent(mouseEvent, path, this);
          success = true;
          event.consume();
        }
      }
    }
  }