Debian Codegraph @

uk/ac/babraham/FastQC/Help/HelpDialog.java

raw symbols SCIP
1 /**
2 * Copyright 2009-15 Simon Andrews
3 *
4 * This file is part of SeqMonk.
5 *
6 * SeqMonk is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * SeqMonk is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with SeqMonk; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 package uk.ac.babraham.FastQC.Help;
21
22
23 import java.io.File;
24
25 import javax.swing.JDialog;
26 import javax.swing.JFrame;
27 import javax.swing.JScrollPane;
28 import javax.swing.JSplitPane;
29 import javax.swing.JTree;
30 import javax.swing.event.TreeSelectionEvent;
31 import javax.swing.event.TreeSelectionListener;
32 import javax.swing.tree.DefaultMutableTreeNode;
33 import javax.swing.tree.DefaultTreeModel;
34
35
36 /**
37 * The Class HelpDialog is the root window of the help system.
38 */
39 public class HelpDialog extends JDialog implements TreeSelectionListener {
40
41 /** The tree. */
42 private JTree tree;
43
44 /** The current page. */
45 private HelpPageDisplay currentPage = null;
46
47 /** The main split. */
48 private JSplitPane mainSplit;
49
50
51 /**
52 * Instantiates a new help dialog.
53 *
54 * @param parent the parent
55 * @param startingLocation the starting location
56 */
57 public HelpDialog (JFrame parent, File startingLocation) {
58 super(parent,"Help Contents");
59
60 HelpIndexRoot root = new HelpIndexRoot(startingLocation);
61
62 mainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
63 setContentPane(mainSplit);
64
65 tree = new JTree(new DefaultTreeModel(root));
66
67 JSplitPane leftSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
68 leftSplit.setTopComponent(new JScrollPane(tree));
69 leftSplit.setBottomComponent(new HelpSearchPanel(root,this));
70
71 mainSplit.setLeftComponent(leftSplit);
72 currentPage = new HelpPageDisplay(null);
73 mainSplit.setRightComponent(currentPage);
74
75 tree.addTreeSelectionListener(this);
76
77
78 setSize(800,500);
79 setLocationRelativeTo(parent);
80 setVisible(true);
81
82 leftSplit.setDividerLocation(0.7);
83 mainSplit.setDividerLocation(0.3);
84 findStartingPage();
85 }
86
87 /**
88 * Find starting page.
89 */
90 private void findStartingPage () {
91 DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode)tree.getModel().getRoot();
92
93 DisplayPage((HelpPage)currentNode.getFirstLeaf());
94 }
95
96 /**
97 * Display page.
98 *
99 * @param page the page
100 */
101 public void DisplayPage(HelpPage page) {
102 if (currentPage != null) {
103 int d = mainSplit.getDividerLocation();
104 mainSplit.remove(currentPage);
105 currentPage = new HelpPageDisplay(page);
106 mainSplit.setRightComponent(currentPage);
107 mainSplit.setDividerLocation(d);
108 }
109 }
110
111 /* (non-Javadoc)
112 * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
113 */
114 public void valueChanged(TreeSelectionEvent tse) {
115
116 if (tse.getNewLeadSelectionPath() == null) return;
117
118 Object o = tse.getNewLeadSelectionPath().getLastPathComponent();
119 if (o instanceof HelpPage && ((HelpPage)o).isLeaf()) {
120 DisplayPage((HelpPage)o);
121 }
122 }
123
124 }