NetBeans的Gmail插件!

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

先看下解图:

NetBeans的Gmail插件!

NetBeans的Gmail插件!

NetBeans的Gmail插件!

OK,源代码:

/*
*@(#)GmailNotifierAction.java
*Author:88250<[email protected]>,
http://blog.****.net/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.
*/
packagecn.edu.ynu.sei.gmailnotifier;

importorg.openide.util.HelpCtx;
importorg.openide.util.NbBundle;
importorg.openide.util.actions.CallableSystemAction;

/**
*GmailNotifierAction.
*
@author88250<[email protected]>,http://blog.****.net/DL88250
*
@version1.0.0.0,May18,2008
*/
publicfinalclassGmailNotifierActionextendsCallableSystemAction{

privatestaticfinallongserialVersionUID=1L;
GmailNotifierPanelgChecker
=newGmailNotifierPanel();

publicvoidperformAction(){
gChecker.forceCheck();
}

publicStringgetName(){
returnNbBundle.getMessage(GmailNotifierAction.class,
"CTL_GmailNotifierAction");
}

publicHelpCtxgetHelpCtx(){
returnHelpCtx.DEFAULT_HELP;
}

@Override
protectedbooleanasynchronous(){
returnfalse;
}

@Override
publicjava.awt.ComponentgetToolbarPresenter(){
returngChecker;
}
}

/*
*@(#)GmailNotifierOptionsCategory.java
*Author:88250<[email protected]>,
http://blog.****.net/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.
*/
packagecn.edu.ynu.sei.gmailnotifier;

importjavax.swing.Icon;
importjavax.swing.ImageIcon;
importorg.netbeans.spi.options.OptionsCategory;
importorg.netbeans.spi.options.OptionsPanelController;
importorg.openide.util.NbBundle;
importorg.openide.util.Utilities;

/**
*GmailNotifiersettingspanel'scategory.
*
@author88250<[email protected]>,http://blog.****.net/DL88250
*
@version1.0.0.1,May18,2008
*/
publicclassGmailNotifierOptionsCategoryextendsOptionsCategory{

publicOptionsPanelControllercreate(){
returnnewGmailNotifierSettingsPanelController();
}

publicStringgetCategoryName(){
returnNbBundle.getMessage(GmailNotifierOptionsCategory.class,
"OptionsCategory_Name_Gmailnotifier");
}

publicStringgetTitle(){
returnNbBundle.getMessage(GmailNotifierOptionsCategory.class,
"OptionsCategory_Title_Gmailnotifier");
}

@Override
publicIcongetIcon(){
returnnewImageIcon(Utilities.loadImage(
"cn/edu/ynu/sei/gmailnotifier/gm-logo-settings.png"));
}
}

/*
*@(#)GmailNotifierPanel.java
*Author:88250<[email protected]>,
http://blog.****.net/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.
*/
packagecn.edu.ynu.sei.gmailnotifier;

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

/**
*Gmailcheckerpanel.
*
@author88250<[email protected]>,http://blog.****.net/DL88250
*
@version1.0.2.7,May21,2008
*/
publicclassGmailNotifierPanelextendsjavax.swing.JPanel{

privatestaticfinallongserialVersionUID=1L;
//<editor-folddefaultstate="collapsed"desc="variables-consts">
privateGmailBoxmailBox=null;
privateGmailBoxManagergmHelper=null;
privateGmailSettingsettings=null;
privateGmailSettingManagersettingsManager=null;
privateintsubjectCount=0;
privateTimermailNotifierTimer;
privateTimershowSubjectIntervalTimer;
privateStringconnectingTo="<html><b>ConnectingToGmail...</b></html>";
privateStringretrivingUserCountInfo=
"<html><b>RetrievingUsageandCountInformation...</b></html>";
//TODOprivateStringusagePercent="UsagePercentIs:";
privateStringnewMailsCount="TotalNewMailsIs:";
privateStringnoActiveConnection=
"<html><b>NoActiveConnectionorConnectionIsNotUsable...</b></html>";
privateStringinitiateString=
"<html>GmailcheckerModule....<b>Disconnected</b></HTML>";
privateStringtooltipString=
"<html><b>Left</b>clickwillopentheGmailinyourwebbrowser<br> "+
"<b>Right</b>clickwillcheckyournewmails<br> HaveFun:-) </html>";
privateStringRetriving_emails_info=
"<html><b>Retrievinge-mailHeaders...</b></html>";
//</editor-fold>

/**
*Checkmailbox.
*
@return
*/
publicbooleandoCheckMail(){
//<editor-folddefaultstate="collapsed"desc="runnablesforgmHelpercalling">
RunnableconnectRun=newRunnable(){

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

RunnablenewSubjectsCount
=newRunnable(){

publicvoidrun(){
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();
returnfalse;
}
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();
returntrue;
}
}

/**
*Initializeagmailmanager
*
@see{@link#gmHelper}
*/
privatevoidnewGmailManager(){
gmHelper
=newGmailBoxManager(settings.getUserName(),settings.getPassword(),settings.getProxy(),settings.getPort());
}

/**
*Resetinformationtogmailmanager.
*/
privatevoidresetGmailManager(){
gmHelper.userName
=settings.getUserName();
gmHelper.userPassword
=settings.getPassword();
gmHelper.proxyHost
=settings.getProxy();
gmHelper.port
=settings.getPort();
}

/**
*Displaymailsinformation.
*/
privatevoidshowMailsInfo(){
setCount(mailBox.getSubjectsCount());
showSubjectIntervalTimer
=newjava.util.Timer();
showSubjectIntervalTimer.scheduleAtFixedRate(
newTimerTask(){

privateintcurrentSubjectNo;

publicvoidrun(){
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.
*
@paramdelayBeforeStartCheckdelay(second)beforegettingstartcheck
*/
publicvoidstartCheck(intdelayBeforeStartCheck){
settings
=settingsManager.retrieveSettings();
mailBox
=newGmailBox();
if(gmHelper==null){
newGmailManager();
}
else{
resetGmailManager();
}

mailNotifierTimer
=newjava.util.Timer();
mailNotifierTimer.scheduleAtFixedRate(
newTimerTask(){

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

/**
*Defaultconstructor.
*/
publicGmailNotifierPanel(){
initComponents();
jLabel1.setText(initiateString);
jLabel1.setToolTipText(tooltipString);
settingsManager
=newGmailSettingManager();
settings
=settingsManager.retrieveSettings();
startCheck(settings.getDelayBeforeFirstCheck());
}

/**
*Playsound.
*
@paramsoundNamesoundfilename
*/
privatevoidplaySound(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.
*
@paramcountmailcount
*/
privatevoidsetCount(intcount){
this.jLabel1.setText("<html>"+newMailsCount+
"<b><fontcolor="blue">"+count+"</font></b></html>");
}

/**
*Setthelabel'sicon.
*
@paramiconNameiconname
*/
privatevoidsetIcon(StringiconName){
jLabel1.setIcon(
newjavax.swing.ImageIcon(getClass().getResource("/cn/edu/ynu/sei/gmailnotifier/"+iconName+".png")));//NOI18N

}

/**Thismethodiscalledfromwithintheconstructorto
*initializetheform.
*WARNING:DoNOTmodifythiscode.Thecontentofthismethodis
*alwaysregeneratedbytheFormEditor.
*/
//<editor-folddefaultstate="collapsed"desc="GeneratedCode">
privatevoidinitComponents(){

jLabel1
=newjavax.swing.JLabel();

setAlignmentY(
0.0F);
setOpaque(
false);

jLabel1.setFont(
newjava.awt.Font("Tahoma",0,10));//NOI18N
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
jLabel1.setIcon(
newjavax.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(
newjava.awt.Dimension(227,22));
jLabel1.setSize(
newjava.awt.Dimension(227,22));
jLabel1.addMouseListener(
newjava.awt.event.MouseAdapter(){
publicvoidmouseClicked(java.awt.event.MouseEventevt){
jLabel1MouseClicked(evt);
}
publicvoidmouseEntered(java.awt.event.MouseEventevt){
jLabel1MouseEntered(evt);
}
});

org.jdesktop.layout.GroupLayoutlayout
=neworg.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.
*
@paramsubjectNosubjectnumber
*
@returnmailsubjectsnip
*/
privateStringgetSubjectSnip(intsubjectNo){
Stringsubj
=mailBox.getMails().get(subjectNo).getSubject();
returnsubj.length()>40?(subj.substring(0,40)+"...."):subj;
}

//TODOgetContentSnip
/**
*Getnewmailscontentsnip.
*
@paramsubjectNosubjectnumber
*
@returnmailcontentsnip
*/
privateStringgetContentSnip(intsubjectNo){
Stringcont
=mailBox.getMails().get(subjectNo).getContent();
returncont.length()>100?(cont.substring(0,100)+"...."):cont;
}

privatevoidjLabel1MouseClicked(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();
}
}

privatevoidjLabel1MouseEntered(java.awt.event.MouseEventevt){
if(mailBox.getSubjectsCount()!=0){
StringBuildersnips
=newStringBuilder();
for(inti=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
publicjavax.swing.JLabeljLabel1;
//Endofvariablesdeclaration

/**
*Checkmailinboxbyforce.
*/
publicvoidforceCheck(){
if(showSubjectIntervalTimer!=null){
showSubjectIntervalTimer.cancel();
}
if(mailNotifierTimer!=null){
mailNotifierTimer.cancel();
}
startCheck(
0);
}
}

/*
*@(#)GmailNotifierSettingsPanel.java
*Author:88250<[email protected]>,
http://blog.****.net/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.
*/
packagecn.edu.ynu.sei.gmailnotifier;

importcn.edu.ynu.sei.gmailnotifier.common.GmailSetting;
importjavax.swing.SpinnerNumberModel;

/**
*GmailNotifiersettingspanel.
*
@author88250<[email protected]>,http://blog.****.net/DL88250
*
@version1.0.0.2,May21,2008
*/
publicclassGmailNotifierSettingsPanelextendsjavax.swing.JPanel{

privatestaticfinallongserialVersionUID=1L;
publicbooleanisChanged=false;

/**
*Defaultconstructor.
*/
publicGmailNotifierSettingsPanel(){
initComponents();
}

/**
*SetallsettingsinUI.
*
@paramsettinggmailsettings
*/
publicvoidpopulateUI(GmailSettingsetting){
this.jTextField1.setText(setting.getUserName());
this.jPasswordField1.setText(setting.getPassword());
this.jCheckBox1.setSelected(setting.isVoiceOn());

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

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

/**
*Retieveallsettings.
*
@returngmailsettings
*/
publicGmailSettingreturnSetting(){
returnnewGmailSetting(jTextField1.getText(),newString(
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">
privatevoidinitComponents(){

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

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(
"GeneralOptions"));

jTextField1.addPropertyChangeListener(
newjava.beans.PropertyChangeListener(){
publicvoidpropertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel.
this.propertyChange(evt);
}
});

jPasswordField1.addPropertyChangeListener(
newjava.beans.PropertyChangeListener(){
publicvoidpropertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel.
this.propertyChange(evt);
}
});

jCheckBox1.setText(
"Enablesounds");
jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(
0,0,0,0));
jCheckBox1.setMargin(
newjava.awt.Insets(0,0,0,0));
jCheckBox1.addPropertyChangeListener(
newjava.beans.PropertyChangeListener(){
publicvoidpropertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel.
this.propertyChange(evt);
}
});

jLabel1.setText(
"Username");

jLabel2.setText(
"Password");

org.jdesktop.layout.GroupLayoutjPanel1Layout
=neworg.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(
newjava.beans.PropertyChangeListener(){
publicvoidpropertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel.
this.propertyChange(evt);
}
});

jLabel9.setText(
"Host:");

jLabel10.setText(
"Port:");

jTextField3.addPropertyChangeListener(
newjava.beans.PropertyChangeListener(){
publicvoidpropertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel.
this.propertyChange(evt);
}
});

jCheckBox3.setText(
"Connectviaproxy");
jCheckBox3.setBorder(javax.swing.BorderFactory.createEmptyBorder(
0,0,0,0));
jCheckBox3.setMargin(
newjava.awt.Insets(0,0,0,0));
jCheckBox3.addPropertyChangeListener(
newjava.beans.PropertyChangeListener(){
publicvoidpropertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel.
this.propertyChange(evt);
}
});

org.jdesktop.layout.GroupLayoutjPanel3Layout
=neworg.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(
newSpinnerNumberModel(
newInteger(15),
newInteger(0),
null,
newInteger(5)
));
jSpinner1.addPropertyChangeListener(
newjava.beans.PropertyChangeListener(){
publicvoidpropertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel.
this.propertyChange(evt);
}
});

jSpinner2.setModel(
newSpinnerNumberModel(
newInteger(3),
newInteger(1),
newInteger(15),
newInteger(1)
));
jSpinner2.addPropertyChangeListener(
newjava.beans.PropertyChangeListener(){
publicvoidpropertyChange(java.beans.PropertyChangeEventevt){
GmailNotifierSettingsPanel.
this.propertyChange(evt);
}
});

jSpinner3.setModel(
newSpinnerNumberModel(
newInteger(15),
newInteger(0),
null,
newInteger(5)
));
jSpinner3.addPropertyChangeListener(
newjava.beans.PropertyChangeListener(){
publicvoidpropertyChange(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
=neworg.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
=neworg.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.
*
@paramevtpropertychangevnt
*/
privatevoidpropertyChange(java.beans.PropertyChangeEventevt){
isChanged
=true;
}
//Variablesdeclaration-donotmodify
privatejavax.swing.JCheckBoxjCheckBox1;
privatejavax.swing.JCheckBoxjCheckBox3;
privatejavax.swing.JLabeljLabel1;
privatejavax.swing.JLabeljLabel10;
privatejavax.swing.JLabeljLabel2;
privatejavax.swing.JLabeljLabel3;
privatejavax.swing.JLabeljLabel4;
privatejavax.swing.JLabeljLabel5;
privatejavax.swing.JLabeljLabel6;
privatejavax.swing.JLabeljLabel7;
privatejavax.swing.JLabeljLabel8;
privatejavax.swing.JLabeljLabel9;
privatejavax.swing.JPaneljPanel1;
privatejavax.swing.JPaneljPanel2;
privatejavax.swing.JPaneljPanel3;
privatejavax.swing.JPasswordFieldjPasswordField1;
privatejavax.swing.JSpinnerjSpinner1;
privatejavax.swing.JSpinnerjSpinner2;
privatejavax.swing.JSpinnerjSpinner3;
privatejavax.swing.JTextFieldjTextField1;
privatejavax.swing.JTextFieldjTextField2;
privatejavax.swing.JTextFieldjTextField3;
//Endofvariablesdeclaration
}

/*
*@(#)GmailNotifierSettingsPanelController.java
*Author:88250<[email protected]>,
http://blog.****.net/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.
*/
packagecn.edu.ynu.sei.gmailnotifier;

importcn.edu.ynu.sei.gmailnotifier.common.GmailSettingManager;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.beans.PropertyChangeListener;
importjavax.swing.JComponent;
importorg.netbeans.spi.options.OptionsPanelController;
importorg.openide.DialogDescriptor;
importorg.openide.DialogDisplayer;
importorg.openide.util.HelpCtx;
importorg.openide.util.Lookup;

/**
*GmailNotifiersettingspanel'scontroller.
*
@author88250<[email protected]>,http://blog.****.net/DL88250
*
@version1.0.0.3,May21,2008
*/
publicclassGmailNotifierSettingsPanelControllerextendsOptionsPanelController{

privateGmailNotifierSettingsPanelsettingPanel=
newGmailNotifierSettingsPanel();
privateGmailSettingManagersettingManager=newGmailSettingManager();
privateStringsureTocancle=
"<html><b>doyouwanttosavethechangesthatyoumade"+
"intoGmailsettingDialog?</b><html>";

publicvoidapplyChanges(){
if(settingPanel.isChanged){
settingManager.storeSettings(settingPanel.returnSetting());
settingPanel.isChanged
=false;
}
}

publicvoidcancel(){
if(settingPanel.isChanged){
DialogDescriptorddesc
=newDialogDescriptor((Object)sureTocancle,
"Changeswilllost",
true,DialogDescriptor.YES_NO_OPTION,
DialogDescriptor.CANCEL_OPTION,
newActionListener(){

publicvoidactionPerformed(ActionEvente){
if(e.getActionCommand().equalsIgnoreCase("yes")){
settingManager.storeSettings(
settingPanel.returnSetting());
}
}
});
DialogDisplayer.getDefault().createDialog(ddesc).setVisible(
true);
}
}

publicbooleanisValid(){
returntrue;
}

publicbooleanisChanged(){
returntrue;
}

publicJComponentgetComponent(LookupmasterLookup){
returnsettingPanel;
}

publicHelpCtxgetHelpCtx(){
returnHelpCtx.DEFAULT_HELP;
}

publicvoidupdate(){
settingPanel.populateUI(settingManager.retrieveSettings());
}

publicvoidaddPropertyChangeListener(PropertyChangeListenerl){
}

publicvoidremovePropertyChangeListener(PropertyChangeListenerl){
}
}

/*
*@(#)GmailBox.java
*Author:88250<[email protected]>,
http://blog.****.net/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.
*/
packagecn.edu.ynu.sei.gmailnotifier.common;

importjava.util.ArrayList;
importjava.util.List;

/**
*Gmailmailboxinformation.
*
@author88250<[email protected]>,http://blog.****.net/DL88250
*
@version1.0.0.5,May21,2008
*/
publicclassGmailBox{

privateList<Mail>mails=newArrayList<Mail>();

/**
*Defaultconsturctor.
*/
publicGmailBox(){
}

/**
*Constructorwithparameters.
*
@paramnewMailCountnewmailcount
*/
publicGmailBox(List<Mail>mails){
this.setMails(mails);
}

//<editor-folddefaultstate="collapsed"desc="Getters&Setters">
publicList<Mail>getMails(){
returnmails;
}

publicintgetSubjectsCount(){
returnmails.size();
}

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

/*
*@(#)GmailBox.java
*Author:88250<[email protected]>,
http://blog.****.net/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.
*/
packagecn.edu.ynu.sei.gmailnotifier.common;

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

/**
*Gmailmailboxmanager.
*
@author88250<[email protected]>,http://blog.****.net/DL88250
*
@version1.0.2.6,May21,2008
*/
publicclassGmailBoxManager{

publicStringuserName="Username";
publicStringuserPassword="Password";
publicStringproxyHost="NoProxy";
publicintport=0;
privatestaticStorestore;

/**
*Constructorwithparameters.
*
@paramuserNameusername
*
@paramuserPassworduserpassword
*
@paramproxyHostproxyhost
*
@paramportproxyport
*/
publicGmailBoxManager(StringuserName,StringuserPassword,
StringproxyHost,
intport){
this.userPassword=userPassword;
this.userName=userName;
this.proxyHost=proxyHost;
this.port=port;
}

/**
*Connecttothemailbox.
*
@returnifconnectsuccessfully,return<code>true</code>,
*otherwise,return<code>false</code>
*/
publicbooleanconnect(){
if(!proxyHost.equalsIgnoreCase("NoProxy")){
//TODOsetProxy(proxyHost,port);
}else{
if(store==null||!store.isConnected()){
Security.addProvider(
newcom.sun.net.ssl.internal.ssl.Provider());
finalStringSSL_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
=newURLName("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());
returnfalse;
}
try{
store.connect();
}
catch(MessagingExceptionex){
System.err.println(ex.getMessage());
returnfalse;
}
}
}

returntrue;
}

/**
*Isconnectedmailbox?
*
@returnifconnected,return<code>true</code>,
*otherwise,return<code>false</code>
*/
publicbooleanisConnected(){
returnstore!=null?store.isConnected():false;
}

/**
*Getthenewmailboxinformation.
*
@returnmailbox
*/
publicGmailBoxgetMailBox(){
if(store==null||!store.isConnected()){
connect();
}
//TODOintusagePercent=0;
intnewMailCount=0;
List
<Mail>mails=newArrayList<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=newHashSet<String>();
for(inti=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(
newMail(sub,""/*content*/));
}
returnnewGmailBox(mails);
}
else{
System.err.println(
"Noanynewmail!");
}
}
catch(Exceptionex){
System.err.println(ex.getMessage());
}

//returnemptymailbox
returnnewGmailBox();
}

/**
*Opentheurlinsystem'swebbrowser.
*
@paramurlthespecifiedurltoopen
*/
@SuppressWarnings(value
={"unchcked"})
publicstaticvoidopenURL(Stringurl){
StringosName
=System.getProperty("os.name");
try{
if(osName.startsWith("MacOS")){
ClassfileMgr
=Class.forName("com.apple.eio.FileManager");
@SuppressWarnings(
"unchecked")
MethodopenURL
=fileMgr.getDeclaredMethod("openURL",
newClass[]{String.class});
openURL.invoke(
null,newObject[]{url});
}
elseif(osName.startsWith("Windows")){
Runtime.getRuntime().exec(
"rundll32url.dll,FileProtocolHandler"+
url);
}
else{
//assumeUnixorLinux
String[]browsers={
"firefox","opera","konqueror",
"epiphany","mozilla","netscape"
};
Stringbrowser
=null;
for(intcount=0;
count
<browsers.length&&browser==null;
count
++){
if(Runtime.getRuntime().exec(
newString[]{"which",browsers[count]}).waitFor()==
0){
browser
=browsers[count];
}

}
if(browser==null){
thrownewException("Couldnotfindwebbrowser");
}
else{
Runtime.getRuntime().exec(
newString[]{browser,url});
}
}
}
catch(Exceptione){
JOptionPane.showMessageDialog(
null,
"Errorattemptingtolaunchwebbrowser"+": "+e.getLocalizedMessage());
}
}
}

/*
*@(#)GmailSetting.java
*Author:88250<[email protected]>,
http://blog.****.net/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.
*/
packagecn.edu.ynu.sei.gmailnotifier.common;

importjava.io.Serializable;

/**
*GmailNotifiersettins.
*
@author88250<[email protected]>,http://blog.****.net/DL88250
*
@version1.0.0.5,May21,2008
*
@seeSerializable
*/
publicclassGmailSettingimplementsSerializable{

privatestaticfinallongserialVersionUID=1L;
privateStringuserName="Username";
privateStringpassword="Password";
privatebooleanuseProxy;
privateStringProxy="NoProxy";
privateintport;
privateintcheckMailInterval=5;//minute

privateintdisplayRotationInterval=5;//second

privateintdelayBeforeFirstCheck=15;//second

privatebooleanvoiceOn;

/**
*Constructorwithparameters.
*
@paramuserNameusername
*
@parampassworduserpassword
*
@paramuseProxyusingproxy?
*
@paramproxyproxyhostsetting("192.168.110.65")
*
@paramportproxyportsetting(808)
*
@paramdelayBeforeFirstCheckdelaybeforefirstcheckafternetbeansluanched
*
@paramcheckIntervalcheckmailinterval
*
@paramrotationIntervalrotationdisplayinterval
*
@paramvoiceOnplaysoundwhenretrievingmails
*/
publicGmailSetting(StringuserName,Stringpassword,
booleanuseProxy,Stringproxy,intport,
intdelayBeforeFirstCheck,intcheckInterval,
introtationInterval,
booleanvoiceOn){
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.
*/
publicGmailSetting(){
}

//<editor-folddefaultstate="collapsed"desc="getters&setters">
publicStringgetProxy(){
returnProxy;
}

publicvoidsetProxy(StringProxy){
this.Proxy=Proxy;
}

publicintgetCheckMailInterval(){
returncheckMailInterval;
}

publicvoidsetCheckMailInterval(intcheckMailInterval){
this.checkMailInterval=checkMailInterval;
}

publicintgetDelayBeforeFirstCheck(){
returndelayBeforeFirstCheck;
}

publicvoidsetDelayBeforeFirstCheck(intdelayBeforeFirstCheck){
this.delayBeforeFirstCheck=delayBeforeFirstCheck;
}

publicintgetDisplayRotationInterval(){
returndisplayRotationInterval;
}

publicvoidsetDisplayRotationInterval(intdisplayRotationInterval){
this.displayRotationInterval=displayRotationInterval;
}

publicStringgetPassword(){
returnpassword;
}

publicvoidsetPassword(Stringpassword){
this.password=password;
}

publicintgetPort(){
returnport;
}

publicvoidsetPort(intport){
this.port=port;
}

publicbooleanisUseProxy(){
returnuseProxy;
}

publicvoidsetUseProxy(booleanuseProxy){
this.useProxy=useProxy;
}

publicStringgetUserName(){
returnuserName;
}

publicvoidsetUserName(StringuserName){
this.userName=userName;
}

publicbooleanisVoiceOn(){
returnvoiceOn;
}

publicvoidsetVoiceOn(booleanvoiceOn){
this.voiceOn=voiceOn;
}
//</editor-fold>
}

/*
*@(#)GmailSettingManager.java
*Author:88250<[email protected]>,
http://blog.****.net/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.
*/
packagecn.edu.ynu.sei.gmailnotifier.common;

importjava.io.IOException;
importjava.io.ObjectInputStream;
importjava.io.ObjectOutputStream;
importorg.openide.filesystems.FileLock;
importorg.openide.filesystems.FileObject;
importorg.openide.filesystems.Repository;

/**
*GmailNotifiersettinsmanager.
*
@author88250<[email protected]>,http://blog.****.net/DL88250
*
@version1.0.0.8,May21,2008
*/
publicclassGmailSettingManager{

FileObjectfolderObject
=null;
FileObjectSettingFile
=null;
GmailSettinggSetting
=newGmailSetting();
FileLocklock
=null;

/**
*Defaultconstructor.
*/
publicGmailSettingManager(){
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.
*
@paramGmailSettingsgmailsettings
*
@returnifstoresuccessfully,return<code>true</code>,
*otherwise,return<code>false</code>
*/
publicbooleanstoreSettings(GmailSettingsettings){
try{
if(folderObject.getFileObject("GmailNotifier","Cfg")==null){
SettingFile
=folderObject.createData("GmailNotifier","Cfg");
}
SettingFile
=folderObject.getFileObject("GmailNotifier","Cfg");

lock
=SettingFile.lock();
//serialize
ObjectOutputStreamobjectOutStr=newObjectOutputStream(
SettingFile.getOutputStream(lock));

objectOutStr.writeObject(settings);
objectOutStr.close();
lock.releaseLock();
}
catch(IOExceptionex){
//TODOfilecannotbecreated,dosomethingaboutit
ex.printStackTrace();
returnfalse;
}
returntrue;
}

/**
*Retrievegmailnotifiersettings.
*
@returngmailsettings
*/
publicGmailSettingretrieveSettings(){
SettingFile
=folderObject.getFileObject("GmailNotifier","Cfg");
try{
//unserialize
ObjectInputStreamobjectInStr=newObjectInputStream(SettingFile.
getInputStream());
gSetting
=(GmailSetting)objectInStr.readObject();
objectInStr.close();
}
catch(IOExceptionex){
ex.printStackTrace();
returnnull;
}
catch(ClassNotFoundExceptionex){
ex.printStackTrace();
returnnull;
}
returngSetting;
}
}

/*
*@(#)GmailBox.java
*Author:88250<[email protected]>,
http://blog.****.net/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.
*/
packagecn.edu.ynu.sei.gmailnotifier.common;

/**
*Amailmessagedescription.Itcontainsthefollowinginformation:
*<p>
*<ol>
*<li>Subject</li>
*<li>Content(snip)</li>
*</ol>
*</p>
*
@author88250<[email protected]>,http://blog.****.net/DL88250
*
@version1.0.0.0,May21,2008
*/
publicclassMail{

privateStringsubject;
privateStringcontent;

/**
*Constructorwithparameters.
*
@paramsubjectmailsubject
*
@paramcontentmailcontent
*/
publicMail(Stringsubject,Stringcontent){
this.subject=subject;
this.content=content;
}

//<editor-folddefaultstate="collapsed"desc="Getters&Setters">
publicStringgetContent(){
returncontent;
}

publicvoidsetContent(Stringcontent){
this.content=content;
}

publicStringgetSubject(){
returnsubject;
}

publicvoidsetSubject(Stringsubject){
this.subject=subject;
}
//</editor-fold>
}

厄。。。。。。。