KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > gui > TextAreaDialog


1 /*
2  * TextAreaDialog.java - A dialog box with a text area
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 2001, 2003 Slava Pestov
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */

22
23 package org.gjt.sp.jedit.gui;
24
25 //{{{ Imports
26
import javax.swing.*;
27 import javax.swing.border.*;
28 import java.awt.*;
29 import java.awt.event.*;
30 import org.gjt.sp.jedit.*;
31 //}}}
32

33 public class TextAreaDialog extends EnhancedDialog
34 {
35     //{{{ TextAreaDialog constructor
36
public TextAreaDialog(Frame frame, String JavaDoc title, String JavaDoc caption,
37         Icon icon, String JavaDoc text)
38     {
39         super(frame,title,true);
40
41         init(caption,icon,text);
42     } //}}}
43

44     //{{{ TextAreaDialog constructor
45
public TextAreaDialog(Frame frame, String JavaDoc name, Throwable JavaDoc t)
46     {
47         this(frame,jEdit.getProperty(name + ".title"),
48             jEdit.getProperty(name + ".message"),
49             UIManager.getIcon("OptionPane.errorIcon"),
50             MiscUtilities.throwableToString(t));
51     } //}}}
52

53     //{{{ TextAreaDialog constructor
54
public TextAreaDialog(Dialog frame, String JavaDoc title, String JavaDoc caption,
55         Icon icon, String JavaDoc text)
56     {
57         super(frame,title,true);
58
59         init(caption,icon,text);
60     } //}}}
61

62     //{{{ TextAreaDialog constructor
63
public TextAreaDialog(Dialog frame, String JavaDoc name, Throwable JavaDoc t)
64     {
65         this(frame,jEdit.getProperty(name + ".title"),
66             jEdit.getProperty(name + ".message"),
67             UIManager.getIcon("OptionPane.errorIcon"),
68             MiscUtilities.throwableToString(t));
69     } //}}}
70

71     //{{{ init() method
72
private void init(String JavaDoc caption,
73         Icon icon, String JavaDoc text)
74     {
75         JPanel content = new JPanel(new BorderLayout(12,12));
76         content.setBorder(new EmptyBorder(12,12,12,12));
77         setContentPane(content);
78
79         Box iconBox = new Box(BoxLayout.Y_AXIS);
80         iconBox.add(new JLabel(icon));
81         iconBox.add(Box.createGlue());
82         content.add(BorderLayout.WEST,iconBox);
83
84         JPanel centerPanel = new JPanel(new BorderLayout(6,6));
85
86         centerPanel.add(BorderLayout.NORTH,
87             GUIUtilities.createMultilineLabel(caption));
88
89         JTextArea textArea = new JTextArea(10,80);
90
91         textArea.setText(text);
92         textArea.setLineWrap(true);
93         textArea.setCaretPosition(0);
94         centerPanel.add(BorderLayout.CENTER,new JScrollPane(textArea));
95
96         content.add(BorderLayout.CENTER,centerPanel);
97
98         Box buttons = new Box(BoxLayout.X_AXIS);
99         buttons.add(Box.createGlue());
100         JButton ok = new JButton(jEdit.getProperty("common.ok"));
101         ok.addActionListener(new ActionHandler());
102         buttons.add(ok);
103         buttons.add(Box.createGlue());
104         content.add(BorderLayout.SOUTH,buttons);
105
106         getRootPane().setDefaultButton(ok);
107
108         pack();
109         setLocationRelativeTo(getParent());
110         setVisible(true);
111     } //}}}
112

113     //{{{ ok() method
114
public void ok()
115     {
116         dispose();
117     } //}}}
118

119     //{{{ cancel() method
120
public void cancel()
121     {
122         dispose();
123     } //}}}
124

125     //{{{ ActionHandler class
126
class ActionHandler implements ActionListener
127     {
128         //{{{ actionPerformed() method
129
public void actionPerformed(ActionEvent evt)
130         {
131             dispose();
132         } //}}}
133
} //}}}
134
}
135
Popular Tags