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