Java Code Examples for javax.swing.JTree

The following are top voted examples for showing how to use javax.swing.JTree. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Neukoelln_SER316   File: TaskTreeTableCellRenderer.java   Source Code and License 7 votes vote down vote up
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
        boolean expanded, boolean leaf, int row, boolean hasFocus) {
    // if root then just return some component
    // it is not shown anyway
    super.getTreeCellRendererComponent(
            tree, value, selected,
            expanded, leaf, row,
            hasFocus);
    if (value instanceof Project)
        return empty_panel;
    if (!(value instanceof Task))
        return empty_panel;
    Task t = (Task) value; 
    setText(t.getText());
    setToolTipText(t.getDescription());
    setIcon(getStatusIcon(t));
    applyFont(t, this);
    //return getTaskTreeCellRenderer(t, selected, hasFocus);
    return this;
}
 
Example 2
Project: SER316-Aachen   File: TaskTreeTableCellRenderer.java   Source Code and License 6 votes vote down vote up
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
        boolean expanded, boolean leaf, int row, boolean hasFocus) {
    // if root then just return some component
    // it is not shown anyway
    super.getTreeCellRendererComponent(
            tree, value, selected,
            expanded, leaf, row,
            hasFocus);
    if (value instanceof Project)
        return empty_panel;
    if (!(value instanceof Task))
        return empty_panel;
    Task t = (Task) value; 
    setText(t.getText());
    setToolTipText(t.getDescription());
    setIcon(getStatusIcon(t));
    applyFont(t, this);
    //return getTaskTreeCellRenderer(t, selected, hasFocus);
    return this;
}
 
Example 3
Project: JAddOn   File: JTreeUtils.java   Source Code and License 6 votes vote down vote up
public static JTree updateJTree(JTree tree, TreeArrayList<?> data, ExpandedPaths ep) {
    ArrayList<String> expanded_paths = null;
    TreePath[] paths = null;
    if(ep != null) {
        expanded_paths = ep.getExpandedPaths(tree);
        paths = tree.getSelectionPaths();
    }
    DefaultMutableTreeNode top = getDefaultMutableTreeNodeOfHashMap(data);
    DefaultTreeModel model = new DefaultTreeModel(top);
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    model.reload(root);
    tree.setModel(model);
    if(ep != null) {
        ep.expandPaths(tree, expanded_paths);
        tree.setSelectionPaths(paths);
    }
    return tree;
}
 
Example 4
Project: Cognizant-Intelligent-Test-Scripter   File: JCheckBoxTree.java   Source Code and License 6 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
        boolean selected, boolean expanded, boolean leaf, int row,
        boolean hasFocus) {
    TreeNode node = (TreeNode) value;
    TreePath tp = new TreePath(getPath(node));
    CheckedNode cn = nodesCheckingState.get(tp);
    checkBox.setIcon(getIcon(value));
    if (cn == null) {
        return this;
    }
    checkBox.setSelected(cn.isSelected);
    checkBox.setText(node.toString());
    checkBox.setOpaque(cn.isSelected && cn.hasChildren && !cn.allChildrenSelected);
    return this;
}
 
Example 5
Project: SER316-Munich   File: TaskTreeTableCellRenderer.java   Source Code and License 6 votes vote down vote up
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
        boolean expanded, boolean leaf, int row, boolean hasFocus) {
    // if root then just return some component
    // it is not shown anyway
    super.getTreeCellRendererComponent(
            tree, value, selected,
            expanded, leaf, row,
            hasFocus);
    if (value instanceof Project)
        return empty_panel;
    if (!(value instanceof Task))
        return empty_panel;
    Task t = (Task) value; 
    setText(t.getText());
    setToolTipText(t.getDescription());
    setIcon(getStatusIcon(t));
    applyFont(t, this);
    //return getTaskTreeCellRenderer(t, selected, hasFocus);
    return this;
}
 
Example 6
Project: marathonv5   File: JavaElementFactory.java   Source Code and License 6 votes vote down vote up
public static void reset() {
    add(Component.class, JavaElement.class);
    add(JList.class, JListJavaElement.class);
    add(JTabbedPane.class, JTabbedPaneJavaElement.class);
    add(JComboBox.class, JComboBoxJavaElement.class);
    add(JTable.class, JTableJavaElement.class);
    add(JTableHeader.class, JTableHeaderJavaElement.class);
    add(JTree.class, JTreeJavaElement.class);
    add(JToggleButton.class, JToggleButtonJavaElement.class);
    add(JSpinner.class, JSpinnerJavaElement.class);
    add(JProgressBar.class, JProgressBarJavaElement.class);
    add(JSplitPane.class, JSplitPaneJavaElement.class);
    add(JTextComponent.class, JTextComponentJavaElement.class);
    add(EditorContainer.class, JTreeEditingContainerJavaElement.class);
    add(JEditorPane.class, JEditorPaneJavaElement.class);
    add(JMenuItem.class, JMenuItemJavaElement.class);
    add(JSlider.class, JSliderJavaElement.class);
    add(JSpinner.class, JSpinnerJavaElement.class);
    add(DefaultEditor.class, DefaultEditorJavaElement.class);
    add(JColorChooser.class, JColorChooserJavaElement.class);
    add(JFileChooser.class, JFileChooserJavaElement.class);
}
 
Example 7
Project: Wilmersdorf_SER316   File: TaskTreeTableCellRenderer.java   Source Code and License 6 votes vote down vote up
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
        boolean expanded, boolean leaf, int row, boolean hasFocus) {
    // if root then just return some component
    // it is not shown anyway
    super.getTreeCellRendererComponent(
            tree, value, selected,
            expanded, leaf, row,
            hasFocus);
    if (value instanceof Project)
        return empty_panel;
    if (!(value instanceof Task))
        return empty_panel;
    Task t = (Task) value; 
    setText(t.getText());
    setToolTipText(t.getDescription());
    setIcon(getStatusIcon(t));
    applyFont(t, this);
    //return getTaskTreeCellRenderer(t, selected, hasFocus);
    return this;
}
 
Example 8
Project: swingspy   File: SwingSpyPanel.java   Source Code and License 6 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
	super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

	DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
	if (node.getUserObject() != null) {
		ComponentWrapper userObject = (ComponentWrapper) node.getUserObject();
		if (userObject != null) {
			Component c = userObject.component;
			for (int i = 0; i < cmpClasses.length; i++) {
				Class clazz = cmpClasses[i];
				if (clazz.isAssignableFrom(c.getClass())) {
					setIcon(cmpIcons[i]);
					return this;
				}
			}
		}
		setIcon(noneIcon);
	}
	return this;
}
 
Example 9
Project: automatic-variants   File: PackageTree.java   Source Code and License 6 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    PackageNode item = (PackageNode) value;

    if (hasFocus) {
	item.updateHelp(help, true);
    }

    Component defaultC = defaultR.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    if (item.isDisabled()) {
	defaultC.setForeground(disabledColor);
    }

    if (item.type == PackageNode.Type.VARSET && ((VariantSet)item).spec == null) {
	defaultC.setForeground(Color.RED);
    }

    return defaultC;
}
 
Example 10
Project: incubator-netbeans   File: HintsPanel.java   Source Code and License 6 votes vote down vote up
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {

            renderer.setBackground(selected ? dr.getBackgroundSelectionColor() : dr.getBackgroundNonSelectionColor());
            renderer.setForeground(selected ? dr.getTextSelectionColor() : dr.getTextNonSelectionColor());
            renderer.setFont(renderer.getFont().deriveFont(Font.PLAIN));
            renderer.setOpaque(true);
            renderer.setEnabled(tree.isEnabled());

            Object data = ((DefaultMutableTreeNode) value).getUserObject();
            if (data instanceof HintCategory) {
                HintCategory cat = ((HintCategory) data);
                renderer.setText(cat.displayName);
            } else if (data instanceof HintMetadata) {
                HintMetadata treeRule = (HintMetadata) data;
                if (treeRule.options.contains(Options.QUERY)) {
                    renderer.setFont(renderer.getFont().deriveFont(Font.ITALIC));
                }
                renderer.setText(treeRule.displayName);

            } else {
                renderer.setText(value.toString());
            }

            return renderer;
        }
 
Example 11
Project: jdk8u-jdk   File: SynthTreeUI.java   Source Code and License 6 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
                                              boolean sel,
                                              boolean expanded,
                                              boolean leaf, int row,
                                              boolean hasFocus) {
    if (!useTreeColors && (sel || hasFocus)) {
        SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel.
                     getUIOfType(getUI(), SynthLabelUI.class),
                           sel, hasFocus, tree.isEnabled(), false);
    }
    else {
        SynthLookAndFeel.resetSelectedUI();
    }
    return super.getTreeCellRendererComponent(tree, value, sel,
                                              expanded, leaf, row, hasFocus);
}
 
Example 12
Project: openjdk-jdk10   File: LastNodeLowerHalfDrop.java   Source Code and License 6 votes vote down vote up
private boolean haveCompleteNode(JTree tree) {
    int[] selRows = tree.getSelectionRows();
    TreePath path = tree.getPathForRow(selRows[0]);
    DefaultMutableTreeNode first = (DefaultMutableTreeNode)
            path.getLastPathComponent();
    int childCount = first.getChildCount();
    // first has children and no children are selected.
    if (childCount > 0 && selRows.length == 1) {
        return false;
    }
    // first may have children.
    for (int i = 1; i < selRows.length; i++) {
        path = tree.getPathForRow(selRows[i]);
        DefaultMutableTreeNode next = (DefaultMutableTreeNode)
                path.getLastPathComponent();
        if (first.isNodeChild(next)) {
            // Found a child of first.
            if (childCount > selRows.length - 1) {
                // Not all children of first are selected.
                return false;
            }
        }
    }
    return true;
}
 
Example 13
Project: VASSAL-src   File: ConfigureTree.java   Source Code and License 6 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
  if (value instanceof DefaultMutableTreeNode) {
    final Configurable c =
      (Configurable) ((DefaultMutableTreeNode) value).getUserObject();
    if (c != null) {
      leaf = c.getAllowableConfigureComponents().length == 0;
      value = (c.getConfigureName() != null ? c.getConfigureName() : "") +
              " [" + getConfigureName(c.getClass()) + "]";
    }
  }

  return super.getTreeCellRendererComponent(
    tree, value, sel, expanded, leaf, row, hasFocus
  );
}
 
Example 14
Project: incubator-netbeans   File: DebuggingViewComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Store first visible node and its offset. Called when the view is scrolled
 * by the user.
 */
private void storeScrollPosition() {
    JTree tree = getJTree();
    if (tree != null) {
        int scrollTop = mainScrollPane.getViewport().getViewPosition().y;
        int row = tree.getClosestRowForLocation(tree.getRowBounds(0).x + 1,
                scrollTop);
        if (row >= 0) {
            TreePath path = tree.getPathForRow(row);
            if (path != null) {
                int offset = tree.getRowBounds(row).y - scrollTop;
                visibleTreePosition = new VisibleTreePosition(
                        path, offset);
                return;
            }
        } else {
            return;
        }
    }
    visibleTreePosition = null;
}
 
Example 15
Project: SER316-Dresden   File: TaskTreeTableCellRenderer.java   Source Code and License 6 votes vote down vote up
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
        boolean expanded, boolean leaf, int row, boolean hasFocus) {
    // if root then just return some component
    // it is not shown anyway
    super.getTreeCellRendererComponent(
            tree, value, selected,
            expanded, leaf, row,
            hasFocus);
    if (value instanceof Project)
        return empty_panel;
    if (!(value instanceof Task))
        return empty_panel;
    Task t = (Task) value; 
    setText(t.getText());
    setToolTipText(t.getDescription());
    setIcon(getStatusIcon(t));
    applyFont(t, this);
    //return getTaskTreeCellRenderer(t, selected, hasFocus);
    return this;
}
 
Example 16
Project: openjdk-jdk10   File: MultiTreeUI.java   Source Code and License 5 votes vote down vote up
/**
 * Invokes the <code>getPathBounds</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public Rectangle getPathBounds(JTree a, TreePath b) {
    Rectangle returnValue =
        ((TreeUI) (uis.elementAt(0))).getPathBounds(a,b);
    for (int i = 1; i < uis.size(); i++) {
        ((TreeUI) (uis.elementAt(i))).getPathBounds(a,b);
    }
    return returnValue;
}
 
Example 17
Project: openjdk-jdk10   File: JTreeOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JTree.setScrollsOnExpand(boolean)} through queue
 */
public void setScrollsOnExpand(final boolean b) {
    runMapping(new MapVoidAction("setScrollsOnExpand") {
        @Override
        public void map() {
            ((JTree) getSource()).setScrollsOnExpand(b);
        }
    });
}
 
Example 18
Project: openjdk-jdk10   File: UpdateUIRecursionTest.java   Source Code and License 5 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
                          boolean selected, boolean expanded, boolean leaf,
                          int row, boolean hasFocus)
{
    return renderer.getTreeCellRendererComponent(tree, value, leaf,
                                            expanded, leaf, row, hasFocus);
}
 
Example 19
Project: marathonv5   File: TreeIconDemo2.java   Source Code and License 5 votes vote down vote up
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf,
        int row, boolean hasFocus) {

    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    if (leaf && isTutorialBook(value)) {
        setIcon(tutorialIcon);
        setToolTipText("This book is in the Tutorial series.");
    } else {
        setToolTipText(null); // no tool tip
    }

    return this;
}
 
Example 20
Project: openjdk-jdk10   File: JTreeOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JTree.expandPath(TreePath)} through queue
 */
public void expandPath(final TreePath treePath) {
    runMapping(new MapVoidAction("expandPath") {
        @Override
        public void map() {
            ((JTree) getSource()).expandPath(treePath);
        }
    });
}
 
Example 21
Project: openjdk-jdk10   File: JTreeOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JTree.getLastSelectedPathComponent()} through queue
 */
public Object getLastSelectedPathComponent() {
    return (runMapping(new MapAction<Object>("getLastSelectedPathComponent") {
        @Override
        public Object map() {
            return ((JTree) getSource()).getLastSelectedPathComponent();
        }
    }));
}
 
Example 22
Project: OpenJSharp   File: SchemaTreeTraverser.java   Source Code and License 5 votes vote down vote up
public final Component getTreeCellRendererComponent(JTree tree, Object value,
                                                    boolean selected, boolean expanded, boolean leaf, int row,
                                                    boolean hasFocus) {
    if (value instanceof SchemaTreeNode) {
        SchemaTreeNode stn = (SchemaTreeNode) value;

        this.setValues(null, stn.getCaption(), selected);
        return this;
    }
    throw new IllegalStateException("Unknown node");
}
 
Example 23
Project: jdk8u-jdk   File: MultiTreeUI.java   Source Code and License 5 votes vote down vote up
/**
 * Invokes the <code>getPathBounds</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public Rectangle getPathBounds(JTree a, TreePath b) {
    Rectangle returnValue =
        ((TreeUI) (uis.elementAt(0))).getPathBounds(a,b);
    for (int i = 1; i < uis.size(); i++) {
        ((TreeUI) (uis.elementAt(i))).getPathBounds(a,b);
    }
    return returnValue;
}
 
Example 24
Project: openjdk-jdk10   File: JTreeOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JTree.getVisibleRowCount()} through queue
 */
public int getVisibleRowCount() {
    return (runMapping(new MapIntegerAction("getVisibleRowCount") {
        @Override
        public int map() {
            return ((JTree) getSource()).getVisibleRowCount();
        }
    }));
}
 
Example 25
Project: openjdk-jdk10   File: JTreeOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JTree.fireTreeExpanded(TreePath)} through queue
 */
public void fireTreeExpanded(final TreePath treePath) {
    runMapping(new MapVoidAction("fireTreeExpanded") {
        @Override
        public void map() {
            ((JTree) getSource()).fireTreeExpanded(treePath);
        }
    });
}
 
Example 26
Project: OpenJSharp   File: SynthTreeUI.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void paintDropLine(Graphics g) {
    JTree.DropLocation loc = tree.getDropLocation();
    if (!isDropLine(loc)) {
        return;
    }

    Color c = (Color)style.get(paintContext, "Tree.dropLineColor");
    if (c != null) {
        g.setColor(c);
        Rectangle rect = getDropLineRect(loc);
        g.fillRect(rect.x, rect.y, rect.width, rect.height);
    }
}
 
Example 27
Project: JAddOn   File: TreeTransferHandler.java   Source Code and License 5 votes vote down vote up
public boolean canImport(TransferHandler.TransferSupport support) {
    if(!support.isDrop()) {
        return false;
    }
    support.setShowDropLocation(true);
    if(!support.isDataFlavorSupported(nodesFlavor)) {
        return false;
    }
    // Do not allow a drop on the drag source selections.
    JTree.DropLocation dl =
            (JTree.DropLocation)support.getDropLocation();
    JTree tree = (JTree)support.getComponent();
    int dropRow = tree.getRowForPath(dl.getPath());
    int[] selRows = tree.getSelectionRows();
    for(int i = 0; i < selRows.length; i++) {
        if(selRows[i] == dropRow) {
            return false;
        }
    }
    // Do not allow MOVE-action drops if a non-leaf node is
    // selected unless all of its children are also selected.
    int action = support.getDropAction();
    if(action == MOVE) {
        return haveCompleteNode(tree);
    }
    // Do not allow a non-leaf node to be copied to a level
    // which is less than its source level.
    TreePath dest = dl.getPath();
    DefaultMutableTreeNode target =
        (DefaultMutableTreeNode)dest.getLastPathComponent();
    TreePath path = tree.getPathForRow(selRows[0]);
    DefaultMutableTreeNode firstNode =
        (DefaultMutableTreeNode)path.getLastPathComponent();
    if(firstNode.getChildCount() > 0 &&
           target.getLevel() < firstNode.getLevel()) {
        return false;
    }
    return true;
}
 
Example 28
Project: marathonv5   File: JTreeJavaElement.java   Source Code and License 5 votes vote down vote up
private String getPathText(JTree tree, TreePath path) {
    Object lastPathComponent = path.getLastPathComponent();
    if (lastPathComponent == null) {
        return "";
    }
    return getTextForNodeObject(tree, lastPathComponent);
}
 
Example 29
Project: openjdk-jdk10   File: Test8013571.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) {
    DefaultMutableTreeNode root = create("root");
    root.add(create("colors", "blue", "violet", "red", "yellow"));
    root.add(create("sports", "basketball", "soccer", "football", "hockey"));
    root.add(create("food", "hot dogs", "pizza", "ravioli", "bananas"));
    Test8013571 model = new Test8013571(root);
    JTree tree = new JTree(model);
    model.fireTreeChanged(tree);
}
 
Example 30
Project: openjdk-jdk10   File: bug8003830.java   Source Code and License 5 votes vote down vote up
public void testNPEAtActionsPage() {
    JTree tree = new JTree();
    BasicTreeUI ui = new NullReturningTreeUI();
    tree.setUI(ui);
    BasicTreeUI.TreePageAction tpa = ui.new TreePageAction(0, "down");
    tpa.actionPerformed(new ActionEvent(tree, 0, ""));
}
 
Example 31
Project: incubator-netbeans   File: CheckListener.java   Source Code and License 5 votes vote down vote up
public void mouseClicked(MouseEvent e) {
    // todo (#pf): we need to solve problem between click and double
    // click - click should be possible only on the check box area
    // and double click should be bordered by title text.
    // we need a test how to detect where the mouse pointer is
    JTree tree = (JTree) e.getSource();
    Point p = e.getPoint();
    int x = e.getX();
    int y = e.getY();
    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);

    // if path exists and mouse is clicked exactly once
    if( null == path )
        return;
    
    Node node = Visualizer.findNode( path.getLastPathComponent() );
    if( null == node )
        return;
    
    Rectangle chRect = CheckRenderer.getCheckBoxRectangle();
    Rectangle rowRect = tree.getPathBounds(path);
    chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
    if (e.getClickCount() == 1 && chRect.contains(p)) {
        boolean isSelected = settings.isNodeVisible( node );
        settings.setNodeVisible( node, !isSelected );
        tree.repaint();
    }
}
 
Example 32
Project: openjdk-jdk10   File: JTreeOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JTree.fireTreeWillCollapse(TreePath)} through queue
 */
public void fireTreeWillCollapse(final TreePath treePath) {
    runMapping(new MapVoidAction("fireTreeWillCollapse") {
        @Override
        public void map() throws ExpandVetoException {
            ((JTree) getSource()).fireTreeWillCollapse(treePath);
        }
    });
}
 
Example 33
Project: incubator-netbeans   File: CheckNodeListener.java   Source Code and License 5 votes vote down vote up
static void selectNextPrev(final boolean next, boolean isQuery, JTree tree) {
    int[] rows = tree.getSelectionRows();
    int newRow = rows == null || rows.length == 0 ? 0 : rows[0];
    int maxcount = tree.getRowCount();
    CheckNode node;
    do {
        if (next) {
            newRow++;
            if (newRow >= maxcount) {
                newRow = 0;
            }
        } else {
            newRow--;
            if (newRow < 0) {
                newRow = maxcount - 1;
            }
        }
        TreePath path = tree.getPathForRow(newRow);
        node = (CheckNode) path.getLastPathComponent();
        if (!node.isLeaf()) {
            tree.expandRow(newRow);
            maxcount = tree.getRowCount();
        }
    } while (!node.isLeaf());
    tree.setSelectionRow(newRow);
    tree.scrollRowToVisible(newRow);
}
 
Example 34
Project: incubator-netbeans   File: HintsPanelLogic.java   Source Code and License 5 votes vote down vote up
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_SPACE) {

        if ( e.getSource() instanceof JTree ) {
            JTree tree = (JTree) e.getSource();
            TreePath path = tree.getSelectionPath();

            if ( toggle( path )) {
                e.consume();
            }
        }
    }
}
 
Example 35
Project: openjdk-jdk10   File: SynthTreeUI.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void paintDropLine(Graphics g) {
    JTree.DropLocation loc = tree.getDropLocation();
    if (!isDropLine(loc)) {
        return;
    }

    Color c = (Color)style.get(paintContext, "Tree.dropLineColor");
    if (c != null) {
        g.setColor(c);
        Rectangle rect = getDropLineRect(loc);
        g.fillRect(rect.x, rect.y, rect.width, rect.height);
    }
}
 
Example 36
Project: myqq   File: MyTreeIcon.java   Source Code and License 5 votes vote down vote up
public Component getTreeCellRendererComponent(
                    JTree tree,
                    Object value,
                    boolean sel,
                    boolean expanded,
                    boolean leaf,
                    int row,
                    boolean hasFocus) 
{
    super.getTreeCellRendererComponent(tree, value, sel,expanded,
    		leaf, row, hasFocus);
    for(String str:nodeImages)
    {
    	String[] temp=str.split(MyTools.SPLIT1);
    	if(value.toString().startsWith(temp[0])&&!temp[0].equals(""))//注意Value一定要toString()
    	{
    		 try
{
	//Image grayImage = GrayFilter.createDisabledImage(ImageIO.read(Main.class.getResource(temp[1])));
	if(temp.length==2)//如果是:用户名;图片路径,那么就是好友节点
     			//this.setIcon(new ImageIcon(grayImage));
		this.setIcon(MyTools.getIcon(temp[1]));
     		else if(temp.length==3)//如果是:用户名;图片路径1;图片路径2,那么表示分组节点,
     		{
     			if(!expanded)
     				this.setIcon(MyTools.getIcon(temp[1]));
     			else 
     				this.setIcon(MyTools.getIcon(temp[2]));
     		}
}
catch (Exception e)
{
	e.printStackTrace();
}
    		
    	}
    }
    return this;
}
 
Example 37
Project: ramus   File: ModelsPanel.java   Source Code and License 5 votes vote down vote up
private void init() {
    treeModel.setRoot(createRoot());

    tree = new JTree(treeModel) {
        @Override
        public TreeCellRenderer getCellRenderer() {
            TreeCellRenderer renderer = super.getCellRenderer();
            if (renderer == null)
                return null;
            ((DefaultTreeCellRenderer) renderer).setLeafIcon(new ImageIcon(
                    getClass().getResource("/images/function.png")));
            return renderer;
        }
    };

    tree.setCellRenderer(new Renderer());

    tree.setEditable(true);

    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if ((e.getButton() == MouseEvent.BUTTON1)
                    && (e.getClickCount() == 2)) {
                openDiagram();
            }
        }

    });

    tree.setRootVisible(true);

    JScrollPane pane = new JScrollPane();
    pane.setViewportView(tree);
    this.add(pane, BorderLayout.CENTER);
}
 
Example 38
Project: openjdk-jdk10   File: JTreeOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JTree.setRowHeight(int)} through queue
 */
public void setRowHeight(final int i) {
    runMapping(new MapVoidAction("setRowHeight") {
        @Override
        public void map() {
            ((JTree) getSource()).setRowHeight(i);
        }
    });
}
 
Example 39
Project: openjdk-jdk10   File: JTreeOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JTree.getRowForPath(TreePath)} through queue
 */
public int getRowForPath(final TreePath treePath) {
    return (runMapping(new MapIntegerAction("getRowForPath") {
        @Override
        public int map() {
            return ((JTree) getSource()).getRowForPath(treePath);
        }
    }));
}
 
Example 40
Project: JAddOn   File: TreeTransferHandler.java   Source Code and License 5 votes vote down vote up
public boolean importData(TransferHandler.TransferSupport support) {
    if(!canImport(support)) {
        return false;
    }
    // Extract transfer data.
    DefaultMutableTreeNode[] nodes = null;
    try {
        Transferable t = support.getTransferable();
        nodes = (DefaultMutableTreeNode[])t.getTransferData(nodesFlavor);
    } catch(UnsupportedFlavorException ufe) {
        System.out.println("UnsupportedFlavor: " + ufe.getMessage());
    } catch(java.io.IOException ioe) {
        System.out.println("I/O error: " + ioe.getMessage());
    }
    // Get drop location info.
    JTree.DropLocation dl =
            (JTree.DropLocation)support.getDropLocation();
    int childIndex = dl.getChildIndex();
    TreePath dest = dl.getPath();
    DefaultMutableTreeNode parent =
        (DefaultMutableTreeNode)dest.getLastPathComponent();
    JTree tree = (JTree)support.getComponent();
    DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
    // Configure for drop mode.
    int index = childIndex;    // DropMode.INSERT
    if(childIndex == -1) {     // DropMode.ON
        index = parent.getChildCount();
    }
    // Add data to model.
    for(int i = 0; i < nodes.length; i++) {
        model.insertNodeInto(nodes[i], parent, index++);
    }
    return true;
}