Thinlet

package thinlet
public class Thinlet
extends java.awt.Container
implements java.lang.Runnable, java.io.Serializable

Constructor
publicThinlet()

public Thinlet()

Method
public voidadd(Object component)

public void add(java.lang.Object component)

Adds the specified component to the root desktop

Parameters:

component - a widget to be added

public voidadd(Object parent, Object component)

public void add(java.lang.Object parent, java.lang.Object component)

Adds the specified component to the end of the specified container

Parameters:

parent - a container

component - a component to be added

public voidadd(Object parent, Object component, int index)

public void add(java.lang.Object parent, java.lang.Object component, int index)

Adds the specified component to the container at the given position

Parameters:

parent - a container

component - a component to be inserted

index - the position at which to insert the component, or -1 to insert the component at the end

protected voidcharacters(String text)

protected void characters(java.lang.String text)

The SAX-like parser calls this method, you have to overwrite it

Parameters:

text - the content of a tag

public static Objectcreate(String classname)

public static java.lang.Object create(java.lang.String classname) throws java.lang.IllegalArgumentException

Creates a new component

Parameters:

classname - the widget type (e.g. button)

Returns:

a new component, every component is simply an Object

Throws:

java.lang.IllegalArgumentException - for unknown widget type

public booleandestroy()

public boolean destroy()

This method is called by the FrameLauncher if the window was closing, or AppletLauncher's destroy method. Overwrite it to e.g. save the application changes.

Returns:

true to exit, and false to keep the frame and continue the application

protected voidendElement()

protected void endElement()

The SAX-like parser calls this method, you have to overwrite it

public Objectfind(Object component, String name)

public java.lang.Object find(java.lang.Object component, java.lang.String name)

Finds the first component from the specified component by a name

Parameters:

component - the widget is searched inside this component

name - parameter value identifies the widget

Returns:

the first suitable component, or null

public Objectfind(String name)

public java.lang.Object find(java.lang.String name)

Finds the first component from the root desktop by a specified name value

Parameters:

name - parameter value identifies the widget

Returns:

the first suitable component, or null

public booleangetBoolean(Object component, String key)

public boolean getBoolean(java.lang.Object component, java.lang.String key)

Gets the property value of the given component by the property key

public StringgetChoice(Object component, String key)

public java.lang.String getChoice(java.lang.Object component, java.lang.String key)

Gets the property value of the given component by the property key

public static StringgetClass(Object component)

public static java.lang.String getClass(java.lang.Object component)

Gets the type of the given component

Parameters:

component - a widget

Returns:

the class name of the component (e.g. button)

public ColorgetColor(Object component, String key)

public java.awt.Color getColor(java.lang.Object component, java.lang.String key)

Get custom color of a component.

Parameters:

component - a component

key - the identifier of the parameter, e.g. "foreground"

Returns:

value of the custom color, or null if default color is used

public ComponentgetComponent(Object component, String key)

public java.awt.Component getComponent(java.lang.Object component, java.lang.String key)

Get the AWT component of the given (currently bean) widget

Parameters:

component - a bean widget

key - the identifier of the parameter

Returns:

an AWT component, or null

public intgetCount(Object component)

public int getCount(java.lang.Object component)

Gets the count of subcomponents in the list of the given component

Parameters:

component - a widget

Returns:

the number of components in this component

protected static StringgetDOMAttribute(Object node, String key)

protected static java.lang.String getDOMAttribute(java.lang.Object node, java.lang.String key)

Gets the attribute value by the specified key for a DOM tag

Parameters:

node - a specified tag

key - a string to identify the value pair

Returns:

the value, or null

protected static intgetDOMCount(Object node, String key)

protected static int getDOMCount(java.lang.Object node, java.lang.String key)

Gets the number of tags in a tag by a specified tagname

Parameters:

node - a specified tag

key - the searched tagname

Returns:

the number of tags

protected static ObjectgetDOMNode(Object node, String key, int index)

protected static java.lang.Object getDOMNode(java.lang.Object node, java.lang.String key, int index)

Gets the subtag of the specified tag by tagname and index

Parameters:

node - a specified tag

key - the searched tagname

index - the index of the requested subtag

Returns:

the found tag, or null

protected static StringgetDOMText(Object node)

protected static java.lang.String getDOMText(java.lang.Object node)

Gets the content string of a tag

Parameters:

node - a specified tag

Returns:

the value, or null

public ObjectgetDesktop()

public java.lang.Object getDesktop()

Get the topmost component

Returns:

the root object (it is a desktop), never null

public FontgetFont(Object component, String key)

public java.awt.Font getFont(java.lang.Object component, java.lang.String key)

Get custom font of a component.

Parameters:

component - a component

key - the identifier of the parameter, e.g. "font"

Returns:

may return null if the default font is used

public ImagegetIcon(Object component, String key)

public java.awt.Image getIcon(java.lang.Object component, java.lang.String key)

Gets the property value of the given component by the property key

public ImagegetIcon(String path)

public java.awt.Image getIcon(java.lang.String path)

Creates an image, and loads it immediately by default

Parameters:

path - is relative to your thinlet instance or the classpath (if the path starts with '/' character), or a full URL

Returns:

the loaded image or null

public ImagegetIcon(String path, boolean preload)

public java.awt.Image getIcon(java.lang.String path, boolean preload)

Creates an image from the specified resource. To speed up loading the same images use a cache (a simple hashtable). And flush the resources being used by an image when you won't use it henceforward

Parameters:

path - is relative to your thinlet instance or the classpath, or an URL

preload - waits for the whole image if true, starts loading (and repaints, and updates the layout) only when required (painted, or size requested) if false

Returns:

the loaded image or null

public intgetInteger(Object component, String key)

public int getInteger(java.lang.Object component, java.lang.String key)

Gets the property value of the given component by the property key

public ObjectgetItem(Object component, int index)

public java.lang.Object getItem(java.lang.Object component, int index)

Returns the subcomponent of the given component's specified list at the given index

Parameters:

component - a specified container

index - the index of the component to get

Returns:

the indexth component in this container

public Object[]getItems(Object component)

public java.lang.Object[] getItems(java.lang.Object component)

Gets all the components in this container

Parameters:

component - a specified container

Returns:

an array of all the components in this container

public ObjectgetParent(Object component)

public java.lang.Object getParent(java.lang.Object component)

Gets the parent of this component

Parameters:

component - a widget

Returns:

the parent container of this component or item

public DimensiongetPreferredSize()

public java.awt.Dimension getPreferredSize()

Gets the preferred size of the root component

Overrides:

getPreferredSize in class java.awt.Container

Returns:

a dimension object indicating the root component's preferred size

public ObjectgetProperty(Object component, Object key)

public java.lang.Object getProperty(java.lang.Object component, java.lang.Object key)

Returns the value of the property with the specified key.

Parameters:

component - searches the hashtable of this component

key - the client property key

Returns:

the value to which the key is mapped or null if the key is not mapped to any value

public intgetSelectedIndex(Object component)

public int getSelectedIndex(java.lang.Object component)

Gets the index of the first selected item in the given component

Parameters:

component - a widget (combobox, tabbedpane, list, table, or tree)

Returns:

the first selected index or -1

public ObjectgetSelectedItem(Object component)

public java.lang.Object getSelectedItem(java.lang.Object component)

Gets the first selected item of the given component

Parameters:

component - a widget (combobox, tabbedpane, list, table, or tree)

Returns:

the first selected item or null

public Object[]getSelectedItems(Object component)

public java.lang.Object[] getSelectedItems(java.lang.Object component)

Gets the selected item of the given component (list, table, or tree) when multiple selection is allowed

Parameters:

component - a widget

Returns:

the array of selected items, or a 0 length array

public StringgetString(Object component, String key)

public java.lang.String getString(java.lang.Object component, java.lang.String key)

Gets the property value of the given component by the property key

public ObjectgetWidget(Object component, String key)

public java.lang.Object getWidget(java.lang.Object component, java.lang.String key)

protected voidhandleException(Throwable throwable)

protected void handleException(java.lang.Throwable throwable)

Overwrite this method to handle exceptions thrown by the invoked custom methods

Parameters:

throwable - the thrown exception by the bussiness logic

public booleanisFocusTraversable()

public boolean isFocusTraversable()

This component can be traversed using Tab or Shift-Tab keyboard focus traversal, although 1.4 replaced this method by isFocusable, so 1.4 compilers write deprecation warning

Overrides:

isFocusTraversable in class java.awt.Component

Returns:

true as focus-transverable component, overwrites the default false value

public voidpaint(Graphics g)

public void paint(java.awt.Graphics g)

Paints the components inside the graphics clip area

Overrides:

paint in class java.awt.Container

public Objectparse(InputStream inputstream)

public java.lang.Object parse(java.io.InputStream inputstream) throws java.io.IOException

Creates a component from the given stream

Parameters:

inputstream - e.g. new URL("http://myserver/myservlet").openStream()

Returns:

the root component of the parsed stream

Throws:

java.io.IOException -

public Objectparse(InputStream inputstream, Object handler)

public java.lang.Object parse(java.io.InputStream inputstream, java.lang.Object handler) throws java.io.IOException

Creates a component from the given stream and event handler

Parameters:

inputstream - read xml from this stream

handler - event handlers are implemented in this object

Returns:

the parsed components' root

Throws:

java.io.IOException -

public Objectparse(String path)

public java.lang.Object parse(java.lang.String path) throws java.io.IOException

Creates a component (and its subcomponents, and properties) from the given xml resource

Parameters:

path - is relative to your thinlet instance or the classpath (if the path starts with an / character), or a full URL

Returns:

the root component of the parsed resource

Throws:

java.io.IOException -

public Objectparse(String path, Object handler)

public java.lang.Object parse(java.lang.String path, java.lang.Object handler) throws java.io.IOException

Creates a component from the given xml resource using the specified event handler

Parameters:

path - is relative to your application package or the classpath, or an URL

handler - bussiness methods are implemented in this object

Returns:

the parsed components' root

Throws:

java.io.IOException -

protected ObjectparseDOM(InputStream inputstream)

protected java.lang.Object parseDOM(java.io.InputStream inputstream) throws java.io.IOException

You can use the internal xml parser as a simple DOM-like parser, use the getDOMAttribute, getDOMText, getDOMCount, getDOMNode, getClass, and getParent methods to analise the document

Parameters:

inputstream - e.g. new URL("http://myserver/myservlet").openStream()

Returns:

the root tag

Throws:

java.io.IOException -

protected voidparseXML(InputStream inputstream)

protected void parseXML(java.io.InputStream inputstream) throws java.io.IOException

You can use the internal xml parser as a simple SAX-like parser, during the process it calls the startElement, characters, and endElement methods

Parameters:

inputstream - e.g. new URL("http://myserver/myservlet").openStream()

Throws:

java.io.IOException -

protected voidprocessEvent(AWTEvent e)

protected void processEvent(java.awt.AWTEvent e)

Dispatches mouse, key, focus, and component events occurring on the Thinlet component internally

Overrides:

processEvent in class java.awt.Container

public voidputProperty(Object component, Object key, Object value)

public void putProperty(java.lang.Object component, java.lang.Object key, java.lang.Object value)

Binds the specified key to the specified value, and stores in this component. Null value removes the property. Use the parameter tag in the xml resource to bind a string value, the format is: parameter='key=value'

Parameters:

component - the hashtable is binded to this component

key - the client property key

value - the new client property value

public voidremove(Object component)

public void remove(java.lang.Object component)

Remove the specified component from its parent list, or delete component's popupmenu or table's header

Parameters:

component - the component to be removed

public voidremoveAll(Object component)

public void removeAll(java.lang.Object component)

Removes all the components from this container's specified list

Parameters:

component - the specified container

public voidrepaint(Object component)

public void repaint(java.lang.Object component)

Repaint the given component's area later

Parameters:

component - a visible widget inside thinlet desktop

public booleanrequestFocus(Object component)

public boolean requestFocus(java.lang.Object component)

Requests that both the Thinlet component, and the given widget get the input focus

Parameters:

component - a focusable widget inside visible and enabled parents, and tabbedpane's selected tab

Returns:

true, if the given component was focusable

public synchronized voidrun()

public synchronized void run()

A second thread is used to repeat value change events for scrollbar or spinbox during the mouse is pressed, or to pop up tooltip

public voidsetBoolean(Object component, String key, boolean value)

public void setBoolean(java.lang.Object component, java.lang.String key, boolean value)

Sets the given property pair (key and value) for the component

public voidsetChoice(Object component, String key, String value)

public void setChoice(java.lang.Object component, java.lang.String key, java.lang.String value)

Sets the given property pair (key and value) for the component

public voidsetColor(Object component, String key, Color color)

public void setColor(java.lang.Object component, java.lang.String key, java.awt.Color color)

Set custom color on a component. Notes: For "foreground" key, this sets the text color. For "background" key, on gradient-filled components (such as tabs, buttons etc) this will result in a component filled with solid background color, and not a new gradient. Also, Color.brighter() will be used for highlight, and Color.darker() will be used for pressed or not selected.

Parameters:

component - component to use for custom color

key - currently "background" and "foreground" are supported

color - custom color to use, or null to reset component to use default color

public voidsetColors(int background, int text, int textbackground, int border, int disable, int hover, int press, int focus, int select)

public void setColors(int background, int text, int textbackground, int border, int disable, int hover, int press, int focus, int select)

Sets the 9 colors used for components, and repaints the whole UI

Parameters:

background - the backround of panels (dialogs, desktops), and disabled controls, not editable texts, lines between list items (the default value if #e6e6e6)

text - for text, arrow foreground (black by default)

textbackground - the background of text components, and lists (white by default)

border - for outer in inner borders of enabled components (#909090 by default)

disable - for text, border, arrow color in disabled components (#b0b0b0 by default)

hover - indicates that the mouse is inside a button area (#ededed by default)

press - for pressed buttons, gradient image is calculated using the background and this press color (#b9b9b9 by default)

focus - for text caret and rectagle color marking the focus owner (#89899a by default)

select - used as the background of selected text, and list items, and in slider (#c5c5dd by default)

public voidsetComponent(Object component, String key, Component bean)

public void setComponent(java.lang.Object component, java.lang.String key, java.awt.Component bean)

Set the AWT component for the given (currently bean) widget

Parameters:

component - a bean widget

key - the identifier of the parameter

bean - an AWT component, or null

public voidsetFont(Font font)

public void setFont(java.awt.Font font)

Sets the only one font used everywhere, and revalidates the whole UI. Scrollbar width/height, spinbox, and combobox button width, and slider size is the same as the font height

Overrides:

setFont in class java.awt.Container

Parameters:

font - the default font is SansSerif, plain, and 12pt

public voidsetFont(Object component, Font font)

public void setFont(java.lang.Object component, java.awt.Font font)

Set custom font on a component, use the other setFont method instead

public voidsetFont(Object component, String key, Font font)

public void setFont(java.lang.Object component, java.lang.String key, java.awt.Font font)

Set custom font on a component

Parameters:

component - component to use the custom font

font - custom font to use, or null to reset component to use default font

public voidsetIcon(Object component, String key, Image icon)

public void setIcon(java.lang.Object component, java.lang.String key, java.awt.Image icon)

Sets the given property pair (key and value) for the component

public voidsetInteger(Object component, String key, int value)

public void setInteger(java.lang.Object component, java.lang.String key, int value)

Sets the given property pair (key and value) for the component

public voidsetKeystroke(Object component, String key, String value)

public void setKeystroke(java.lang.Object component, java.lang.String key, java.lang.String value)

public voidsetMethod(Object component, String key, String value, Object root, Object handler)

public void setMethod(java.lang.Object component, java.lang.String key, java.lang.String value, java.lang.Object root, java.lang.Object handler) throws java.lang.IllegalArgumentException

Sets a new event handler method for a component

Parameters:

component - the target component

key - the key name of the parameter (e.g. action)

value - the method name and parameters (e.g. foo(this, this.text, mybutton, mybutton.enabled) for public void foo(Object component, String text, Object mybutton, boolean enabled))

root - the search starting component for name components in the arguments

handler - the target event handler object including the method

Throws:

java.lang.IllegalArgumentException -

public voidsetResourceBundle(ResourceBundle resourcebundle)

public void setResourceBundle(java.util.ResourceBundle resourcebundle) throws java.util.MissingResourceException

Set a bundle used in parse method, it replaces the parameter values starting with the 'i18n.' string with a value found in the given bundle

Parameters:

resourcebundle - a bundle for the next parsing or null to remove the current one

Throws:

java.util.MissingResourceException - if no object for the given key can be found

public voidsetString(Object component, String key, String value)

public void setString(java.lang.Object component, java.lang.String key, java.lang.String value)

Sets the given property pair (key and value) for the component

protected voidstartElement(String name, Hashtable attributelist)

protected void startElement(java.lang.String name, java.util.Hashtable attributelist)

The SAX-like parser calls this method, you have to overwrite it

Parameters:

name - of the tag

attributelist - a list of attributes including keys and value pairs

public voidupdate(Graphics g)

public void update(java.awt.Graphics g)

Invokes the paint method

Overrides:

update in class java.awt.Container