本文整理汇总了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);
}
示例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;
}
示例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();
}
示例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);
}
示例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();
}
示例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;
}
};
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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);
}
}
示例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();
}
示例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;
}
};
}
示例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);
}
示例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
}
}
示例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);
}