| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
package uk.ac.babraham.FastQC.Help; |
| 21 |
|
| 22 |
import java.awt.BorderLayout; |
| 23 |
import java.awt.event.ActionEvent; |
| 24 |
import java.awt.event.ActionListener; |
| 25 |
import java.io.IOException; |
| 26 |
|
| 27 |
import javax.swing.BorderFactory; |
| 28 |
import javax.swing.DefaultListModel; |
| 29 |
import javax.swing.JButton; |
| 30 |
import javax.swing.JList; |
| 31 |
import javax.swing.JPanel; |
| 32 |
import javax.swing.JScrollPane; |
| 33 |
import javax.swing.JTextField; |
| 34 |
import javax.swing.ListSelectionModel; |
| 35 |
import javax.swing.event.ListSelectionEvent; |
| 36 |
import javax.swing.event.ListSelectionListener; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class HelpSearchPanel extends JPanel implements ActionListener, ListSelectionListener, Runnable { |
| 42 |
|
| 43 |
|
| 44 |
private HelpIndexRoot root; |
| 45 |
|
| 46 |
|
| 47 |
private JTextField queryField; |
| 48 |
|
| 49 |
|
| 50 |
private JList resultList; |
| 51 |
|
| 52 |
|
| 53 |
private DefaultListModel listModel; |
| 54 |
|
| 55 |
|
| 56 |
private JButton searchButton; |
| 57 |
|
| 58 |
|
| 59 |
private HelpDialog dialog; |
| 60 |
|
| 61 |
|
| 62 |
private JScrollPane resultsScrollPane; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public HelpSearchPanel (HelpIndexRoot root,HelpDialog dialog) { |
| 71 |
this.root = root; |
| 72 |
this.dialog = dialog; |
| 73 |
|
| 74 |
setLayout(new BorderLayout()); |
| 75 |
|
| 76 |
JPanel queryPanel = new JPanel(); |
| 77 |
queryPanel.setLayout(new BorderLayout()); |
| 78 |
queryPanel.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); |
| 79 |
queryField = new JTextField(); |
| 80 |
queryField.setActionCommand("search"); |
| 81 |
queryField.addActionListener(this); |
| 82 |
queryPanel.add(queryField,BorderLayout.CENTER); |
| 83 |
searchButton = new JButton("Search"); |
| 84 |
searchButton.setActionCommand("search"); |
| 85 |
searchButton.addActionListener(this); |
| 86 |
queryPanel.add(searchButton,BorderLayout.EAST); |
| 87 |
add(queryPanel,BorderLayout.NORTH); |
| 88 |
|
| 89 |
listModel = new DefaultListModel(); |
| 90 |
listModel.addElement("[No search results]"); |
| 91 |
resultList = new JList(listModel); |
| 92 |
resultList.addListSelectionListener(this); |
| 93 |
resultList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
| 94 |
resultsScrollPane = new JScrollPane(resultList); |
| 95 |
add(resultsScrollPane,BorderLayout.CENTER); |
| 96 |
|
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
public void actionPerformed(ActionEvent e) { |
| 103 |
Thread t = new Thread(this); |
| 104 |
t.start(); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public void valueChanged(ListSelectionEvent lse) { |
| 111 |
Object o = resultList.getSelectedValue(); |
| 112 |
if (o != null && o instanceof HelpPage) { |
| 113 |
dialog.DisplayPage((HelpPage)o); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public void run() { |
| 121 |
searchButton.setEnabled(false); |
| 122 |
listModel.removeAllElements(); |
| 123 |
if (queryField.getText().trim().length() > 0) { |
| 124 |
HelpPage[] results; |
| 125 |
try { |
| 126 |
results = root.findPagesForTerm(queryField.getText().trim()); |
| 127 |
} |
| 128 |
catch (IOException e) { |
| 129 |
e.printStackTrace(); |
| 130 |
searchButton.setEnabled(true); |
| 131 |
return; |
| 132 |
} |
| 133 |
if (results.length > 0) { |
| 134 |
for (int r=0;r<results.length;r++) { |
| 135 |
listModel.addElement(results[r]); |
| 136 |
} |
| 137 |
} |
| 138 |
else { |
| 139 |
listModel.addElement("[No search results]"); |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
remove(resultsScrollPane); |
| 150 |
revalidate(); |
| 151 |
resultList = new JList(listModel); |
| 152 |
resultList.addListSelectionListener(this); |
| 153 |
resultsScrollPane = new JScrollPane(resultList); |
| 154 |
add(resultsScrollPane,BorderLayout.CENTER); |
| 155 |
revalidate(); |
| 156 |
repaint(); |
| 157 |
|
| 158 |
searchButton.setEnabled(true); |
| 159 |
} |
| 160 |
} |