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 ch.uzh.ifi.attempto.echocomp.Style;
018 import nextapp.echo.app.ApplicationInstance;
019 import nextapp.echo.app.Button;
020 import nextapp.echo.app.Color;
021 import nextapp.echo.app.Extent;
022 import nextapp.echo.app.Font;
023 import nextapp.echo.app.ImageReference;
024 import nextapp.echo.app.event.ActionEvent;
025 import nextapp.echo.app.event.ActionListener;
026 import nextapp.echo.webcontainer.command.BrowserRedirectCommand;
027
028 /**
029 * This class represents a web link that points to a foreign website.
030 *
031 * @author Tobias Kuhn
032 */
033 public class WebLink extends Button implements ActionListener {
034
035 private static final long serialVersionUID = -7315714524602560410L;
036
037 private String url;
038
039 /**
040 * Creates a new web link.
041 *
042 * @param url The URL of the website.
043 * @param text The link text.
044 * @param verbose If true then the URL is included in the link text.
045 */
046 public WebLink(String url, String text, boolean verbose) {
047 if (verbose) {
048 setText(text + " (" + url + ")");
049 } else {
050 setText(text);
051 }
052 this.url = url;
053 initButton();
054 }
055
056 /**
057 * Creates a new web link.
058 *
059 * @param url The URL of the website.
060 * @param text The link text.
061 */
062 public WebLink(String url, String text) {
063 this(url, text, false);
064 }
065
066 /**
067 * Creates a new web link with the URL as the link text.
068 *
069 * @param url The URL of the website.
070 */
071 public WebLink(String url) {
072 this(url, url, false);
073 }
074
075 /**
076 * Creates a new web link consisting of an image.
077 *
078 * @param url The URL of the website.
079 * @param image The image that acts as a link.
080 */
081 public WebLink(String url, ImageReference image) {
082 super(image);
083 this.url = url;
084 initButton();
085 }
086
087 private void initButton() {
088 setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13)));
089 setForeground(Style.mediumForeground);
090 setLineWrap(false);
091 setRolloverEnabled(true);
092 setRolloverForeground(Color.BLUE);
093 addActionListener(this);
094 }
095
096 public void actionPerformed(ActionEvent e) {
097 ApplicationInstance.getActive().enqueueCommand(new BrowserRedirectCommand(url));
098 }
099
100 }