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 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 " + 119 (ind.hasDefiniteArticle() ? 120 "with \"the\": \"" + ind.getPrettyWord(0) + "\"." : 121 "without \"the\"." 122 ) + " " + 123 (ind.getAbbreviation() != null ? 124 "This proper name has an abbreviation: \"" + ind.getPrettyWord(2) + "\"." : 125 "" 126 ), 127 Font.ITALIC 128 )); 129 lexiconGrid.add(new SolidLabel("word class", Font.ITALIC + Font.BOLD, 11)); 130 lexiconGrid.add(new SolidLabel("proper name", Font.ITALIC)); 131 lexiconGrid.add(new SolidLabel("word", Font.ITALIC + Font.BOLD, 11)); 132 lexiconGrid.add(new SolidLabel(ind.getPrettyWord(1))); 133 lexiconGrid.add(new SolidLabel("... used with \"the\"", Font.ITALIC + Font.BOLD, 11)); 134 lexiconGrid.add(new SolidLabel((ind.hasDefiniteArticle(0) ? "yes" : "no"), Font.ITALIC)); 135 lexiconGrid.add(new SolidLabel("abbreviation", Font.ITALIC + Font.BOLD, 11)); 136 lexiconGrid.add(new SolidLabel(ind.getAbbreviation())); 137 lexiconGrid.add(new SolidLabel("... used with \"the\"", Font.ITALIC + Font.BOLD, 11)); 138 if (ind.getAbbreviation() == null) { 139 lexiconGrid.add(new SolidLabel()); 140 } else { 141 lexiconGrid.add(new SolidLabel((ind.hasDefiniteArticle(2) ? "yes" : "no"), Font.ITALIC)); 142 } 143 } else if (oe instanceof NounConcept) { 144 NounConcept noun = (NounConcept) oe; 145 String sg = noun.getPrettyWord(0); 146 String pl = noun.getPrettyWord(1); 147 iconRow.add(new Label(new ResourceImageReference("ch/uzh/ifi/attempto/acewiki/gui/img/concept.png"))); 148 iconRow.add(new Label( 149 "\"" + sg + "\" is a noun and represents a type of things. " + 150 "It stands for all things that are " + pl + ". " + 151 "The singular form is \"" + sg + "\" and the plural form is \"" + pl + "\".", 152 Font.ITALIC 153 )); 154 lexiconGrid.add(new SolidLabel("word class", Font.ITALIC + Font.BOLD, 11)); 155 lexiconGrid.add(new SolidLabel("noun", Font.ITALIC)); 156 lexiconGrid.add(new SolidLabel("singular", Font.ITALIC + Font.BOLD, 11)); 157 lexiconGrid.add(new SolidLabel(sg)); 158 lexiconGrid.add(new SolidLabel("plural", Font.ITALIC + Font.BOLD, 11)); 159 lexiconGrid.add(new SolidLabel(pl)); 160 } else if (oe instanceof VerbRole) { 161 VerbRole verb = (VerbRole) oe; 162 String th = verb.getPrettyWord(0); 163 String inf = verb.getPrettyWord(1); 164 String pp = verb.getPrettyPastPart(); 165 iconRow.add(new Label(new ResourceImageReference("ch/uzh/ifi/attempto/acewiki/gui/img/role.png"))); 166 iconRow.add(new Label( 167 "\"" + inf + "\" is a verb and represents a relation between things. " + 168 "It represents the fact that certain things " + inf + " other things. " + 169 "The third singular form is \"" + th + "\", the bare infinitive form is \"" + inf + "\", " + 170 "and the past participle form is " + (pp == null ? "undefined" : "\"" + pp + "\"") + ".", 171 Font.ITALIC 172 )); 173 lexiconGrid.add(new SolidLabel("word class", Font.ITALIC + Font.BOLD, 11)); 174 lexiconGrid.add(new SolidLabel("verb", Font.ITALIC)); 175 lexiconGrid.add(new SolidLabel("third singular", Font.ITALIC + Font.BOLD, 11)); 176 lexiconGrid.add(new SolidLabel(th)); 177 lexiconGrid.add(new SolidLabel("bare infinitive", Font.ITALIC + Font.BOLD, 11)); 178 lexiconGrid.add(new SolidLabel(inf)); 179 lexiconGrid.add(new SolidLabel("past participle", Font.ITALIC + Font.BOLD, 11)); 180 lexiconGrid.add(new SolidLabel(pp)); 181 } else if (oe instanceof OfRole) { 182 OfRole of = (OfRole) oe; 183 iconRow.add(new Label(new ResourceImageReference("ch/uzh/ifi/attempto/acewiki/gui/img/role.png"))); 184 iconRow.add(new Label( 185 "\"" + of.getPrettyNoun() + " of\" is an of-construct and represents a relation between things. " + 186 "It represents the fact that certain things are a " + of.getPrettyNoun() + " of other things. " + 187 "It consists of the noun \"" + of.getPrettyNoun() + "\" plus the preposition \"of\".", 188 Font.ITALIC 189 )); 190 lexiconGrid.add(new SolidLabel("word class", Font.ITALIC + Font.BOLD, 11)); 191 lexiconGrid.add(new SolidLabel("of-construct", Font.ITALIC)); 192 lexiconGrid.add(new SolidLabel("noun", Font.ITALIC + Font.BOLD, 11)); 193 lexiconGrid.add(new SolidLabel(of.getPrettyNoun())); 194 } else if (oe instanceof TrAdjRole) { 195 TrAdjRole tradj = (TrAdjRole) oe; 196 iconRow.add(new Label(new ResourceImageReference("ch/uzh/ifi/attempto/acewiki/gui/img/role.png"))); 197 iconRow.add(new Label( 198 "\"" + tradj.getPrettyWord(0) + "\" is a transitive adjective and represents a relation between things. " + 199 "It represents the fact that certain things are " + tradj.getPrettyWord(0) + " other things. ", 200 Font.ITALIC 201 )); 202 lexiconGrid.add(new SolidLabel("word class", Font.ITALIC + Font.BOLD, 11)); 203 lexiconGrid.add(new SolidLabel("transitive adjective", Font.ITALIC)); 204 lexiconGrid.add(new SolidLabel("word", Font.ITALIC + Font.BOLD, 11)); 205 lexiconGrid.add(new SolidLabel(tradj.getPrettyWord(0))); 206 } 207 208 textColumn.add(new VSpace()); 209 210 Row headButtonRow = new Row(); 211 headButtonRow.add(editButton); 212 headButtonRow.add(new HSpace()); 213 headButtonRow.add(delButton); 214 textColumn.add(headButtonRow); 215 } 216 217 public void actionPerformed(ActionEvent e) { 218 Wiki wiki = getWiki(); 219 if ("Article".equals(e.getActionCommand())) { 220 log("page", "pressed: article"); 221 wiki.showPage(page); 222 } else if ("References".equals(e.getActionCommand())) { 223 log("page", "pressed: references"); 224 wiki.showPage(new ReferencesPage(page)); 225 } else if ("Individuals".equals(e.getActionCommand())) { 226 log("page", "pressed: individuals"); 227 wiki.showPage(new IndividualsPage((ConceptPage) page)); 228 } else if ("Hierarchy".equals(e.getActionCommand())) { 229 log("page", "pressed: hierarchy"); 230 wiki.showPage(new HierarchyPage((ConceptPage) page)); 231 } else if ("Assignments".equals(e.getActionCommand())) { 232 log("page", "pressed: assignments"); 233 wiki.showPage(new AssignmentsPage((IndividualPage) page)); 234 } else if (e.getSource() == delButton) { 235 log("page", "pressed: delete"); 236 OntologyElement oe = page.getOntologyElement(); 237 List<Sentence> references = wiki.getOntology().getReferences(oe); 238 for (Sentence s : oe.getSentences()) { 239 references.remove(s); 240 } 241 if (!references.isEmpty()) { 242 log("page", "error: cannot delete article with references"); 243 wiki.showWindow(new MessageWindow("Error", "This article cannot be deleted, because other articles refer to it.", null, this, "OK")); 244 } else { 245 log("page", "delete confirmation"); 246 wiki.showWindow(new MessageWindow("Delete", "Do you really want to delete this word and all the content of its article?", null, this, "Yes", "No")); 247 } 248 } else if (e.getSource() instanceof MessageWindow && e.getActionCommand().equals("Yes")) { 249 log("page", "delete confirmed"); 250 wiki.getOntology().remove(page.getOntologyElement()); 251 wiki.showStartPage(); 252 } else if (e.getSource() == editButton) { 253 log("page", "pressed: edit word"); 254 if (page instanceof ConceptPage) { 255 wiki.showWindow(NounForm.createEditorWindow((NounConcept) page.getOntologyElement(), wiki)); 256 } else if (page instanceof IndividualPage) { 257 wiki.showWindow(ProperNameForm.createEditorWindow((Individual) page.getOntologyElement(), wiki)); 258 } else if (page.getOntologyElement() instanceof OfRole) { 259 wiki.showWindow(NounOfForm.createEditorWindow((OfRole) page.getOntologyElement(), wiki)); 260 } else if (page.getOntologyElement() instanceof VerbRole) { 261 wiki.showWindow(VerbForm.createEditorWindow((VerbRole) page.getOntologyElement(), wiki)); 262 } else if (page.getOntologyElement() instanceof TrAdjRole) { 263 wiki.showWindow(TrAdjForm.createEditorWindow((TrAdjRole) page.getOntologyElement(), wiki)); 264 } 265 } 266 } 267 268 public boolean equals(Object obj) { 269 if (obj instanceof WordPage) { 270 return page.equals(((WordPage) obj).page); 271 } 272 return false; 273 } 274 275 public boolean isExpired() { 276 return page.isExpired(); 277 } 278 279 public String toString() { 280 return "-WORD- " + page.getOntologyElement().getWord(); 281 } 282 283 }