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.editor; 016 017 import nextapp.echo2.app.Alignment; 018 import nextapp.echo2.app.Column; 019 import nextapp.echo2.app.Extent; 020 import nextapp.echo2.app.Font; 021 import nextapp.echo2.app.Insets; 022 import nextapp.echo2.app.Row; 023 import nextapp.echo2.app.event.ActionEvent; 024 import nextapp.echo2.app.event.ActionListener; 025 import ch.uzh.ifi.attempto.acewiki.core.ontology.Comment; 026 import ch.uzh.ifi.attempto.acewiki.core.ontology.OntologyElement; 027 import ch.uzh.ifi.attempto.acewiki.core.ontology.Statement; 028 import ch.uzh.ifi.attempto.acewiki.gui.page.ArticlePage; 029 import ch.uzh.ifi.attempto.echocomp.GeneralButton; 030 import ch.uzh.ifi.attempto.echocomp.Style; 031 import ch.uzh.ifi.attempto.echocomp.TextArea; 032 import ch.uzh.ifi.attempto.echocomp.WindowPane; 033 034 /** 035 * This class represents the editor window that is used to create and edit comments. 036 * 037 * @author Tobias Kuhn 038 */ 039 public class CommentEditorWindow extends WindowPane implements ActionListener { 040 041 private static final long serialVersionUID = -8313716974943714079L; 042 043 private Statement statement; 044 private ArticlePage page; 045 private boolean edit; 046 047 private TextArea textArea; 048 private GeneralButton okButton; 049 private GeneralButton cancelButton; 050 051 /** 052 * Creates a new comment editor window that can be used to either create a new comment 053 * or to edit an existing comment. 054 * 055 * @param statement The statement in front of which the new comment should be added (in the 056 * case of edit=false) or the comment that should be edited (in the case of edit=true). 057 * @param page The host page of the comment. 058 * @param edit true if an existing comment should be edited, or false if a new comment should 059 * be created. 060 */ 061 public CommentEditorWindow(Statement statement, ArticlePage page, boolean edit) { 062 this.statement = statement; 063 this.page = page; 064 this.edit = edit; 065 066 setModal(true); 067 setTitle("Comment Editor"); 068 setTitleFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13))); 069 setWidth(new Extent(500)); 070 setHeight(new Extent(300)); 071 setResizable(false); 072 setTitleBackground(Style.windowTitleBackground); 073 setStyleName("Default"); 074 075 Column mainColumn = new Column(); 076 mainColumn.setInsets(new Insets(10, 10)); 077 mainColumn.setCellSpacing(new Extent(10)); 078 079 textArea = new TextArea(455, 195); 080 textArea.setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13))); 081 if (edit) { 082 textArea.setText(statement.getText()); 083 } 084 mainColumn.add(textArea); 085 086 Row buttonBar = new Row(); 087 buttonBar.setAlignment(new Alignment(Alignment.RIGHT, Alignment.CENTER)); 088 buttonBar.setCellSpacing(new Extent(5)); 089 okButton = new GeneralButton("OK", 70, this); 090 buttonBar.add(okButton); 091 cancelButton = new GeneralButton("Cancel", 70, this); 092 buttonBar.add(cancelButton); 093 mainColumn.add(buttonBar); 094 095 add(mainColumn); 096 } 097 098 public void actionPerformed(ActionEvent e) { 099 if (e.getSource() == okButton) { 100 if (edit) { 101 OntologyElement owner = page.getOntologyElement(); 102 owner.edit(statement, new Comment(textArea.getText(), owner)); 103 page.update(); 104 } else { 105 OntologyElement owner = page.getOntologyElement(); 106 owner.add(statement, new Comment(textArea.getText(), owner)); 107 page.update(); 108 } 109 setVisible(false); 110 dispose(); 111 } else if (e.getSource() == cancelButton) { 112 setVisible(false); 113 dispose(); 114 } 115 } 116 117 }