001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016:
017: package org.columba.mail.gui.composer.util;
018:
019: import java.awt.BorderLayout;
020: import java.awt.GridLayout;
021: import java.awt.event.ActionEvent;
022: import java.awt.event.ActionListener;
023:
024: import javax.swing.BorderFactory;
025: import javax.swing.JButton;
026: import javax.swing.JDialog;
027: import javax.swing.JLabel;
028: import javax.swing.JPanel;
029: import javax.swing.JTextField;
030: import javax.swing.event.DocumentEvent;
031: import javax.swing.event.DocumentListener;
032:
033: import org.columba.core.gui.base.ButtonWithMnemonic;
034: import org.columba.core.gui.frame.FrameManager;
035: import org.columba.mail.util.MailResourceLoader;
036:
037: /**
038: * @author fdietz
039: */
040: public class SubjectDialog extends JDialog implements ActionListener {
041:
042: private boolean bool = false;
043: private JTextField subjectTextField;
044: private String subject;
045: private JButton okButton;
046:
047: public SubjectDialog() {
048: super (FrameManager.getInstance().getActiveFrame(), true);
049: }
050:
051: public void showDialog(String subject) {
052: this .subject = subject;
053:
054: JLabel subjectLabel = new JLabel("Subject:");
055:
056: okButton = new ButtonWithMnemonic(MailResourceLoader.getString(
057: "global", "ok"));
058: okButton.addActionListener(this );
059: okButton.setActionCommand("OK");
060: okButton.setSelected(true);
061:
062: subjectTextField = new JTextField(subject, 30);
063: subjectTextField.setCaretPosition(subject.length());
064: subjectTextField.selectAll();
065: subjectTextField.getDocument().addDocumentListener(
066: new MyDocumentListener());
067:
068: //TODO (@author fdietz): i18n
069: setTitle("Enter Subject...");
070:
071: //dialog.getContentPane().setLayout( new BoxLayout( dialog.getContentPane(), BoxLayout.Y_AXIS ) );
072: getContentPane().setLayout(new BorderLayout());
073:
074: JPanel centerPanel = new JPanel();
075: centerPanel.setLayout(new BorderLayout());
076:
077: //centerPanel.setLayout( new BoxLayout( centerPanel, BoxLayout.Y_AXIS ) );
078: centerPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5,
079: 5));
080:
081: /*
082: TitledBorder etched = javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), " Login ");
083: centerPanel.setBorder( etched );
084: */
085: JPanel panel = new JPanel();
086:
087: panel.setLayout(new BorderLayout());
088:
089: JPanel leftInformationPanel = new JPanel();
090: leftInformationPanel.setBorder(BorderFactory.createEmptyBorder(
091: 0, 5, 5, 5));
092: leftInformationPanel.setLayout(new GridLayout(0, 1, 50, 5));
093: panel.add(leftInformationPanel, BorderLayout.CENTER);
094:
095: JPanel rightInformationPanel = new JPanel();
096: rightInformationPanel.setLayout(new GridLayout(0, 1, 50, 5));
097: rightInformationPanel.setBorder(BorderFactory
098: .createEmptyBorder(0, 5, 5, 5));
099: panel.add(rightInformationPanel, BorderLayout.EAST);
100:
101: leftInformationPanel.add(subjectLabel);
102: rightInformationPanel.add(subjectTextField);
103:
104: //centerPanel.add( Box.createRigidArea( new java.awt.Dimension(0,5) ) );
105: centerPanel.add(panel, BorderLayout.NORTH);
106:
107: /*
108: JPanel panel = new JPanel();
109: panel.setLayout( new BoxLayout( panel, BoxLayout.X_AXIS ) );
110: panel.add( hostLabel );
111: centerPanel.add( panel );
112: */
113: //centerPanel.add( Box.createRigidArea( new java.awt.Dimension(0,5) ) );
114: //centerPanel.add( Box.createRigidArea( new java.awt.Dimension(0,5) ) );
115: getContentPane().add(centerPanel, BorderLayout.CENTER);
116:
117: JPanel bottomPanel = new JPanel();
118: bottomPanel.setLayout(new BorderLayout());
119:
120: JPanel buttonPanel = new JPanel();
121: buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5,
122: 5));
123: buttonPanel.setLayout(new GridLayout(1, 2, 10, 0));
124: buttonPanel.add(okButton);
125:
126: bottomPanel.add(buttonPanel, BorderLayout.EAST);
127:
128: getContentPane().add(bottomPanel, BorderLayout.SOUTH);
129:
130: pack();
131:
132: getRootPane().setDefaultButton(okButton);
133:
134: setLocationRelativeTo(null);
135: setVisible(true);
136: }
137:
138: public boolean success() {
139: return bool;
140: }
141:
142: public String getSubject() {
143: return subject;
144: }
145:
146: public void actionPerformed(ActionEvent e) {
147: String action = e.getActionCommand();
148:
149: if (action.equals("OK")) {
150: subject = subjectTextField.getText();
151:
152: bool = true;
153:
154: dispose();
155: }
156: }
157:
158: class MyDocumentListener implements DocumentListener {
159: public void insertUpdate(DocumentEvent e) {
160: updateButton();
161: }
162:
163: public void removeUpdate(DocumentEvent e) {
164: updateButton();
165: }
166:
167: protected void updateButton() {
168: okButton
169: .setEnabled(subjectTextField.getText().length() > 0);
170: }
171:
172: public void changedUpdate(DocumentEvent e) {
173: //Plain text components don't fire these events
174: }
175: }
176: }
|