Search in sources :

Example 1 with Dimensions

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;
}
Also used : IntValidator(org.apache.pivot.wtk.validation.IntValidator) BoxPane(org.apache.pivot.wtk.BoxPane) Label(org.apache.pivot.wtk.Label) Dimensions(org.apache.pivot.wtk.Dimensions) FlowPane(org.apache.pivot.wtk.FlowPane) TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

Example 2 with Dimensions

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));
    }
}
Also used : BoxPane(org.apache.pivot.wtk.BoxPane) Dimensions(org.apache.pivot.wtk.Dimensions) TextInput(org.apache.pivot.wtk.TextInput)

Example 3 with Dimensions

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;
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) GradientPaint(java.awt.GradientPaint)

Example 4 with Dimensions

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;
}
Also used : ScrollPane(org.apache.pivot.wtk.ScrollPane) ScrollBarPolicy(org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) Paint(java.awt.Paint)

Example 5 with Dimensions

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);
}
Also used : ScrollPane(org.apache.pivot.wtk.ScrollPane) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) Paint(java.awt.Paint)

Aggregations

Dimensions (org.apache.pivot.wtk.Dimensions)76 Component (org.apache.pivot.wtk.Component)40 GradientPaint (java.awt.GradientPaint)21 Point (org.apache.pivot.wtk.Point)16 FontRenderContext (java.awt.font.FontRenderContext)9 Button (org.apache.pivot.wtk.Button)9 Paint (java.awt.Paint)7 Rectangle2D (java.awt.geom.Rectangle2D)6 LineMetrics (java.awt.font.LineMetrics)5 BoxPane (org.apache.pivot.wtk.BoxPane)5 FlowPane (org.apache.pivot.wtk.FlowPane)5 Label (org.apache.pivot.wtk.Label)5 ScrollPane (org.apache.pivot.wtk.ScrollPane)4 Separator (org.apache.pivot.wtk.Separator)4 Form (org.apache.pivot.wtk.Form)3 ImageView (org.apache.pivot.wtk.ImageView)3 Image (org.apache.pivot.wtk.media.Image)3 Color (java.awt.Color)2 Font (java.awt.Font)2 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)2