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.acewiki.gui;
016
017 import nextapp.echo.app.Alignment;
018 import nextapp.echo.app.Button;
019 import nextapp.echo.app.Color;
020 import nextapp.echo.app.Component;
021 import nextapp.echo.app.Extent;
022 import nextapp.echo.app.Font;
023 import nextapp.echo.app.Insets;
024 import nextapp.echo.app.Row;
025 import nextapp.echo.app.event.ActionEvent;
026 import nextapp.echo.app.event.ActionListener;
027 import nextapp.echo.app.layout.RowLayoutData;
028 import ch.uzh.ifi.attempto.echocomp.Label;
029 import ch.uzh.ifi.attempto.echocomp.SolidLabel;
030 import ch.uzh.ifi.attempto.echocomp.Style;
031
032 /**
033 * This class represents a title label which is used for article titles.
034 *
035 * @author Tobias Kuhn
036 */
037 public class Title extends Row implements ActionListener {
038
039 private static final long serialVersionUID = 7797492687936611323L;
040
041 private Component titleComp;
042 private ActionListener actionListener;
043
044 /**
045 * Creates a new clickable title which has two parts. The second part is shown in gray.
046 *
047 * @param text The text of the main part of the title.
048 * @param postTitle The text of the second part of the title in gray.
049 * @param tooltip The tooltip text.
050 * @param actionListener The action listener.
051 */
052 public Title(String text, String postTitle, String tooltip, ActionListener actionListener) {
053 this.actionListener = actionListener;
054 setInsets(new Insets(10, 5, 10, 5));
055 Row row = new Row();
056 row.setCellSpacing(new Extent(5));
057 if (actionListener == null) {
058 Label l = new Label(text);
059 if (tooltip != null) {
060 l.setToolTipText(tooltip);
061 }
062 titleComp = l;
063 } else {
064 Button b = new Button(text);
065 b.setInsets(new Insets(0, 0, 0, 0));
066 b.setRolloverEnabled(true);
067 b.setRolloverForeground(Color.BLUE);
068 b.addActionListener(this);
069 if (tooltip != null) {
070 b.setToolTipText(tooltip);
071 }
072 titleComp = b;
073 }
074 titleComp.setFont(new Font(Style.fontTypeface, Font.PLAIN, new Extent(20)));
075 row.add(titleComp);
076 SolidLabel postTitleLabel = new SolidLabel(postTitle);
077 postTitleLabel.setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(20)));
078 postTitleLabel.setForeground(Color.DARKGRAY);
079 RowLayoutData layout = new RowLayoutData();
080 layout.setAlignment(new Alignment(Alignment.CENTER, Alignment.BOTTOM));
081 postTitleLabel.setLayoutData(layout);
082 row.add(postTitleLabel);
083 add(row);
084 }
085 /**
086 * Creates a new non-clickable title which has two parts. The second part is shown in gray.
087 *
088 * @param text The text of the main part of the title.
089 * @param postTitle The text of the second part of the title in gray.
090 */
091 public Title(String text, String postTitle) {
092 this(text, postTitle, null, null);
093 }
094
095 /**
096 * Creates a new clickable title.
097 *
098 * @param text The text of the title.
099 * @param italic Defines whether the title text should be displayed in italics.
100 * @param tooltip The tooltip text.
101 * @param actionListener The action listener.
102 */
103 public Title(String text, boolean italic, String tooltip, ActionListener actionListener) {
104 this.actionListener = actionListener;
105 setInsets(new Insets(10, 5, 5, 5));
106 if (actionListener == null) {
107 Label l = new Label(text);
108 if (tooltip != null) {
109 l.setToolTipText(tooltip);
110 }
111 titleComp = l;
112 } else {
113 Button b = new Button(text);
114 b.setInsets(new Insets(0, 0, 0, 0));
115 b.setRolloverEnabled(true);
116 b.setRolloverForeground(Color.BLUE);
117 b.addActionListener(this);
118 if (tooltip != null) {
119 b.setToolTipText(tooltip);
120 }
121 titleComp = b;
122 }
123 if (italic) {
124 titleComp.setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(20)));
125 } else {
126 titleComp.setFont(new Font(Style.fontTypeface, Font.PLAIN, new Extent(20)));
127 }
128 add(titleComp);
129 }
130
131 /**
132 * Creates a new non-clickable title.
133 *
134 * @param text The text of the title.
135 * @param tooltip The tooltip text.
136 * @param actionListener The action listener.
137 */
138 public Title(String text, String tooltip, ActionListener actionListener) {
139 this(text, false, tooltip, actionListener);
140 }
141
142 /**
143 * Creates a new clickable title.
144 *
145 * @param text The text of the title.
146 * @param italic Defines whether the title text should be displayed in italics.
147 */
148 public Title(String text, boolean italic) {
149 this(text, italic, null, null);
150 }
151
152 /**
153 * Creates a new non-clickable title.
154 *
155 * @param text The title text.
156 */
157 public Title(String text) {
158 this(text, false, null, null);
159 }
160
161 /**
162 * Resets the title text.
163 *
164 * @param text The title text.
165 */
166 public void setText(String text) {
167 if (titleComp instanceof Label) {
168 ((Label) titleComp).setText(text);
169 } else if (titleComp instanceof Button) {
170 ((Button) titleComp).setText(text);
171 }
172 }
173
174 /**
175 * Sets the foreground color of the title text.
176 *
177 * @param color The foreground color.
178 */
179 public void setColor(Color color) {
180 titleComp.setForeground(color);
181 }
182
183 public void actionPerformed(ActionEvent e) {
184 actionListener.actionPerformed(new ActionEvent(this, "Title clicked"));
185 }
186
187 }