Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/hexidec/ekit/dialog/SimpleInfoDialog.java


1   /*
2   GNU Lesser General Public License
3   
4   SimpleInfoDialog
5   Copyright (C) 2000-2002  Howard A Kistler
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.dialog;
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  
39    public static final int ERROR    = JOptionPane.ERROR_MESSAGE;
40    public static final int INFO     = JOptionPane.INFORMATION_MESSAGE;
41    public static final int WARNING  = JOptionPane.WARNING_MESSAGE;
42    public static final int QUESTION = JOptionPane.QUESTION_MESSAGE;
43    public static final int PLAIN    = JOptionPane.PLAIN_MESSAGE;
44  
45    private JOptionPane jOptionPane;
46  
47    public SimpleInfoDialog(Frame parent, String title, boolean bModal, String message, int type)
48    {
49      super(parent, title, bModal);
50      final Object[] buttonLabels = { Translatrix.getTranslationString("DialogClose") };
51      jOptionPane = new JOptionPane(message, type, JOptionPane.DEFAULT_OPTION, null, buttonLabels, buttonLabels[0]);
52  
53      setContentPane(jOptionPane);
54      setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
55  
56      addWindowListener(new WindowAdapter() {
57        public void windowClosing(WindowEvent we)
58        {
59          jOptionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION));
60        }
61      });
62  
63      jOptionPane.addPropertyChangeListener(new PropertyChangeListener() {
64        public void propertyChange(PropertyChangeEvent e)
65        {
66          String prop = e.getPropertyName();
67          if(isVisible() 
68            && (e.getSource() == jOptionPane)
69            && (prop.equals(JOptionPane.VALUE_PROPERTY) || prop.equals(JOptionPane.INPUT_VALUE_PROPERTY)))
70          {
71            setVisible(false);
72          }
73        }
74      });
75  
76      this.pack();
77      int centerX = (int)(((parent.getSize().getWidth()  / 2) + parent.getLocation().getX()) - (this.getSize().getWidth()  / 2));
78      int centerY = (int)(((parent.getSize().getHeight() / 2) + parent.getLocation().getY()) - (this.getSize().getHeight() / 2));
79      if(centerX < 0) { centerX = 0; }
80      if(centerY < 0) { centerY = 0; }
81      this.setLocation(centerX, centerY);
82      this.show();
83    }
84  
85    public SimpleInfoDialog(Frame parent, String title, boolean bModal, String message)
86    {
87      this(parent, title, bModal, message, WARNING);
88    }
89  }