Package javax.swing.tree

Examples of javax.swing.tree.DefaultTreeModel


      //      toolBarPanel.add(m_toolBars, BorderLayout.CENTER);

      //    add(m_toolBars, BorderLayout.NORTH);
      add(toolBarPanel, BorderLayout.NORTH);

      DefaultTreeModel model = new DefaultTreeModel(jtreeRoot);

      // subclass JTree so that tool tips can be displayed for leaves (if necessary)
      m_componentTree = new JTree(model) {
        public String getToolTipText(MouseEvent e) {
          if ((getRowForLocation(e.getX(), e.getY())) == -1) {
            return null;
          }
          TreePath currPath = getPathForLocation(e.getX(), e.getY());
          if (currPath.getLastPathComponent() instanceof DefaultMutableTreeNode) {
            DefaultMutableTreeNode node =
              (DefaultMutableTreeNode)currPath.getLastPathComponent();
            if (node.isLeaf()) {
              JTreeLeafDetails leaf = (JTreeLeafDetails)node.getUserObject();
              return leaf.getToolTipText();
            }
          }
          return null;
        }     
      };

      m_componentTree.setEnabled(true);
      m_componentTree.setToolTipText("");
      m_componentTree.setRootVisible(false);
      m_componentTree.setShowsRootHandles(true);
      m_componentTree.setCellRenderer(new BeanIconRenderer());
      DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
      selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
      m_componentTree.setSelectionModel(selectionModel);

      m_componentTree.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {

          if (((e.getModifiers() & InputEvent.BUTTON1_MASK)
              != InputEvent.BUTTON1_MASK) || e.isAltDown()) {
            boolean clearSelection = true;
            /*TreePath path =
                m_componentTree.getPathForLocation(e.getX(), e.getY());
              if (path != null) {
                DefaultMutableTreeNode tNode =
                  (DefaultMutableTreeNode)path.getLastPathComponent();

                if (tNode.isLeaf()) {
                  System.out.println("Rick click selection");

//                  m_componentTree.setSelectionPath(path);
                }
              }*/

            if (clearSelection) {
              // right click cancels selected component
              m_toolBarBean = null;
              m_mode = NONE;
              KnowledgeFlowApp.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
              m_componentTree.clearSelection();
            }
          }


          TreePath p = m_componentTree.getSelectionPath();
          if (p != null) {
            if (p.getLastPathComponent() instanceof DefaultMutableTreeNode) {
              DefaultMutableTreeNode tNode = (DefaultMutableTreeNode)p.getLastPathComponent();

              if (tNode.isLeaf()) {
//                System.err.println("Selected : " + tNode.getUserObject().toString());
                Object userObject = tNode.getUserObject();
                if (userObject instanceof JTreeLeafDetails) {

                  if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0 &&
                      ((JTreeLeafDetails)userObject).isMetaBean()) {
                    if (m_firstUserComponentOpp) {
                      installWindowListenerForSavingUserStuff();
                      m_firstUserComponentOpp = false;
                    }

                    Vector toRemove = ((JTreeLeafDetails)userObject).getMetaBean();
                    DefaultTreeModel model = (DefaultTreeModel) m_componentTree.getModel();
                    MutableTreeNode userRoot = (MutableTreeNode)tNode.getParent(); // The "User" folder
                    model.removeNodeFromParent(tNode);
                    m_userComponents.remove(toRemove);

                    if (m_userComponents.size() == 0) {
                      model.removeNodeFromParent(userRoot);
                      m_userCompNode = null;
                    }

                  } else {
                    ((JTreeLeafDetails)userObject).instantiateBean();
View Full Code Here


      ex.printStackTrace();
    }
  }

  private void addToUserTreeNode(BeanInstance meta, boolean installListener) {
    DefaultTreeModel model = (DefaultTreeModel) m_componentTree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    if (m_userCompNode == null) {           
      m_userCompNode = new DefaultMutableTreeNode("User");
      model.insertNodeInto(m_userCompNode, root, 0);
    }

    Vector beanHolder = new Vector();
    beanHolder.add(meta);

    try {
      StringBuffer serialized = copyToBuffer(beanHolder);

      String displayName ="";
      ImageIcon scaledIcon = null;
      //
      if (meta.getBean() instanceof Visible) {
        //((Visible)copy).getVisual().scale(3);
        scaledIcon = new ImageIcon(((Visible)meta.getBean()).getVisual().scale(0.33));
        displayName = ((Visible)meta.getBean()).getVisual().getText();     
      }

      Vector metaDetails = new Vector();
      metaDetails.add(displayName);
      metaDetails.add(serialized);
      metaDetails.add(scaledIcon);
      SerializedObject so = new SerializedObject(metaDetails);
      Vector copy = (Vector)so.getObject();

      JTreeLeafDetails metaLeaf = new JTreeLeafDetails(displayName, copy, scaledIcon);


      DefaultMutableTreeNode newUserComp = new DefaultMutableTreeNode(metaLeaf);
      model.insertNodeInto(newUserComp, m_userCompNode, 0);

      // add to the list of user components
      m_userComponents.add(copy);

      if (installListener && m_firstUserComponentOpp) {
View Full Code Here

        System.err.println("[KnowledgeFlow] Problem reading user components.");
        ex.printStackTrace();
        return;
      }
      if (tempV.size() > 0) {
        DefaultTreeModel model = (DefaultTreeModel) m_componentTree.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
        if (m_userCompNode == null) {           
          m_userCompNode = new DefaultMutableTreeNode("User");
          model.insertNodeInto(m_userCompNode, root, 0);
        }

        // add the components
        for (int i = 0; i < tempV.size(); i++) {
          Vector tempB = (Vector)tempV.elementAt(i);
          String displayName = (String)tempB.get(0);
          StringBuffer serialized = (StringBuffer)tempB.get(1);
          ImageIcon scaledIcon = (ImageIcon)tempB.get(2);
          JTreeLeafDetails treeLeaf = new JTreeLeafDetails(displayName, tempB,
              scaledIcon);
          DefaultMutableTreeNode newUserComp = new DefaultMutableTreeNode(treeLeaf);
          model.insertNodeInto(newUserComp, m_userCompNode, 0);

          // add to the list of user components
          m_userComponents.add(tempB);

          //addToUserToolBar(tempB, false);
View Full Code Here

      return Collections.enumeration(children);
    }

    public void circuitChanged(CircuitEvent event) {
      int action = event.getAction();
      DefaultTreeModel model = (DefaultTreeModel) getModel();
      if (action == CircuitEvent.ACTION_SET_NAME) {
        model.nodeChanged(this);
      } else {
        if (computeChildren()) {
          model.nodeStructureChanged(this);
        } else if (action == CircuitEvent.ACTION_INVALIDATE) {
          Object o = event.getData();
          for (int i = children.size() - 1; i >= 0; i--) {
            Object o2 = children.get(i);
            if (o2 instanceof ComponentNode) {
              ComponentNode n = (ComponentNode) o2;
              if (n.comp == o) {
                int[] changed = { i };
                children.remove(i);
                model.nodesWereRemoved(this, changed, new Object[] { n });
                children.add(i, new ComponentNode(this, n.comp));
                model.nodesWereInserted(this, changed);
              }
            }
          }
        }
      }
View Full Code Here

  }
 
  private Model logModel;
 
  public ComponentSelector(Model logModel) {
    DefaultTreeModel model = new DefaultTreeModel(null);
    model.setAsksAllowsChildren(false);
    setModel(model);
    setRootVisible(false);
    setLogModel(logModel);
    setCellRenderer(new MyCellRenderer());
  }
View Full Code Here

  }
 
  public void setLogModel(Model value) {
    this.logModel = value;
   
    DefaultTreeModel model = (DefaultTreeModel) getModel();
    CircuitNode curRoot = (CircuitNode) model.getRoot();
    CircuitState state = logModel == null ? null : logModel.getCircuitState();
    if (state == null) {
      if (curRoot != null) model.setRoot(null);
      return;
    }
    if (curRoot == null || curRoot.circuitState != state) {
      curRoot = new CircuitNode(null, state, null);
      model.setRoot(curRoot);
    }
  }
View Full Code Here

  public void addChild(Widget widget, Object constraint) throws GUIException {
    if (widget instanceof TreeItem) {
      if (rootNode == null) {
        rootNode = (TreeItem) widget;
        rootNode.setTree(this);
        tree.setModel(new DefaultTreeModel(rootNode, false));
        addChild(rootNode);
      } else {
        throw new GUIException("A Tree can only have one root node");
      }
    } else {
View Full Code Here

    rootContent.add(demoContent, BorderLayout.CENTER);
    rootContent.add(placeHolder, BorderLayout.NORTH);

    final DemoSelectorTreeNode root = new DemoSelectorTreeNode(null,
        demoSelector);
    final DefaultTreeModel model = new DefaultTreeModel(root);
    final JTree demoTree = new JTree(model);
    demoTree.addTreeSelectionListener(new TreeSelectionHandler());

    JSplitPane rootSplitPane =
        new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
View Full Code Here

    }

    private void createTreePanel() {
        rootNode = new TaskTreeBaseNode();

        model = new DefaultTreeModel(rootNode);
        tree = new JTree(model);

        tree.setRootVisible(false);
        tree.setShowsRootHandles(true);
View Full Code Here

                int module;
                String id = null;
                String key = null;
                String filename = null;

                DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
               
                DefaultMutableTreeNode current;
                DefaultMutableTreeNode parent;
                DefaultMutableTreeNode previous;
                boolean exists = false;
               
                Collection<String> keys = DataFilters.isFilterActive(getModule()) ?
                              DataManager.getKeyList(DataFilters.getCurrent(getModule())) : null;
               
                while (rs.next() && !stop) {
                    int level = 0;
                    parent = top;
                   
                    id = rs.getString(1);
                    module = rs.getInt(2);
                    filename = rs.getString(3);
                   
                    if (keys != null && !keys.contains(id)) continue;
                   
                    StringTokenizer st = new StringTokenizer(filename, (filename.indexOf("/") > -1 ? "/" : "\\"));
                    while (st.hasMoreElements()) {
                      key = (String) st.nextElement();
                     
                        if (stop) break;
                       
                        // check the whole last leaf
                        top.getLastLeaf();
                       
                        previous = parent.getChildCount() == 0 ? null : ((DefaultMutableTreeNode) parent.getChildAt(parent.getChildCount() - 1));
                        exists = previous != null && ((NodeElementprevious.getUserObject()).getComparableKey().equals(key.toLowerCase());
                       
                        if (!exists) {
                            ne = new FileNodeElement(key, new File(filename));
                            ne.addItem(id, module);
                            current = new DcDefaultMutableTreeNode(ne);
                            model.insertNodeInto(current, parent, parent.getChildCount());
                            parent = current;
                          
                        } else { // exists
                            existingNe =( NodeElement) previous.getUserObject();
                            existingNe.addItem(id, module);
                            model.nodeChanged(previous);
                            parent = previous;   
                        }
                        level++;
                  }
                }
View Full Code Here

TOP

Related Classes of javax.swing.tree.DefaultTreeModel

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.