001    // This file is part of the Attempto Java Packages.
002    // Copyright 2008-2009, 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 nextapp.echo2.app.Color;
018    import nextapp.echo2.app.event.ActionEvent;
019    import ch.uzh.ifi.attempto.acewiki.Wiki;
020    import ch.uzh.ifi.attempto.acewiki.core.ontology.Concept;
021    import ch.uzh.ifi.attempto.acewiki.core.ontology.NounConcept;
022    import ch.uzh.ifi.attempto.acewiki.core.ontology.OntologyElement;
023    
024    /**
025     * This class stands for an article page showing the article of a concept. At the
026     * moment, concepts are represented only by nouns.
027     * 
028     * @author Tobias Kuhn
029     */
030    public class ConceptPage extends ArticlePage {
031            
032            private static final long serialVersionUID = -505381176379658743L;
033    
034            private NounConcept concept;
035            
036            /**
037             * Creates a new article page for a concept.
038             * 
039             * @param concept The concept.
040             * @param wiki The wiki instance.
041             */
042            protected ConceptPage(Concept concept, Wiki wiki) {
043                    super(wiki, concept);
044                    this.concept = (NounConcept) concept;
045                    
046                    addTab("Individuals", this);
047                    addTab("Hierarchy", this);
048            }
049            
050            public OntologyElement getOntologyElement() {
051                    return concept;
052            }
053    
054            public void actionPerformed(ActionEvent e) {
055                    super.actionPerformed(e);
056                    if ("Individuals".equals(e.getActionCommand())) {
057                            getWiki().showPage(new IndividualsPage(this));
058                    } else if ("Hierarchy".equals(e.getActionCommand())) {
059                            getWiki().showPage(new HierarchyPage(this));
060                    }
061            }
062            
063            protected void doUpdate() {
064                    super.doUpdate();
065                    
066                    getTitle().setText(concept.getHeadword());
067                    
068                    Thread thread = new Thread() {
069                            public void run() {
070                                    synchronized (getWiki().getApplication()) {
071                                            getWiki().enqueueTask(new Runnable() {
072                                                    public void run() {
073                                                            if (concept.getOntology().isSatisfiable(concept)) {
074                                                                    getTitle().setColor(Color.BLACK);
075                                                            } else {
076                                                                    getTitle().setColor(new Color(193, 0, 0));
077                                                            }
078                                                    }
079                                            });
080                                            try {
081                                                    sleep(500);
082                                            } catch (InterruptedException ex) {}
083                                    }
084                            }
085                    };
086                    thread.setPriority(Thread.MIN_PRIORITY);
087                    thread.start();
088            }
089    
090    }