001: /*
002: * Created on Jun 23, 2004
003: *
004: * TODO To change the template for this generated file go to
005: * Window - Preferences - Java - Code Style - Code Templates
006: */
007: package net.refractions.udig.internal.ui;
008:
009: import java.awt.Rectangle;
010: import java.rmi.server.UID;
011: import java.util.Iterator;
012: import java.util.Set;
013:
014: import javax.units.SI;
015:
016: import net.refractions.udig.ui.graphics.SWTGraphics;
017: import net.refractions.udig.ui.internal.Messages;
018:
019: import org.eclipse.core.runtime.IPlatformRunnable;
020: import org.eclipse.core.runtime.Platform;
021: import org.eclipse.jface.dialogs.MessageDialog;
022: import org.eclipse.swt.graphics.Image;
023: import org.eclipse.swt.graphics.Path;
024: import org.eclipse.swt.widgets.Display;
025: import org.eclipse.ui.PlatformUI;
026: import org.eclipse.ui.application.WorkbenchAdvisor;
027: import org.geotools.referencing.FactoryFinder;
028:
029: public class UDIGApplication implements IPlatformRunnable {
030:
031: @SuppressWarnings("unused")
032: public Object run(Object args) {
033: WorkbenchAdvisor workbenchAdvisor = new UDIGWorkbenchAdvisor();
034: Display display = PlatformUI.createDisplay();
035:
036: boolean shutdown = init();
037: if (shutdown)
038: return IPlatformRunnable.EXIT_OK;
039:
040: int returnCode = IPlatformRunnable.EXIT_OK;
041: try {
042: returnCode = PlatformUI.createAndRunWorkbench(display,
043: workbenchAdvisor);
044: } catch (Throwable t) {
045: UiPlugin.log(Messages.UDIGApplication_error, t);
046: } finally {
047: Platform.endSplash();
048: display.dispose();
049: }
050: if (returnCode == PlatformUI.RETURN_RESTART)
051: return IPlatformRunnable.EXIT_RESTART;
052: return IPlatformRunnable.EXIT_OK;
053: }
054:
055: private boolean init() {
056: checkForJAI();
057:
058: if (!checkForGDI())
059: return true;
060:
061: loadCommonlyUsedObject();
062:
063: return false;
064: }
065:
066: private void loadCommonlyUsedObject() {
067: //potential fix for win32 (occasionally blocks in Drawing.feature(Point/etc) during first render)
068: new UID(); //seed the random number generator
069:
070: load(FactoryFinder.getCoordinateOperationAuthorityFactories());
071: load(FactoryFinder.getCoordinateOperationAuthorityFactories());
072: load(FactoryFinder.getCRSFactories());
073: load(FactoryFinder.getCSFactories());
074: load(FactoryFinder.getDatumAuthorityFactories());
075: load(FactoryFinder.getDatumFactories());
076: load(FactoryFinder.getMathTransformFactories());
077: @SuppressWarnings("unused")
078: Object o = SI.BIT;
079: o = SI.GRAM;
080: o = SI.KILOGRAM;
081: o = SI.METER;
082: o = SI.RADIAN;
083: o = SI.SECOND;
084: o = SI.STERADIAN;
085: }
086:
087: private void load(Set coordinateOperationAuthorityFactories) {
088: for (Iterator iter = coordinateOperationAuthorityFactories
089: .iterator(); iter.hasNext();) {
090: iter.next();
091: }
092: }
093:
094: private boolean checkForGDI() {
095: if (Platform.getOS().equals(Platform.OS_WIN32)) {
096: // test to make sure that GDI+ is installed
097: Image image = null;
098: Path path = null;
099: try {
100: image = new Image(Display.getCurrent(), 10, 10);
101: path = SWTGraphics.convertToPath(new Rectangle(0, 0, 8,
102: 8), Display.getCurrent());
103: } catch (Exception e) {
104: MessageDialog
105: .openError(
106: Display.getCurrent().getActiveShell(),
107: Messages.UDIGApplication_title,
108: Messages.UDIGApplication_error1
109: + Messages.UDIGApplication_error2
110: + "http://www.microsoft.com/downloads/details.aspx?FamilyID=6A63AB9C-DF12-4D41-933C-BE590FEAA05A&displaylang=en"); //$NON-NLS-1$
111: return false;
112: } finally {
113: if (image != null)
114: image.dispose();
115: if (path != null)
116: path.dispose();
117: }
118: }
119: return true;
120: }
121:
122: private void checkForJAI() {
123: try {
124: Class.forName("javax.media.jai.operator.OrDescriptor"); //$NON-NLS-1$
125: } catch (Throwable th) {
126: JaiErrorDialog.display();
127: }
128: }
129: }
|