当前位置: 首页>>代码示例>>Java>>正文


Java Shape.getBounds方法代码示例

本文整理汇总了Java中java.awt.Shape.getBounds方法的典型用法代码示例。如果您正苦于以下问题:Java Shape.getBounds方法的具体用法?Java Shape.getBounds怎么用?Java Shape.getBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Shape的用法示例。


在下文中一共展示了Shape.getBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transformShape

import java.awt.Shape; //导入方法依赖的package包/类
protected static Shape transformShape(int tx, int ty, Shape s) {
    if (s == null) {
        return null;
    }

    if (s instanceof Rectangle) {
        Rectangle r = s.getBounds();
        r.translate(tx, ty);
        return r;
    }
    if (s instanceof Rectangle2D) {
        Rectangle2D rect = (Rectangle2D) s;
        return new Rectangle2D.Double(rect.getX() + tx,
                                      rect.getY() + ty,
                                      rect.getWidth(),
                                      rect.getHeight());
    }

    if (tx == 0 && ty == 0) {
        return cloneShape(s);
    }

    AffineTransform mat = AffineTransform.getTranslateInstance(tx, ty);
    return mat.createTransformedShape(s);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:SunGraphics2D.java

示例2: getPreferredSpan

import java.awt.Shape; //导入方法依赖的package包/类
public float getPreferredSpan(int axis) {
        switch (axis) {
            case Y_AXIS:
                return getEditorUI().getLineHeight();
            case X_AXIS:
//                try {
                    int offset = Math.max(0, getEndOffset() - 1);
                    Shape retShape = modelToView(offset, new Rectangle(), Position.Bias.Forward, false);
                    int ret = retShape.getBounds().x + retShape.getBounds().width;
                    return Math.max(ret, 1f);
//                } catch (BadLocationException ble) {
//                    LOG.log(Level.INFO, "Can't determine x-axis span", ble); //NOI18N
//                }
        }
        
        return 1f;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:DrawEngineLineView.java

示例3: draw

import java.awt.Shape; //导入方法依赖的package包/类
private static void draw(Shape clip, Shape to, Image vi, BufferedImage bi,
                         int scale) {
    Graphics2D big = bi.createGraphics();
    big.setComposite(AlphaComposite.Src);
    big.setClip(clip);
    Rectangle toBounds = to.getBounds();
    int x1 = toBounds.x;

    int y1 = toBounds.y;
    int x2 = x1 + toBounds.width;
    int y2 = y1 + toBounds.height;
    big.drawImage(vi, x1, y1, x2, y2, 0, 0, toBounds.width / scale,
                  toBounds.height / scale, null);
    big.dispose();
    vi.flush();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:IncorrectClipSurface2SW.java

示例4: paint

import java.awt.Shape; //导入方法依赖的package包/类
/** This method is called by Swing to draw highlights. */
public void paint(Graphics gr, int start, int end, Shape shape, JTextComponent text) {
	Color old = gr.getColor();
	gr.setColor(color);
	try {
		Rectangle box = shape.getBounds(), a = text.getUI().modelToView(text, start),
				b = text.getUI().modelToView(text, end);
		if (a.y == b.y) {
			// same line (Note: furthermore, if start==end, then we draw all
			// the way to the right edge)
			Rectangle r = a.union(b);
			gr.fillRect(r.x, r.y, (r.width <= 1 ? (box.x + box.width - r.x) : r.width), r.height);
		} else {
			// Multiple lines; (Note: on first line we'll draw from "start"
			// and extend to rightmost)
			gr.fillRect(a.x, a.y, box.x + box.width - a.x, a.height);
			if (a.y + a.height < b.y)
				gr.fillRect(box.x, a.y + a.height, box.width, b.y - (a.y + a.height));
			gr.fillRect(box.x, b.y, b.x - box.x, b.height);
		}
	} catch (BadLocationException e) {} // Failure to highlight is not fatal
	gr.setColor(old);
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:24,代码来源:OurHighlighter.java

示例5: draw

import java.awt.Shape; //导入方法依赖的package包/类
private static void draw(Shape clip, Shape shape, Image from, Image to) {
    Graphics2D g2d = (Graphics2D) to.getGraphics();
    g2d.setXORMode(Color.BLACK);
    g2d.setClip(clip);
    Rectangle toBounds = shape.getBounds();
    g2d.drawImage(from, toBounds.x, toBounds.y, toBounds.width,
                  toBounds.height, null);
    g2d.dispose();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:IncorrectClipXorModeSurface2Surface.java

示例6: getIcon

import java.awt.Shape; //导入方法依赖的package包/类
/**
 * Returns an icon.
 *
 * @param shape  the shape.
 * @param fillPaint  the fill paint.
 * @param outlinePaint  the outline paint.
 *
 * @return The icon.
 */
private Icon getIcon(Shape shape, final Paint fillPaint, 
                    final Paint outlinePaint) {

  final int width = shape.getBounds().width;
  final int height = shape.getBounds().height;
  final GeneralPath path = new GeneralPath(shape);
  return new Icon() {
      public void paintIcon(Component c, Graphics g, int x, int y) {
          Graphics2D g2 = (Graphics2D) g;
          path.transform(AffineTransform.getTranslateInstance(x, y));
          if (fillPaint != null) {
              g2.setPaint(fillPaint);
              g2.fill(path);
          }
          if (outlinePaint != null) {
              g2.setPaint(outlinePaint);
              g2.draw(path);
          }
          path.transform(AffineTransform.getTranslateInstance(-x, -y));
    }

    public int getIconWidth() {
        return width;
    }

    public int getIconHeight() {
        return height;
    }

  };
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:41,代码来源:MinMaxCategoryRenderer.java

示例7: paint

import java.awt.Shape; //导入方法依赖的package包/类
/**
       * Renders the view.
       *
       * @param g the graphics context
       * @param allocation the region to render into
       */
      public void paint(Graphics g, Shape allocation) {
          if (view != null) {
              Rectangle alloc = (allocation instanceof Rectangle) ?
          (Rectangle)allocation : allocation.getBounds();
setSize(alloc.width, alloc.height);
              view.paint(g, allocation);
          }
      }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:CollapsedView.java

示例8: reallocate

import java.awt.Shape; //导入方法依赖的package包/类
/**
 * Reallocate the view to the new size given by the passed shape.
 *
 * @param a shape to which to reallocate the view.
 * @return rectangle bounding the shape. The returned rectangle
 *  can be mutated.
 */
protected Rectangle reallocate(Shape a) {
    Rectangle alloc = a.getBounds(); // makes a fresh rectangle instance
    
    setSize(alloc.width, alloc.height); // set new size
    
    return alloc;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:GapBoxView.java

示例9: fallBackModelToY

import java.awt.Shape; //导入方法依赖的package包/类
private double fallBackModelToY(int offset) {
    Shape s;
    try {
        s = textComponent.modelToView(offset);
    } catch (BadLocationException ex) {
        Exceptions.printStackTrace(ex);
        s = null;
    }

    if (s != null) {
        return s.getBounds().y;
    } else {
        return 0d;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:ViewHierarchyImpl.java

示例10: draw

import java.awt.Shape; //导入方法依赖的package包/类
public void draw(GamePiece p, Graphics g, int x, int y,
                 Component obs, double zoom) {
  if (thickness > 0) {
    if (c != null) {
      // Find the border by outsetting the bounding box, and then scaling
      // the shape to fill the outset.
      final Shape s = p.getShape();
      final Rectangle br = s.getBounds();

      // Don't bother if the shape is empty.
      if (!br.isEmpty()) {
        final double xzoom = (br.getWidth()+1) / br.getWidth();
        final double yzoom = (br.getHeight()+1) / br.getHeight();
        final AffineTransform t = AffineTransform.getTranslateInstance(x,y);
        t.scale(xzoom*zoom, yzoom*zoom);

        final Graphics2D g2d = (Graphics2D) g;
        final Stroke str = g2d.getStroke();
        g2d.setStroke(
          new BasicStroke(Math.max(1, Math.round(zoom*thickness))));
        g2d.setColor(c);
        g2d.draw(t.createTransformedShape(s));
        g2d.setStroke(str);
      }
    }
    else {
      highlightSelectionBounds(p, g, x, y, obs, zoom);
    }
  }

  // Draw any additional highlighters
  for (Highlighter h : highlighters) {
    h.draw(p, g, x, y, obs, zoom);
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:36,代码来源:ColoredBorder.java

示例11: getChildViewBounds

import java.awt.Shape; //导入方法依赖的package包/类
/**
 * Returns the bounds of a child view as a rectangle, since
 * <code>View</code>s tend to use <code>Shape</code>.
 *
 * @param parent The parent view of the child whose bounds we're getting.
 * @param line The index of the child view.
 * @param editorRect Returned from the text area's
 *        <code>getVisibleEditorRect</code> method.
 * @return The child view's bounds.
 */
protected static final Rectangle getChildViewBounds(View parent, int line,
									Rectangle editorRect) {
	Shape alloc = parent.getChildAllocation(line, editorRect);
	if (alloc==null) {
		// WrappedSyntaxView can have this when made so small it's
		// no longer visible
		return new Rectangle();
	}
	return alloc instanceof Rectangle ? (Rectangle)alloc :
									alloc.getBounds();
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:22,代码来源:AbstractGutterComponent.java

示例12: getIcon

import java.awt.Shape; //导入方法依赖的package包/类
/**
 * Returns an icon.
 *
 * @param shape  the shape.
 * @param fillPaint  the fill paint.
 * @param outlinePaint  the outline paint.
 *
 * @return the icon.
 */
private Icon getIcon(Shape shape, final Paint fillPaint, final Paint outlinePaint) {

  final int width = shape.getBounds().width;
  final int height = shape.getBounds().height;
  final GeneralPath path = new GeneralPath(shape);
  return new Icon() {
      public void paintIcon(Component c, Graphics g, int x, int y) {
          Graphics2D g2 = (Graphics2D) g;
          path.transform(AffineTransform.getTranslateInstance(x, y));
          if (fillPaint != null) {
              g2.setPaint(fillPaint);
              g2.fill(path);
          }
          if (outlinePaint != null) {
              g2.setPaint(outlinePaint);
              g2.draw(path);
          }
          path.transform(AffineTransform.getTranslateInstance(-x, -y));
    }

    public int getIconWidth() {
        return width;
    }

    public int getIconHeight() {
        return height;
    }

  };
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:40,代码来源:MinMaxCategoryRenderer.java

示例13: modelToView

import java.awt.Shape; //导入方法依赖的package包/类
@Override
public Shape modelToView(int pos, Shape a, Position.Bias b)
		throws BadLocationException {

	if (! isAllocationValid()) {
		Rectangle alloc = a.getBounds();
		setSize(alloc.width, alloc.height);
	}

	boolean isBackward = (b == Position.Bias.Backward);
	int testPos = (isBackward) ? Math.max(0, pos - 1) : pos;
	if(isBackward && testPos < getStartOffset()) {
		return null;
	}

	int vIndex = getViewIndexAtPosition(testPos);
	if ((vIndex != -1) && (vIndex < getViewCount())) {
		View v = getView(vIndex);
		if(v != null && testPos >= v.getStartOffset() &&
				testPos < v.getEndOffset()) {
			Shape childShape = getChildAllocation(vIndex, a);
			if (childShape == null) {
				// We are likely invalid, fail.
				return null;
			}
			Shape retShape = v.modelToView(pos, childShape, b);
			if(retShape == null && v.getEndOffset() == pos) {
				if(++vIndex < getViewCount()) {
					v = getView(vIndex);
					retShape = v.modelToView(pos, getChildAllocation(vIndex, a), b);
				}
			}
			return retShape;
		}
	}

	throw new BadLocationException("Position not represented by view", pos);

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:40,代码来源:WrappedSyntaxView.java

示例14: paint

import java.awt.Shape; //导入方法依赖的package包/类
/**
 * Paints a highlight.
 *
 * @param g the graphics context
 * @param offs0 the starting model offset >= 0
 * @param offs1 the ending model offset >= offs1
 * @param bounds the bounding box for the highlight
 * @param c the editor
 */
public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) {
    Rectangle alloc = bounds.getBounds();
    try {
        // --- determine locations ---
        TextUI mapper = c.getUI();
        Rectangle p0 = mapper.modelToView(c, offs0);
        Rectangle p1 = mapper.modelToView(c, offs1);

        // --- render ---
        Color color = getColor();

        if (color == null) {
            g.setColor(c.getSelectionColor());
        }
        else {
            g.setColor(color);
        }
        boolean firstIsDot = false;
        boolean secondIsDot = false;
        if (c.isEditable()) {
            int dot = c.getCaretPosition();
            firstIsDot = (offs0 == dot);
            secondIsDot = (offs1 == dot);
        }
        if (p0.y == p1.y) {
            // same line, render a rectangle
            Rectangle r = p0.union(p1);
            if (r.width > 0) {
                if (firstIsDot) {
                    r.x++;
                    r.width--;
                }
                else if (secondIsDot) {
                    r.width--;
                }
            }
            g.fillRect(r.x, r.y, r.width, r.height);
        } else {
            // different lines
            int p0ToMarginWidth = alloc.x + alloc.width - p0.x;
            if (firstIsDot && p0ToMarginWidth > 0) {
                p0.x++;
                p0ToMarginWidth--;
            }
            g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height);
            if ((p0.y + p0.height) != p1.y) {
                g.fillRect(alloc.x, p0.y + p0.height, alloc.width,
                           p1.y - (p0.y + p0.height));
            }
            if (secondIsDot && p1.x > alloc.x) {
                p1.x--;
            }
            g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height);
        }
    } catch (BadLocationException e) {
        // can't render
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:68,代码来源:WindowsTextUI.java

示例15: drawOverEntities

import java.awt.Shape; //导入方法依赖的package包/类
@Override
public void drawOverEntities(Graphics2D g, int s)
{
	float time = Math.max(T(), getLength());
	Shape bound = pos.getBorder(s);
	Rectangle border = bound.getBounds();
	Point2D.Double f = new Point2D.Double(border.getCenterX(), border.getCenterY());
	Paint grad = new RadialGradientPaint(f, s / 3, new float[] {0, .7f, 1}, new Color[]{
			new Color(1, 0, 0, 0), 
			new Color(1, 0, 0, .2f * (1 - time / getLength())), 
			new Color(1, 0, 0, .8f * (1 - time / getLength()))});
	g.setPaint(grad);
	g.fill(bound);
}
 
开发者ID:Chroniaro,项目名称:What-Happened-to-Station-7,代码行数:15,代码来源:TileDamage.java


注:本文中的java.awt.Shape.getBounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。