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