use of org.apache.pivot.wtk.CornerRadii in project pivot by apache.
the class CornerRadiiTest method test.
@Test
public void test() {
CornerRadii r0 = CornerRadii.NONE;
CornerRadii r0a = new CornerRadii(0);
CornerRadii r1 = new CornerRadii(1);
CornerRadii r1a = CornerRadii.decode("[1, 1, 1, 1]");
CornerRadii r2 = new CornerRadii(2, 2, 2, 2);
CornerRadii r2a = new CornerRadii(2);
CornerRadii r2b = CornerRadii.decode("{topLeft:2, bottomLeft:2, topRight:2, bottomRight:2}");
CornerRadii r3 = new CornerRadii(2, 3, 4, 5);
CornerRadii r3a = CornerRadii.decode("2, 3; 4, 5");
assertEquals(r0, r0a);
assertEquals(r1, r1a);
assertNotEquals(r0, r1);
assertEquals(r2, r2a);
assertEquals(r2a, r2b);
assertEquals(r3, r3a);
assertEquals(r3a.toString(), "CornerRadii [2,3; 4,5]");
}
use of org.apache.pivot.wtk.CornerRadii in project pivot by apache.
the class ComponentInspectorSkin method addCornerRadiiControl.
private static Component addCornerRadiiControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
CornerRadii cornerRadii = (CornerRadii) dictionary.get(key);
BoxPane boxPane = new BoxPane(Orientation.VERTICAL);
section.add(boxPane);
Form.setLabel(boxPane, key);
FlowPane flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
TextInput textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(4);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(cornerRadii.topLeft));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
CornerRadii cornerRadiiLocal = (CornerRadii) dictionary.get(key);
try {
int topLeft = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new CornerRadii(topLeft, cornerRadiiLocal.topRight, cornerRadiiLocal.bottomLeft, cornerRadiiLocal.bottomRight));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(cornerRadiiLocal.topLeft));
}
}
}
});
Label label = new Label("topLeft");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(4);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(cornerRadii.topRight));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
CornerRadii cornerRadiiLocal = (CornerRadii) dictionary.get(key);
try {
int topRight = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new CornerRadii(cornerRadiiLocal.topLeft, topRight, cornerRadiiLocal.bottomLeft, cornerRadiiLocal.bottomRight));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(cornerRadiiLocal.topRight));
}
}
}
});
label = new Label("topRight");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(4);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(cornerRadii.bottomLeft));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
CornerRadii cornerRadiiLocal = (CornerRadii) dictionary.get(key);
try {
int bottomLeft = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new CornerRadii(cornerRadiiLocal.topLeft, cornerRadiiLocal.topRight, bottomLeft, cornerRadiiLocal.bottomRight));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(cornerRadiiLocal.bottomLeft));
}
}
}
});
label = new Label("bottomLeft");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(4);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(cornerRadii.bottomRight));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
CornerRadii cornerRadiiLocal = (CornerRadii) dictionary.get(key);
try {
int bottomRight = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new CornerRadii(cornerRadiiLocal.topLeft, cornerRadiiLocal.topRight, cornerRadiiLocal.bottomLeft, bottomRight));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(cornerRadiiLocal.bottomRight));
}
}
}
});
label = new Label("bottomRight");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
return boxPane;
}
Aggregations