source: trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/CollectionInfoDialog.java@ 2225

Last change on this file since 2225 was 2225, checked in by daven, 23 years ago

added QueryHistory, tooltips on collectionInfoButton. Altered
CSModel to retain CollectionInfo objects and longCollectionNames
for performance. Added files for a BerryBasket - to be turned on
soon. Added sorting of the QueryHistory via the TableMap and TableSorter
files - from the Java Swing tutorial - not sure about GPL status
of these 2.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/*
2
3 * CollectionInfoDialog.java
4 * Copyright (C) 2001 New Zealand Digital Library Project
5
6 *
7
8 * This program is free software; you can redistribute it and/or modify
9
10 * it under the terms of the GNU General Public License as published by
11
12 * the Free Software Foundation; either version 2 of the License, or
13
14 * (at your option) any later version.
15
16 *
17
18 * This program is distributed in the hope that it will be useful,
19
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
24 * GNU General Public License for more details.
25
26 *
27
28 * You should have received a copy of the GNU General Public License
29
30 * along with this program; if not, write to the Free Software
31
32 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33
34 */
35
36
37package org.nzdl.gsdl.SimpleGraphicalClient;
38
39import javax.swing.*;
40import javax.swing.text.*;
41import javax.swing.text.html.*;
42import java.awt.*;
43import java.awt.event.*;
44import java.util.*;
45import java.text.*;
46import java.io.*;
47
48import org.nzdl.gsdl.service.*;
49
50public class CollectionInfoDialog extends JDialog implements ActionListener, Constants {
51
52private JButton okButton;
53private JPanel buttonPanel, holderPanel, contentPanel, collectionNamePanel;
54private String publicString, betaString;
55private String fullCollectionName = "";
56private String descString = "";
57private String numOfWordsString, numOfDocsString;
58private NumberFormat numFormat = NumberFormat.getInstance();
59
60 CollectionInfoDialog(Frame f, String collectionName, CSModel csModel) {
61 super(f, "Collection Information" );
62
63 contentPanel = new JPanel(new GridLayout(0,2, 5, 4));;
64 buttonPanel = new JPanel();
65
66 NzdlCollectionInfo collectionInfo = csModel.getCollectionInfo(collectionName);
67 /*
68 Set n = nzdl.getMetaData(collectionName, "collection", "collectionname");
69 if (n.size() == 1) {
70 fullCollectionName = (String) n.toArray()[0];
71 }
72 else {
73 System.err.println(collectionName + " has more than 1 collectionname");
74 }
75 n.clear();
76 */
77 collectionNamePanel = new JPanel();
78 // collectionNamePanel.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
79 collectionNamePanel.add(new JLabel(csModel.getLongCollectionName(collectionName)));
80
81 contentPanel.add(new JLabel("Short collection name:"));
82 JLabel collectionLabel = new JLabel(collectionName);
83 contentPanel.add(collectionLabel);
84 contentPanel.add(new JLabel("Number of Documents:"));
85
86 long numOfDocs = collectionInfo.getNumOfDocs();
87 if (numOfDocs == 0)
88 numOfDocsString = "unknown";
89 else
90 numOfDocsString = numFormat.format(numOfDocs);
91 contentPanel.add(new JLabel(numOfDocsString));
92 contentPanel.add(new JLabel("Number of Words:"));
93
94 long numOfWords = collectionInfo.getNumOfWords();
95 if (numOfWords == 0)
96 numOfWordsString = "unknown";
97 else
98 numOfWordsString = numFormat.format(numOfWords);
99 contentPanel.add(new JLabel(numOfWordsString));
100 contentPanel.add(new JLabel("Size:"));
101 long numOfBytes = collectionInfo.getNumOfBytes();
102 contentPanel.add(new JLabel(formatByteSize(numOfBytes)));
103 contentPanel.add(new JLabel("Last built on:"));
104 // waiting for API to return a correct Date object ...
105 Date buildDate = new Date( collectionInfo.getBuildDate()*1000);
106 contentPanel.add(new JLabel(DateFormat.getDateTimeInstance().format(buildDate)));
107 contentPanel.add(new JLabel("Is it Public?"));
108
109 if (collectionInfo.isPublic())
110 publicString = "yes";
111 else
112 publicString = "no";
113 contentPanel.add(new JLabel(publicString));
114 contentPanel.add(new JLabel("Is it beta?"));
115 if (collectionInfo.isBeta())
116 betaString = "yes";
117 else
118 betaString = "no";
119 contentPanel.add(new JLabel(betaString));
120
121 JPanel descPanel = new JPanel();
122 descString = csModel.getCollectionDescription(collectionName);
123 //System.err.println(descString);
124 if (descString.length() > 0) {
125 descPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10,2,5,2), BorderFactory.createTitledBorder("Description")));
126 JTextPane descPane = new JTextPane();
127 HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
128 HTMLDocument htmlDoc = new HTMLDocument();
129 descPane.setEditorKit(htmlEditorKit);
130 try {
131 htmlEditorKit.read(new StringReader(descString), htmlDoc, 0);
132 }
133 catch (Exception e) {
134 System.err.println(e);
135 }
136 descPane.setEditable(false);
137 descPane.setFont(docFont);
138 descPane.setDocument(htmlDoc);
139 descPane.setCaretPosition(1); // we know descString.length() > 0
140 JScrollPane scrollPane = new JScrollPane(descPane);
141 scrollPane.setPreferredSize(new Dimension(420, 130));
142 descPanel.add(scrollPane);
143 } // if
144
145 okButton = new JButton("Ok");
146 okButton.setPreferredSize(new Dimension(80,20));
147 okButton.addActionListener(this);
148 buttonPanel.add( okButton );
149 getRootPane().setDefaultButton(okButton);
150
151 holderPanel = new JPanel();
152 holderPanel.setBorder(BorderFactory.createEmptyBorder(10,10,2,10));
153 holderPanel.setLayout( new BoxLayout(holderPanel, BoxLayout.Y_AXIS));
154 holderPanel.add(collectionNamePanel);
155 holderPanel.add(contentPanel);
156 if (descString.length() > 0) {
157 holderPanel.add(Box.createVerticalStrut(10));
158 holderPanel.add(descPanel); // only if we have a description to show
159 }
160 holderPanel.add(Box.createVerticalStrut(5));
161 holderPanel.add(buttonPanel);
162 getContentPane().add(holderPanel);
163 pack();
164 setVisible(true);
165 } //end CollectionInfoDialog constructor
166
167
168
169public void actionPerformed(ActionEvent e) {
170 Object source = e.getSource();
171 if (source == okButton)
172 {
173 //System.err.println("ok button pressed!");
174
175 dispose(); //close window
176 }
177 else
178 {
179 System.err.println("event not processed in CollectionInfoDialog");
180 }
181} //end actionPerformed
182
183
184 /* generate a string with correct sizing information */
185 /* bytes, K or G */
186 public String formatByteSize (long numberOfBytes) {
187 int minfd = numFormat.getMinimumFractionDigits();
188 int maxfd = numFormat.getMaximumFractionDigits();
189 String resultString;
190 numFormat.setMinimumFractionDigits(1);
191 numFormat.setMaximumFractionDigits(1);
192 if (numberOfBytes > 1073741824)
193 resultString = numFormat.format((numberOfBytes / (float)1073741824)) + " G";
194 else
195 if (numberOfBytes > 1048576)
196 resultString = numFormat.format((numberOfBytes / (float)1048576)) + " M";
197 else {
198 numFormat.setMinimumFractionDigits(0);
199 numFormat.setMaximumFractionDigits(0);
200 if (numberOfBytes > 1024)
201 resultString = numFormat.format((numberOfBytes / (float)1024)) + " K";
202 else
203 resultString = numFormat.format(numberOfBytes) + " bytes";
204 }
205 numFormat.setMinimumFractionDigits(minfd);
206 numFormat.setMaximumFractionDigits(maxfd);
207 return resultString;
208} // end formatByteSize
209
210
211
212} // end CollectionInfoDialog class
Note: See TracBrowser for help on using the repository browser.