KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > MessageDialog


1 /*
2  * MessageDialog.java
3  *
4  * Copyright (C) 1999-2003 Peter Graves
5  * $Id: MessageDialog.java,v 1.3 2003/07/23 16:11:47 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program 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
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 import java.awt.Graphics JavaDoc;
25 import java.awt.event.KeyEvent JavaDoc;
26 import java.awt.event.WindowEvent JavaDoc;
27 import javax.swing.BorderFactory JavaDoc;
28 import javax.swing.Box JavaDoc;
29 import javax.swing.JTextArea JavaDoc;
30 import javax.swing.UIManager JavaDoc;
31
32 public class MessageDialog extends AbstractDialog
33 {
34     private Editor editor;
35
36     protected MessageDialog(Editor editor)
37     {
38         super(editor);
39         this.editor = editor;
40     }
41
42     public static void showMessageDialog(Editor editor, String JavaDoc text,
43         String JavaDoc title)
44     {
45         MessageDialog d = new MessageDialog(editor != null ? editor :
46             Editor.currentEditor());
47         d.initialize(text, title);
48         if (editor != null)
49             editor.setDefaultCursor();
50         d.show();
51     }
52
53     public final static void showMessageDialog(String JavaDoc text, String JavaDoc title)
54     {
55         showMessageDialog(Editor.currentEditor(), text, title);
56     }
57
58     protected void initialize(String JavaDoc text, String JavaDoc title)
59     {
60         setModal(true);
61         setTitle(title);
62         mainPanel.setBorder(BorderFactory.createEmptyBorder(18, 18, 6, 18));
63         TextArea JavaDoc textArea = new TextArea JavaDoc(text);
64         textArea.setAlignmentX(LEFT_ALIGNMENT);
65         textArea.setEditable(false);
66         textArea.setBorder(BorderFactory.createEmptyBorder());
67         textArea.setBackground(UIManager.getColor("control"));
68         mainPanel.add(textArea);
69         mainPanel.add(Box.createVerticalStrut(14));
70         addButtons();
71         pack();
72         centerDialog();
73         if (okButton != null)
74             okButton.requestFocus();
75     }
76
77     protected void addButtons()
78     {
79         addOK();
80     }
81
82     public void keyPressed(KeyEvent JavaDoc e)
83     {
84         if (e.getModifiers() == 0) {
85             switch (e.getKeyCode()) {
86                 case KeyEvent.VK_ENTER:
87                 case KeyEvent.VK_SPACE:
88                     enter();
89                     break;
90                 case KeyEvent.VK_ESCAPE:
91                     escape();
92                     break;
93             }
94         }
95     }
96
97     public void windowActivated(WindowEvent JavaDoc e)
98     {
99         requestFocus();
100     }
101
102     private static class TextArea extends JTextArea JavaDoc
103     {
104         public TextArea(String JavaDoc text)
105         {
106             super(text);
107         }
108
109         public void paintComponent(Graphics JavaDoc g)
110         {
111             Display.setRenderingHints(g);
112             super.paintComponent(g);
113         }
114     }
115 }
116
Popular Tags