Initial commit from SVN.

This commit is contained in:
wcrisman
2014-05-30 10:31:51 -07:00
commit b45e56b890
1968 changed files with 370949 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
/*
* Copyright (c) 2005,2006 Declarative Engineering LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Declarative Engineering LLC
* verson 1 which accompanies this distribution, and is available at
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
*/
package com.foundation.view.swt;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import com.common.comparison.Comparator;
import com.common.util.LiteHashMap;
import com.foundation.view.DisplayMetadata;
import com.foundation.view.IViewContext;
import com.foundation.view.IViewRequestHandler;
import com.foundation.view.ViewSystemMetadata;
/**
* This class provides access to the non-view specific view system functionality.
*/
public class SwtViewContext implements IViewContext {
/** The one and only SWT view context object. */
private static final SwtViewContext singleton = new SwtViewContext();
/** An application data map that allows the application to store key value pairs associated with the view context. */
private LiteHashMap applicationDataMap = null;
/** The application specific context data. */
private Object applicationData = null;
/**
* SwtViewContext constructor.
*/
private SwtViewContext() {
super();
}//SwtViewContext()//
/**
* Gets the one and only instance of the swt view context.
* @return The view context which provides access to the non-view specific view system functionality.
*/
public static SwtViewContext getSingleton() {
return singleton;
}//getSingleton()//
/**
* Gets the display for the swt view context.
* @return The swt view display.
*/
public Display getDisplay() {
return EventLoop.getSingleton().getDisplay();
}//getDisplay()//
/* (non-Javadoc)
* @see com.foundation.view.IViewContext#getViewSystemMetadata()
*/
public ViewSystemMetadata getViewSystemMetadata() {
org.eclipse.swt.widgets.Monitor[] monitors = getDisplay().getMonitors();
DisplayMetadata[] displayMetadata = new DisplayMetadata[monitors.length];
ViewSystemMetadata viewSystemMetadata = new ViewSystemMetadata(displayMetadata);
//Collect information about each monitor.//
for(int monitorIndex = 0; monitorIndex < monitors.length; monitorIndex++) {
Rectangle bounds = monitors[monitorIndex].getBounds();
Rectangle clientArea = monitors[monitorIndex].getClientArea();
displayMetadata[monitorIndex] = new DisplayMetadata(new int[] {bounds.x, bounds.y, bounds.width, bounds.height}, new int[] {clientArea.x, clientArea.y, clientArea.width, clientArea.height});
}//for//
return viewSystemMetadata;
}//getViewSystemMetadata()//
/* (non-Javadoc)
* @see com.foundation.view.IViewContext#getRequestHandler()
*/
public IViewRequestHandler getRequestHandler() {
return EventLoop.getSingleton();
}//getRequestHandler()//
/* (non-Javadoc)
* @see com.foundation.view.IViewContext#getApplicationData()
*/
public Object getApplicationData() {
return applicationData;
}//getApplicationData()//
/* (non-Javadoc)
* @see com.foundation.view.IViewContext#setApplicationData(java.lang.Object)
*/
public void setApplicationData(Object applicationData) {
this.applicationData = applicationData;
}//setApplicationData()//
/* (non-Javadoc)
* @see com.foundation.view.IViewContext#getApplicationData(java.lang.Object)
*/
public Object getApplicationData(Object key) {
return applicationDataMap == null ? null : applicationDataMap.get(key);
}//getApplicationData()//
/* (non-Javadoc)
* @see com.foundation.view.IViewContext#setApplicationData(java.lang.Object, java.lang.Object)
*/
public void setApplicationData(Object key, Object applicationData) {
if(applicationDataMap == null) {
applicationDataMap = new LiteHashMap(10, Comparator.getLogicalComparator(), Comparator.getLogicalComparator());
}//if//
applicationDataMap.put(key, applicationData);
}//setApplicationData()//
/**
* Shuts down the swt event loop, freeing the thread and allowing the application to close gracefully.
*/
public void shutdown() {
new Thread(new Runnable() {
public void run() {
EventLoop.getSingleton().stop();
}//run()//
}).start();
}//shutdown()//
}//SwtViewContext//