in batik-svgbrowser/src/main/java/org/apache/batik/apps/svgbrowser/Main.java [265:460]
public Main(String[] args) {
arguments = args;
if (Platform.isOSX) {
uiSpecialization = "OSX";
// Move the menu bars to the top of the screen.
System.setProperty("apple.laf.useScreenMenuBar", "true");
// Register listeners for the About and Preferences menu items
// in the application menu (using reflection).
try {
Class Application = Class.forName("com.apple.eawt.Application");
Class ApplicationListener =
Class.forName("com.apple.eawt.ApplicationListener");
Class ApplicationEvent =
Class.forName("com.apple.eawt.ApplicationEvent");
Method getApplication = Application.getMethod("getApplication",
new Class[0]);
Method addApplicationListener =
Application.getMethod("addApplicationListener",
new Class[] { ApplicationListener });
final Method setHandled =
ApplicationEvent.getMethod("setHandled",
new Class[] { Boolean.TYPE });
Method setEnabledPreferencesMenu =
Application.getMethod("setEnabledPreferencesMenu",
new Class[] { Boolean.TYPE });
InvocationHandler listenerHandler = new InvocationHandler() {
public Object invoke(Object proxy, Method method,
Object[] args) {
String name = method.getName();
if (name.equals("handleAbout")) {
JSVGViewerFrame relativeTo =
(JSVGViewerFrame) viewerFrames.get(0);
AboutDialog dlg = new AboutDialog(relativeTo);
// Work around pack() bug on some platforms
dlg.setSize(dlg.getPreferredSize());
dlg.setLocationRelativeTo(relativeTo);
dlg.setVisible(true);
dlg.toFront();
} else if (name.equals("handlePreferences")) {
JSVGViewerFrame relativeTo =
(JSVGViewerFrame) viewerFrames.get(0);
showPreferenceDialog(relativeTo);
} else if (name.equals("handleQuit")) {
// Do nothing, let the OS quit the app.
} else {
return null;
}
try {
setHandled.invoke(args[0],
new Object[] { Boolean.TRUE });
} catch (Exception e) {
}
return null;
}
};
Object application = getApplication.invoke(null, (Object[]) null);
setEnabledPreferencesMenu.invoke(application,
new Object[] { Boolean.TRUE });
Object listener =
Proxy.newProxyInstance(Main.class.getClassLoader(),
new Class[] { ApplicationListener },
listenerHandler);
addApplicationListener.invoke(application,
new Object[] { listener });
} catch (Exception ex) {
ex.printStackTrace();
uiSpecialization = null;
}
}
//
// Preferences
//
Map defaults = new HashMap(11);
defaults.put(PreferenceDialog.PREFERENCE_KEY_LANGUAGES,
Locale.getDefault().getLanguage());
defaults.put(PreferenceDialog.PREFERENCE_KEY_SHOW_RENDERING,
Boolean.FALSE);
defaults.put(PreferenceDialog.PREFERENCE_KEY_AUTO_ADJUST_WINDOW,
Boolean.TRUE);
defaults.put(PreferenceDialog.PREFERENCE_KEY_SELECTION_XOR_MODE,
Boolean.FALSE);
defaults.put(PreferenceDialog.PREFERENCE_KEY_ENABLE_DOUBLE_BUFFERING,
Boolean.TRUE);
defaults.put(PreferenceDialog.PREFERENCE_KEY_SHOW_DEBUG_TRACE,
Boolean.FALSE);
defaults.put(PreferenceDialog.PREFERENCE_KEY_PROXY_HOST,
"");
defaults.put(PreferenceDialog.PREFERENCE_KEY_PROXY_PORT,
"");
defaults.put(PreferenceDialog.PREFERENCE_KEY_CSS_MEDIA,
"screen");
defaults.put(PreferenceDialog.PREFERENCE_KEY_DEFAULT_FONT_FAMILY,
DEFAULT_DEFAULT_FONT_FAMILY);
defaults.put(PreferenceDialog.PREFERENCE_KEY_IS_XML_PARSER_VALIDATING,
Boolean.FALSE);
defaults.put(PreferenceDialog.PREFERENCE_KEY_ENFORCE_SECURE_SCRIPTING,
Boolean.TRUE);
defaults.put(PreferenceDialog.PREFERENCE_KEY_GRANT_SCRIPT_FILE_ACCESS,
Boolean.FALSE);
defaults.put(PreferenceDialog.PREFERENCE_KEY_GRANT_SCRIPT_NETWORK_ACCESS,
Boolean.FALSE);
defaults.put(PreferenceDialog.PREFERENCE_KEY_LOAD_JAVA,
Boolean.TRUE);
defaults.put(PreferenceDialog.PREFERENCE_KEY_LOAD_ECMASCRIPT,
Boolean.TRUE);
defaults.put(PreferenceDialog.PREFERENCE_KEY_ALLOWED_SCRIPT_ORIGIN,
ResourceOrigin.DOCUMENT);
defaults.put(PreferenceDialog.PREFERENCE_KEY_ALLOWED_EXTERNAL_RESOURCE_ORIGIN,
ResourceOrigin.ANY);
defaults.put(PREFERENCE_KEY_VISITED_URI_LIST,
"");
defaults.put(PREFERENCE_KEY_VISITED_URI_LIST_LENGTH,
MAX_VISITED_URIS);
defaults.put(PreferenceDialog.PREFERENCE_KEY_ANIMATION_RATE_LIMITING_MODE,
1);
defaults.put(PreferenceDialog.PREFERENCE_KEY_ANIMATION_RATE_LIMITING_CPU,
0.75f);
defaults.put(PreferenceDialog.PREFERENCE_KEY_ANIMATION_RATE_LIMITING_FPS,
(float) 10);
defaults.put(PreferenceDialog.PREFERENCE_KEY_USER_STYLESHEET_ENABLED,
Boolean.TRUE);
securityEnforcer
= new ApplicationSecurityEnforcer(this.getClass(),
SQUIGGLE_SECURITY_POLICY);
try {
preferenceManager = new XMLPreferenceManager(SQUIGGLE_CONFIGURATION_FILE,
defaults);
String dir = System.getProperty(PROPERTY_USER_HOME);
File f = new File(dir, BATIK_CONFIGURATION_SUBDIRECTORY);
f.mkdir();
XMLPreferenceManager.setPreferenceDirectory(f.getCanonicalPath());
preferenceManager.load();
setPreferences();
initializeLastVisited();
Authenticator.setDefault(new JAuthenticator());
} catch (Exception e) {
e.printStackTrace();
}
//
// Initialization
//
final AboutDialog initDialog = new AboutDialog();
((BorderLayout) initDialog.getContentPane().getLayout()).setVgap(8);
final JProgressBar pb = new JProgressBar(0, 3);
initDialog.getContentPane().add(pb, BorderLayout.SOUTH);
// Work around pack() bug on some platforms
Dimension ss = initDialog.getToolkit().getScreenSize();
Dimension ds = initDialog.getPreferredSize();
initDialog.setLocation((ss.width - ds.width) / 2,
(ss.height - ds.height) / 2);
initDialog.setSize(ds);
initDialog.setVisible(true);
final JSVGViewerFrame v = new JSVGViewerFrame(this);
JSVGCanvas c = v.getJSVGCanvas();
c.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() {
public void documentLoadingStarted(SVGDocumentLoaderEvent e) {
pb.setValue(1);
}
public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
pb.setValue(2);
}
});
c.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
pb.setValue(3);
}
});
c.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
initDialog.dispose();
v.dispose();
System.gc();
run();
}
});
c.setSize(100, 100);
svgInitializationURI = Main.class.getResource(SVG_INITIALIZATION).toString();
c.loadSVGDocument(svgInitializationURI);
}