001 // This file is part of AceWiki.
002 // Copyright 2008-2012, AceWiki developers.
003 //
004 // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU
005 // Lesser General Public License as published by the Free Software Foundation, either version 3 of
006 // the License, or (at your option) any later version.
007 //
008 // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010 // Lesser General Public License for more details.
011 //
012 // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If
013 // not, see http://www.gnu.org/licenses/.
014
015 package ch.uzh.ifi.attempto.acewiki.gui;
016
017 import nextapp.echo.app.Button;
018 import nextapp.echo.app.Extent;
019 import nextapp.echo.app.event.ActionListener;
020 import ch.uzh.ifi.attempto.acewiki.Wiki;
021
022 /**
023 * This class represents a button consisting of an icon, for example forward and backward arrows to
024 * navigate through the wiki history.
025 *
026 * @author Tobias Kuhn
027 */
028 public class IconButton extends Button {
029
030 private static final long serialVersionUID = 9007778082893227249L;
031
032 /**
033 * Creates a new icon button. The name has to correspond to the name of the icon image files
034 * and is also shown as a tooltip.
035 *
036 * @param name The name of the icon button.
037 * @param actionListener The action listener for this button.
038 */
039 public IconButton(String name, ActionListener actionListener) {
040 setRolloverEnabled(true);
041 setWidth(new Extent(25));
042 setHeight(new Extent(25));
043 String filename = name.toLowerCase();
044 setIcon(Wiki.getImage(filename + ".png"));
045 setRolloverIcon(Wiki.getImage(filename + "h.png"));
046 setDisabledIcon(Wiki.getImage(filename + "i.png"));
047 setActionCommand(name);
048 setToolTipText(name);
049 addActionListener(actionListener);
050 }
051
052 }