org.netbeans.api.visual.widget.Widget.getBounds()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(157)

本文整理了Java中org.netbeans.api.visual.widget.Widget.getBounds()方法的一些代码示例,展示了Widget.getBounds()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Widget.getBounds()方法的具体详情如下:
包路径:org.netbeans.api.visual.widget.Widget
类名称:Widget
方法名:getBounds

Widget.getBounds介绍

[英]Returns the resolved bounds of the widget. The bounds are specified relatively to the location of the widget.

The location is resolved/set by calling resolveBounds method which should be called from Layout interface implementation only. Therefore the corrent value is available only after the scene is validated (SceneListener.sceneValidated method). Before validation a previous/obsolete or null value could be returned. See Layout section in documentation.
[中]返回小部件的已解析边界。边界是相对于小部件的位置指定的。
通过调用resolveBounds方法解析/设置位置,该方法应仅从Layout接口实现调用。因此,只有在验证场景后,相应的值才可用(SceneListener.sceneValidated方法)。在验证之前,可以返回以前的/过时的或null值。请参阅文档中的布局部分。

代码示例

代码示例来源:origin: in.jlibs/org-netbeans-api-visual

private void checkViewLocationInBounds (Point location, Widget v, int dx, int dy) {
  Rectangle view = v.getBounds ();
  Rectangle viewport = ScrollWidget.this.viewport.getBounds ();
  if (dx < 0 && location.x > view.x)
    location.x = view.x;
  if (dy < 0 && location.y > view.y)
    location.y = view.y;
  if (dx > 0 && location.x + view.width < viewport.x + viewport.width)
    location.x = viewport.x + viewport.width - view.width;
  if (dy > 0 && location.y + view.height < viewport.y + viewport.height)
    location.y = viewport.y + viewport.height - view.height;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

private void checkViewLocationInBounds (Point location, Widget v, int dx, int dy) {
  Rectangle view = v.getBounds ();
  Rectangle viewport = ScrollWidget.this.viewport.getBounds ();
  if (dx < 0 && location.x > view.x)
    location.x = view.x;
  if (dy < 0 && location.y > view.y)
    location.y = view.y;
  if (dx > 0 && location.x + view.width < viewport.x + viewport.width)
    location.x = viewport.x + viewport.width - view.width;
  if (dy > 0 && location.y + view.height < viewport.y + viewport.height)
    location.y = viewport.y + viewport.height - view.height;
}

代码示例来源:origin: net.sourceforge.javydreamercsw/Client-UI

private int getChildX(Widget parent, Widget child) {
  //Get parent location
  int x;
  Rectangle bounds = parent.getBounds();
  if (bounds != null && child instanceof RequirementHierarchyNode) {
    x = 0;
  } else if (bounds != null && child instanceof StepHierarchyNode) {
    x = (bounds.x + bounds.width + horizontalGap) * 3;
  } else {
    x = 0;
  }
  return x;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

/**
 * Called to whether a particular location in local coordination system is controlled (otionally also painted) by the widget.
 * @param localLocation the local location
 * @return true, if the location belong to the widget
 */
public boolean isHitAt (Point localLocation) {
  return visible  &&  getBounds ().contains (localLocation);
}

代码示例来源:origin: in.jlibs/org-netbeans-api-visual

/**
 * Called to whether a particular location in local coordination system is controlled (otionally also painted) by the widget.
 * @param localLocation the local location
 * @return true, if the location belong to the widget
 */
public boolean isHitAt (Point localLocation) {
  return visible  &&  getBounds ().contains (localLocation);
}

代码示例来源:origin: net.sourceforge.javydreamercsw/Client-UI

private int getChildY(Widget parent, Widget child) {
  //Get parent location
  Rectangle bounds = parent.getBounds();
  return bounds == null ? 0 : (verticalGap
      + (child.getBounds() == null ? bounds.height
      : child.getBounds().height))
      * (mainLayer.getChildren().size() - 1);
}

代码示例来源:origin: in.jlibs/org-netbeans-api-visual

/**
 * Returns a client area of the widget.
 * @return the client area
 */
public final Rectangle getClientArea () {
  Rectangle bounds = getBounds ();
  if (bounds == null)
    return null;
  Insets insets = getBorder ().getInsets ();
  return new Rectangle (bounds.x + insets.left, bounds.y + insets.top, bounds.width - insets.left - insets.right, bounds.height - insets.top - insets.bottom);
}

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

final void revalidateWidget (Widget widget) {
  Rectangle widgetBounds = widget.getBounds ();
  if (widgetBounds != null) {
    Rectangle sceneBounds = widget.convertLocalToScene (widgetBounds);
    if (repaintRegion == null)
      repaintRegion = sceneBounds;
    else
      repaintRegion.add (sceneBounds);
  }
  repaintWidgets.add (widget);
}

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

/**
 * Returns a client area of the widget.
 * @return the client area
 */
public final Rectangle getClientArea () {
  Rectangle bounds = getBounds ();
  if (bounds == null)
    return null;
  Insets insets = getBorder ().getInsets ();
  return new Rectangle (bounds.x + insets.left, bounds.y + insets.top, bounds.width - insets.left - insets.right, bounds.height - insets.top - insets.bottom);
}

代码示例来源:origin: in.jlibs/org-netbeans-api-visual

final void revalidateWidget (Widget widget) {
  Rectangle widgetBounds = widget.getBounds ();
  if (widgetBounds != null) {
    Rectangle sceneBounds = widget.convertLocalToScene (widgetBounds);
    if (repaintRegion == null)
      repaintRegion = sceneBounds;
    else
      repaintRegion.add (sceneBounds);
  }
  repaintWidgets.add (widget);
}

代码示例来源:origin: in.jlibs/org-netbeans-api-visual

public java.util.List<Rectangle> getRegions (Widget movingWidget) {
  java.util.List<Widget> children = collectionLayer.getChildren ();
  ArrayList<Rectangle> regions = new ArrayList<Rectangle> (children.size ());
  for (Widget widget : children)
    if (widget != movingWidget)
      regions.add (widget.convertLocalToScene (outerBounds ? widget.getBounds () : widget.getClientArea ()));
  return regions;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

public java.util.List<Rectangle> getRegions (Widget movingWidget) {
  java.util.List<Widget> children = collectionLayer.getChildren ();
  ArrayList<Rectangle> regions = new ArrayList<Rectangle> (children.size ());
  for (Widget widget : children)
    if (widget != movingWidget)
      regions.add (widget.convertLocalToScene (outerBounds ? widget.getBounds () : widget.getClientArea ()));
  return regions;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

/**
 * Returns a scene location of a related widget.
 * @return the scene location; null if no related widget is assigned
 */
public Point getRelatedSceneLocation () {
  if (relatedWidget != null) {
    Rectangle bounds = relatedWidget.getBounds ();
    if (bounds == null)
      throw new IllegalStateException ("Widget (" + relatedWidget + ") was not added into the scene");
    return GeomUtil.center (relatedWidget.convertLocalToScene (bounds));
  }
  assert false : "Anchor.getRelatedSceneLocation has to be overridden when a related widget is not used";
  return null;
}

代码示例来源:origin: in.jlibs/org-netbeans-api-visual

/**
 * Returns a scene location of a related widget.
 * @return the scene location; null if no related widget is assigned
 */
public Point getRelatedSceneLocation () {
  if (relatedWidget != null) {
    Rectangle bounds = relatedWidget.getBounds ();
    if (bounds == null)
      throw new IllegalStateException ("Widget (" + relatedWidget + ") was not added into the scene");
    return GeomUtil.center (relatedWidget.convertLocalToScene (bounds));
  }
  assert false : "Anchor.getRelatedSceneLocation has to be overridden when a related widget is not used";
  return null;
}

代码示例来源:origin: in.jlibs/org-netbeans-api-visual

private Dimension calculateSize () {
  if (isPreferredBoundsSet ()) {
    Rectangle preferredBounds = getPreferredBounds ();
    Insets insets = getBorder ().getInsets ();
    return new Dimension (preferredBounds.width - insets.left - insets.right, preferredBounds.height - insets.top - insets.bottom);
  } else
    return view.getBounds ().getSize ();
}

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

private Dimension calculateSize () {
  if (isPreferredBoundsSet ()) {
    Rectangle preferredBounds = getPreferredBounds ();
    Insets insets = getBorder ().getInsets ();
    return new Dimension (preferredBounds.width - insets.left - insets.right, preferredBounds.height - insets.top - insets.bottom);
  } else
    return view.getBounds ().getSize ();
}

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

/**
 * Called to paint the children widgets only using the Graphics2D instance acquired from Scene.getGraphics method.
 */
protected void paintChildren () {
  if (checkClipping) {
    Rectangle clipBounds = scene.getGraphics ().getClipBounds ();
    for (Widget child : children) {
      Point location = child.getLocation ();
      Rectangle bounds = child.getBounds ();
      bounds.translate (location.x, location.y);
      if (clipBounds == null  ||  bounds.intersects (clipBounds))
        child.paint ();
    }
  } else
    for (Widget child : children)
      child.paint ();
}

代码示例来源:origin: in.jlibs/org-netbeans-api-visual

public void justify (Widget widget) {
  assert widget == cardLayoutWidget;
  if (activeChildWidget != null  &&  activeChildWidget.isVisible ())
    for (Widget child : cardLayoutWidget.getChildren ())
      if (child == activeChildWidget) {
        Rectangle bounds = widget.getClientArea ();
        Point location = child.getLocation ();
        Rectangle childBounds = child.getBounds ();
        bounds.translate (- location.x, - location.y);
        childBounds.add (bounds);
        child.resolveBounds (location, bounds);
        return;
      }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

public void justify (Widget widget) {
  assert widget == cardLayoutWidget;
  if (activeChildWidget != null  &&  activeChildWidget.isVisible ())
    for (Widget child : cardLayoutWidget.getChildren ())
      if (child == activeChildWidget) {
        Rectangle bounds = widget.getClientArea ();
        Point location = child.getLocation ();
        Rectangle childBounds = child.getBounds ();
        bounds.translate (- location.x, - location.y);
        childBounds.add (bounds);
        child.resolveBounds (location, bounds);
        return;
      }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

public void keyPressed (KeyEvent e) {
  // HACK for invoking tooltip using Ctrl+F1 because a condition in ToolTipManager.shouldRegisterBindings cannot be satisfied
  if (e.getKeyCode () == KeyEvent.VK_F1  && (e.getModifiers () & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) {
    MouseContext context = new MouseContext ();
    resolveContext (scene.getFocusedWidget (), context);
    context.commit (this);
    Widget focusedWidget = scene.getFocusedWidget ();
    Point location = focusedWidget.getScene ().convertSceneToView (focusedWidget.convertLocalToScene (focusedWidget.getBounds ().getLocation ()));
    MouseEvent event = new MouseEvent (this, 0, 0, 0, location.x, location.y, 0, false);
    ToolTipManager manager = ToolTipManager.sharedInstance ();
    manager.mouseEntered (event);
    manager.mouseMoved (event);
  }
  WidgetAction.State state = processKeyOperator (Operator.KEY_PRESSED, new WidgetAction.WidgetKeyEvent (++ eventIDcounter, e));
  if (state.isConsumed ())
    e.consume ();
}

相关文章