1 17 package org.columba.mail.gui.composer.util; 18 19 import java.awt.BorderLayout ; 20 import java.awt.GridLayout ; 21 import java.awt.event.ActionEvent ; 22 import java.awt.event.ActionListener ; 23 24 import javax.swing.BorderFactory ; 25 import javax.swing.JButton ; 26 import javax.swing.JDialog ; 27 import javax.swing.JLabel ; 28 import javax.swing.JPanel ; 29 import javax.swing.JTextField ; 30 import javax.swing.event.DocumentEvent ; 31 import javax.swing.event.DocumentListener ; 32 33 import org.columba.core.gui.base.ButtonWithMnemonic; 34 import org.columba.core.gui.frame.FrameManager; 35 import org.columba.mail.util.MailResourceLoader; 36 37 40 public class SubjectDialog extends JDialog implements ActionListener { 41 42 private boolean bool = false; 43 private JTextField subjectTextField; 44 private String subject; 45 private JButton okButton; 46 47 public SubjectDialog() { 48 super(FrameManager.getInstance().getActiveFrame(), true); 49 } 50 51 public void showDialog(String subject) { 52 this.subject = subject; 53 54 JLabel subjectLabel = new JLabel ("Subject:"); 55 56 okButton = new ButtonWithMnemonic(MailResourceLoader.getString( 57 "global", "ok")); 58 okButton.addActionListener(this); 59 okButton.setActionCommand("OK"); 60 okButton.setSelected(true); 61 62 subjectTextField = new JTextField (subject, 30); 63 subjectTextField.setCaretPosition(subject.length()); 64 subjectTextField.selectAll(); 65 subjectTextField.getDocument().addDocumentListener(new MyDocumentListener()); 66 67 setTitle("Enter Subject..."); 69 70 getContentPane().setLayout(new BorderLayout ()); 72 73 JPanel centerPanel = new JPanel (); 74 centerPanel.setLayout(new BorderLayout ()); 75 76 centerPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 78 79 83 JPanel panel = new JPanel (); 84 85 panel.setLayout(new BorderLayout ()); 86 87 JPanel leftInformationPanel = new JPanel (); 88 leftInformationPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 89 5)); 90 leftInformationPanel.setLayout(new GridLayout (0, 1, 50, 5)); 91 panel.add(leftInformationPanel, BorderLayout.CENTER); 92 93 JPanel rightInformationPanel = new JPanel (); 94 rightInformationPanel.setLayout(new GridLayout (0, 1, 50, 5)); 95 rightInformationPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 96 5, 5)); 97 panel.add(rightInformationPanel, BorderLayout.EAST); 98 99 leftInformationPanel.add(subjectLabel); 100 rightInformationPanel.add(subjectTextField); 101 102 centerPanel.add(panel, BorderLayout.NORTH); 104 105 111 getContentPane().add(centerPanel, BorderLayout.CENTER); 114 115 JPanel bottomPanel = new JPanel (); 116 bottomPanel.setLayout(new BorderLayout ()); 117 118 JPanel buttonPanel = new JPanel (); 119 buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 120 buttonPanel.setLayout(new GridLayout (1, 2, 10, 0)); 121 buttonPanel.add(okButton); 122 123 bottomPanel.add(buttonPanel, BorderLayout.EAST); 124 125 getContentPane().add(bottomPanel, BorderLayout.SOUTH); 126 127 pack(); 128 129 getRootPane().setDefaultButton(okButton); 130 131 setLocationRelativeTo(null); 132 setVisible(true); 133 } 134 135 public boolean success() { 136 return bool; 137 } 138 139 public String getSubject() { 140 return subject; 141 } 142 143 public void actionPerformed(ActionEvent e) { 144 String action = e.getActionCommand(); 145 146 if (action.equals("OK")) { 147 subject = subjectTextField.getText(); 148 149 bool = true; 150 151 dispose(); 152 } 153 } 154 155 class MyDocumentListener implements DocumentListener { 156 public void insertUpdate(DocumentEvent e) { 157 updateButton(); 158 } 159 160 public void removeUpdate(DocumentEvent e) { 161 updateButton(); 162 } 163 164 protected void updateButton() { 165 okButton.setEnabled(subjectTextField.getText().length() > 0); 166 } 167 168 public void changedUpdate(DocumentEvent e) { 169 } 171 } 172 } 173 | Popular Tags |