Package javax.swing.tree

Examples of javax.swing.tree.DefaultMutableTreeNode


    Node node = (Node)selectedPath[0].getLastPathComponent();
    if (node.getType() == Node.PROGRAM) {
      Program[] selectedPrograms = new Program[selectedPath.length];
      for (int i=0; i<selectedPath.length; i++) {
        DefaultMutableTreeNode curNode = (DefaultMutableTreeNode) selectedPath[i].getLastPathComponent();
        selectedPrograms[i] = ((ProgramItem)curNode.getUserObject()).getProgram();
      }

      return new ProgramContextMenu(mTree, selectedPath, PluginTreeModel.getPlugin(selectedPath[0]), selectedPrograms);
    }
    else if (node.getType() == Node.PLUGIN_ROOT) {
View Full Code Here


      final int standard_toolset = 0;
      final int wrapper_toolset = 1;

      int toolBarType = standard_toolset;

      DefaultMutableTreeNode jtreeRoot = new DefaultMutableTreeNode("Weka");
      // set up wrapper toolsets
      for (int i = 0; i < TOOLBARS.size(); i++) {
        Vector tempBarSpecs = (Vector) TOOLBARS.elementAt(i);

        // name for the tool bar
        String tempToolSetName = (String) tempBarSpecs.elementAt(0);
        DefaultMutableTreeNode subTreeNode = new DefaultMutableTreeNode(tempToolSetName);
        jtreeRoot.add(subTreeNode);

        // Used for weka leaf packages
        //        Box singletonHolderPanel = null;

        // name of the bean component to handle this class of weka algorithms
        String tempBeanCompName = (String) tempBarSpecs.elementAt(1);

        // a JPanel holding an instantiated bean + label ready to be added
        // to the current toolbar
        JPanel tempBean;

        // the root package for weka algorithms
        String rootPackage = "";
        weka.gui.HierarchyPropertyParser hpp = null;
        Hashtable hpps = null;

        // Is this a wrapper toolbar?
        if (tempBeanCompName.compareTo("null") != 0) {
          tempBean = null;
          toolBarType = wrapper_toolset;
          rootPackage = (String) tempBarSpecs.elementAt(2);
          //      hpp = (weka.gui.HierarchyPropertyParser)tempBarSpecs.elementAt(3);
          hpps = (Hashtable) tempBarSpecs.elementAt(3);

          try {
            // modifications by Zerbetto
            // Beans.instantiate(null, tempBeanCompName);
            Beans.instantiate(this.getClass().getClassLoader(), tempBeanCompName);

            // end modifications by Zerbetto
          } catch (Exception ex) {
            // ignore
            System.err.println("[KnowledgeFlow] Failed to instantiate: " + tempBeanCompName);

            break;
          }
        } else {
          toolBarType = standard_toolset;
        }

        // a toolbar to hold buttons---one for each algorithm
        //        JToolBar tempToolBar = new JToolBar();

        //      System.err.println(tempToolBar.getLayout());
        //      tempToolBar.setLayout(new FlowLayout());
        int z = 2;

        if (toolBarType == wrapper_toolset) {
          Enumeration enm = hpps.keys();

          while (enm.hasMoreElements()) {
            String root = (String) enm.nextElement();
            String userPrefix = "";
            hpp = (HierarchyPropertyParser) hpps.get(root);

            if (!hpp.goTo(rootPackage)) {
              System.out.println("[KnowledgeFlow] Processing user package... ");
              //            System.exit(1);
              userPrefix = root + ".";
            }

            String[] primaryPackages = hpp.childrenValues();

            for (int kk = 0; kk < primaryPackages.length; kk++) {

              hpp.goToChild(primaryPackages[kk]);

              // check to see if this is a leaf - if so then there are no
              // sub packages
              if (hpp.isLeafReached()) {
                /*              if (singletonHolderPanel == null) {
                  singletonHolderPanel = Box.createHorizontalBox();
                  singletonHolderPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
                      tempToolSetName));
                } */

                String algName = hpp.fullValue();
                // -- tempBean = instantiateToolBarBean(true, tempBeanCompName, algName);
                Object visibleCheck = instantiateBean((toolBarType == wrapper_toolset),
                    tempBeanCompName, algName);

                //if (tempBean != null) {
                if (visibleCheck != null) {
                  // tempToolBar.add(tempBean);
                  //                  singletonHolderPanel.add(tempBean);


                  /*Object visibleCheck = instantiateBean((toolBarType == wrapper_toolset),
                      tempBeanCompName, algName); */
                  if (visibleCheck instanceof BeanContextChild) {
                    m_bcSupport.add(visibleCheck);
                  }
                  ImageIcon scaledForTree = null;
                  if (visibleCheck instanceof Visible) {
                    BeanVisual bv = ((Visible)visibleCheck).getVisual();
                    if (bv != null) {
                      scaledForTree = new ImageIcon(bv.scale(0.33));
                      // m_iconLookup.put(algName, scaledForTree);
                    }
                  }
                  JTreeLeafDetails leafData = new JTreeLeafDetails(tempBeanCompName, algName,
                      scaledForTree);
                  DefaultMutableTreeNode leafAlgo =
                    new DefaultMutableTreeNode(leafData);
                  subTreeNode.add(leafAlgo);            
                }

                hpp.goToParent();
              } else {
                // make a titledborder JPanel to hold all the schemes in this
                // package
                //            JPanel holderPanel = new JPanel();
                /* Box holderPanel = Box.createHorizontalBox();
                holderPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(userPrefix +
                    primaryPackages[kk])); */

                DefaultMutableTreeNode firstLevelOfMainAlgoType =
                  new DefaultMutableTreeNode(primaryPackages[kk]);
                subTreeNode.add(firstLevelOfMainAlgoType);

                //processPackage(holderPanel, tempBeanCompName, hpp, firstLevelOfMainAlgoType);
                processPackage(tempBeanCompName, hpp, firstLevelOfMainAlgoType);
                //                tempToolBar.add(holderPanel);
              }
            }

            /*          if (singletonHolderPanel != null) {
              tempToolBar.add(singletonHolderPanel);
              singletonHolderPanel = null;
            } */
          }
        } else {
          /*        Box holderPanel = Box.createHorizontalBox();
          holderPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
              tempToolSetName)); */

          for (int j = z; j < tempBarSpecs.size(); j++) {
            tempBean = null;
            tempBeanCompName = (String) tempBarSpecs.elementAt(j);
            Object visibleCheck = instantiateBean((toolBarType == wrapper_toolset),
                tempBeanCompName, "");

            /* --         tempBean = instantiateToolBarBean((toolBarType == wrapper_toolset),
                tempBeanCompName, ""); */

            //if (tempBean != null) {
            if (visibleCheck != null) {
              // set tool tip text (if any)
              // setToolTipText(tempBean)
              //              holderPanel.add(tempBean);

              String treeName = tempBeanCompName;
              if (treeName.lastIndexOf('.') > 0) {
                treeName = treeName.substring(treeName.lastIndexOf('.') + 1,
                    treeName.length());
              }

              /*Object visibleCheck = instantiateBean((toolBarType == wrapper_toolset),
                  tempBeanCompName, ""); */
              if (visibleCheck instanceof BeanContextChild) {
                m_bcSupport.add(visibleCheck);
              }
              ImageIcon scaledForTree = null;

              if (visibleCheck instanceof Visible) {
                BeanVisual bv = ((Visible)visibleCheck).getVisual();
                if (bv != null) {
                  scaledForTree = new ImageIcon(bv.scale(0.33));

                  //m_iconLookup.put(treeName, scaledForTree);
                }
              }
              JTreeLeafDetails leafData = new JTreeLeafDetails(tempBeanCompName, "",
                  scaledForTree);
              DefaultMutableTreeNode fixedLeafNode = new DefaultMutableTreeNode(leafData);
              subTreeNode.add(fixedLeafNode);           
            }
          }

          //      tempToolBar.add(holderPanel);
        }

        //        JScrollPane tempJScrollPane = createScrollPaneForToolBar(tempToolBar);
        // ok, now create tabbed pane to hold this toolbar
        //        m_toolBars.addTab(tempToolSetName, null, tempJScrollPane, tempToolSetName);
      }

      /// ----

      // TODO Prescan for bean plugins and only create user tree node if there
      // are actually some beans (rather than just all perspectives)

      // Any plugin components to process?
      if (BEAN_PLUGINS_PROPERTIES != null &&
          BEAN_PLUGINS_PROPERTIES.size() > 0) {               

        boolean pluginBeans = false;

        DefaultMutableTreeNode userSubTree = null;
        for (int i = 0; i < BEAN_PLUGINS_PROPERTIES.size(); i++) {
          Properties tempP = BEAN_PLUGINS_PROPERTIES.get(i);
          JPanel tempBean = null;
          String components =
            tempP.getProperty("weka.gui.beans.KnowledgeFlow.Plugins");
          if (components != null && components.length() > 0) {
            if (!pluginBeans) {
              // make the Plugins tree node entry
              userSubTree = new DefaultMutableTreeNode("Plugins");
              jtreeRoot.add(userSubTree);
              pluginBeans = true;
            }

            StringTokenizer st2 = new StringTokenizer(components, ", ");

            while (st2.hasMoreTokens()) {
              String tempBeanCompName = st2.nextToken().trim();

              String treeName = tempBeanCompName;
              if (treeName.lastIndexOf('.') > 0) {
                treeName = treeName.substring(treeName.lastIndexOf('.') + 1,
                    treeName.length());
              }

              //            tempBean = instantiateToolBarBean(false, tempBeanCompName, "");
              /*          if (m_pluginsToolBar == null) {
              // need to create the plugins tab and toolbar
              setUpPluginsToolBar();
            }
            m_pluginsBoxPanel.add(tempBean); */

              Object visibleCheck = instantiateBean((toolBarType == wrapper_toolset),
                  tempBeanCompName, "");
              if (visibleCheck instanceof BeanContextChild) {
                m_bcSupport.add(visibleCheck);
              }
              ImageIcon scaledForTree = null;
              if (visibleCheck instanceof Visible) {
                BeanVisual bv = ((Visible)visibleCheck).getVisual();
                if (bv != null) {
                  scaledForTree = new ImageIcon(bv.scale(0.33));
                  //m_iconLookup.put(tempBeanCompName, scaledForTree);
                }
              }
              JTreeLeafDetails leafData = new JTreeLeafDetails(tempBeanCompName, "",
                  scaledForTree);
              DefaultMutableTreeNode pluginLeaf = new DefaultMutableTreeNode(leafData);
              userSubTree.add(pluginLeaf);
            }
          }

          // check for perspectives
          String perspectives =
            tempP.getProperty(("weka.gui.beans.KnowledgeFlow.Perspectives"));
          if (perspectives != null && perspectives.length() > 0) {
            StringTokenizer st2 = new StringTokenizer(perspectives, ",");
            while (st2.hasMoreTokens()) {
              String className = st2.nextToken();
              try {
                Object p = Class.forName(className).newInstance();
                if (p instanceof KFPerspective &&
                    p instanceof JPanel) {
                  String title = ((KFPerspective)p).getPerspectiveTitle();
                  System.out.println("[KnowledgeFlow] loaded perspective: " + title);
                  PLUGIN_PERSPECTIVES.put(className, title);

                  // not selected as part of the users set of perspectives yet...
                  ((KFPerspective)p).setLoaded(false);

                  // check to see if user has selected to use this perspective
                  if (VISIBLE_PERSPECTIVES.contains(className)) {
                    // add to the perspective cache. After processing
                    // all plugins we will iterate over the sorted
                    // VISIBLE_PERSPECTIVES in order to add them
                    // to the toolbar in consistent sorted order
                   
                    //((KFPerspective)p).setMainKFPerspective(m_mainKFPerspective);
                    PERSPECTIVE_CACHE.put(className, (KFPerspective)p);                   
                  }
                }
              } catch (Exception ex) {
                if (m_logPanel != null) {
                  m_logPanel.logMessage("[KnowledgeFlow] WARNING: " +
                      "unable to instantiate perspective \""
                      + className + "\"");
                } else {
                  System.err.println("[KnowledgeFlow] WARNING: " +
                      "unable to instantiate perspective \""
                      + className + "\"");
                }
              }
            }
          }
        }
      }
     
      m_togglePerspectivesB.setEnabled(PLUGIN_PERSPECTIVES.keySet().size() > 0);

      //      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);
View Full Code Here

      return;
    }
    String [] children = hpp.childrenValues();
    for (int i = 0; i < children.length; i++) {
      hpp.goToChild(children[i]);
      DefaultMutableTreeNode child = null;

      if (hpp.isLeafReached()) {
        String algName = hpp.fullValue();

        Object visibleCheck = instantiateBean(true,
            tempBeanCompName, algName);
        if (visibleCheck instanceof BeanContextChild) {
          m_bcSupport.add(visibleCheck);
        }
        ImageIcon scaledForTree = null;
        if (visibleCheck instanceof Visible) {
          BeanVisual bv = ((Visible)visibleCheck).getVisual();
          if (bv != null) {
            scaledForTree = new ImageIcon(bv.scale(0.33));
            // m_iconLookup.put(algName, scaledForTree);
          }
        }
        JTreeLeafDetails leafData = new JTreeLeafDetails(tempBeanCompName, algName,
            scaledForTree);
        child = new DefaultMutableTreeNode(leafData);       
      } else {
        child = new DefaultMutableTreeNode(children[i]);
      }
      parentNode.add(child);

      processPackage(tempBeanCompName, hpp, child);
    }
View Full Code Here

    }
  }

  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);
View Full Code Here

        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);
View Full Code Here

    // Add columns.
    for (Iterator iter = table.columns(); iter.hasNext(); ) {
  Column column = (Column)iter.next();
  ColumnInfo info = new ColumnInfo(column, designer);
  tableNode.add(new DefaultMutableTreeNode(info, false));
    }

    // A signal that we have loaded the columns.
    tableNode = null;
}
View Full Code Here

    if (!mDisableUpdate) {
      MutableTreeNode rootNode = (MutableTreeNode) this.getRoot();
      @SuppressWarnings("unchecked")
      Enumeration<DefaultMutableTreeNode> e = rootNode.children();
      while (e.hasMoreElements() && !mDisableUpdate) {
        DefaultMutableTreeNode n = e.nextElement();

        Object o = n.getUserObject();
        if (o instanceof Plugin) {
          Plugin p = (Plugin) o;
          p.getRootNode().update();
        }
        else if(n.equals(FavoritesPlugin.getRootNode().getMutableTreeNode())) {
          FavoritesPlugin.getRootNode().update();
        } else if(n.equals(ReminderPlugin.getRootNode().getMutableTreeNode())) {
          ReminderPlugin.getRootNode().update();
        }
      }
    }
  }
View Full Code Here

  }

  public static Plugin getPlugin(TreePath path) {
    if (path.getPathCount() > 1) {
      Object o = path.getPathComponent(1);
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
      o = node.getUserObject();
      if (o instanceof Plugin) {
        Plugin plugin = (Plugin) o;
        return plugin;
      }
    }
View Full Code Here

  }

  public static PluginProxy getPluginProxy(TreePath path) {
    if (path.getPathCount() > 1) {
      Object o = path.getPathComponent(1);
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
      o = node.getUserObject();
      if (o instanceof PluginProxy) {
        PluginProxy proxy = (PluginProxy) o;
        return proxy;
      }
    }
View Full Code Here

            }
            paths = buf.toString();
        }

        // Create the nodes.
        DefaultMutableTreeNode top = new DefaultMutableTreeNode("VPF Data Libraries");
        try {
            createNodes(top, dataPaths);
        } catch (FormatException fe) {
            Debug.output("Caught FormatException reading data: "
                    + fe.getMessage());
View Full Code Here

TOP

Related Classes of javax.swing.tree.DefaultMutableTreeNode

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.