001: /*
002: * TextAreaDialog.java - A dialog box with a text area
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 2001, 2003 Slava Pestov
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit.gui;
024:
025: //{{{ Imports
026: import javax.swing.*;
027: import javax.swing.border.*;
028: import java.awt.*;
029: import java.awt.event.*;
030: import org.gjt.sp.jedit.*;
031:
032: //}}}
033:
034: public class TextAreaDialog extends EnhancedDialog {
035: //{{{ TextAreaDialog constructor
036: public TextAreaDialog(Frame frame, String title, String caption,
037: Icon icon, String text) {
038: super (frame, title, true);
039:
040: init(caption, icon, text);
041: } //}}}
042:
043: //{{{ TextAreaDialog constructor
044: public TextAreaDialog(Frame frame, String name, Throwable t) {
045: this (frame, jEdit.getProperty(name + ".title"), jEdit
046: .getProperty(name + ".message"), UIManager
047: .getIcon("OptionPane.errorIcon"), MiscUtilities
048: .throwableToString(t));
049: } //}}}
050:
051: //{{{ TextAreaDialog constructor
052: public TextAreaDialog(Dialog frame, String title, String caption,
053: Icon icon, String text) {
054: super (frame, title, true);
055:
056: init(caption, icon, text);
057: } //}}}
058:
059: //{{{ TextAreaDialog constructor
060: public TextAreaDialog(Dialog frame, String name, Throwable t) {
061: this (frame, jEdit.getProperty(name + ".title"), jEdit
062: .getProperty(name + ".message"), UIManager
063: .getIcon("OptionPane.errorIcon"), MiscUtilities
064: .throwableToString(t));
065: } //}}}
066:
067: //{{{ init() method
068: private void init(String caption, Icon icon, String text) {
069: JPanel content = new JPanel(new BorderLayout(12, 12));
070: content.setBorder(new EmptyBorder(12, 12, 12, 12));
071: setContentPane(content);
072:
073: Box iconBox = new Box(BoxLayout.Y_AXIS);
074: iconBox.add(new JLabel(icon));
075: iconBox.add(Box.createGlue());
076: content.add(BorderLayout.WEST, iconBox);
077:
078: JPanel centerPanel = new JPanel(new BorderLayout(6, 6));
079:
080: centerPanel.add(BorderLayout.NORTH, GUIUtilities
081: .createMultilineLabel(caption));
082:
083: JTextArea textArea = new JTextArea(10, 80);
084:
085: textArea.setText(text);
086: textArea.setLineWrap(true);
087: textArea.setCaretPosition(0);
088: centerPanel.add(BorderLayout.CENTER, new JScrollPane(textArea));
089:
090: content.add(BorderLayout.CENTER, centerPanel);
091:
092: Box buttons = new Box(BoxLayout.X_AXIS);
093: buttons.add(Box.createGlue());
094: JButton ok = new JButton(jEdit.getProperty("common.ok"));
095: ok.addActionListener(new ActionHandler());
096: buttons.add(ok);
097: buttons.add(Box.createGlue());
098: content.add(BorderLayout.SOUTH, buttons);
099:
100: getRootPane().setDefaultButton(ok);
101:
102: pack();
103: setLocationRelativeTo(getParent());
104: setVisible(true);
105: } //}}}
106:
107: //{{{ ok() method
108: public void ok() {
109: dispose();
110: } //}}}
111:
112: //{{{ cancel() method
113: public void cancel() {
114: dispose();
115: } //}}}
116:
117: //{{{ ActionHandler class
118: class ActionHandler implements ActionListener {
119: //{{{ actionPerformed() method
120: public void actionPerformed(ActionEvent evt) {
121: dispose();
122: } //}}}
123: } //}}}
124: }
|