001 // This file is part of AceWiki. 002 // Copyright 2008-2012, AceWiki developers. 003 // 004 // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU 005 // Lesser General Public License as published by the Free Software Foundation, either version 3 of 006 // the License, or (at your option) any later version. 007 // 008 // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 010 // Lesser General Public License for more details. 011 // 012 // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If 013 // not, see http://www.gnu.org/licenses/. 014 015 package ch.uzh.ifi.attempto.echocomp; 016 017 import nextapp.echo.app.Alignment; 018 import nextapp.echo.app.Column; 019 import nextapp.echo.app.Extent; 020 import nextapp.echo.app.Font; 021 import nextapp.echo.app.Insets; 022 import nextapp.echo.app.Row; 023 import nextapp.echo.app.WindowPane; 024 import nextapp.echo.app.event.ActionEvent; 025 import nextapp.echo.app.event.ActionListener; 026 027 /** 028 * This class represents a window that contains a text area plus "OK" and "Cancel" buttons. 029 * 030 * @author Tobias Kuhn 031 */ 032 public class TextAreaWindow extends WindowPane implements ActionListener { 033 034 private static final long serialVersionUID = -8910244587508187438L; 035 036 private ActionListener actionListener; 037 038 private TextArea textArea; 039 040 /** 041 * Creates a new text area window with the given title, text, and action-listener. 042 * 043 * @param title The title of the window. 044 * @param text The initial text in the text area. 045 * @param actionListener The action-listener or null. 046 */ 047 public TextAreaWindow(String title, String text, ActionListener actionListener) { 048 this.actionListener = actionListener; 049 050 setModal(true); 051 setTitle(title); 052 setTitleFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13))); 053 setResizable(false); 054 setTitleBackground(Style.windowTitleBackground); 055 setStyleName("Default"); 056 057 Column mainColumn = new Column(); 058 mainColumn.setInsets(new Insets(10, 10)); 059 mainColumn.setCellSpacing(new Extent(10)); 060 061 textArea = new TextArea(); 062 textArea.setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13))); 063 textArea.setText(text); 064 mainColumn.add(textArea); 065 066 Row buttonBar = new Row(); 067 buttonBar.setAlignment(new Alignment(Alignment.RIGHT, Alignment.CENTER)); 068 buttonBar.setCellSpacing(new Extent(5)); 069 GeneralButton okButton = new GeneralButton("OK", 70, this); 070 buttonBar.add(okButton); 071 GeneralButton cancelButton = new GeneralButton("Cancel", 70, this); 072 buttonBar.add(cancelButton); 073 mainColumn.add(buttonBar); 074 075 add(mainColumn); 076 077 setSize(450, 300); 078 } 079 080 /** 081 * Creates a new text area window with an empty text area and the given title and 082 * action-listener. 083 * 084 * @param title The title of the window. 085 * @param actionListener The action-listener or null. 086 */ 087 public TextAreaWindow(String title, ActionListener actionListener) { 088 this(title, "", actionListener); 089 } 090 091 /** 092 * Returns the text of the text area. 093 * 094 * @return The text of the text area. 095 */ 096 public String getText() { 097 return textArea.getText(); 098 } 099 100 /** 101 * Sets the text of the text area. 102 * 103 * @param text The new text of the text area. 104 */ 105 public void setText(String text) { 106 textArea.setText(text); 107 } 108 109 /** 110 * Sets the size of the text area window. The size of the text area is set accordingly. 111 * 112 * @param width The width of the window in pixels. 113 * @param height The height of the window in pixels. 114 */ 115 public void setSize(int width, int height) { 116 if (width < 200) width = 200; 117 if (height < 120) height = 120; 118 setWidth(new Extent(width)); 119 setHeight(new Extent(height)); 120 textArea.setWidth(new Extent(width - 45)); 121 textArea.setHeight(new Extent(height - 105)); 122 } 123 124 public void actionPerformed(ActionEvent e) { 125 if (actionListener != null) { 126 actionListener.actionPerformed(new ActionEvent(this, e.getActionCommand())); 127 } 128 setVisible(false); 129 dispose(); 130 } 131 132 }