Changeset 2210 for trunk/java-client


Ignore:
Timestamp:
2001-03-20T19:16:07+12:00 (23 years ago)
Author:
daven
Message:

improved collection information dialog with HTML display
of long collection descriptions

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

Legend:

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

    r2197 r2210  
    3838
    3939import javax.swing.*;
     40import javax.swing.text.*;
     41import javax.swing.text.html.*;
    4042import java.awt.*;
    4143import java.awt.event.*;
    4244import java.util.*;
    4345import java.text.*;
     46import java.io.*;
    4447
    4548import org.nzdl.gsdl.service.*;
    4649
    47 public class CollectionInfoDialog extends JDialog implements ActionListener {
     50public class CollectionInfoDialog extends JDialog implements ActionListener, Constants {
    4851
    4952private JButton okButton;
    50 private JPanel  buttonPanel, holderPanel, contentPanel;
    51     private String publicString, betaString;
    52     private JLabel sizeLabel;
    53 
    54 CollectionInfoDialog(Frame f, String collectionName, CSModel csModel) {
     53private JPanel  buttonPanel, holderPanel, contentPanel, collectionNamePanel;
     54private String publicString, betaString;
     55private String fullCollectionName = "";
     56private String descString = "";
     57private NumberFormat numFormat = NumberFormat.getInstance();
     58
     59CollectionInfoDialog(Frame f, String collectionName, NzdlService nzdl) {
    5560    super(f, "Collection Information" );
    5661
    5762    contentPanel = new JPanel(new GridLayout(0,2, 5, 4));;
    58            
    5963    buttonPanel = new JPanel();
    6064
    61     JLabel prefTitle = new JLabel(collectionName, SwingConstants.CENTER);
    62     prefTitle.setAlignmentX(JLabel.CENTER_ALIGNMENT);
    63     JPanel prefTitlePanel = new JPanel();
    64     prefTitlePanel.add(prefTitle);
    65 
    66     NzdlCollectionInfo collectionInfo =  csModel.getNzdlService().getCollectionInfo(collectionName);
    67 
    68     contentPanel.add(new JLabel("Collection:"));
     65    NzdlCollectionInfo collectionInfo =  nzdl.getCollectionInfo(collectionName);
     66    Set n = nzdl.getMetaData(collectionName, "collection", "collectionname");
     67      if (n.size() == 1) {
     68    fullCollectionName =  (String) n.toArray()[0];
     69     }
     70    else {
     71    System.err.println(collectionName + " has more than 1 collectionname");
     72    }
     73    n.clear();
     74
     75    collectionNamePanel = new JPanel();
     76    // collectionNamePanel.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
     77    collectionNamePanel.add(new JLabel(fullCollectionName));
     78
     79    contentPanel.add(new JLabel("Short collection name:"));
    6980    JLabel collectionLabel = new JLabel(collectionName);
    7081    contentPanel.add(collectionLabel);
    7182    contentPanel.add(new JLabel("Number of Documents:"));
    72     contentPanel.add(new JLabel("" + collectionInfo.getNumOfDocs()));
     83    String numOfDocs = numFormat.format( collectionInfo.getNumOfDocs());
     84    contentPanel.add(new JLabel(numOfDocs));
    7385    contentPanel.add(new JLabel("Number of Words:"));
    74     contentPanel.add(new JLabel("" +  collectionInfo.getNumOfWords()));
     86    String numOfWords = numFormat.format( collectionInfo.getNumOfWords());
     87    contentPanel.add(new JLabel(numOfWords));
    7588    contentPanel.add(new JLabel("Size:"));
    7689    long numOfBytes = collectionInfo.getNumOfBytes();
    77     if (numOfBytes > 1023) {
    78     sizeLabel = new JLabel((numOfBytes / 1024) + " K");
    79     }
    80     else {
    81     sizeLabel = new JLabel(numOfBytes + " bytes");
    82     }
    83     contentPanel.add(sizeLabel);
     90    contentPanel.add(new JLabel(formatByteSize(numOfBytes)));
    8491    contentPanel.add(new JLabel("Last built on:"));
    8592    Date buildDate = new Date( collectionInfo.getBuildDate()*1000);
     
    99106    contentPanel.add(new JLabel(betaString));
    100107
     108    JPanel descPanel = new JPanel();
     109    Set descSet = nzdl.getMetaData(collectionName, "collection", "collectionextra");
     110    if (descSet.size() == 1) {
     111    descString = (String) descSet.toArray()[0];
     112    //System.err.println(descString);
     113    if (descString.length() > 0) {
     114        descPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10,2,5,2), BorderFactory.createTitledBorder("Description")));
     115        JTextPane descPane = new JTextPane();
     116        HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
     117        HTMLDocument htmlDoc = new HTMLDocument();
     118        descPane.setEditorKit(htmlEditorKit);
     119        try {
     120        htmlEditorKit.read(new StringReader(descString), htmlDoc, 0);
     121        }
     122        catch (Exception e) {
     123        System.err.println(e);
     124        }
     125        descPane.setEditable(false);
     126        descPane.setFont(docFont);
     127        descPane.setDocument(htmlDoc);
     128        descPane.setCaretPosition(1); // we know descString.length() > 0
     129        JScrollPane scrollPane = new JScrollPane(descPane);
     130        scrollPane.setPreferredSize(new Dimension(420, 130));
     131        descPanel.add(scrollPane);
     132    } // if
     133    } // if
     134    descSet.clear();
     135
    101136    okButton = new JButton("Ok");
    102137    okButton.setPreferredSize(new Dimension(80,20));
     
    104139    buttonPanel.add( okButton );
    105140    getRootPane().setDefaultButton(okButton);
    106 
     141   
    107142    holderPanel = new JPanel();
    108143    holderPanel.setBorder(BorderFactory.createEmptyBorder(10,10,2,10));
    109     holderPanel.setLayout( new BorderLayout());
    110     holderPanel.add( contentPanel, BorderLayout.NORTH);
    111     holderPanel.add( buttonPanel, BorderLayout.SOUTH);
     144    holderPanel.setLayout( new BoxLayout(holderPanel, BoxLayout.Y_AXIS));
     145    holderPanel.add(collectionNamePanel);
     146    holderPanel.add(contentPanel);
     147    if (descString.length() > 0) {
     148    holderPanel.add(Box.createVerticalStrut(10));
     149    holderPanel.add(descPanel); // only if we have a description to show
     150    }
     151    holderPanel.add(Box.createVerticalStrut(5));
     152    holderPanel.add(buttonPanel);
    112153    getContentPane().add(holderPanel);
    113     //setSize(new Dimension(300,300));
    114 
    115154    pack();
    116155    setVisible(true);
    117 } //end CollectionInfoDialog constructor
     156    } //end CollectionInfoDialog constructor
    118157
    119158
     
    133172} //end actionPerformed
    134173
     174
     175    /* generate a string with correct sizing information */
     176    /* bytes, K or G */
     177    public String formatByteSize (long numberOfBytes) {
     178    int minfd = numFormat.getMinimumFractionDigits();
     179    int maxfd = numFormat.getMaximumFractionDigits();
     180    String resultString;
     181    numFormat.setMinimumFractionDigits(1);
     182    numFormat.setMaximumFractionDigits(1);
     183    if (numberOfBytes > 1073741824)
     184         resultString =  numFormat.format((numberOfBytes / (float)1073741824)) + " G";
     185    else
     186        if (numberOfBytes > 1048576)
     187        resultString = numFormat.format((numberOfBytes / (float)1048576)) + " M";
     188        else {
     189        numFormat.setMinimumFractionDigits(0);
     190        numFormat.setMaximumFractionDigits(0);
     191        if (numberOfBytes > 1024)
     192            resultString = numFormat.format((numberOfBytes / (float)1024)) + " K";
     193            else
     194            resultString =  numFormat.format(numberOfBytes) + " bytes";
     195        }
     196    numFormat.setMinimumFractionDigits(minfd);
     197    numFormat.setMaximumFractionDigits(maxfd);
     198        return resultString;
     199} // end formatByteSize
     200
     201
     202
    135203} // end CollectionInfoDialog class
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/SearchPanel.java

    r2199 r2210  
    252252    if (e.getSource() == collectionInfoButton) {
    253253        //System.err.println("colllection info button pressed");
    254         CollectionInfoDialog cid = new CollectionInfoDialog(windowParent, collectionList.getSelectedItem().toString(), csModel);
     254        CollectionInfoDialog cid = new CollectionInfoDialog(windowParent, collectionList.getSelectedItem().toString(), nzdl);
    255255    }
    256256    else {
Note: See TracChangeset for help on using the changeset viewer.