Example usage for com.intellij.openapi.ui ThreeComponentsSplitter ThreeComponentsSplitter

List of usage examples for com.intellij.openapi.ui ThreeComponentsSplitter ThreeComponentsSplitter

Introduction

In this page you can find the example usage for com.intellij.openapi.ui ThreeComponentsSplitter ThreeComponentsSplitter.

Prototype

@Deprecated
public ThreeComponentsSplitter(boolean vertical, boolean onePixelDividers) 

Source Link

Usage

From source file:com.android.tools.idea.editors.hierarchyview.HierarchyViewer.java

License:Apache License

public HierarchyViewer(@NotNull ViewNode node, @NotNull BufferedImage preview,
        @NotNull final PropertiesComponent propertiesComponent, @NotNull Disposable parent) {
    myRoot = node;/*from  w w  w.ja  v  a2s .com*/

    // Create UI
    // Preview
    myPreview = new ViewNodeActiveDisplay(node, preview);

    // Node tree
    myNodeTree = new RollOverTree(node);
    myNodeTree.setCellRenderer(new ViewNodeTreeRenderer());

    // Properties table
    myTableModel = new ViewNodeTableModel();
    myPropertiesTable = new JBTable(myTableModel);
    myPropertiesTable.setFillsViewportHeight(true);
    myPropertiesTable.getTableHeader().setReorderingAllowed(false);
    myPropertiesSpeedSearch = new TableSpeedSearch(myPropertiesTable, (object, cell) -> {
        if (object == null) {
            return null;
        }

        assert object instanceof String : "The model is expected to return String instances as values";
        return (String) object;
    });
    myPropertiesSpeedSearch.setComparator(new SpeedSearchComparator(false, false));

    myContentSplitter = new ThreeComponentsSplitter(false, true);
    Disposer.register(parent, myContentSplitter);

    final JScrollPane firstComponent = ScrollPaneFactory.createScrollPane(myNodeTree);
    final JScrollPane lastComponent = ScrollPaneFactory.createScrollPane(myPropertiesTable);

    myContentSplitter.setFirstComponent(firstComponent);
    myContentSplitter.setInnerComponent(myPreview);
    myContentSplitter.setLastComponent(lastComponent);

    // make sure the two side panels never show up with 0 width
    int minWidth = 20;
    setMinimumWidth(firstComponent, minWidth);
    setMinimumWidth(lastComponent, minWidth);
    myContentSplitter.setHonorComponentsMinimumSize(true);

    int width = Math.max(propertiesComponent.getInt(FIRST_COMPONENT_WIDTH, DEFAULT_WIDTH), minWidth);
    myContentSplitter.setFirstSize(width);

    width = Math.max(propertiesComponent.getInt(LAST_COMPONENT_WIDTH, DEFAULT_WIDTH), minWidth);
    myContentSplitter.setLastSize(width);

    // listen to size changes and update the saved sizes
    ComponentAdapter resizeListener = new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent componentEvent) {
            propertiesComponent.setValue(FIRST_COMPONENT_WIDTH, firstComponent.getSize().width, DEFAULT_WIDTH);
            propertiesComponent.setValue(LAST_COMPONENT_WIDTH, lastComponent.getSize().width, DEFAULT_WIDTH);
        }
    };
    firstComponent.addComponentListener(resizeListener);
    lastComponent.addComponentListener(resizeListener);

    myPreview.addViewNodeActiveDisplayListener(this);
    myNodeTree.addTreeSelectionListener(this);
    myNodeTree.addTreeHoverListener(this);

    // Expand visible nodes
    for (int i = 0; i < myNodeTree.getRowCount(); i++) {
        TreePath path = myNodeTree.getPathForRow(i);
        ViewNode n = (ViewNode) path.getLastPathComponent();
        if (n.isDrawn()) {
            myNodeTree.expandPath(path);
        }
    }

    // Select the root node
    myNodeTree.setSelectionRow(0);

    // Node popup
    myNodePopup = new JBPopupMenu();
    myNodeVisibleMenuItem = new JBCheckboxMenuItem("Show in preview");
    myNodeVisibleMenuItem.addActionListener(new ShowHidePreviewActionListener());
    myNodePopup.add(myNodeVisibleMenuItem);
    myNodeTree.addMouseListener(new NodeRightClickAdapter());
}