Package javax.swing.tree

Examples of javax.swing.tree.TreeModel


      // add to tree
      viewer.addAnnotationToTree(annot);

      // inspect results
      TreeModel model = viewer.getSelectedAnnotationTree().getModel();
      DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
      assertEquals("Annotations", root.getUserObject().toString());
      DefaultMutableTreeNode typeNode = (DefaultMutableTreeNode) root.getChildAt(0);
      assertEquals("Example", typeNode.getUserObject().toString());
      DefaultMutableTreeNode fsNode = (DefaultMutableTreeNode) typeNode.getChildAt(0);
      Enumeration children = fsNode.children();
View Full Code Here


        visible. 
        @throws LocationUnavailableException if no matching path is found.
    */
    public static TreePath findMatchingPath(JTree tree, TreePath path) {
        Object[] input = path.getPath();
        TreeModel model = tree.getModel();
        Object root = model.getRoot();
        // If the root is not visible and it doesn't match the first path
        // element, start the path with the invisible root.
        if (!tree.isRootVisible()
            && !matchesLastComponent(tree, input[0], new TreePath(root))) {
            Object[] tmp = new Object[input.length+1];
View Full Code Here

        // The given array is a tree path of objects which may or may not be
        // node objects.  Convert them to existing tree objects if necessary.
        // Return null if any of them are not found.
        Log.debug("Comparing " + realPath + " with " + input[0]
                  + " from " + java.util.Arrays.asList(input));
        TreeModel model = tree.getModel();
        if (!matchesLastComponent(tree, input[0], realPath)) {
            Log.debug("no root match");
        }
        else {
            Log.debug("node matched: " + realPath.getLastPathComponent());
            if (input.length == 1)
                return realPath;

            Object[] subs = new Object[input.length-1];
            System.arraycopy(input, 1, subs, 0, subs.length);
            Object obj = realPath.getLastPathComponent();
            int count = model.getChildCount(obj);
            Log.debug("Obj " + obj + " (" + obj.getClass() + ") has " + count);
            // Find the right child to match
            for (int i=0;i < count;i++) {
                Log.debug("checking child " + i);
                Object child = model.getChild(obj, i);
                TreePath newPath =
                    findMatchingPath(tree, realPath.pathByAddingChild(child),
                                     subs);
                if (newPath != null) {
                    return newPath;
View Full Code Here

        Vector<Vector<String>> obj7 = new Vector<Vector<String>>();
        Vector<String> obj71 = new Vector<String>();
        obj71.add("node1");
        obj71.add("node2");
        obj7.add(obj71);
        TreeModel model = JTree.createTreeModel(obj1);
        assertTrue(model instanceof DefaultTreeModel);
        assertTrue(model.getRoot() instanceof DefaultMutableTreeNode);
        assertEquals("root", ((DefaultMutableTreeNode) model.getRoot()).getUserObject());
        assertEquals(3, model.getChildCount(model.getRoot()));
        assertTrue(model.getChild(model.getRoot(), 0) instanceof JTree.DynamicUtilTreeNode);
        model = JTree.createTreeModel(obj2);
        assertTrue(model instanceof DefaultTreeModel);
        assertTrue(model.getRoot() instanceof DefaultMutableTreeNode);
        assertEquals("root", ((DefaultMutableTreeNode) model.getRoot()).getUserObject());
        assertEquals(3, model.getChildCount(model.getRoot()));
        assertTrue(model.getChild(model.getRoot(), 0) instanceof JTree.DynamicUtilTreeNode);
        model = JTree.createTreeModel(obj3);
        assertTrue(model instanceof DefaultTreeModel);
        assertTrue(model.getRoot() instanceof DefaultMutableTreeNode);
        assertEquals("root", ((DefaultMutableTreeNode) model.getRoot()).getUserObject());
        assertEquals(3, model.getChildCount(model.getRoot()));
        assertTrue(model.getChild(model.getRoot(), 0) instanceof JTree.DynamicUtilTreeNode);
        assertTrue(((String) ((DefaultMutableTreeNode) ((DefaultMutableTreeNode) model
                .getRoot()).getChildAt(0)).getUserObject()).startsWith("node"));
        model = JTree.createTreeModel(obj4);
        assertTrue(model instanceof DefaultTreeModel);
        assertTrue(model.getRoot() instanceof DefaultMutableTreeNode);
        assertEquals("root", ((DefaultMutableTreeNode) model.getRoot()).getUserObject());
        assertEquals(0, model.getChildCount(model.getRoot()));
        model = JTree.createTreeModel(obj5);
        assertTrue(model instanceof DefaultTreeModel);
        assertTrue(model.getRoot() instanceof DefaultMutableTreeNode);
        assertEquals("root", ((DefaultMutableTreeNode) model.getRoot()).getUserObject());
        assertEquals(0, model.getChildCount(model.getRoot()));
        model = JTree.createTreeModel(obj6);
        assertTrue(model instanceof DefaultTreeModel);
        assertTrue(model.getRoot() instanceof DefaultMutableTreeNode);
        assertEquals("root", ((DefaultMutableTreeNode) model.getRoot()).getUserObject());
        assertEquals(0, model.getChildCount(model.getRoot()));
        model = JTree.createTreeModel(obj7);
        assertTrue(model instanceof DefaultTreeModel);
        assertTrue(model.getRoot() instanceof DefaultMutableTreeNode);
        assertEquals("root", ((DefaultMutableTreeNode) model.getRoot()).getUserObject());
        assertEquals(1, model.getChildCount(model.getRoot()));
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) model
                .getRoot()).getChildAt(0);
        assertTrue(child instanceof JTree.DynamicUtilTreeNode);
        assertEquals(obj71, child.getUserObject());
        assertEquals(2, child.getChildCount());
        assertTrue(model.getChild(child, 0) instanceof JTree.DynamicUtilTreeNode);
        model = JTree.createTreeModel(null);
        assertTrue(model instanceof DefaultTreeModel);
        assertTrue(model.getRoot() instanceof DefaultMutableTreeNode);
        assertEquals("root", ((DefaultMutableTreeNode) model.getRoot()).getUserObject());
        assertEquals(0, model.getChildCount(model.getRoot()));
    }
View Full Code Here

    public void testGetClosestRowForLocation() {
        assertEquals(0, tree.getClosestRowForLocation(-1000, -1000));
    }

    public void testGetDefaultTreeModel() {
        TreeModel model1 = JTree.getDefaultTreeModel();
        TreeModel model2 = JTree.getDefaultTreeModel();
        assertTrue(model1 instanceof DefaultTreeModel);
        assertNotSame(model1, model2);
        assertTrue(model1.getRoot() instanceof DefaultMutableTreeNode);
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model1.getRoot();
        assertEquals(3, root.getChildCount());
View Full Code Here

        buf.append( filter );
        buf.append( "\n" );
        results.setFilter( buf.toString() );

        TreeNode astRoot = new ASTNode( null, root );
        TreeModel treeModel = new DefaultTreeModel( astRoot, true );
        results.setTreeModel( treeModel );
        results.setTableModel( tableModel );
        centerOnScreen( results );
        results.setVisible( true );
        return true;
View Full Code Here

        AnnotatedFilterTreeDialog treeDialog = new AnnotatedFilterTreeDialog( PartitionFrame.this, false );
        treeDialog.setFilter( filter );

        partition.getSearchEngine().getOptimizer().annotate( root );
        TreeNode astRoot = new ASTNode( null, root );
        TreeModel model = new DefaultTreeModel( astRoot, true );
        treeDialog.setModel( model );
        treeDialog.setVisible( true );
        return true;
    }
View Full Code Here

   * Checks whether the model has been changed, and if so unregister and register listeners.
   */
  private final void checkModel()
  {
    // find out whether the model object (the TreeModel) has been changed
    TreeModel model = getModelObject();
    if (model != previousModel)
    {
      if (previousModel != null)
      {
        previousModel.removeTreeModelListener(this);
      }

      previousModel = model;

      if (model != null)
      {
        model.addTreeModelListener(this);
      }
      // model has been changed, redraw whole tree
      invalidateAll();
    }
  }
View Full Code Here

   *            The tree node
   * @return iterable presentation of node children
   */
  public final Iterator<Object> nodeChildren(Object node)
  {
    TreeModel model = getTreeModel();
    int count = model.getChildCount(node);
    List<Object> nodes = new ArrayList<Object>(count);
    for (int i = 0; i < count; ++i)
    {
      nodes.add(model.getChild(node, i));
    }
    return nodes.iterator();
  }
View Full Code Here

   * register listeners.
   */
  private final void checkModel()
  {
    // find out whether the model object (the TreeModel) has been changed
    TreeModel model = (TreeModel)getModelObject();
    if (model != previousModel)
    {
      if (previousModel != null)
      {
        previousModel.removeTreeModelListener(this);
      }

      previousModel = model;

      if (model != null)
      {
        model.addTreeModelListener(this);
      }
      // model has been changed, redraw whole tree
      invalidateAll();
    }
  }
View Full Code Here

TOP

Related Classes of javax.swing.tree.TreeModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.