source: trunk/gsdl3/extensions/vishnu/src/vishnu/testvis/visual/Vishnu.java@ 8404

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

moved teh getparam(engine) bit to Vishnu, and now pass it in to DataMAnager constructor

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