?? gmailer4j.java
字號:
package siuying.gm.app.gmailer4j;
import java.io.*;
import java.util.*;
import java.util.logging.*;
import java.util.prefs.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import bsh.*;
import EDU.oswego.cs.dl.util.concurrent.misc.*;
import siuying.gm.*;
import siuying.gm.app.gmailer4j.controller.*;
import siuying.gm.app.gmailer4j.model.*;
import siuying.gm.app.gmailer4j.ui.*;
import siuying.gm.structure.*;
import snoozesoft.systray4j.*;
import com.Ostermiller.util.Browser;
import com.jgoodies.plaf.Options;
import com.jgoodies.plaf.LookUtils;
import com.jgoodies.looks.demo.Settings;
import com.jgoodies.plaf.plastic.PlasticLookAndFeel;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.plaf.metal.DefaultMetalTheme;
/**
* GMailer4j main program
* @version 0.3.12
*/
public class GMailer4j {
/***** models *****/
/**
* General data about gmail
* number of mail in standard box, space used ..etc
*/
private TreeMap gminfo;
/**
* List of Labels
*/
private TreeMap gmlabel;
/**
* List of searches made
* String -> Integer mappings
*/
private TreeMap gmsearch;
/**
* list of conversations in mailboxes
* String: boxname -> ArrayList<GMThreads>: threads
*/
private HashMap mailboxes = null;
/**
* list of conversation entries in a conversation
* String: conversation id -> ArrayList<GMConversationEntry>: entry
*/
private HashMap converation = null;
/* views (most views are included in controllers) */
private GMJFrame_AboutBox aboutDlg;
/* controllers */
private GMMainFrameController mainCtrl;
private GMSysTrayController systrayCtrl;
private ConfigureOption configOption;
private GMConvPanelController convCtrl;
/* required objects */
private Logger logger = Logger.getLogger(GMailer4j.class.getName());
private GMConnector conn;
private SwingWorker mailChecker;
private Preferences pref;
private GMStorage storage;
private Settings settings = Utils.DEF_SETTING;
private boolean loaded = false;
/* model */
private MailboxTreeModel mailboxModel;
private ThreadsTableModel threadsModel;
public final static int LOGON_OFF = 0;
public final static int LOGON_ON = 1;
public final static int LOGGING = 2;
/**
* Configures the user interface; requests Swing settings and
* jGoodies Looks options from the launcher.
*/
private void configureUI() {
Options.setDefaultIconSize(new Dimension(18, 18));
// Set font options
UIManager.put(
Options.USE_SYSTEM_FONTS_APP_KEY,
settings.isUseSystemFonts());
Options.setGlobalFontSizeHints(settings.getFontSizeHints());
Options.setUseNarrowButtons(settings.isUseNarrowButtons());
// Global options
Options.setTabIconsEnabled(settings.isTabIconsEnabled());
UIManager.put(Options.POPUP_DROP_SHADOW_ENABLED_KEY,
settings.isPopupDropShadowEnabled());
// Work around caching in MetalRadioButtonUI
JRadioButton radio = new JRadioButton();
radio.getUI().uninstallUI(radio);
JCheckBox checkBox = new JCheckBox();
checkBox.getUI().uninstallUI(checkBox);
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try {
Options.setUseNarrowButtons(true);
Options.setDefaultIconSize(new Dimension(18, 18));
Options.setPopupDropShadowEnabled(true);
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
}
UIDefaults defaults = UIManager.getDefaults();
defaults.remove("SplitPane.border");
defaults.remove("SplitPaneDivider.border");
}
/**
* Initialize the program and then show it
* Then it build a background worker thread that check mail periodically
*/
public GMailer4j() {
// initialize look and feel
configureUI();
// possibly show loading screen
// pre-startup
// - object initialization, open storage..etc
init();
loaded = true;
// loading completed, startup
mainCtrl.show();
// post-startup
// - open data store and place data to view
// auto minimize
if (pref.node("General").getBoolean("automin", false)) {
// minimize the software
mainCtrl.getFrame().setState(Frame.ICONIFIED);
mainCtrl.getFrame().hide();
}else{
// bring software to front
mainCtrl.getFrame().toFront();
}
// auto connect
if (pref.node("General").getBoolean("autolog", false) &&
!conn.isConnected()) {
connect();
}
// background mail checker thread
// check mail at specified interval
mailChecker = new SwingWorker() {
protected Object construct() {
boolean value = true;
int interval = pref.node("General").getInt("checkinterval", 10) * 60000;
boolean check = pref.node("General").getBoolean("checkmail", false);
logger.info("checkinterval: " + interval + "; check mail? " + check);
while (value) {
try {
Thread.sleep(interval);
}
catch (InterruptedException ie) {
value = false;
}
interval = pref.node("General").getInt("checkinterval", 10) * 60000;
if (check && conn.isConnected()) {
// check mail
fetchBox("Inbox", 0);
}
}
return "Done";
}
};
mailChecker.start();
setMessage("Offline", "GMailer for Java initialized. ");
}
/**
* Initialize the application
* Initialize preference, storage controllers, views
*/
protected void init(){
String status = "";
try{
// load the class "Utils"
// (to initialize the thread pools)
status = "Initialize utilities functions ...";
logger.info(status);
Class.forName("siuying.gm.app.gmailer4j.ThreadUtils");
// load preferences
status = "Initialize Preferences ...";
logger.info(status);
pref = Preferences.userNodeForPackage(GMailer4j.class);
// load data store
status = "Initialize Data Store ...";
logger.info(status);
String username = pref.node("Accounts").get("username", "Username");
if (!username.equals("Username") &&
!username.equals("")){
storage = XMLStorage.getXMLStorage("data" + File.separator +
username);
storage.open();
}
// set browser
Browser.load(pref);
// initialize objects
conn = new GMConnector(); // setup connection
// initialize controls
mainCtrl = new GMMainFrameController();
configOption = new ConfigureOption(mainCtrl.getFrame(), pref);
systrayCtrl = new GMSysTrayController(mainCtrl.getFrame());
convCtrl = new GMConvPanelController(mainCtrl.getFrame());
// initialize view
aboutDlg = new GMJFrame_AboutBox(mainCtrl.getFrame());
// initialize model
mailboxModel = new MailboxTreeModel();
threadsModel = new ThreadsTableModel();
// setup models
status = "Setup Models ...";
logger.info(status);
setupModels();
// setup controllers
status = "Setup Controllers ...";
logger.info(status);
setupControllers();
// setup views
status = "Setup Views ...";
logger.info(status);
setupViews();
}catch (Exception e){
logger.warning("Critical error occured during initialization, abort (" +
e.getMessage() + ")");
e.printStackTrace();
System.exit(1);
}
}
private void setupControllers(){
/* setup main controller */
mainCtrl.addActionListener(this.getActionListener());
final JFrame mainframe = mainCtrl.getFrame();
WindowListener winListener = new WindowAdapter(){
public void windowClosing(WindowEvent e) {
if (systrayCtrl.isAvaliable()){
mainCtrl.getFrame().hide();
}else{
shutdown();
}
}
};
mainframe.addWindowListener(winListener);
mainCtrl.setShowContent(false);
mainCtrl.setBottomPanel(convCtrl.getPanel());
/* setup config option panel*/
mainCtrl.addMouseListener(getMouseListener());
/* setup systray controller */
SysTrayMenuListener systrayAction = new SysTrayMenuAdapter(){
public void menuItemSelected( SysTrayMenuEvent e ) {
// if the program is not loaded, ignore events
if (!loaded) return;
String command = e.getActionCommand().intern();
if (command == "Exit") {
shutdown();
}else if (command == "About"){
if (!aboutDlg.isVisible()){
aboutDlg.pack();
JFrame frame = mainCtrl.getFrame();
Dimension dlgSize = aboutDlg.getPreferredSize();
Dimension frmSize = frame.getSize();
Point loc = frame.getLocation();
aboutDlg.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
aboutDlg.show();
aboutDlg.toFront();
}else{
aboutDlg.toFront();
}
}else if (command == "Login"){
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -