Example usage for javax.swing JScrollPane getHeight

List of usage examples for javax.swing JScrollPane getHeight

Introduction

In this page you can find the example usage for javax.swing JScrollPane getHeight.

Prototype

@BeanProperty(bound = false)
public int getHeight() 

Source Link

Document

Returns the current height of this component.

Usage

From source file:ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.java

private void doSynchronizeTreeWithHighlitedPath() {
    String highlitedPath = myMessages.getHighlitedPath();
    if (highlitedPath == null) {
        return;// w w  w.  ja  v  a  2s. c om
    }

    final AbstractLayoutCache layout = ((OutlineModel) getModel()).getLayout();
    int lastSegmentRow = -1;
    int currentSegmentRow = -1;
    int currentSelectedRow = -1;
    int currentMessageIndex = -1;
    for (int row = 0; row < layout.getRowCount(); row++) {

        TreePath path = layout.getPathForRow(row);
        Object component = path.getLastPathComponent();
        if (component instanceof TreeNodeMessage) {
            currentMessageIndex = ((TreeNodeMessage) component).getMessageIndex();
            if (highlitedPath.startsWith(currentMessageIndex + "/")) {
                expandPath(path);
            } else {
                // collapsePath(path);
            }
            continue;
        }

        if (component instanceof TreeNodeUnknown) {
            continue;
        }

        if (component instanceof TreeNodeSegment) {
            lastSegmentRow = row;
        }

        TreeNodeBase node = (TreeNodeBase) component;

        String terserPath = (currentMessageIndex) + node.getTerserPath();
        if (highlitedPath != null && highlitedPath.startsWith(terserPath)
                && !highlitedPath.startsWith(terserPath + "(")) {
            expandPath(path);
            if (highlitedPath.equals(terserPath)) {
                currentSelectedRow = row;
                getSelectionModel().setSelectionInterval(row, row);
                currentSegmentRow = lastSegmentRow;
            }
        } else {
            // collapsePath(path);
        }

    }

    // Adjust the tree scrollpane's scroll position so that the newly
    // selected row is visible
    if (currentSegmentRow != -1 && currentSelectedRow != -1 && !myRespondingToManualRangeChange) {
        JViewport viewPort = (JViewport) getParent();
        final JScrollPane scrollPane = (JScrollPane) viewPort.getParent();

        int tableHeaderHeight = getTableHeader().getHeight();

        int numRowsVisible = ((scrollPane.getHeight() - tableHeaderHeight) / layout.getRowHeight()) - 1;
        int segmentDelta = currentSelectedRow - currentSegmentRow;
        if (segmentDelta > numRowsVisible) {
            currentSegmentRow = currentSegmentRow + (segmentDelta - numRowsVisible);
        }

        final int scrollToRow = currentSegmentRow;
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                scrollPane.getVerticalScrollBar().setValue(layout.getRowHeight() * scrollToRow);
            }
        });

    }
}