?? jzipjar.java
字號:
package org.jr.jzj;
/**
* <p>Copyright: Copyright (c) 2002-2003</p>
* <p>Company: JavaResearch(http://www.javaresearch.org)</p>
* <p>最后更新日期:2003年2月15日
* @author Cherami,Barney,Brain
* @version 0.8
*/
import java.util.*;
import java.util.prefs.*;
import java.awt.event.*;
import javax.swing.*;
import org.jr.swing.util.*;
/**
* 系統(tǒng)的運行類,完成系統(tǒng)的最初的初始化和版本判斷。
* <P>由于這個類是整個系統(tǒng)的入口,因此會完成很多初始化工作。
* <p>特別是由于本系統(tǒng)是針對JDK1.4設計的,因此需要對運行環(huán)境的JDK或者JRE進行判斷。
*/
public class JZipJar {
private static JZJLogger logger;
public static Preferences preference;
private static MainFrame frame;
/**
* 系統(tǒng)入口,完成必須的初始化和JDK版本判斷,一切正常的情況下運行系統(tǒng)
* @param args 命令行參數(shù)
*/
public static void main(String[] args) {
//判斷JDK或者JRE的的版本的兼容性,不兼容時退出
if (!canRun()) {
System.exit(1);
}
//系統(tǒng)初始化
init();
//一切正常,加載主界面
frame = new MainFrame();
frame.setIconImage(new ImageIcon(MainFrame.class.getResource(ImageNames.
img_f_icon)).getImage()); //設置應用程序圖標
frame.setSize(preference.getInt("mainframe_width", 640),
preference.getInt("mainframe_height", 480));
frame.setLocation(preference.getInt("mainframe_location_x", 0),
preference.getInt("mainframe_location_y", 0));
frame.show();
if (preference.getBoolean("mainframe_maximize", true)) {
frame.setExtendedState(JFrame.MAXIMIZED_BOTH); //設置為最大化模式
}
//是否自動打開文件打開對話框
if (preference.getBoolean("autoopen", false)) {
frame.open();
}
frame.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
preference.putInt("mainframe_width", frame.getWidth());
preference.putInt("mainframe_height", frame.getHeight());
preference.putBoolean("mainframe_maximize", SwingUtil.isMaximized(frame));
}
public void componentMoved(ComponentEvent e) {
preference.putInt("mainframe_location_x", frame.getLocationOnScreen().x);
preference.putInt("mainframe_location_y", frame.getLocationOnScreen().y);
}
}
);
}
/**
* 得到系統(tǒng)需要的全局的區(qū)域設置
* @return 全局的區(qū)域設置
*/
public static Locale getSystemLocale() {
Locale locale = Locale.getDefault();
//Locale locale=Locale.FRANCE;
//Locale locale=Locale.ENGLISH;
if (!locale.equals(Locale.getDefault())) {
Locale.setDefault(locale);
}
return locale;
}
/**
* 判斷本程序能否運行。
* <P>現(xiàn)在的條件是JRE的版本必須足夠并且沒有另一個此程序在運行
* @return 滿足所有條件時返回true,否則返回false
*/
private static boolean canRun() {
return isJREVersionCompatible();
}
/**
* 判斷本程序能否在用戶的JDK或者JRE環(huán)境下運行。
* <P>由于本程序是針對JDK1.4設計的,因此只有和JDK1.4兼容的環(huán)境下才能運行
* @return 用戶的JDK或者JRE版本和JDK1.4兼容時返回true,否則返回false
*/
private static boolean isJREVersionCompatible() {
// 加載測試類
Class testClass = null;
try {
testClass = Class.forName("java.lang.Object");
}
catch (ClassNotFoundException e) {
System.err.println(e);
return false;
}
// 得到包的版本信息并檢查兼容性
//由于日志功能也是1.4才推出的,因此在不兼容的時候向標準錯誤輸出而不是日志
Package testPackage = testClass.getPackage();
if (testPackage == null) {
System.err.println("No version information");
System.err.println(
"Pls use JRE compatible with SUN JDK 1.4 or later to run this program");
return false;
}
else if (!testPackage.isCompatibleWith("1.4")) {
System.err.println("JDK Vendor:" + testPackage.getImplementationVendor() +
",JDK version:" + testPackage.getSpecificationVersion());
System.err.println(
"Pls use JRE compatible with SUN JDK 1.4 or later to run this program");
return false;
}
return true;
}
/**
* 判斷用戶是否已經(jīng)打開了一個JZJ。
* @return 用戶已經(jīng)打開了一個時返回true,否則返回false
*/
private static boolean noExistedInstance() {
return preference.getBoolean("is_running", false);
}
/**
* 系統(tǒng)的初始化,完成系統(tǒng)所有的基本參數(shù)的加載工作。
*/
private static void init() {
preference = Preferences.userRoot().node("jzj");
JZJLogger.init(preference.get("log_file", "JZJlogs.log"),
preference.getInt("log_level", JZJLogger.ERROR),
preference.getBoolean("log_debug", true)); //初始化日志管理器
logger = new JZJLogger(JZipJar.class);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -