1 33 34 package edu.rice.cs.util.swing; 35 36 import edu.rice.cs.drjava.ui.MainFrame; 37 import java.awt.*; 38 import java.awt.event.*; 39 import javax.swing.*; 40 import javax.swing.border.*; 41 import java.io.Serializable ; 42 43 47 public class ScrollableDialog implements Serializable { 48 49 public static final int DEFAULT_WIDTH = 500; 50 51 public static final int DEFAULT_HEIGHT = 400; 52 53 protected JDialog _dialog; 54 55 protected JTextArea _textArea; 56 57 protected JPanel _buttonPanel; 58 59 66 public ScrollableDialog(JFrame parent, String title, String header, String text) { 67 this(parent, title, header, text, DEFAULT_WIDTH, DEFAULT_HEIGHT); 68 } 69 70 79 public ScrollableDialog(JFrame parent, String title, String header, String text, int width, int height) 80 { 81 _dialog = new JDialog(parent, title, true); 82 Container content = _dialog.getContentPane(); 83 84 content.setLayout(new BorderLayout()); 85 86 _textArea = new JTextArea(); 88 _textArea.setEditable(false); 89 _textArea.setText(text); 90 91 _dialog.setSize(width, height); 93 94 JScrollPane textScroll = 96 new BorderlessScrollPane(_textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 97 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 98 JPanel scrollWrapper = new JPanel(new BorderLayout(0,5)); 99 scrollWrapper.setBorder(new EmptyBorder(5,5,0,5)); 100 scrollWrapper.add(new JLabel(header),BorderLayout.NORTH); 101 scrollWrapper.add(textScroll,BorderLayout.CENTER); 102 JPanel bottomPanel = new JPanel(new BorderLayout()); 103 _buttonPanel = new JPanel(new GridLayout(1,0,5,5)); 104 bottomPanel.add(_buttonPanel,BorderLayout.EAST); 105 bottomPanel.setBorder(new EmptyBorder(5,5,5,5)); 106 _addButtons(); 107 108 content.add(scrollWrapper, BorderLayout.CENTER); 109 content.add(bottomPanel, BorderLayout.SOUTH); 110 111 } 116 117 121 protected void _addButtons() { 122 _buttonPanel.add(new JButton(_okAction)); 123 } 124 125 127 private Action _okAction = new AbstractAction("OK") { 128 public void actionPerformed(ActionEvent e) { 129 _dialog.dispose(); 130 } 131 }; 132 133 137 public void setTextFont(Font f) { 138 _textArea.setFont(f); 139 } 140 141 142 public void show() { 143 MainFrame.setPopupLoc(_dialog, _dialog.getOwner()); 144 _dialog.setVisible(true); 145 } 146 } 147 | Popular Tags |