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.List; 018 019 import nextapp.echo2.app.Border; 020 import nextapp.echo2.app.Color; 021 import nextapp.echo2.app.Column; 022 import nextapp.echo2.app.Extent; 023 import nextapp.echo2.app.Font; 024 import nextapp.echo2.app.Grid; 025 import nextapp.echo2.app.Insets; 026 import nextapp.echo2.app.ResourceImageReference; 027 import nextapp.echo2.app.Row; 028 import nextapp.echo2.app.event.ActionEvent; 029 import nextapp.echo2.app.event.ActionListener; 030 import ch.uzh.ifi.attempto.acewiki.Wiki; 031 import ch.uzh.ifi.attempto.acewiki.core.ontology.Individual; 032 import ch.uzh.ifi.attempto.acewiki.core.ontology.NounConcept; 033 import ch.uzh.ifi.attempto.acewiki.core.ontology.OfRole; 034 import ch.uzh.ifi.attempto.acewiki.core.ontology.OntologyElement; 035 import ch.uzh.ifi.attempto.acewiki.core.ontology.Sentence; 036 import ch.uzh.ifi.attempto.acewiki.core.ontology.TrAdjRole; 037 import ch.uzh.ifi.attempto.acewiki.core.ontology.VerbRole; 038 import ch.uzh.ifi.attempto.acewiki.gui.Title; 039 import ch.uzh.ifi.attempto.acewiki.gui.editor.NounForm; 040 import ch.uzh.ifi.attempto.acewiki.gui.editor.NounOfForm; 041 import ch.uzh.ifi.attempto.acewiki.gui.editor.ProperNameForm; 042 import ch.uzh.ifi.attempto.acewiki.gui.editor.TrAdjForm; 043 import ch.uzh.ifi.attempto.acewiki.gui.editor.VerbForm; 044 import ch.uzh.ifi.attempto.echocomp.HSpace; 045 import ch.uzh.ifi.attempto.echocomp.Label; 046 import ch.uzh.ifi.attempto.echocomp.MessageWindow; 047 import ch.uzh.ifi.attempto.echocomp.SmallButton; 048 import ch.uzh.ifi.attempto.echocomp.SolidLabel; 049 import ch.uzh.ifi.attempto.echocomp.VSpace; 050 051 /** 052 * This class represents a page that shows the details about a certain word. 053 * 054 * @author Tobias Kuhn 055 */ 056 public class WordPage extends WikiPage implements ActionListener { 057 058 private static final long serialVersionUID = 5800290686564822519L; 059 060 private ArticlePage page; 061 062 private SmallButton editButton = new SmallButton("edit...", this); 063 private SmallButton delButton = new SmallButton("delete...", this); 064 065 private Column textColumn = new Column(); 066 067 /** 068 * Creates a new word page. 069 * 070 * @param page The main page that contains the article. 071 */ 072 public WordPage(ArticlePage page) { 073 super(page.getWiki(), new Title(page.getOntologyElement().getHeadword(), "- " + page.getOntologyElement().getType())); 074 this.page = page; 075 076 addTab("Article", this); 077 addSelectedTab(page.getOntologyElement().getType()); 078 addTab("References", this); 079 if (page instanceof ConceptPage) { 080 addTab("Individuals", this); 081 addTab("Hierarchy", this); 082 } 083 if (page instanceof IndividualPage) { 084 addTab("Assignments", this); 085 } 086 087 add(new VSpace(10)); 088 089 textColumn.setInsets(new Insets(10, 10, 5, 20)); 090 textColumn.setCellSpacing(new Extent(5)); 091 add(textColumn); 092 } 093 094 protected void doUpdate() { 095 getTitle().setText(page.getOntologyElement().getHeadword()); 096 097 textColumn.removeAll(); 098 099 Grid iconRow = new Grid(2); 100 iconRow.setRowHeight(0, new Extent(110)); 101 iconRow.setColumnWidth(0, new Extent(100)); 102 iconRow.setInsets(new Insets(0, 0, 0, 10)); 103 textColumn.add(iconRow); 104 105 Grid lexiconGrid = new Grid(2); 106 lexiconGrid.setInsets(new Insets(5, 1, 20, 2)); 107 lexiconGrid.setBorder(new Border(1, Color.DARKGRAY, Border.STYLE_SOLID)); 108 lexiconGrid.setBackground(new Color(245, 245, 245)); 109 textColumn.add(lexiconGrid); 110 111 OntologyElement oe = page.getOntologyElement(); 112 if (oe instanceof Individual) { 113 Individual ind = (Individual) oe; 114 iconRow.add(new Label(new ResourceImageReference("ch/uzh/ifi/attempto/acewiki/gui/img/individual.png"))); 115 iconRow.add(new Label( 116 "\"" + ind.getPrettyWord(1) + "\" is a proper name and represents an individual. " + 117 "There is exactly one thing that has the name \"" + ind.getPrettyWord(1) + "\". " + 118 "This proper name is used " + (ind.hasDefiniteArticle() ? "with a definite article: \"" + ind.getPrettyWord(0) + "\"." : "without a definite article."), 119 Font.ITALIC 120 )); 121 lexiconGrid.add(new SolidLabel("word class", Font.ITALIC + Font.BOLD, 11)); 122 lexiconGrid.add(new SolidLabel("proper name", Font.ITALIC)); 123 lexiconGrid.add(new SolidLabel("word", Font.ITALIC + Font.BOLD, 11)); 124 lexiconGrid.add(new SolidLabel(ind.getPrettyWord(1))); 125 lexiconGrid.add(new SolidLabel("definite article", Font.ITALIC + Font.BOLD, 11)); 126 lexiconGrid.add(new SolidLabel((ind.hasDefiniteArticle() ? "yes" : "no"), Font.ITALIC)); 127 } else if (oe instanceof NounConcept) { 128 NounConcept noun = (NounConcept) oe; 129 String sg = noun.getPrettyWord(0); 130 String pl = noun.getPrettyWord(1); 131 iconRow.add(new Label(new ResourceImageReference("ch/uzh/ifi/attempto/acewiki/gui/img/concept.png"))); 132 iconRow.add(new Label( 133 "\"" + sg + "\" is a noun and represents a type of things. " + 134 "It stands for all things that are " + pl + ". " + 135 "The singular form is \"" + sg + "\" and the plural form is \"" + pl + "\".", 136 Font.ITALIC 137 )); 138 lexiconGrid.add(new SolidLabel("word class", Font.ITALIC + Font.BOLD, 11)); 139 lexiconGrid.add(new SolidLabel("noun", Font.ITALIC)); 140 lexiconGrid.add(new SolidLabel("singular", Font.ITALIC + Font.BOLD, 11)); 141 lexiconGrid.add(new SolidLabel(sg)); 142 lexiconGrid.add(new SolidLabel("plural", Font.ITALIC + Font.BOLD, 11)); 143 lexiconGrid.add(new SolidLabel(pl)); 144 } else if (oe instanceof VerbRole) { 145 VerbRole verb = (VerbRole) oe; 146 String th = verb.getPrettyWord(0); 147 String inf = verb.getPrettyWord(1); 148 String pp = verb.getPrettyPastPart(); 149 iconRow.add(new Label(new ResourceImageReference("ch/uzh/ifi/attempto/acewiki/gui/img/role.png"))); 150 iconRow.add(new Label( 151 "\"" + inf + "\" is a verb and represents a relation between things. " + 152 "It represents the fact that certain things " + inf + " other things. " + 153 "The third singular form is \"" + th + "\", the bare infinitive form is \"" + inf + "\", " + 154 "and the past participle form is " + (pp == null ? "undefined" : "\"" + pp + "\"") + ".", 155 Font.ITALIC 156 )); 157 lexiconGrid.add(new SolidLabel("word class", Font.ITALIC + Font.BOLD, 11)); 158 lexiconGrid.add(new SolidLabel("verb", Font.ITALIC)); 159 lexiconGrid.add(new SolidLabel("third singular", Font.ITALIC + Font.BOLD, 11)); 160 lexiconGrid.add(new SolidLabel(th)); 161 lexiconGrid.add(new SolidLabel("bare infinitive", Font.ITALIC + Font.BOLD, 11)); 162 lexiconGrid.add(new SolidLabel(inf)); 163 lexiconGrid.add(new SolidLabel("past participle", Font.ITALIC + Font.BOLD, 11)); 164 lexiconGrid.add(new SolidLabel(pp)); 165 } else if (oe instanceof OfRole) { 166 OfRole of = (OfRole) oe; 167 iconRow.add(new Label(new ResourceImageReference("ch/uzh/ifi/attempto/acewiki/gui/img/role.png"))); 168 iconRow.add(new Label( 169 "\"" + of.getPrettyNoun() + " of\" is an of-construct and represents a relation between things. " + 170 "It represents the fact that certain things are a " + of.getPrettyNoun() + " of other things. " + 171 "It consists of the noun \"" + of.getPrettyNoun() + "\" plus the preposition \"of\".", 172 Font.ITALIC 173 )); 174 lexiconGrid.add(new SolidLabel("word class", Font.ITALIC + Font.BOLD, 11)); 175 lexiconGrid.add(new SolidLabel("of-construct", Font.ITALIC)); 176 lexiconGrid.add(new SolidLabel("noun", Font.ITALIC + Font.BOLD, 11)); 177 lexiconGrid.add(new SolidLabel(of.getPrettyNoun())); 178 } else if (oe instanceof TrAdjRole) { 179 TrAdjRole tradj = (TrAdjRole) oe; 180 iconRow.add(new Label(new ResourceImageReference("ch/uzh/ifi/attempto/acewiki/gui/img/role.png"))); 181 iconRow.add(new Label( 182 "\"" + tradj.getPrettyWord(0) + "\" is a transitive adjective and represents a relation between things. " + 183 "It represents the fact that certain things are " + tradj.getPrettyWord(0) + " other things. ", 184 Font.ITALIC 185 )); 186 lexiconGrid.add(new SolidLabel("word class", Font.ITALIC + Font.BOLD, 11)); 187 lexiconGrid.add(new SolidLabel("transitive adjective", Font.ITALIC)); 188 lexiconGrid.add(new SolidLabel("word", Font.ITALIC + Font.BOLD, 11)); 189 lexiconGrid.add(new SolidLabel(tradj.getPrettyWord(0))); 190 } 191 192 textColumn.add(new VSpace()); 193 194 Row headButtonRow = new Row(); 195 headButtonRow.add(editButton); 196 headButtonRow.add(new HSpace()); 197 headButtonRow.add(delButton); 198 textColumn.add(headButtonRow); 199 } 200 201 public void actionPerformed(ActionEvent e) { 202 Wiki wiki = getWiki(); 203 if ("Article".equals(e.getActionCommand())) { 204 log("page", "pressed: article"); 205 wiki.showPage(page); 206 } else if ("References".equals(e.getActionCommand())) { 207 log("page", "pressed: references"); 208 wiki.showPage(new ReferencesPage(page)); 209 } else if ("Individuals".equals(e.getActionCommand())) { 210 log("page", "pressed: individuals"); 211 wiki.showPage(new IndividualsPage((ConceptPage) page)); 212 } else if ("Hierarchy".equals(e.getActionCommand())) { 213 log("page", "pressed: hierarchy"); 214 wiki.showPage(new HierarchyPage((ConceptPage) page)); 215 } else if ("Assignments".equals(e.getActionCommand())) { 216 log("page", "pressed: assignments"); 217 wiki.showPage(new AssignmentsPage((IndividualPage) page)); 218 } else if (e.getSource() == delButton) { 219 log("page", "pressed: delete"); 220 OntologyElement oe = page.getOntologyElement(); 221 List<Sentence> references = wiki.getOntology().getReferences(oe); 222 for (Sentence s : oe.getSentences()) { 223 references.remove(s); 224 } 225 if (!references.isEmpty()) { 226 log("page", "error: cannot delete article with references"); 227 wiki.showWindow(new MessageWindow("Error", "This article cannot be deleted, because other articles refer to it.", null, this, "OK")); 228 } else { 229 log("page", "delete confirmation"); 230 wiki.showWindow(new MessageWindow("Delete", "Do you really want to delete this word and all the content of its article?", null, this, "Yes", "No")); 231 } 232 } else if (e.getSource() instanceof MessageWindow && e.getActionCommand().equals("Yes")) { 233 log("page", "delete confirmed"); 234 wiki.getOntology().remove(page.getOntologyElement()); 235 wiki.showStartPage(); 236 } else if (e.getSource() == editButton) { 237 log("page", "pressed: edit word"); 238 if (page instanceof ConceptPage) { 239 wiki.showWindow(NounForm.createEditorWindow((NounConcept) page.getOntologyElement(), wiki)); 240 } else if (page instanceof IndividualPage) { 241 wiki.showWindow(ProperNameForm.createEditorWindow((Individual) page.getOntologyElement(), wiki)); 242 } else if (page.getOntologyElement() instanceof OfRole) { 243 wiki.showWindow(NounOfForm.createEditorWindow((OfRole) page.getOntologyElement(), wiki)); 244 } else if (page.getOntologyElement() instanceof VerbRole) { 245 wiki.showWindow(VerbForm.createEditorWindow((VerbRole) page.getOntologyElement(), wiki)); 246 } else if (page.getOntologyElement() instanceof TrAdjRole) { 247 wiki.showWindow(TrAdjForm.createEditorWindow((TrAdjRole) page.getOntologyElement(), wiki)); 248 } 249 } 250 } 251 252 public boolean equals(Object obj) { 253 if (obj instanceof WordPage) { 254 return page.equals(((WordPage) obj).page); 255 } 256 return false; 257 } 258 259 public boolean isExpired() { 260 return page.isExpired(); 261 } 262 263 public String toString() { 264 return "-WORD- " + page.getOntologyElement().getWord(); 265 } 266 267 }