Search in sources :

Example 1 with ScrollBarPolicy

use of org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy in project pivot by apache.

the class ComponentExplorerWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    splitPane = (SplitPane) namespace.get("splitPane");
    treeView = (TreeView) namespace.get("treeView");
    contentScrollPane = (ScrollPane) namespace.get("contentScrollPane");
    contentPane = (Border) namespace.get("contentPane");
    sourceTextArea = (TextArea) namespace.get("sourceTextArea");
    componentPropertyInspector = (ComponentPropertyInspector) namespace.get("componentPropertyInspector");
    componentStyleInspector = (ComponentStyleInspector) namespace.get("componentStyleInspector");
    eventLogger = (EventLogger) namespace.get("eventLogger");
    horizontalScrollBarPolicyGroup = (ButtonGroup) namespace.get("horizontalScrollBarPolicyGroup");
    verticalScrollBarPolicyGroup = (ButtonGroup) namespace.get("verticalScrollBarPolicyGroup");
    horizontalAutoButton = (Button) namespace.get("horizontalAutoButton");
    horizontalFillButton = (Button) namespace.get("horizontalFillButton");
    horizontalFillToCapacityButton = (Button) namespace.get("horizontalFillToCapacityButton");
    horizontalNeverButton = (Button) namespace.get("horizontalNeverButton");
    horizontalAlwaysButton = (Button) namespace.get("horizontalAlwaysButton");
    verticalAutoButton = (Button) namespace.get("verticalAutoButton");
    verticalFillButton = (Button) namespace.get("verticalFillButton");
    verticalFillToCapacityButton = (Button) namespace.get("verticalFillToCapacityButton");
    verticalNeverButton = (Button) namespace.get("verticalNeverButton");
    verticalAlwaysButton = (Button) namespace.get("verticalAlwaysButton");
    treeView.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {

        @Override
        public void selectedPathsChanged(TreeView treeViewArgument, Sequence<Path> previousSelectedPaths) {
            Component component = null;
            Object node = treeViewArgument.getSelectedNode();
            if (node instanceof ComponentNode) {
                ComponentNode componentNode = (ComponentNode) node;
                URL url = componentNode.getSrc();
                try {
                    sourceTextArea.setText(url);
                } catch (IOException exception) {
                    throw new RuntimeException(exception);
                }
                BXMLSerializer bxmlSerializer = new BXMLSerializer();
                try {
                    component = (Component) bxmlSerializer.readObject(url);
                } catch (IOException exception) {
                    throw new RuntimeException(exception);
                } catch (SerializationException exception) {
                    throw new RuntimeException(exception);
                }
                switch(componentNode.getHorizontalScrollBarPolicy()) {
                    case AUTO:
                        horizontalScrollBarPolicyGroup.setSelection(horizontalAutoButton);
                        break;
                    case FILL:
                        horizontalScrollBarPolicyGroup.setSelection(horizontalFillButton);
                        break;
                    case FILL_TO_CAPACITY:
                        horizontalScrollBarPolicyGroup.setSelection(horizontalFillToCapacityButton);
                        break;
                    case NEVER:
                        horizontalScrollBarPolicyGroup.setSelection(horizontalNeverButton);
                        break;
                    case ALWAYS:
                        horizontalScrollBarPolicyGroup.setSelection(horizontalAlwaysButton);
                        break;
                    default:
                        break;
                }
                switch(componentNode.getVerticalScrollBarPolicy()) {
                    case AUTO:
                        verticalScrollBarPolicyGroup.setSelection(verticalAutoButton);
                        break;
                    case FILL:
                        verticalScrollBarPolicyGroup.setSelection(verticalFillButton);
                        break;
                    case FILL_TO_CAPACITY:
                        verticalScrollBarPolicyGroup.setSelection(verticalFillToCapacityButton);
                        break;
                    case NEVER:
                        verticalScrollBarPolicyGroup.setSelection(verticalNeverButton);
                        break;
                    case ALWAYS:
                        verticalScrollBarPolicyGroup.setSelection(verticalAlwaysButton);
                        break;
                    default:
                        break;
                }
            } else {
                sourceTextArea.setText("");
            }
            contentPane.setContent(component);
            componentPropertyInspector.setSource(component);
            componentStyleInspector.setSource(component);
            eventLogger.setSource(component);
            eventLogger.clearLog();
        }
    });
    treeView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {

        @Override
        public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
            if (button == Mouse.Button.LEFT && count == 2) {
                Path path = treeView.getNodeAt(y);
                if (path != null) {
                    List<?> treeData = treeView.getTreeData();
                    Object node = Tree.get(treeData, path);
                    if (node instanceof List<?>) {
                        treeView.setBranchExpanded(path, !treeView.isBranchExpanded(path));
                    }
                }
            }
            return false;
        }
    });
    horizontalScrollBarPolicyGroup.getButtonGroupListeners().add(new ButtonGroupListener() {

        @Override
        public void selectionChanged(ButtonGroup buttonGroup, Button previousSelection) {
            Button button = buttonGroup.getSelection();
            ScrollBarPolicy horizontalScrollBarPolicy = null;
            if (button == horizontalAutoButton) {
                horizontalScrollBarPolicy = ScrollBarPolicy.AUTO;
            } else if (button == horizontalFillButton) {
                horizontalScrollBarPolicy = ScrollBarPolicy.FILL;
            } else if (button == horizontalFillToCapacityButton) {
                horizontalScrollBarPolicy = ScrollBarPolicy.FILL_TO_CAPACITY;
            } else if (button == horizontalNeverButton) {
                horizontalScrollBarPolicy = ScrollBarPolicy.NEVER;
            } else if (button == horizontalAlwaysButton) {
                horizontalScrollBarPolicy = ScrollBarPolicy.ALWAYS;
            }
            if (horizontalScrollBarPolicy != null) {
                contentScrollPane.setHorizontalScrollBarPolicy(horizontalScrollBarPolicy);
            }
        }
    });
    verticalScrollBarPolicyGroup.getButtonGroupListeners().add(new ButtonGroupListener() {

        @Override
        public void selectionChanged(ButtonGroup buttonGroup, Button previousSelection) {
            Button button = buttonGroup.getSelection();
            ScrollBarPolicy verticalScrollBarPolicy = null;
            if (button == verticalAutoButton) {
                verticalScrollBarPolicy = ScrollBarPolicy.AUTO;
            } else if (button == verticalFillButton) {
                verticalScrollBarPolicy = ScrollBarPolicy.FILL;
            } else if (button == verticalFillToCapacityButton) {
                verticalScrollBarPolicy = ScrollBarPolicy.FILL_TO_CAPACITY;
            } else if (button == verticalNeverButton) {
                verticalScrollBarPolicy = ScrollBarPolicy.NEVER;
            } else if (button == verticalAlwaysButton) {
                verticalScrollBarPolicy = ScrollBarPolicy.ALWAYS;
            }
            if (verticalScrollBarPolicy != null) {
                contentScrollPane.setVerticalScrollBarPolicy(verticalScrollBarPolicy);
            }
        }
    });
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) SerializationException(org.apache.pivot.serialization.SerializationException) IOException(java.io.IOException) URL(java.net.URL) ButtonGroupListener(org.apache.pivot.wtk.ButtonGroupListener) Mouse(org.apache.pivot.wtk.Mouse) ButtonGroup(org.apache.pivot.wtk.ButtonGroup) Button(org.apache.pivot.wtk.Button) ScrollBarPolicy(org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy) TreeViewSelectionListener(org.apache.pivot.wtk.TreeViewSelectionListener) TreeView(org.apache.pivot.wtk.TreeView) ComponentMouseButtonListener(org.apache.pivot.wtk.ComponentMouseButtonListener) List(org.apache.pivot.collections.List) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 2 with ScrollBarPolicy

use of org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy 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 3 with ScrollBarPolicy

use of org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy in project pivot by apache.

the class ScrollPaneSkin method layout.

@Override
public void layout() {
    ScrollPane scrollPane = (ScrollPane) getComponent();
    ScrollBarPolicy horizontalPolicy = scrollPane.getHorizontalScrollBarPolicy();
    ScrollBarPolicy verticalPolicy = scrollPane.getVerticalScrollBarPolicy();
    boolean fillWidthToCapacity = false;
    boolean fillHeightToCapacity = false;
    if (horizontalPolicy == ScrollBarPolicy.FILL_TO_CAPACITY) {
        horizontalPolicy = ScrollBarPolicy.AUTO;
        fillWidthToCapacity = true;
    }
    if (verticalPolicy == ScrollBarPolicy.FILL_TO_CAPACITY) {
        verticalPolicy = ScrollBarPolicy.AUTO;
        fillHeightToCapacity = true;
    }
    layoutHelper(horizontalPolicy, verticalPolicy);
    Component view = scrollPane.getView();
    if (view != null && (fillWidthToCapacity || fillHeightToCapacity)) {
        // We assumed AUTO. Now we check our assumption to see if we
        // need to adjust it to use FILL
        boolean adjustWidth = false, adjustHeight = false;
        if (fillWidthToCapacity) {
            Component rowHeader = scrollPane.getRowHeader();
            int rowHeaderWidth = rowHeader != null ? rowHeader.getWidth() : 0;
            int verticalScrollBarWidth = verticalScrollBar.isVisible() ? verticalScrollBar.getWidth() : 0;
            int minViewWidth = getWidth() - rowHeaderWidth - verticalScrollBarWidth;
            if (view.getWidth() < minViewWidth) {
                horizontalPolicy = ScrollBarPolicy.FILL;
                adjustWidth = true;
            }
        }
        if (fillHeightToCapacity) {
            Component columnHeader = scrollPane.getColumnHeader();
            int columnHeaderHeight = columnHeader != null ? columnHeader.getHeight() : 0;
            int horizontalScrollBarHeight = horizontalScrollBar.isVisible() ? horizontalScrollBar.getHeight() : 0;
            int minViewHeight = getHeight() - columnHeaderHeight - horizontalScrollBarHeight;
            if (view.getHeight() < minViewHeight) {
                verticalPolicy = ScrollBarPolicy.FILL;
                adjustHeight = true;
            }
        }
        if (adjustWidth || adjustHeight) {
            layoutHelper(horizontalPolicy, verticalPolicy);
        }
    }
    cachedHorizontalScrollBarHeight = horizontalScrollBar.getHeight();
    cachedVerticalScrollBarWidth = verticalScrollBar.getWidth();
}
Also used : ScrollPane(org.apache.pivot.wtk.ScrollPane) ScrollBarPolicy(org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy) Component(org.apache.pivot.wtk.Component) Paint(java.awt.Paint)

Example 4 with ScrollBarPolicy

use of org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy in project pivot by apache.

the class ScrollPaneSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = 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 verticalPolicy = scrollPane.getVerticalScrollBarPolicy();
        if (verticalPolicy != ScrollBarPolicy.FILL) {
            // Get the unconstrained preferred size of the view
            Dimensions preferredViewSize = view.getPreferredSize();
            if (verticalPolicy == ScrollBarPolicy.FILL_TO_CAPACITY) {
                if (height < 0) {
                    verticalPolicy = ScrollBarPolicy.AUTO;
                } else {
                    int preferredHeight = preferredViewSize.height + preferredColumnHeaderHeight;
                    if (preferredHeight < height) {
                        verticalPolicy = ScrollBarPolicy.FILL;
                    } else {
                        verticalPolicy = ScrollBarPolicy.AUTO;
                    }
                }
            }
            if (verticalPolicy == ScrollBarPolicy.ALWAYS || verticalPolicy == ScrollBarPolicy.NEVER || verticalPolicy == ScrollBarPolicy.AUTO) {
                preferredWidth = preferredViewSize.width + preferredRowHeaderWidth;
                // preferred width calculation
                if (verticalPolicy == ScrollBarPolicy.ALWAYS || (verticalPolicy == ScrollBarPolicy.AUTO && height > 0 && preferredViewSize.height + preferredColumnHeaderHeight > height)) {
                    preferredWidth += verticalScrollBar.getPreferredWidth(-1);
                }
            }
        }
        if (verticalPolicy == ScrollBarPolicy.FILL) {
            // Preferred width is the sum of the constrained preferred
            // width of the view and the unconstrained preferred width of
            // the row header
            int heightUpdated = height;
            if (heightUpdated >= 0) {
                // Subtract the unconstrained preferred height of the
                // column header from the height constraint
                heightUpdated = Math.max(heightUpdated - preferredColumnHeaderHeight, 0);
            }
            preferredWidth = view.getPreferredWidth(heightUpdated) + preferredRowHeaderWidth;
        }
    }
    return preferredWidth;
}
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)

Aggregations

Component (org.apache.pivot.wtk.Component)4 ScrollBarPolicy (org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy)4 Paint (java.awt.Paint)3 ScrollPane (org.apache.pivot.wtk.ScrollPane)3 Dimensions (org.apache.pivot.wtk.Dimensions)2 IOException (java.io.IOException)1 URL (java.net.URL)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 List (org.apache.pivot.collections.List)1 Path (org.apache.pivot.collections.Sequence.Tree.Path)1 SerializationException (org.apache.pivot.serialization.SerializationException)1 Button (org.apache.pivot.wtk.Button)1 ButtonGroup (org.apache.pivot.wtk.ButtonGroup)1 ButtonGroupListener (org.apache.pivot.wtk.ButtonGroupListener)1 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)1 Mouse (org.apache.pivot.wtk.Mouse)1 TreeView (org.apache.pivot.wtk.TreeView)1 TreeViewSelectionListener (org.apache.pivot.wtk.TreeViewSelectionListener)1