edu.umd.cfar.lamp.apploader
Class AppLoader

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjava.awt.Frame
                  extended byjavax.swing.JFrame
                      extended byedu.umd.cfar.lamp.apploader.AppLoader
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.RootPaneContainer, java.io.Serializable, javax.swing.WindowConstants

public class AppLoader
extends javax.swing.JFrame

A module loader uses the module rdf format to set up its menus and loads modules as beans in seperate windows. It extends JFrame, providing the main menu. The menu contains all the items specified in the preferences as attached to lal:Core, the uri for the running instance of this bean. See the AppLoader owl schema for more information.

Author:
davidm
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
 
Nested classes inherited from class java.awt.Frame
java.awt.Frame.AccessibleAWTFrame
 
Nested classes inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
AppLoader(PrefsManager prefs)
          Create a new application window for the application described in the referenced preferences.
 
Method Summary
static java.lang.Class box(java.lang.Class primitive)
          Get the box class for a primitive type.
static java.lang.Object[] checkMethod(java.lang.reflect.Method meth, java.lang.Object val)
          Checks that the method can take the given parameter.
 edu.umd.cfar.lamp.apploader.Actionator getActionForResource(com.hp.hpl.jena.rdf.model.Resource r)
          Assuming r describes an action, gets the action it describes.
 java.lang.Object getBean(java.lang.String uri)
          Gets a non-anonymous application bean by URI.
 java.awt.event.ActionListener getExitListener()
          Gets a listener for the exit action.
 HotkeyProcessor getHotkeyManager()
           
 java.awt.Image getIconFor(com.hp.hpl.jena.rdf.model.Resource beanR)
          If the provided bean/resource has an LAL.icon specified, this finds it, and returns it as a java image.
 java.lang.String getLabelFor(com.hp.hpl.jena.rdf.model.Resource beanR)
          Gets the localized label for the resource.
 java.lang.Object getLoadedBeanForResource(com.hp.hpl.jena.rdf.model.Resource r)
          Gets an application bean that has already been loaded.
 java.util.logging.Logger getLogger()
          Gets the java logger associated with this application's core bean.
 PrefsManager getPrefs()
          Get the preferences for the application
 com.hp.hpl.jena.rdf.model.Resource getResourceForBean(java.lang.Object bean)
          Gets the resource for the given application bean, if it has been loaded.
 java.awt.event.ActionListener getShowWindowActionListener()
          A ShowWindowAction tells the apploader to display a bean (its uri is passed as the command) in a JFrame, or bring it to the front if it already loaded in a JFrame.
 AttemptToPerformAction getVetoCloseAction()
          Gets the action that is currently invoked when the user tries to close the main frame.
static boolean getWindowModified(javax.swing.JComponent jc)
          Gets the 'window modified' property of the given Swing component.
 void initializeBeanFromResource(java.lang.Object bean, java.lang.Object parent, com.hp.hpl.jena.rdf.model.Resource r)
          Initializes bean in parent context.
 void initializeBeanFromResource(com.hp.hpl.jena.rdf.model.Resource r)
          Initialize the bean specified by the resource.
static boolean isMac()
          Determines if the application is running on a Macintosh.
 java.lang.Object loadBeanFromResource(com.hp.hpl.jena.rdf.model.Resource r)
          Load a bean from its resource.
static java.lang.Object loadObjectFromName(java.lang.String name)
          Construct a new instance of the Class referenced by the referenced java name.
static void main(java.lang.String[] args)
          Creates a new AppLoader and initializes it.
static boolean ofType(java.lang.Class type, java.lang.Object val)
          Checks to see that the object is assignable from the given type.
 java.lang.Object rdfNodeToValue(com.hp.hpl.jena.rdf.model.RDFNode propVal)
          Gets the java value represented by the RDFNode.
 java.lang.Object rdfNodeToValue(com.hp.hpl.jena.rdf.model.RDFNode propVal, java.lang.Object parent)
          Gets the java value represented by the RDFNode.
 void setLoadedBean(com.hp.hpl.jena.rdf.model.Resource r, java.lang.Object bean)
          Adds the given object to the list of loaded beans with the given URI.
 void setPrefs(PrefsManager prefs)
          Sets the prefs.
static void setProperty(java.lang.Object bean, java.lang.String prop, java.lang.Object val)
          Set a property on a bean using the javabeans patterns.
 void setVetoCloseAction(AttemptToPerformAction vetoCloseAction)
          Sets action handler to be invoked when the user tries to close the main window.
 void setWindowDocumentTitle(com.hp.hpl.jena.rdf.model.Resource r, java.lang.String docTitle)
          Sets the title of the document window to reflect the name of the document.
 void setWindowModified(com.hp.hpl.jena.rdf.model.Resource r, boolean val)
          Sets the windowModified field of the given frame.
 void shutdown()
          Exit the system, executing the appropriate shut down actions.
static java.net.URI string2uri(java.lang.String fname)
          Converts a string to a URI.
static java.lang.String toBeanGet(java.lang.String propName)
          Returns the method name for the getter of the given property.
static java.lang.String toBeanIs(java.lang.String propName)
          Returns the method name for the getter for boolean properties, aka the 'izzer'.
static java.lang.String toBeanSet(java.lang.String propName)
          Returns the method name for the setter of the given property.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Frame
addNotify, finalize, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Constructor Detail

AppLoader

public AppLoader(PrefsManager prefs)
          throws com.hp.hpl.jena.rdf.model.RDFException,
                 PreferenceException
Create a new application window for the application described in the referenced preferences.

Parameters:
prefs - Preferences (RDF Triples) that describes an application using the apploader schemata
Throws:
com.hp.hpl.jena.rdf.model.RDFException - Something is wrong with the graph
PreferenceException - Something is wrong with the graph's semantics
Method Detail

getBean

public java.lang.Object getBean(java.lang.String uri)
Gets a non-anonymous application bean by URI.

Parameters:
uri - the identifier of the bean to extract
Returns:
the bean value
Throws:
java.lang.IllegalArgumentException - if the bean is not found, the identifier is not valid, or there is some error while loading the bean from the preference data

rdfNodeToValue

public java.lang.Object rdfNodeToValue(com.hp.hpl.jena.rdf.model.RDFNode propVal)
                                throws PreferenceException
Gets the java value represented by the RDFNode. If no appropriate interpretation is found, it returns the parameter as a Resource. For example, a Resource that is known to be an lal:Bean will be converted to the bean it represents.

Parameters:
propVal - An RDFNode to convert
Returns:
The value the node represents/references
Throws:
PreferenceException
com.hp.hpl.jena.rdf.model.RDFException

rdfNodeToValue

public java.lang.Object rdfNodeToValue(com.hp.hpl.jena.rdf.model.RDFNode propVal,
                                       java.lang.Object parent)
                                throws PreferenceException
Gets the java value represented by the RDFNode. If no appropriate interpretation is found, it returns the parameter as a Resource. For example, a Resource that is known to be an lal:Bean will be converted to the bean it represents.

Parameters:
propVal - The node to convert/interpret/find.
parent - The context for the node; if it is a property value without a lal:propertyOf link, it assumes it is a property of this.
Returns:
The value the property refers to.
Throws:
PreferenceException
com.hp.hpl.jena.rdf.model.RDFException

loadObjectFromName

public static java.lang.Object loadObjectFromName(java.lang.String name)
                                           throws PreferenceException
Construct a new instance of the Class referenced by the referenced java name. It uses the no-arg constructor.

Parameters:
name - the name of the object to create
Returns:
A new instance of the object.
Throws:
PreferenceException - When the object couldn't be constructed for one reason or another, e.g. the named class can't be found or it doesn't have a no-arg constructor

loadBeanFromResource

public java.lang.Object loadBeanFromResource(com.hp.hpl.jena.rdf.model.Resource r)
                                      throws PreferenceException
Load a bean from its resource. Does not put it in the list of application beans.

Parameters:
r - The model node to reference f or construction.
Returns:
A new, unitialized instance of the bean.
Throws:
PreferenceException

getLoadedBeanForResource

public java.lang.Object getLoadedBeanForResource(com.hp.hpl.jena.rdf.model.Resource r)
Gets an application bean that has already been loaded.

Parameters:
r - The resource describing the bean
Returns:
The bean, or null if a bean matching the resource hasn't been loaded.

setLoadedBean

public void setLoadedBean(com.hp.hpl.jena.rdf.model.Resource r,
                          java.lang.Object bean)
Adds the given object to the list of loaded beans with the given URI. If the URI is already defined, this replaces it, but it does not replace it in any existing contexts.

Parameters:
r -
bean -

getResourceForBean

public com.hp.hpl.jena.rdf.model.Resource getResourceForBean(java.lang.Object bean)
Gets the resource for the given application bean, if it has been loaded. It uses the .equals method, which is questionable.

Parameters:
bean - The bean whose URI to find
Returns:
The URI, if found, or null, otherwise

initializeBeanFromResource

public void initializeBeanFromResource(com.hp.hpl.jena.rdf.model.Resource r)
                                throws PreferenceException
Initialize the bean specified by the resource. This means setting the properties as described in the preferences. It is a good idea to initialize the beans that r requires before initializing itself. The object must have already been initialized by loadBeanFromResource.

Parameters:
r - The description of the bean to initialize.
Throws:
PreferenceException

initializeBeanFromResource

public void initializeBeanFromResource(java.lang.Object bean,
                                       java.lang.Object parent,
                                       com.hp.hpl.jena.rdf.model.Resource r)
                                throws PreferenceException
Initializes bean in parent context. This is useful for dynamic beans.

Parameters:
bean - The object described by r that you wish to initialize
parent - The parent for the bean
r - The description of the bean to initialize.
Throws:
PreferenceException

getLabelFor

public java.lang.String getLabelFor(com.hp.hpl.jena.rdf.model.Resource beanR)
Gets the localized label for the resource.

Parameters:
beanR - The first RDFS.label for the resource found in the closest language to the user'
Returns:
The localized label

getIconFor

public java.awt.Image getIconFor(com.hp.hpl.jena.rdf.model.Resource beanR)
If the provided bean/resource has an LAL.icon specified, this finds it, and returns it as a java image.

Parameters:
beanR - The bean to check
Returns:
the image, if it is found, else null

toBeanSet

public static java.lang.String toBeanSet(java.lang.String propName)
Returns the method name for the setter of the given property.

Parameters:
propName - The java name of the property
Returns:
a method name in in the form setProp

toBeanGet

public static java.lang.String toBeanGet(java.lang.String propName)
Returns the method name for the getter of the given property. Note that there are two possible getter names, getprop and isprop.

Parameters:
propName - The java name of the property
Returns:
a method name in in the form getProp

toBeanIs

public static java.lang.String toBeanIs(java.lang.String propName)
Returns the method name for the getter for boolean properties, aka the 'izzer'. Note that there are two possible getter names, getprop and isprop.

Parameters:
propName - The java name of the property
Returns:
a method name in in the form isProp

getShowWindowActionListener

public java.awt.event.ActionListener getShowWindowActionListener()
A ShowWindowAction tells the apploader to display a bean (its uri is passed as the command) in a JFrame, or bring it to the front if it already loaded in a JFrame. This is useful for setting up a 'window' or 'view' menu. I'll probably modify it to support toolboxes and stuff later.

Returns:
The listener for the action.

shutdown

public void shutdown()
Exit the system, executing the appropriate shut down actions. This does not close the program, but does serialize the user preferences.


getExitListener

public java.awt.event.ActionListener getExitListener()
Gets a listener for the exit action.

Returns:
An ActionListener that runs 'shutdown' when an action is performed.

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        com.hp.hpl.jena.rdf.model.RDFException,
                        PreferenceException
Creates a new AppLoader and initializes it. Note that the preferences are loaded from the file specified by the "lal.prefs" property.

Parameters:
args - interpreted as triggers and flags specified in the preferences
Throws:
java.io.IOException
com.hp.hpl.jena.rdf.model.RDFException
PreferenceException

getPrefs

public PrefsManager getPrefs()
Get the preferences for the application

Returns:
PrefsManager The preferences.

setPrefs

public void setPrefs(PrefsManager prefs)
Sets the prefs. This won't cause them to be reparsed. It isn't clear what should be done, in that case.

Parameters:
prefs - The prefs to set

setProperty

public static void setProperty(java.lang.Object bean,
                               java.lang.String prop,
                               java.lang.Object val)
                        throws java.lang.IllegalArgumentException,
                               java.lang.IllegalAccessException,
                               java.lang.reflect.InvocationTargetException
Set a property on a bean using the javabeans patterns.

Parameters:
bean - The instance to modify.
prop - The name of the property to set
val - The new value of the property
Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

ofType

public static boolean ofType(java.lang.Class type,
                             java.lang.Object val)
Checks to see that the object is assignable from the given type. Unlike Class.isAssignableFrom, this also works for transfering between the boxed types and the primatives (e.g. Integer and int).

Parameters:
type -
val -
Returns:

box

public static java.lang.Class box(java.lang.Class primitive)
Get the box class for a primitive type. For example, if this is the Class for the int type, this returns Integer.class

Parameters:
primitive - The primitive type. If not a primitive, this returns null
Returns:
The corresponding box type

checkMethod

public static java.lang.Object[] checkMethod(java.lang.reflect.Method meth,
                                             java.lang.Object val)
Checks that the method can take the given parameter.

Parameters:
meth - The method to check.
val - The value to pass, or list of values for a multi-arg method
Returns:
the object array to pass to the method, if it is valid. Otherwise, returns null

string2uri

public static java.net.URI string2uri(java.lang.String fname)
Converts a string to a URI. If the string isn't already a valid URI, it is interpreted as a path to a file, and a file: URI is returned.

Parameters:
fname - The String to convert to a URI
Returns:
A valid URI from the given String.

getActionForResource

public edu.umd.cfar.lamp.apploader.Actionator getActionForResource(com.hp.hpl.jena.rdf.model.Resource r)
Assuming r describes an action, gets the action it describes.

Parameters:
r - The description of an action to take
Returns:
An instance (perhaps already constructed) fitting the description passed in
Throws:
java.lang.IllegalArgumentException - When the resource doesn't describe an understandable action

getVetoCloseAction

public AttemptToPerformAction getVetoCloseAction()
Gets the action that is currently invoked when the user tries to close the main frame.

Returns:
AttemptToPerformAction

setVetoCloseAction

public void setVetoCloseAction(AttemptToPerformAction vetoCloseAction)
Sets action handler to be invoked when the user tries to close the main window.

Parameters:
vetoCloseAction - The vetoCloseAction to set

isMac

public static boolean isMac()
Determines if the application is running on a Macintosh. This is useful for configuring the user interface.

Returns:
Returns true if the application is running on a mac.

setWindowDocumentTitle

public void setWindowDocumentTitle(com.hp.hpl.jena.rdf.model.Resource r,
                                   java.lang.String docTitle)
Sets the title of the document window to reflect the name of the document.

Parameters:
r - the bean to retitle
docTitle - the title of the edited document

setWindowModified

public void setWindowModified(com.hp.hpl.jena.rdf.model.Resource r,
                              boolean val)
Sets the windowModified field of the given frame. If isMac is true, it adds the dark dot to the red button. On others platforms, it appends an asterisk before the window title.

Parameters:
r - the bean to mark as modified/unmodified
val - true if the bean's contents have been modified since the last save point

getWindowModified

public static boolean getWindowModified(javax.swing.JComponent jc)
Gets the 'window modified' property of the given Swing component.

Parameters:
jc - the swing component to check
Returns:
true when the windowModified property is set to true

getLogger

public java.util.logging.Logger getLogger()
Gets the java logger associated with this application's core bean.

Returns:
the logger

getHotkeyManager

public HotkeyProcessor getHotkeyManager()
Returns:
Returns the hotkeyManager.