private void initializeFont (Font baseFont, int size, boolean bold, boolean italic) { Map attributes = baseFont.getAttributes(); attributes.put(TextAttribute.SIZE, new Float(size)); attributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR); attributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR); try { attributes.put(TextAttribute.class.getDeclaredField("KERNING").get(null), TextAttribute.class.getDeclaredField("KERNING_ON").get(null)); } catch (Throwable ignored) { } font = baseFont.deriveFont(attributes); metrics = GlyphPage.scratchGraphics.getFontMetrics(font); ascent = metrics.getAscent(); descent = metrics.getDescent(); leading = metrics.getLeading(); // Determine width of space glyph (getGlyphPixelBounds gives a width of zero). char[] chars = " ".toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); spaceWidth = vector.getGlyphLogicalBounds(0).getBounds().width; }
public void testSetBounds() { try { Shape shape = createMock(Shape.class); reset(shape); Rectangle shapeBounds = new Rectangle(8, 7, 9, 3); expect(shape.getBounds()).andReturn(shapeBounds); expect(shape.getBounds2D()).andReturn(shapeBounds); replay(shape); ExplicitBoundsShape target = new ExplicitBoundsShape(shape); assertEquals(shapeBounds, target.getBounds()); assertEquals(shapeBounds, target.getBounds2D()); Rectangle bounds = new Rectangle(1, 2, 5, 6); target.setBounds(bounds); assertEquals(bounds, target.getBounds()); assertEquals(bounds, target.getBounds2D()); verify(shape); } catch (Throwable e) { java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", e); fail("Should not throw " + e.getClass().getSimpleName()); } }
private void initializeFont (Font baseFont, int size, boolean bold, boolean italic) { Map attributes = baseFont.getAttributes(); attributes.put(TextAttribute.SIZE, new Float(size)); attributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR); attributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR); try { attributes.put(TextAttribute.class.getDeclaredField("KERNING").get(null), TextAttribute.class.getDeclaredField("KERNING_ON").get(null)); } catch (Throwable ignored) { } font = baseFont.deriveFont(attributes); metrics = GlyphPage.scratchGraphics.getFontMetrics(font); ascent = metrics.getAscent(); descent = metrics.getDescent(); leading = metrics.getLeading(); // Determine width of space glyph (getGlyphPixelBounds gives a width of zero). char[] chars = " ".toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); spaceWidth = vector.getGlyphLogicalBounds(0).getBounds().width; }
expect(shape.contains(0.0, 0.0)).andReturn(false); expect(shape.contains(0.0, 0.0, 0.0, 0.0)).andReturn(false); expect(shape.getBounds()).andReturn(null); expect(shape.getBounds2D()).andReturn(null); expect(shape.getPathIterator(null)).andReturn(null);
public int getZHeight(Font font){ int height = (int) font.createGlyphVector(fakeRenderContext, "Z").getOutline().getBounds().getHeight(); if(DEBUG) System.out.println("Z height: "+height); return height; }
int getGradientSteps(Shape gradientShape) { Rectangle rect = gradientShape.getBounds(); int lower = 1; int upper = (int)(Math.max(rect.getWidth(),rect.getHeight())/2.0); while (lower < upper-1) { int mid = lower + (upper - lower) / 2; BasicStroke bs = new BasicStroke(mid, capStyle, joinStyle); Area area = new Area(bs.createStrokedShape(gradientShape)); if (area.isSingular()) { upper = mid; } else { lower = mid; } } return upper; }
public Rectangle getClipBounds() { if(getDeviceclip() != null) { final Shape clip = getClip(); return clip != null ? clip.getBounds() : null; } return null; }
AffineTransform.getScaleInstance(1, fontHeightMultiple) ); bounds = layout.getOutline(trans).getBounds(); } else { bounds = layout.getBounds();
@Override public Rectangle getClipBounds() { return clip != null ? clip.getBounds() : null; }
public Rectangle getBounds() { return shape.getBounds(); }
/** * Returns the explicitly defined bounds for this shape. If no bounds were explicitly set, it * delegates the call to the actual shape. * * @return the Rectangle representing the Shape's bounding box. * @see Shape */ public Rectangle getBounds() { if (bounds != null) return new Rectangle( (int) bounds.getMinX(), (int) bounds.getMinY(), (int) bounds.getWidth(), (int) bounds.getHeight()); return shape.getBounds(); }
void union(Shape bounds) { if (bounds == null) { return; } Rectangle alloc = (bounds instanceof Rectangle) ? (Rectangle)bounds : bounds.getBounds(); if (width == 0 || height == 0) { x = alloc.x; y = alloc.y; width = alloc.width; height = alloc.height; } else { width = Math.max(x + width, alloc.x + alloc.width); height = Math.max(y + height, alloc.y + alloc.height); x = Math.min(x, alloc.x); width -= x; y = Math.min(y, alloc.y); height -= y; } }
public class RoundJTextField extends JTextField { private Shape shape; public RoundJTextField(int size) { super(size); setOpaque(false); // As suggested by @AVD in comment. } protected void paintComponent(Graphics g) { g.setColor(getBackground()); g.fillRoundRect(0, 0, getWidth()-1, getHeight()-1, 15, 15); super.paintComponent(g); } protected void paintBorder(Graphics g) { g.setColor(getForeground()); g.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 15, 15); } public boolean contains(int x, int y) { if (shape == null || !shape.getBounds().equals(getBounds())) { shape = new RoundRectangle2D.Float(0, 0, getWidth()-1, getHeight()-1, 15, 15); } return shape.contains(x, y); } }
/** * 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(); }
public Rectangle getGraphicDimensions() { if (graphic instanceof MarkStyle2D) { return ((MarkStyle2D) graphic).getTransformedShape(0f, 0f).getBounds(); } else if (graphic instanceof GraphicStyle2D) { BufferedImage i = ((GraphicStyle2D) graphic).getImage(); return new Rectangle(i.getWidth(), i.getHeight()); } else if (graphic instanceof IconStyle2D) { final Icon icon = ((IconStyle2D) graphic).getIcon(); return new Rectangle(icon.getIconWidth(), icon.getIconWidth()); } else { throw new RuntimeException( "Can't render graphic which is not a MarkStyle2D or a GraphicStyle2D"); } }
/** * Fetches the allocation for the given child view.<p> * Overridden to account for code folding. * * @param index The index of the child, >= 0 &&< getViewCount(). * @param a The allocation to this view * @return The allocation to the child; or <code>null</code> if * <code>a</code> is <code>null</code>; or <code>null</code> if the * layout is invalid */ @Override public Shape getChildAllocation(int index, Shape a) { if (a != null) { Shape ca = getChildAllocationImpl(index, a); if ((ca != null) && (!isAllocationValid())) { // The child allocation may not have been set yet. Rectangle r = (ca instanceof Rectangle) ? (Rectangle) ca : ca .getBounds(); if ((r.width == 0) && (r.height == 0)) { return null; } } return ca; } return null; }
g2d.fill(shape.getBounds());
/** * Determine the rectangle that represents the given line. * * @param a The region allocated for the view to render into * @param line The line number to find the region of. This must * be a valid line number in the model. */ protected Rectangle lineToRect(Shape a, int line) { Rectangle r = null; updateMetrics(); if (metrics != null) { Rectangle alloc = a.getBounds(); // NOTE: lineHeight is not initially set here, leading to the // current line not being highlighted when a document is first // opened. So, we set it here just in case. lineHeight = host!=null ? host.getLineHeight() : lineHeight; if (host != null && host.isCodeFoldingEnabled()) { FoldManager fm = host.getFoldManager(); int hiddenCount = fm.getHiddenLineCountAbove(line); line -= hiddenCount; } r = new Rectangle(alloc.x, alloc.y + line*lineHeight, alloc.width, lineHeight); } return r; }
@Override public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) { int offs = -1; if (! isAllocationValid()) { Rectangle alloc = a.getBounds(); setSize(alloc.width, alloc.height); } // Get the child view for the line at (x,y), and ask it for the // specific offset. Rectangle alloc = getInsideAllocation(a); View v = getViewAtPoint((int) x, (int) y, alloc); if (v != null) { offs = v.viewToModel(x, y, alloc, bias); // Code folding may have hidden the last line. If so, return the last // visible offset instead of the last offset. if (host.isCodeFoldingEnabled() && v == getView(getViewCount() - 1) && offs == v.getEndOffset() - 1) { offs = host.getLastVisibleOffset(); } } return offs; }