use of org.apache.pivot.wtk.MenuButton in project pivot by apache.
the class TerraMenuButtonSkin method getPreferredHeight.
@Override
public int getPreferredHeight(int width) {
int preferredHeight = 0;
if (width == -1) {
preferredHeight = getPreferredSize().height;
} else {
MenuButton menuButton = (MenuButton) getComponent();
Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
dataRenderer.render(menuButton.getButtonData(), menuButton, false);
preferredHeight = dataRenderer.getPreferredHeight(-1) + padding.top + padding.bottom + 2;
// Adjust for preferred aspect ratio
if (!Float.isNaN(maximumAspectRatio) && (float) width / (float) preferredHeight > maximumAspectRatio) {
preferredHeight = (int) (width / maximumAspectRatio);
}
}
return preferredHeight;
}
use of org.apache.pivot.wtk.MenuButton in project pivot by apache.
the class TerraMenuButtonSkin method paint.
@Override
public void paint(Graphics2D graphics) {
MenuButton menuButton = (MenuButton) getComponent();
int width = getWidth();
int height = getHeight();
Color colorLocal = null;
Color backgroundColorLocal = null;
Color bevelColorLocal = null;
Color borderColorLocal = null;
if (!toolbar || highlighted || menuButton.isFocused() || menuPopup.isOpen()) {
if (menuButton.isEnabled()) {
colorLocal = this.color;
backgroundColorLocal = this.backgroundColor;
bevelColorLocal = (pressed || (menuPopup.isOpen() && !menuPopup.isClosing())) ? pressedBevelColor : this.bevelColor;
borderColorLocal = this.borderColor;
} else {
colorLocal = disabledColor;
backgroundColorLocal = disabledBackgroundColor;
bevelColorLocal = disabledBevelColor;
borderColorLocal = disabledBorderColor;
}
}
// Paint the background
if (backgroundColorLocal != null && bevelColorLocal != null) {
GraphicsUtilities.setAntialiasingOn(graphics);
if (!themeIsFlat()) {
graphics.setPaint(new GradientPaint(width / 2f, 0, bevelColorLocal, width / 2f, height / 2f, backgroundColorLocal));
} else {
graphics.setPaint(backgroundColorLocal);
}
graphics.fill(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
}
// Paint the content
GraphicsUtilities.setAntialiasingOff(graphics);
Bounds contentBounds = new Bounds(padding.left + 1, padding.top + 1, Math.max(width - (padding.getWidth() + spacing + TRIGGER_WIDTH + 2), 0), Math.max(height - (padding.getHeight() + 2), 0));
Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
dataRenderer.render(menuButton.getButtonData(), menuButton, highlighted);
dataRenderer.setSize(contentBounds.getSize());
Graphics2D contentGraphics = (Graphics2D) graphics.create();
contentGraphics.translate(contentBounds.x, contentBounds.y);
contentGraphics.clipRect(0, 0, contentBounds.width, contentBounds.height);
dataRenderer.paint(contentGraphics);
contentGraphics.dispose();
GraphicsUtilities.setAntialiasingOn(graphics);
// Paint the border
if (borderColorLocal != null && !themeIsFlat()) {
graphics.setPaint(borderColorLocal);
graphics.setStroke(new BasicStroke(1));
graphics.draw(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
}
// Paint the focus state
if (menuButton.isFocused() && !toolbar) {
BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 0.0f, 2.0f }, 0.0f);
graphics.setStroke(dashStroke);
graphics.setColor(this.borderColor);
graphics.draw(new RoundRectangle2D.Double(2.5, 2.5, Math.max(width - 5, 0), Math.max(height - 5, 0), CORNER_RADIUS / 2, CORNER_RADIUS / 2));
}
GraphicsUtilities.setAntialiasingOff(graphics);
// Paint the trigger
GeneralPath triggerIconShape = new GeneralPath(Path2D.WIND_EVEN_ODD);
triggerIconShape.moveTo(0, 0);
triggerIconShape.lineTo(3, 3);
triggerIconShape.lineTo(6, 0);
triggerIconShape.closePath();
Graphics2D triggerGraphics = (Graphics2D) graphics.create();
triggerGraphics.setStroke(new BasicStroke(0));
triggerGraphics.setPaint(colorLocal);
Bounds triggerBounds = new Bounds(Math.max(width - (padding.right + TRIGGER_WIDTH), 0), 0, // TODO: this calculation doesn't look right \\// (should be + not -?)
TRIGGER_WIDTH, Math.max(height - (padding.top - padding.bottom), 0));
int tx = triggerBounds.x + (triggerBounds.width - triggerIconShape.getBounds().width) / 2;
int ty = triggerBounds.y + (triggerBounds.height - triggerIconShape.getBounds().height) / 2;
triggerGraphics.translate(tx, ty);
triggerGraphics.draw(triggerIconShape);
triggerGraphics.fill(triggerIconShape);
triggerGraphics.dispose();
}
use of org.apache.pivot.wtk.MenuButton in project pivot by apache.
the class TerraMenuButtonSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
int preferredWidth = 0;
if (height == -1) {
preferredWidth = getPreferredSize().width;
} else {
MenuButton menuButton = (MenuButton) getComponent();
Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
dataRenderer.render(menuButton.getButtonData(), menuButton, false);
preferredWidth = dataRenderer.getPreferredWidth(-1) + TRIGGER_WIDTH + padding.left + padding.right + spacing + 2;
// Adjust for preferred aspect ratio
if (!Float.isNaN(minumumAspectRatio) && (float) preferredWidth / (float) height < minumumAspectRatio) {
preferredWidth = (int) (height * minumumAspectRatio);
}
}
return preferredWidth;
}
use of org.apache.pivot.wtk.MenuButton in project pivot by apache.
the class TerraMenuButtonSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
MenuButton menuButton = (MenuButton) getComponent();
Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
dataRenderer.render(menuButton.getButtonData(), menuButton, false);
Dimensions contentSize = dataRenderer.getPreferredSize();
int preferredWidth = contentSize.width + TRIGGER_WIDTH + padding.left + padding.right + 2;
int preferredHeight = contentSize.height + padding.top + padding.bottom + 2;
// Adjust for preferred aspect ratio
float aspectRatio = (float) preferredWidth / (float) preferredHeight;
if (!Float.isNaN(minumumAspectRatio) && aspectRatio < minumumAspectRatio) {
preferredWidth = (int) (preferredHeight * minumumAspectRatio);
}
if (!Float.isNaN(maximumAspectRatio) && aspectRatio > maximumAspectRatio) {
preferredHeight = (int) (preferredWidth / maximumAspectRatio);
}
return new Dimensions(preferredWidth, preferredHeight);
}
Aggregations