Changeset 2153


Ignore:
Timestamp:
2001-03-10T12:50:08+13:00 (23 years ago)
Author:
daven
Message:

switch to using JTextPane, HTMLDocument, EditorKit etc implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/SearchPanel.java

    r2152 r2153  
    2525import javax.swing.*;
    2626import javax.swing.border.*;
    27 import javax.swing.event.*;
     27import javax.swing.event.*;
     28import javax.swing.text.*;
     29import javax.swing.text.html.*;
     30
    2831
    2932// local libraries
     
    3841
    3942/**
    40  * A Class representing the Panel in which the Queryign action happens.
     43 * A Class representing the Panel in which the Querying action happens.
    4144 *
    4245 * Does most of the actual `work' in the package.
     
    6366  JList   resultsList;   
    6467  JScrollPane scrollResultsPane;
     68  JScrollPane scrollDataPane;
     69  JFrame windowParent;
    6570  /** where the doc contents are displayed */
    66   JEditorPane dataTextArea; 
    67   JScrollPane scrollDataPane;
    68 
     71  JTextPane documentPane;
     72  HTMLEditorKit htmlEditorKit;
     73  HTMLDocument htmlDoc;
     74 
    6975  final static String DOC_HEADER = "<html><body>";
    7076  final static String DOC_FOOTER = "</body></html>";
     
    7783  {
    7884    super();
     85    windowParent = parent;
    7986    csModel = newCsModel;
    8087    setLayout( new BoxLayout(this, BoxLayout.Y_AXIS));
     
    8794    }
    8895      };
    89 
    90 
    9196    searchTextField.setText("Enter search terms here");
    9297    searchTextField.setFont(searchTextFieldFont);
    9398    searchTextField.setColumns(35);
    94     searchTextField.setBorder(BorderFactory.createEmptyBorder(0,2,0,2));
     99    searchTextField.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
    95100    searchButton = new JButton("Search");
    96101   
     
    103108    collectionListPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    104109    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
    115111    collectionList = new JComboBox(csModel.getCollectionList()){
    116112    public boolean isFocusTraversable() {
     
    119115      };
    120116
    121 
    122 
    123 
    124 
    125117    //collectionList.setSelectedIndex(0); // only if there is content
    126118    collectionListPanel.add(collectionLabel);
    127119    collectionListPanel.add(collectionList);
    128120
    129    
    130121    searchTextFieldPanel = new JPanel();
    131122    searchTextFieldPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
     
    143134    queryFormulationPanel.add(searchTextFieldPanel);
    144135    queryFormulationPanel.add(searchButtonPanel);
    145    
    146136   
    147137    resultsPanel = new JPanel();
     
    160150    dataPanel.setLayout(new BorderLayout());
    161151    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);
    170165    scrollDataPane.setPreferredSize(new Dimension(300, 300));
    171166    dataPanel.add(scrollDataPane, BorderLayout.CENTER);
     
    185180
    186181  /** respond to the user pressing the Search button */
     182
    187183
    188184  public void actionPerformed(ActionEvent e) {
     
    218214      if (docIDs.size() == 0 ) { // no real results
    219215    csModel.addResult(new Result(Result.FAKE_RESULT, "", ""));
     216    documentPane.setText("");
    220217      }
    221218      else { // there are some results
     
    246243      Result result =  (Result) resultsList.getSelectedValue();
    247244      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");
    250248      }
    251249      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);
     271System.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));
    259275      }
    260276    } //end valueChanged
Note: See TracChangeset for help on using the changeset viewer.