001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.cleverphl.gui;
025:
026: import jacareto.cleverphl.CleverPHL;
027:
028: import java.awt.BorderLayout;
029: import java.awt.Dialog;
030: import java.awt.Frame;
031: import java.awt.Point;
032: import java.awt.Window;
033: import java.awt.event.ActionEvent;
034: import java.awt.event.ActionListener;
035:
036: import javax.swing.JButton;
037: import javax.swing.JDialog;
038: import javax.swing.JLabel;
039: import javax.swing.JPanel;
040: import javax.swing.border.EmptyBorder;
041:
042: /**
043: * A Message Dialog with a line of text (the message) and a button. Use this dialog if you just
044: * want to show a message to the user.
045: *
046: * <p>
047: * This dialog is modal and not resizable. It is set to the middle of the screen.
048: * </p>
049: *
050: * <p>
051: * When the user presses the button, the message dialog will be closed.
052: * </p>
053: *
054: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
055: * @version 0.9
056: */
057: public class CleverPHLMsgDialog extends JDialog implements
058: ActionListener {
059: /**
060: * Creates a new message dialog with a specified title, owner frame, message and button text.
061: * The dialog is set visible in this constructor.
062: *
063: * @param cleverPHL the CleverPHL instance
064: * @param owner The frame which is the owner of this dialog
065: * @param title The title of the dialog
066: * @param message The message
067: * @param buttonText The text of the button
068: */
069: public CleverPHLMsgDialog(CleverPHL cleverPHL, Frame owner,
070: String title, String message, String buttonText) {
071: super (owner, title, true);
072: setLocation(owner);
073: create(message, buttonText);
074: }
075:
076: /**
077: * Creates a new message dialog with a specified title, owner dialog, message and the specified
078: * button text. The dialog is set visible in this constructor.
079: *
080: * @param cleverPHL the CleverPHL instance
081: * @param owner The frame which is the owner of this dialog
082: * @param title The title of the frame
083: * @param message The message
084: * @param buttonText The text of the button
085: */
086: public CleverPHLMsgDialog(CleverPHL cleverPHL, Dialog owner,
087: String title, String message, String buttonText) {
088: super (owner, title, true);
089: setLocation(owner);
090: create(message, buttonText);
091: }
092:
093: /**
094: * Creates the components and the layout of the dialog.
095: *
096: * @param message the message to be displayed
097: * @param buttonText the text of the button
098: */
099: private void create(String message, String buttonText) {
100: // creating the button
101: JButton button = new JButton(buttonText);
102: button.addActionListener(this );
103:
104: getContentPane().setLayout(new BorderLayout());
105:
106: JPanel labelPanel = new JPanel();
107: labelPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
108: labelPanel.add(new JLabel(message));
109: getContentPane().add(labelPanel, BorderLayout.NORTH);
110:
111: JPanel buttonPanel = new JPanel();
112: buttonPanel.add(button);
113: buttonPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
114: getContentPane().add(buttonPanel, BorderLayout.SOUTH);
115: pack();
116: setResizable(false);
117: setVisible(true);
118: }
119:
120: /**
121: * Sets the location of the message dialog relativ to the owners position
122: *
123: * @param owner the owner
124: */
125: public void setLocation(Window owner) {
126: Point ownerLoc = owner.getLocation();
127: setLocation(((int) ownerLoc.getX()) + 20, ((int) ownerLoc
128: .getY()) + 20);
129: }
130:
131: /**
132: * Invoked when the button was pressed.
133: *
134: * @param e The action event
135: */
136: public void actionPerformed(ActionEvent e) {
137: dispose();
138: }
139: }
|