|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jgame.platform.AppConfig
public class AppConfig
A generic class for handling the user configuration of application
settings. It manages a set of fields that can be loaded, saved, and
edited. It can load and save configurations from/to both a file and an
object (reading/setting fields in the object), and it can create a GUI for
editing them. It can also be run on just an object (excluding the
possibility of saving to a file) or on just a file. The class has a
standard main() for editing a previously saved file, use java
jgame.AppConfig [filename]
.
The types and names of the fields can be obtained by either loading them from a previously saved file, or by deriving them from the object to be configured. AppConfig maintains a copy of the configurable fields and their types. You can choose when to load or save the contents of the AppConfig object to/from object or file. The GUI comes with a "Save" button (save to file and to object) and an "Apply" button (save to object, not to file). This class does not handle mismatches between fields in an object and in a corresponding file very robustly yet.
The Gui consists of a list of editable form fields. The name to display next to each field can be set manually or determined automatically from the field name in the object. The order in which the Gui fields are displayed is the same as that in which they are defined.
GameConfig is able to handle several types of fields. It determines the type of Gui element and the file representation automatically from the type. The following file format is used: each field is found on a separate line, in the format [fieldname] '\t' [guiname] '\t' [type] '\t' [value] It handles the following field types:
Class/Type GUI representation file representation int number field int [number] int keystroke field key [keycode] double number field double [number] boolean button boolean [true/false] String textfield String [string, \n is escaped as '\n']
Constructor Summary | |
---|---|
AppConfig(java.lang.String title,
java.lang.Class cls)
Configure a class with static fields without the possibility of file storage. |
|
AppConfig(java.lang.String title,
java.lang.Class cls,
java.lang.String filename)
Configure a class with static fields with corresponding file. |
|
AppConfig(java.lang.String title,
java.lang.Object obj)
Configure an object without the possibility of file storage. |
|
AppConfig(java.lang.String title,
java.lang.Object obj,
java.lang.String filename)
Configure an object with corresponding file. |
|
AppConfig(java.lang.String title,
java.lang.String filename)
Configure a file. |
Method Summary | |
---|---|
void |
closeGui()
Hide the Gui in case it was visible. |
void |
defineField(java.lang.String fieldname,
java.lang.String guiname,
java.lang.String type)
Define a field as configurable, ignore if field already exists. |
void |
defineFields(java.lang.String prefix,
java.lang.String suffix,
java.lang.String guiprefix,
java.lang.String guisuffix)
Define a set of fields as configurable, by matching the object's fields with the given pattern. |
void |
defineFields(java.lang.String prefix,
java.lang.String suffix,
java.lang.String guiprefix,
java.lang.String guisuffix,
java.lang.String type)
Define a set of fields as configurable, by matching the object's fields with the given pattern. |
java.lang.String |
getFilename()
Get the filespec of the file that this AppConfig is associated with, null if only object or class is defined. |
java.lang.Object |
getObject()
Get the object that this AppConfig is associated with, null if not defined. |
java.lang.Class |
getObjectClass()
Get the class that this AppConfig is associated with, null if only a file is defined. |
boolean |
isGuiOpen()
Check if GUI is visible right now. |
void |
loadFromFile()
Load settings from file. |
void |
loadFromObject()
Load settings from previously specified fields in object. |
static void |
main(java.lang.String[] args)
Edit a previously created file. |
void |
openGui()
Make the Gui visible on screen, and let the user make a selection whether to save, apply, or just close. |
void |
saveToFile()
Save settings to file. |
void |
saveToObject()
Save settings into object. |
void |
setField(java.lang.String field,
java.lang.Object value,
boolean update_gui)
Set field's value, given that field is already defined. |
void |
setGuiSettings(java.awt.Font mainfont,
java.awt.Font bigfont,
java.awt.Color textcolor,
java.awt.Color bgcolor,
java.awt.Color hltcolor)
Configure the look of the GUI |
void |
setListener(java.awt.event.ActionListener list)
Set listener for special events. |
void |
setObject(java.lang.Object obj)
Set or replace the object that this AppConfig should be associated with. |
java.lang.String |
toString()
|
void |
waitUntilGuiClosed()
Block until the Gui closes. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public AppConfig(java.lang.String title, java.lang.String filename)
public AppConfig(java.lang.String title, java.lang.Object obj, java.lang.String filename)
filename
- filespec, or null if no filepublic AppConfig(java.lang.String title, java.lang.Class cls, java.lang.String filename)
filename
- filespec, or null if no filepublic AppConfig(java.lang.String title, java.lang.Object obj)
public AppConfig(java.lang.String title, java.lang.Class cls)
Method Detail |
---|
public java.lang.String toString()
toString
in class java.lang.Object
public void setGuiSettings(java.awt.Font mainfont, java.awt.Font bigfont, java.awt.Color textcolor, java.awt.Color bgcolor, java.awt.Color hltcolor)
mainfont
- font used for labels and fieldsbigfont
- font used for title and buttonstextcolor
- colour used for all textbgcolor
- colour used for backgroundhltcolor
- colour used for highlighted background and fieldspublic static void main(java.lang.String[] args)
public java.lang.Object getObject()
public void setObject(java.lang.Object obj)
public java.lang.Class getObjectClass()
public java.lang.String getFilename()
public void setListener(java.awt.event.ActionListener list)
list
- null means disablepublic void loadFromFile()
public void saveToFile()
public void loadFromObject()
public void saveToObject()
public void defineField(java.lang.String fieldname, java.lang.String guiname, java.lang.String type)
public void defineFields(java.lang.String prefix, java.lang.String suffix, java.lang.String guiprefix, java.lang.String guisuffix)
defineFields(String,String,String,String,String)
public void defineFields(java.lang.String prefix, java.lang.String suffix, java.lang.String guiprefix, java.lang.String guisuffix, java.lang.String type)
type
- fieldtype, null means derive from fielddefineField(String,String,String)
public void setField(java.lang.String field, java.lang.Object value, boolean update_gui)
public void openGui()
public void closeGui()
public boolean isGuiOpen()
public void waitUntilGuiClosed()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |