source: trunk/greenstone3-extensions/vishnu/src/vishnu/testvis/visual/Vishnu.java@ 8189

Last change on this file since 8189 was 8189, checked in by kjdon, 20 years ago

first version of Imperial College's Visualiser code

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 10.7 KB
Line 
1package vishnu.testvis.visual;
2import vishnu.testvis.treemap.visual.TMNavigator;
3import vishnu.testvis.sammon.*;
4import vishnu.testvis.object.*;
5import vishnu.testvis.evaluate.*;
6import vishnu.testvis.dendro.*;
7import java.awt.*;
8import javax.swing.*;
9import java.awt.event.*;
10import java.beans.*;
11import javax.swing.event.*;
12import java.io.*;
13import java.util.Vector;
14import java.util.Properties;
15import java.applet.*;
16import java.net.*;
17import vishnu.datablock.*;
18
19public class Vishnu extends JApplet
20{
21 public JTabbedPane theTabbedPane = null;
22 public PlainPanel plainPanel = null;
23 public GraphicalPane sammonPanel = null;
24 public RadVizPanel radVizPanel = null;
25 public DendroPanel dendroPanel = null;
26 public JButton findButton = null;
27
28 public DataManager dataManager = null;
29
30 public Logging log = null;
31 public Queries queries = null;
32 public boolean searchStarted = false;
33 public boolean firstSearch = true;
34 public boolean refine = false;
35
36 public JTextField searchBox = null;
37 public JComboBox collCombo = null;
38 protected int largeFont = 16;
39
40 public String query = null;
41 public String coll = null;
42
43 public String server_address = null;
44
45 protected Dimension size = null;
46
47 public void init()
48 {
49 query = getParameter("query");
50 coll = getParameter("collection");
51 String library = getParameter("library");
52 String viscgi = getParameter("viscgi");
53 if (library == null ) {
54 System.err.println("Error: library parameter is null!!");
55 // what should we do?
56 return;
57 }
58
59 server_address = library;
60 if (viscgi != null) {
61 // if viscgi parameter is set (even if empty) we assume that
62 // the server is running cgi-like with arguments in the url
63 server_address += viscgi;
64 server_address = tidy_URL(server_address, true);
65 } else {
66 server_address = tidy_URL(server_address, false);
67 }
68
69 String w = getParameter("width");
70 String h = getParameter("height");
71
72 if( (w != null) && (h != null) )
73 size = new Dimension(Integer.parseInt(w),Integer.parseInt(h));
74 else size = new Dimension(1000,800);
75
76 dataManager = new DataManager(this);
77
78 this.setSize(size);
79
80 theTabbedPane = new JTabbedPane();
81
82 radVizPanel = new RadVizPanel(this);
83 radVizPanel.setName("RadialVis");
84
85 plainPanel = new PlainPanel(this);
86 plainPanel.setName("PlainVis");
87
88 sammonPanel = new GraphicalPane(this);
89 sammonPanel.setName("SammonVis");
90
91 dendroPanel = new DendroPanel(this);
92 dendroPanel.setName("DendroVis");
93
94 findButton = new JButton();
95 try {
96 jbInit();
97 } catch(Exception e){e.printStackTrace();}
98
99 initCollections();
100
101 if( query != null && !query.equals("null") ){
102 searchBox.setText(query);
103 findQuery();
104 }
105 }
106
107 protected void initCollections() {
108
109 Collection current_collection=null;
110 if( coll == null || coll.equals("") || coll.equals("null") ) {
111 current_collection = ((Collection)dataManager.collections.elementAt(0));
112 coll = current_collection.dir;
113 } else {
114 for( int i = 0; i < dataManager.collections.size(); i++ ){
115 Collection c = (Collection)dataManager.collections.elementAt(i);
116 if( c.dir.equals(coll) ){
117 current_collection = c;
118 break;
119 }
120 }
121 }
122 if (current_collection == null) {
123 // could still be null if we specified an invalid collection in the parameters
124 current_collection = ((Collection)dataManager.collections.elementAt(0));
125 coll = current_collection.dir;
126 }
127
128 dataManager.currentCollection = current_collection;
129 dataManager.requestCollection();
130 System.out.println("Requesting collection " + current_collection.name);
131 collCombo.setSelectedItem(current_collection);
132 }
133
134 protected void jbInit() throws Exception
135 {
136 JPanel pane = new JPanel();
137 setContentPane(pane);
138 pane.setBorder(BorderFactory.createLineBorder(Color.black, 2));
139 pane.setLayout(new BorderLayout());
140
141 JPanel searchPanel = new JPanel();
142 searchPanel.setLayout(new BorderLayout(5,5));
143 searchPanel.setBackground(SystemColor.control);
144 searchBox = new JTextField();
145 searchBox.setPreferredSize(new Dimension((int)(size.width/5), 26));
146 searchBox.setEditable(true);
147 searchBox.addKeyListener(new java.awt.event.KeyAdapter(){
148 public void keyPressed(KeyEvent e)
149 {
150 findButton_keyPressed(e);
151 }
152 });
153
154 JLabel searchLabel = new JLabel();
155 searchLabel.setFont(new java.awt.Font("Monospaced", 0, largeFont));
156 searchLabel.setForeground(Color.black);
157 searchLabel.setText("Search:");
158
159 searchPanel.add(searchLabel, BorderLayout.WEST);
160 searchPanel.add(searchBox, BorderLayout.CENTER);
161
162 JPanel collPanel = new JPanel();
163 collPanel.setLayout(new BorderLayout(5,5));
164 collPanel.setBackground(SystemColor.control);
165
166 collCombo = new JComboBox(dataManager.collections);
167 collCombo.setEditable(false);
168 collCombo.addItemListener(new java.awt.event.ItemListener() {
169 public void itemStateChanged(ItemEvent i) {
170 if (i.getStateChange()==ItemEvent.SELECTED){
171 dataManager.currentCollection = (Collection)i.getItem();
172 collCombo.hidePopup();
173 coll = dataManager.currentCollection.dir;
174 dataManager.requestCollection();
175 update();
176
177 }
178
179 }
180 });
181 collCombo.setRenderer(new javax.swing.DefaultListCellRenderer() {
182 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
183 {
184 setText(((Collection)value).name);
185 setFont(list.getFont());
186 return this;
187 }
188 });
189
190
191 JLabel collLabel = new JLabel();
192 collLabel.setFont(new java.awt.Font("Monospaced", 0, largeFont));
193 collLabel.setForeground(Color.black);
194 collLabel.setText("Collection:");
195
196 collPanel.add(collLabel, BorderLayout.WEST);
197 collPanel.add(collCombo, BorderLayout.CENTER);
198
199 JPanel topPanel = new JPanel();
200 topPanel.setLayout(new BorderLayout(10,10));
201 topPanel.setBackground(SystemColor.control);
202 topPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
203
204 JPanel backPanel = new JPanel();
205 backPanel.setPreferredSize(new Dimension(size.width,size.height));
206 backPanel.setBackground(SystemColor.control);
207 backPanel.setLayout(new BorderLayout());
208
209 theTabbedPane.setBackground(SystemColor.control);
210 theTabbedPane.setFont(new java.awt.Font("Monospaced", Font.BOLD, largeFont));
211 theTabbedPane.addChangeListener(new javax.swing.event.ChangeListener(){
212 public void stateChanged(ChangeEvent e)
213 {
214 theTabbedPane_stateChanged(e);
215 }
216 });
217
218 findButton.setBackground(SystemColor.control);
219 findButton.setFont(new java.awt.Font("Monospaced", 0, largeFont));
220 findButton.setBorder(BorderFactory.createEtchedBorder());
221 findButton.setText("Find");
222 findButton.addKeyListener(new java.awt.event.KeyAdapter(){
223 public void keyPressed(KeyEvent e)
224 {
225 findButton_keyPressed(e);
226 }
227 });
228
229 findButton.addMouseListener(new java.awt.event.MouseAdapter(){
230 public void mouseClicked(MouseEvent e)
231 {
232 findButton_mouseClicked(e);
233 }
234 });
235
236 pane.add(backPanel, BorderLayout.CENTER);
237 backPanel.add(theTabbedPane, BorderLayout.CENTER);
238
239 theTabbedPane.add(plainPanel, "PlainVis");
240 theTabbedPane.add(radVizPanel, "RadialVis");
241 theTabbedPane.add(sammonPanel,"SammonVis");
242 theTabbedPane.add(dendroPanel,"DendroVis");
243 theTabbedPane.setForegroundAt(0,Color.blue);
244
245 pane.add(topPanel, BorderLayout.NORTH);
246
247 topPanel.add(collPanel, BorderLayout.WEST);
248 topPanel.add(searchPanel, BorderLayout.CENTER);
249 topPanel.add(findButton, BorderLayout.EAST);
250
251 theTabbedPane.setPreferredSize(size);
252
253 }
254
255
256 public void update()
257 {
258 plainPanel.update();
259 radVizPanel.update();
260 dendroPanel.update();
261 sammonPanel.update();
262 }
263
264
265 void findQuery()
266 {
267 refine = false;
268
269 int docCount;
270 String text = null;
271
272 text = (String)searchBox.getText();
273 if(text.trim().length() < 1) return;
274 query = text.trim();
275
276 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
277
278 int count = 1;
279 String q = query;
280 docCount = dataManager.query(q);
281 if (docCount == 0 ) {
282 JOptionPane.showMessageDialog(this,"No documents found related to " + text);
283 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
284 return;
285 }
286
287 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
288 }
289
290
291 void theTabbedPane_stateChanged(ChangeEvent e)
292 {
293 for( int i = 0; i < theTabbedPane.getTabCount(); i++ )
294 {
295 theTabbedPane.setForegroundAt(i,Color.black);
296 }
297
298 int tab = theTabbedPane.getSelectedIndex();
299
300 theTabbedPane.setForegroundAt(tab,Color.blue);
301 }
302
303
304 void findButton_keyPressed(KeyEvent e)
305 {
306 int key = e.getKeyCode();
307 if (key==10)
308 {
309 findButton.setSelected(true);
310 findQuery();
311 findButton.setSelected(false);
312 }
313 }
314
315 void findButton_mouseClicked(MouseEvent e)
316 {
317 findQuery();
318 }
319
320
321 // Tidy up URLs
322 //
323 // Ensure a URL address (as string) has a protocol, host, and file.
324 //
325 // If the URL is a CGI script URL, it should be tidied up so that it is
326 // appropriate to tage attrib=value pairs on the end. This means it
327 // must either end with a "?" or (if it contains a question-mark
328 // internally) end with a "&".
329 // taken from Phind.java, Greenstone digital library.
330 String tidy_URL(String address, boolean isCGI) {
331
332 // System.err.println("tidy URL: " + address);
333
334 // make sure the URL has protocol, host, and file
335 if (address.startsWith("http")) {
336 // the address has all the necessary components
337 } else if (address.startsWith("/")) {
338 // there is not protocol and host
339 URL document = getDocumentBase();
340 String port = "";
341 if (document.getPort()!=-1) {
342 port = ":" + document.getPort();
343 }
344 address = "http://" + document.getHost() + port + address;
345 } else {
346 // this URL is relative to the directory the document is in
347 URL document = getDocumentBase();
348 String directory = document.getFile();
349 int end = directory.lastIndexOf('/');
350 String port = "";
351 if (document.getPort()!=-1) {
352 port = ":" + document.getPort();
353 }
354 directory = directory.substring(0,end + 1);
355 address = "http://" + document.getHost() + port + directory + address;
356
357 }
358
359 // if the URL is a cgi script, make sure it has a "?" in ti,
360 // and that it ends with a "?" or "&"
361 if (isCGI) {
362 if (address.indexOf((int) '?') == -1) {
363 address = address + "?";
364 } else if (!address.endsWith("?")) {
365 address = address + "&";
366 }
367 }
368
369 return address;
370 }
371
372}
373
374
375
376
377
378
379
380
Note: See TracBrowser for help on using the repository browser.