⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jms.java

📁 Java Mail Server JAVA编写的邮件服务器
💻 JAVA
字号:
/**************************************************************** * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.     * *                                                              * * Copyright 2008 Jun Li(SiChuan University, the School of      * * Software Engineering). All rights reserved.                  * *                                                              * * Licensed to the JMS under one  or more contributor license   * * agreements.  See the LICENCE file  distributed with this     * * work for additional information regarding copyright          * * ownership.  The JMS licenses this file  you may not use this * * file except in compliance  with the License.                 * *                                                              * * Unless required by applicable law or agreed to in writing,   * * software distributed under the License is distributed on an  * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       * * KIND, either express or implied.  See the License for the    * * specific language governing permissions and limitations      * * under the License.                                           * ****************************************************************/package org.jpxx.mail;import java.awt.AWTException;import java.awt.Image;import java.awt.MenuItem;import java.awt.PopupMenu;import java.awt.SystemTray;import java.awt.Toolkit;import java.awt.TrayIcon;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import javax.swing.JFrame;import javax.swing.UIManager;import org.apache.log4j.Logger;import java.nio.channels.FileLock;/** * * This class is to start mail server. *  * @author Jun Li * @version $Revision: 0.0.3 $, $Date: 2008/05/19 $ * @since JMS 0.0.2 *  */public class JMS {    private TrayIcon ti;    /**     * Class factory     */    private Factory factory = Factory.getSingletonInstance();    /**     * Creates an instance of Logger and initializes it.      * It is to write log for <code>MailServer</code>.     */    private Logger log = factory.getLogger(this);    private FileLock fl;    /**     * Lock     */    private final static File lockFile = new File(Constants.TEMP_DIR + "JMS.lock");    private LockThread lockThread;    private JMS() {        lockThread = new LockThread();        lockThread.start();        init();        /**         * Start JMS         */        MailServer.getSingletonInstance().startServer();    }    public static void main(String args[]) {        if (lockFile.exists()) {            System.exit(0);        } else {            new JMS();        }    }    private void init() {        /**         * Tray ICON         */        Image image = Toolkit.getDefaultToolkit().getImage(                getClass().getResource(                "/org/jpxx/mail/JMS.gif"));        PopupMenu menu = new PopupMenu(); //Menu                MenuItem manage = new MenuItem("Manage");        ActionListener showListener = new ActionListener() {            public void actionPerformed(ActionEvent e) {                //SystemTray.getSystemTray().remove(ti); // Remove                try {                    JFrame f = (JFrame) Class.forName("org.jpxx.mail.console.LoginGUI").newInstance();                    f.setVisible(true);                } catch (Exception ex) {                }            }        };        manage.addActionListener(showListener);        menu.add(manage);        menu.addSeparator();        MenuItem quit = new MenuItem("Quit");        quit.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                try {                    lockThread.close();                } catch (IOException ex) {                    if (!lockFile.delete()) {                        try {                            lockThread.stop();                        } catch (Exception excep) {                        }                        lockThread = null;                        lockFile.delete();                    }                }                System.exit(0);            }        });        menu.add(quit);        //        ti = new TrayIcon(image, "JMS 0.0.3", menu);        ti.addActionListener(showListener);        String skinName = "org.jvnet.substance.skin.SubstanceGreenMagicLookAndFeel";        try {            UIManager.setLookAndFeel(skinName);        } catch (Exception ex) {        }        if (SystemTray.isSupported()) {            minimizeToTray();        } else {            log.error("Tray Icon not supported.");        }    }    private void minimizeToTray() {        SystemTray tray = SystemTray.getSystemTray();        try {            tray.add(ti);        } catch (AWTException e) {        }    }    class LockThread extends Thread {        FileOutputStream fos;        private LockThread() {            File f = new File(Constants.TEMP_DIR);            if (!f.exists()) {                f.mkdirs();            }        }        @Override        public void run() {            try {                fos = new FileOutputStream(lockFile);                fl = fos.getChannel().tryLock();            } catch (Exception e) {                e.printStackTrace();            }        }        public void close() throws IOException {            if (fl != null) {                fl.release();                fos.close();                lockFile.delete();            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -