1 package hayashi.yuu.tools.mail.gui;
\r
2 import hayashi.yuu.tools.properties.Properties;
\r
3 import hayashi.yuu.tools.properties.PropertyItem;
\r
4 import hayashi.yuu.tools.mail.SendMail;
\r
5 import hayashi.yuu.tools.mail.SiteData;
\r
7 import java.awt.BorderLayout;
\r
8 import java.awt.FlowLayout;
\r
9 import java.awt.GridLayout;
\r
10 import java.awt.Rectangle;
\r
11 import java.awt.Toolkit;
\r
12 import java.awt.event.WindowEvent;
\r
13 import java.awt.event.WindowListener;
\r
14 import java.io.FileInputStream;
\r
15 import java.io.FileNotFoundException;
\r
16 import java.io.FileOutputStream;
\r
17 import java.io.IOException;
\r
18 import java.util.logging.Logger;
\r
20 import javax.swing.BorderFactory;
\r
21 import javax.swing.JButton;
\r
22 import javax.swing.JComponent;
\r
23 import javax.swing.JDialog;
\r
24 import javax.swing.JFrame;
\r
25 import javax.swing.JLabel;
\r
26 import javax.swing.JOptionPane;
\r
27 import javax.swing.JPanel;
\r
28 import javax.swing.JTextArea;
\r
32 * <p>アプリケーション設定を行うモーダルダイアログフォーム</p>
\r
45 @SuppressWarnings("serial")
\r
46 public class SettingDialog extends JDialog implements WindowListener
\r
52 public static Properties prop;
\r
53 public static SetupMailServer mailServerPanel;
\r
54 public static MailAddrPanel mailAddrPanel;
\r
55 public static String fileName;
\r
56 static Logger logger;
\r
62 public SettingDialog(JFrame parent, boolean modal, String propertiesFileName, Logger logger) throws FileNotFoundException, IOException {
\r
63 super(parent, modal);
\r
64 SettingDialog.logger = logger;
\r
65 SettingDialog.fileName = propertiesFileName;
\r
68 prop = new Properties();
\r
69 prop.load(new FileInputStream(propertiesFileName));
\r
71 addWindowListener(this);
\r
72 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
\r
74 this.parent = parent;
\r
76 getContentPane().setLayout(new BorderLayout());
\r
77 setSize(420, SetupMailServer.CATEGORY_HEIGHT + MailAddrPanel.CATEGORY_HEIGHT + (PropertyItem.LINE_HEIGHT * 9));
\r
82 JPanel topPanel = new JPanel();
\r
83 label1 = new JLabel("メール送信 設定", JLabel.CENTER);
\r
84 label1.setBounds(10,10,340,20);
\r
85 topPanel.add(label1);
\r
86 getContentPane().add(topPanel, BorderLayout.NORTH);
\r
89 * カテゴリ:[ メールサーバーの設定 ]
\r
91 mailServerPanel = new SetupMailServer(prop);
\r
94 * カテゴリ:[ メールの配信先設定 ]
\r
96 mailAddrPanel = new MailAddrPanel(prop);
\r
101 JPanel mainPanel = new JPanel();
\r
102 mainPanel.setLayout(new FlowLayout());
\r
103 mainPanel.add(makePanel("メールサーバーの設定", mailServerPanel));
\r
104 mainPanel.add(makePanel("メールの配信先", mailAddrPanel));
\r
105 getContentPane().add(mainPanel, BorderLayout.CENTER);
\r
108 * [OK]ボタン : このダイアログウインドウを閉じる
\r
110 JButton saveButton = new JButton("保存");
\r
111 saveButton.setBounds(145,65,66,27);
\r
112 saveButton.addActionListener(new java.awt.event.ActionListener() {
\r
113 public void actionPerformed(java.awt.event.ActionEvent evt) {
\r
115 SettingDialog.prop.store(new FileOutputStream(SettingDialog.fileName), "SendMail GUI");
\r
117 catch (FileNotFoundException e) {
\r
118 // TODO Auto-generated catch block
\r
119 e.printStackTrace();
\r
121 catch (IOException e) {
\r
122 // TODO Auto-generated catch block
\r
123 e.printStackTrace();
\r
126 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(SettingDialog.this, WindowEvent.WINDOW_CLOSING));
\r
132 * [Cancel]ボタン : このダイアログウインドウを閉じる
\r
134 JButton cancelButton = new JButton("取消");
\r
135 cancelButton.setBounds(145,65,66,27);
\r
136 cancelButton.addActionListener(new java.awt.event.ActionListener() {
\r
137 public void actionPerformed(java.awt.event.ActionEvent evt) {
\r
138 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(SettingDialog.this, WindowEvent.WINDOW_CLOSING));
\r
144 * [テスト送信]ボタン : テストメールを送信する
\r
146 JButton testButton = new JButton("テスト送信");
\r
147 testButton.setBounds(145,65,66,27);
\r
148 testButton.addActionListener(new java.awt.event.ActionListener() {
\r
149 public void actionPerformed(java.awt.event.ActionEvent evt) {
\r
150 SiteData siteData = SettingDialog.mailServerPanel.getSiteData();
\r
151 SettingDialog.mailAddrPanel.getSiteData(siteData);
\r
152 SendMail mail = new SendMail(siteData);
\r
153 mail.setSubject("[SendMail] メール送信テスト");
\r
154 mail.setContent("このメールは[SendMail]からのメール送信テストです。");
\r
157 SettingDialog.logger.info("メールを送信しました。");
\r
158 JOptionPane.showMessageDialog(SendMailGUI.mainFrame, "メールを送信しました。", "成功", JOptionPane.INFORMATION_MESSAGE);
\r
159 } catch (Exception e) {
\r
160 e.printStackTrace();
\r
161 SettingDialog.logger.warning("メール送信に失敗しました。");
\r
162 JOptionPane.showMessageDialog(SendMailGUI.mainFrame, "メールを送信できませんでした。", "失敗", JOptionPane.ERROR_MESSAGE);
\r
170 JPanel bottomPanel = new JPanel();
\r
171 bottomPanel.add(saveButton);
\r
172 bottomPanel.add(cancelButton);
\r
173 bottomPanel.add(testButton);
\r
174 getContentPane().add(bottomPanel, BorderLayout.SOUTH);
\r
183 private JPanel makePanel(String title, JComponent compo) {
\r
184 JPanel p = new JPanel(new GridLayout(1,1));
\r
185 p.setBorder(BorderFactory.createTitledBorder(title));
\r
190 public String getPropertiesFilename() {
\r
195 * Shows or hides the component depending on the boolean flag b.
\r
196 * @param b if true, show the component; otherwise, hide the component.
\r
197 * @see java.awt.Component#isVisible
\r
199 public void setVisible(boolean b) {
\r
201 Rectangle bounds = getParent().getBounds();
\r
202 Rectangle abounds = getBounds();
\r
203 setLocation(bounds.x + (bounds.width - abounds.width)/ 2, bounds.y + (bounds.height - abounds.height)/2);
\r
205 super.setVisible(b);
\r
208 public void windowClosed(WindowEvent e) {
\r
212 public void windowActivated(WindowEvent arg0) {
\r
215 public void windowClosing(WindowEvent arg0) {
\r
219 public void windowDeactivated(WindowEvent arg0) {
\r
222 public void windowDeiconified(WindowEvent arg0) {
\r
225 public void windowIconified(WindowEvent arg0) {
\r
228 public void windowOpened(WindowEvent arg0) {
\r