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

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

dynamically update display mode based on preference changes. i.e. if the user
switches to raw text mode the document display should update on the
exit of the prefences dialog, not until the user selects a new result.
Altered the listhandler in SearchPanel.java to simplify this and reduce
occurrences of multiple code.

  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 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
60CollectionInfoDialog(Frame f, String collectionName, NzdlService nzdl) {
61 super(f, "Collection Information" );
62
63 contentPanel = new JPanel(new GridLayout(0,2, 5, 4));;
64 buttonPanel = new JPanel();
65
66 NzdlCollectionInfo collectionInfo = nzdl.getCollectionInfo(collectionName);
67 Set n = nzdl.getMetaData(collectionName, "collection", "collectionname");
68 if (n.size() == 1) {
69 fullCollectionName = (String) n.toArray()[0];
70 }
71 else {
72 System.err.println(collectionName + " has more than 1 collectionname");
73 }
74 n.clear();
75
76 collectionNamePanel = new JPanel();
77 // collectionNamePanel.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
78 collectionNamePanel.add(new JLabel(fullCollectionName));
79
80 contentPanel.add(new JLabel("Short collection name:"));
81 JLabel collectionLabel = new JLabel(collectionName);
82 contentPanel.add(collectionLabel);
83 contentPanel.add(new JLabel("Number of Documents:"));
84
85 long numOfDocs = collectionInfo.getNumOfDocs();
86 if (numOfDocs == 0)
87 numOfDocsString = "unknown";
88 else
89 numOfDocsString = numFormat.format(numOfDocs);
90 contentPanel.add(new JLabel(numOfDocsString));
91 contentPanel.add(new JLabel("Number of Words:"));
92
93 long numOfWords = collectionInfo.getNumOfWords();
94 if (numOfWords == 0)
95 numOfWordsString = "unknown";
96 else
97 numOfWordsString = numFormat.format(numOfWords);
98 contentPanel.add(new JLabel(numOfWordsString));
99 contentPanel.add(new JLabel("Size:"));
100 long numOfBytes = collectionInfo.getNumOfBytes();
101 contentPanel.add(new JLabel(formatByteSize(numOfBytes)));
102 contentPanel.add(new JLabel("Last built on:"));
103 // waiting for API to return a correct Date object ...
104 Date buildDate = new Date( collectionInfo.getBuildDate()*1000);
105 contentPanel.add(new JLabel(DateFormat.getDateTimeInstance().format(buildDate)));
106 contentPanel.add(new JLabel("Is it Public?"));
107
108 if (collectionInfo.isPublic())
109 publicString = "yes";
110 else
111 publicString = "no";
112 contentPanel.add(new JLabel(publicString));
113 contentPanel.add(new JLabel("Is it beta?"));
114 if (collectionInfo.isBeta())
115 betaString = "yes";
116 else
117 betaString = "no";
118 contentPanel.add(new JLabel(betaString));
119
120 JPanel descPanel = new JPanel();
121 Set descSet = nzdl.getMetaData(collectionName, "collection", "collectionextra");
122 if (descSet.size() == 1) {
123 descString = (String) descSet.toArray()[0];
124 //System.err.println(descString);
125 if (descString.length() > 0) {
126 descPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10,2,5,2), BorderFactory.createTitledBorder("Description")));
127 JTextPane descPane = new JTextPane();
128 HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
129 HTMLDocument htmlDoc = new HTMLDocument();
130 descPane.setEditorKit(htmlEditorKit);
131 try {
132 htmlEditorKit.read(new StringReader(descString), htmlDoc, 0);
133 }
134 catch (Exception e) {
135 System.err.println(e);
136 }
137 descPane.setEditable(false);
138 descPane.setFont(docFont);
139 descPane.setDocument(htmlDoc);
140 descPane.setCaretPosition(1); // we know descString.length() > 0
141 JScrollPane scrollPane = new JScrollPane(descPane);
142 scrollPane.setPreferredSize(new Dimension(420, 130));
143 descPanel.add(scrollPane);
144 } // if
145 } // if
146 descSet.clear();
147
148 okButton = new JButton("Ok");
149 okButton.setPreferredSize(new Dimension(80,20));
150 okButton.addActionListener(this);
151 buttonPanel.add( okButton );
152 getRootPane().setDefaultButton(okButton);
153
154 holderPanel = new JPanel();
155 holderPanel.setBorder(BorderFactory.createEmptyBorder(10,10,2,10));
156 holderPanel.setLayout( new BoxLayout(holderPanel, BoxLayout.Y_AXIS));
157 holderPanel.add(collectionNamePanel);
158 holderPanel.add(contentPanel);
159 if (descString.length() > 0) {
160 holderPanel.add(Box.createVerticalStrut(10));
161 holderPanel.add(descPanel); // only if we have a description to show
162 }
163 holderPanel.add(Box.createVerticalStrut(5));
164 holderPanel.add(buttonPanel);
165 getContentPane().add(holderPanel);
166 pack();
167 setVisible(true);
168 } //end CollectionInfoDialog constructor
169
170
171
172public void actionPerformed(ActionEvent e) {
173 Object source = e.getSource();
174 if (source == okButton)
175 {
176 //System.err.println("ok button pressed!");
177
178 dispose(); //close window
179 }
180 else
181 {
182 System.err.println("event not processed in CollectionInfoDialog");
183 }
184} //end actionPerformed
185
186
187 /* generate a string with correct sizing information */
188 /* bytes, K or G */
189 public String formatByteSize (long numberOfBytes) {
190 int minfd = numFormat.getMinimumFractionDigits();
191 int maxfd = numFormat.getMaximumFractionDigits();
192 String resultString;
193 numFormat.setMinimumFractionDigits(1);
194 numFormat.setMaximumFractionDigits(1);
195 if (numberOfBytes > 1073741824)
196 resultString = numFormat.format((numberOfBytes / (float)1073741824)) + " G";
197 else
198 if (numberOfBytes > 1048576)
199 resultString = numFormat.format((numberOfBytes / (float)1048576)) + " M";
200 else {
201 numFormat.setMinimumFractionDigits(0);
202 numFormat.setMaximumFractionDigits(0);
203 if (numberOfBytes > 1024)
204 resultString = numFormat.format((numberOfBytes / (float)1024)) + " K";
205 else
206 resultString = numFormat.format(numberOfBytes) + " bytes";
207 }
208 numFormat.setMinimumFractionDigits(minfd);
209 numFormat.setMaximumFractionDigits(maxfd);
210 return resultString;
211} // end formatByteSize
212
213
214
215} // end CollectionInfoDialog class
Note: See TracBrowser for help on using the repository browser.