|
jrworkspace by jTEM |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.jtem.jrworkspace.plugin.simplecontroller.SimpleController
public class SimpleController
A simple implementation of the Controller
interface.
It creates a JFrame if a plug-in with PerspectiveFlavor
is registered. First call registerPlugin(Plugin)
to insert a plug-in. Then call
startup()
to initialize the application.
Plugin
s to read and save properties. These properties
are read from and saved to a file
at startup and shutdown via XStream.
When shutdown()
is called (from the main windows closing method or from a plugin that implements
ShutdownFlavor
) the user gets the chance to decide where the properties are saved.
The decisions are saved
via the java preferences API (see setPropertiesResource(Class, String)
. If nothing
else is specified the SimpleController
tries to read the plugin properties from
System.getProperty("user.home") + "/.jrworkspace/default_simple.xml"and saves the user decisions in the preferences node of the package of the SimpleController.
Besides the name (and path) of the properties file the user may choose
true
), PropertiesFlavor
).It is recommended that applications call
setPropertiesResource(MyClass.class,"propertiesFileName")before calling
startup()
. Then the controller loads the plugin properties from this resource. After deployment this
resource may most likely only be opened for reading, which has the effect that it will only be used
to call setPropertiesInputStream(InputStream)
and the properties file will retain its default
value or whatever it is set to via setPropertiesFile(File)
.
When loading properties the availability of a properties file is checked in the following order
true
true
or both files above can't be opened for writing.
Note to Eclipse developers: if you change the path of the file to save the properties into in the dialog at shutdown to point to the source folder and DISABLE the load from this file check box, then the resource will be accessed to load the properties (and the situation after deployment is always tested) and the source folder file is used to save (which then may be included in version control). In order to trigger copying of the source folder file to the bin folder one may add a do nothing builder which has "Refresh resources upon completion" enabled and make sure that the "Filtered resources" do not filter this file.
Plugin
Nested Class Summary | |
---|---|
protected class |
SimpleController.FlavorListener
The methods in this class are intended to be invoked when the respective controller is started. |
protected class |
SimpleController.MenuFlavorComparator
|
static class |
SimpleController.Status
|
protected class |
SimpleController.ToolBarFlavorComparator
|
Constructor Summary | |
---|---|
SimpleController()
Construct a SimpleController. |
Method Summary | ||
---|---|---|
protected void |
activatePlugin(Plugin p)
|
|
|
deleteProperty(Class<?> context,
String key)
Deletes a property from this controller |
|
|
getPlugin(Class<T> clazz)
Returns an instance of the plug-in class clazz, if there is a plug-in of this class available. |
|
|
getPlugins(Class<T> clazz)
Returns all plug-ins for which the following expression evaluates to true pClass.isAssignableFrom(plug-in) |
|
|
getProperty(Class<?> context,
String key,
T defaultValue)
Retrieves a property from this Controller. |
|
String |
getUserPropertyFile()
|
|
protected void |
initializeComponents()
|
|
boolean |
isActive(Plugin p)
Returns true if the controller believes this plug-in is active |
|
boolean |
isAskBeforeSaveOnExit()
|
|
boolean |
isLoadFromUserPropertyFile()
|
|
boolean |
isSaveOnExit()
|
|
protected void |
loadProperties()
|
|
protected void |
readUserPreferences()
|
|
void |
registerPlugin(Plugin p)
Registers a plug-in with this SimpleController |
|
protected boolean |
savePropertiesOnExit()
|
|
void |
setAskBeforeSaveOnExit(boolean askBeforeSaveOnExit)
|
|
void |
setFullscreen(boolean fs)
If there is a main window it's full-screen mode can be changed with this method |
|
void |
setLoadFromUserPropertyFile(boolean loadFromUserPropertyFile)
|
|
void |
setManageLookAndFeel(boolean manageLookAndFeel)
The SimpleController manages the swing look and feel if this flag is set |
|
void |
setPropertiesFile(File propertiesFile)
Sets the properties File of this SimpleController. |
|
void |
setPropertiesInputStream(InputStream in)
Sets the properties InputStream of this SimpleController. |
|
void |
setPropertiesResource(Class<?> clazz,
String propertiesFileName)
The provided resource serves 2 purposes: to set the properties File and InputStream via setPropertiesFile(File)
(if this resource allows write access) and setPropertiesInputStream(InputStream)
(if this resource allows read access),
to save and read user decisions about the reading and loading of the property file in a package specific node, via
the Java Preferences API. |
|
void |
setSaveOnExit(boolean saveOnExit)
|
|
void |
setShowMenuBar(boolean show)
Hides or reveals this controllers menu bar |
|
void |
setShowPreferencesWindow(boolean show)
Sets the visibility state of the preferences windows if there is one |
|
void |
setShowStatusBar(boolean show)
Hides or reveals this controllers status bar |
|
void |
setShowToolBar(boolean show)
Hides or reveals this controllers tool bar |
|
void |
setUserPropertyFile(String userPropertyFile)
Overwrite or initialize the file chosen by the user for reading and writing of properties. |
|
void |
shutdown()
Call this method to save the properties and exit the application. |
|
void |
startup()
Installs all registered plug-ins, reads user preferences, restores plugin properties, and opens the main window if there is a plug-in implementing PerspectiveFlavor |
|
JRootPane |
startupLocal()
Starts this SimpleController but does not open the main window instead it returns the content panel of this window that can be used outside of the controller. |
|
Object |
storeProperty(Class<?> context,
String key,
Object property)
Stores the property with the given key and context class |
|
protected void |
updateMainWindow()
|
|
protected void |
updateMenuBarInternal()
|
|
protected void |
updateToolBar()
|
|
protected void |
writeUserPreferences()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected AboutDialog aboutDialog
protected JPanel centerPanel
protected static boolean DEFAULT_ASK_BEFORE_SAVE_ON_EXIT
protected static boolean DEFAULT_LOAD_FROM_USER_PROPERTY_FILE
protected static boolean DEFAULT_SAVE_ON_EXIT
protected static String DEFAULT_USER_PROPERTY_FILE
protected Stack<Plugin> dependencyStack
protected SimpleController.FlavorListener flavorListener
protected Frame fullScreenFrame
protected boolean hasHelpMenu
protected boolean hasMainWindow
protected boolean hasMenuBar
protected boolean hasPreferencesMenu
protected boolean hasStatusBar
protected boolean hasToolBar
protected HelpWindow helpWindow
protected HelpWindowAction helpWindowAction
protected Set<Class<? extends Plugin>> installed
protected boolean localStartup
protected JFrame mainWindow
protected boolean manageLookAndFeel
protected PerspectiveFlavor perspective
protected Set<Plugin> plugins
protected PreferencesWindow preferencesWindow
protected HashMap<String,Object> properties
protected com.thoughtworks.xstream.XStream propertyxStream
protected File propFile
protected InputStream propInputStream
protected SimpleController.Status status
protected JLabel statusLabel
protected JPanel toolBarPanel
protected Preferences userPreferences
Constructor Detail |
---|
public SimpleController()
shutdown()
.
Method Detail |
---|
protected void activatePlugin(Plugin p)
public <T> T deleteProperty(Class<?> context, String key)
Controller
deleteProperty
in interface Controller
T
- The property typecontext
- A contextkey
- The key name of the property to delete
public <T extends Plugin> T getPlugin(Class<T> clazz)
Controller
getPlugin
in interface Controller
T
- the class type of the plug-in to getclazz
- the class
public <T> List<T> getPlugins(Class<T> clazz)
Controller
getPlugins
in interface Controller
T
- the plug-in class typeclazz
- the class of type T
public <T> T getProperty(Class<?> context, String key, T defaultValue)
Controller
getProperty
in interface Controller
T
- The property typecontext
- A contextkey
- the key name of the property to retrievedefaultValue
- a default value, which is returned if the
property was not saved before
public String getUserPropertyFile()
protected void initializeComponents()
public boolean isActive(Plugin p)
Controller
isActive
in interface Controller
p
- the plug-in
public boolean isAskBeforeSaveOnExit()
public boolean isLoadFromUserPropertyFile()
public boolean isSaveOnExit()
protected void loadProperties()
protected void readUserPreferences()
public void registerPlugin(Plugin p)
p
- the plug-in to registerprotected boolean savePropertiesOnExit()
public void setAskBeforeSaveOnExit(boolean askBeforeSaveOnExit)
public void setFullscreen(boolean fs)
fs
- public void setLoadFromUserPropertyFile(boolean loadFromUserPropertyFile)
public void setManageLookAndFeel(boolean manageLookAndFeel)
manageLookAndFeel
- public void setPropertiesFile(File propertiesFile)
propertiesFile
- a file or nullsetPropertiesResource(Class, String)
public void setPropertiesInputStream(InputStream in)
File
is provided
the InputStream
is used for reading the properties.
in
- an InputStream or nullsetPropertiesResource(Class, String)
public void setPropertiesResource(Class<?> clazz, String propertiesFileName)
File
and InputStream
via setPropertiesFile(File)
(if this resource allows write access) and setPropertiesInputStream(InputStream)
(if this resource allows read access),
clazz
- the class from which the resource may be obtained, the the
properties node of package of this class is used to save the user decisions.
Can be null, then the user preferences are disabled and only static property files are used.propertiesFileName
- name of the resource that contains the plug-in properties. This argument may
be null, then only the second purpose is served and the properties File
and
InputStream
are NOT set to null and may be set independently.public void setSaveOnExit(boolean saveOnExit)
public void setShowMenuBar(boolean show)
show
- a flagpublic void setShowPreferencesWindow(boolean show)
show
- public void setShowStatusBar(boolean show)
show
- a flagpublic void setShowToolBar(boolean show)
show
- a flagpublic void setUserPropertyFile(String userPropertyFile)
userPropertyFile
- public void shutdown()
setPropertiesResource(Class, String)
public void startup()
PerspectiveFlavor
public JRootPane startupLocal()
public Object storeProperty(Class<?> context, String key, Object property)
Controller
storeProperty
in interface Controller
context
- the context class e.g. the plug-in class which stores the valuekey
- a key stringproperty
- the property to save
protected void updateMainWindow()
protected void updateMenuBarInternal()
protected void updateToolBar()
protected void writeUserPreferences()
|
jrworkspace by jTEM |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |