use of org.apache.pivot.wtk.Dimensions 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.Dimensions in project pivot by apache.
the class ComponentInspectorSkin method updateDimensionsControl.
private void updateDimensionsControl(Dictionary<String, Object> dictionary, String key) {
BoxPane boxPane = (BoxPane) controls.get(key);
if (boxPane != null) {
Dimensions dimensions = (Dimensions) dictionary.get(key);
TextInput widthTextInput = (TextInput) ((FlowPane) boxPane.get(0)).get(0);
TextInput heightTextInput = (TextInput) ((FlowPane) boxPane.get(1)).get(0);
widthTextInput.setText(String.valueOf(dimensions.width));
heightTextInput.setText(String.valueOf(dimensions.height));
}
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class FakeWindowSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
int preferredWidth = 0;
int heightMutable = height;
FakeWindow frame = (FakeWindow) getComponent();
// Include title bar width plus left/right title bar borders
Dimensions titleBarSize = titleBarTablePane.getPreferredSize();
preferredWidth = Math.max(titleBarSize.width + 2, preferredWidth);
if (heightMutable != -1) {
// Subtract title bar height and top/bottom title bar borders
// from height constraint
heightMutable -= titleBarSize.height + 2;
}
Component content = frame.getContent();
if (content != null) {
if (heightMutable != -1) {
// Subtract padding, top/bottom content borders, and content
// bevel from height constraint
heightMutable -= padding.getHeight() + (1) + 2;
heightMutable = Math.max(heightMutable, 0);
}
preferredWidth = Math.max(preferredWidth, content.getPreferredWidth(heightMutable));
}
// Add padding and left/right content borders
preferredWidth += padding.getWidth() + 2;
return preferredWidth;
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class ScrollPaneSkin method getPreferredHeight.
@Override
public int getPreferredHeight(int width) {
int preferredHeight = 0;
ScrollPane scrollPane = (ScrollPane) getComponent();
Component view = scrollPane.getView();
if (view != null) {
int preferredRowHeaderWidth = 0;
Component rowHeader = scrollPane.getRowHeader();
if (rowHeader != null) {
preferredRowHeaderWidth = rowHeader.getPreferredWidth(-1);
}
int preferredColumnHeaderHeight = 0;
Component columnHeader = scrollPane.getColumnHeader();
if (columnHeader != null) {
preferredColumnHeaderHeight = columnHeader.getPreferredHeight(-1);
}
ScrollBarPolicy horizontalPolicy = scrollPane.getHorizontalScrollBarPolicy();
if (horizontalPolicy != ScrollBarPolicy.FILL) {
// Get the unconstrained preferred size of the view
Dimensions preferredViewSize = view.getPreferredSize();
if (horizontalPolicy == ScrollBarPolicy.FILL_TO_CAPACITY) {
if (width < 0) {
horizontalPolicy = ScrollBarPolicy.AUTO;
} else {
int preferredWidth = preferredViewSize.width + preferredRowHeaderWidth;
if (preferredWidth < width) {
horizontalPolicy = ScrollBarPolicy.FILL;
} else {
horizontalPolicy = ScrollBarPolicy.AUTO;
}
}
}
if (horizontalPolicy == ScrollBarPolicy.ALWAYS || horizontalPolicy == ScrollBarPolicy.NEVER || horizontalPolicy == ScrollBarPolicy.AUTO) {
preferredHeight = preferredViewSize.height + preferredColumnHeaderHeight;
// height calculation
if (horizontalPolicy == ScrollBarPolicy.ALWAYS || (horizontalPolicy == ScrollBarPolicy.AUTO && width > 0 && preferredViewSize.width + preferredRowHeaderWidth > width)) {
preferredHeight += horizontalScrollBar.getPreferredHeight(-1);
}
}
}
if (horizontalPolicy == ScrollBarPolicy.FILL) {
// Preferred height is the sum of the constrained preferred height
// of the view and the unconstrained preferred height of the column header
int widthUpdated = width;
if (widthUpdated >= 0) {
// Subtract the unconstrained preferred width of the row header
// from the width constraint
widthUpdated = Math.max(widthUpdated - preferredRowHeaderWidth, 0);
}
preferredHeight = view.getPreferredHeight(widthUpdated) + preferredColumnHeaderHeight;
}
}
return preferredHeight;
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class ScrollPaneSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
ScrollPane scrollPane = (ScrollPane) getComponent();
int preferredWidth = 0;
int preferredHeight = 0;
Component view = scrollPane.getView();
if (view != null) {
Dimensions preferredViewSize = view.getPreferredSize();
preferredWidth += preferredViewSize.width;
preferredHeight += preferredViewSize.height;
Component rowHeader = scrollPane.getRowHeader();
if (rowHeader != null) {
preferredWidth += rowHeader.getPreferredWidth(-1);
}
Component columnHeader = scrollPane.getColumnHeader();
if (columnHeader != null) {
preferredHeight += columnHeader.getPreferredHeight(-1);
}
if (scrollPane.getHorizontalScrollBarPolicy() == ScrollBarPolicy.ALWAYS) {
preferredHeight += horizontalScrollBar.getPreferredHeight(-1);
}
if (scrollPane.getVerticalScrollBarPolicy() == ScrollBarPolicy.ALWAYS) {
preferredWidth += verticalScrollBar.getPreferredWidth(-1);
}
}
return new Dimensions(preferredWidth, preferredHeight);
}
Aggregations