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            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 + 2));
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                    setActionCommand(text);
055                    
056                    setRolloverEnabled(true);
057                    setRolloverForeground(Style.lightForeground);
058                    setRolloverBackground(Style.darkBackground);
059                    setInsets(new Insets(2, 1));
060                    setAlignment(new Alignment(Alignment.CENTER, Alignment.CENTER));
061                    setTextAlignment(new Alignment(Alignment.CENTER, Alignment.CENTER));
062                    
063                    setEnabled(enabled);
064                    setLineWrap(false);
065            }
066            
067            /**
068             * Creates a new small button.
069             * 
070             * @param text The button text.
071             * @param actionListener The action-listener of the button.
072             * @param size The size of the text.
073             */
074            public SmallButton(String text, ActionListener actionListener, int size) {
075                    this(text, actionListener, size, true);
076            }
077            
078            /**
079             * Creates a new small button with text size 10.
080             * 
081             * @param text The button text.
082             * @param actionListener The action-listener of the button.
083             * @param enabled false if the button should be disabled.
084             */
085            public SmallButton(String text, ActionListener actionListener, boolean enabled) {
086                    this(text, actionListener, 10, enabled);
087            }
088            
089            /**
090             * Creates a new small button with text size 10.
091             * 
092             * @param text The button text.
093             * @param actionListener The action-listener of the button.
094             */
095            public SmallButton(String text, ActionListener actionListener) {
096                    this(text, actionListener, 10, true);
097            }
098    
099    }