Changeset 2210 for trunk/java-client
- Timestamp:
- 2001-03-20T19:16:07+12:00 (23 years ago)
- 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 38 38 39 39 import javax.swing.*; 40 import javax.swing.text.*; 41 import javax.swing.text.html.*; 40 42 import java.awt.*; 41 43 import java.awt.event.*; 42 44 import java.util.*; 43 45 import java.text.*; 46 import java.io.*; 44 47 45 48 import org.nzdl.gsdl.service.*; 46 49 47 public class CollectionInfoDialog extends JDialog implements ActionListener {50 public class CollectionInfoDialog extends JDialog implements ActionListener, Constants { 48 51 49 52 private 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) { 53 private JPanel buttonPanel, holderPanel, contentPanel, collectionNamePanel; 54 private String publicString, betaString; 55 private String fullCollectionName = ""; 56 private String descString = ""; 57 private NumberFormat numFormat = NumberFormat.getInstance(); 58 59 CollectionInfoDialog(Frame f, String collectionName, NzdlService nzdl) { 55 60 super(f, "Collection Information" ); 56 61 57 62 contentPanel = new JPanel(new GridLayout(0,2, 5, 4));; 58 59 63 buttonPanel = new JPanel(); 60 64 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:")); 69 80 JLabel collectionLabel = new JLabel(collectionName); 70 81 contentPanel.add(collectionLabel); 71 82 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)); 73 85 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)); 75 88 contentPanel.add(new JLabel("Size:")); 76 89 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))); 84 91 contentPanel.add(new JLabel("Last built on:")); 85 92 Date buildDate = new Date( collectionInfo.getBuildDate()*1000); … … 99 106 contentPanel.add(new JLabel(betaString)); 100 107 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 101 136 okButton = new JButton("Ok"); 102 137 okButton.setPreferredSize(new Dimension(80,20)); … … 104 139 buttonPanel.add( okButton ); 105 140 getRootPane().setDefaultButton(okButton); 106 141 107 142 holderPanel = new JPanel(); 108 143 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); 112 153 getContentPane().add(holderPanel); 113 //setSize(new Dimension(300,300));114 115 154 pack(); 116 155 setVisible(true); 117 } //end CollectionInfoDialog constructor156 } //end CollectionInfoDialog constructor 118 157 119 158 … … 133 172 } //end actionPerformed 134 173 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 135 203 } // end CollectionInfoDialog class -
trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/SearchPanel.java
r2199 r2210 252 252 if (e.getSource() == collectionInfoButton) { 253 253 //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); 255 255 } 256 256 else {
Note:
See TracChangeset
for help on using the changeset viewer.