/************************************************************************** /* Main window (menus, toolbar) for GuiSearcher. /* /* Copyright (c) 2003-2004 by Bernhard Bablok (mail@bablokb.de) /* /* This library is free software; you can redistribute it and/or modify /* it under the terms of the GNU Lesser General Public License as published /* by the Free Software Foundation; either version 2 of the License or /* (at your option) any later version. /* /* This library 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 Lesser General Public License for more details. /* /* You should have received a copy of the GNU Lesser General Public License /* along with this library; see the file COPYING.LESSER. If not, write to /* the Free Software Foundation Inc., 59 Temple Place - Suite 330, /* Boston, MA 02111-1307 USA /**************************************************************************/ package de.bablokb.luala.app; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** Main window (menus, toolbar) for GuiSearcher. @version $Revision: 1.5 $ @author $Author: bablokb $ */ public class GuiSearcherFrame extends JFrame { ///////////////////////////////////////////////////////////////////////////// /** Default window-size constant. */ private final static int DEFAULT_WIDTH = 600, DEFAULT_HEIGHT = 600; ///////////////////////////////////////////////////////////////////////////// /** Window-title constant. */ private final static String WINDOW_TITLE = "LUcene Application LAyer Search Application"; ///////////////////////////////////////////////////////////////////////////// /** The {@link ExitAction} for this application. */ private final ExitAction iExitAction = new ExitAction(); ///////////////////////////////////////////////////////////////////////////// /** The {@link OpenIndexAction} for this application. */ private final OpenIndexAction iOpenIndexAction = new OpenIndexAction(); ///////////////////////////////////////////////////////////////////////////// /** Create frame, set window title, add exit-processing. @param title window title */ public GuiSearcherFrame(String title) { if (title == null) setTitle(WINDOW_TITLE); else setTitle(title); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { GuiSearcher.getInstance().processExit(); }}); // getContentPane().add(getToolBar(),BorderLayout.NORTH); setJMenuBar(getMenu()); } ///////////////////////////////////////////////////////////////////////////// /** Create application-menu. @return The JMenuBar of the application. */ public JMenuBar getMenu() { JMenuBar menu = new JMenuBar(); // Index-menu: open an index, leave the application. JMenu indexMenu = new JMenu("Index"); indexMenu.setMnemonic(KeyEvent.VK_I); menu.add(indexMenu); JMenuItem openIndexItem = new JMenuItem(); openIndexItem.setAction(iOpenIndexAction); indexMenu.add(openIndexItem); indexMenu.addSeparator(); JMenuItem exitItem = new JMenuItem(); exitItem.setAction(iExitAction); indexMenu.add(exitItem); return menu; } ///////////////////////////////////////////////////////////////////////////// /** Create application-toolbar. @return The application-toolbar. */ public JToolBar getToolBar() { JToolBar toolBar = new JToolBar(); toolBar.add(iOpenIndexAction); toolBar.addSeparator(); toolBar.add(iExitAction); return toolBar; } ///////////////////////////////////////////////////////////////////////////// /** Return preferred size. @return A Dimension-object with the preferred size. */ // public Dimension getPreferredSize() { // return new Dimension(DEFAULT_WIDTH,DEFAULT_HEIGHT); // } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /** This action processes the exit-command. */ class ExitAction extends AbstractAction { public ExitAction() { super("Exit"); putValue(SHORT_DESCRIPTION,"Quit the application"); putValue(MNEMONIC_KEY,new Integer(KeyEvent.VK_Q)); // String image = "/toolbarButtonGraphics/media/StepBack16.gif"; // URL imageURL = GuiSearcherFrame.class.getResource(image); // putValue(SMALL_ICON,new ImageIcon(imageURL)); } public void actionPerformed(ActionEvent e) { GuiSearcher.getInstance().processExit(); } } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /** This action processes the openIndex-command. */ class OpenIndexAction extends AbstractAction { public OpenIndexAction() { super("Open..."); putValue(SHORT_DESCRIPTION,"Open a search-index"); putValue(MNEMONIC_KEY,new Integer(KeyEvent.VK_O)); // String image = "/toolbarButtonGraphics/media/Open16.gif"; // URL imageURL = GuiSearcherFrame.class.getResource(image); // putValue(SMALL_ICON,new ImageIcon(imageURL)); } public void actionPerformed(ActionEvent e) { GuiSearcher.getInstance().processOpenIndex(); } } }