示例#1
0
  /**
   * Read the description of this RootFolder into a Folder and create the GUI components of the
   * Folder.
   *
   * @param node the element tree containing the Folder description
   * @return a node that is the root node in an expandable JTree
   */
  private DefaultMutableTreeNode readDescription(Element node) {
    Element e;

    // create a new Folder that contains the contents of this RootFolder
    Folder f = new Folder(null);

    // get some basic attributes
    name = XMLutils.getElementString("name", node); // $NON-NLS-1$
    title = XMLutils.getElementString("title", node); // $NON-NLS-1$
    description = XMLutils.getElementString("description", node); // $NON-NLS-1$
    tooltip = XMLutils.getElementString("tooltip", node); // $NON-NLS-1$

    // read any global parameters
    if ((e = node.getChild("parameters")) != null) { // $NON-NLS-1$
      globalParams = ParameterSet.readParameters(e);
      ParameterSet.globalParameterSet = globalParams;
    }

    // read a button panel
    if ((e = node.getChild("buttons")) != null) { // $NON-NLS-1$
      buttonPanel = new ButtonPanel(this);
      buttonPanel.readButtons(e);
    }

    // is the root node visible
    Boolean bval = XMLutils.getElementBoolean("visible", node); // $NON-NLS-1$
    if (bval != null) {
      rootIsVisible = bval.booleanValue();
    }

    // are the tree handles visible
    bval = XMLutils.getElementBoolean("showHandles", node); // $NON-NLS-1$
    if (bval != null) {
      showHandles = bval.booleanValue();
    }

    // create a new JTree node with the Folder as the data object
    DefaultMutableTreeNode newnode = new DefaultMutableTreeNode(f);

    // read the Folder from the element tree
    f.readFolder(newnode, node);

    return newnode;
  }
示例#2
0
    /* (non-Javadoc)
     * @see javax.swing.tree.DefaultTreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
     */
    public Component getTreeCellRendererComponent(
        JTree tree,
        Object value,
        boolean sel,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {

      super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

      Folder f = getFolderForNode(value);

      if (f != null) {
        String folderName = f.getTitle();

        if (folderName == null || folderName.length() == 0) {
          folderName = f.getDataItemName();
        }

        if (f.getFolderIcon() != null) {
          setIcon(f.getFolderIcon());
        } else {
          setText(folderName);
        }
        setToolTipText(f.getTooltip());
      } else {
        setToolTipText(null); // no tool tip
      }

      return this;
    }
示例#3
0
  /**
   * Read the definition of this Folder from the XML element tree.
   *
   * @param treenode the JTree node that represents this Folder
   * @param node the XML element tree
   */
  public void readFolder(DefaultMutableTreeNode treenode, Element node) {
    Element e;
    String source = null;

    // base class reads common values
    super.readDescription(node);

    // get the heading
    heading = XMLutils.getElementString("heading", node); // $NON-NLS-1$

    // if a background colour has been specified then set it also for the tabbed pane
    if (bgcolour != null) {
      tabbedPane.setBackground(bgcolour);
    }

    source = XMLutils.getElementString("source", node); // $NON-NLS-1$
    // if a source has been specified then read the description from the source
    // test the value of url, if it has been set then this could be the 2nd
    // time we are in this method, a source tag in a sourced description would
    // otherwise cause an infinite loop
    if (source != null && url == null) {
      url = source;
      readFolderFromURL(source, treenode);
      return;
    }

    // read the list of tabs in this folder
    if ((e = node.getChild("tabList")) != null) { // $NON-NLS-1$
      if (LOG.isDebugEnabled()) {
        LOG.debug(name + Messages.getString(BUNDLE_NAME, "Folder.4")); // $NON-NLS-1$
      }
      // iterate through the list
      List<Element> children = e.getChildren();
      Iterator<Element> iterator = children.iterator();
      while (iterator.hasNext()) {
        Element tabnode = (Element) iterator.next();

        // create a new Tab and read the definition
        Tab t = new Tab(this);
        t.readDescription(tabnode);

        // add the tab to this folder
        addDataItem(t);
      }
    }

    Element tds;
    // get any tabbed data sets
    // Tabbed data sets are siblings of other tabs in the tabbed pane and are
    // themselves a tabbed pane with a set of sub tabs
    if ((tds = node.getChild("tabbedDataSet")) != null) { // $NON-NLS-1$
      if (LOG.isDebugEnabled()) {
        LOG.debug(name + Messages.getString(BUNDLE_NAME, "Folder.6")); // $NON-NLS-1$
      }
      // create a new tabbed data set
      TabbedDataSet tabset = new TabbedDataSet(this);

      // read the description and add it to the tabbed pane
      tabset.bgcolour = bgcolour;
      tabset.readDescription(tds);

      addDataItem(tabset);
    }

    // read any sub folders recursively
    if ((e = node.getChild("folderList")) != null) { // $NON-NLS-1$
      if (LOG.isDebugEnabled()) {
        LOG.debug(name + Messages.getString(BUNDLE_NAME, "Folder.8")); // $NON-NLS-1$
      }
      // iterate through the list of folders
      List<Element> children = e.getChildren();
      Iterator<Element> iterator = children.iterator();
      while (iterator.hasNext()) {
        Element folder = (Element) iterator.next();

        // create a new Folder
        Folder f = new Folder(this);

        DefaultMutableTreeNode newnode = new DefaultMutableTreeNode(f);

        // read the description of the folder and add it to the JTree
        // as a child of the tree node that this Folder represents
        f.readFolder(newnode, folder);

        treenode.add(newnode);
      }
    }

    layoutComponents();

    // get any specified icon
    try {
      String logo = XMLutils.getElementString("icon", node); // $NON-NLS-1$
      if (logo != null) {
        URL u = new URL(logo);
        this.icon = new ImageIcon(u); // createAppletImageIcon(logo,title);
      }
    } catch (Exception ex) {
      LOG.error(name, ex);
    }
  }
示例#4
0
  /**
   * Create a new JTree using the root node as the root of the tree
   *
   * @return the newly created JTree
   */
  private JTree getFolderTree() {

    if (rootNode == null) {
      throw new RuntimeException(Messages.getString(BUNDLE_NAME, "RootFolder.10")); // $NON-NLS-1$
    }

    final JTree tree = new JTree(rootNode);

    // this tree is not editable
    tree.setEditable(false);

    // setup some default properties
    tree.putClientProperty("JTree.lineStyle", "Angled"); // $NON-NLS-1$ //$NON-NLS-2$
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setShowsRootHandles(showHandles);

    // set the cell renderer to display text and/or images
    tree.setCellRenderer(new FolderIconRenderer());

    /* when the user clicks on a tree node then load the Folder for the node
     * that is clicked
     */
    tree.addTreeSelectionListener(
        new TreeSelectionListener() {

          public void valueChanged(TreeSelectionEvent e) {
            @SuppressWarnings("unused")
            TreePath treePath = e.getNewLeadSelectionPath();
            DefaultMutableTreeNode node =
                (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

            if (node == null) {
              return;
            }

            Object nodeInfo = node.getUserObject();
            loadNodeObject(nodeInfo);
          }
        });

    // the maximum hieght of each row in the JTree
    int maxRowHeight = -1;

    /* determine the maximum height of the nodes in the JTree by getting the
     * maximum hieght of each Folder node in the tree.  It is helpful if using images
     * for Folder nodes that all images are the same height.
     */
    Enumeration<TreeNode> e = rootNode.breadthFirstEnumeration();
    DefaultMutableTreeNode node;

    Folder f = getFolderForNode(rootNode);

    // determine the maximum height of the root Folder node
    if (f != null) {
      ImageIcon icon;
      if ((icon = f.getFolderIcon()) != null) {
        maxRowHeight = Math.max(maxRowHeight, icon.getIconHeight());
      }
    }

    // determine the maximum height of all child nodes
    for (; e.hasMoreElements(); ) {
      node = (DefaultMutableTreeNode) e.nextElement();
      f = getFolderForNode(node);

      if (f != null) {
        ImageIcon icon;
        if ((icon = f.getFolderIcon()) != null) {
          maxRowHeight = Math.max(maxRowHeight, icon.getIconHeight());
        }
      }
    }

    // set the rowheight of the JTree to the maximum of the current height and the
    // maximum Folder node height
    int rowHeight = tree.getRowHeight();
    if (maxRowHeight > rowHeight) {
      tree.setRowHeight(maxRowHeight);
    }

    return tree;
  }