/** * 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; }
/** 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); }