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

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

added view stuff back in. A collection may be built with views - these are not predefined but are just subdirs in the import folder. the applet now has a menu for views, if they are available

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