001 // This file is part of the Attempto Java Packages. 002 // Copyright 2008, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch). 003 // 004 // The Attempto Java Packages is free software: you can redistribute it and/or modify it under the 005 // terms of the GNU Lesser General Public License as published by the Free Software Foundation, 006 // either version 3 of the License, or (at your option) any later version. 007 // 008 // The Attempto Java Packages is distributed in the hope that it will be useful, but WITHOUT ANY 009 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 010 // PURPOSE. See the GNU Lesser General Public License for more details. 011 // 012 // You should have received a copy of the GNU Lesser General Public License along with the Attempto 013 // Java Packages. If not, see http://www.gnu.org/licenses/. 014 015 package ch.uzh.ifi.attempto.echocomp; 016 017 import nextapp.echo2.app.Alignment; 018 import nextapp.echo2.app.Button; 019 import nextapp.echo2.app.Color; 020 import nextapp.echo2.app.Extent; 021 import nextapp.echo2.app.Font; 022 import nextapp.echo2.app.Insets; 023 import nextapp.echo2.app.event.ActionListener; 024 025 /** 026 * This class creates borderless small buttons. 027 * 028 * @author Tobias Kuhn 029 */ 030 public class SmallButton extends Button { 031 032 /** 033 * Creates a new small button. 034 * 035 * @param text The button text. 036 * @param actionListener The action-listener of the button. 037 * @param size The size of the text. 038 * @param enabled false if the button should be disabled. 039 */ 040 public SmallButton(String text, ActionListener actionListener, int size, boolean enabled) { 041 super(text); 042 043 setActionCommand(text); 044 addActionListener(actionListener); 045 046 setHeight(new Extent(size + 2)); 047 setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(size))); 048 setBackground(null); 049 setForeground(Style.mediumForeground); 050 setDisabledBackground(null); 051 setDisabledForeground(Color.BLACK); 052 setActionCommand(text); 053 054 setRolloverEnabled(true); 055 setRolloverForeground(Style.lightForeground); 056 setRolloverBackground(Style.darkBackground); 057 setInsets(new Insets(2, 1)); 058 setAlignment(new Alignment(Alignment.CENTER, Alignment.CENTER)); 059 setTextAlignment(new Alignment(Alignment.CENTER, Alignment.CENTER)); 060 061 setEnabled(enabled); 062 } 063 064 /** 065 * Creates a new small button. 066 * 067 * @param text The button text. 068 * @param actionListener The action-listener of the button. 069 * @param size The size of the text. 070 */ 071 public SmallButton(String text, ActionListener actionListener, int size) { 072 this(text, actionListener, size, true); 073 } 074 075 /** 076 * Creates a new small button with text size 10. 077 * 078 * @param text The button text. 079 * @param actionListener The action-listener of the button. 080 * @param enabled false if the button should be disabled. 081 */ 082 public SmallButton(String text, ActionListener actionListener, boolean enabled) { 083 this(text, actionListener, 10, enabled); 084 } 085 086 /** 087 * Creates a new small button with text size 10. 088 * 089 * @param text The button text. 090 * @param actionListener The action-listener of the button. 091 */ 092 public SmallButton(String text, ActionListener actionListener) { 093 this(text, actionListener, 10, true); 094 } 095 096 }