Commit | Line | Data |
---|---|---|
c2da4d40 JL |
1 | /* |
2 | GNU Lesser General Public License | |
3 | ||
4 | SimpleInfoDialog | |
6ce136da | 5 | Copyright (C) 2000 Howard Kistler |
c2da4d40 JL |
6 | |
7 | This library is free software; you can redistribute it and/or | |
8 | modify it under the terms of the GNU Lesser General Public | |
9 | License as published by the Free Software Foundation; either | |
10 | version 2.1 of the License, or (at your option) any later version. | |
11 | ||
12 | This library is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public | |
18 | License along with this library; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | */ | |
21 | ||
22 | package com.hexidec.ekit.component; | |
23 | ||
24 | import java.awt.Frame; | |
25 | import java.awt.event.WindowAdapter; | |
26 | import java.awt.event.WindowEvent; | |
27 | import java.beans.PropertyChangeEvent; | |
28 | import java.beans.PropertyChangeListener; | |
29 | import javax.swing.JDialog; | |
30 | import javax.swing.JOptionPane; | |
31 | ||
32 | import com.hexidec.util.Translatrix; | |
33 | ||
34 | /** Class for providing a dialog that lets the user specify values for tag attributes. | |
35 | */ | |
36 | public 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 | } |