use of org.apache.pivot.wtk.Checkbox in project pivot by apache.
the class TerraCheckboxSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
Checkbox checkbox = (Checkbox) getComponent();
Button.DataRenderer dataRenderer = checkbox.getDataRenderer();
dataRenderer.render(checkbox.getButtonData(), checkbox, false);
int preferredWidth = CHECKBOX_SIZE;
int preferredHeight = CHECKBOX_SIZE;
Object buttonData = checkbox.getButtonData();
if (buttonData != null) {
dataRenderer.render(buttonData, checkbox, false);
preferredWidth += dataRenderer.getPreferredWidth(-1) + spacing * 2;
preferredHeight = Math.max(preferredHeight, dataRenderer.getPreferredHeight(-1));
}
return new Dimensions(preferredWidth, preferredHeight);
}
use of org.apache.pivot.wtk.Checkbox in project pivot by apache.
the class TerraCheckboxSkin method paint.
@Override
public void paint(Graphics2D graphics) {
Checkbox checkbox = (Checkbox) getComponent();
int width = getWidth();
int height = getHeight();
// Paint the button
int offset = (height - CHECKBOX_SIZE) / 2;
graphics.translate(0, offset);
paintButton(graphics, checkbox.isEnabled(), checkbox.getState());
graphics.translate(0, -offset);
// Paint the content
Button.DataRenderer dataRenderer = checkbox.getDataRenderer();
Object buttonData = checkbox.getButtonData();
dataRenderer.render(buttonData, checkbox, false);
dataRenderer.setSize(Math.max(width - (CHECKBOX_SIZE + spacing * 2), 0), height);
Graphics2D contentGraphics = (Graphics2D) graphics.create();
contentGraphics.translate(CHECKBOX_SIZE + spacing, 0);
contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
dataRenderer.paint(contentGraphics);
contentGraphics.dispose();
// Paint the focus state
if (checkbox.isFocused()) {
if (buttonData == null) {
Color focusColor = ColorUtilities.setTransparencyInColor(buttonSelectionColor, ALPHA);
graphics.setColor(focusColor);
graphics.fillRect(0, 0, CHECKBOX_SIZE, CHECKBOX_SIZE);
} else {
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(buttonBorderColor);
GraphicsUtilities.setAntialiasingOn(graphics);
Rectangle2D focusRectangle = new Rectangle2D.Double(CHECKBOX_SIZE + 1, 0.5, dataRenderer.getWidth() + spacing * 2 - 2, dataRenderer.getHeight() - 1);
graphics.draw(focusRectangle);
}
}
}
use of org.apache.pivot.wtk.Checkbox in project pivot by apache.
the class RepeatableListButtons method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
colorListButton = (ListButton) namespace.get("colorListButton");
checkboxBoxPane = (BoxPane) namespace.get("checkboxBoxPane");
ButtonStateListener buttonStateListener = new ButtonStateListener() {
@Override
public void stateChanged(Button button, State previousState) {
if (button.isSelected()) {
selectedCount++;
} else {
selectedCount--;
}
applyColorAction.setEnabled(selectedCount > 0);
}
};
ArrayList<String> numbers = new ArrayList<>("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten");
for (String number : numbers) {
Checkbox checkbox = new Checkbox(number);
checkbox.getButtonStateListeners().add(buttonStateListener);
checkboxBoxPane.add(checkbox);
}
}
Aggregations