这几天写了一个NetBeans的插件——Gmail Notifier : -)。偶的Ubuntu上不了网。。。。只能在Windows下测试了。。。。
先看下解图:
OK,源代码:
/*
*@(#)GmailNotifierAction.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay18,2008,7:47:18PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-1307,USA.
*/
package cn.edu.ynu.sei.gmailnotifier;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CallableSystemAction;
/**
*GmailNotifierAction.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.0,May18,2008
*/
public final class GmailNotifierAction extends CallableSystemAction{
private static final long serialVersionUID = 1L ;
GmailNotifierPanelgChecker = new GmailNotifierPanel();
public void performAction(){
gChecker.forceCheck();
}
public StringgetName(){
return NbBundle.getMessage(GmailNotifierAction. class ,
" CTL_GmailNotifierAction " );
}
public HelpCtxgetHelpCtx(){
return HelpCtx.DEFAULT_HELP;
}
@Override
protected boolean asynchronous(){
return false ;
}
@Override
public java.awt.ComponentgetToolbarPresenter(){
return gChecker;
}
}
*@(#)GmailNotifierAction.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay18,2008,7:47:18PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-1307,USA.
*/
package cn.edu.ynu.sei.gmailnotifier;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CallableSystemAction;
/**
*GmailNotifierAction.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.0,May18,2008
*/
public final class GmailNotifierAction extends CallableSystemAction{
private static final long serialVersionUID = 1L ;
GmailNotifierPanelgChecker = new GmailNotifierPanel();
public void performAction(){
gChecker.forceCheck();
}
public StringgetName(){
return NbBundle.getMessage(GmailNotifierAction. class ,
" CTL_GmailNotifierAction " );
}
public HelpCtxgetHelpCtx(){
return HelpCtx.DEFAULT_HELP;
}
@Override
protected boolean asynchronous(){
return false ;
}
@Override
public java.awt.ComponentgetToolbarPresenter(){
return gChecker;
}
}
/*
*@(#)GmailNotifierOptionsCategory.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay18,2008,11:25:57PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-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;
/**
*GmailNotifiersettingspanel'scategory.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.1,May18,2008
*/
public class GmailNotifierOptionsCategory extends OptionsCategory{
public OptionsPanelControllercreate(){
return new GmailNotifierSettingsPanelController();
}
public StringgetCategoryName(){
return NbBundle.getMessage(GmailNotifierOptionsCategory. class ,
" OptionsCategory_Name_Gmailnotifier " );
}
public StringgetTitle(){
return NbBundle.getMessage(GmailNotifierOptionsCategory. class ,
" OptionsCategory_Title_Gmailnotifier " );
}
@Override
public IcongetIcon(){
return new ImageIcon(Utilities.loadImage(
" cn/edu/ynu/sei/gmailnotifier/gm-logo-settings.png " ));
}
}
*@(#)GmailNotifierOptionsCategory.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay18,2008,11:25:57PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-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;
/**
*GmailNotifiersettingspanel'scategory.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.1,May18,2008
*/
public class GmailNotifierOptionsCategory extends OptionsCategory{
public OptionsPanelControllercreate(){
return new GmailNotifierSettingsPanelController();
}
public StringgetCategoryName(){
return NbBundle.getMessage(GmailNotifierOptionsCategory. class ,
" OptionsCategory_Name_Gmailnotifier " );
}
public StringgetTitle(){
return NbBundle.getMessage(GmailNotifierOptionsCategory. class ,
" OptionsCategory_Title_Gmailnotifier " );
}
@Override
public IcongetIcon(){
return new ImageIcon(Utilities.loadImage(
" cn/edu/ynu/sei/gmailnotifier/gm-logo-settings.png " ));
}
}
/*
*@(#)GmailNotifierPanel.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay18,2008,9:10:24PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-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;
/**
*Gmailcheckerpanel.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.2.7,May21,2008
*/
public class GmailNotifierPanel extends javax.swing.JPanel{
private static final long serialVersionUID = 1L ;
// <editor-folddefaultstate="collapsed"desc="variables-consts">
private GmailBoxmailBox = null ;
private GmailBoxManagergmHelper = null ;
private GmailSettingsettings = null ;
private GmailSettingManagersettingsManager = null ;
private int subjectCount = 0 ;
private TimermailNotifierTimer;
private TimershowSubjectIntervalTimer;
private StringconnectingTo = " <html><b>ConnectingToGmail...</b></html> " ;
private StringretrivingUserCountInfo =
" <html><b>RetrievingUsageandCountInformation...</b></html> " ;
// TODOprivateStringusagePercent="UsagePercentIs:";
private StringnewMailsCount = " TotalNewMailsIs: " ;
private StringnoActiveConnection =
" <html><b>NoActiveConnectionorConnectionIsNotUsable...</b></html> " ;
private StringinitiateString =
" <html>GmailcheckerModule....<b>Disconnected</b></HTML> " ;
private StringtooltipString =
" <html><b>Left</b>clickwillopentheGmailinyourwebbrowser<br> " +
" <b>Right</b>clickwillcheckyournewmails<br> HaveFun:-) </html> " ;
private StringRetriving_emails_info =
" <html><b>Retrievinge-mailHeaders...</b></html> " ;
// </editor-fold>
/**
*Checkmailbox.
* @return
*/
public boolean doCheckMail(){
// <editor-folddefaultstate="collapsed"desc="runnablesforgmHelpercalling">
RunnableconnectRun = new Runnable(){
public void run(){
if (gmHelper.connect()){
mailBox = gmHelper.getMailBox();
} else {
jLabel1.setText(noActiveConnection);
}
}
};
RunnablenewSubjectsCount = new Runnable(){
public void run(){
subjectCount = mailBox.getSubjectsCount();
if (subjectCount > 0 ){
playSound( " notify " );
}
}
};
// </editor-fold>
ProgressHandleProgHandl = 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 " );
}
// TODOalways33%?:-)
ProgHandl.progress(Retriving_emails_info, 33 );
ProgHandl.progress( 33 );
ProgHandl.finish();
return true ;
}
}
/**
*Initializeagmailmanager
* @see { @link #gmHelper}
*/
private void newGmailManager(){
gmHelper = new GmailBoxManager(settings.getUserName(),settings.getPassword(),settings.getProxy(),settings.getPort());
}
/**
*Resetinformationtogmailmanager.
*/
private void resetGmailManager(){
gmHelper.userName = settings.getUserName();
gmHelper.userPassword = settings.getPassword();
gmHelper.proxyHost = settings.getProxy();
gmHelper.port = settings.getPort();
}
/**
*Displaymailsinformation.
*/
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 );
}
/**
*Gettingstartcheckmail.
* @param delayBeforeStartCheckdelay(second)beforegettingstartcheck
*/
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 );
}
/**
*Defaultconstructor.
*/
public GmailNotifierPanel(){
initComponents();
jLabel1.setText(initiateString);
jLabel1.setToolTipText(tooltipString);
settingsManager = new GmailSettingManager();
settings = settingsManager.retrieveSettings();
startCheck(settings.getDelayBeforeFirstCheck());
}
/**
*Playsound.
* @param soundNamesoundfilename
*/
private void playSound(StringsoundName){
if (settings.isVoiceOn()){
AudioClipClip;
URLUrl;
try {
Url = getClass().getResource(
" /cn/edu/ynu/sei/gmailnotifier/ " +
soundName + " .wav " );
Clip = Applet.newAudioClip(Url);
Clip.play();
} catch (Exceptione){
System.err.println(e.getMessage());
}
}
}
/**
*Setmailcountfordisplay.
* @param countmailcount
*/
private void setCount( int count){
this .jLabel1.setText( " <html> " + newMailsCount +
" <b><fontcolor="blue"> " + count + " </font></b></html> " );
}
/**
*Setthelabel'sicon.
* @param iconNameiconname
*/
private void setIcon(StringiconName){
jLabel1.setIcon( new javax.swing.ImageIcon(getClass().getResource( " /cn/edu/ynu/sei/gmailnotifier/ " + iconName + " .png " ))); // NOI18N
}
/** Thismethodiscalledfromwithintheconstructorto
*initializetheform.
*WARNING:DoNOTmodifythiscode.Thecontentofthismethodis
*alwaysregeneratedbytheFormEditor.
*/
// <editor-folddefaultstate="collapsed"desc="GeneratedCode">
private void initComponents(){
jLabel1 = new javax.swing.JLabel();
setAlignmentY( 0.0F );
setOpaque( false );
jLabel1.setFont( new java.awt.Font( " Tahoma " , 0 , 10 )); // 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>GmailNotifierModule....<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( 227 , 22 ));
jLabel1.setSize( new java.awt.Dimension( 227 , 22 ));
jLabel1.addMouseListener( new java.awt.event.MouseAdapter(){
public void mouseClicked(java.awt.event.MouseEventevt){
jLabel1MouseClicked(evt);
}
public void mouseEntered(java.awt.event.MouseEventevt){
jLabel1MouseEntered(evt);
}
});
org.jdesktop.layout.GroupLayoutlayout = 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>
/**
*Getnewmailssubjectsnip.
* @param subjectNosubjectnumber
* @return mailsubjectsnip
*/
private StringgetSubjectSnip( int subjectNo){
Stringsubj = mailBox.getMails().get(subjectNo).getSubject();
return subj.length() > 40 ? (subj.substring( 0 , 40 ) + " .... " ):subj;
}
// TODOgetContentSnip
/**
*Getnewmailscontentsnip.
* @param subjectNosubjectnumber
* @return mailcontentsnip
*/
private StringgetContentSnip( int subjectNo){
Stringcont = mailBox.getMails().get(subjectNo).getContent();
return cont.length() > 100 ? (cont.substring( 0 , 100 ) + " .... " ):cont;
}
private void jLabel1MouseClicked(java.awt.event.MouseEventevt){
// leftclicked
if (evt.getModifiers() == MouseEvent.BUTTON1_MASK){
GmailBoxManager.openURL( " http://www.gmail.com " );
}
// rightclicked
if (evt.getModifiers() == MouseEvent.BUTTON3_MASK){
forceCheck();
}
}
private void jLabel1MouseEntered(java.awt.event.MouseEventevt){
if (mailBox.getSubjectsCount() != 0 ){
StringBuildersnips = new StringBuilder();
for ( int i = 0 ;i < subjectCount;i ++ ){
snips.append( " <html><b> " + (i + 1 ) + " </b>: " +
" <fontcolor="blue"> " +
getSubjectSnip(i) +
" </font><br> " );
// snips.append(""+getContentSnip(i)+"<br>");
// snips.append("---<br>");
}
snips.append( " </html> " );
jLabel1.setToolTipText(snips.toString());
} else {
jLabel1.setToolTipText(tooltipString);
}
}
// Variablesdeclaration-donotmodify
public javax.swing.JLabeljLabel1;
// Endofvariablesdeclaration
/**
*Checkmailinboxbyforce.
*/
public void forceCheck(){
if (showSubjectIntervalTimer != null ){
showSubjectIntervalTimer.cancel();
}
if (mailNotifierTimer != null ){
mailNotifierTimer.cancel();
}
startCheck( 0 );
}
}
*@(#)GmailNotifierPanel.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay18,2008,9:10:24PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-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;
/**
*Gmailcheckerpanel.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.2.7,May21,2008
*/
public class GmailNotifierPanel extends javax.swing.JPanel{
private static final long serialVersionUID = 1L ;
// <editor-folddefaultstate="collapsed"desc="variables-consts">
private GmailBoxmailBox = null ;
private GmailBoxManagergmHelper = null ;
private GmailSettingsettings = null ;
private GmailSettingManagersettingsManager = null ;
private int subjectCount = 0 ;
private TimermailNotifierTimer;
private TimershowSubjectIntervalTimer;
private StringconnectingTo = " <html><b>ConnectingToGmail...</b></html> " ;
private StringretrivingUserCountInfo =
" <html><b>RetrievingUsageandCountInformation...</b></html> " ;
// TODOprivateStringusagePercent="UsagePercentIs:";
private StringnewMailsCount = " TotalNewMailsIs: " ;
private StringnoActiveConnection =
" <html><b>NoActiveConnectionorConnectionIsNotUsable...</b></html> " ;
private StringinitiateString =
" <html>GmailcheckerModule....<b>Disconnected</b></HTML> " ;
private StringtooltipString =
" <html><b>Left</b>clickwillopentheGmailinyourwebbrowser<br> " +
" <b>Right</b>clickwillcheckyournewmails<br> HaveFun:-) </html> " ;
private StringRetriving_emails_info =
" <html><b>Retrievinge-mailHeaders...</b></html> " ;
// </editor-fold>
/**
*Checkmailbox.
* @return
*/
public boolean doCheckMail(){
// <editor-folddefaultstate="collapsed"desc="runnablesforgmHelpercalling">
RunnableconnectRun = new Runnable(){
public void run(){
if (gmHelper.connect()){
mailBox = gmHelper.getMailBox();
} else {
jLabel1.setText(noActiveConnection);
}
}
};
RunnablenewSubjectsCount = new Runnable(){
public void run(){
subjectCount = mailBox.getSubjectsCount();
if (subjectCount > 0 ){
playSound( " notify " );
}
}
};
// </editor-fold>
ProgressHandleProgHandl = 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 " );
}
// TODOalways33%?:-)
ProgHandl.progress(Retriving_emails_info, 33 );
ProgHandl.progress( 33 );
ProgHandl.finish();
return true ;
}
}
/**
*Initializeagmailmanager
* @see { @link #gmHelper}
*/
private void newGmailManager(){
gmHelper = new GmailBoxManager(settings.getUserName(),settings.getPassword(),settings.getProxy(),settings.getPort());
}
/**
*Resetinformationtogmailmanager.
*/
private void resetGmailManager(){
gmHelper.userName = settings.getUserName();
gmHelper.userPassword = settings.getPassword();
gmHelper.proxyHost = settings.getProxy();
gmHelper.port = settings.getPort();
}
/**
*Displaymailsinformation.
*/
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 );
}
/**
*Gettingstartcheckmail.
* @param delayBeforeStartCheckdelay(second)beforegettingstartcheck
*/
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 );
}
/**
*Defaultconstructor.
*/
public GmailNotifierPanel(){
initComponents();
jLabel1.setText(initiateString);
jLabel1.setToolTipText(tooltipString);
settingsManager = new GmailSettingManager();
settings = settingsManager.retrieveSettings();
startCheck(settings.getDelayBeforeFirstCheck());
}
/**
*Playsound.
* @param soundNamesoundfilename
*/
private void playSound(StringsoundName){
if (settings.isVoiceOn()){
AudioClipClip;
URLUrl;
try {
Url = getClass().getResource(
" /cn/edu/ynu/sei/gmailnotifier/ " +
soundName + " .wav " );
Clip = Applet.newAudioClip(Url);
Clip.play();
} catch (Exceptione){
System.err.println(e.getMessage());
}
}
}
/**
*Setmailcountfordisplay.
* @param countmailcount
*/
private void setCount( int count){
this .jLabel1.setText( " <html> " + newMailsCount +
" <b><fontcolor="blue"> " + count + " </font></b></html> " );
}
/**
*Setthelabel'sicon.
* @param iconNameiconname
*/
private void setIcon(StringiconName){
jLabel1.setIcon( new javax.swing.ImageIcon(getClass().getResource( " /cn/edu/ynu/sei/gmailnotifier/ " + iconName + " .png " ))); // NOI18N
}
/** Thismethodiscalledfromwithintheconstructorto
*initializetheform.
*WARNING:DoNOTmodifythiscode.Thecontentofthismethodis
*alwaysregeneratedbytheFormEditor.
*/
// <editor-folddefaultstate="collapsed"desc="GeneratedCode">
private void initComponents(){
jLabel1 = new javax.swing.JLabel();
setAlignmentY( 0.0F );
setOpaque( false );
jLabel1.setFont( new java.awt.Font( " Tahoma " , 0 , 10 )); // 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>GmailNotifierModule....<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( 227 , 22 ));
jLabel1.setSize( new java.awt.Dimension( 227 , 22 ));
jLabel1.addMouseListener( new java.awt.event.MouseAdapter(){
public void mouseClicked(java.awt.event.MouseEventevt){
jLabel1MouseClicked(evt);
}
public void mouseEntered(java.awt.event.MouseEventevt){
jLabel1MouseEntered(evt);
}
});
org.jdesktop.layout.GroupLayoutlayout = 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>
/**
*Getnewmailssubjectsnip.
* @param subjectNosubjectnumber
* @return mailsubjectsnip
*/
private StringgetSubjectSnip( int subjectNo){
Stringsubj = mailBox.getMails().get(subjectNo).getSubject();
return subj.length() > 40 ? (subj.substring( 0 , 40 ) + " .... " ):subj;
}
// TODOgetContentSnip
/**
*Getnewmailscontentsnip.
* @param subjectNosubjectnumber
* @return mailcontentsnip
*/
private StringgetContentSnip( int subjectNo){
Stringcont = mailBox.getMails().get(subjectNo).getContent();
return cont.length() > 100 ? (cont.substring( 0 , 100 ) + " .... " ):cont;
}
private void jLabel1MouseClicked(java.awt.event.MouseEventevt){
// leftclicked
if (evt.getModifiers() == MouseEvent.BUTTON1_MASK){
GmailBoxManager.openURL( " http://www.gmail.com " );
}
// rightclicked
if (evt.getModifiers() == MouseEvent.BUTTON3_MASK){
forceCheck();
}
}
private void jLabel1MouseEntered(java.awt.event.MouseEventevt){
if (mailBox.getSubjectsCount() != 0 ){
StringBuildersnips = new StringBuilder();
for ( int i = 0 ;i < subjectCount;i ++ ){
snips.append( " <html><b> " + (i + 1 ) + " </b>: " +
" <fontcolor="blue"> " +
getSubjectSnip(i) +
" </font><br> " );
// snips.append(""+getContentSnip(i)+"<br>");
// snips.append("---<br>");
}
snips.append( " </html> " );
jLabel1.setToolTipText(snips.toString());
} else {
jLabel1.setToolTipText(tooltipString);
}
}
// Variablesdeclaration-donotmodify
public javax.swing.JLabeljLabel1;
// Endofvariablesdeclaration
/**
*Checkmailinboxbyforce.
*/
public void forceCheck(){
if (showSubjectIntervalTimer != null ){
showSubjectIntervalTimer.cancel();
}
if (mailNotifierTimer != null ){
mailNotifierTimer.cancel();
}
startCheck( 0 );
}
}
/*
*@(#)GmailNotifierSettingsPanel.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay18,2008,11:25:57PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-1307,USA.
*/
package cn.edu.ynu.sei.gmailnotifier;
import cn.edu.ynu.sei.gmailnotifier.common.GmailSetting;
import javax.swing.SpinnerNumberModel;
/**
*GmailNotifiersettingspanel.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.2,May21,2008
*/
public class GmailNotifierSettingsPanel extends javax.swing.JPanel{
private static final long serialVersionUID = 1L ;
public boolean isChanged = false ;
/**
*Defaultconstructor.
*/
public GmailNotifierSettingsPanel(){
initComponents();
}
/**
*SetallsettingsinUI.
* @param settinggmailsettings
*/
public void populateUI(GmailSettingsetting){
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 ;
}
/**
*Retieveallsettings.
* @return gmailsettings
*/
public GmailSettingreturnSetting(){
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());
}
/** Thismethodiscalledfromwithintheconstructorto
*initializetheform.
*WARNING:DoNOTmodifythiscode.Thecontentofthismethodis
*alwaysregeneratedbytheFormEditor.
*/
// <editor-folddefaultstate="collapsed"desc="GeneratedCode">
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( " GeneralOptions " ));
jTextField1.addPropertyChangeListener( new java.beans.PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
jPasswordField1.addPropertyChangeListener( new java.beans.PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
jCheckBox1.setText( " Enablesounds " );
jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder( 0 , 0 , 0 , 0 ));
jCheckBox1.setMargin( new java.awt.Insets( 0 , 0 , 0 , 0 ));
jCheckBox1.addPropertyChangeListener( new java.beans.PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
jLabel1.setText( " Username " );
jLabel2.setText( " Password " );
org.jdesktop.layout.GroupLayoutjPanel1Layout = 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( 132 , 132 , 132 ))
);
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( 16 , 16 , 16 )
.add(jLabel2))
.add(jPanel1Layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPasswordField1,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 30 ,Short.MAX_VALUE)))
.add( 17 , 17 , 17 )
.add(jCheckBox1))
);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder( " AdvancedOptions " ));
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder( " ProxySettings " ));
jPanel3.setName( " ProxySettings " ); // NOI18N
jTextField2.addPropertyChangeListener( new java.beans.PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
jLabel9.setText( " Host: " );
jLabel10.setText( " Port: " );
jTextField3.addPropertyChangeListener( new java.beans.PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
jCheckBox3.setText( " Connectviaproxy " );
jCheckBox3.setBorder(javax.swing.BorderFactory.createEmptyBorder( 0 , 0 , 0 , 0 ));
jCheckBox3.setMargin( new java.awt.Insets( 0 , 0 , 0 , 0 ));
jCheckBox3.addPropertyChangeListener( new java.beans.PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
org.jdesktop.layout.GroupLayoutjPanel3Layout = 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( 18 , 18 , 18 )
.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( 14 , 14 , 14 )
.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( 20 , 20 , 20 ))
);
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.PropertyChangeEventevt){
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.PropertyChangeEventevt){
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.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
jLabel3.setText( " Seconds " );
jLabel4.setText( " Minutes " );
jLabel5.setText( " Seconds " );
jLabel6.setText( " Delaybeforefirstmailcheck: " );
jLabel7.setText( " Mailcheckinterval: " );
jLabel8.setText( " Rotationdelay: " );
org.jdesktop.layout.GroupLayoutjPanel2Layout = 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( 18 , 18 , 18 )
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel6)
.add(jLabel7)
.add(jLabel8))
.add( 18 , 18 , 18 )
.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( 18 , 18 , 18 )
.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( 15 , 15 , 15 )
.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( 14 , 14 , 14 )
.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( 45 , 45 , 45 )
.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.GroupLayoutlayout = 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>
/**
*Propertychangeeventhandle.
* @param evtpropertychangevnt
*/
private void propertyChange(java.beans.PropertyChangeEventevt){
isChanged = true ;
}
// Variablesdeclaration-donotmodify
private javax.swing.JCheckBoxjCheckBox1;
private javax.swing.JCheckBoxjCheckBox3;
private javax.swing.JLabeljLabel1;
private javax.swing.JLabeljLabel10;
private javax.swing.JLabeljLabel2;
private javax.swing.JLabeljLabel3;
private javax.swing.JLabeljLabel4;
private javax.swing.JLabeljLabel5;
private javax.swing.JLabeljLabel6;
private javax.swing.JLabeljLabel7;
private javax.swing.JLabeljLabel8;
private javax.swing.JLabeljLabel9;
private javax.swing.JPaneljPanel1;
private javax.swing.JPaneljPanel2;
private javax.swing.JPaneljPanel3;
private javax.swing.JPasswordFieldjPasswordField1;
private javax.swing.JSpinnerjSpinner1;
private javax.swing.JSpinnerjSpinner2;
private javax.swing.JSpinnerjSpinner3;
private javax.swing.JTextFieldjTextField1;
private javax.swing.JTextFieldjTextField2;
private javax.swing.JTextFieldjTextField3;
// Endofvariablesdeclaration
}
*@(#)GmailNotifierSettingsPanel.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay18,2008,11:25:57PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-1307,USA.
*/
package cn.edu.ynu.sei.gmailnotifier;
import cn.edu.ynu.sei.gmailnotifier.common.GmailSetting;
import javax.swing.SpinnerNumberModel;
/**
*GmailNotifiersettingspanel.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.2,May21,2008
*/
public class GmailNotifierSettingsPanel extends javax.swing.JPanel{
private static final long serialVersionUID = 1L ;
public boolean isChanged = false ;
/**
*Defaultconstructor.
*/
public GmailNotifierSettingsPanel(){
initComponents();
}
/**
*SetallsettingsinUI.
* @param settinggmailsettings
*/
public void populateUI(GmailSettingsetting){
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 ;
}
/**
*Retieveallsettings.
* @return gmailsettings
*/
public GmailSettingreturnSetting(){
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());
}
/** Thismethodiscalledfromwithintheconstructorto
*initializetheform.
*WARNING:DoNOTmodifythiscode.Thecontentofthismethodis
*alwaysregeneratedbytheFormEditor.
*/
// <editor-folddefaultstate="collapsed"desc="GeneratedCode">
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( " GeneralOptions " ));
jTextField1.addPropertyChangeListener( new java.beans.PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
jPasswordField1.addPropertyChangeListener( new java.beans.PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
jCheckBox1.setText( " Enablesounds " );
jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder( 0 , 0 , 0 , 0 ));
jCheckBox1.setMargin( new java.awt.Insets( 0 , 0 , 0 , 0 ));
jCheckBox1.addPropertyChangeListener( new java.beans.PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
jLabel1.setText( " Username " );
jLabel2.setText( " Password " );
org.jdesktop.layout.GroupLayoutjPanel1Layout = 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( 132 , 132 , 132 ))
);
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( 16 , 16 , 16 )
.add(jLabel2))
.add(jPanel1Layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPasswordField1,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 30 ,Short.MAX_VALUE)))
.add( 17 , 17 , 17 )
.add(jCheckBox1))
);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder( " AdvancedOptions " ));
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder( " ProxySettings " ));
jPanel3.setName( " ProxySettings " ); // NOI18N
jTextField2.addPropertyChangeListener( new java.beans.PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
jLabel9.setText( " Host: " );
jLabel10.setText( " Port: " );
jTextField3.addPropertyChangeListener( new java.beans.PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
jCheckBox3.setText( " Connectviaproxy " );
jCheckBox3.setBorder(javax.swing.BorderFactory.createEmptyBorder( 0 , 0 , 0 , 0 ));
jCheckBox3.setMargin( new java.awt.Insets( 0 , 0 , 0 , 0 ));
jCheckBox3.addPropertyChangeListener( new java.beans.PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
org.jdesktop.layout.GroupLayoutjPanel3Layout = 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( 18 , 18 , 18 )
.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( 14 , 14 , 14 )
.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( 20 , 20 , 20 ))
);
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.PropertyChangeEventevt){
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.PropertyChangeEventevt){
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.PropertyChangeEventevt){
GmailNotifierSettingsPanel. this .propertyChange(evt);
}
});
jLabel3.setText( " Seconds " );
jLabel4.setText( " Minutes " );
jLabel5.setText( " Seconds " );
jLabel6.setText( " Delaybeforefirstmailcheck: " );
jLabel7.setText( " Mailcheckinterval: " );
jLabel8.setText( " Rotationdelay: " );
org.jdesktop.layout.GroupLayoutjPanel2Layout = 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( 18 , 18 , 18 )
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel6)
.add(jLabel7)
.add(jLabel8))
.add( 18 , 18 , 18 )
.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( 18 , 18 , 18 )
.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( 15 , 15 , 15 )
.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( 14 , 14 , 14 )
.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( 45 , 45 , 45 )
.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.GroupLayoutlayout = 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>
/**
*Propertychangeeventhandle.
* @param evtpropertychangevnt
*/
private void propertyChange(java.beans.PropertyChangeEventevt){
isChanged = true ;
}
// Variablesdeclaration-donotmodify
private javax.swing.JCheckBoxjCheckBox1;
private javax.swing.JCheckBoxjCheckBox3;
private javax.swing.JLabeljLabel1;
private javax.swing.JLabeljLabel10;
private javax.swing.JLabeljLabel2;
private javax.swing.JLabeljLabel3;
private javax.swing.JLabeljLabel4;
private javax.swing.JLabeljLabel5;
private javax.swing.JLabeljLabel6;
private javax.swing.JLabeljLabel7;
private javax.swing.JLabeljLabel8;
private javax.swing.JLabeljLabel9;
private javax.swing.JPaneljPanel1;
private javax.swing.JPaneljPanel2;
private javax.swing.JPaneljPanel3;
private javax.swing.JPasswordFieldjPasswordField1;
private javax.swing.JSpinnerjSpinner1;
private javax.swing.JSpinnerjSpinner2;
private javax.swing.JSpinnerjSpinner3;
private javax.swing.JTextFieldjTextField1;
private javax.swing.JTextFieldjTextField2;
private javax.swing.JTextFieldjTextField3;
// Endofvariablesdeclaration
}
/*
*@(#)GmailNotifierSettingsPanelController.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay18,2008,11:25:57PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-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;
/**
*GmailNotifiersettingspanel'scontroller.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.3,May21,2008
*/
public class GmailNotifierSettingsPanelController extends OptionsPanelController{
private GmailNotifierSettingsPanelsettingPanel =
new GmailNotifierSettingsPanel();
private GmailSettingManagersettingManager = new GmailSettingManager();
private StringsureTocancle =
" <html><b>doyouwanttosavethechangesthatyoumade " +
" intoGmailsettingDialog?</b><html> " ;
public void applyChanges(){
if (settingPanel.isChanged){
settingManager.storeSettings(settingPanel.returnSetting());
settingPanel.isChanged = false ;
}
}
public void cancel(){
if (settingPanel.isChanged){
DialogDescriptorddesc = new DialogDescriptor((Object)sureTocancle,
" Changeswilllost " ,
true ,DialogDescriptor.YES_NO_OPTION,
DialogDescriptor.CANCEL_OPTION, new ActionListener(){
public void actionPerformed(ActionEvente){
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 JComponentgetComponent(LookupmasterLookup){
return settingPanel;
}
public HelpCtxgetHelpCtx(){
return HelpCtx.DEFAULT_HELP;
}
public void update(){
settingPanel.populateUI(settingManager.retrieveSettings());
}
public void addPropertyChangeListener(PropertyChangeListenerl){
}
public void removePropertyChangeListener(PropertyChangeListenerl){
}
}
*@(#)GmailNotifierSettingsPanelController.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay18,2008,11:25:57PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-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;
/**
*GmailNotifiersettingspanel'scontroller.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.3,May21,2008
*/
public class GmailNotifierSettingsPanelController extends OptionsPanelController{
private GmailNotifierSettingsPanelsettingPanel =
new GmailNotifierSettingsPanel();
private GmailSettingManagersettingManager = new GmailSettingManager();
private StringsureTocancle =
" <html><b>doyouwanttosavethechangesthatyoumade " +
" intoGmailsettingDialog?</b><html> " ;
public void applyChanges(){
if (settingPanel.isChanged){
settingManager.storeSettings(settingPanel.returnSetting());
settingPanel.isChanged = false ;
}
}
public void cancel(){
if (settingPanel.isChanged){
DialogDescriptorddesc = new DialogDescriptor((Object)sureTocancle,
" Changeswilllost " ,
true ,DialogDescriptor.YES_NO_OPTION,
DialogDescriptor.CANCEL_OPTION, new ActionListener(){
public void actionPerformed(ActionEvente){
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 JComponentgetComponent(LookupmasterLookup){
return settingPanel;
}
public HelpCtxgetHelpCtx(){
return HelpCtx.DEFAULT_HELP;
}
public void update(){
settingPanel.populateUI(settingManager.retrieveSettings());
}
public void addPropertyChangeListener(PropertyChangeListenerl){
}
public void removePropertyChangeListener(PropertyChangeListenerl){
}
}
/*
*@(#)GmailBox.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay19,2008,10:6:39AM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-1307,USA.
*/
package cn.edu.ynu.sei.gmailnotifier.common;
import java.util.ArrayList;
import java.util.List;
/**
*Gmailmailboxinformation.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.5,May21,2008
*/
public class GmailBox{
private List < Mail > mails = new ArrayList < Mail > ();
/**
*Defaultconsturctor.
*/
public GmailBox(){
}
/**
*Constructorwithparameters.
* @param newMailCountnewmailcount
*/
public GmailBox(List < Mail > mails){
this .setMails(mails);
}
// <editor-folddefaultstate="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<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay19,2008,10:6:39AM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-1307,USA.
*/
package cn.edu.ynu.sei.gmailnotifier.common;
import java.util.ArrayList;
import java.util.List;
/**
*Gmailmailboxinformation.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.5,May21,2008
*/
public class GmailBox{
private List < Mail > mails = new ArrayList < Mail > ();
/**
*Defaultconsturctor.
*/
public GmailBox(){
}
/**
*Constructorwithparameters.
* @param newMailCountnewmailcount
*/
public GmailBox(List < Mail > mails){
this .setMails(mails);
}
// <editor-folddefaultstate="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<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay17,2008,7:17:34PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-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;
/**
*Gmailmailboxmanager.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.2.6,May21,2008
*/
public class GmailBoxManager{
public StringuserName = " Username " ;
public StringuserPassword = " Password " ;
public StringproxyHost = " NoProxy " ;
public int port = 0 ;
private static Storestore;
/**
*Constructorwithparameters.
* @param userNameusername
* @param userPassworduserpassword
* @param proxyHostproxyhost
* @param portproxyport
*/
public GmailBoxManager(StringuserName,StringuserPassword,
StringproxyHost, int port){
this .userPassword = userPassword;
this .userName = userName;
this .proxyHost = proxyHost;
this .port = port;
}
/**
*Connecttothemailbox.
* @return ifconnectsuccessfully,return<code>true</code>,
*otherwise,return<code>false</code>
*/
public boolean connect(){
if ( ! proxyHost.equalsIgnoreCase( " NoProxy " )){
// TODOsetProxy(proxyHost,port);
} else {
if (store == null || ! store.isConnected()){
Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider());
final StringSSL_FACTORY = " javax.net.ssl.SSLSocketFactory " ;
Propertiesprops = 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 " );
Sessionsession = Session.getDefaultInstance(props, null );
session.setDebug( false ); // TODOresetdebugflag
URLNameurln = new URLName( " imap " , " imap.gmail.com " , 993 , null ,
userName,
userPassword);
// TODOavailablePOP3s!
// URLNameurln=newURLName("pop3s","pop.gmail.com",995,null,
// userName,userPassword);
try {
store = session.getStore(urln);
} catch (javax.mail.NoSuchProviderExceptionex){
System.err.println(ex.getMessage());
return false ;
}
try {
store.connect();
} catch (MessagingExceptionex){
System.err.println(ex.getMessage());
return false ;
}
}
}
return true ;
}
/**
*Isconnectedmailbox?
* @return ifconnected,return<code>true</code>,
*otherwise,return<code>false</code>
*/
public boolean isConnected(){
return store != null ? store.isConnected(): false ;
}
/**
*Getthenewmailboxinformation.
* @return mailbox
*/
public GmailBoxgetMailBox(){
if (store == null || ! store.isConnected()){
connect();
}
// TODOintusagePercent=0;
int newMailCount = 0 ;
List < Mail > mails = new ArrayList < Mail > ();
try {
Folderinbox = store.getFolder( " Inbox " );
inbox.open(Folder.READ_ONLY);
newMailCount = inbox.getUnreadMessageCount();
if (newMailCount != 0 ){
Message[]messages = inbox.getMessages( 1 ,newMailCount);
// weonlyfucusonmail,notmessage,sousingSet
// toignoretheduplicatesubjectmessages
Set < String > subjects = new HashSet < String > ();
for ( int i = 0 ;i < messages.length;i ++ ){
Stringsubject = messages[i].getSubject();
// TODOparsethemailbody
// Stringcontent=messages[i].getContent();
// Onlysubject
if (subject == null ){
subject = " nosubject " ;
}
subjects.add(subject);
}
for (Stringsub:subjects){
mails.add( new Mail(sub, "" /* content */ ));
}
return new GmailBox(mails);
} else {
System.err.println( " Noanynewmail! " );
}
} catch (Exceptionex){
System.err.println(ex.getMessage());
}
// returnemptymailbox
return new GmailBox();
}
/**
*Opentheurlinsystem'swebbrowser.
* @param urlthespecifiedurltoopen
*/
@SuppressWarnings(value = { " unchcked " })
public static void openURL(Stringurl){
StringosName = System.getProperty( " os.name " );
try {
if (osName.startsWith( " MacOS " )){
ClassfileMgr = Class.forName( " com.apple.eio.FileManager " );
@SuppressWarnings( " unchecked " )
MethodopenURL = fileMgr.getDeclaredMethod( " openURL " ,
new Class[]{String. class });
openURL.invoke( null , new Object[]{url});
} else if (osName.startsWith( " Windows " )){
Runtime.getRuntime().exec( " rundll32url.dll,FileProtocolHandler " +
url);
} else {
// assumeUnixorLinux
String[]browsers = {
" firefox " , " opera " , " konqueror " ,
" epiphany " , " mozilla " , " netscape "
};
Stringbrowser = 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( " Couldnotfindwebbrowser " );
} else {
Runtime.getRuntime().exec( new String[]{browser,url});
}
}
} catch (Exceptione){
JOptionPane.showMessageDialog( null ,
" Errorattemptingtolaunchwebbrowser " + " : " + e.getLocalizedMessage());
}
}
}
*@(#)GmailBox.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay17,2008,7:17:34PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-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;
/**
*Gmailmailboxmanager.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.2.6,May21,2008
*/
public class GmailBoxManager{
public StringuserName = " Username " ;
public StringuserPassword = " Password " ;
public StringproxyHost = " NoProxy " ;
public int port = 0 ;
private static Storestore;
/**
*Constructorwithparameters.
* @param userNameusername
* @param userPassworduserpassword
* @param proxyHostproxyhost
* @param portproxyport
*/
public GmailBoxManager(StringuserName,StringuserPassword,
StringproxyHost, int port){
this .userPassword = userPassword;
this .userName = userName;
this .proxyHost = proxyHost;
this .port = port;
}
/**
*Connecttothemailbox.
* @return ifconnectsuccessfully,return<code>true</code>,
*otherwise,return<code>false</code>
*/
public boolean connect(){
if ( ! proxyHost.equalsIgnoreCase( " NoProxy " )){
// TODOsetProxy(proxyHost,port);
} else {
if (store == null || ! store.isConnected()){
Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider());
final StringSSL_FACTORY = " javax.net.ssl.SSLSocketFactory " ;
Propertiesprops = 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 " );
Sessionsession = Session.getDefaultInstance(props, null );
session.setDebug( false ); // TODOresetdebugflag
URLNameurln = new URLName( " imap " , " imap.gmail.com " , 993 , null ,
userName,
userPassword);
// TODOavailablePOP3s!
// URLNameurln=newURLName("pop3s","pop.gmail.com",995,null,
// userName,userPassword);
try {
store = session.getStore(urln);
} catch (javax.mail.NoSuchProviderExceptionex){
System.err.println(ex.getMessage());
return false ;
}
try {
store.connect();
} catch (MessagingExceptionex){
System.err.println(ex.getMessage());
return false ;
}
}
}
return true ;
}
/**
*Isconnectedmailbox?
* @return ifconnected,return<code>true</code>,
*otherwise,return<code>false</code>
*/
public boolean isConnected(){
return store != null ? store.isConnected(): false ;
}
/**
*Getthenewmailboxinformation.
* @return mailbox
*/
public GmailBoxgetMailBox(){
if (store == null || ! store.isConnected()){
connect();
}
// TODOintusagePercent=0;
int newMailCount = 0 ;
List < Mail > mails = new ArrayList < Mail > ();
try {
Folderinbox = store.getFolder( " Inbox " );
inbox.open(Folder.READ_ONLY);
newMailCount = inbox.getUnreadMessageCount();
if (newMailCount != 0 ){
Message[]messages = inbox.getMessages( 1 ,newMailCount);
// weonlyfucusonmail,notmessage,sousingSet
// toignoretheduplicatesubjectmessages
Set < String > subjects = new HashSet < String > ();
for ( int i = 0 ;i < messages.length;i ++ ){
Stringsubject = messages[i].getSubject();
// TODOparsethemailbody
// Stringcontent=messages[i].getContent();
// Onlysubject
if (subject == null ){
subject = " nosubject " ;
}
subjects.add(subject);
}
for (Stringsub:subjects){
mails.add( new Mail(sub, "" /* content */ ));
}
return new GmailBox(mails);
} else {
System.err.println( " Noanynewmail! " );
}
} catch (Exceptionex){
System.err.println(ex.getMessage());
}
// returnemptymailbox
return new GmailBox();
}
/**
*Opentheurlinsystem'swebbrowser.
* @param urlthespecifiedurltoopen
*/
@SuppressWarnings(value = { " unchcked " })
public static void openURL(Stringurl){
StringosName = System.getProperty( " os.name " );
try {
if (osName.startsWith( " MacOS " )){
ClassfileMgr = Class.forName( " com.apple.eio.FileManager " );
@SuppressWarnings( " unchecked " )
MethodopenURL = fileMgr.getDeclaredMethod( " openURL " ,
new Class[]{String. class });
openURL.invoke( null , new Object[]{url});
} else if (osName.startsWith( " Windows " )){
Runtime.getRuntime().exec( " rundll32url.dll,FileProtocolHandler " +
url);
} else {
// assumeUnixorLinux
String[]browsers = {
" firefox " , " opera " , " konqueror " ,
" epiphany " , " mozilla " , " netscape "
};
Stringbrowser = 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( " Couldnotfindwebbrowser " );
} else {
Runtime.getRuntime().exec( new String[]{browser,url});
}
}
} catch (Exceptione){
JOptionPane.showMessageDialog( null ,
" Errorattemptingtolaunchwebbrowser " + " : " + e.getLocalizedMessage());
}
}
}
/*
*@(#)GmailSetting.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay19,2008,9:17:35AM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-1307,USA.
*/
package cn.edu.ynu.sei.gmailnotifier.common;
import java.io.Serializable;
/**
*GmailNotifiersettins.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.5,May21,2008
* @see Serializable
*/
public class GmailSetting implements Serializable{
private static final long serialVersionUID = 1L ;
private StringuserName = " Username " ;
private Stringpassword = " Password " ;
private boolean useProxy;
private StringProxy = " NoProxy " ;
private int port;
private int checkMailInterval = 5 ; // minute
private int displayRotationInterval = 5 ; // second
private int delayBeforeFirstCheck = 15 ; // second
private boolean voiceOn;
/**
*Constructorwithparameters.
* @param userNameusername
* @param passworduserpassword
* @param useProxyusingproxy?
* @param proxyproxyhostsetting("192.168.110.65")
* @param portproxyportsetting(808)
* @param delayBeforeFirstCheckdelaybeforefirstcheckafternetbeansluanched
* @param checkIntervalcheckmailinterval
* @param rotationIntervalrotationdisplayinterval
* @param voiceOnplaysoundwhenretrievingmails
*/
public GmailSetting(StringuserName,Stringpassword,
boolean useProxy,Stringproxy, 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);
}
/**
*Defaultconstructor.
*/
public GmailSetting(){
}
// <editor-folddefaultstate="collapsed"desc="getters&setters">
public StringgetProxy(){
return Proxy;
}
public void setProxy(StringProxy){
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 StringgetPassword(){
return password;
}
public void setPassword(Stringpassword){
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 StringgetUserName(){
return userName;
}
public void setUserName(StringuserName){
this .userName = userName;
}
public boolean isVoiceOn(){
return voiceOn;
}
public void setVoiceOn( boolean voiceOn){
this .voiceOn = voiceOn;
}
// </editor-fold>
}
*@(#)GmailSetting.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay19,2008,9:17:35AM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-1307,USA.
*/
package cn.edu.ynu.sei.gmailnotifier.common;
import java.io.Serializable;
/**
*GmailNotifiersettins.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.5,May21,2008
* @see Serializable
*/
public class GmailSetting implements Serializable{
private static final long serialVersionUID = 1L ;
private StringuserName = " Username " ;
private Stringpassword = " Password " ;
private boolean useProxy;
private StringProxy = " NoProxy " ;
private int port;
private int checkMailInterval = 5 ; // minute
private int displayRotationInterval = 5 ; // second
private int delayBeforeFirstCheck = 15 ; // second
private boolean voiceOn;
/**
*Constructorwithparameters.
* @param userNameusername
* @param passworduserpassword
* @param useProxyusingproxy?
* @param proxyproxyhostsetting("192.168.110.65")
* @param portproxyportsetting(808)
* @param delayBeforeFirstCheckdelaybeforefirstcheckafternetbeansluanched
* @param checkIntervalcheckmailinterval
* @param rotationIntervalrotationdisplayinterval
* @param voiceOnplaysoundwhenretrievingmails
*/
public GmailSetting(StringuserName,Stringpassword,
boolean useProxy,Stringproxy, 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);
}
/**
*Defaultconstructor.
*/
public GmailSetting(){
}
// <editor-folddefaultstate="collapsed"desc="getters&setters">
public StringgetProxy(){
return Proxy;
}
public void setProxy(StringProxy){
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 StringgetPassword(){
return password;
}
public void setPassword(Stringpassword){
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 StringgetUserName(){
return userName;
}
public void setUserName(StringuserName){
this .userName = userName;
}
public boolean isVoiceOn(){
return voiceOn;
}
public void setVoiceOn( boolean voiceOn){
this .voiceOn = voiceOn;
}
// </editor-fold>
}
/*
*@(#)GmailSettingManager.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay19,2008,9:18:48PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-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;
/**
*GmailNotifiersettinsmanager.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.8,May21,2008
*/
public class GmailSettingManager{
FileObjectfolderObject = null ;
FileObjectSettingFile = null ;
GmailSettinggSetting = new GmailSetting();
FileLocklock = null ;
/**
*Defaultconstructor.
*/
public GmailSettingManager(){
folderObject = Repository.getDefault().getDefaultFileSystem().getRoot().
getFileObject( " GmailNotifierSettings " );
if (folderObject == null ){
try {
folderObject = Repository.getDefault().getDefaultFileSystem().
getRoot().createFolder( " GmailNotifierSettings " );
storeSettings(gSetting);
} catch (IOExceptionex){
ex.printStackTrace();
// TODOfilecannotbecreated,dosomethingaboutit
}
}
}
/**
*Storethegmailnotifiersettings.
* @param GmailSettingsgmailsettings
* @return ifstoresuccessfully,return<code>true</code>,
*otherwise,return<code>false</code>
*/
public boolean storeSettings(GmailSettingsettings){
try {
if (folderObject.getFileObject( " GmailNotifier " , " Cfg " ) == null ){
SettingFile = folderObject.createData( " GmailNotifier " , " Cfg " );
}
SettingFile = folderObject.getFileObject( " GmailNotifier " , " Cfg " );
lock = SettingFile.lock();
// serialize
ObjectOutputStreamobjectOutStr = new ObjectOutputStream(
SettingFile.getOutputStream(lock));
objectOutStr.writeObject(settings);
objectOutStr.close();
lock.releaseLock();
} catch (IOExceptionex){
// TODOfilecannotbecreated,dosomethingaboutit
ex.printStackTrace();
return false ;
}
return true ;
}
/**
*Retrievegmailnotifiersettings.
* @return gmailsettings
*/
public GmailSettingretrieveSettings(){
SettingFile = folderObject.getFileObject( " GmailNotifier " , " Cfg " );
try {
// unserialize
ObjectInputStreamobjectInStr = new ObjectInputStream(SettingFile.
getInputStream());
gSetting = (GmailSetting)objectInStr.readObject();
objectInStr.close();
} catch (IOExceptionex){
ex.printStackTrace();
return null ;
} catch (ClassNotFoundExceptionex){
ex.printStackTrace();
return null ;
}
return gSetting;
}
}
*@(#)GmailSettingManager.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay19,2008,9:18:48PM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-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;
/**
*GmailNotifiersettinsmanager.
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.8,May21,2008
*/
public class GmailSettingManager{
FileObjectfolderObject = null ;
FileObjectSettingFile = null ;
GmailSettinggSetting = new GmailSetting();
FileLocklock = null ;
/**
*Defaultconstructor.
*/
public GmailSettingManager(){
folderObject = Repository.getDefault().getDefaultFileSystem().getRoot().
getFileObject( " GmailNotifierSettings " );
if (folderObject == null ){
try {
folderObject = Repository.getDefault().getDefaultFileSystem().
getRoot().createFolder( " GmailNotifierSettings " );
storeSettings(gSetting);
} catch (IOExceptionex){
ex.printStackTrace();
// TODOfilecannotbecreated,dosomethingaboutit
}
}
}
/**
*Storethegmailnotifiersettings.
* @param GmailSettingsgmailsettings
* @return ifstoresuccessfully,return<code>true</code>,
*otherwise,return<code>false</code>
*/
public boolean storeSettings(GmailSettingsettings){
try {
if (folderObject.getFileObject( " GmailNotifier " , " Cfg " ) == null ){
SettingFile = folderObject.createData( " GmailNotifier " , " Cfg " );
}
SettingFile = folderObject.getFileObject( " GmailNotifier " , " Cfg " );
lock = SettingFile.lock();
// serialize
ObjectOutputStreamobjectOutStr = new ObjectOutputStream(
SettingFile.getOutputStream(lock));
objectOutStr.writeObject(settings);
objectOutStr.close();
lock.releaseLock();
} catch (IOExceptionex){
// TODOfilecannotbecreated,dosomethingaboutit
ex.printStackTrace();
return false ;
}
return true ;
}
/**
*Retrievegmailnotifiersettings.
* @return gmailsettings
*/
public GmailSettingretrieveSettings(){
SettingFile = folderObject.getFileObject( " GmailNotifier " , " Cfg " );
try {
// unserialize
ObjectInputStreamobjectInStr = new ObjectInputStream(SettingFile.
getInputStream());
gSetting = (GmailSetting)objectInStr.readObject();
objectInStr.close();
} catch (IOExceptionex){
ex.printStackTrace();
return null ;
} catch (ClassNotFoundExceptionex){
ex.printStackTrace();
return null ;
}
return gSetting;
}
}
/*
*@(#)GmailBox.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay21,2008,11:15:50AM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-1307,USA.
*/
package cn.edu.ynu.sei.gmailnotifier.common;
/**
*Amailmessagedescription.Itcontainsthefollowinginformation:
*<p>
*<ol>
*<li>Subject</li>
*<li>Content(snip)</li>
*</ol>
*</p>
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.0,May21,2008
*/
public class Mail{
private Stringsubject;
private Stringcontent;
/**
*Constructorwithparameters.
* @param subjectmailsubject
* @param contentmailcontent
*/
public Mail(Stringsubject,Stringcontent){
this .subject = subject;
this .content = content;
}
// <editor-folddefaultstate="collapsed"desc="Getters&Setters">
public StringgetContent(){
return content;
}
public void setContent(Stringcontent){
this .content = content;
}
public StringgetSubject(){
return subject;
}
public void setSubject(Stringsubject){
this .subject = subject;
}
// </editor-fold>
}
*@(#)GmailBox.java
*Author:88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
*CreatedonMay21,2008,11:15:50AM
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby
*theFreeSoftwareFoundation;eitherversion3oftheLicense,or
*(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULibraryGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace-Suite330,Boston,MA02111-1307,USA.
*/
package cn.edu.ynu.sei.gmailnotifier.common;
/**
*Amailmessagedescription.Itcontainsthefollowinginformation:
*<p>
*<ol>
*<li>Subject</li>
*<li>Content(snip)</li>
*</ol>
*</p>
* @author 88250<DL88250@gmail.com>, http://blog.youkuaiyun.com/DL88250
* @version 1.0.0.0,May21,2008
*/
public class Mail{
private Stringsubject;
private Stringcontent;
/**
*Constructorwithparameters.
* @param subjectmailsubject
* @param contentmailcontent
*/
public Mail(Stringsubject,Stringcontent){
this .subject = subject;
this .content = content;
}
// <editor-folddefaultstate="collapsed"desc="Getters&Setters">
public StringgetContent(){
return content;
}
public void setContent(Stringcontent){
this .content = content;
}
public StringgetSubject(){
return subject;
}
public void setSubject(Stringsubject){
this .subject = subject;
}
// </editor-fold>
}
厄。。。。。。。