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.echocomp;
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.Grid;
022 import nextapp.echo2.app.Insets;
023 import nextapp.echo2.app.ResourceImageReference;
024 import nextapp.echo2.app.Row;
025 import nextapp.echo2.app.event.ActionEvent;
026 import nextapp.echo2.app.event.ActionListener;
027 import nextapp.echo2.app.layout.GridLayoutData;
028
029 /**
030 * This is a convenience class for easy creation of message windows.
031 *
032 * @author Tobias Kuhn
033 */
034 public class MessageWindow extends WindowPane implements ActionListener {
035
036 private static final long serialVersionUID = -6999194368016297503L;
037
038 private ActionListener actionListener;
039
040 /**
041 * Creates a new message window.
042 *
043 * @param title The title of the window.
044 * @param image The image to be displayed above the text.
045 * @param message The message text.
046 * @param parent The parent window.
047 * @param actionListener The action-listener.
048 * @param options A list of options each represented by a button in the message window.
049 */
050 public MessageWindow(String title, ResourceImageReference image, String message, WindowPane parent, ActionListener actionListener, String... options) {
051 this.actionListener = actionListener;
052 setTitle(title);
053 setTitleFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13)));
054 setModal(true);
055 setWidth(new Extent(400));
056 setHeight(new Extent(165));
057 setResizable(false);
058 setMovable(true);
059 setTitleBackground(Style.windowTitleBackground);
060 setStyleName("Default");
061
062 Grid grid = new Grid(1);
063 grid.setInsets(new Insets(10, 10, 10, 0));
064 grid.setColumnWidth(0, new Extent(380));
065 grid.setRowHeight(0, new Extent(70));
066
067 Column iconMessageColumn = new Column();
068 GridLayoutData layout1 = new GridLayoutData();
069 layout1.setAlignment(new Alignment(Alignment.LEFT, Alignment.TOP));
070 iconMessageColumn.setLayoutData(layout1);
071
072 if (image != null) {
073 iconMessageColumn.add(new Label(image));
074 iconMessageColumn.add(new VSpace(5));
075 }
076
077 Label label = new Label(message);
078 label.setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13)));
079 iconMessageColumn.add(label);
080 grid.add(iconMessageColumn);
081
082 Row buttonBar = new Row();
083 buttonBar.setCellSpacing(new Extent(10));
084 for (String s : options) {
085 buttonBar.add(new GeneralButton(s, 70, this));
086 }
087 GridLayoutData layout2 = new GridLayoutData();
088 layout2.setAlignment(new Alignment(Alignment.CENTER, Alignment.BOTTOM));
089 buttonBar.setLayoutData(layout2);
090 grid.add(buttonBar);
091
092 add(grid);
093
094 if (parent != null) {
095 setPositionX(new Extent(parent.getPositionX().getValue() + (parent.getWidth().getValue() - getWidth().getValue())/2));
096 setPositionY(new Extent(parent.getPositionY().getValue() + (parent.getHeight().getValue() - getHeight().getValue())/2));
097 }
098 }
099
100 /**
101 * Creates a new message window.
102 *
103 * @param title The title of the window.
104 * @param message The message text.
105 * @param parent The parent window.
106 * @param actionListener The action-listener.
107 * @param options A list of options each represented by a button in the message window.
108 */
109 public MessageWindow(String title, String message, WindowPane parent, ActionListener actionListener, String... options) {
110 this(title, null, message, parent, actionListener, options);
111 }
112
113 /**
114 * Creates a new message window.
115 *
116 * @param title The title of the window.
117 * @param message The message text.
118 * @param parent The parent window.
119 * @param options A list of options each represented by a button in the message window.
120 */
121 public MessageWindow(String title, String message, WindowPane parent, String... options) {
122 this(title, null, message, parent, null, options);
123 }
124
125 /**
126 * Creates a new message window.
127 *
128 * @param title The title of the window.
129 * @param message The message text.
130 * @param options A list of options each represented by a button in the message window.
131 */
132 public MessageWindow(String title, String message, String... options) {
133 this(title, null, message, null, null, options);
134 }
135
136 public void actionPerformed(ActionEvent e) {
137 setVisible(false);
138 if (actionListener != null) {
139 actionListener.actionPerformed(new ActionEvent(this, e.getActionCommand()));
140 }
141 }
142
143 }