use of org.apache.pivot.wtk.PushButton in project pivot by apache.
the class TerraPromptSkin method optionInserted.
@Override
public void optionInserted(Prompt prompt, int index) {
Object option = prompt.getOptions().get(index);
PushButton optionButton = new PushButton(option);
optionButton.setStyleName(BUTTON_STYLE_NAME);
optionButton.getButtonPressListeners().add(optionButtonPressListener);
optionButtonBoxPane.insert(optionButton, index);
}
use of org.apache.pivot.wtk.PushButton in project pivot by apache.
the class TerraPushButtonSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
int preferredWidth = 0;
if (height == -1) {
preferredWidth = getPreferredSize().width;
} else {
PushButton pushButton = (PushButton) getComponent();
Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
dataRenderer.render(pushButton.getButtonData(), pushButton, false);
// Include padding in constraint
int contentHeight = height;
if (contentHeight != -1) {
contentHeight = Math.max(contentHeight - paddingHeight(), 0);
}
preferredWidth = dataRenderer.getPreferredWidth(contentHeight) + paddingWidth();
// Adjust for preferred aspect ratio
if (!Float.isNaN(minimumAspectRatio) && (float) preferredWidth / (float) height < minimumAspectRatio) {
preferredWidth = (int) (height * minimumAspectRatio);
}
}
return preferredWidth;
}
use of org.apache.pivot.wtk.PushButton in project pivot by apache.
the class TerraPushButtonSkin method paint.
@Override
public void paint(Graphics2D graphics) {
PushButton pushButton = (PushButton) getComponent();
int width = getWidth();
int height = getHeight();
Color backgroundColorLocal = null;
Color bevelColorLocal = null;
Color borderColorLocal = null;
if (!toolbar || highlighted || pushButton.isFocused()) {
if (pushButton.isEnabled()) {
backgroundColorLocal = this.backgroundColor;
bevelColorLocal = (pressed || pushButton.isSelected()) ? pressedBevelColor : this.bevelColor;
borderColorLocal = this.borderColor;
} else {
backgroundColorLocal = disabledBackgroundColor;
bevelColorLocal = disabledBevelColor;
borderColorLocal = disabledBorderColor;
}
}
// Paint the background
GraphicsUtilities.setAntialiasingOn(graphics);
if (backgroundColorLocal != null && bevelColorLocal != null) {
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);
Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
dataRenderer.render(pushButton.getButtonData(), pushButton, highlighted);
dataRenderer.setSize(Math.max(width - paddingWidth(), 0), Math.max(getHeight() - paddingHeight(), 0));
Graphics2D contentGraphics = (Graphics2D) graphics.create();
contentGraphics.translate(padding.left + 1, padding.top + 1);
contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
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 (pushButton.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));
}
}
use of org.apache.pivot.wtk.PushButton in project pivot by apache.
the class TerraPushButtonSkin method getPreferredHeight.
@Override
public int getPreferredHeight(int width) {
int preferredHeight = 0;
if (width == -1) {
preferredHeight = getPreferredSize().height;
} else {
PushButton pushButton = (PushButton) getComponent();
Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
dataRenderer.render(pushButton.getButtonData(), pushButton, false);
// Include padding in constraint
int contentWidth = width;
if (contentWidth != -1) {
contentWidth = Math.max(contentWidth - paddingWidth(), 0);
}
preferredHeight = dataRenderer.getPreferredHeight(contentWidth) + paddingHeight();
// 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.PushButton in project pivot by apache.
the class TerraAlertSkin method optionInserted.
@Override
public void optionInserted(Alert alert, int index) {
Object option = alert.getOptions().get(index);
PushButton optionButton = new PushButton(option);
optionButton.setStyleName(BUTTON_STYLE_NAME);
optionButton.getButtonPressListeners().add(optionButtonPressListener);
optionButtonBoxPane.insert(optionButton, index);
}
Aggregations