Java Code Examples for javax.swing.JTree

The following examples show how to use javax.swing.JTree. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Logisim   Source File: ProjectExplorer.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean canPerformAction(JTree targetTree, Object draggedNode, int action, Point location) {
	TreePath pathTarget = targetTree.getPathForLocation(location.x, location.y);
	if (pathTarget == null) {
		targetTree.setSelectionPath(null);
		return false;
	}
	targetTree.setSelectionPath(pathTarget);
	if (action == DnDConstants.ACTION_COPY) {
		return false;
	} else if (action == DnDConstants.ACTION_MOVE) {
		Object targetNode = pathTarget.getLastPathComponent();
		return canMove(draggedNode, targetNode);
	} else {
		return false;
	}
}
 
Example 2
Source Project: marathonv5   Source File: JTreeJavaElement.java    License: Apache License 2.0 6 votes vote down vote up
private boolean setCellSelection(Properties[] properties) {
    JTree tree = (JTree) component;
    if (properties.length == 0) {
        tree.setSelectionRows(new int[0]);
        return true;
    }
    List<TreePath> paths = new ArrayList<TreePath>();
    for (Properties propertie : properties) {
        TreePath path = getPath(tree, propertie.getProperty("Path"));
        if (path != null) {
            paths.add(path);
        }
    }
    if (paths.size() != properties.length) {
        return false;
    }
    tree.setSelectionPaths(paths.toArray(new TreePath[paths.size()]));
    return true;
}
 
Example 3
Source Project: binnavi   Source File: MemberNodeTransferHandler.java    License: Apache License 2.0 6 votes vote down vote up
private static List<TypeMemberTreeNode> getSelectedNodesSorted(final JTree tree) {
  final List<TypeMemberTreeNode> nodes = Lists.newArrayList();
  for (final TreePath path : tree.getSelectionPaths()) {
    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    if (node instanceof TypeMemberTreeNode) {
      nodes.add((TypeMemberTreeNode) node);
    } else {
      return Lists.newArrayList();
    }
  }
  Collections.sort(nodes, new Comparator<TypeMemberTreeNode>() {
    @Override
    public int compare(final TypeMemberTreeNode node0, final TypeMemberTreeNode node1) {
      return node0.getTypeMember().compareTo(node1.getTypeMember());
    }
  });

  return nodes;
}
 
Example 4
Source Project: org.alloytools.alloy   Source File: OurTree.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This method is called by Swing to return an object to be drawn.
 */
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean isLeaf, int row, boolean isFocused) {
    String string = tree.convertValueToText(value, isSelected, expanded, isLeaf, row, isFocused);
    this.isFocused = isFocused;
    this.isSelected = isSelected;
    setText(string);
    setForeground(UIManager.getColor(isSelected ? "Tree.selectionForeground" : "Tree.textForeground"));
    preferredHeight = 0; // By default, don't override width/height
    if (do_isDouble(value)) {
        Dimension d = super.getPreferredSize();
        preferredWidth = d.width + 3;
        preferredHeight = d.height * 2;
    }
    return this;
}
 
Example 5
@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);
    RobotComponent comp = (RobotComponent) value;

    if (comp.isValid()) {
        setForeground(Color.black);
    } else {
        setForeground(Color.red);
    }

    if (comp.supportsChildren() && leaf) {
        setIcon(getOpenIcon());
    }

    return this;
}
 
Example 6
Source Project: ghidra   Source File: DualProgramTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEscapeOpenSecondProgram() throws Exception {

	restoreProgram(diffTestP2);
	loadProgram(diffTestP1);
	launchDiffByAction();
	Window win = waitForWindow("Select Other Program");
	assertNotNull(win);
	waitForSwing();

	Component comp = getComponentOfType(win, JComboBox.class);
	assertNotNull(comp);

	JTree tree = findComponent(win, JTree.class);
	TreeTestUtils.selectTreeNodeByText(tree, "DiffTestPgm2");
	triggerActionKey(comp, 0, KeyEvent.VK_ESCAPE);
	waitForSwing();
	assertNull(fp2.getTopLevelAncestor());

	win = getWindow("Select Other Program");
	assertNull(win);
	closeProgram();
	assertNull(cb.getCurrentLocation());
}
 
Example 7
Source Project: zap-extensions   Source File: PopupInstantiateTemplate.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean isEnableForComponent(Component invoker) {
    if (invoker.getName() != null && invoker.getName().equals(ScriptsListPanel.TREE)) {
        try {
            JTree tree = (JTree) invoker;
            ScriptNode node = (ScriptNode) tree.getLastSelectedPathComponent();

            if (node == null
                    || !node.isTemplate()
                    || node.getUserObject() == null
                    || !(node.getUserObject() instanceof ScriptWrapper)) {
                return false;
            }

            if (((ScriptWrapper) node.getUserObject()).getEngine() == null) {
                return false;
            }

            return extension.getScriptsPanel().getSelectedScript() != null;
        } catch (Exception e) {
        }
    }
    return false;
}
 
Example 8
Source Project: marathonv5   Source File: RTree.java    License: Apache License 2.0 6 votes vote down vote up
private String getTextForNode(JTree tree, int row) {
    TreePath treePath = tree.getPathForRow(row);
    if (treePath == null) {
        return row + "";
    }
    StringBuilder sb = new StringBuilder();
    int start = tree.isRootVisible() ? 0 : 1;
    Object[] objs = treePath.getPath();
    for (int i = start; i < objs.length; i++) {
        String pathString;
        if (objs[i].toString() == null) {
            pathString = "";
        } else {
            pathString = escapeSpecialCharacters(getTextForNodeObject(tree, objs[i]));
        }
        sb.append("/" + pathString);
    }
    return sb.toString();
}
 
Example 9
/**
 * Returns the rendered cell for the supplied value.
 *
 * @param jtrHierarchy
 *            The JTree
 * @param value
 *            The value to assign to the cell
 * @param isSelected
 *            True if cell is selected
 * @param isExpanded
 *            True if cell is expanded
 * @param leaf
 *            True if cell is a lesaf
 * @param row
 *            The row of the cell to render
 * @param hasFocus
 *            If true, render cell appropriately
 * @return The renderered cell
 */
@Override
public Component getTreeCellRendererComponent(JTree jtrHierarchy, Object value, boolean isSelected,
		boolean isExpanded, boolean leaf, int row, boolean hasFocus) {
	JLabel cell = (JLabel) super.getTreeCellRendererComponent(jtrHierarchy, value, isSelected, isExpanded, leaf,
			row, hasFocus);

	DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;

	Object userObject = treeNode.getUserObject();

	if (userObject instanceof X509Certificate) {
		X509Certificate cert = (X509Certificate) userObject;

		cell.setText(X509CertUtil.getShortName(cert));

		ImageIcon icon = new ImageIcon(getClass().getResource(
				"images/certificate_node.png"));
		cell.setIcon(icon);

		cell.setToolTipText(X500NameUtils.x500PrincipalToX500Name(cert.getSubjectX500Principal()).toString());
	}

	return cell;
}
 
Example 10
@SwingThread
void expandToFirstLeaf(int max) {
    Debug.println("expand to first leaf");
    if (leavesShown()) {
        return;
    }
    JTree jTree = getTree();
    int i = 0;
    while (true) {
        int rows = jTree.getRowCount();
        if (i >= rows || rows >= max) {
            break;
        }
        TreePath treePath = jTree.getPathForRow(i);
        Object lastPathComponent = treePath.getLastPathComponent();
        if (lastPathComponent instanceof BugLeafNode) {
            return;
        }
        jTree.expandRow(i++);
    }
}
 
Example 11
Source Project: SmartIM   Source File: CheckBoxTreeCellRenderer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 返回的是一个<code>JPanel</code>对象,该对象中包含一个<code>JCheckBox</code>对象 和一个
 * <code>JLabel</code>对象。并且根据每个结点是否被选中来决定<code>JCheckBox</code> 是否被选中。
 */
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
    boolean leaf, int row, boolean hasFocus) {
    String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
    setEnabled(tree.isEnabled());
    if (value instanceof CheckBoxTreeNode) {
        check.setSelected(((CheckBoxTreeNode)value).isSelected());
    }
    label.setFont(tree.getFont());
    label.setText(stringValue);
    label.setSelected(selected);
    label.setFocus(hasFocus);
    if (leaf)
        label.setIcon(UIManager.getIcon("Tree.leafIcon"));
    else if (expanded)
        label.setIcon(UIManager.getIcon("Tree.openIcon"));
    else
        label.setIcon(UIManager.getIcon("Tree.closedIcon"));

    return this;
}
 
Example 12
Source Project: binnavi   Source File: CTagTreeCellRenderer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(final JTree tree,
    final Object value,
    final boolean sel,
    final boolean expanded,
    final boolean leaf,
    final int row,
    final boolean hasFocus) {
  final boolean selected = m_lastSelectionNode != null &&
      ((DefaultMutableTreeNode) value).getUserObject() == m_lastSelectionNode.getUserObject();

  super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, selected);

  setForeground(DEFAULT_FOREGROUND_COLOR);

  if (value instanceof CTagTreeNode) {
    renderTagTreeNode((CTagTreeNode) value);
  } else if (value instanceof CTaggedGraphNodeNode) {
    renderTaggedGraphNodeNode((CTaggedGraphNodeNode) value);
  } else if (value instanceof CTaggedGraphNodesContainerNode) {
    renderTaggedGraphNodesContainerNode((CTaggedGraphNodesContainerNode) value);
  }

  return this;
}
 
Example 13
Source Project: marathonv5   Source File: RTreeTest.java    License: Apache License 2.0 6 votes vote down vote up
public void singleNodeSelected() throws Throwable, InvocationTargetException {
    final JTree tree = (JTree) ComponentUtils.findComponent(JTree.class, frame);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    siw(new Runnable() {
        @Override
        public void run() {
            tree.expandRow(0);
            tree.setSelectionRow(0);
        }
    });
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override
        public void run() {
            Rectangle rowBounds = tree.getRowBounds(0);
            RTree rTree = new RTree(tree, null, rowBounds.getLocation(), lr);
            rTree.mouseButton1Pressed(null);
        }
    });
    Call call = lr.getCall();
    AssertJUnit.assertEquals("click", call.getFunction());
    AssertJUnit.assertEquals("/Root Node", call.getCellinfo());
}
 
Example 14
Source Project: binnavi   Source File: CProjectLoader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Loads a project inside a thread.
 * 
 * @param parent Parent window used for dialogs.
 * @param project Project to load.
 * @param projectTree Project tree to expand on project loading. This argument can be null.
 */
private static void loadProjectThreaded(final Window parent, final INaviProject project,
    final JTree projectTree) {
  Preconditions.checkNotNull(parent, "IE00005: Parent argument can not be null");

  Preconditions.checkNotNull(project, "IE01284: Project argument can not be null");

  if (project.isLoading()) {
    return;
  }

  new Thread() {
    @Override
    public void run() {
      loadProjectInternal(parent, project, projectTree);
    }
  }.start();
}
 
Example 15
Source Project: dragonwell8_jdk   Source File: MultiTreeUI.java    License: GNU General Public License v2.0 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 16
Source Project: binnavi   Source File: CModuleInitializeAction.java    License: Apache License 2.0 5 votes vote down vote up
public CModuleInitializeAction(final JTree projectTree, final INaviModule[] modules) {
  super(generateMenuEntryName(modules));

  m_projectTree =
      Preconditions.checkNotNull(projectTree, "IE01901: Project tree argument can not be null");
  m_modules =
      Preconditions.checkNotNull(modules, "IE01902: Module argument can't be null").clone();

  putValue(ACCELERATOR_KEY, HotKeys.INITIALIZE_MODULE_ACCELERATOR_KEY.getKeyStroke());
  putValue(MNEMONIC_KEY, (int) "HK_MENU_INITIALIZE_MODULE".charAt(0));
}
 
Example 17
Source Project: openjdk-jdk9   Source File: JTreeOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTree.setInvokesStopCellEditing(boolean)} through queue
 */
public void setInvokesStopCellEditing(final boolean b) {
    runMapping(new MapVoidAction("setInvokesStopCellEditing") {
        @Override
        public void map() {
            ((JTree) getSource()).setInvokesStopCellEditing(b);
        }
    });
}
 
Example 18
Source Project: jdk8u-dev-jdk   Source File: MultiTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>stopEditing</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 boolean stopEditing(JTree a) {
    boolean returnValue =
        ((TreeUI) (uis.elementAt(0))).stopEditing(a);
    for (int i = 1; i < uis.size(); i++) {
        ((TreeUI) (uis.elementAt(i))).stopEditing(a);
    }
    return returnValue;
}
 
Example 19
Source Project: jdk8u_jdk   Source File: MultiTreeUI.java    License: GNU General Public License v2.0 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 20
Source Project: openAGV   Source File: TreeMouseAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
  JTree objectTree = treeView.getTree();
  TreePath selPath = objectTree.getPathForLocation(e.getX(), e.getY());
  if (selPath == null) {
    if (e.getButton() == MouseEvent.BUTTON3) {
      showPopupMenu(e.getX(), e.getY());
    }
  }
  else {
    UserObject userObject = getUserObject(selPath);

    if (e.getButton() == MouseEvent.BUTTON3) {
      evaluateRightClick(e, userObject, treeView.getSelectedItems());
    }
    else if (e.getButton() == MouseEvent.BUTTON1) {

      //This Method tells the OpenTCSView what elements are currently selected
      ((AbstractUserObject) userObject).selectMultipleObjects();

      if (e.getClickCount() == 2) {
        userObject.doubleClicked();
      }

    }

  }

}
 
Example 21
public Component getTreeCellRendererComponentPersistent(JTree tree, Object value, boolean sel, boolean expanded,
                                                            boolean leaf, int row, boolean hasFocus) {
        LockContentionTreeCellRenderer renderer = new LockContentionTreeCellRenderer();
//        renderer.setLeafIcon(leafIcon);
//        renderer.setClosedIcon(closedIcon);
//        renderer.setOpenIcon(openIcon);

        return renderer.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    }
 
Example 22
Source Project: openjdk-jdk8u   Source File: MultiTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>isEditing</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 boolean isEditing(JTree a) {
    boolean returnValue =
        ((TreeUI) (uis.elementAt(0))).isEditing(a);
    for (int i = 1; i < uis.size(); i++) {
        ((TreeUI) (uis.elementAt(i))).isEditing(a);
    }
    return returnValue;
}
 
Example 23
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
                                              boolean leaf,
                                              int row, boolean hasFocus) {
    JLabel label = (JLabel) super.getTreeCellRendererComponent(tree,
                                                               value, sel,
                                                               expanded, leaf, row,
                                                               hasFocus);
    Layer layer = (Layer) value;
    if (ProductSceneView.BASE_IMAGE_LAYER_ID.equals(layer.getId())) {
        label.setText(String.format("<html><b>%s</b></html>", layer.getName()));
    }
    return label;

}
 
Example 24
Source Project: binnavi   Source File: CModuleNodeComponent.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new component object.
 *
 * @param projectTree Project tree that is updated when certain events happen.
 * @param database Database where the module is stored.
 * @param addressSpace Address space the module belongs to (this argument can be null in case of a
 *        global module).
 * @param module Module that provides the information displayed in the component.
 * @param container Container that represents the context in which the module is displayed.
 */
public CModuleNodeComponent(final JTree projectTree, final IDatabase database,
    final INaviAddressSpace addressSpace, final INaviModule module,
    final IViewContainer container) {
  super(new BorderLayout());

  Preconditions.checkNotNull(database, "IE01977: Database argument can't be null");
  this.module = Preconditions.checkNotNull(module, "IE01978: Module argument can't be null");

  // Note: the order of creating tabs must not be changed since, e.g., focusSectionAddress relies
  // upon a fixed index.
  tabbedPane.addTab("Overview", OVERVIEW_ICON, overviewPanel =
      new CModuleOverviewPanel(projectTree, database, addressSpace, module, container));
  tabbedPane.addTab("Functions" + String.format(" (%d)", module.getFunctionCount()),
      FUNCTIONS_ICON, functionsPanel =
          new CNativeFunctionViewsNodeComponent(projectTree, database, module, container));
  tabbedPane.addTab("Views" + String.format(" (%d)", module.getCustomViewCount()), VIEWS_ICON,
      viewsPanel = new CModuleViewsContainerComponent(projectTree, container));
  tabbedPane.addTab("Debug Traces", TRACES_ICON,
      tracesPanel = new CTracesNodeComponent(projectTree, container));
  tabbedPane.addTab(
      "Sections and Types", DATA_ICON, dataPanel = new CDataNodeComponent(module, container));

  tabbedPane.setEnabledAt(1, module.isLoaded());
  tabbedPane.setEnabledAt(2, module.isLoaded());
  tabbedPane.setEnabledAt(3, module.isLoaded());
  tabbedPane.setEnabledAt(4, module.isLoaded());

  module.addListener(internalModuleListener);

  add(tabbedPane);
  lookup.put(module, this);
}
 
Example 25
Source Project: WorldGrower   Source File: CommunityDialog.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void expandAllNodes(JTree tree, int startingIndex, int rowCount){
    for(int i=startingIndex;i<rowCount;++i){
        tree.expandRow(i);
    }

    if(tree.getRowCount()!=rowCount){
        expandAllNodes(tree, rowCount, tree.getRowCount());
    }
}
 
Example 26
Source Project: netbeans   Source File: BrowserUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void restoreState(final JTreeTable ttable, List paths, TreePath selected) {
    if (paths != null) {
        JTree tree = ttable.getTree();
        HeapWalkerNode root = (HeapWalkerNode)tree.getModel().getRoot();
        for (Object path : paths) ensurePathComputed(root, (TreePath)path, new HashSet());
        ttable.setup(paths, selected);
    }
}
 
Example 27
Source Project: pumpernickel   Source File: RepaintingDecoration.java    License: MIT License 5 votes vote down vote up
@Override
public Icon getIcon(JTree tree, Object value, boolean selected,
		boolean expanded, boolean leaf, int row, boolean isRollover,
		boolean isPressed) {
	return decoration.getIcon(tree, value, selected, expanded, leaf, row,
			isRollover, isPressed);
}
 
Example 28
Source Project: dsworkbench   Source File: ProfileTreeNodeRenderer.java    License: Apache License 2.0 5 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);

    try {
        DefaultMutableTreeNode node = ((DefaultMutableTreeNode) value);
        if (node.getUserObject() instanceof String) {
            setIcon(server);
        } else if (node.getUserObject() instanceof UserProfile) {
            if (((UserProfile) node.getUserObject()).isUVAccount()) {
                setIcon(uvProfile);
            } else {
                setIcon(mainProfile);
            }
        }
    } catch (Exception ignored) {
    }
    return this;
}
 
Example 29
Source Project: dragonwell8_jdk   Source File: MultiTreeUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>isEditing</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 boolean isEditing(JTree a) {
    boolean returnValue =
        ((TreeUI) (uis.elementAt(0))).isEditing(a);
    for (int i = 1; i < uis.size(); i++) {
        ((TreeUI) (uis.elementAt(i))).isEditing(a);
    }
    return returnValue;
}
 
Example 30
Source Project: marathonv5   Source File: DynamicTree.java    License: Apache License 2.0 5 votes vote down vote up
public DynamicTree() {
    super(new GridLayout(1, 0));

    rootNode = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(rootNode);
    treeModel.addTreeModelListener(new MyTreeModelListener());
    tree = new JTree(treeModel);
    tree.setEditable(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setShowsRootHandles(true);

    JScrollPane scrollPane = new JScrollPane(tree);
    add(scrollPane);
}
 
Example 31
Source Project: binnavi   Source File: CProjectTreeNode.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tells each child node to release its allocated resources.
 * 
 * @param tree The project tree.
 * @param component Component shown in the main window then the node is selected.
 * @param menuBuilder Creates the main menu and the context menu of the node.
 * @param object The object represented by the tree node.
 */
protected CProjectTreeNode(final JTree tree, final ILazyComponent component,
    final CAbstractMenuBuilder menuBuilder, final T object) {
  m_tree = Preconditions.checkNotNull(tree, "Error: tree argument can not be null");
  m_component =
      Preconditions.checkNotNull(component, "Error: component argument can not be null");
  m_menuBuilder =
      Preconditions.checkNotNull(menuBuilder, "Error: menuBuilder argument can not be null");
  m_object = object;
}
 
Example 32
@Override
public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean sel, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
  final DefaultTreeCellRenderer result = (DefaultTreeCellRenderer) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
  if (value instanceof Topic) {
    result.setIcon(getIconForTopic((Topic) value));
    result.setText(extractTextFromTopic((Topic) value));
  }
  return result;
}
 
Example 33
Source Project: openjdk-jdk9   Source File: JTreeOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTree.addSelectionPath(TreePath)} through queue
 */
public void addSelectionPath(final TreePath treePath) {
    runMapping(new MapVoidAction("addSelectionPath") {
        @Override
        public void map() {
            ((JTree) getSource()).addSelectionPath(treePath);
        }
    });
}
 
Example 34
Source Project: zap-extensions   Source File: AlertReportExportMenuItem.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean isEnableForComponent(Component invoker) {
    if (invoker.getName() != null && "treeAlert".equals(invoker.getName())) {
        JTree tree = (JTree) invoker;
        if (tree.getLastSelectedPathComponent() != null) {
            DefaultMutableTreeNode node =
                    (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            this.treeAlert = tree;
            if (!node.isRoot()) {
                return true;
            }
        }
    }
    return false;
}
 
Example 35
Source Project: jdk1.8-source-analysis   Source File: MultiTreeUI.java    License: Apache License 2.0 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 36
Source Project: jdk1.8-source-analysis   Source File: MultiTreeUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Invokes the <code>getPathForRow</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 TreePath getPathForRow(JTree a, int b) {
    TreePath returnValue =
        ((TreeUI) (uis.elementAt(0))).getPathForRow(a,b);
    for (int i = 1; i < uis.size(); i++) {
        ((TreeUI) (uis.elementAt(i))).getPathForRow(a,b);
    }
    return returnValue;
}
 
Example 37
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    DefaultMutableTreeNode node = ((DefaultMutableTreeNode)value);
    Object o = node.getUserObject();
    setText(o.toString());
    setOpaque(false);
    setToolTipText(null);
    if (o instanceof ConfigEntryNode) {
        ConfigEntryNode entry = (ConfigEntryNode)o;
        String key = entry.getKey();
        StringBuilder problems = new StringBuilder();
        for (ConfigConstraint constraint : config.getViolatedConstraints()) {
            if (constraint.getKeys().contains(key)) {
                if (problems.length() != 0) {
                    problems.append("\n");
                }
                problems.append(constraint.getDescription());
            }
        }
        if (problems.length() != 0) {
            setBackground(Color.RED);
            setOpaque(true);
            setToolTipText(problems.toString());
        }
    }
    return this;
}
 
Example 38
Source Project: DroidUIBuilder   Source File: MakeLayoutPane.java    License: Apache License 2.0 5 votes vote down vote up
private JTree initTreeLayoutExplore()
{
	final JTree treeLayoutExplore = new JTree(AndroidEditor.instance().getLayoutTreeModel());
	treeLayoutExplore.setShowsRootHandles(true);
	treeLayoutExplore.addTreeSelectionListener(new TreeSelectionListener(){
		public void valueChanged(TreeSelectionEvent arg0){
			Widget w = (Widget) treeLayoutExplore.getLastSelectedPathComponent();
			AndroidEditor.instance().select(w);
		}
	});
	treeLayoutExplore.setBorder(BorderFactory.createTitledBorder("Layout Explorer"));
	treeLayoutExplore.setMinimumSize(new Dimension(200, 400));
	return treeLayoutExplore;
}
 
Example 39
Source Project: gradle-view   Source File: DependencyViewerStandalone.java    License: Apache License 2.0 5 votes vote down vote up
public void updateView(GradleNode rootDependency, GradleNode selectedDependency) {
    // TODO replace this hack with something that populates the GradleNode graph

    DefaultMutableTreeNode fullRoot = new DefaultMutableTreeNode(new GradleNode("Project Dependencies"));
    if(rootDependency == null) {
        DefaultMutableTreeNode loading = new DefaultMutableTreeNode(new GradleNode("Loading..."));
        fullRoot.add(loading);
    } else {
        DefaultMutableTreeNode flattenedRoot = convertToSortedTreeNode(rootDependency);
        DefaultMutableTreeNode hierarchyRoot = convertToHierarchyTreeNode(rootDependency);
        fullRoot.add(flattenedRoot);
        fullRoot.add(hierarchyRoot);
    }

    TreeModel treeModel = new DefaultTreeModel(fullRoot);
    final JTree fullTree = new JTree(treeModel);
    fullTree.setCellRenderer(dependencyCellRenderer);

    // expand path for first level from root
    //fullTree.expandPath(new TreePath(hierarchyRoot.getNextNode().getPath()));

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            if(gradleBaseDir != null) {
                setTitle(TITLE + " - " + gradleBaseDir);
            }
            splitter.setLeftComponent(new JScrollPane(fullTree));
            splitter.setRightComponent(new JScrollPane(information));
            splitter.setDividerLocation(0.75);
        }
    });
}
 
Example 40
Source Project: visualvm   Source File: BrowserViewSupport.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Class getColumnClass(int column) {
    switch (column) {
        case 0: return JTree.class;
        case 1: return String.class;
        case 2: return Long.class;
        default: return null;
    }
}