Search in sources :

Example 1 with TreeCellEditor

use of javax.swing.tree.TreeCellEditor in project gephi by gephi.

the class DirectoryChooserUI method createTree.

private JComponent createTree() {
    final DirectoryHandler dirHandler = createDirectoryHandler(fileChooser);
    // #106011: don't show "colors, food, sports" sample model after init :-)
    tree = new JTree(new Object[0]) {

        @Override
        protected void processMouseEvent(MouseEvent e) {
            dirHandler.preprocessMouseEvent(e);
            super.processMouseEvent(e);
        }

        // For speed (#127170):
        @Override
        public boolean isLargeModel() {
            return true;
        }

        // To work with different font sizes (#106223); see: http://www.javalobby.org/java/forums/t19562.html
        private boolean firstPaint = true;

        @Override
        public void setFont(Font f) {
            firstPaint = true;
            super.setFont(f);
        }

        @Override
        public void paint(Graphics g) {
            if (firstPaint) {
                g.setFont(getFont());
                setRowHeight(Math.max(/* icon height plus insets? */
                17, g.getFontMetrics().getHeight()));
                firstPaint = false;
                // Setting the fixed height will generate another paint request, no need to complete this one
                return;
            }
            super.paint(g);
        }
    };
    // #105642: start with right content in tree 
    File curDir = fileChooser.getCurrentDirectory();
    if (curDir == null) {
        curDir = fileChooser.getFileSystemView().getRoots()[0];
    }
    updateTree(curDir);
    tree.setFocusable(true);
    tree.setOpaque(true);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setToggleClickCount(0);
    tree.addTreeExpansionListener(new TreeExpansionHandler());
    TreeKeyHandler keyHandler = new TreeKeyHandler();
    tree.addKeyListener(keyHandler);
    tree.addFocusListener(keyHandler);
    tree.addMouseListener(dirHandler);
    tree.addFocusListener(dirHandler);
    tree.addTreeSelectionListener(dirHandler);
    if (fileChooser.isMultiSelectionEnabled()) {
        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    } else {
        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    }
    TreeCellEditor tce = new DirectoryCellEditor(tree, fileChooser, new JTextField());
    tree.setCellEditor(tce);
    tce.addCellEditorListener(dirHandler);
    tree.setCellRenderer(new DirectoryTreeRenderer());
    JScrollPane scrollBar = new JScrollPane(tree);
    scrollBar.setViewportView(tree);
    tree.setInvokesStopCellEditing(true);
    return scrollBar;
}
Also used : MouseEvent(java.awt.event.MouseEvent) TreeCellEditor(javax.swing.tree.TreeCellEditor) FileObject(org.openide.filesystems.FileObject) File(java.io.File)

Example 2 with TreeCellEditor

use of javax.swing.tree.TreeCellEditor in project intellij-community by JetBrains.

the class NewErrorTreeEditor method getTreeCellEditorComponent.

@Override
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row) {
    final ErrorTreeElement element = getElement(value);
    if (element instanceof EditableMessageElement) {
        EditableMessageElement editableMessageElement = (EditableMessageElement) element;
        final CustomizeColoredTreeCellRenderer leftSelfRenderer = editableMessageElement.getLeftSelfRenderer();
        final TreeCellEditor rightSelfEditor = editableMessageElement.getRightSelfEditor();
        myColoredTreeCellRenderer.setCurrentCallback(leftSelfRenderer);
        myRightCellRenderer.setCurrentCallback(rightSelfEditor);
        return myWrapperEditor.getTreeCellEditorComponent(tree, value, selected, expanded, leaf, row);
    }
    return myTree.getCellRenderer().getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, true);
}
Also used : TreeCellEditor(javax.swing.tree.TreeCellEditor) CustomizeColoredTreeCellRenderer(com.intellij.ui.CustomizeColoredTreeCellRenderer)

Aggregations

TreeCellEditor (javax.swing.tree.TreeCellEditor)2 CustomizeColoredTreeCellRenderer (com.intellij.ui.CustomizeColoredTreeCellRenderer)1 MouseEvent (java.awt.event.MouseEvent)1 File (java.io.File)1 FileObject (org.openide.filesystems.FileObject)1