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.Border;
019    import nextapp.echo2.app.Button;
020    import nextapp.echo2.app.Color;
021    import nextapp.echo2.app.Extent;
022    import nextapp.echo2.app.Font;
023    import nextapp.echo2.app.Insets;
024    import nextapp.echo2.app.event.ActionListener;
025    
026    /**
027     * This is a convenience class for easy creation of buttons.
028     * 
029     * @author Tobias Kuhn
030     */
031    public class GeneralButton extends Button {
032    
033            /**
034             * Creates a new button.
035             * 
036             * @param text The button text.
037             * @param width The button width.
038             * @param actionListener The action-listener of the button.
039             */
040            public GeneralButton(String text, int width, ActionListener actionListener) {
041                    super(text);
042                    
043                    if (width > 0) {
044                            setWidth(new Extent(width));
045                    }
046                    setHeight(new Extent(17));
047                    setBackground(Style.mediumBackground);
048                    setForeground(Style.darkForeground);
049                    setBorder(new Border(1, Color.BLACK, Border.STYLE_OUTSET));
050                    setDisabledBackground(Style.lightDisabled);
051                    setDisabledForeground(Style.darkDisabled);
052                    setDisabledBorder(new Border(1, Color.BLACK, Border.STYLE_OUTSET));
053                    setRolloverEnabled(true);
054                    setRolloverForeground(Style.lightForeground);
055                    setRolloverBackground(Style.darkBackground);
056                    setRolloverBorder(new Border(1, Color.BLACK, Border.STYLE_SOLID));
057                    setInsets(new Insets(2, 0));
058                    setAlignment(new Alignment(Alignment.CENTER, Alignment.CENTER));
059                    setTextAlignment(new Alignment(Alignment.CENTER, Alignment.CENTER));
060                    setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13)));
061                    
062                    setActionCommand(text);
063                    addActionListener(actionListener);
064            }
065            
066            /**
067             * Creates a new button.
068             * 
069             * @param text The button text.
070             * @param actionListener The action-listener of the button.
071             */
072            public GeneralButton(String text, ActionListener actionListener) {
073                    this(text, 0, actionListener);
074            }
075    
076    }