Changeset 2153 for trunk/java-client/org/nzdl
- Timestamp:
- 2001-03-10T12:50:08+13:00 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/SearchPanel.java
r2152 r2153 25 25 import javax.swing.*; 26 26 import javax.swing.border.*; 27 import javax.swing.event.*; 27 import javax.swing.event.*; 28 import javax.swing.text.*; 29 import javax.swing.text.html.*; 30 28 31 29 32 // local libraries … … 38 41 39 42 /** 40 * A Class representing the Panel in which the Queryi gnaction happens.43 * A Class representing the Panel in which the Querying action happens. 41 44 * 42 45 * Does most of the actual `work' in the package. … … 63 66 JList resultsList; 64 67 JScrollPane scrollResultsPane; 68 JScrollPane scrollDataPane; 69 JFrame windowParent; 65 70 /** where the doc contents are displayed */ 66 JEditorPane dataTextArea; 67 JScrollPane scrollDataPane; 68 71 JTextPane documentPane; 72 HTMLEditorKit htmlEditorKit; 73 HTMLDocument htmlDoc; 74 69 75 final static String DOC_HEADER = "<html><body>"; 70 76 final static String DOC_FOOTER = "</body></html>"; … … 77 83 { 78 84 super(); 85 windowParent = parent; 79 86 csModel = newCsModel; 80 87 setLayout( new BoxLayout(this, BoxLayout.Y_AXIS)); … … 87 94 } 88 95 }; 89 90 91 96 searchTextField.setText("Enter search terms here"); 92 97 searchTextField.setFont(searchTextFieldFont); 93 98 searchTextField.setColumns(35); 94 searchTextField.setBorder(BorderFactory.createEmptyBorder( 0,2,0,2));99 searchTextField.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); 95 100 searchButton = new JButton("Search"); 96 101 … … 103 108 collectionListPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); 104 109 collectionLabel = new JLabel("Collection: "); 105 /*collectionList = new JComboBox(csModel.getCollectionList()){ 106 public boolean isFocusTraversable() { 107 return false; 108 } 109 }; */ 110 //System.err.println("size is " + csModel.getCollectionListSize()); 111 //Collection coll = csModel.getCollectionList(); 112 //System.err.println("coll size is " + coll.size()); 113 //Vector vec = new Vector(coll); 114 //System.err.println("vector size is " + vec.size()); 110 115 111 collectionList = new JComboBox(csModel.getCollectionList()){ 116 112 public boolean isFocusTraversable() { … … 119 115 }; 120 116 121 122 123 124 125 117 //collectionList.setSelectedIndex(0); // only if there is content 126 118 collectionListPanel.add(collectionLabel); 127 119 collectionListPanel.add(collectionList); 128 120 129 130 121 searchTextFieldPanel = new JPanel(); 131 122 searchTextFieldPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); … … 143 134 queryFormulationPanel.add(searchTextFieldPanel); 144 135 queryFormulationPanel.add(searchButtonPanel); 145 146 136 147 137 resultsPanel = new JPanel(); … … 160 150 dataPanel.setLayout(new BorderLayout()); 161 151 dataPanel.setBorder(BorderFactory.createEmptyBorder(3,3,3,3)); 162 dataTextArea = new JEditorPane("text/html", 163 "<html><body>Document details will appear here.</body></html>"); 164 dataTextArea.setEditable(false); 165 dataTextArea.setEditable(false); 166 dataTextArea.setFont(docFont); 167 dataTextArea.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 168 //dataTextArea.setPreferredSize(new Dimension(100, 100)); 169 scrollDataPane = new JScrollPane(dataTextArea); 152 /* documentPane = new JEditorPane("text/html", 153 "<html><body>Document details will appear here.</body></html>"); 154 */ 155 documentPane = new JTextPane(); 156 htmlEditorKit = new HTMLEditorKit(); 157 158 documentPane.setEditorKit(htmlEditorKit); 159 documentPane.setEditable(false); 160 documentPane.setFont(docFont); 161 documentPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 162 //documentPane.setPreferredSize(new Dimension(100, 100)); 163 164 scrollDataPane = new JScrollPane(documentPane); 170 165 scrollDataPane.setPreferredSize(new Dimension(300, 300)); 171 166 dataPanel.add(scrollDataPane, BorderLayout.CENTER); … … 185 180 186 181 /** respond to the user pressing the Search button */ 182 187 183 188 184 public void actionPerformed(ActionEvent e) { … … 218 214 if (docIDs.size() == 0 ) { // no real results 219 215 csModel.addResult(new Result(Result.FAKE_RESULT, "", "")); 216 documentPane.setText(""); 220 217 } 221 218 else { // there are some results … … 246 243 Result result = (Result) resultsList.getSelectedValue(); 247 244 if (result.toString() == Result.FAKE_RESULT) { 248 dataTextArea.setText(""); 249 //System.err.println("no results"); 245 //System.err.println("no results"); 246 documentPane.setText(""); 247 //System.err.println("no results"); 250 248 } 251 249 else { 252 //get the document content from the result object 253 // use a String for the moment to hold the contents 254 // should cache document contents here to speed access 255 String documentContents = csModel.getNzdlService().getDocument(result.getCollectionName(), result.getDocID()); 256 documentContents = DOC_HEADER + documentContents + DOC_FOOTER; 257 dataTextArea.setText(documentContents); 258 dataTextArea.setCaretPosition(0); 250 windowParent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 251 //get the document content from the result object 252 // use a String for the moment to hold the contents 253 // should cache document contents here to speed access 254 // String documentContents = csModel.getNzdlService().getDocument(result.getCollectionName(), result.getDocID()); 255 htmlDoc = new HTMLDocument(); 256 try 257 { 258 htmlEditorKit.read( new StringReader(csModel.getNzdlService().getDocument(result.getCollectionName(), result.getDocID())), htmlDoc, 0); 259 } 260 catch(BadLocationException badLocException) 261 { 262 System.err.println("Bad Location Exception in creating HTML doc" + badLocException); 263 } 264 catch(IOException ioException) 265 { 266 System.err.println("IO Exception whilst reading doc contents" + ioException); 267 } 268 documentPane.setStyledDocument( htmlDoc ); 269 //documentContents = DOC_HEADER + documentContents + DOC_FOOTER; 270 //documentPane.setText(documentContents); 271 System.err.println("caret(before) = " + documentPane.getCaretPosition()); 272 documentPane.setCaretPosition(1); 273 System.err.println("caret = " + documentPane.getCaretPosition()); 274 windowParent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 259 275 } 260 276 } //end valueChanged
Note:
See TracChangeset
for help on using the changeset viewer.