1 package hayashi.yuu.tools.mail.gui;
\r
3 import hayashi.yuu.tools.logger.LoggerFactory;
\r
4 import hayashi.yuu.tools.mail.SendMail;
\r
5 import hayashi.yuu.tools.mail.SiteData;
\r
6 import hayashi.yuu.tools.properties.Encrypt;
\r
9 import java.awt.event.*;
\r
10 import java.io.FileNotFoundException;
\r
11 import java.io.IOException;
\r
12 import java.util.logging.Logger;
\r
14 import javax.swing.JFrame;
\r
15 import javax.swing.JLabel;
\r
16 import javax.swing.JMenu;
\r
17 import javax.swing.JMenuBar;
\r
18 import javax.swing.JMenuItem;
\r
19 import javax.swing.JPanel;
\r
20 import javax.swing.JScrollPane;
\r
21 import javax.swing.JTextArea;
\r
22 import javax.swing.WindowConstants;
\r
25 @SuppressWarnings("serial")
\r
26 public class SendMailGUI extends JFrame implements ActionListener
\r
28 public static SendMailGUI mainFrame;
\r
29 boolean fComponentsAdjusted;
\r
31 JMenuBar mainMenuBar; // [メニュー]
\r
32 JMenu menuFile; // [メニュー]->[ファイル(F)]
\r
33 JMenuItem miSetting; // [メニュー]->[ファイル(F)]->[設定...]
\r
34 JMenuItem miExit; // [メニュー]->[ファイル(F)]->[終了(X)]
\r
36 public Logger logger;
\r
37 public static SiteData mailProp;
\r
38 public static String propertiesFileName;
\r
43 * 第一: メールアカウントの設定ファイル名
\r
44 * @param args properties File Name
\r
45 * @throws Exception error
\r
47 public static void main(String args[]) throws Exception {
\r
48 String fileName = "sendmail.properties";
\r
49 if (args.length > 0) {
\r
52 (new SendMailGUI(fileName)).setVisible(true);
\r
55 public SendMailGUI(String propertiesName) throws Exception {
\r
56 Encrypt.PASSWORD_KEY = "hayashihimitukagi";
\r
57 logger = LoggerFactory.getInstance(); // Loggerオブジェクトの生成
\r
58 SendMailGUI.propertiesFileName = propertiesName;
\r
59 SendMailGUI.mailProp = new SiteData(SendMailGUI.propertiesFileName);
\r
62 logger.info("SendMailGUI - プログラム起動");
\r
65 fComponentsAdjusted = false;
\r
66 setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
\r
67 Container container = getContentPane();
\r
68 container.setLayout(new BorderLayout());
\r
69 setTitle("SendMail GUI");
\r
73 // [メニュー]->[ファイル(F)]
\r
74 menuFile = new JMenu("ファイル(F)");
\r
75 menuFile.setMnemonic('F');
\r
76 menuFile.setFont(new Font("Dialog", 0, 12));
\r
78 // [メニュー]->[ファイル(F)]->[設定...]
\r
79 miSetting = new JMenuItem("設定...");
\r
80 miSetting.addActionListener(this);
\r
81 miSetting.setFont(new Font("Dialog", 0, 12));
\r
82 menuFile.add(miSetting);
\r
84 // [メニュー]->[ファイル(F)]->[------------]
\r
85 menuFile.addSeparator();
\r
87 // [メニュー]->[ファイル(F)]->[終了(X)]
\r
88 miExit = new JMenuItem("終了(X)");
\r
89 miExit.addActionListener(this);
\r
90 miExit.setMnemonic('X');
\r
91 miExit.setFont(new Font("Dialog", 0, 12));
\r
92 menuFile.add(miExit);
\r
95 mainMenuBar = new JMenuBar();
\r
96 mainMenuBar.add(menuFile);
\r
97 getRootPane().setJMenuBar(mainMenuBar);
\r
100 headPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
\r
101 getContentPane().add(BorderLayout.NORTH, headPanel);
\r
102 JLabel label1 = new JLabel("SendMail GUI - サンプルプログラム", JLabel.CENTER);
\r
103 label1.setBounds(10,10,340,20);
\r
106 JPanel mainPanel = new JPanel(new FlowLayout());
\r
107 //mainPanel.setPreferredSize(new Dimension(500, 400));
\r
108 getContentPane().add(mainPanel, BorderLayout.CENTER);
\r
110 JTextArea textArea = new JTextArea(20, 60);
\r
111 textArea.setEditable(false);
\r
112 textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
\r
113 textArea.append("メール送信設定 サンプルプログラム\n");
\r
114 textArea.setCaretPosition(0);
\r
115 JScrollPane scrollPane = new JScrollPane(textArea);
\r
116 scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
\r
117 mainPanel.add(scrollPane, BorderLayout.CENTER);
\r
120 JPanel southPanel = new JPanel(new FlowLayout());
\r
121 getContentPane().add(BorderLayout.SOUTH, southPanel);
\r
123 JLabel label2 = new JLabel("All rights reserved.Copyright(c) 2010,, Hayashi,Yuu.", JLabel.CENTER);
\r
124 label2.setBounds(10,40,340,20);
\r
125 southPanel.add(label2);
\r
128 setLocationRelativeTo(null);
\r
132 public SendMail getMailInstance() {
\r
133 return new SendMail(SendMailGUI.mailProp);
\r
136 public static String getPropertiesFileName() {
\r
137 return propertiesFileName;
\r
140 public void addNotify() {
\r
141 Dimension d = getSize();
\r
143 if (fComponentsAdjusted) {
\r
146 setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
\r
147 Component components[] = getComponents();
\r
148 for (int i = 0; i < components.length; i++) {
\r
149 Point p = components[i].getLocation();
\r
150 p.translate(getInsets().left, getInsets().top);
\r
151 components[i].setLocation(p);
\r
154 fComponentsAdjusted = true;
\r
159 * @param event イベント
\r
161 public void actionPerformed(ActionEvent event) {
\r
162 Object object = event.getSource();
\r
163 if(object == miExit) {
\r
164 miExit_Action(event);
\r
166 else if (object == miSetting) {
\r
167 miSetting_Action(event);
\r
173 * [メニュー]->[ファイル]->[終了]
\r
177 void miExit_Action(ActionEvent event) {
\r
179 logger.info("SendMailGUI - プログラム終了");
\r
185 * [メニュー]->[ファイル]->[設定...]
\r
189 void miSetting_Action(ActionEvent event) {
\r
191 (new SettingDialog(this, true, SendMailGUI.getPropertiesFileName(), logger)).setVisible(true);
\r
193 catch (FileNotFoundException e) {
\r
195 e.printStackTrace();
\r
197 catch (IOException e) {
\r
199 e.printStackTrace();
\r