Java Code Examples for javax.swing.tree.DefaultTreeModel

The following examples show how to use javax.swing.tree.DefaultTreeModel. 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 check out the related API usage on the sidebar.
Example 1
Source Project: Zettelkasten   Source File: TreeUtil.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method selects the first entry in a jTree that start with the text
 * that is entered in the filter-textfield.
 *
 * @param tree the jTree where the item should be selected
 * @param textfield the related filtertextfield that contains the user-input
 */
public static void selectByTyping(javax.swing.JTree tree, javax.swing.JTextField textfield) {
    DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel();
    MutableTreeNode root = (MutableTreeNode) dtm.getRoot();
    String text = textfield.getText().toLowerCase();
    if (root != null && !text.isEmpty()) {
        for (int cnt = 0; cnt < dtm.getChildCount(root); cnt++) {
            MutableTreeNode child = (MutableTreeNode) dtm.getChild(root, cnt);
            String childtext = child.toString().toLowerCase();
            if (childtext.startsWith(text)) {
                TreePath tp = new TreePath(root);
                tp = tp.pathByAddingChild(child);
                tree.setSelectionPath(tp);
                tree.scrollPathToVisible(tp);
                return;
            }
        }
    }
}
 
Example 2
Source Project: Luyten   Source File: Model.java    License: Apache License 2.0 6 votes vote down vote up
public void closeFile() {
	for (OpenFile co : hmap) {
		int pos = house.indexOfTab(co.name);
		if (pos >= 0)
			house.remove(pos);
		co.close();
	}

	final State oldState = state;
	Model.this.state = null;
	if (oldState != null) {
		Closer.tryClose(oldState);
	}

	hmap.clear();
	tree.setModel(new DefaultTreeModel(null));
	metadataSystem = new MetadataSystem(typeLoader);
	file = null;
	treeExpansionState = null;
	open = false;
	mainWindow.onFileLoadEnded(file, open);
}
 
Example 3
Source Project: consulo   Source File: TemplateListPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void createTemplateEditor(final TemplateImpl template,
                                  String shortcut,
                                  Map<TemplateOptionalProcessor, Boolean> options,
                                  Map<TemplateContextType, Boolean> context) {
  myCurrentTemplateEditor = new LiveTemplateSettingsEditor(template, shortcut, options, context, new Runnable() {
    @Override
    public void run() {
      DefaultMutableTreeNode node = getNode(getSingleSelectedIndex());
      if (node != null) {
        ((DefaultTreeModel)myTree.getModel()).nodeChanged(node);
        TemplateSettings.getInstance().setLastSelectedTemplate(template.getGroupName(), template.getKey());
      }
    }
  }, TemplateSettings.getInstance().getTemplate(template.getKey(), template.getGroupName()) != null);
  for (Component component : myDetailsPanel.getComponents()) {
    if (component instanceof LiveTemplateSettingsEditor) {
      myDetailsPanel.remove(component);
    }
  }

  myDetailsPanel.add(myCurrentTemplateEditor, TEMPLATE_SETTINGS);
}
 
Example 4
Source Project: jdk8u-jdk   Source File: Test8015926.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 5
Source Project: jdk8u_jdk   Source File: XSheet.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Update the label of the supplied MBean tree node.
 */
// Call on EDT
private void updateNotificationsNodeLabel(
        DefaultMutableTreeNode node, String label) {
    synchronized (mbeansTab.getTree()) {
        invalidate();
        XNodeInfo oldUserObject = (XNodeInfo) node.getUserObject();
        XNodeInfo newUserObject = new XNodeInfo(
                oldUserObject.getType(), oldUserObject.getData(),
                label, oldUserObject.getToolTipText());
        node.setUserObject(newUserObject);
        DefaultTreeModel model =
                (DefaultTreeModel) mbeansTab.getTree().getModel();
        model.nodeChanged(node);
        validate();
        repaint();
    }
}
 
Example 6
Source Project: nosql4idea   Source File: MongoEditionPanel.java    License: Apache License 2.0 6 votes vote down vote up
public void addValue(Object value) {
    List<TreeNode> node = new LinkedList<TreeNode>();

    NoSqlTreeNode parentNode = getParentNode();

    NoSqlTreeNode treeNode = new NoSqlTreeNode(MongoValueDescriptor.createDescriptor(parentNode.getChildCount(), value));
    if (value instanceof DBObject) {
        JsonTreeModel.processDbObject(treeNode, (DBObject) value);
    }

    node.add(treeNode);

    DefaultTreeModel treeModel = (DefaultTreeModel) editTableView.getTree().getModel();
    TreeUtil.addChildrenTo(parentNode, node);
    treeModel.reload(parentNode);
}
 
Example 7
Source Project: hottub   Source File: XSheet.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Update the label of the supplied MBean tree node.
 */
// Call on EDT
private void updateNotificationsNodeLabel(
        DefaultMutableTreeNode node, String label) {
    synchronized (mbeansTab.getTree()) {
        invalidate();
        XNodeInfo oldUserObject = (XNodeInfo) node.getUserObject();
        XNodeInfo newUserObject = new XNodeInfo(
                oldUserObject.getType(), oldUserObject.getData(),
                label, oldUserObject.getToolTipText());
        node.setUserObject(newUserObject);
        DefaultTreeModel model =
                (DefaultTreeModel) mbeansTab.getTree().getModel();
        model.nodeChanged(node);
        validate();
        repaint();
    }
}
 
Example 8
Source Project: JByteMod-Beta   Source File: ClassTree.java    License: GNU General Public License v2.0 6 votes vote down vote up
public ClassTree(JByteMod jam) {
  this.jbm = jam;
  this.setRootVisible(false);
  this.setShowsRootHandles(true);
  this.setCellRenderer(new TreeCellRenderer());
  this.addTreeSelectionListener(new TreeSelectionListener() {
    public void valueChanged(TreeSelectionEvent e) {
      SortedTreeNode node = (SortedTreeNode) ClassTree.this.getLastSelectedPathComponent();
      if (node == null)
        return;
      if (node.getCn() != null && node.getMn() != null) {
        jam.selectMethod(node.getCn(), node.getMn());
      } else if (node.getCn() != null) {
        jam.selectClass(node.getCn());
      } else {

      }
    }
  });
  this.model = new DefaultTreeModel(new SortedTreeNode(""));
  this.setModel(model);
  this.setTransferHandler(new JarDropHandler(this, 0));
  this.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
}
 
Example 9
Source Project: mobile-persistence   Source File: GeneratorLogPage.java    License: MIT License 6 votes vote down vote up
protected void logTree (final TreeNode node)
{ 
  Runnable runner = 
    new Runnable()
    {
      public void run()
      {
        setModel(new DefaultTreeModel(node));
        getTree().expandPath(errorsPath);
        getTree().expandPath(runwarningsPath);
        getTree().expandPath(warningsPath);
        getTree().expandPath(informationPath);
        getTree().scrollRowToVisible(getTree().getRowCount()-1);
      }
    };

  if (!SwingUtilities.isEventDispatchThread())
  {
    SwingUtilities.invokeLater(runner);  
  }
  else
  {
    runner.run();
  }
}
 
Example 10
Source Project: jdk8u-jdk   Source File: Test8015926.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 11
Source Project: netbeans-mmd-plugin   Source File: KnowledgeViewPane.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public JComponent createComponent() {
  if (myComponent != null) {
    return myComponent;
  }

  DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(null);
  DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
  myTree = createTree(treeModel);
  enableDnD();
  myComponent = ScrollPaneFactory.createScrollPane(myTree);
  myTreeStructure = createStructure();
  setTreeBuilder(createBuilder(treeModel));

  installComparator();
  initTree();

  return myComponent;
}
 
Example 12
Source Project: netbeans   Source File: HintsPanelLogic.java    License: Apache License 2.0 6 votes vote down vote up
void connect( JTree errorTree, DefaultTreeModel errModel, JComboBox severityComboBox, 
              JCheckBox tasklistCheckBox, JPanel customizerPanel,
              JEditorPane descriptionTextArea) {
    
    this.errorTree = errorTree;
    this.errModel = errModel;
    this.severityComboBox = severityComboBox;
    this.tasklistCheckBox = tasklistCheckBox;
    this.customizerPanel = customizerPanel;
    this.descriptionTextArea = descriptionTextArea;        
    
    valueChanged( null );
    
    errorTree.addKeyListener(this);
    errorTree.addMouseListener(this);
    errorTree.getSelectionModel().addTreeSelectionListener(this);
        
    severityComboBox.addActionListener(this);
    tasklistCheckBox.addChangeListener(this);
    
}
 
Example 13
Source Project: QLExpress   Source File: FileTree.java    License: Apache License 2.0 6 votes vote down vote up
public void initData(String  rootPath){
        File f=new File(rootPath);
        PathNode root=new PathNode(f.getName(), rootPath,f.isDirectory());
        File[] files=f.listFiles();
        for(int i=0;i<files.length;i++){
        	if(files[i].isDirectory() || files[i].getName().endsWith(".ql")){
        		PathNode node=new PathNode(files[i].getName(), files[i].getAbsolutePath(),files[i].isDirectory());
        		root.add(node);
        	}
        }
        model=new DefaultTreeModel(root);
        this.setModel(model);
        FileTreeRenderer renderer=new FileTreeRenderer();
        this.setCellRenderer(renderer);
        this.repaint();
}
 
Example 14
Source Project: bigtable-sql   Source File: RecentFilesController.java    License: Apache License 2.0 6 votes vote down vote up
private void onRemoveSelected()
{

   HashSet<DefaultMutableTreeNode> changedParents = new HashSet<DefaultMutableTreeNode>();
   TreePath[] paths = _dialog.treFiles.getSelectionPaths();

   DefaultTreeModel model = (DefaultTreeModel) _dialog.treFiles.getModel();
   for (TreePath path : paths)
   {
      DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) path.getLastPathComponent();
      if( dmtn.getUserObject() instanceof File )
      {
         model.removeNodeFromParent(dmtn);
         changedParents.add((DefaultMutableTreeNode) path.getParentPath().getLastPathComponent());
      }
   }

   for (DefaultMutableTreeNode changedParent : changedParents)
   {
      model.nodeStructureChanged(changedParent);
   }

   writeUiTreeToModel();

}
 
Example 15
Source Project: hottub   Source File: Test8015926.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 16
protected static TreeModel getTreeModel() {
    root = new DefaultMutableTreeNode("Root");

    a = new DefaultMutableTreeNode("A");
    root.add(a);
    a1 = new DefaultMutableTreeNode("a1");
    a.add(a1);

    b = new DefaultMutableTreeNode("B");
    root.add(b);
    b1 = new DefaultMutableTreeNode("b1");
    b.add(b1);
    b2 = new DefaultMutableTreeNode("b2");
    b.add(b2);

    c = new DefaultMutableTreeNode("C");
    root.add(c);
    c1 = new DefaultMutableTreeNode("c1");
    c.add(c1);
    return new DefaultTreeModel(root);
}
 
Example 17
Source Project: rest-client   Source File: JSONTree.java    License: Apache License 2.0 6 votes vote down vote up
/**
* 
* @Title      : JSONTree 
* @Description: Default constructor 
* @Param      :
 */
public JSONTree()
{
    super(new GridLayout(1, 0));

    rootNode = new CheckBoxTreeNode(RESTConst.JSON);
    treeModel = new DefaultTreeModel(rootNode);

    tree = new JTree(treeModel);
    tree.setCellRenderer(new CheckBoxTreeCellRenderer());
    tree.setEditable(false);
    tree.setToolTipText(RESTConst.EXCLUDE_NODE);
    tree.setShowsRootHandles(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addMouseListener(ma);

    JScrollPane scrollPane = new JScrollPane(tree);
    this.add(scrollPane);
    this.initPopupMenu();
}
 
Example 18
Source Project: nosql4idea   Source File: NoSqlExplorerPanel.java    License: Apache License 2.0 6 votes vote down vote up
public void reloadAllServerConfigurations() {
    this.databaseVendorClientManager.cleanUpServers();
    databaseTree.setRootVisible(false);

    List<ServerConfiguration> serverConfigurations = getServerConfigurations();
    if (serverConfigurations.size() == 0) {
        databaseTree.setModel(null);
        return;
    }

    final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    databaseTree.setModel(new DefaultTreeModel(rootNode));

    for (ServerConfiguration serverConfiguration : serverConfigurations) {
        DatabaseServer mongoServer = new DatabaseServer(serverConfiguration);
        this.databaseVendorClientManager.registerServer(mongoServer);
        DefaultMutableTreeNode serverNode = new DefaultMutableTreeNode(mongoServer);
        rootNode.add(serverNode);
        if (serverConfiguration.isConnectOnIdeStartup()) {
            this.reloadServerConfiguration(serverNode, false);
        }
    }

    TreeUtil.expand(databaseTree, 2);
}
 
Example 19
Source Project: pumpernickel   Source File: AquaLocationSourceList.java    License: MIT License 6 votes vote down vote up
public AquaLocationSourceList(LocationHistory directoryStack,
		GraphicCache graphicCache) {
	super(new DefaultTreeModel(new DefaultMutableTreeNode("root")));

	treeModel = (DefaultTreeModel) getModel();
	root = (DefaultMutableTreeNode) treeModel.getRoot();

	this.directoryStack = directoryStack;
	this.graphicCache = graphicCache;

	treeModel.insertNodeInto(devices, root, 0);
	treeModel.insertNodeInto(places, root, 1);
	addTreeSelectionListener(treeSelectionListener);
	directoryStack.addChangeListener(directoryStackListener);
	setExpandsSelectedPaths(true);
	setCellRenderer(new SourceListLocationRenderer(graphicCache, this));
	getSelectionModel().setSelectionMode(
			TreeSelectionModel.SINGLE_TREE_SELECTION);
	setUI(new SourceListTreeUI(this));

	expandPath(new TreePath(devices.getPath()));
	expandPath(new TreePath(places.getPath()));
}
 
Example 20
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
@Override public boolean importData(TransferHandler.TransferSupport support) {
  DefaultMutableTreeNode[] nodes;
  try {
    Transferable t = support.getTransferable();
    nodes = (DefaultMutableTreeNode[]) t.getTransferData(FLAVOR);
  } catch (UnsupportedFlavorException | IOException ex) {
    return false;
  }
  TransferHandler.DropLocation tdl = support.getDropLocation();
  if (tdl instanceof JTree.DropLocation) {
    JTree.DropLocation dl = (JTree.DropLocation) tdl;
    int childIndex = dl.getChildIndex();
    TreePath dest = dl.getPath();
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) dest.getLastPathComponent();
    JTree tree = (JTree) support.getComponent();
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    AtomicInteger idx = new AtomicInteger(childIndex < 0 ? parent.getChildCount() : childIndex);
    Stream.of(nodes).forEach(node -> {
      DefaultMutableTreeNode clone = new DefaultMutableTreeNode(node.getUserObject());
      model.insertNodeInto(deepCopyTreeNode(node, clone), parent, idx.incrementAndGet());
    });
    return true;
  }
  return false;
}
 
Example 21
Source Project: Llunatic   Source File: StatefulView.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void scrollToNode(final Node n) {
    // has to be delayed to be sure that events for Visualizers
    // were processed and TreeNodes are already in hierarchy
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            TreeNode tn = Visualizer.findVisualizer(n);
            if (tn == null) {
                return;
            }
            TreeModel model = tree.getModel();
            if (!(model instanceof DefaultTreeModel)) {
                return;
            }
            TreePath path = new TreePath(((DefaultTreeModel) model).getPathToRoot(tn));
            Rectangle r = tree.getPathBounds(path);
            if (r != null) {
                tree.scrollRectToVisible(r);
            }
        }
    });
}
 
Example 22
Source Project: openjdk-jdk8u   Source File: Test8015926.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 23
Source Project: TrakEM2   Source File: ProjectTree.java    License: GNU General Public License v3.0 6 votes vote down vote up
/** Move up (-1) or down (1). */
private void move(final DefaultMutableTreeNode node, final int direction) {
	final ProjectThing pt = (ProjectThing)node.getUserObject();
	if (null == pt) return;
	// Move: within the list of children of the parent ProjectThing:
	if (!pt.move(direction)) return;
	// If moved, reposition within the list of children
	final DefaultMutableTreeNode parent_node = (DefaultMutableTreeNode)node.getParent();
	int index = parent_node.getChildCount() -1;
	((DefaultTreeModel)this.getModel()).removeNodeFromParent(node);
	index = pt.getParent().getChildren().indexOf(pt);
	((DefaultTreeModel)this.getModel()).insertNodeInto(node, parent_node, index);
	// restore selection path
	final TreePath trp = new TreePath(node.getPath());
	this.scrollPathToVisible(trp);
	this.setSelectionPath(trp);
	this.updateUILater();
}
 
Example 24
Source Project: marathonv5   Source File: RTreeTest.java    License: Apache License 2.0 6 votes vote down vote up
public void singleNodeWithSpecialChars() 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() {
            DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
            DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
            root.setUserObject("Root Node [] , / Special");
            tree.expandRow(0);
            tree.setSelectionRow(0);
        }
    });
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override
        public void run() {
            Rectangle cb = tree.getPathBounds(tree.getPathForRow(0));
            RTree rTree = new RTree(tree, null, new Point(cb.x + 2, cb.y + 2), lr);
            rTree.mouseButton1Pressed(null);
        }
    });
    Call call = lr.getCall();
    AssertJUnit.assertEquals("click", call.getFunction());
    AssertJUnit.assertEquals("/Root Node [] , \\/ Special", call.getCellinfo());
}
 
Example 25
Source Project: netbeans   Source File: ExcludeDependencyPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void setReferenceTree(CheckNode mtb) {
    Artifact art = (Artifact) mtb.getUserObject();
    if (modelCache.containsKey(art)) {
        trRef.setModel(modelCache.get(art));
    } else {
        if (rootnode == null) {
            trRef.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
        } else {
            DependencyExcludeNodeVisitor nv = new DependencyExcludeNodeVisitor(art.getGroupId(), art.getArtifactId(), art.getType());
            rootnode.accept(nv);
            Set<DependencyNode> nds = nv.getDirectDependencies();
            DefaultTreeModel dtm = new DefaultTreeModel(createReferenceModel(nds, mtb));
            trRef.setModel(dtm);
            modelCache.put(art, dtm);
        }
    }
}
 
Example 26
Source Project: jdk8u-dev-jdk   Source File: XSheet.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Update the label of the supplied MBean tree node.
 */
// Call on EDT
private void updateNotificationsNodeLabel(
        DefaultMutableTreeNode node, String label) {
    synchronized (mbeansTab.getTree()) {
        invalidate();
        XNodeInfo oldUserObject = (XNodeInfo) node.getUserObject();
        XNodeInfo newUserObject = new XNodeInfo(
                oldUserObject.getType(), oldUserObject.getData(),
                label, oldUserObject.getToolTipText());
        node.setUserObject(newUserObject);
        DefaultTreeModel model =
                (DefaultTreeModel) mbeansTab.getTree().getModel();
        model.nodeChanged(node);
        validate();
        repaint();
    }
}
 
Example 27
Source Project: ApkToolPlus   Source File: ClasspathEntry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method to get a node or add a new class of package node to
 * a parent node. New nodes will be added in correct sort order, packages first.
 * @param newNodeName the name of the new node.
 * @param parentNode the parent node.
 * @param packageNode whether the new node is a package node or not.
 * @param model the tree model.
 * @param reset whether a reset operation is in progress.
 * @return the fould or created node.
 */
protected ClassTreeNode addOrFindNode(String newNodeName,
                                      ClassTreeNode parentNode,
                                      boolean packageNode,
                                      DefaultTreeModel model,
                                      boolean reset)
{
    int childCount = parentNode.getChildCount();

    ClassTreeNode newNode = new ClassTreeNode(newNodeName, packageNode);
    for (int i = 0; i < childCount; i++) {
        ClassTreeNode childNode = (ClassTreeNode)parentNode.getChildAt(i);
        String childNodeName = childNode.toString();
        if (childNode.getChildCount() > 0 && !packageNode) {
            continue;
        } else if (childNode.getChildCount() == 0 && packageNode) {
            insertNode(newNode, parentNode, i, model, reset);
            return newNode;
        } else if (newNodeName.equals(childNodeName)) {
            return childNode;
        } else if (newNodeName.compareTo(childNodeName) < 0) {
            insertNode(newNode, parentNode, i, model, reset);
            return newNode;
        }
    }
    insertNode(newNode, parentNode, childCount, model, reset);

    return newNode;
}
 
Example 28
Source Project: zap-extensions   Source File: HttpMessageSelectorPanel.java    License: Apache License 2.0 5 votes vote down vote up
public HttpMessageSelectorPanel() {
    panel = new JPanel();
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setAutoCreateGaps(true);

    SiteNode root =
            new SiteNode(
                    null,
                    -1,
                    Constant.messages.getString(
                            "fuzz.httpfuzzer.select.message.dialogue.rootNode"));
    SiteNode mainTreeRoot = Model.getSingleton().getSession().getSiteTree().getRoot();
    copyTree(mainTreeRoot, root);
    messagesTreeModel = new DefaultTreeModel(root);

    messagesTree = new JTree(messagesTreeModel);
    messagesTree.setVisibleRowCount(10);
    messagesTree.setShowsRootHandles(true);
    messagesTree.setName("HttpMessageSelectorTree");
    messagesTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    messagesTree.setCellRenderer(
            new SiteMapTreeCellRenderer(Collections.<SiteMapListener>emptyList()));
    messagesTree.expandRow(0);

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(messagesTree);

    layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(scrollPane));
    layout.setVerticalGroup(layout.createSequentialGroup().addComponent(scrollPane));
}
 
Example 29
Source Project: consulo   Source File: InspectionRVContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
private static void processDepth(@Nullable DefaultTreeModel model, final InspectionTreeNode child, final InspectionTreeNode current) {
  InspectionTreeNode[] children = new InspectionTreeNode[child.getChildCount()];
  for (int i = 0; i < children.length; i++) {
    children[i] = (InspectionTreeNode)child.getChildAt(i);
  }
  for (InspectionTreeNode node : children) {
    merge(model, node, current, true);
  }
}
 
Example 30
Source Project: myqq   Source File: MyTree.java    License: MIT License 5 votes vote down vote up
/**
 * 初始化
 */
public void init()
{	
	tree.setRootVisible(false);//设置根节点不可见
       tree.setAutoscrolls(true);//设置自动滚动
       tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);//设置单选模式
       
       nodeImages=new ArrayList<String>();
       nodeImages.add("所有在线用户"+MyTools.SPLIT1+"../img/face/f023.png"+MyTools.SPLIT1+"../img/face/f019.png");
       nodeImages.add("所有不在线用户"+MyTools.SPLIT1+"../img/face/f035.png"+MyTools.SPLIT1+"../img/face/f033.png");
       nodeImages.add("我的好友"+MyTools.SPLIT1+"../img/face/f051.png"+MyTools.SPLIT1+"../img/face/f049.png");
       DefaultMutableTreeNode root=new DefaultMutableTreeNode("root");
       treeModel=new DefaultTreeModel(root);//新建一个用于存放好友树的Model
       for(int i=0;i<groupNames.length;i++)
       {
       	DefaultMutableTreeNode node=new DefaultMutableTreeNode(groupNames[i]);
       
       	for(int j=0;j<friendInfos.get(i).length;j++)
       	{
       		String[] temp=friendInfos.get(i)[j].split(MyTools.SPLIT3);
       		//System.out.println(friendInfos.get(i)[j]);
       		String friendName=temp[0];//好友用户名
       		String ip=temp[1];//好友IP地址
       		String port=temp[2];//好友的端口号
       		String headImage=temp[3];//好友头像
       		String state=temp[4];//状态
       		nodeImages.add(friendName+MyTools.SPLIT1+"../img/headImage/small/"+headImage+"_32.jpg");
       		node.add(new DefaultMutableTreeNode(friendName+"("+ip+":"+port+")"));
       	}
       	root.add(node);
       }
       tree.setCellRenderer(new MyTreeIcon(nodeImages));
       tree.setModel(treeModel);  
}