/**
   * Recursively rebuild the tree nodes.
   *
   * @param root The full abstract path to the root saved layout directory.
   * @param local The current directory relative to root (null if none).
   * @param tnode The current parent tree node.
   */
  private void rebuildTreeModel(Path root, Path local, DefaultMutableTreeNode tnode) {
    TreeSet<Path> subdirs = new TreeSet<Path>();
    TreeSet<String> layouts = new TreeSet<String>();
    {
      Path current = new Path(root, local);
      File files[] = current.toFile().listFiles();
      if (files != null) {
        int wk;
        for (wk = 0; wk < files.length; wk++) {
          String name = files[wk].getName();
          if (files[wk].isDirectory()) subdirs.add(new Path(local, name));
          else if (files[wk].isFile()) layouts.add(name);
        }
      }
    }

    for (Path subdir : subdirs) {
      TreeData data = new TreeData(subdir);
      DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, true);
      tnode.add(child);

      rebuildTreeModel(root, subdir, child);
    }

    for (String lname : layouts) {
      TreeData data = new TreeData(new Path(local, lname), lname);
      DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, false);
      tnode.add(child);
    }
  }
  void addChildren(DefaultMutableTreeNode parent, File parentDirFile) {

    for (File file : parentDirFile.listFiles()) {
      String[] namesplitStrings = file.toString().split("\\\\");
      String filename = namesplitStrings[namesplitStrings.length - 1];

      if (file.isDirectory()) {
        DefaultMutableTreeNode child = new DefaultMutableTreeNode(filename);
        addChildren(child, file);
        parent.add(child);
      } else if (file.isFile()) {
        parent.add(new DefaultMutableTreeNode(filename));
      }
    }
  }
Example #3
0
  // reorder the nodes
  private void reorder(Vector nodes) {

    debug("reorder nodes");

    // remove all the children of topNode (they'll be added back later)
    topNode.removeAllChildren();

    // Create an array of the elements for sorting & copy the elements
    // into the array.
    DefaultMutableTreeNode[] array = new DefaultMutableTreeNode[nodes.size()];
    nodes.copyInto(array);

    // Sort the array (Quick Sort)
    quickSort(array, 0, array.length - 1);

    // Reload the topNode. Everthing is in order now.
    for (int i = 0; i < array.length; i++) {
      topNode.add((DefaultMutableTreeNode) array[i]);
    }

    // Tell the tree to repaint itself
    ((DefaultTreeModel) tree.getModel()).reload();
    tree.invalidate();
    tree.repaint();
  }
  /**
   * Adds nodes to the specified parent node recurrsively.
   *
   * @param parent_node the parent node.
   * @param list the list of child node names.
   */
  protected void addNode(DefaultMutableTreeNode parent_node, Vector list) {
    SortableArray array = null;

    if (mode == DATE_ORIENTED && parent_node.getLevel() <= 2) {
      array = new Array(list.size());

      for (int i = 0; i < list.size(); i++)
        ((Array) array).set(i, Integer.parseInt((String) list.elementAt(i)));
    } else {
      array = new StringArray(list.size());

      for (int i = 0; i < list.size(); i++)
        ((StringArray) array).set(i, (String) list.elementAt(i));
    }

    ArrayIndex index = array.sortAscendant();

    for (int i = 0; i < array.getArraySize(); i++) {
      String name = (String) list.elementAt(index.get(i));

      // Converts 1...12 to January...December.
      if (mode == DATE_ORIENTED && parent_node.getLevel() == 1) {
        int month = Integer.parseInt(name);
        name = JulianDay.getFullSpellMonthString(month);
      }

      DefaultMutableTreeNode node = new DefaultMutableTreeNode(name);
      parent_node.add(node);
    }
  }
Example #5
0
  private TreeModel buildModel(Object[] resolvers) {
    TreeModel fullModel = null;
    DefaultMutableTreeNode top = new DefaultMutableTreeNode(Tr.t("root"));

    try {
      cpos = null;
      for (Object resolver : resolvers) {
        if (resolver instanceof ColorPository) {
          cpos = (ColorPository) resolver;
          GraphCellRenderer graphCellRenderer = new GraphCellRenderer(cpos);
          colors.setCellRenderer(graphCellRenderer);
          break;
        }
      }
      Collection<ColorPository.ClassRecord> classes = cpos.getClasses();
      String[] classNames = new String[classes.size()];
      Iterator<ColorPository.ClassRecord> it = classes.iterator();
      int count = 0;
      while (it.hasNext()) {
        classNames[count] = it.next().name;
        count++;
      }
      Arrays.sort(classNames);

      for (String className : classNames) {
        ColorPository.ColorRecord[] colors = cpos.enumerateColors(className);
        String[] colorNames = new String[colors.length];
        for (int a = 0; a < colorNames.length; a++) {
          colorNames[a] = colors[a].name;
        }
        Arrays.sort(colorNames);

        DefaultMutableTreeNode tn = new DefaultMutableTreeNode(className);
        top.add(tn);
        for (String colorName : colorNames) {
          tn.add(new DefaultMutableTreeNode(colorName));
        }
      }

      fullModel = new DefaultTreeModel(top);
    } catch (Exception e) {
      fullModel = new DefaultTreeModel(new DefaultMutableTreeNode(Tr.t("root.failed")));
      // e.printStackTrace();
    }
    return fullModel;
  }
Example #6
0
 private MutableTreeNode populatePlot(Plot p) throws SQLException {
   DefaultMutableTreeNode tree = new DefaultMutableTreeNode(p);
   // tree.add(populateAttributes(p));
   Statement stmt = db.statement();
   for (Tree t : p.loadTrees(stmt)) {
     tree.add(populateTree(t));
   }
   stmt.close();
   return tree;
 }
Example #7
0
 private MutableTreeNode populateNest(Nest n) throws SQLException {
   DefaultMutableTreeNode tree = new DefaultMutableTreeNode(n);
   // tree.add(populateAttributes(n));
   Statement stmt = db.statement();
   for (Visit v : n.loadVisits(stmt)) {
     tree.add(populateVisit(v));
   }
   stmt.close();
   return tree;
 }
Example #8
0
 private MutableTreeNode populateCavity(Cavity c) throws SQLException {
   DefaultMutableTreeNode tree = new DefaultMutableTreeNode(c);
   // tree.add(populateAttributes(c));
   Statement stmt = db.statement();
   for (Nest n : c.loadNests(stmt)) {
     tree.add(populateNest(n));
   }
   stmt.close();
   return tree;
 }
Example #9
0
 private MutableTreeNode populateTree(Tree t) throws SQLException {
   DefaultMutableTreeNode tree = new DefaultMutableTreeNode(t);
   // tree.add(populateAttributes(t));
   Statement stmt = db.statement();
   for (Cavity c : t.loadCavities(stmt)) {
     tree.add(populateCavity(c));
   }
   stmt.close();
   return tree;
 }
Example #10
0
  private MutableTreeNode populateAttributes(CavityDBObject obj) {
    DefaultMutableTreeNode tree = new DefaultMutableTreeNode("attrs");
    Class cls = obj.getClass();
    for (Field f : cls.getFields()) {
      int mod = f.getModifiers();
      if (Modifier.isPublic(mod) && !Modifier.isStatic(mod)) {
        String fieldName = f.getName();
        try {
          Object value = f.get(obj);
          tree.add(
              new DefaultMutableTreeNode(String.format("%s=%s", fieldName, String.valueOf(value))));

        } catch (IllegalAccessException e) {
          // do nothing.
        }
      }
    }
    return tree;
  }
  // Public Methods
  public void appendNextTreeGeneration(Vector generation) {
    DefaultMutableTreeNode nextGeneration = generationNodeBuilder(generation);

    generations.add(nextGeneration);

    // If Generations contains leaf nodes (generated objects)
    // Enabled Save All Menu Item
    if (generations.getLeafCount() > 0) miSaveAll.setEnabled(true);
    else miSaveAll.setEnabled(false);

    // Update JTree View

    // affected nodes needing updating
    int[] nodeRangeToUpdate = {generations.getIndex(nextGeneration)};
    ((DefaultTreeModel) tree.getModel()).nodesWereInserted(generations, nodeRangeToUpdate);

    // Expand Parent after first child node is displayed
    if (generationNumber == 1) tree.expandRow(0);

    ++generationNumber;
  }
Example #12
0
 private void populate() throws SQLException {
   Collection<Plot> plots = db.select(Plot.class).values();
   for (Plot p : plots) {
     top.add(populatePlot(p));
   }
 }
  /**
   * Constructs a X509 certificate panel.
   *
   * @param certificates <tt>X509Certificate</tt> objects
   */
  public X509CertificatePanel(Certificate[] certificates) {
    setLayout(new BorderLayout(5, 5));

    // Certificate chain list
    TransparentPanel topPanel = new TransparentPanel(new BorderLayout());
    topPanel.add(
        new JLabel(
            "<html><body><b>"
                + R.getI18NString("service.gui.CERT_INFO_CHAIN")
                + "</b></body></html>"),
        BorderLayout.NORTH);

    DefaultMutableTreeNode top = new DefaultMutableTreeNode();
    DefaultMutableTreeNode previous = top;
    for (int i = certificates.length - 1; i >= 0; i--) {
      Certificate cert = certificates[i];
      DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert);
      previous.add(next);
      previous = next;
    }
    JTree tree = new JTree(top);
    tree.setBorder(new BevelBorder(BevelBorder.LOWERED));
    tree.setRootVisible(false);
    tree.setExpandsSelectedPaths(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setCellRenderer(
        new DefaultTreeCellRenderer() {

          @Override
          public Component getTreeCellRendererComponent(
              JTree tree,
              Object value,
              boolean sel,
              boolean expanded,
              boolean leaf,
              int row,
              boolean hasFocus) {
            JLabel component =
                (JLabel)
                    super.getTreeCellRendererComponent(
                        tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
              Object o = ((DefaultMutableTreeNode) value).getUserObject();
              if (o instanceof X509Certificate) {
                component.setText(getSimplifiedName((X509Certificate) o));
              } else {
                // We don't know how to represent this certificate type,
                // let's use the first 20 characters
                String text = o.toString();
                if (text.length() > 20) {
                  text = text.substring(0, 20);
                }
                component.setText(text);
              }
            }
            return component;
          }
        });
    tree.getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {

              @Override
              public void valueChanged(TreeSelectionEvent e) {
                valueChangedPerformed(e);
              }
            });
    tree.setSelectionPath(
        new TreePath((((DefaultTreeModel) tree.getModel()).getPathToRoot(previous))));
    topPanel.add(tree, BorderLayout.CENTER);

    add(topPanel, BorderLayout.NORTH);

    // Certificate details pane
    Caret caret = infoTextPane.getCaret();
    if (caret instanceof DefaultCaret) {
      ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    }

    /*
     * Make JEditorPane respect our default font because we will be using it
     * to just display text.
     */
    infoTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);

    infoTextPane.setOpaque(false);
    infoTextPane.setEditable(false);
    infoTextPane.setContentType("text/html");
    infoTextPane.setText(toString(certificates[0]));

    final JScrollPane certScroll = new JScrollPane(infoTextPane);
    certScroll.setPreferredSize(new Dimension(300, 500));
    add(certScroll, BorderLayout.CENTER);
  }
Example #14
0
  /** Construct a new Help panel */
  public HelpPanel() {
    // Try to build our help tree, keeping an eye out for malformed URLs
    try {
      // root node
      top = new DefaultMutableTreeNode(new HelpItem("MIDIMatrix", "top"));

      // matrices node
      category = new DefaultMutableTreeNode(new HelpItem("Matrices", "matrices"));
      top.add(category);
      category.add(new DefaultMutableTreeNode(new HelpItem("Note Entry", "matrices-noteentry")));
      category.add(
          new DefaultMutableTreeNode(
              new HelpItem("Pitches, volume, and instruments", "matrices-metadata")));
      category.add(new DefaultMutableTreeNode(new HelpItem("Playback", "matrices-playback")));

      // sequences node
      category = new DefaultMutableTreeNode(new HelpItem("Sequences", "sequences"));
      top.add(category);
      category.add(
          new DefaultMutableTreeNode(new HelpItem("Parts of a sequence", "sequences-parts")));
      category.add(
          new DefaultMutableTreeNode(
              new HelpItem("Constructing a sequence", "sequences-construction")));
      category.add(new DefaultMutableTreeNode(new HelpItem("Playback", "sequences-playback")));

      // controls node
      category = new DefaultMutableTreeNode(new HelpItem("Controls", "controls"));
      top.add(category);
      category.add(
          new DefaultMutableTreeNode(new HelpItem("MIDI devices", "controls-mididevices")));
      category.add(new DefaultMutableTreeNode(new HelpItem("Saving", "controls-saving")));

      // about node
      category = new DefaultMutableTreeNode(new HelpItem("About", "about"));
      top.add(category);
      category.add(new DefaultMutableTreeNode(new HelpItem("Author", "about-author")));
      category.add(new DefaultMutableTreeNode(new HelpItem("License", "about-license")));

      // javadoc node
      // category = new DefaultMutableTreeNode(new HelpItem("JavaDoc", base + "javadoc/"));
      // top.add(category);
    } catch (MalformedURLException e) {
      top = new DefaultMutableTreeNode("ERROR");
    }
    helpTree = new JTree(top);
    helpTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    helpTree.addTreeSelectionListener(
        new TreeSelectionListener() {

          public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node =
                (DefaultMutableTreeNode) helpTree.getLastSelectedPathComponent();
            if (node == null) {
              return;
            }
            // try {
            helpPane.scrollToReference(((HelpItem) node.getUserObject()).getHash());
            /*} catch (IOException exc) {

                JOptionPane.showMessageDialog(
                        null,
                        "There was a problem fetching the help page " + exc.getMessage() + "\n" +
                        "Make sure you're connected to the internet before continuing",
                        "Help Oops!",
                        JOptionPane.ERROR_MESSAGE,
                        null);
            }*/
          }
        });

    treePane = new JScrollPane(helpTree);
    treePane.setPreferredSize(new Dimension(200, 750));

    helpPane = new JEditorPane();
    scroller = new JScrollPane(helpPane);
    helpPane.setEditable(false);
    helpPane.setPreferredSize(new Dimension(550, 750));
    helpPane.addHyperlinkListener(
        new HyperlinkListener() {

          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              JEditorPane pane = (JEditorPane) e.getSource();
              if (e instanceof HTMLFrameHyperlinkEvent) {
                HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
                HTMLDocument doc = (HTMLDocument) pane.getDocument();
                doc.processHTMLFrameHyperlinkEvent(evt);
                if (e.getDescription().indexOf("#") != -1) {
                  System.err.println("Found anchor");
                  pane.scrollToReference(
                      e.getDescription().substring(e.getDescription().indexOf("#")));
                }
              } else {
                try {
                  pane.setPage(e.getURL());
                } catch (Throwable t) {
                  t.printStackTrace();
                }
              }
            }
          }
        });
    try {
      helpPane.setPage(HelpPanel.class.getResource("help.xhtml"));
    } catch (IOException e) {
      helpPane.setText("Couldn't fetch help page, sorry!  " + e.getMessage());
    }

    content = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    content.add(treePane);
    content.add(scroller);

    add(content);
  }