D 的个人博客

但行好事莫问前程

  menu
417 文章
3446695 浏览
9 当前访客
ღゝ◡╹)ノ❤️

NetBeans的Gmail插件!

这几天写了一个NetBeans的插件——Gmail Notifier : -)。偶的Ubuntu上不了网。。。。只能在Windows下测试了。。。。

先看下解图:

OK,源代码:

 

/*
 * @(#)GmailNotifierAction.java
 * Author: 88250 <[email protected]>, 
http://blog.csdn.net/DL88250
 * Created on May 18, 2008, 7:47:18 PM
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
*/
package cn.edu.ynu.sei.gmailnotifier;

import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CallableSystemAction;

/**
 * Gmail Notifier Action.
 * 
@author 88250 <[email protected]>, http://blog.csdn.net/DL88250
 * 
@version 1.0.0.0, May 18, 2008
 
*/
public final class GmailNotifierAction extends CallableSystemAction {

    
private static final long serialVersionUID = 1L;
    GmailNotifierPanel gChecker 
= new GmailNotifierPanel();

    
public void performAction() {
        gChecker.forceCheck();
    }

    
public String getName() {
        
return NbBundle.getMessage(GmailNotifierAction.class,
                
"CTL_GmailNotifierAction");
    }

    
public HelpCtx getHelpCtx() {
        
return HelpCtx.DEFAULT_HELP;
    }

    @Override
    
protected boolean asynchronous() {
        
return false;
    }

    @Override
    
public java.awt.Component getToolbarPresenter() {
        
return gChecker;
    }
}

 

 

/*
 * @(#)GmailNotifierOptionsCategory.java
 * Author: 88250 <[email protected]>, 
http://blog.csdn.net/DL88250
 * Created on May 18, 2008, 11:25:57 PM
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
*/
package cn.edu.ynu.sei.gmailnotifier;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import org.netbeans.spi.options.OptionsCategory;
import org.netbeans.spi.options.OptionsPanelController;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;

/**
 * Gmail Notifier settings panel's category.
 * 
@author 88250 <[email protected]>, http://blog.csdn.net/DL88250
 * 
@version 1.0.0.1, May 18, 2008
 
*/
public class GmailNotifierOptionsCategory extends OptionsCategory {

    
public OptionsPanelController create() {
        
return new GmailNotifierSettingsPanelController();
    }

    
public String getCategoryName() {
        
return NbBundle.getMessage(GmailNotifierOptionsCategory.class,
                
"OptionsCategory_Name_Gmailnotifier");
    }

    
public String getTitle() {
        
return NbBundle.getMessage(GmailNotifierOptionsCategory.class,
                
"OptionsCategory_Title_Gmailnotifier");
    }

    @Override
    
public Icon getIcon() {
        
return new ImageIcon(Utilities.loadImage(
                
"cn/edu/ynu/sei/gmailnotifier/gm-logo-settings.png"));
    }
}

 

/*
 * @(#)GmailNotifierPanel.java
 * Author: 88250 <[email protected]>, 
http://blog.csdn.net/DL88250
 * Created on May 18, 2008, 9:10:24 PM
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
*/
package cn.edu.ynu.sei.gmailnotifier;

import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;
import cn.edu.ynu.sei.gmailnotifier.common.GmailSetting;
import cn.edu.ynu.sei.gmailnotifier.common.GmailSettingManager;
import cn.edu.ynu.sei.gmailnotifier.common.GmailBox;
import cn.edu.ynu.sei.gmailnotifier.common.GmailBoxManager;
import java.awt.event.MouseEvent;
import java.util.Timer;
import java.util.TimerTask;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.openide.util.RequestProcessor;

/**
 * Gmail checker panel.
 * 
@author 88250 <[email protected]>, http://blog.csdn.net/DL88250
 * 
@version 1.0.2.7, May 21, 2008
 
*/
public class GmailNotifierPanel extends javax.swing.JPanel {

    
private static final long serialVersionUID = 1L;
    
//<editor-fold defaultstate="collapsed" desc="variables-consts">
    private GmailBox mailBox = null;
    
private GmailBoxManager gmHelper = null;
    
private GmailSetting settings = null;
    
private GmailSettingManager settingsManager = null;
    
private int subjectCount = 0;
    
private Timer mailNotifierTimer;
    
private Timer showSubjectIntervalTimer;
    
private String connectingTo = "<html><b>Connecting To Gmail...</b></html>";
    
private String retrivingUserCountInfo =
            
"<html><b>Retrieving Usage and Count Information...</b></html>";
    
// TODO private String usagePercent = "Usage Percent Is : ";
    private String newMailsCount = "Total New Mails Is : ";
    
private String noActiveConnection =
            
"<html><b>No Active Connection or Connection Is Not Usable...</b></html>";
    
private String initiateString =
            
"<html>Gmail checker Module.... <b>Disconnected</b></HTML>";
    
private String tooltipString =
            
"<html><b>Left</b> click will open the Gmail in your web browser<br> " +
            
"<b>Right</b> click will check your new mails<br> Have Fun :-) </html>";
    
private String Retriving_emails_info =
            
"<html><b>Retrieving e-mail Headers...</b></html>";
    
//</editor-fold>

    
/**
     * Check mail box.
     * 
@return
     
*/
    
public boolean doCheckMail() {
        
//<editor-fold defaultstate="collapsed" desc="runnables for gmHelper calling">
        Runnable connectRun = new Runnable() {

            
public void run() {
                
if (gmHelper.connect()) {
                    mailBox 
= gmHelper.getMailBox();
                } 
else {
                    jLabel1.setText(noActiveConnection);
                }
            }
        };

        Runnable newSubjectsCount 
= new Runnable() {

            
public void run() {
                subjectCount 
= mailBox.getSubjectsCount();
                
if (subjectCount > 0) {
                    playSound(
"notify");
                }
            }
        };
        
//</editor-fold>

        ProgressHandle ProgHandl 
= ProgressHandleFactory.createHandle(
                connectingTo);
        jLabel1.setText(connectingTo);
        ProgHandl.start(
99);
        RequestProcessor.getDefault().post(connectRun).waitFinished();

        jLabel1.setText(retrivingUserCountInfo);
        
        ProgHandl.progress(retrivingUserCountInfo, 
33);
        RequestProcessor.getDefault().post(newSubjectsCount).waitFinished();

        
if (!gmHelper.isConnected()) {
            jLabel1.setText(noActiveConnection);
            setIcon(
"gm-logo-disabled");
            ProgHandl.finish();
            
return false;
        } 
else {
            jLabel1.setText(Retriving_emails_info);
            
if (subjectCount > 0) {
                setIcon(
"gm-logo-new");
            } 
else {
                 setIcon(
"gm-logo");
            }
            
// TODO always 33% ? :-)
            ProgHandl.progress(Retriving_emails_info, 33);
            ProgHandl.progress(
33);
            ProgHandl.finish();
            
return true;
        }
    }

    
/**
     * Initialize a gmail manager
     * 
@see {@link #gmHelper}
     
*/
    
private void newGmailManager() {
        gmHelper 
= new GmailBoxManager(settings.getUserName(), settings.getPassword(), settings.getProxy(), settings.getPort());
    }

    
/**
     * Reset information to gmail manager.
     
*/
    
private void resetGmailManager() {
        gmHelper.userName 
= settings.getUserName();
        gmHelper.userPassword 
= settings.getPassword();
        gmHelper.proxyHost 
= settings.getProxy();
        gmHelper.port 
= settings.getPort();
    }

    
/**
     * Display mails information.
     
*/
    
private void showMailsInfo() {
        setCount(mailBox.getSubjectsCount());
        showSubjectIntervalTimer 
= new java.util.Timer();
        showSubjectIntervalTimer.scheduleAtFixedRate(
new TimerTask() {

            
private int currentSubjectNo;

            
public void run() {
                
if (currentSubjectNo < subjectCount) {
                    jLabel1.setText(
"<html><b>" +
                            (currentSubjectNo 
+ 1+ "</b> :" +
                            getSubjectSnip(currentSubjectNo) 
+ "</html>");
                    currentSubjectNo
++;
                } 
else {
                    showSubjectIntervalTimer.cancel();
                    setCount(mailBox.getSubjectsCount());
                    mailBox 
= gmHelper.getMailBox();
                }

            }
        }, settings.getDisplayRotationInterval() 
* 1000,
                settings.getDisplayRotationInterval() 
* 1000);
    }

    
/**
     * Getting start check mail.
     * 
@param delayBeforeStartCheck delay(second) before getting start check
     
*/
    
public void startCheck(int delayBeforeStartCheck) {
        settings 
= settingsManager.retrieveSettings();
        mailBox 
= new GmailBox();
        
if (gmHelper == null) {
            newGmailManager();
        } 
else {
            resetGmailManager();
        }

        mailNotifierTimer 
= new java.util.Timer();
        mailNotifierTimer.scheduleAtFixedRate(
new TimerTask() {

            
public void run() {
                subjectCount 
= 0;
                
if (doCheckMail()) {
                    showMailsInfo();
                }
            }
        }, delayBeforeStartCheck 
* 1000,
                settings.getCheckMailInterval() 
* 60 * 1000);
    }

    
/**
     * Default constructor.
     
*/
    
public GmailNotifierPanel() {
        initComponents();
        jLabel1.setText(initiateString);
        jLabel1.setToolTipText(tooltipString);
        settingsManager 
= new GmailSettingManager();
        settings 
= settingsManager.retrieveSettings();
        startCheck(settings.getDelayBeforeFirstCheck());
    }

    
/**
     * Play sound.
     * 
@param soundName sound file name
     
*/
    
private void playSound(String soundName) {
        
if (settings.isVoiceOn()) {
            AudioClip Clip;
            URL Url;
            
try {
                Url 
= getClass().getResource(
                        
"/cn/edu/ynu/sei/gmailnotifier/" +
                        soundName 
+ ".wav");
                Clip 
= Applet.newAudioClip(Url);
                Clip.play();
            } 
catch (Exception e) {
                System.err.println(e.getMessage());
            }
        }
    }

    
/**
     * Set mail count for display.
     * 
@param count mail count
     
*/
    
private void setCount(int count) {
        
this.jLabel1.setText("<html>" + newMailsCount +
                
" <b><font color="blue">" + count + "</font></b></html>");
    }

    
/**
     * Set the label's icon.
     * 
@param iconName icon name
     
*/
    
private void setIcon(String iconName) {
        jLabel1.setIcon(
new javax.swing.ImageIcon(getClass().getResource("/cn/edu/ynu/sei/gmailnotifier/" + iconName + ".png"))); // NOI18N

    }

    
/** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     
*/
    
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 
= new javax.swing.JLabel();

        setAlignmentY(
0.0F);
        setOpaque(
false);

        jLabel1.setFont(
new java.awt.Font("Tahoma"010)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel1.setIcon(
new javax.swing.ImageIcon(getClass().getResource("/cn/edu/ynu/sei/gmailnotifier/gm-logo-disabled.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, "<html>Gmail Notifier Module.... <b>Disconnected</b></html>");
        jLabel1.setToolTipText(
"");
        jLabel1.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        jLabel1.setAlignmentY(
0.0F);
        jLabel1.setAutoscrolls(
true);
        jLabel1.setDoubleBuffered(
true);
        jLabel1.setIconTextGap(
2);
        jLabel1.setOpaque(
false);
        jLabel1.setPreferredSize(
new java.awt.Dimension(22722));
        jLabel1.setSize(
new java.awt.Dimension(22722));
        jLabel1.addMouseListener(
new java.awt.event.MouseAdapter() {
            
public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
            
public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel1MouseEntered(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout 
= new org.jdesktop.layout.GroupLayout(this);
        
this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
237, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
24, Short.MAX_VALUE)
        );
    }
// </editor-fold>                        

    
/**
     * Get new mails subject snip.
     * 
@param subjectNo subject number
     * 
@return mail subject snip
     
*/
    
private String getSubjectSnip(int subjectNo) {
        String subj 
= mailBox.getMails().get(subjectNo).getSubject();
        
return subj.length() > 40 ? (subj.substring(040+ "....") : subj;
    }

    
// TODO getContentSnip
    /**
     * Get new mails content snip.
     * 
@param subjectNo subject number
     * 
@return mail content snip
     
*/
    
private String getContentSnip(int subjectNo) {
        String cont 
= mailBox.getMails().get(subjectNo).getContent();
        
return cont.length() > 100 ? (cont.substring(0100+ "....") : cont;
    }

    
private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {                                     
        
// left clicked
        if (evt.getModifiers() == MouseEvent.BUTTON1_MASK) {
            GmailBoxManager.openURL(
"http://www.gmail.com");
        }
        
// right clicked
        if (evt.getModifiers() == MouseEvent.BUTTON3_MASK) {
            forceCheck();
        }
    }                                    

private void jLabel1MouseEntered(java.awt.event.MouseEvent evt) {                                     
    
if (mailBox.getSubjectsCount() != 0) {
        StringBuilder snips 
= new StringBuilder();
        
for (int i = 0; i < subjectCount; i++) {
            snips.append(
"<html><b>" + (i + 1+ "</b>: " +
                    
"<font color="blue">" +
                    getSubjectSnip(i) 
+
                    
"</font><br>");
        
//snips.append("   " + getContentSnip(i) + "<br>");
        
//snips.append("---<br>");
        }
        snips.append(
"</html>");
        jLabel1.setToolTipText(snips.toString());
    } 
else {
        jLabel1.setToolTipText(tooltipString);
    }
}                                    

    
// Variables declaration - do not modify                     
    public javax.swing.JLabel jLabel1;
    
// End of variables declaration                   

    
/**
     * Check mail inbox by force.
     
*/
    
public void forceCheck() {
        
if (showSubjectIntervalTimer != null) {
            showSubjectIntervalTimer.cancel();
        }
        
if (mailNotifierTimer != null) {
            mailNotifierTimer.cancel();
        }
        startCheck(
0);
    }
}

 

/*
 * @(#)GmailNotifierSettingsPanel.java
 * Author: 88250 <[email protected]>, 
http://blog.csdn.net/DL88250
 * Created on May 18, 2008, 11:25:57 PM
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
*/
package cn.edu.ynu.sei.gmailnotifier;

import cn.edu.ynu.sei.gmailnotifier.common.GmailSetting;
import javax.swing.SpinnerNumberModel;

/**
 * Gmail Notifier settings panel.
 * 
@author 88250 <[email protected]>, http://blog.csdn.net/DL88250
 * 
@version 1.0.0.2, May 21, 2008
 
*/
public class GmailNotifierSettingsPanel extends javax.swing.JPanel {

    
private static final long serialVersionUID = 1L;
    
public boolean isChanged = false;

    
/**
     * Default constructor.
     
*/
    
public GmailNotifierSettingsPanel() {
        initComponents();
    }

    
/**
     * Set all settings in UI.
     * 
@param setting gmail settings
     
*/
    
public void populateUI(GmailSetting setting) {
        
this.jTextField1.setText(setting.getUserName());
        
this.jPasswordField1.setText(setting.getPassword());
        
this.jCheckBox1.setSelected(setting.isVoiceOn());

        
this.jSpinner1.setValue(new Integer(setting.getDisplayRotationInterval()));
        
this.jSpinner2.setValue(new Integer(setting.getCheckMailInterval()));
        
this.jSpinner3.setValue(new Integer(setting.getDisplayRotationInterval()));

        
this.jCheckBox3.setSelected(setting.isUseProxy());
        
this.jTextField2.setText(setting.getProxy());
        
this.jTextField3.setText(String.valueOf(setting.getPort()));
        isChanged 
= true;
    }

    
/**
     * Retieve all settings.
     * 
@return gmail settings
     
*/
    
public GmailSetting returnSetting() {
        
return new GmailSetting(jTextField1.getText(), new String(
                jPasswordField1.getPassword()),
                jCheckBox3.isSelected(), jTextField2.getText(),
                Integer.parseInt(jTextField3.getText()),
                ((Integer) jSpinner1.getValue()).intValue(),
                ((Integer) jSpinner2.getValue()).intValue(),
                ((Integer) jSpinner3.getValue()).intValue(),
                jCheckBox1.isSelected());
    }

    
/** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     
*/
    
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 
= new javax.swing.JPanel();
        jTextField1 
= new javax.swing.JTextField();
        jPasswordField1 
= new javax.swing.JPasswordField();
        jCheckBox1 
= new javax.swing.JCheckBox();
        jLabel1 
= new javax.swing.JLabel();
        jLabel2 
= new javax.swing.JLabel();
        jPanel2 
= new javax.swing.JPanel();
        jPanel3 
= new javax.swing.JPanel();
        jTextField2 
= new javax.swing.JTextField();
        jLabel9 
= new javax.swing.JLabel();
        jLabel10 
= new javax.swing.JLabel();
        jTextField3 
= new javax.swing.JTextField();
        jCheckBox3 
= new javax.swing.JCheckBox();
        jSpinner1 
= new javax.swing.JSpinner();
        jSpinner2 
= new javax.swing.JSpinner();
        jSpinner3 
= new javax.swing.JSpinner();
        jLabel3 
= new javax.swing.JLabel();
        jLabel4 
= new javax.swing.JLabel();
        jLabel5 
= new javax.swing.JLabel();
        jLabel6 
= new javax.swing.JLabel();
        jLabel7 
= new javax.swing.JLabel();
        jLabel8 
= new javax.swing.JLabel();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(
"General Options"));

        jTextField1.addPropertyChangeListener(
new java.beans.PropertyChangeListener() {
            
public void propertyChange(java.beans.PropertyChangeEvent evt) {
                GmailNotifierSettingsPanel.
this.propertyChange(evt);
            }
        });

        jPasswordField1.addPropertyChangeListener(
new java.beans.PropertyChangeListener() {
            
public void propertyChange(java.beans.PropertyChangeEvent evt) {
                GmailNotifierSettingsPanel.
this.propertyChange(evt);
            }
        });

        jCheckBox1.setText(
"Enable sounds");
        jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(
0000));
        jCheckBox1.setMargin(
new java.awt.Insets(0000));
        jCheckBox1.addPropertyChangeListener(
new java.beans.PropertyChangeListener() {
            
public void propertyChange(java.beans.PropertyChangeEvent evt) {
                GmailNotifierSettingsPanel.
this.propertyChange(evt);
            }
        });

        jLabel1.setText(
"Username");

        jLabel2.setText(
"Password");

        org.jdesktop.layout.GroupLayout jPanel1Layout 
= new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel2)
                            .add(jLabel1))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, 
false)
                            .add(jPasswordField1)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
208, Short.MAX_VALUE)))
                    .add(jCheckBox1))
                .add(
132132132))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                        .add(
161616)
                        .add(jLabel2))
                    .add(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPasswordField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
30, Short.MAX_VALUE)))
                .add(
171717)
                .add(jCheckBox1))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(
"Advanced Options"));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(
"Proxy Settings"));
        jPanel3.setName(
"Proxy Settings"); // NOI18N

        jTextField2.addPropertyChangeListener(
new java.beans.PropertyChangeListener() {
            
public void propertyChange(java.beans.PropertyChangeEvent evt) {
                GmailNotifierSettingsPanel.
this.propertyChange(evt);
            }
        });

        jLabel9.setText(
"Host:");

        jLabel10.setText(
"Port:");

        jTextField3.addPropertyChangeListener(
new java.beans.PropertyChangeListener() {
            
public void propertyChange(java.beans.PropertyChangeEvent evt) {
                GmailNotifierSettingsPanel.
this.propertyChange(evt);
            }
        });

        jCheckBox3.setText(
"Connect via proxy");
        jCheckBox3.setBorder(javax.swing.BorderFactory.createEmptyBorder(
0000));
        jCheckBox3.setMargin(
new java.awt.Insets(0000));
        jCheckBox3.addPropertyChangeListener(
new java.beans.PropertyChangeListener() {
            
public void propertyChange(java.beans.PropertyChangeEvent evt) {
                GmailNotifierSettingsPanel.
this.propertyChange(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel3Layout 
= new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jCheckBox3)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel9)
                            .add(jLabel10))
                        .add(
181818)
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, 
false)
                            .add(jTextField3)
                            .add(jTextField2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
142, Short.MAX_VALUE))))
                .addContainerGap(
190, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jCheckBox3)
                .add(
141414)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel9))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel10))
                .add(
202020))
        );

        jSpinner1.setModel(
new SpinnerNumberModel(
            
new Integer(15),
            
new Integer(0),
            
null,
            
new Integer(5)
        ));
        jSpinner1.addPropertyChangeListener(
new java.beans.PropertyChangeListener() {
            
public void propertyChange(java.beans.PropertyChangeEvent evt) {
                GmailNotifierSettingsPanel.
this.propertyChange(evt);
            }
        });

        jSpinner2.setModel(
new SpinnerNumberModel(
            
new Integer(3),
            
new Integer(1),
            
new Integer(15),
            
new Integer(1)
        ));
        jSpinner2.addPropertyChangeListener(
new java.beans.PropertyChangeListener() {
            
public void propertyChange(java.beans.PropertyChangeEvent evt) {
                GmailNotifierSettingsPanel.
this.propertyChange(evt);
            }
        });

        jSpinner3.setModel(
new SpinnerNumberModel(
            
new Integer(15),
            
new Integer(0),
            
null,
            
new Integer(5)
        ));
        jSpinner3.addPropertyChangeListener(
new java.beans.PropertyChangeListener() {
            
public void propertyChange(java.beans.PropertyChangeEvent evt) {
                GmailNotifierSettingsPanel.
this.propertyChange(evt);
            }
        });

        jLabel3.setText(
"Seconds");

        jLabel4.setText(
"Minutes");

        jLabel5.setText(
"Seconds");

        jLabel6.setText(
"Delay before first mail check:");

        jLabel7.setText(
"Mail check interval:");

        jLabel8.setText(
"Rotation delay:");

        org.jdesktop.layout.GroupLayout jPanel2Layout 
= new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(
181818)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel6)
                            .add(jLabel7)
                            .add(jLabel8))
                        .add(
181818)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jSpinner1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
93, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jSpinner2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
93, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jSpinner3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
93, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(
181818)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel4)
                            .add(jLabel3)
                            .add(jLabel5)))
                    .add(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(jSpinner1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3))
                .add(
151515)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jSpinner2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel4)
                    .add(jLabel7))
                .add(
141414)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jSpinner3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel5)
                    .add(jLabel8))
                .add(
454545)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(
53, Short.MAX_VALUE))
        );

        jPanel3.getAccessibleContext().setAccessibleName(
"");

        org.jdesktop.layout.GroupLayout layout 
= new org.jdesktop.layout.GroupLayout(this);
        
this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
406, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }
// </editor-fold>                        

    
/**
     * Property change event handle.
     * 
@param evt property chang evnt
     
*/
    
private void propertyChange(java.beans.PropertyChangeEvent evt) {                                
        isChanged 
= true;
    }                               
    
// Variables declaration - do not modify                     
    private javax.swing.JCheckBox jCheckBox1;
    
private javax.swing.JCheckBox jCheckBox3;
    
private javax.swing.JLabel jLabel1;
    
private javax.swing.JLabel jLabel10;
    
private javax.swing.JLabel jLabel2;
    
private javax.swing.JLabel jLabel3;
    
private javax.swing.JLabel jLabel4;
    
private javax.swing.JLabel jLabel5;
    
private javax.swing.JLabel jLabel6;
    
private javax.swing.JLabel jLabel7;
    
private javax.swing.JLabel jLabel8;
    
private javax.swing.JLabel jLabel9;
    
private javax.swing.JPanel jPanel1;
    
private javax.swing.JPanel jPanel2;
    
private javax.swing.JPanel jPanel3;
    
private javax.swing.JPasswordField jPasswordField1;
    
private javax.swing.JSpinner jSpinner1;
    
private javax.swing.JSpinner jSpinner2;
    
private javax.swing.JSpinner jSpinner3;
    
private javax.swing.JTextField jTextField1;
    
private javax.swing.JTextField jTextField2;
    
private javax.swing.JTextField jTextField3;
    
// End of variables declaration                   
}

 

/*
 * @(#)GmailNotifierSettingsPanelController.java
 * Author: 88250 <[email protected]>, 
http://blog.csdn.net/DL88250
 * Created on May 18, 2008, 11:25:57 PM
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
*/
package cn.edu.ynu.sei.gmailnotifier;

import cn.edu.ynu.sei.gmailnotifier.common.GmailSettingManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
import org.netbeans.spi.options.OptionsPanelController;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.util.HelpCtx;
import org.openide.util.Lookup;

/**
 * Gmail Notifier settings panel's controller.
 * 
@author 88250 <[email protected]>, http://blog.csdn.net/DL88250
 * 
@version 1.0.0.3, May 21, 2008
 
*/
public class GmailNotifierSettingsPanelController extends OptionsPanelController {

    
private GmailNotifierSettingsPanel settingPanel =
            
new GmailNotifierSettingsPanel();
    
private GmailSettingManager settingManager = new GmailSettingManager();
    
private String sureTocancle =
            
"<html><b>do you want to save the changes that you made" +
            
" into Gmail setting Dialog ?</b><html>";

    
public void applyChanges() {
        
if (settingPanel.isChanged) {
            settingManager.storeSettings(settingPanel.returnSetting());
            settingPanel.isChanged 
= false;
        }
    }

    
public void cancel() {
        
if (settingPanel.isChanged) {
            DialogDescriptor ddesc 
= new DialogDescriptor((Object) sureTocancle,
                    
"Changes will lost",
                    
true, DialogDescriptor.YES_NO_OPTION,
                    DialogDescriptor.CANCEL_OPTION, 
new ActionListener() {

                
public void actionPerformed(ActionEvent e) {
                    
if (e.getActionCommand().equalsIgnoreCase("yes")) {
                        settingManager.storeSettings(
                                settingPanel.returnSetting());
                    }
                }
            });
            DialogDisplayer.getDefault().createDialog(ddesc).setVisible(
true);
        }
    }

    
public boolean isValid() {
        
return true;
    }

    
public boolean isChanged() {
        
return true;
    }

    
public JComponent getComponent(Lookup masterLookup) {
        
return settingPanel;
    }

    
public HelpCtx getHelpCtx() {
        
return HelpCtx.DEFAULT_HELP;
    }

    
public void update() {
        settingPanel.populateUI(settingManager.retrieveSettings());
    }

    
public void addPropertyChangeListener(PropertyChangeListener l) {
    }

    
public void removePropertyChangeListener(PropertyChangeListener l) {
    }
}

 

/*
 * @(#)GmailBox.java
 * Author: 88250 <[email protected]>, 
http://blog.csdn.net/DL88250
 * Created on May 19, 2008, 10:6:39 AM
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
*/
package cn.edu.ynu.sei.gmailnotifier.common;

import java.util.ArrayList;
import java.util.List;

/**
 * Gmail mail box information. 
 * 
@author 88250 <[email protected]>, http://blog.csdn.net/DL88250
 * 
@version 1.0.0.5, May 21, 2008
 
*/
public class GmailBox {

    
private List<Mail> mails = new ArrayList<Mail>();

    
/**
     * Default consturctor.
     
*/
    
public GmailBox() {
    }

    
/**
     * Constructor with parameters.
     * 
@param newMailCount new mail count
     
*/
    
public GmailBox(List<Mail> mails) {
        
this.setMails(mails);
    }

    
//<editor-fold defaultstate="collapsed" desc="Getters & Setters">
    public List<Mail> getMails() {
        
return mails;
    }

    
public int getSubjectsCount() {
        
return mails.size();
    }

    
public void setMails(List<Mail> mails) {
        
if (mails != null) {
            
this.mails = mails;
        }
    }
    
//</editor-fold>
}

 

/*
 * @(#)GmailBox.java
 * Author: 88250 <[email protected]>, 
http://blog.csdn.net/DL88250
 * Created on May 17, 2008, 7:17:34 PM
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
*/
package cn.edu.ynu.sei.gmailnotifier.common;

import java.lang.reflect.Method;
import java.security.Security;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.URLName;
import javax.swing.JOptionPane;

/**
 * Gmail mail box manager. 
 * 
@author 88250 <[email protected]>, http://blog.csdn.net/DL88250
 * 
@version 1.0.2.6, May 21, 2008
 
*/
public class GmailBoxManager {

    
public String userName = "User name";
    
public String userPassword = "Password";
    
public String proxyHost = "No Proxy";
    
public int port = 0;
    
private static Store store;

    
/**
     * Constructor with parameters.
     * 
@param userName user name
     * 
@param userPassword user password
     * 
@param proxyHost proxy host
     * 
@param port proxy port
     
*/
    
public GmailBoxManager(String userName, String userPassword,
            String proxyHost, 
int port) {
        
this.userPassword = userPassword;
        
this.userName = userName;
        
this.proxyHost = proxyHost;
        
this.port = port;
    }

    
/**
     * Connect to the mail box.
     * 
@return if connect successfully, return <code>true</code>,
     * otherwise, return <code>false</code>
     
*/
    
public boolean connect() {
        
if (!proxyHost.equalsIgnoreCase("No Proxy")) {
            
// TODO setProxy(proxyHost, port);
        } else {
            
if (store == null || !store.isConnected()) {
                Security.addProvider(
new com.sun.net.ssl.internal.ssl.Provider());
                
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
                Properties props 
= System.getProperties();
                props.setProperty(
"mail.pop3.socketFactory.class", SSL_FACTORY);
                props.setProperty(
"mail.pop3.socketFactory.fallback""false");
                props.setProperty(
"mail.pop3.port""995");
                props.setProperty(
"mail.pop3.socketFactory.port""995");
                props.setProperty(
"mail.imap.socketFactory.class", SSL_FACTORY);
                props.setProperty(
"mail.imap.socketFactory.fallback""false");
                props.setProperty(
"mail.imap.port""993");
                props.setProperty(
"mail.imap.socketFactory.port""993");

                Session session 
= Session.getDefaultInstance(props, null);
                session.setDebug(
false); // TODO reset debug flag

                URLName urln 
= new URLName("imap""imap.gmail.com"993null,
                        userName,
                        userPassword);
                
// TODO available POP3s!
//        URLName urln = new URLName("pop3s", "pop.gmail.com", 995, null,
//                userName, userPassword);
                try {
                    store 
= session.getStore(urln);
                } 
catch (javax.mail.NoSuchProviderException ex) {
                    System.err.println(ex.getMessage());
                    
return false;
                }
                
try {
                    store.connect();
                } 
catch (MessagingException ex) {
                    System.err.println(ex.getMessage());
                    
return false;
                }
            }
        }

        
return true;
    }

    
/**
     * Is connected mail box?
     * 
@return if connected, return <code>true</code>,
     * otherwise, return <code>false</code>
     
*/
    
public boolean isConnected() {
        
return store != null ? store.isConnected() : false;
    }

    
/**
     * Get the new mail box information.
     * 
@return mail box
     
*/
    
public GmailBox getMailBox() {
        
if (store == null || !store.isConnected()) {
            connect();
        }
        
// TODO   int usagePercent=0;
        int newMailCount = 0;
        List
<Mail> mails = new ArrayList<Mail>();
        
try {
            Folder inbox 
= store.getFolder("Inbox");
            inbox.open(Folder.READ_ONLY);
            newMailCount 
= inbox.getUnreadMessageCount();

            
if (newMailCount != 0) {
                Message[] messages 
= inbox.getMessages(1, newMailCount);
                
// we only fucus on mail, not message, so using Set 
                
// to ignore the duplicate subject messages
                Set<String> subjects = new HashSet<String>();
                
for (int i = 0; i < messages.length; i++) {
                    String subject 
= messages[i].getSubject();
                    
// TODO parse the mail body
                    
// String content = messages[i].getContent();
                    
// Only subject
                    if (subject == null) {
                        subject 
= "no subject";
                    }
                    subjects.add(subject);
                }
                
for (String sub : subjects) {
                     mails.add(
new Mail(sub, ""/* content */));
                }
                
return new GmailBox(mails);
            } 
else {
                System.err.println(
"No any new mail!");
            }
        } 
catch (Exception ex) {
            System.err.println(ex.getMessage());
        }

        
// return empty mail box
        return new GmailBox();
    }

    
/**
     * Open the url in system's web browser.
     * 
@param url the specified url to open
     
*/
    @SuppressWarnings(value 
= {"unchcked"})
    
public static void openURL(String url) {
        String osName 
= System.getProperty("os.name");
        
try {
            
if (osName.startsWith("Mac OS")) {
                Class fileMgr 
= Class.forName("com.apple.eio.FileManager");
                @SuppressWarnings(
"unchecked")
                Method openURL 
= fileMgr.getDeclaredMethod("openURL",
                        
new Class[]{String.class});
                openURL.invoke(
nullnew Object[]{url});
            } 
else if (osName.startsWith("Windows")) {
                Runtime.getRuntime().exec(
"rundll32 url.dll,FileProtocolHandler " +
                        url);
            } 
else {
                
//assume Unix or Linux
                String[] browsers = {
                    
"firefox""opera""konqueror",
                    
"epiphany""mozilla""netscape"
                };
                String browser 
= null;
                
for (int count = 0;
                        count 
< browsers.length && browser == null;
                        count
++) {
                    
if (Runtime.getRuntime().exec(
                            
new String[]{"which", browsers[count]}).waitFor() ==
                            
0) {
                        browser 
= browsers[count];
                    }

                }
                
if (browser == null) {
                    
throw new Exception("Could not find web browser");
                } 
else {
                    Runtime.getRuntime().exec(
new String[]{browser, url});
                }
            }
        } 
catch (Exception e) {
            JOptionPane.showMessageDialog(
null,
                    
"Error attempting to launch web browser" + ": " + e.getLocalizedMessage());
        }
    }
}

 

/*
 * @(#)GmailSetting.java
 * Author: 88250 <[email protected]>, 
http://blog.csdn.net/DL88250
 * Created on May 19, 2008, 9:17:35 AM
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
*/
package cn.edu.ynu.sei.gmailnotifier.common;

import java.io.Serializable;

/**
 * Gmail Notifier settins. 
 * 
@author 88250 <[email protected]>, http://blog.csdn.net/DL88250
 * 
@version 1.0.0.5, May 21, 2008
 * 
@see Serializable
 
*/
public class GmailSetting implements Serializable {

    
private static final long serialVersionUID = 1L;
    
private String userName = "User name";
    
private String password = "Password";
    
private boolean useProxy;
    
private String Proxy = "No Proxy";
    
private int port;
    
private int checkMailInterval = 5;        // minute

    
private int displayRotationInterval = 5// second

    
private int delayBeforeFirstCheck = 15;  // second

    
private boolean voiceOn;

    
/**
     * Constructor with parameters.
     * 
@param userName user name
     * 
@param password user password
     * 
@param useProxy using proxy?
     * 
@param proxy proxy host setting ("192.168.110.65")
     * 
@param port  proxy port setting (808)
     * 
@param delayBeforeFirstCheck delay before first check after netbeans luanched
     * 
@param checkInterval check mail interval
     * 
@param rotationInterval rotation display interval
     * 
@param voiceOn play sound when retrieving mails
     
*/
    
public GmailSetting(String userName, String password,
                        
boolean useProxy, String proxy, int port,
                        
int delayBeforeFirstCheck, int checkInterval,
                        
int rotationInterval,
                        
boolean voiceOn) {
        
this.setUserName(userName);
        
this.setPassword(password);
        
this.setCheckMailInterval(checkInterval);
        
this.setDisplayRotationInterval(rotationInterval);
        
this.setPort(port);
        
this.setVoiceOn(voiceOn);
        
this.setProxy(proxy);
        
this.setDelayBeforeFirstCheck(delayBeforeFirstCheck);
        
this.setUseProxy(useProxy);
    }

    
/**
     * Default constructor.
     
*/
    
public GmailSetting() {
    }

    
//<editor-fold defaultstate="collapsed" desc="getters & setters">
    public String getProxy() {
        
return Proxy;
    }

    
public void setProxy(String Proxy) {
        
this.Proxy = Proxy;
    }

    
public int getCheckMailInterval() {
        
return checkMailInterval;
    }

    
public void setCheckMailInterval(int checkMailInterval) {
        
this.checkMailInterval = checkMailInterval;
    }

    
public int getDelayBeforeFirstCheck() {
        
return delayBeforeFirstCheck;
    }

    
public void setDelayBeforeFirstCheck(int delayBeforeFirstCheck) {
        
this.delayBeforeFirstCheck = delayBeforeFirstCheck;
    }

    
public int getDisplayRotationInterval() {
        
return displayRotationInterval;
    }

    
public void setDisplayRotationInterval(int displayRotationInterval) {
        
this.displayRotationInterval = displayRotationInterval;
    }

    
public String getPassword() {
        
return password;
    }

    
public void setPassword(String password) {
        
this.password = password;
    }

    
public int getPort() {
        
return port;
    }

    
public void setPort(int port) {
        
this.port = port;
    }

    
public boolean isUseProxy() {
        
return useProxy;
    }

    
public void setUseProxy(boolean useProxy) {
        
this.useProxy = useProxy;
    }

    
public String getUserName() {
        
return userName;
    }

    
public void setUserName(String userName) {
        
this.userName = userName;
    }

    
public boolean isVoiceOn() {
        
return voiceOn;
    }

    
public void setVoiceOn(boolean voiceOn) {
        
this.voiceOn = voiceOn;
    }
    
//</editor-fold>
}

 

/*
 * @(#)GmailSettingManager.java
 * Author: 88250 <[email protected]>, 
http://blog.csdn.net/DL88250
 * Created on May 19, 2008, 9:18:48 PM
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
*/
package cn.edu.ynu.sei.gmailnotifier.common;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.Repository;

/**
 * Gmail Notifier settins manager. 
 * 
@author 88250 <[email protected]>, http://blog.csdn.net/DL88250
 * 
@version 1.0.0.8, May 21, 2008
 
*/
public class GmailSettingManager {

    FileObject folderObject 
= null;
    FileObject SettingFile 
= null;
    GmailSetting gSetting 
= new GmailSetting();
    FileLock lock 
= null;

   
/**
    * Default constructor.
    
*/
    
public GmailSettingManager() {
        folderObject 
= Repository.getDefault().getDefaultFileSystem().getRoot().
                getFileObject(
"GmailNotifierSettings");
        
if (folderObject == null) {
            
try {
                folderObject 
= Repository.getDefault().getDefaultFileSystem().
                        getRoot().createFolder(
"GmailNotifierSettings");
                storeSettings(gSetting);
            } 
catch (IOException ex) {
                ex.printStackTrace();
            
// TODO file can not be created , do something about it
            }
        }
    }

    
/**
     * Store the gmail notifier settings.
     * 
@param GmailSettings gmail settings
     * 
@return if store successfully, return <code>true</code>,
     * otherwise, return <code>false</code>
     
*/
    
public boolean storeSettings(GmailSetting settings) {
        
try {
            
if (folderObject.getFileObject("GmailNotifier""Cfg"== null) {
                SettingFile 
= folderObject.createData("GmailNotifier""Cfg");
            }
            SettingFile 
= folderObject.getFileObject("GmailNotifier""Cfg");

            lock 
= SettingFile.lock();
            
// serialize
            ObjectOutputStream objectOutStr = new ObjectOutputStream(
                    SettingFile.getOutputStream(lock));

            objectOutStr.writeObject(settings);
            objectOutStr.close();
            lock.releaseLock();
        } 
catch (IOException ex) {
            
// TODO file can not be created , do something about it
            ex.printStackTrace();
            
return false;
        }
        
return true;
    }

    
/**
     * Retrieve gmail notifier settings.
     * 
@return gmail settings
     
*/
    
public GmailSetting retrieveSettings() {
        SettingFile 
= folderObject.getFileObject("GmailNotifier""Cfg");
        
try {
            
// unserialize
            ObjectInputStream objectInStr = new ObjectInputStream(SettingFile.
                    getInputStream());
            gSetting 
= (GmailSetting) objectInStr.readObject();
            objectInStr.close();
        } 
catch (IOException ex) {
            ex.printStackTrace();
            
return null;
        } 
catch (ClassNotFoundException ex) {
            ex.printStackTrace();
            
return null;
        }
        
return gSetting;
    }
}

 

/*
 * @(#)GmailBox.java
 * Author: 88250 <[email protected]>, 
http://blog.csdn.net/DL88250
 * Created on May 21, 2008, 11:15:50 AM
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
*/
package cn.edu.ynu.sei.gmailnotifier.common;

/**
 * A mail message description. It contains the following information: 
 * <p>
 * <ol>
 * <li>Subject</li>
 * <li>Content (snip)</li>
 * </ol>
 * </p>
 * 
@author 88250 <[email protected]>, http://blog.csdn.net/DL88250
 * 
@version 1.0.0.0, May 21, 2008
 
*/
public class Mail {

    
private String subject;
    
private String content;

    
/**
     * Constructor with parameters.
     * 
@param subject mail subject
     * 
@param content mail content
     
*/
    
public Mail(String subject, String content) {
        
this.subject = subject;
        
this.content = content;
    }

    
//<editor-fold defaultstate="collapsed" desc="Getters & Setters">
    public String getContent() {
        
return content;
    }

    
public void setContent(String content) {
        
this.content = content;
    }

    
public String getSubject() {
        
return subject;
    }

    
public void setSubject(String subject) {
        
this.subject = subject;
    }
    
//</editor-fold>
}

 

厄。。。。。。。