001: /*
002: * MessageDialog.java
003: *
004: * Copyright (C) 1999-2003 Peter Graves
005: * $Id: MessageDialog.java,v 1.3 2003/07/23 16:11:47 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import java.awt.Graphics;
025: import java.awt.event.KeyEvent;
026: import java.awt.event.WindowEvent;
027: import javax.swing.BorderFactory;
028: import javax.swing.Box;
029: import javax.swing.JTextArea;
030: import javax.swing.UIManager;
031:
032: public class MessageDialog extends AbstractDialog {
033: private Editor editor;
034:
035: protected MessageDialog(Editor editor) {
036: super (editor);
037: this .editor = editor;
038: }
039:
040: public static void showMessageDialog(Editor editor, String text,
041: String title) {
042: MessageDialog d = new MessageDialog(editor != null ? editor
043: : Editor.currentEditor());
044: d.initialize(text, title);
045: if (editor != null)
046: editor.setDefaultCursor();
047: d.show();
048: }
049:
050: public final static void showMessageDialog(String text, String title) {
051: showMessageDialog(Editor.currentEditor(), text, title);
052: }
053:
054: protected void initialize(String text, String title) {
055: setModal(true);
056: setTitle(title);
057: mainPanel.setBorder(BorderFactory.createEmptyBorder(18, 18, 6,
058: 18));
059: TextArea textArea = new TextArea(text);
060: textArea.setAlignmentX(LEFT_ALIGNMENT);
061: textArea.setEditable(false);
062: textArea.setBorder(BorderFactory.createEmptyBorder());
063: textArea.setBackground(UIManager.getColor("control"));
064: mainPanel.add(textArea);
065: mainPanel.add(Box.createVerticalStrut(14));
066: addButtons();
067: pack();
068: centerDialog();
069: if (okButton != null)
070: okButton.requestFocus();
071: }
072:
073: protected void addButtons() {
074: addOK();
075: }
076:
077: public void keyPressed(KeyEvent e) {
078: if (e.getModifiers() == 0) {
079: switch (e.getKeyCode()) {
080: case KeyEvent.VK_ENTER:
081: case KeyEvent.VK_SPACE:
082: enter();
083: break;
084: case KeyEvent.VK_ESCAPE:
085: escape();
086: break;
087: }
088: }
089: }
090:
091: public void windowActivated(WindowEvent e) {
092: requestFocus();
093: }
094:
095: private static class TextArea extends JTextArea {
096: public TextArea(String text) {
097: super (text);
098: }
099:
100: public void paintComponent(Graphics g) {
101: Display.setRenderingHints(g);
102: super.paintComponent(g);
103: }
104: }
105: }
|