///////////////////////////////////////////////////////// // Module ResultPanel.java // Version 1.05 // Language Java // Author Sudhakar Chandrasekaran (thaths@netscape.com) // History // 05/17/97 Cleaning up after hacking binge // 05/16/97 Added addResult() // Legalese // Copyright (C) 1996-1997 Sudhakar Chandrasekharan // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the // Free Software Foundation; either version 2 of the license, or (at your // option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. Writers of free software // cannot afford getting sued! // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 675 Mass Ave., Cambridge, MA 02139, USA. // // Sudhakar "Thaths" Chandrasekharan, 20 Apr 1997. //////////////////////////////////////////////////////// import java.awt.*; import java.net.*; import java.util.Vector; public class ResultPanel extends Panel { MyFrame myFrame; List resultsList; Vector urls = new Vector(); Label numOfResults; int numOfHits = 0; ResultPanel(MyFrame mf) { myFrame = mf; urls.ensureCapacity(mf.clientSearch.totalPages); Label headingLabel = new Label("Search Results", Label.CENTER); numOfResults = new Label("Matches found :", Label.LEFT); resultsList = new List(7,false); setLayout(new GridLayout(3,1)); add(headingLabel); add(resultsList); add(numOfResults); } // This method is invoked when a new search // is initiated or when the 'Clear' buton is clicked public void clearList() { urls.removeAllElements(); resultsList.clear(); } // This method is invoked when a search match is found public void addResult(String match, String url) { numOfHits ++; // urls.setElementAt(new String(url), resultsList.countItems()); urls.addElement(new String(url)); resultsList.addItem(match); numOfResults.setText("Matches Found :" + numOfHits); myFrame.searchPanel.clearButton.enable(); } // Draw a nice 3-D box around this panel public void paint(Graphics g) { Dimension d = size(); Color bg = getBackground(); g.setColor(bg); g.draw3DRect(0,0,d.width-1,d.height-1,true); g.draw3DRect(2,2,d.width-5,d.height-5,false); } // The padding for this panel public Insets insets() { return new Insets(3,3,3,3); } // The panel should at least be this size public Dimension minimumSize() { Dimension d = new Dimension(400,120); return d; } // Would prefer the panel to be this size public Dimension preferredSize() { Dimension d = new Dimension(400,120); return d; } // Event handler public boolean handleEvent(Event e) { // A match in the list was selected if (e.target instanceof List) { List list = (List)(e.target); switch (e.id) { case Event.LIST_SELECT: int sIndex = ((Integer)e.arg).intValue(); URL dest; try { dest = new URL((String) urls.elementAt(sIndex)); myFrame.clientSearch.getAppletContext().showDocument(dest, "Results"); } catch (MalformedURLException excep) { System.out.println("ClientSearch: Bad URL - Ignoring."); } } } return super.handleEvent(e); } }