    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.acewiki.gui;
    016
    017    import ch.uzh.ifi.attempto.echocomp.Label;
    018    import ch.uzh.ifi.attempto.echocomp.SolidLabel;
    019    import ch.uzh.ifi.attempto.echocomp.Style;
    020    import nextapp.echo2.app.Alignment;
    021    import nextapp.echo2.app.Color;
    022    import nextapp.echo2.app.Extent;
    023    import nextapp.echo2.app.Font;
    024    import nextapp.echo2.app.Insets;
    025    import nextapp.echo2.app.Row;
    026    import nextapp.echo2.app.layout.RowLayoutData;
    027
    028    /**
    029     * This class represents a title label which is used for article titles.
    030     *
    031     * @author Tobias Kuhn
    032     */
    033    public class Title extends Row {
    034
    035            private static final long serialVersionUID = 7797492687936611323L;
    036
    037            private Label titleLabel;
    038
    039            /**
    040             * Creates a new title which has two parts. The second part is shown in gray font.
    041             *
    042             * @param text The text of the main part of the title.
    043             * @param postTitle The text of the second part of the title in gray font.
    044             */
    045            public Title(String text, String postTitle) {
    046                    setInsets(new Insets(10, 5, 10, 5));
    047                    Row row = new Row();
    048                    row.setCellSpacing(new Extent(5));
    049                    titleLabel = new Label(text);
    050                    titleLabel.setFont(new Font(Style.fontTypeface, Font.PLAIN, new Extent(20)));
    051                    row.add(titleLabel);
    052                    SolidLabel postTitleLabel = new SolidLabel(postTitle);
    053                    postTitleLabel.setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(20)));
    054                    postTitleLabel.setForeground(Color.DARKGRAY);
    055                    RowLayoutData layout = new RowLayoutData();
    056                    layout.setAlignment(new Alignment(Alignment.CENTER, Alignment.BOTTOM));
    057                    postTitleLabel.setLayoutData(layout);
    058                    row.add(postTitleLabel);
    059                    add(row);
    060            }
    061
    062            /**
    063             * Creates a new title.
    064             *
    065             * @param text The text of the title.
    066             * @param italic Defines whether the title text should be displayed in italics.
    067             */
    068            public Title(String text, boolean italic) {
    069                    setInsets(new Insets(10, 5, 5, 5));
    070                    titleLabel = new Label(text);
    071                    if (italic) {
    072                            titleLabel.setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(20)));
    073                    } else {
    074                            titleLabel.setFont(new Font(Style.fontTypeface, Font.PLAIN, new Extent(20)));
    075                    }
    076                    add(titleLabel);
    077            }
    078
    079            /**
    080             * Creates a new title.
    081             *
    082             * @param text The title text.
    083             */
    084            public Title(String text) {
    085                    this(text, false);
    086            }
    087
    088            /**
    089             * Resets the title text.
    090             *
    091             * @param text The title text.
    092             */
    093            public void setText(String text) {
    094                    titleLabel.setText(text);
    095            }
    096
    097            /**
    098             * Sets the foreground color of the title text.
    099             *
    100             * @param color The foreground color.
    101             */
    102            public void setColor(Color color) {
    103                    titleLabel.setForeground(color);
    104            }
    105
    106    }