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.page;
016    
017    import java.util.ArrayList;
018    import java.util.Collections;
019    import java.util.Comparator;
020    
021    import nextapp.echo2.app.Color;
022    import nextapp.echo2.app.Column;
023    import nextapp.echo2.app.Extent;
024    import nextapp.echo2.app.Font;
025    import nextapp.echo2.app.Insets;
026    import nextapp.echo2.app.Row;
027    import nextapp.echo2.app.event.ActionEvent;
028    import nextapp.echo2.app.event.ActionListener;
029    import ch.uzh.ifi.attempto.acewiki.Wiki;
030    import ch.uzh.ifi.attempto.acewiki.core.ontology.OntologyElement;
031    import ch.uzh.ifi.attempto.acewiki.gui.ListItem;
032    import ch.uzh.ifi.attempto.acewiki.gui.Title;
033    import ch.uzh.ifi.attempto.acewiki.gui.WikiLink;
034    import ch.uzh.ifi.attempto.echocomp.Label;
035    import ch.uzh.ifi.attempto.echocomp.SolidLabel;
036    import ch.uzh.ifi.attempto.echocomp.Style;
037    import ch.uzh.ifi.attempto.echocomp.VSpace;
038    
039    /**
040     * This class represents the start page of a wiki.
041     * 
042     * @author Tobias Kuhn
043     */
044    public class StartPage extends WikiPage implements ActionListener {
045            
046            private static final long serialVersionUID = -1528040616289818728L;
047            
048            private Column linksColumn = new Column();
049            
050            /**
051             * Creates a new start page.
052             * 
053             * @param wiki The wiki instance.
054             * @param title The title of the wiki.
055             * @param description The description of the wiki.
056             */
057            public StartPage(Wiki wiki, String title, String description) {
058                    super(wiki, new Title(( title == null || title.length() == 0 ? "Untitled Wiki" : title ), true) );
059                    
060                    addSelectedTab("Main Page");
061                    addTab("Index", this);
062                    addTab("Search", this);
063                    
064                    add(new VSpace(10));
065                    
066                    if (description != null && description.length() > 0) {
067                            addHeadline("Description");
068                            Row desc = new Row();
069                            desc.setInsets(new Insets(10, 10, 0, 15));
070                            desc.add(new Label(description, Font.ITALIC));
071                            add(desc);
072                    }
073                    
074                    addHeadline("Largest Articles");
075                    linksColumn.setInsets(new Insets(10, 10, 0, 15));
076                    add(linksColumn);
077    
078                    add(new VSpace(20));
079                    addHorizontalLine();
080                    
081                    Row footer = new Row();
082                    footer.setInsets(new Insets(10, 10, 0, 20));
083                    String vers = Wiki.getInfo("acewiki-version");
084                    String stage = Wiki.getInfo("acewiki-release-stage");
085                    String dev = Wiki.getInfo("acewiki-developer");
086                    String date = Wiki.getInfo("acewiki-build-date");
087                    SolidLabel footerLabel = new SolidLabel("AceWiki " + vers + " (" + stage + "), " + dev + ", " + date, Font.ITALIC);
088                    footerLabel.setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(10)));
089                    footerLabel.setForeground(Color.DARKGRAY);
090                    footer.add(footerLabel);
091                    add(footer);
092                    
093                    update();
094            }
095            
096            protected void doUpdate() {
097                    linksColumn.removeAll();
098                    ArrayList<OntologyElement> elements = new ArrayList<OntologyElement>(getWiki().getOntology().getOntologyElements());
099                    Collections.sort(elements,
100                            new Comparator<OntologyElement>() {
101                                    public int compare(OntologyElement oe1, OntologyElement oe2) {
102                                            return oe2.getSentences().size() - oe1.getSentences().size();
103                                    }
104                            }
105                    );
106                    int max = (elements.size() > 10 ? 10 : elements.size());
107                    for (int i = 0; i < max; i++) {
108                            Row r = new Row();
109                            r.add(new ListItem(new WikiLink(elements.get(i), getWiki())));
110                            linksColumn.add(r);
111                    }
112            }
113    
114            public void actionPerformed(ActionEvent e) {
115                    if ("Index".equals(e.getActionCommand())) {
116                            getWiki().showIndexPage();
117                    } else if ("Search".equals(e.getActionCommand())) {
118                            getWiki().showSearchPage();
119                    }
120            }
121    
122            public boolean equals(Object obj) {
123                    return obj instanceof StartPage;
124            }
125            
126            public String toString() {
127                    return "-MAIN-";
128            }
129    
130    }