Example #1
0
 /**
  * Add a component in the list of components that should be refreshed. If <i>c</i> already has a
  * dirty region, the rectangle <i>(x,y,w,h)</i> will be unioned with the region that should be
  * redrawn.
  *
  * @param c Component to repaint, null results in nothing happening.
  * @param x X coordinate of the region to repaint
  * @param y Y coordinate of the region to repaint
  * @param w Width of the region to repaint
  * @param h Height of the region to repaint
  * @see JComponent#repaint
  */
 @Override
 public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
   Rectangle dirtyRegion = getDirtyRegion(c);
   if (dirtyRegion.width == 0 && dirtyRegion.height == 0) {
     int lastDeltaX = c.getX();
     int lastDeltaY = c.getY();
     Container parent = c.getParent();
     while (parent instanceof JComponent) {
       if (!parent.isVisible() || !parent.isDisplayable()) {
         return;
       }
       if (parent instanceof JXPanel
           && (((JXPanel) parent).getAlpha() < 1f || !parent.isOpaque())) {
         x += lastDeltaX;
         y += lastDeltaY;
         lastDeltaX = lastDeltaY = 0;
         c = (JComponent) parent;
       }
       lastDeltaX += parent.getX();
       lastDeltaY += parent.getY();
       parent = parent.getParent();
     }
   }
   super.addDirtyRegion(c, x, y, w, h);
 }
  /**
   * Positions the specified dialog at a position relative to its parent.
   *
   * @param dialog the dialog to be positioned.
   * @param horizontalPercent the relative location.
   * @param verticalPercent the relative location.
   */
  public static void positionDialogRelativeToParent(
      final Dialog dialog, final double horizontalPercent, final double verticalPercent) {
    final Container parent = dialog.getParent();
    if (parent == null || (parent.isVisible() == false)) {
      positionFrameOnScreen(dialog, horizontalPercent, verticalPercent);
      return;
    }

    final Dimension d = dialog.getSize();
    final Dimension p = parent.getSize();

    final int baseX = parent.getX();
    final int baseY = parent.getY();

    final int parentPointX = baseX + (int) (horizontalPercent * p.width);
    final int parentPointY = baseY + (int) (verticalPercent * p.height);

    final int dialogPointX = parentPointX - (int) (horizontalPercent * d.width);
    final int dialogPointY = parentPointY - (int) (verticalPercent * d.height);

    // make sure the dialog fits completely on the screen...
    final Rectangle s = parent.getGraphicsConfiguration().getBounds();
    final Rectangle r = new Rectangle(dialogPointX, dialogPointY, d.width, d.height);
    final Rectangle intersectedDialogBounds = r.intersection(s);
    if (intersectedDialogBounds.width < d.width) {
      r.x = s.width - d.width;
      r.width = d.width;
    }
    if (intersectedDialogBounds.height < d.height) {
      r.y = s.height - d.height;
      r.height = d.height;
    }
    final Rectangle finalIntersection = r.intersection(s);
    dialog.setBounds(finalIntersection);
  }
Example #3
0
 /**
  * Retorna a localização do centro deste conector em relação ao <code>Container</code> do parent
  * deste conector.
  *
  * @return Um ponto indicando a localização. Caso o conector não possua parent, retorna <code>null
  *     </code>.
  */
 public Point getCenterLocationOnParentContainer() {
   Container c = getParent();
   if (c == null) {
     return null;
   }
   return new Point(c.getX() + getX() + getWidth() / 2, c.getY() + getY() + getHeight() / 2);
 }
Example #4
0
 /**
  * Retorna a localização deste conector em relação ao <code>Container</code> do parent deste
  * conector.
  *
  * @return Um ponto indicando a localização. Caso o conector não possua parent, retorna <code>null
  *     </code>.
  */
 public Point getLocationOnParentContainer() {
   Container c = getParent();
   if (c == null) {
     return null;
   }
   return new Point(c.getX() + getX(), c.getY() + getY());
 }
Example #5
0
 /** Calculates the absolute location of the board frame in his outmost parent frame. */
 java.awt.Point absolute_panel_location() {
   int x = this.scroll_pane.getX();
   int y = this.scroll_pane.getY();
   java.awt.Container curr_parent = this.scroll_pane.getParent();
   while (curr_parent != null) {
     x += curr_parent.getX();
     y += curr_parent.getY();
     curr_parent = curr_parent.getParent();
   }
   return new java.awt.Point(x, y);
 }
  private void posicionaLabel() {

    int x = lastAcessible.getX() + lastAcessible.getWidth() + 3;
    int y = ((int) (lastAcessible.getHeight() + 16) / 2) + lastAcessible.getY() - 16;
    //        label.setLocation(x, control.getY());
    //        label.setLocation(0,0);
    label.setLabelFor(control);
    label.setBounds(x, y, 16, 16);
    //        ((JTextArea) control).setJComponentZOrder(label, 1);
    //            label.setLocation(Integer.parseInt(JOptionPane.showInputDialog("x")),
    // Integer.parseInt(JOptionPane.showInputDialog("y")));
  }
Example #7
0
 // ------------- maxX() ---------------------
 private int maxX() {
   return (int) (_parent.getX() + _parent.getWidth() - this.getWidth());
 }
Example #8
0
 // ------------- minX() ---------------------
 private int minX() {
   return (int) _parent.getX();
 }
  protected boolean canDirectlyAccessGraphics() {
    // TODO: what about popup windows / tooltips???

    // TODO: some of the queries could be cached instead of polling,
    // for example isShowing(), isOpaque(), getParent() etc.

    //////        // Shouldn't access graphics - no buffering would cause flickering
    //////        if (bufferType == BUFFER_NONE) return false;

    // Cannot access graphics - there are some child components
    if (getComponentCount() != 0) return false;

    // Cannot access graphics - component doesn't fully control its area
    if (!isOpaque()) return false;

    // Cannot access graphics - not in Swing tree
    if (!(getParent() instanceof JComponent)) return false;

    // Cannot access graphics - component not showing, doesn't make sense
    if (!isShowing()) return false;

    // Cannot access graphics - component area is not up-to-date
    Rectangle dirtyRegion =
        RepaintManager.currentManager(this).getDirtyRegion((JComponent) getParent());
    if (dirtyRegion != null && dirtyRegion.width > 0 && dirtyRegion.height > 0) return false;

    // --- Reused from JViewport -------------------------------------------

    Rectangle clip = new Rectangle(0, 0, getWidth(), getHeight());
    Rectangle oldClip = new Rectangle();
    Rectangle tmp2 = null;
    Container parent;
    Component lastParent = null;
    int x, y, w, h;

    for (parent = this;
        parent != null && isLightweightComponent(parent);
        parent = parent.getParent()) {
      x = parent.getX();
      y = parent.getY();
      w = parent.getWidth();
      h = parent.getHeight();

      oldClip.setBounds(clip);
      SwingUtilities.computeIntersection(0, 0, w, h, clip);
      if (!clip.equals(oldClip)) return false;

      if (lastParent != null
          && parent instanceof JComponent
          && !((JComponent) parent).isOptimizedDrawingEnabled()) {
        Component comps[] = parent.getComponents();
        int index = 0;

        for (int i = comps.length - 1; i >= 0; i--) {
          if (comps[i] == lastParent) {
            index = i - 1;
            break;
          }
        }

        while (index >= 0) {
          tmp2 = comps[index].getBounds(tmp2);
          if (tmp2.intersects(clip)) return false;
          index--;
        }
      }
      clip.x += x;
      clip.y += y;
      lastParent = parent;
    }

    // No Window parent.
    if (parent == null) return false;

    return true;
  }