use of org.apache.pivot.wtk.Border in project pivot by apache.
the class BorderSkin method getBaseline.
@Override
public int getBaseline(int width, int height) {
int baseline = -1;
Border border = (Border) getComponent();
// Delegate baseline calculation to the content component
Component content = border.getContent();
if (content != null) {
int clientWidth = Math.max(width - paddingThicknessWidth(), 0);
int clientHeight = Math.max(height - paddingThicknessHeight(), 0);
baseline = content.getBaseline(clientWidth, clientHeight);
}
// Include top padding value and top border thickness
if (baseline != -1) {
baseline += (padding.top + topThickness);
}
return baseline;
}
use of org.apache.pivot.wtk.Border in project pivot by apache.
the class BorderSkin method install.
@Override
public void install(Component component) {
super.install(component);
Border border = (Border) component;
border.getBorderListeners().add(this);
}
use of org.apache.pivot.wtk.Border in project pivot by apache.
the class BorderSkin method layout.
@Override
public void layout() {
int width = getWidth();
int height = getHeight();
Border border = (Border) getComponent();
Component content = border.getContent();
if (content != null) {
content.setLocation(padding.left + thickness, padding.top + topThickness);
int contentWidth = Math.max(width - paddingThicknessWidth(), 0);
int contentHeight = Math.max(height - paddingThicknessHeight(), 0);
content.setSize(contentWidth, contentHeight);
}
}
use of org.apache.pivot.wtk.Border in project pivot by apache.
the class BorderSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
int preferredWidth = 0;
int preferredHeight = 0;
Border border = (Border) getComponent();
String title = border.getTitle();
if (title != null && title.length() > 0) {
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
Rectangle2D headingBounds = font.getStringBounds(title, fontRenderContext);
preferredWidth = (int) Math.ceil(headingBounds.getWidth());
}
Component content = border.getContent();
if (content != null) {
Dimensions preferredSize = content.getPreferredSize();
preferredWidth = Math.max(preferredWidth, preferredSize.width);
preferredHeight += preferredSize.height;
}
preferredWidth += paddingThicknessWidth();
preferredHeight += paddingThicknessHeight();
return new Dimensions(preferredWidth, preferredHeight);
}
use of org.apache.pivot.wtk.Border in project pivot by apache.
the class BorderSkin method paint.
@Override
public void paint(Graphics2D graphics) {
Border border = (Border) getComponent();
String title = border.getTitle();
// TODO Java2D doesn't support variable corner radii; we'll need to
// "fake" this by drawing multiple arcs
int cornerRadius = cornerRadii.topLeft;
int width = getWidth();
int height = getHeight();
int strokeX = thickness / 2;
int strokeY = topThickness / 2;
int strokeWidth = Math.max(width - thickness, 0);
int strokeHeight = Math.max(height - (int) Math.ceil((topThickness + thickness) * 0.5), 0);
// Draw the background
Paint backgroundPaint = getBackgroundPaint();
if (backgroundPaint != null) {
graphics.setPaint(backgroundPaint);
if (cornerRadius > 0) {
GraphicsUtilities.setAntialiasingOn(graphics);
graphics.fillRoundRect(strokeX, strokeY, strokeWidth, strokeHeight, cornerRadius, cornerRadius);
GraphicsUtilities.setAntialiasingOff(graphics);
} else {
graphics.fillRect(strokeX, strokeY, strokeWidth, strokeHeight);
}
}
// Draw the title
if (title != null) {
FontRenderContext fontRenderContext = GraphicsUtilities.prepareForText(graphics, font, titleColor);
// Note that we add one pixel to the string bounds for spacing
Rectangle2D titleBounds = font.getStringBounds(title, fontRenderContext);
titleBounds = new Rectangle2D.Double(padding.left + thickness, (topThickness - titleBounds.getHeight()) / 2, titleBounds.getWidth() + 1, titleBounds.getHeight());
graphics.drawString(title, (int) titleBounds.getX(), (int) (titleBounds.getY() + titleAscent));
Area titleClip = new Area(graphics.getClip());
titleClip.subtract(new Area(titleBounds));
graphics.clip(titleClip);
}
// Draw the border
if (thickness > 0 && !themeIsFlat()) {
graphics.setPaint(color);
if (cornerRadius > 0) {
GraphicsUtilities.setAntialiasingOn(graphics);
graphics.setStroke(new BasicStroke(thickness));
graphics.draw(new RoundRectangle2D.Double(0.5 * thickness, 0.5 * topThickness, strokeWidth, strokeHeight, cornerRadius, cornerRadius));
GraphicsUtilities.setAntialiasingOff(graphics);
} else {
int y = (topThickness - thickness) / 2;
GraphicsUtilities.drawRect(graphics, 0, y, width, Math.max(height - y, 0), thickness);
}
}
}
Aggregations