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.echocomp; 016 017 import nextapp.echo.app.Alignment; 018 import nextapp.echo.app.Button; 019 import nextapp.echo.app.Color; 020 import nextapp.echo.app.Extent; 021 import nextapp.echo.app.Font; 022 import nextapp.echo.app.Insets; 023 import nextapp.echo.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 private static final long serialVersionUID = 1529104452172147464L; 033 034 /** 035 * Creates a new small button. 036 * 037 * @param text The button text. 038 * @param actionListener The action-listener of the button. 039 * @param size The size of the text. 040 * @param enabled false if the button should be disabled. 041 */ 042 public SmallButton(String text, ActionListener actionListener, int size, boolean enabled) { 043 super(text); 044 045 setActionCommand(text); 046 addActionListener(actionListener); 047 048 setHeight(new Extent(size + 4)); 049 setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(size))); 050 setBackground(null); 051 setForeground(Style.mediumForeground); 052 setDisabledBackground(null); 053 setDisabledForeground(Color.BLACK); 054 055 setRolloverEnabled(true); 056 setRolloverForeground(Style.lightForeground); 057 setRolloverBackground(Style.darkBackground); 058 setInsets(new Insets(2, 0)); 059 setAlignment(new Alignment(Alignment.CENTER, Alignment.CENTER)); 060 setTextAlignment(new Alignment(Alignment.CENTER, Alignment.CENTER)); 061 062 setEnabled(enabled); 063 setLineWrap(false); 064 } 065 066 /** 067 * Creates a new small button. 068 * 069 * @param text The button text. 070 * @param actionListener The action-listener of the button. 071 * @param size The size of the text. 072 */ 073 public SmallButton(String text, ActionListener actionListener, int size) { 074 this(text, actionListener, size, true); 075 } 076 077 /** 078 * Creates a new small button with text size 10. 079 * 080 * @param text The button text. 081 * @param actionListener The action-listener of the button. 082 * @param enabled false if the button should be disabled. 083 */ 084 public SmallButton(String text, ActionListener actionListener, boolean enabled) { 085 this(text, actionListener, 10, enabled); 086 } 087 088 /** 089 * Creates a new small button with text size 10. 090 * 091 * @param text The button text. 092 * @param actionListener The action-listener of the button. 093 */ 094 public SmallButton(String text, ActionListener actionListener) { 095 this(text, actionListener, 10, true); 096 } 097 098 }