Import of Ekit 0.9h
[old-projects.git] / ekit / com / hexidec / ekit / component / SimpleInfoDialog.java
CommitLineData
c2da4d40
JL
1/*
2GNU Lesser General Public License
3
4SimpleInfoDialog
6ce136da 5Copyright (C) 2000 Howard Kistler
c2da4d40
JL
6
7This library is free software; you can redistribute it and/or
8modify it under the terms of the GNU Lesser General Public
9License as published by the Free Software Foundation; either
10version 2.1 of the License, or (at your option) any later version.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20*/
21
22package com.hexidec.ekit.component;
23
24import java.awt.Frame;
25import java.awt.event.WindowAdapter;
26import java.awt.event.WindowEvent;
27import java.beans.PropertyChangeEvent;
28import java.beans.PropertyChangeListener;
29import javax.swing.JDialog;
30import javax.swing.JOptionPane;
31
32import com.hexidec.util.Translatrix;
33
34/** Class for providing a dialog that lets the user specify values for tag attributes.
35 */
36public class SimpleInfoDialog extends JDialog
37{
38 public static final int ERROR = JOptionPane.ERROR_MESSAGE;
39 public static final int INFO = JOptionPane.INFORMATION_MESSAGE;
40 public static final int WARNING = JOptionPane.WARNING_MESSAGE;
41 public static final int QUESTION = JOptionPane.QUESTION_MESSAGE;
42 public static final int PLAIN = JOptionPane.PLAIN_MESSAGE;
43
44 private JOptionPane jOptionPane;
45 private Object[] buttonLabels;
46 private Integer buttonState = new Integer(JOptionPane.CLOSED_OPTION);
47
48 public SimpleInfoDialog(Frame parent, String title, boolean bModal, String message, int type)
49 {
50 super(parent, title, bModal);
51 if(type == QUESTION)
52 {
53 buttonLabels = new Object[]{ Translatrix.getTranslationString("DialogAccept"), Translatrix.getTranslationString("DialogCancel") };
54 jOptionPane = new JOptionPane(message, type, JOptionPane.OK_CANCEL_OPTION, null, buttonLabels, buttonLabels[0]);
55 }
56 else
57 {
58 buttonLabels = new Object[]{ Translatrix.getTranslationString("DialogClose") };
59 jOptionPane = new JOptionPane(message, type, JOptionPane.DEFAULT_OPTION, null, buttonLabels, buttonLabels[0]);
60 }
61
62 setContentPane(jOptionPane);
63 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
64
65 jOptionPane.addPropertyChangeListener(new PropertyChangeListener()
66 {
67 public void propertyChange(PropertyChangeEvent e)
68 {
69 String prop = e.getPropertyName();
70 if(isVisible() && (e.getSource() == jOptionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY) || prop.equals(JOptionPane.INPUT_VALUE_PROPERTY)))
71 {
72 setVisible(false);
73 }
74 }
75 });
76
77 this.pack();
78 int centerX = (int)(((parent.getSize().getWidth() / 2) + parent.getLocation().getX()) - (this.getSize().getWidth() / 2));
79 int centerY = (int)(((parent.getSize().getHeight() / 2) + parent.getLocation().getY()) - (this.getSize().getHeight() / 2));
80 if(centerX < 0) { centerX = 0; }
81 if(centerY < 0) { centerY = 0; }
82 this.setLocation(centerX, centerY);
83 this.show();
84 }
85
86 public SimpleInfoDialog(Frame parent, String title, boolean bModal, String message)
87 {
88 this(parent, title, bModal, message, WARNING);
89 }
90
91 public String getDecisionValue()
92 {
93 return jOptionPane.getValue().toString();
94 }
95}