Changeset 2190 for trunk/java-client


Ignore:
Timestamp:
2001-03-18T12:39:16+12:00 (23 years ago)
Author:
daven
Message:

preference for displaying raw text or HTML now working

Location:
trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient
Files:
4 edited

Legend:

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

    r2184 r2190  
    5050
    5151
     52    /* Preference Strings */
     53
     54    String DISPLAY_FIRST_DOC = "Automatically display the first document";
     55    String RAW_TEXT = "Always display raw text (don't interpret HTML)";
     56    String MULTIPLE_SERVERS =  "Connect to multiple servers";
     57    String LOG_SERVICE = "Log at the NzdlService level";
     58    String CACHE_CORBA = "Cache corba requests";
     59    String SAVE_DOCS = "Save documents";
     60
    5261/*Fonts */
    5362
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/PreferencesDialog.java

    r2188 r2190  
    5050private JPanel  buttonPanel, holderPanel;
    5151private Box contentBox;
     52    private JCheckBox showFirstDocCheckBox, showAsTextCheckBox, connectToMultipleCheckBox, logNetworkLevelCheckBox, useCacheCheckBox,  saveDocsCheckBox;
     53
    5254
    5355
     
    7072
    7173    //contentBox.add();
    72     String preferanceName = null;
    7374    // the preferences themselves ...
    7475
    75     preferanceName = "Automatically display the first document";
    76     JCheckBox showFirstDocCheckBox =
    77       new JCheckBox(preferanceName, NzdlPreferences.getBoolean(preferanceName));
     76    showFirstDocCheckBox =
     77      new JCheckBox( Constants.DISPLAY_FIRST_DOC, NzdlPreferences.getBoolean( Constants.DISPLAY_FIRST_DOC));
    7878    showFirstDocCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
    7979
    80     preferanceName = "Always display raw text (don't interpret HTML)";
    81     JCheckBox showAsTextCheckBox =
    82       new JCheckBox(preferanceName, NzdlPreferences.getBoolean(preferanceName));
     80    showAsTextCheckBox =
     81      new JCheckBox( Constants.RAW_TEXT, NzdlPreferences.getBoolean(Constants.RAW_TEXT));
    8382    showAsTextCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
    8483
    85     preferanceName = "Connect to multiple servers";
    86     JCheckBox connectToMultipleCheckBox =
    87       new JCheckBox(preferanceName, NzdlPreferences.getBoolean(preferanceName));
     84    connectToMultipleCheckBox =
     85      new JCheckBox(Constants.MULTIPLE_SERVERS, NzdlPreferences.getBoolean(Constants.MULTIPLE_SERVERS));
    8886    connectToMultipleCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
    8987
    90     preferanceName = "Log at the NzdlService level";
    91     JCheckBox logNetworkLevelCheckBox =
    92       new JCheckBox(preferanceName, NzdlPreferences.getBoolean(preferanceName));
     88    logNetworkLevelCheckBox =
     89      new JCheckBox(Constants.LOG_SERVICE, NzdlPreferences.getBoolean(Constants.LOG_SERVICE));
    9390    logNetworkLevelCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
    9491
    95     preferanceName = "Cache corba requests";
    96     JCheckBox useCacheCheckBox =
    97       new JCheckBox(preferanceName, NzdlPreferences.getBoolean(preferanceName));
     92    useCacheCheckBox =
     93      new JCheckBox(Constants.CACHE_CORBA, NzdlPreferences.getBoolean(Constants.CACHE_CORBA));
    9894    useCacheCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
    9995
    100     preferanceName = "Save documents";
    101     JCheckBox saveDocsCheckBox =
    102       new JCheckBox(preferanceName, NzdlPreferences.getBoolean(preferanceName));
     96    saveDocsCheckBox =
     97      new JCheckBox(Constants.SAVE_DOCS, NzdlPreferences.getBoolean(Constants.SAVE_DOCS));
    10398    saveDocsCheckBox.setHorizontalAlignment(SwingConstants.LEFT);
    104 
    10599
    106100    // add the preferences ...
     
    144138        //System.err.println("ok button pressed!");
    145139
     140        NzdlPreferences.setBoolean(Constants.DISPLAY_FIRST_DOC,showFirstDocCheckBox.isSelected());
     141        NzdlPreferences.setBoolean(Constants.RAW_TEXT, showAsTextCheckBox.isSelected());
     142        NzdlPreferences.setBoolean(Constants.MULTIPLE_SERVERS, connectToMultipleCheckBox.isSelected());
     143        NzdlPreferences.setBoolean(Constants.LOG_SERVICE,logNetworkLevelCheckBox.isSelected());
     144        NzdlPreferences.setBoolean(Constants.CACHE_CORBA, useCacheCheckBox.isSelected());
     145        NzdlPreferences.setBoolean(Constants.SAVE_DOCS, saveDocsCheckBox.isSelected());
    146146      NzdlPreferences.getInstance().save();
    147147      dispose(); //close window
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/SearchPanel.java

    r2184 r2190  
    3838import org.nzdl.gsdl.service.NzdlService;
    3939import org.nzdl.gsdl.service.NzdlServiceClient;
     40import org.nzdl.gsdl.util.NzdlPreferences;
    4041
    4142
     
    7071  JFrame windowParent;
    7172    //JEditorPane documentPane;
    72     JTextPane documentPane;
    73   HTMLEditorKit htmlEditorKit;
     73    JTextPane documentPane; // make this a JTextComponent ??
     74    JTextArea documentArea;
     75    JTextComponent documentComponent;
     76    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
     77    StyledEditorKit styledEditorKit = new StyledEditorKit();
    7478    GMLDocument htmlDoc = new GMLDocument();
     79    DefaultStyledDocument defaultStyledDoc = new DefaultStyledDocument();
    7580    final static GMLDocument blankDoc = new GMLDocument();
    7681 
     
    149154    dataPanel.setLayout(new BorderLayout());
    150155    dataPanel.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
    151      documentPane = new JTextPane();
    152      //documentPane = new JEditorPane();
    153     htmlEditorKit  =  new HTMLEditorKit();   
    154     documentPane.setEditorKit(htmlEditorKit);
     156    documentPane = new JTextPane() { // to control scrolling for raw text docs
     157                           public boolean getScrollableTracksViewportWidth() {
     158                           if (getSize().width < getParent().getSize().width)
     159                    return true;
     160                           else return false;
     161                           }
     162                           public void setSize(Dimension d) {
     163                           if (d.width < getParent().getSize().width)
     164                    d.width = getParent().getSize().width;
     165                                super.setSize(d);
     166                           }
     167    }; // end custom JTextPane
    155168    documentPane.setEditable(false);
    156169    documentPane.setFont(docFont);
     
    225238      csModel.addResult(new Result((String)titleMap.get(resultDocID), resultDocID, collectionName ));
    226239    } //end while
     240    if (NzdlPreferences.getInstance().getBoolean(Constants.DISPLAY_FIRST_DOC))
    227241    resultsList.setSelectedIndex(0); // should be under Preference control!
    228242      } // end else
     
    258272      }
    259273      else {
    260 
    261       Date startTime = new Date();
     274 // a real result representing a real document to deal with
     275
    262276      windowParent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    263       //trash the old htmlDoc ...
     277      //trash the old htmlDoc for memory/garbage collection
    264278      try {
    265279        if (htmlDoc != null)
    266280          htmlDoc.remove(0, htmlDoc.getLength());
     281        if (defaultStyledDoc != null)
     282        defaultStyledDoc.remove(0, defaultStyledDoc.getLength());
    267283      } catch (Exception exception) {
    268284        throw new Error (exception.toString());
    269285      }
     286      defaultStyledDoc = new DefaultStyledDocument();
    270287      htmlDoc = new GMLDocument();
    271       Date t1 = new Date();
    272       Date d1 = new Date();
    273       Date d2 = new Date();
    274       Date d21 = new Date();
    275       Date d3 = new Date();
    276       try { // get the document and read it in as HTML
    277            d1 = new Date();
     288
     289      try { // get the document
    278290          String docContents = csModel.getNzdlService().getDocument(result.getCollectionName(),  result.getDocID());
    279            d2 = new Date();
    280           //long ddiff1 = d2.getTime() - d1.getTime();
    281           // System.err.println("getDocument = " + ddiff1 + "ms");
    282            StringReader sr = new StringReader(docContents);
    283            d21 = new Date();
    284            htmlEditorKit.read( sr, htmlDoc, 0); // should be under preference control!
    285            d3 = new Date();
    286           //long ddiff2 = d3.getTime() - d2.getTime();
    287               //System.err.println("StringReader() = " + ddiff2 + "ms");
    288          
    289           // htmlEditorKit.read( new StringReader(csModel.getNzdlService().getDocument(result.getCollectionName(),  result.getDocID())), htmlDoc, 0);
    290       }
     291           StringReader sr = new StringReader( docContents);
     292           if (NzdlPreferences.getInstance().getBoolean(Constants.RAW_TEXT)) { // display the document as raw text
     293           documentPane.setEditorKit(styledEditorKit);
     294           styledEditorKit.read( sr, defaultStyledDoc, 0);
     295           documentPane.setDocument(defaultStyledDoc);
     296           }
     297           else { // treat as HTML
     298           documentPane.setEditorKit(htmlEditorKit);
     299           htmlEditorKit.read( sr, htmlDoc, 0);
     300           documentPane.setStyledDocument( htmlDoc );
     301           }
     302           // htmlEditorKit.read( new StringReader(csModel.getNzdlService().getDocument(result.getCollectionName(),  result.getDocID())), htmlDoc, 0);
     303           }
    291304      catch(BadLocationException badLocException)
    292305      {
     
    297310          System.err.println("IO Exception whilst reading doc contents" + ioException);
    298311      }
    299       Date t2 = new Date();
    300       long diff = t2.getTime() - t1.getTime();
    301       long ddiff1 = d2.getTime() - d1.getTime();
    302       long ddiff2 = d21.getTime() - d2.getTime();
    303       long ddiff3 = d3.getTime() - d21.getTime();
    304       System.err.println("nzdl.getDocument = " + ddiff1 + "ms");
    305       System.err.println("StringReader() constructor = " + ddiff2 + "ms");
    306       System.err.println("EditorKit.read() = " + ddiff3 + " ms");
    307       System.err.println("getDocument total = " + diff + " ms");
    308      
    309       Date t3 = new Date();
    310 
    311       documentPane.setStyledDocument( htmlDoc );
    312 
    313       Date t4 = new Date();
    314       long diff2 = t4.getTime() - t3.getTime();
    315       System.err.println("documentPane set " + diff2 + " ms");
    316 
     312
     313      //documentPane.setStyledDocument( htmlDoc );
     314      // should check for empty document here
    317315      documentPane.setCaretPosition(1);
    318 
    319       //Date t5 = new Date();
    320       //long diff7 = t5.getTime() - t4.getTime();
    321       //System.err.println("documentPane scroll " + diff7 + " ms");
    322 
    323       //System.err.println("getting image data...");
    324           htmlDoc.getImageData(nzdl, result.getCollectionName());
     316      // we might not be using htmlDoc at this point!!
     317      //htmlDoc.getImageData(nzdl, result.getCollectionName());
    325318      windowParent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    326       Date endTime = new Date();
    327       long diff5 = endTime.getTime() - startTime.getTime();
    328       System.err.println("total time " + diff5 + " ms");
    329319      //System.err.println("prefix = " + nzdl.getCollectionInfo(result.getCollectionName()).getHTTPPrefix());
    330320      }
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/SimpleGraphicalClient.java

    r2184 r2190  
    3333import org.nzdl.gsdl.service.NzdlService;
    3434import org.nzdl.gsdl.service.NzdlServiceClient;
     35import org.nzdl.gsdl.util.NzdlPreferences;
    3536import org.nzdl.gsdl.util.NzdlServiceFactory;
    3637
Note: See TracChangeset for help on using the changeset viewer.