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