コード例 #1
0
ファイル: MsnTreeTest.java プロジェクト: hbt/jmsnmessenger
  public MsnTreeTest() {
    String[] tab = {"hello", "test", "blabla"};

    container = getContentPane();
    container.setLayout(null);

    eleve = new DefaultMutableTreeNode("MSN");

    worker = new DefaultMutableTreeNode("Worker");
    prof = new DefaultMutableTreeNode("Profs");

    for (int i = 0; i < tab.length; i++) {
      worker.add(new DefaultMutableTreeNode(tab[i]));
      prof.add(new DefaultMutableTreeNode(tab[i]));
    }
    //        worker.add(new DefaultMutableTreeNode("hello world2"));

    eleve.add(worker);
    eleve.add(prof);

    tree = new JTree(eleve);

    scroll = new JScrollPane(tree);
    scroll.setBounds(10, 10, 100, 100);

    container.add(scroll);

    setSize(300, 300);
    setLocation(200, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);

    //        worker.add(n);

  }
コード例 #2
0
  /**
   * 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);
    }
  }
コード例 #3
0
  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));
      }
    }
  }
コード例 #4
0
ファイル: Browser.java プロジェクト: tdanford/nrc-wildlife
 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;
 }
コード例 #5
0
ファイル: Browser.java プロジェクト: tdanford/nrc-wildlife
 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;
 }
コード例 #6
0
ファイル: Browser.java プロジェクト: tdanford/nrc-wildlife
 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;
 }
コード例 #7
0
ファイル: Browser.java プロジェクト: tdanford/nrc-wildlife
 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;
 }
コード例 #8
0
ファイル: Browser.java プロジェクト: tdanford/nrc-wildlife
  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;
  }
コード例 #9
0
  // 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;
  }
コード例 #10
0
ファイル: Browser.java プロジェクト: tdanford/nrc-wildlife
 private void populate() throws SQLException {
   Collection<Plot> plots = db.select(Plot.class).values();
   for (Plot p : plots) {
     top.add(populatePlot(p));
   }
 }
コード例 #11
0
ファイル: HelpPanel.java プロジェクト: makyo/midimatrix
  /** 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);
  }