001: /*
002: * (C) Copyright SimulacraMedia 2003. All rights reserved.
003: *
004: * Created on Dec 9, 2004
005: *
006: */
007: package org.openharmonise.him.configuration;
008:
009: import java.awt.BorderLayout;
010: import java.awt.Color;
011: import java.awt.Component;
012: import java.awt.Container;
013: import java.awt.Dialog;
014: import java.awt.Dimension;
015: import java.awt.Font;
016: import java.awt.Frame;
017: import java.awt.GraphicsConfiguration;
018: import java.awt.HeadlessException;
019: import java.awt.LayoutManager;
020: import java.awt.event.ActionEvent;
021: import java.awt.event.ActionListener;
022:
023: import javax.swing.JButton;
024: import javax.swing.JDialog;
025: import javax.swing.JFrame;
026: import javax.swing.JLabel;
027: import javax.swing.JPanel;
028: import javax.swing.JTextField;
029: import javax.swing.JComboBox;
030:
031: /**
032: * Dialog to prompt the user for an email address and choice of
033: * Server content type (Content, Metadata or All).
034: * @author MATT TREANOR
035: * @version $Revision: 1.2 $
036: *
037: */
038: public class EmailDialog extends JDialog implements LayoutManager,
039: ActionListener {
040:
041: private JTextField m_emailTextField;
042: private JPanel m_panel;
043: private JButton m_okButton;
044: private JButton m_cancelButton;
045: private JComboBox m_comboBox;
046: private JLabel m_labelEmail;
047: private JLabel m_labelType;
048: public final String TYPE_ALL = "All";
049: public final String TYPE_CONTENTS = "Content";
050: public final String TYPE_METADATA = "Metadata";
051: private String m_sEmailAddress = null;
052:
053: /**
054: * @param owner
055: * @throws java.awt.HeadlessException
056: */
057: public EmailDialog(Frame owner) throws HeadlessException {
058: super (owner, true);
059: setup();
060: }
061:
062: private void setup() {
063: this .setTitle("Export content");
064: this .setSize(550, 100);
065: this .setResizable(false);
066:
067: m_panel = new JPanel();
068: m_panel.setSize(600, 80);
069: getContentPane().add(m_panel);
070: m_panel.setBackground(new Color(224, 224, 224));
071: getContentPane().setLayout(new BorderLayout());
072: m_panel.setLayout(this );
073:
074: Font font = new Font("Dialog", Font.PLAIN, 11);
075:
076: m_emailTextField = new JTextField(30);
077: m_emailTextField.setFont(font);
078:
079: m_panel.add(m_emailTextField);
080:
081: int x = this .getGraphicsConfiguration().getBounds().width / 2
082: - this .getSize().width / 2;
083: int y = this .getGraphicsConfiguration().getBounds().height / 2
084: - this .getSize().height / 2;
085:
086: this .setLocation(x, y);
087:
088: m_okButton = new JButton("OK");
089: m_okButton.setActionCommand("OK");
090: m_okButton.setFont(font);
091: m_okButton.addActionListener(this );
092:
093: m_cancelButton = new JButton("Cancel");
094: m_cancelButton.setActionCommand("Cancel");
095: m_cancelButton.setFont(font);
096: m_cancelButton.addActionListener(this );
097:
098: //getContentPane().add(m_okButton);
099: m_panel.add(m_okButton);
100: m_panel.add(m_cancelButton);
101:
102: m_comboBox = new JComboBox();
103: m_comboBox.setFont(font);
104: m_comboBox.addItem(TYPE_ALL);
105: m_comboBox.addItem(TYPE_CONTENTS);
106: m_comboBox.addItem(TYPE_METADATA);
107:
108: m_panel.add(m_comboBox);
109:
110: m_labelEmail = new JLabel("Email address");
111: m_labelEmail.setFont(font);
112:
113: m_panel.add(m_labelEmail);
114:
115: m_labelType = new JLabel("Export");
116: m_labelType.setFont(font);
117:
118: m_panel.add(m_labelType);
119: }
120:
121: /* (non-Javadoc)
122: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
123: */
124: public void layoutContainer(Container parent) {
125: int x = 10;
126: int yLabel = 10;
127: int yField = 35;
128:
129: m_labelEmail.setSize(200, 20);
130: m_labelEmail.setLocation(x, yLabel);
131:
132: m_emailTextField.setSize(250, 20);
133: m_emailTextField.setLocation(x, yField);
134: x += m_emailTextField.getWidth() + 20;
135:
136: m_labelType.setSize(90, 20);
137: m_labelType.setLocation(x, yLabel);
138:
139: m_comboBox.setSize(90, 20);
140: m_comboBox.setLocation(x, yField);
141: x += m_comboBox.getWidth() + 20;
142:
143: m_okButton.setSize(50, 20);
144: m_okButton.setLocation(x, yField);
145: x += m_okButton.getWidth() + 20;
146:
147: m_cancelButton.setSize(70, 20);
148: m_cancelButton.setLocation(x, yField);
149: }
150:
151: public String getEmail() {
152: return m_sEmailAddress;
153: }
154:
155: public String getType() {
156: return (String) m_comboBox.getSelectedItem();
157: }
158:
159: /* (non-Javadoc)
160: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
161: */
162: public void removeLayoutComponent(Component comp) {
163: // TODO Auto-generated method stub
164:
165: }
166:
167: /* (non-Javadoc)
168: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
169: */
170: public void addLayoutComponent(String name, Component comp) {
171: // TODO Auto-generated method stub
172:
173: }
174:
175: /* (non-Javadoc)
176: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
177: */
178: public Dimension minimumLayoutSize(Container parent) {
179: // TODO Auto-generated method stub
180: return null;
181: }
182:
183: /* (non-Javadoc)
184: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
185: */
186: public Dimension preferredLayoutSize(Container parent) {
187: // TODO Auto-generated method stub
188: return null;
189: }
190:
191: public static void main(String[] args) {
192: JFrame frame = new JFrame();
193: frame.setTitle("Export Content");
194: frame.setVisible(true);
195: EmailDialog email = new EmailDialog(frame);
196: email.show();
197:
198: System.exit(0);
199: }
200:
201: /* (non-Javadoc)
202: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
203: */
204: public void actionPerformed(ActionEvent e) {
205: if (e.getActionCommand().equals("OK")) {
206: if (isValidEmail()) {
207: m_sEmailAddress = m_emailTextField.getText();
208: this .getParent().setVisible(false);
209: this .hide();
210: } else {
211: m_labelEmail.setForeground(Color.RED);
212: m_labelEmail
213: .setText("Please enter a valid email address");
214: }
215: } else {
216: this .getParent().setVisible(false);
217: this .hide();
218: }
219: }
220:
221: /**
222: * @return
223: */
224: private boolean isValidEmail() {
225: String sEmail = m_emailTextField.getText();
226: int indexAt = sEmail.indexOf("@");
227: int indexPt = sEmail.lastIndexOf(".");
228: if (indexAt > 1 && indexPt > indexAt) {
229: return true;
230: } else {
231: return false;
232: }
233: }
234: }
|