package vishnu.testvis.visual; import vishnu.testvis.treemap.visual.TMNavigator; import vishnu.testvis.sammon.*; import vishnu.testvis.object.*; import vishnu.testvis.evaluate.*; import vishnu.testvis.dendro.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.beans.*; import javax.swing.event.*; import java.io.*; import java.util.Vector; import java.util.Properties; import java.applet.*; import java.net.*; import vishnu.datablock.*; public class Vishnu extends JApplet { public JTabbedPane theTabbedPane = null; public PlainPanel plainPanel = null; public GraphicalPane sammonPanel = null; public RadVizPanel radVizPanel = null; public DendroPanel dendroPanel = null; public JButton findButton = null; public DataManager dataManager = null; public Logging log = null; public Queries queries = null; public boolean searchStarted = false; public boolean firstSearch = true; public boolean refine = false; public JTextField searchBox = null; public JComboBox collCombo = null; protected int largeFont = 16; public String query = null; public String coll = null; public String server_address = null; protected Dimension size = null; public void init() { query = getParameter("query"); coll = getParameter("collection"); String library = getParameter("library"); String viscgi = getParameter("viscgi"); if (library == null ) { System.err.println("Error: library parameter is null!!"); // what should we do? return; } server_address = library; if (viscgi != null) { // if viscgi parameter is set (even if empty) we assume that // the server is running cgi-like with arguments in the url server_address += viscgi; server_address = tidy_URL(server_address, true); } else { server_address = tidy_URL(server_address, false); } String w = getParameter("width"); String h = getParameter("height"); if( (w != null) && (h != null) ) size = new Dimension(Integer.parseInt(w),Integer.parseInt(h)); else size = new Dimension(1000,800); dataManager = new DataManager(this); this.setSize(size); theTabbedPane = new JTabbedPane(); radVizPanel = new RadVizPanel(this); radVizPanel.setName("RadialVis"); plainPanel = new PlainPanel(this); plainPanel.setName("PlainVis"); sammonPanel = new GraphicalPane(this); sammonPanel.setName("SammonVis"); dendroPanel = new DendroPanel(this); dendroPanel.setName("DendroVis"); findButton = new JButton(); try { jbInit(); } catch(Exception e){e.printStackTrace();} initCollections(); if( query != null && !query.equals("null") ){ searchBox.setText(query); findQuery(); } } protected void initCollections() { Collection current_collection=null; if( coll == null || coll.equals("") || coll.equals("null") ) { current_collection = ((Collection)dataManager.collections.elementAt(0)); coll = current_collection.dir; } else { for( int i = 0; i < dataManager.collections.size(); i++ ){ Collection c = (Collection)dataManager.collections.elementAt(i); if( c.dir.equals(coll) ){ current_collection = c; break; } } } if (current_collection == null) { // could still be null if we specified an invalid collection in the parameters current_collection = ((Collection)dataManager.collections.elementAt(0)); coll = current_collection.dir; } dataManager.currentCollection = current_collection; dataManager.requestCollection(); System.out.println("Requesting collection " + current_collection.name); collCombo.setSelectedItem(current_collection); } protected void jbInit() throws Exception { JPanel pane = new JPanel(); setContentPane(pane); pane.setBorder(BorderFactory.createLineBorder(Color.black, 2)); pane.setLayout(new BorderLayout()); JPanel searchPanel = new JPanel(); searchPanel.setLayout(new BorderLayout(5,5)); searchPanel.setBackground(SystemColor.control); searchBox = new JTextField(); searchBox.setPreferredSize(new Dimension((int)(size.width/5), 26)); searchBox.setEditable(true); searchBox.addKeyListener(new java.awt.event.KeyAdapter(){ public void keyPressed(KeyEvent e) { findButton_keyPressed(e); } }); JLabel searchLabel = new JLabel(); searchLabel.setFont(new java.awt.Font("Monospaced", 0, largeFont)); searchLabel.setForeground(Color.black); searchLabel.setText("Search:"); searchPanel.add(searchLabel, BorderLayout.WEST); searchPanel.add(searchBox, BorderLayout.CENTER); JPanel collPanel = new JPanel(); collPanel.setLayout(new BorderLayout(5,5)); collPanel.setBackground(SystemColor.control); collCombo = new JComboBox(dataManager.collections); collCombo.setEditable(false); collCombo.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent i) { if (i.getStateChange()==ItemEvent.SELECTED){ dataManager.currentCollection = (Collection)i.getItem(); collCombo.hidePopup(); coll = dataManager.currentCollection.dir; dataManager.requestCollection(); update(); } } }); collCombo.setRenderer(new javax.swing.DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setText(((Collection)value).name); setFont(list.getFont()); return this; } }); JLabel collLabel = new JLabel(); collLabel.setFont(new java.awt.Font("Monospaced", 0, largeFont)); collLabel.setForeground(Color.black); collLabel.setText("Collection:"); collPanel.add(collLabel, BorderLayout.WEST); collPanel.add(collCombo, BorderLayout.CENTER); JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout(10,10)); topPanel.setBackground(SystemColor.control); topPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); JPanel backPanel = new JPanel(); backPanel.setPreferredSize(new Dimension(size.width,size.height)); backPanel.setBackground(SystemColor.control); backPanel.setLayout(new BorderLayout()); theTabbedPane.setBackground(SystemColor.control); theTabbedPane.setFont(new java.awt.Font("Monospaced", Font.BOLD, largeFont)); theTabbedPane.addChangeListener(new javax.swing.event.ChangeListener(){ public void stateChanged(ChangeEvent e) { theTabbedPane_stateChanged(e); } }); findButton.setBackground(SystemColor.control); findButton.setFont(new java.awt.Font("Monospaced", 0, largeFont)); findButton.setBorder(BorderFactory.createEtchedBorder()); findButton.setText("Find"); findButton.addKeyListener(new java.awt.event.KeyAdapter(){ public void keyPressed(KeyEvent e) { findButton_keyPressed(e); } }); findButton.addMouseListener(new java.awt.event.MouseAdapter(){ public void mouseClicked(MouseEvent e) { findButton_mouseClicked(e); } }); pane.add(backPanel, BorderLayout.CENTER); backPanel.add(theTabbedPane, BorderLayout.CENTER); theTabbedPane.add(plainPanel, "PlainVis"); theTabbedPane.add(radVizPanel, "RadialVis"); theTabbedPane.add(sammonPanel,"SammonVis"); theTabbedPane.add(dendroPanel,"DendroVis"); theTabbedPane.setForegroundAt(0,Color.blue); pane.add(topPanel, BorderLayout.NORTH); topPanel.add(collPanel, BorderLayout.WEST); topPanel.add(searchPanel, BorderLayout.CENTER); topPanel.add(findButton, BorderLayout.EAST); theTabbedPane.setPreferredSize(size); } public void update() { plainPanel.update(); radVizPanel.update(); dendroPanel.update(); sammonPanel.update(); } void findQuery() { refine = false; int docCount; String text = null; text = (String)searchBox.getText(); if(text.trim().length() < 1) return; query = text.trim(); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); int count = 1; String q = query; docCount = dataManager.query(q); if (docCount == 0 ) { JOptionPane.showMessageDialog(this,"No documents found related to " + text); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); return; } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } void theTabbedPane_stateChanged(ChangeEvent e) { for( int i = 0; i < theTabbedPane.getTabCount(); i++ ) { theTabbedPane.setForegroundAt(i,Color.black); } int tab = theTabbedPane.getSelectedIndex(); theTabbedPane.setForegroundAt(tab,Color.blue); } void findButton_keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key==10) { findButton.setSelected(true); findQuery(); findButton.setSelected(false); } } void findButton_mouseClicked(MouseEvent e) { findQuery(); } // Tidy up URLs // // Ensure a URL address (as string) has a protocol, host, and file. // // If the URL is a CGI script URL, it should be tidied up so that it is // appropriate to tage attrib=value pairs on the end. This means it // must either end with a "?" or (if it contains a question-mark // internally) end with a "&". // taken from Phind.java, Greenstone digital library. String tidy_URL(String address, boolean isCGI) { // System.err.println("tidy URL: " + address); // make sure the URL has protocol, host, and file if (address.startsWith("http")) { // the address has all the necessary components } else if (address.startsWith("/")) { // there is not protocol and host URL document = getDocumentBase(); String port = ""; if (document.getPort()!=-1) { port = ":" + document.getPort(); } address = "http://" + document.getHost() + port + address; } else { // this URL is relative to the directory the document is in URL document = getDocumentBase(); String directory = document.getFile(); int end = directory.lastIndexOf('/'); String port = ""; if (document.getPort()!=-1) { port = ":" + document.getPort(); } directory = directory.substring(0,end + 1); address = "http://" + document.getHost() + port + directory + address; } // if the URL is a cgi script, make sure it has a "?" in ti, // and that it ends with a "?" or "&" if (isCGI) { if (address.indexOf((int) '?') == -1) { address = address + "?"; } else if (!address.endsWith("?")) { address = address + "&"; } } return address; } }