/** * Overridden to message super and forward the method to the tree. Since the tree is not actually * in the component hierarchy it will never receive this unless we forward it in this manner. */ public void updateUI() { super.updateUI(); if (tree != null) tree.updateUI(); // Use the tree's default foreground and background colors in the // table. LookAndFeel.installColorsAndFont(this, "Tree.background", "Tree.foreground", "Tree.font"); }
public void setModel(TreeTableModel treeTableModel) { // Create the tree. It will be used as a renderer and editor. tree = new TreeTableCellRenderer(treeTableModel); // Install a tableModel representing the visible rows in the tree. super.setModel(new TreeTableModelAdapter(treeTableModel, tree)); // Force the JTable and JTree to share their row selection models. ListToTreeSelectionModelWrapper selectionWrapper = new ListToTreeSelectionModelWrapper(); tree.setSelectionModel(selectionWrapper); setSelectionModel(selectionWrapper.getListSelectionModel()); // Install the tree editor renderer and editor. setDefaultRenderer(TreeTableModel.class, tree); // No grid. setShowGrid(false); // No intercell spacing setIntercellSpacing(new Dimension(0, 0)); // And update the height of the trees row to match that of // the table. if (tree.getRowHeight() < 1) { // Metal looks better like this. setRowHeight(18); } }
/** * Overridden to pass the new rowHeight to the tree. * * @param rowHeight the new height of the row */ public void setRowHeight(int rowHeight) { super.setRowHeight(rowHeight); if ((tree != null) && (tree.getRowHeight() != rowHeight)) { tree.setRowHeight(getRowHeight()); } }
/** Overridden to pass the new rowHeight to the tree. */ @Override public final void setRowHeight(int newRowHeight) { super.setRowHeight(newRowHeight); if (tree != null && tree.getRowHeight() != newRowHeight) { tree.setRowHeight(getRowHeight()); } }
public JTreeTable(TreeTableModel treeTableModel) { // Create the tree. It will be used as a renderer and editor. tree = new TreeTableCellRenderer(treeTableModel); // Install a tableModel representing the visible rows in the tree. setModel(new TreeTableModelAdapter(treeTableModel, tree)); // Force the JTable and JTree to share their row selection models. final ListToTreeSelectionModelWrapper selectionWrapper = new ListToTreeSelectionModelWrapper(); tree.setSelectionModel(selectionWrapper); setSelectionModel(selectionWrapper.getListSelectionModel()); // Install the tree editor renderer and editor. setDefaultRenderer(TreeTableModel.class, tree); setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor()); // No grid. setShowGrid(false); // No intercell spacing setIntercellSpacing(new Dimension(0, 0)); // And update the height of the trees row to match that of // the table. if (tree.getRowHeight() < 1) { // Metal looks better like this. setRowHeight(getRowHeight()); } final Action expand = new AbstractAction() { private static final long serialVersionUID = -5859674518660156121L; @Override public void actionPerformed(ActionEvent e) { final TreePath selected = tree.getSelectionPath(); final DetailAST ast = (DetailAST) selected.getLastPathComponent(); new CodeSelector(ast, editor, lines2position).select(); if (tree.isExpanded(selected)) { tree.collapsePath(selected); } else { tree.expandPath(selected); } tree.setSelectionPath(selected); } }; final KeyStroke stroke = KeyStroke.getKeyStroke("ENTER"); final String command = "expand/collapse"; getInputMap().put(stroke, command); getActionMap().put(command, expand); }
/** Overriden to pass events on to the tree if the editor does not want to start editing. */ public boolean editCellAt(int row, int column, EventObject e) { if (!super.editCellAt(row, column, e)) { if (e instanceof MouseEvent) { for (int counter = getColumnCount() - 1; counter >= 0; counter--) { if (getColumnClass(counter) == TreeTableModel.class) { MouseEvent me = (MouseEvent) e; MouseEvent newME = new MouseEvent( tree, me.getID(), me.getWhen(), me.getModifiers(), me.getX() - getCellRect(0, counter, true).x, me.getY(), me.getClickCount(), me.isPopupTrigger()); tree.dispatchEvent(newME); break; } } } return false; } return true; }