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