1 22 23 package org.gjt.sp.jedit.gui; 24 25 import javax.swing.*; 27 import javax.swing.border.*; 28 import java.awt.*; 29 import java.awt.event.*; 30 import org.gjt.sp.jedit.*; 31 33 public class TextAreaDialog extends EnhancedDialog 34 { 35 public TextAreaDialog(Frame frame, String title, String caption, 37 Icon icon, String text) 38 { 39 super(frame,title,true); 40 41 init(caption,icon,text); 42 } 44 public TextAreaDialog(Frame frame, String name, Throwable t) 46 { 47 this(frame,jEdit.getProperty(name + ".title"), 48 jEdit.getProperty(name + ".message"), 49 UIManager.getIcon("OptionPane.errorIcon"), 50 MiscUtilities.throwableToString(t)); 51 } 53 public TextAreaDialog(Dialog frame, String title, String caption, 55 Icon icon, String text) 56 { 57 super(frame,title,true); 58 59 init(caption,icon,text); 60 } 62 public TextAreaDialog(Dialog frame, String name, Throwable t) 64 { 65 this(frame,jEdit.getProperty(name + ".title"), 66 jEdit.getProperty(name + ".message"), 67 UIManager.getIcon("OptionPane.errorIcon"), 68 MiscUtilities.throwableToString(t)); 69 } 71 private void init(String caption, 73 Icon icon, String 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 } 113 public void ok() 115 { 116 dispose(); 117 } 119 public void cancel() 121 { 122 dispose(); 123 } 125 class ActionHandler implements ActionListener 127 { 128 public void actionPerformed(ActionEvent evt) 130 { 131 dispose(); 132 } } } 135 | Popular Tags |