Package javax.swing.tree

Examples of javax.swing.tree.TreeModel


  @Override
  protected void prepareActions() throws QTasteTestFailException {
    String[] nodeNames = mData[2].toString().split(mData[3].toString());
    if (component instanceof JTree && nodeNames.length > 0) {
      JTree tree = (JTree) component;
      TreeModel model = tree.getModel();
      Object node = model.getRoot();
      int pathLength = nodeNames.length;
      if ( !tree.isRootVisible() )
      {
        //root is not present in the list.
        pathLength += 1;
      }
      mPath = new Object[pathLength];
      String value = getNodeText(tree, node);
      if ( tree.isRootVisible() )
      {
        System.out.println("compare node (" + value + ") with root (" + nodeNames[0] + ")");
      }
      if (!tree.isRootVisible() || value.equals(nodeNames[0])) {
        mPath[0] = tree.getModel().getRoot();
        for (int i = 0; i < nodeNames.length; i++) {
          for (int childIndex = 0; childIndex < model.getChildCount(node); childIndex++) {
            Object child = model.getChild(node, childIndex);
            value = getNodeText(tree, child);;
            System.out.println("compare node (" + value + ") with value (" + nodeNames[i] + ")");
            if (value.equals(nodeNames[i])) {
              node = child;
              if ( tree.isRootVisible() )
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

                                                         paintBounds.y);
        Enumeration paintingEnumerator = treeState.getVisiblePathsFrom
                                              (initialPath);
        int row = treeState.getRowForPath(initialPath);
        int endY = paintBounds.y + paintBounds.height;
        TreeModel treeModel = tree.getModel();
        SynthContext cellContext = getContext(tree, Region.TREE_CELL);

        drawingCache.clear();

        setHashColor(context.getStyle().getColor(context,
                                                ColorType.FOREGROUND));

        if (paintingEnumerator != null) {
            // First pass, draw the rows

            boolean done = false;
            boolean isExpanded;
            boolean hasBeenExpanded;
            boolean isLeaf;
            Rectangle rowBounds = new Rectangle(0, 0, tree.getWidth(),0);
            Rectangle bounds;
            TreePath path;
            TreeCellRenderer renderer = tree.getCellRenderer();
            DefaultTreeCellRenderer dtcr = (renderer instanceof
                       DefaultTreeCellRenderer) ? (DefaultTreeCellRenderer)
                       renderer : null;

            configureRenderer(cellContext);
            while (!done && paintingEnumerator.hasMoreElements()) {
                path = (TreePath)paintingEnumerator.nextElement();
                bounds = getPathBounds(tree, path);
                if ((path != null) && (bounds != null)) {
                    isLeaf = treeModel.isLeaf(path.getLastPathComponent());
                    if (isLeaf) {
                        isExpanded = hasBeenExpanded = false;
                    }
                    else {
                        isExpanded = treeState.getExpandedState(path);
                        hasBeenExpanded = tree.hasBeenExpanded(path);
                    }
                    rowBounds.y = bounds.y;
                    rowBounds.height = bounds.height;
                    paintRow(renderer, dtcr, context, cellContext, g,
                             paintBounds, insets, bounds, rowBounds, path,
                             row, isExpanded, hasBeenExpanded, isLeaf);
                    if ((bounds.y + bounds.height) >= endY) {
                        done = true;
                    }
                }
                else {
                    done = true;
                }
                row++;
            }

            // Draw the connecting lines and controls.
            // Find each parent and have them draw a line to their last child
            boolean rootVisible = tree.isRootVisible();
            TreePath parentPath = initialPath;
            parentPath = parentPath.getParentPath();
            while (parentPath != null) {
                paintVerticalPartOfLeg(g, paintBounds, insets, parentPath);
                drawingCache.put(parentPath, Boolean.TRUE);
                parentPath = parentPath.getParentPath();
            }
            done = false;
            paintingEnumerator = treeState.getVisiblePathsFrom(initialPath);
            while (!done && paintingEnumerator.hasMoreElements()) {
                path = (TreePath)paintingEnumerator.nextElement();
                bounds = getPathBounds(tree, path);
                if ((path != null) && (bounds != null)) {
                    isLeaf = treeModel.isLeaf(path.getLastPathComponent());
                    if (isLeaf) {
                        isExpanded = hasBeenExpanded = false;
                    }
                    else {
                        isExpanded = treeState.getExpandedState(path);
View Full Code Here

                                                         paintBounds.y);
  Enumeration paintingEnumerator = treeState.getVisiblePathsFrom
                                        (initialPath);
  int row = treeState.getRowForPath(initialPath);
  int endY = paintBounds.y + paintBounds.height;
        TreeModel treeModel = tree.getModel();
        SynthContext cellContext = getContext(tree, Region.TREE_CELL);

  drawingCache.clear();

        setHashColor(context.getStyle().getColor(context,
                                                ColorType.FOREGROUND));

  if (paintingEnumerator != null) {
            // First pass, draw the rows

      boolean done = false;
      boolean isExpanded;
      boolean hasBeenExpanded;
      boolean isLeaf;
      Rectangle boundsBuffer = new Rectangle();
            Rectangle rowBounds = new Rectangle(0, 0, tree.getWidth(),0);
      Rectangle bounds;
      TreePath path;
            TreeCellRenderer renderer = tree.getCellRenderer();
            DefaultTreeCellRenderer dtcr = (renderer instanceof
                       DefaultTreeCellRenderer) ? (DefaultTreeCellRenderer)
                       renderer : null;

            configureRenderer(cellContext);
      while (!done && paintingEnumerator.hasMoreElements()) {
    path = (TreePath)paintingEnumerator.nextElement();
    if (path != null) {
        isLeaf = treeModel.isLeaf(path.getLastPathComponent());
        if (isLeaf) {
      isExpanded = hasBeenExpanded = false;
                    }
        else {
      isExpanded = treeState.getExpandedState(path);
      hasBeenExpanded = tree.hasBeenExpanded(path);
        }
                    bounds = getPathBounds(tree, path);
                    rowBounds.y = bounds.y;
                    rowBounds.height = bounds.height;
        paintRow(renderer, dtcr, context, cellContext, g,
                             paintBounds, insets, bounds, rowBounds, path,
                             row, isExpanded, hasBeenExpanded, isLeaf);
        if ((bounds.y + bounds.height) >= endY) {
      done = true;
                    }
    }
    else {
        done = true;
    }
    row++;
      }

      // Draw the connecting lines and controls.
      // Find each parent and have them draw a line to their last child
            boolean rootVisible = tree.isRootVisible();
            TreePath parentPath = initialPath;
      parentPath = parentPath.getParentPath();
      while (parentPath != null) {
                paintVerticalPartOfLeg(g, paintBounds, insets, parentPath);
    drawingCache.put(parentPath, Boolean.TRUE);
    parentPath = parentPath.getParentPath();
      }
      done = false;
            paintingEnumerator = treeState.getVisiblePathsFrom(initialPath);
      while (!done && paintingEnumerator.hasMoreElements()) {
    path = (TreePath)paintingEnumerator.nextElement();
    if (path != null) {
        isLeaf = treeModel.isLeaf(path.getLastPathComponent());
        if (isLeaf) {
      isExpanded = hasBeenExpanded = false;
                    }
        else {
      isExpanded = treeState.getExpandedState(path);
View Full Code Here

                                 insets.top,
                                 tree.getWidth() - insets.left - insets.right,
                                 0);
        } else {
            int row = tree.getRowForPath(path);
            TreeModel model = getModel();
            Object root = model.getRoot();

            if (path.getLastPathComponent() == root
                    && index >= model.getChildCount(root)) {

                rect = tree.getRowBounds(tree.getRowCount() - 1);
                rect.y = rect.y + rect.height;
                Rectangle xRect;

                if (!tree.isRootVisible()) {
                    xRect = tree.getRowBounds(0);
                } else if (model.getChildCount(root) == 0){
                    xRect = tree.getRowBounds(0);
                    xRect.x += totalChildIndent;
                    xRect.width -= totalChildIndent + totalChildIndent;
                } else {
                    TreePath lastChildPath = path.pathByAddingChild(
                        model.getChild(root, model.getChildCount(root) - 1));
                    xRect = tree.getPathBounds(lastChildPath);
                }

                rect.x = xRect.x;
                rect.width = xRect.width;
            } else {
                rect = tree.getPathBounds(path.pathByAddingChild(
                    model.getChild(path.getLastPathComponent(), index)));
            }
        }

        if (rect.y != 0) {
            rect.y--;
View Full Code Here

      {
        if( tp == null )
          return;

        Object node = tp.getLastPathComponent();
        TreeModel model = mainTree.getModel();
        if( !model.isLeaf( node ) )
        {
          mainTree.expandPath( tp );
          for( int i = 0; i < model.getChildCount( node ); i++ )
          {
            expandAll( tp.pathByAddingChild( model.getChild( node, i ) ) );
          }
        }
      }
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 = (TreeModel)getDefaultModelObject();
    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

   * @param node
   * @return image resource reference
   */
  protected ResourceReference getImageResourceReference(BaseTree tree, Object node)
  {
    TreeModel model = (TreeModel)tree.getDefaultModelObject();
    if (model.isLeaf(node))
    {
      return getResourceItemLeaf(node);
    }
    else
    {
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.