public GAGenerationTreePanel(GAObjectMonitor monitor, String parentNodeTitle) { super(); selectedChildrenPaths = new Vector(); generationNumber = 1; saveNumber = 0; generations = new DefaultMutableTreeNode(parentNodeTitle); gaMonitor = monitor; setLayout(new BorderLayout()); tree = new JTree(generations); tree.setShowsRootHandles(true); tree.setRootVisible(true); tree.putClientProperty("JTree.lineStyle", "Angled"); // Add Action Listeners MyTreeSelectionListener listener = new MyTreeSelectionListener(monitor.getSelectionInfoPanel()); MyTreeClickListener mlistener = new MyTreeClickListener(); tree.addTreeSelectionListener(listener); tree.addMouseListener(mlistener); // Add Scroll Plane scrollPane = new JScrollPane(tree); add(scrollPane, BorderLayout.CENTER); // Add Menu Bar Functionality createMenuBar(); add(menuBar, BorderLayout.NORTH); }
/** * Initialize the common user interface components. * * <p> */ protected JButton[] initUI( String title, JComponent extraComps, String confirm, String[][] extra, String cancel) { JButton[] extraBtns = null; /* create dialog body components */ { JPanel body = new JPanel(); body.setName("MainDialogPanel"); body.setLayout(new BoxLayout(body, BoxLayout.Y_AXIS)); body.add(UIFactory.createPanelLabel("Existing Layouts:")); body.add(Box.createRigidArea(new Dimension(0, 4))); { DefaultMutableTreeNode root = new DefaultMutableTreeNode(new TreeData(), true); DefaultTreeModel model = new DefaultTreeModel(root, true); JTree tree = new JFancyTree(model); pTree = tree; tree.setName("DarkTree"); tree.setCellRenderer(new JLayoutTreeCellRenderer()); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); { JScrollPane scroll = UIFactory.createScrollPane( pTree, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, new Dimension(230, 120), new Dimension(230, 150), null); body.add(scroll); } } if (extraComps != null) body.add(extraComps); extraBtns = super.initUI(title, body, confirm, null, extra, cancel); } return extraBtns; }
public void editSelected() { TreePath selected = tree.getSelectionPath(); if (selected != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) selected.getLastPathComponent(); Object obj = node.getUserObject(); if (obj instanceof CavityDBObject) { CavityDBObject dbObj = (CavityDBObject) obj; new ObjectEditingFrame(new ObjectEditingPanel(dbObj)); } } }
// 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; }
public Browser(CavityNestingDB cndb) throws SQLException { super(new BorderLayout()); setPreferredSize(new Dimension(300, 500)); db = cndb; displayer = new NodeDisplay(); top = new DefaultMutableTreeNode("CavityNestingDB"); tree = new JTree(top); DefaultTreeSelectionModel selModel = new DefaultTreeSelectionModel(); selModel.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION); tree.setSelectionModel(selModel); tree.addTreeSelectionListener( new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { if (e.isAddedPath()) { TreePath path = e.getPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object value = node.getUserObject(); // System.out.println(String.valueOf(value)); if (value instanceof CavityDBObject) { displayer.display((CavityDBObject) value); } else { // System.out.println(value.getClass().getSimpleName()); } } } }); JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); add(splitter, BorderLayout.CENTER); splitter.add(new JScrollPane(tree)); splitter.add(displayer); populate(); }
public SelectableTree() { super("JTree Selections"); WindowUtilities.setNativeLookAndFeel(); addWindowListener(new ExitListener()); Container content = getContentPane(); String[] namesplitStrings = mainDir.toString().split("\\\\"); String filename = namesplitStrings[namesplitStrings.length - 1]; DefaultMutableTreeNode root = new DefaultMutableTreeNode(filename); addChildren(root, mainDir); tree = new JTree(root); tree.addTreeSelectionListener(this); content.add(new JScrollPane(tree), BorderLayout.CENTER); currentSelectionField = new JTextField("Current Selection: NONE"); content.add(currentSelectionField, BorderLayout.SOUTH); setSize(250, 275); setVisible(true); }
@Override public void valueChanged(TreeSelectionEvent event) { currentSelectionField.setText(tree.getLastSelectedPathComponent().toString()); }
/** 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); }