    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 nextapp.echo2.app.Button;
    018    import nextapp.echo2.app.Color;
    019    import nextapp.echo2.app.Extent;
    020    import nextapp.echo2.app.Font;
    021    import nextapp.echo2.app.Insets;
    022    import nextapp.echo2.app.event.ActionEvent;
    023    import nextapp.echo2.app.event.ActionListener;
    024    import ch.uzh.ifi.attempto.acewiki.Wiki;
    025    import ch.uzh.ifi.attempto.acewiki.core.ontology.OntologyElement;
    026    import ch.uzh.ifi.attempto.acewiki.core.text.OntologyTextElement;
    027    import ch.uzh.ifi.attempto.echocomp.Style;
    028
    029    /**
    030     * This class represents a wiki-internal link.
    031     *
    032     * @author Tobias Kuhn
    033     */
    034    public class WikiLink extends Button implements ActionListener {
    035
    036            private static final long serialVersionUID = -2234400779848457043L;
    037
    038            private OntologyElement ontologyElement;
    039            private Wiki wiki;
    040
    041            /**
    042             * Creates a new link to the article of the given ontology element. The headword of the
    043             * ontology element is used as the link text.
    044             *
    045             * @param ontologyElement The ontology element whose article should be linked.
    046             * @param wiki The wiki instance.
    047             */
    048            public WikiLink(OntologyElement ontologyElement, Wiki wiki) {
    049                    super(ontologyElement.getHeadword());
    050                    this.wiki = wiki;
    051                    this.ontologyElement = ontologyElement;
    052                    initButton(false);
    053            }
    054
    055            /**
    056             * Creates a new link to the article of the given ontology element.
    057             *
    058             * @param ontologyElement The ontology element whose article should be linked.
    059             * @param text The link text.
    060             * @param wiki The wiki instance.
    061             * @param red true if the link text should be displayed in red font.
    062             */
    063            public WikiLink(OntologyElement ontologyElement, String text, Wiki wiki, boolean red) {
    064                    super(text);
    065                    this.wiki = wiki;
    066                    this.ontologyElement = ontologyElement;
    067                    initButton(red);
    068            }
    069
    070            /**
    071             * Creates a new wiki link on the basis of a text element. It links to the article of the
    072             * ontology element of the text element. The text of the text element is used as the link
    073             * text.
    074             *
    075             * @param textElement The text element.
    076             * @param wiki The wiki instance.
    077             * @param red true if the link text should be displayed in red font.
    078             */
    079            public WikiLink(OntologyTextElement textElement, Wiki wiki, boolean red) {
    080                    super(textElement.getText());
    081                    this.wiki = wiki;
    082                    this.ontologyElement = textElement.getOntologyElement();
    083                    initButton(red);
    084            }
    085
    086            private void initButton(boolean red) {
    087                    setInsets(new Insets(0, 0, 0, 0));
    088                    setLineWrap(false);
    089                    setRolloverEnabled(true);
    090                    setFont(new Font(Style.fontTypeface, Font.PLAIN, new Extent(13)));
    091                    setRolloverForeground(Color.BLUE);
    092                    if (red) setForeground(new Color(193, 0, 0));
    093                    addActionListener(this);
    094            }
    095
    096            public void actionPerformed(ActionEvent e) {
    097                    wiki.log("page", "pressed: link " + ontologyElement.getWord());
    098                    wiki.showPage(ontologyElement);
    099            }
    100
    101    }