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            private static final long serialVersionUID = -1385798331737572623L;
034    
035            /**
036             * Creates a new button.
037             * 
038             * @param text The button text.
039             * @param width The button width.
040             * @param actionListener The action-listener of the button.
041             */
042            public GeneralButton(String text, int width, ActionListener actionListener) {
043                    super(text);
044                    
045                    if (width > 0) {
046                            setWidth(new Extent(width));
047                    }
048                    setHeight(new Extent(17));
049                    setBackground(Style.mediumBackground);
050                    setForeground(Style.darkForeground);
051                    setBorder(new Border(1, Color.BLACK, Border.STYLE_OUTSET));
052                    setDisabledBackground(Style.lightDisabled);
053                    setDisabledForeground(Style.darkDisabled);
054                    setDisabledBorder(new Border(1, Color.BLACK, Border.STYLE_OUTSET));
055                    setRolloverEnabled(true);
056                    setRolloverForeground(Style.lightForeground);
057                    setRolloverBackground(Style.darkBackground);
058                    setRolloverBorder(new Border(1, Color.BLACK, Border.STYLE_SOLID));
059                    setInsets(new Insets(2, 0));
060                    setAlignment(new Alignment(Alignment.CENTER, Alignment.CENTER));
061                    setTextAlignment(new Alignment(Alignment.CENTER, Alignment.CENTER));
062                    setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13)));
063                    
064                    setActionCommand(text);
065                    addActionListener(actionListener);
066            }
067            
068            /**
069             * Creates a new button.
070             * 
071             * @param text The button text.
072             * @param actionListener The action-listener of the button.
073             */
074            public GeneralButton(String text, ActionListener actionListener) {
075                    this(text, 0, actionListener);
076            }
077    
078    }