/* * Gchecker.java * * Created on October 23, 2005, 4:53 PM */ package gmailchecker.gui; import java.applet.Applet; import java.applet.AudioClip; import java.net.URL; import java.util.*; import gmailchecker.common.GCheckSetting; import gmailchecker.common.GSettingUtil; import gmailchecker.common.GmailCountUsage; import gmailchecker.common.GmailHelper; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; import org.openide.util.RequestProcessor; import siuying.gm.structure.GMThread; /** * * @author Administrator */ public class Gchecker extends javax.swing.JPanel { /** Creates new form Gchecker */ // ArrayList eMailsInformation = null; GmailCountUsage gmcu=null; GmailHelper gmHelper=null; GCheckSetting settings =null; GSettingUtil settingUtil=null; org.openide.util.RequestProcessor.Task tskGm = null; int CurrentMailSubject=0; Timer mailcheckerTimer;//= new java.util.Timer(); Timer ShowSubjectDurationTimer; //= new java.util.Timer(); boolean checkIsUnderGo=false; private String Connecting_to="Connecting To Gmail..."; private String Retriving_user_count_info="Retrieving Usage and Count Information..."; private String usagePercent = "Usage Percent Is : "; private String newMailsCount = "Total New Mails Is : "; private String No_active_connection="No Active Connection or Connection Is Not Usable..."; private String InitiateString ="Gmail checker Module.... Disconnected"; private String ModuletooltipString="GMail Checker Module....."; private String Retriving_emails_info="Retrieving e-mail Headers..."; // public boolean DoCheckMail(){ // Runnable connectRun = new Runnable() { public void run() { gmHelper.connect(); } }; Runnable CheckUsageCount = new Runnable() { public void run() { gmcu=gmHelper.getCountUsage(); if (gmcu.getNewMailCount()>0) playSound("receive"); } }; Runnable GetHeader = new Runnable() { public void run() { eMailsInformation=gmHelper.getMailsInfo(); } }; // ProgressHandle ProgHandl= ProgressHandleFactory.createHandle(Connecting_to); jLabel1.setText(Connecting_to); ProgHandl.start(99); RequestProcessor.getDefault().post(connectRun).waitFinished(); jLabel1.setText(Retriving_user_count_info); ProgHandl.progress(Retriving_user_count_info,33); RequestProcessor.getDefault().post(CheckUsageCount).waitFinished(); if(gmcu.getNewMailCount()==-1 && gmcu.getUsage()==-1 && gmcu.isProblematic()){ jLabel1.setText(No_active_connection); ProgHandl.finish(); return false; }else{ jLabel1.setText(Retriving_emails_info); ProgHandl.progress(Retriving_emails_info,33); RequestProcessor.getDefault().post(GetHeader).waitFinished(); ProgHandl.progress(33); ProgHandl.finish(); return true; } } private void setUsageCount(int count,int usage){ this.jLabel1.setText(newMailsCount+" "+count+" , "+usagePercent+usage+"% "); } private void ShowInfoAuto(){ setUsageCount(gmcu.getNewMailCount(),gmcu.getUsage()); ShowSubjectDurationTimer = new java.util.Timer(); ShowSubjectDurationTimer.scheduleAtFixedRate(new TimerTask() { public void run() { if(CurrentMailSubject"+""+(CurrentMailSubject+1)+" :"+getSubject(CurrentMailSubject)+""); CurrentMailSubject++; } else{ ShowSubjectDurationTimer.cancel(); } } },settings.getDelayBeweenDiplay()*1000,settings.getDelayBeweenDiplay()*1000 ); } public void startCheck(int delayBeforeStartCheck){ settings=settingUtil.retrieveSetting(); gmcu= new GmailCountUsage(0,0,false); gmHelper = new GmailHelper(settings.getUserName(),settings.getPassword(),settings.getProxy(),settings.getPort(),0); mailcheckerTimer = new java.util.Timer(); mailcheckerTimer.scheduleAtFixedRate(new TimerTask() { public void run() { checkIsUnderGo=true; CurrentMailSubject=0; if( DoCheckMail()) ShowInfoAuto(); } },delayBeforeStartCheck,settings.getCheckMailPriod()*60*1000); } public Gchecker() { initComponents(); jLabel1.setText(InitiateString); jLabel1.setToolTipText(ModuletooltipString); settingUtil = new GSettingUtil(); settings=settingUtil.retrieveSetting(); startCheck(settings.getDelayBeforeStartCheck()*1000); } private void playSound(String SoundName){ if (settings.isVoiceOn()){ AudioClip Clip; URL Url; try{ Url=getClass().getResource("org/myorg/gmailchecker/resources/"+SoundName+".wav"); Clip=Applet.newAudioClip(Url); Clip.play(); }catch(Exception e){ }} } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // //GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jLabel1.setFont(new java.awt.Font("Tahoma", 0, 10)); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gmailchecker/resources/gcheck.gif"))); org.openide.awt.Mnemonics.setLocalizedText(jLabel1, "Gmail checker Module.... Disconnected"); jLabel1.setToolTipText("GMail checker module....."); jLabel1.setVerticalAlignment(javax.swing.SwingConstants.TOP); jLabel1.setAlignmentY(0.0F); jLabel1.setAutoscrolls(true); jLabel1.setDoubleBuffered(true); jLabel1.setIconTextGap(2); jLabel1.setOpaque(true); jLabel1.setPreferredSize(new java.awt.Dimension(227, 22)); jLabel1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jLabel1MouseClicked(evt); } }); jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gmailchecker/resources/back.gif"))); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gmailchecker/resources/forward.gif"))); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jLabel1, 0, 468, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) ); }// //GEN-END:initComponents private String getSubject(int subjectNo ){ String tempStr= ((GMThread)(eMailsInformation.get(subjectNo))).getSubjectHtml(); if (tempStr.length()>68) {tempStr.subSequence(0,68);return tempStr+"...";} else return tempStr; } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed if(ShowSubjectDurationTimer!=null) {ShowSubjectDurationTimer.cancel(); if(CurrentMailSubject>0&&gmcu.getNewMailCount()>0){ CurrentMailSubject--; jLabel1.setText(""+""+(CurrentMailSubject+1)+" Subject: "+getSubject(CurrentMailSubject)+""); }else{CurrentMailSubject=gmcu.getNewMailCount(); CurrentMailSubject--; jLabel1.setText(""+""+(CurrentMailSubject+1)+" Subject: "+getSubject(CurrentMailSubject)+""); }} playSound("pop"); }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed if(ShowSubjectDurationTimer!=null) {ShowSubjectDurationTimer.cancel(); if(CurrentMailSubject0){ jLabel1.setText(""+""+(CurrentMailSubject+1)+" Subject: "+getSubject(CurrentMailSubject)+""); CurrentMailSubject++; }else{CurrentMailSubject=0;CurrentMailSubject++; jLabel1.setText(""+""+(CurrentMailSubject+1)+" Subject: "+getSubject(CurrentMailSubject)+"");} } playSound("pop"); }//GEN-LAST:event_jButton2ActionPerformed private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked if(ShowSubjectDurationTimer!=null) ShowSubjectDurationTimer.cancel(); if(mailcheckerTimer!=null) mailcheckerTimer.cancel(); startCheck(0); }//GEN-LAST:event_jLabel1MouseClicked // Variables declaration - do not modify//GEN-BEGIN:variables public javax.swing.JButton jButton1; public javax.swing.JButton jButton2; public javax.swing.JLabel jLabel1; // End of variables declaration//GEN-END:variables public void ForceCheck(){ if(ShowSubjectDurationTimer!=null) ShowSubjectDurationTimer.cancel(); if(mailcheckerTimer!=null) mailcheckerTimer.cancel(); startCheck(0); } }