use of org.apache.pivot.wtk.FlowPane in project pivot by apache.
the class ComponentInspectorSkin method addScopeControl.
private static Component addScopeControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
Scope scope = (Scope) 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(10);
textInput.setMaximumLength(10);
textInput.setValidator(new IntValidator());
textInput.setText(scope == null ? "" : String.valueOf(scope.start));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Scope scopeLocal = (Scope) dictionary.get(key);
try {
int start = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Scope(start, scopeLocal == null ? start : scopeLocal.end, scopeLocal == null ? start : scopeLocal.extent));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(scopeLocal == null ? "" : String.valueOf(scopeLocal.start));
}
}
}
});
Label label = new Label("start");
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(10);
textInput.setMaximumLength(10);
textInput.setValidator(new IntValidator());
textInput.setText(scope == null ? "" : String.valueOf(scope.end));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Scope scopeLocal = (Scope) dictionary.get(key);
try {
int end = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Scope(scopeLocal == null ? end : scopeLocal.start, end, scopeLocal == null ? end : scopeLocal.extent));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(scopeLocal == null ? "" : String.valueOf(scopeLocal.end));
}
}
}
});
label = new Label("end");
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(10);
textInput.setMaximumLength(10);
textInput.setValidator(new IntValidator());
textInput.setText(scope == null ? "" : String.valueOf(scope.extent));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Scope scopeLocal = (Scope) dictionary.get(key);
try {
int extent = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Scope(scopeLocal == null ? extent : scopeLocal.start, scopeLocal == null ? extent : scopeLocal.end, extent));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(scopeLocal == null ? "" : String.valueOf(scopeLocal.extent));
}
}
}
});
label = new Label("extent");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
return boxPane;
}
use of org.apache.pivot.wtk.FlowPane in project pivot by apache.
the class ComponentInspectorSkin method addDimensionsControl.
private static Component addDimensionsControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
Dimensions dimensions = (Dimensions) 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(5);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(dimensions.width));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Dimensions dimensionsLocal = (Dimensions) dictionary.get(key);
try {
int width = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Dimensions(width, dimensionsLocal.height));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(dimensionsLocal.width));
}
}
}
});
Label label = new Label("width");
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(5);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(dimensions.height));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Dimensions dimensionsLocal = (Dimensions) dictionary.get(key);
try {
int height = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Dimensions(dimensionsLocal.width, height));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(dimensionsLocal.height));
}
}
}
});
label = new Label("height");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
return boxPane;
}
use of org.apache.pivot.wtk.FlowPane in project pivot by apache.
the class ComponentInspectorSkin method addLimitsControl.
private static Component addLimitsControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
Limits limits = (Limits) 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(10);
textInput.setMaximumLength(10);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(limits.minimum));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Limits limitsLocal = (Limits) dictionary.get(key);
try {
int min = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Limits(min, limitsLocal.maximum));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(limitsLocal.minimum));
}
}
}
});
Label label = new Label("min");
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(10);
textInput.setMaximumLength(10);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(limits.maximum));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Limits limitsLocal = (Limits) dictionary.get(key);
try {
int max = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Limits(limitsLocal.minimum, max));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(limitsLocal.maximum));
}
}
}
});
label = new Label("max");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
return boxPane;
}
use of org.apache.pivot.wtk.FlowPane in project pivot by apache.
the class FlowPaneSkin method getBaseline.
@Override
public int getBaseline(int width, int height) {
FlowPane flowPane = (FlowPane) getComponent();
int baseline = -1;
if (alignToBaseline) {
int contentWidth = Math.max(width - padding.getWidth(), 0);
// Break the components into multiple rows, and calculate the
// baseline of the first row
int rowWidth = 0;
for (int i = 0, n = flowPane.getLength(); i < n; i++) {
Component component = flowPane.get(i);
if (component.isVisible()) {
Dimensions size = component.getPreferredSize();
if (rowWidth + size.width > contentWidth && rowWidth > 0) {
// and it is not the only component in this row; wrap
break;
}
baseline = Math.max(baseline, component.getBaseline(size.width, size.height));
rowWidth += size.width + horizontalSpacing;
}
}
// Include top padding value
baseline += padding.top;
}
return baseline;
}
use of org.apache.pivot.wtk.FlowPane in project pivot by apache.
the class FlowPaneSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
FlowPane flowPane = (FlowPane) getComponent();
int preferredWidth = 0;
int ascent = 0;
int descent = 0;
int j = 0;
for (int i = 0, n = flowPane.getLength(); i < n; i++) {
Component component = flowPane.get(i);
if (component.isVisible()) {
Dimensions size = component.getPreferredSize();
preferredWidth += size.width;
if (alignToBaseline) {
int baseline = component.getBaseline(size.width, size.height);
ascent = Math.max(ascent, baseline);
descent = Math.max(descent, size.height - baseline);
} else {
ascent = Math.max(ascent, size.height);
}
j++;
}
}
// Include horizontal spacing
if (j > 1) {
preferredWidth += horizontalSpacing * (j - 1);
}
// Include padding
preferredWidth += padding.getWidth();
return new Dimensions(preferredWidth, ascent + descent + padding.getHeight());
}
Aggregations