mkv.MyGUI
Class MyGUIGroup

java.lang.Object
  extended bymkv.MyGUI.MyGUIObject
      extended bymkv.MyGUI.MyGUIGroup
Direct Known Subclasses:
MyGUI

public class MyGUIGroup
extends MyGUIObject

A non visible grouping object that contains other MyGUI elements. MyGUIGroup allows objects to be grouped so that they can be moved, rotated, enabled, disabled and hidden as a group. MyGUIGroup objects difer from traditional Panel objects because they have no width or height, and so do not crop objects that are out of bounds.

Objects placed in the group will be translated, rotated, and scaled before their own draw methods are called. MyGUIGroup also holds the responsibility of passing Mouse and Key events to members of the group. Part of this involves filtering events based on states such as _disabled and _visible. In other words, it only passes Key and Mouse events to objects which are visible and not disabled.

MyGUIGroup plays a larger role in the sense that the MyGUI object inherits many of its methods from the MyGUIGroup class. Originally it was the case that the code from MyGUI was used to build MyGUIGroup but this was obviously leading to a lot of redundancy.

Author:
John Beech
See Also:
MyGUIObject, MyGUI

Field Summary
 java.lang.String _actionCommand
          Description attached to an ActionEvent generated by the component.
 boolean _disabled
          Used to block mouse and key events.
 int _height
          Used to define the bounding box of an object.
 int _id
          The id used to self check if the object has focus.
 MyGUIObject _parent
          The MyGUIObject which acts as the parent of this object.
 processing.core.PApplet _root
          A direct reference to the main processing PApplet.
 float _rotation
          The value in degrees defining the object rotation.
 float _scale
          Visual scale of the object.
 MyGUIStyle _style
          A reference to a MyGUIStyle object used in draw or for font metrics.
 boolean _visible
          The visibility and active state of the object.
 int _width
          Used to define the bounding box of an object.
 int _x
          Positional coordinate of the object.
 int _y
          Positional coordinate of the object.
protected  boolean customMouse
          State if user wants to use custom mouse coordinates
protected  boolean dragged
          State where mouse is clicked and dragged across object.
protected  boolean hover
          State where mouse hovers over object.
protected  boolean lastHover
          State that changes when as a mouse moved outside bounding box.
 int tmouseX
          Local mouse coordinate based on parent.
 int tmouseY
          Local mouse coordinate based on parent.
 
Constructor Summary
MyGUIGroup(processing.core.PApplet root, int x, int y)
          Default class constructor.
MyGUIGroup(processing.core.PApplet root, int x, int y, int size)
          Class constructor where the size of the element array can be specified.
MyGUIGroup(processing.core.PApplet root, int x, int y, int size, MyGUIStyle style)
          Class constructor where you can specify the size of the element array and set the style.
MyGUIGroup(processing.core.PApplet root, int x, int y, MyGUIStyle style)
          Class constructor where you can specify the style but the element array stays at its default value.
 
Method Summary
 int add(MyGUIObject newElement)
          Adds a compatable MyGUI object as a child.
 boolean checkForHit()
          Defines the bounding box or 'hitzone' and returns true if the mouse is in contact.
 void disable()
          Disables this object so that it not longer receives mouse or keyboard events.
 void draw()
          Registered method that tells its children to draw.
 void drawStates()
          Interface method called by draw().
 void enable()
          Activates this object so it is able to receive mouse and keyboard events.
 MyGUIObject get(int index)
          Return an object based on the supplied index or id.
 MyGUIObject getFocused()
          Returns a reference to the MyGUIObject that currently has focus.
 int getFocusIndex()
          Returns the id/index of the currently focused element.
 MyGUIStyle getStyle()
          Returns the currently assigned style.
 boolean hasFocus()
          Returns true if the object has focus.
 boolean isDisabled()
          Checks the _disabled variable and its parent.
 boolean isDragged()
          Returns constant state of mouse clicked compared to this object.
 boolean isEmpty()
          Returns true if there are no elements in the group.
 boolean isFull()
          Returns true if the element array is full.
 void keyPressed(java.awt.event.KeyEvent e)
          Notifies the focus child of the keyPressed event.
 void keyReleased(java.awt.event.KeyEvent e)
          Notifies the focus child of the keyReleased event.
 void keyTyped(java.awt.event.KeyEvent e)
          Notifies the focus child of the keyTyped event.
 void mouseDragged()
          Notifies children of the mouseDragged event.
 void mousePressed()
          Notifies children of the mousePressed event.
 void mouseReleased()
          Notifies children of the mouseReleased event.
protected  float normalize(float n, float min, float max)
          Normalization function that ensures a value always lies within min/max.
 void remove(int id)
          Removes an element by its id.
 void rotate(float degs)
          Increases/decreases the _rotation attribute by the supplied amount.
 void rotateRadians(float rads)
          Increases/decreases the _rotation attribute by the given amount.
 void setActionCommand(java.lang.String command)
          Sets the descriptive action command when an ActionEvent is generated.
 void setID(int newID)
          Sets the unique id to the specified integer.
 void setMouseCoords(int x, int y)
          Allows the user to specify custom mouse coordinates.
 void setParent(MyGUIObject parent)
          Tells the object who its parent is.
 void setStyle(MyGUIStyle style)
          Sets the style of an object after initilisation.
 void updateLocalMouse()
          Calculates the local relative mouse coordinates.
 void useCustomMouse(boolean mode)
          Tells MyGUI that you want to use custom mouse coordinates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

customMouse

protected boolean customMouse
State if user wants to use custom mouse coordinates


_root

public processing.core.PApplet _root
A direct reference to the main processing PApplet. All drawing methods will be sent to to this object.


_parent

public MyGUIObject _parent
The MyGUIObject which acts as the parent of this object. Style, mouse coordinates, visibility and many other variables are inherited from a parent. Parents are not defined in the constructor, instead they must be set using the setParent() method.

See Also:
MyGUIObject.setParent(MyGUIObject parent)

_style

public MyGUIStyle _style
A reference to a MyGUIStyle object used in draw or for font metrics.


_x

public int _x
Positional coordinate of the object. The actual position will depend on the coordinates of parent objects. Parent objects can be translated, scaled and rotated. This means that the x,y coordinate is not an absolute screen position. The x,y coordinate normally define the rotation point of the object.

See Also:
MyGUIObject._rotation, MyGUIObject._scale, MyGUIObject._width, MyGUIObject._height

_y

public int _y
Positional coordinate of the object. The actual position will depend on the coordinates of parent objects. Parent objects can be translated, scaled and rotated. This means that the x,y coordinate is not an absolute screen position. The x,y coordinate normally define the rotation point of the object.

See Also:
MyGUIObject._rotation, MyGUIObject._scale, MyGUIObject._width, MyGUIObject._height

_width

public int _width
Used to define the bounding box of an object. Used both for drawing visual components such as the width and height of a button, and defining the default hit zone of an object. The value may not required in some objects, such as MyGUIGroup but is common in most elements.

See Also:
MyGUIObject._width, MyGUIObject._height, MyGUIObject._x, MyGUIObject._y, MyGUIObject.checkForHit()

_height

public int _height
Used to define the bounding box of an object. Used both for drawing visual components such as the width and height of a button, and defining the default hit zone of an object. The value may not required in some objects, such as MyGUIGroup but is common in most elements.

See Also:
MyGUIObject._width, MyGUIObject._height, MyGUIObject._x, MyGUIObject._y, MyGUIObject.checkForHit()

_id

public int _id
The id used to self check if the object has focus. The id is checked against a value in the parent to see if it has been granted focus. The object's id is commonly a reference to the index in MyGUIGroup elements[] where the object is grouped with other objects. In this situation _id is not unique. However, in programming more advanced grouping schemes this value may have a different role.

See Also:
MyGUIObject.hasFocus(), MyGUIGroup

_rotation

public float _rotation
The value in degrees defining the object rotation. This value is used to transform the drawing matrix and is used in updateLocalMouse(). It can be set directly or by using the rotateDegrees() and rotateRadians() methods.

See Also:
MyGUIObject.rotate(float), MyGUIObject.rotateRadians(float)

_scale

public float _scale
Visual scale of the object. Its default value is 1.0, increasing this makes the object look bigger on the screen, decreasing it makes it smaller. Negative values are allowed.


_visible

public boolean _visible
The visibility and active state of the object. True for visible, false for hidden. When hidden the object will not receive any mouse or key events, and so is practically disabled.

See Also:
MyGUIObject._disabled

_disabled

public boolean _disabled
Used to block mouse and key events. Set to true to disable an object, false for normal operation. When disabled an object should not receive any mouse or key events from its parents. It will still have its draw method called. To reflect the fact that it is disabled a draw state condition should be written to resemble something disabled and unoperable. MyGUIStyle contains a disabled colour which can be used to replace the face, or buttonFace colour in this situation.

See Also:
MyGUIObject._visible, MyGUIStyle.disabled

_actionCommand

public java.lang.String _actionCommand
Description attached to an ActionEvent generated by the component. If an object generates a MyGUIActionEvent then this string will be used for the Event's action command. It will be accessible by the ActionEvent.getActionCommand() method.

See Also:
MyGUIActionEvent, MyGUIObject.setActionCommand(String)

tmouseX

public int tmouseX
Local mouse coordinate based on parent. These integer coordinates reflect the local position of the mouse relative to where the object is now. They are calculated in the updateLocalMouse() method by looking at the parent's value and adjusting for _rotation, _scale and _x, _y translation.

See Also:
MyGUIObject.updateLocalMouse()

tmouseY

public int tmouseY
Local mouse coordinate based on parent. These integer coordinates reflect the local position of the mouse relative to where the object is now. They are calculated in the updateLocalMouse() method by looking at the parent's value and adjusting for _rotation, _scale and _x, _y translation.

See Also:
MyGUIObject.updateLocalMouse()

dragged

protected boolean dragged
State where mouse is clicked and dragged across object. Dragged is only set to true if the object has gained focus and the mouse has not yet been released. The instant that a user clicks inside the bounding box of the object dragged will be set. It is immediately unset on mouseRelease. The method isDragged() can be used to check this state in a program.

See Also:
MyGUIObject.isDragged()

hover

protected boolean hover
State where mouse hovers over object. The most accurate and current value for hover should be based off the boolean checkForHit() method. However, to minimise calls to this method the hover state can be used instead. A shape can be hovered and dragged at the same time.

See Also:
MyGUIObject.checkForHit(), MyGUIObject.lastHover

lastHover

protected boolean lastHover
State that changes when as a mouse moved outside bounding box. Although I've not implemented this anywhere yet, lastHover detected the change between a mouse hovering and not hovering. Important in conjunction with dragged because you may want a button to only respond if the mouse is released over the button as apposed to a user clicking, dragging, moving away from the button, and letting go. Its a fine line, but its actually a feature of most buttons that MyGUIButton neglects.

See Also:
MyGUIObject.hover, MyGUIObject.dragged, MyGUIButton
Constructor Detail

MyGUIGroup

public MyGUIGroup(processing.core.PApplet root,
                  int x,
                  int y)
Default class constructor.

Parameters:
root - a direct reference to the main processing PApplet.
x - x coordinate of the group
y - y coordinate of the group

MyGUIGroup

public MyGUIGroup(processing.core.PApplet root,
                  int x,
                  int y,
                  int size)
Class constructor where the size of the element array can be specified.

Parameters:
root - a direct reference to the main processing PApplet.
x - x coordinate of the group
y - y coordinate of the group
size - size of the element array. The default size is 25.

MyGUIGroup

public MyGUIGroup(processing.core.PApplet root,
                  int x,
                  int y,
                  int size,
                  MyGUIStyle style)
Class constructor where you can specify the size of the element array and set the style.

Parameters:
root - a direct reference to the main processing PApplet.
x - x coordinate of the group
y - y coordinate of the group
size - size of the element array. The default size is 25.
style - personalized style for this object and its children

MyGUIGroup

public MyGUIGroup(processing.core.PApplet root,
                  int x,
                  int y,
                  MyGUIStyle style)
Class constructor where you can specify the style but the element array stays at its default value.

Parameters:
root - a direct reference to the main processing PApplet.
x - x coordinate of the group
y - y coordinate of the group
style - personalized style for this object and its children
Method Detail

add

public int add(MyGUIObject newElement)
Adds a compatable MyGUI object as a child. I'll explain how this work in conjunction with the remove method.

When adding a new element, add first checks to see if there are any null entries in the element array caused by sudden removals. If one is found this will be used first. If there were no null elements and the number of elements is less then the size of the array, then the new element will be added first available place before the end of the array. If there are no spaces left in the array, this method will return -1.

When an object has been successfully added, the setParent() and setID() methods are called in the new object passing information down the hierarchy from parent to child.

Parameters:
newElement - A reference to the MyGUIObject to be added to the group.
Returns:
The id of the new object unique to this group. Returns -1 if the object could not be added.
See Also:
remove(int), MyGUIObject.setParent(MyGUIObject), MyGUIObject.setID(int)

remove

public void remove(int id)
Removes an element by its id. This id matches the id returned by the add method. When an element is removed its slot is set to null. The object is not destroyed from memory though, and you may have a reference to it elsewhere in the code. If you simlpy want to hide an element and stop it processing try setting the _visible state to false.

Parameters:
id - The id of the element to be removed.
See Also:
MyGUIObject._visible, add(MyGUIObject)

setStyle

public void setStyle(MyGUIStyle style)
Sets the style of an object after initilisation. Used to set a custom style for an object, and all its children. This works by reference, where the children look to their parent if they do not have their own style.

Overrides:
setStyle in class MyGUIObject
Parameters:
style - A reference to the new personalized style.
See Also:
MyGUIStyle, MyGUIObject._style

useCustomMouse

public void useCustomMouse(boolean mode)
Tells MyGUI that you want to use custom mouse coordinates. Use in conjunction with setMouseCoords(), this tells updateLocalMouse() not to update tmouseX and tmouseY with values from the parent object.

Parameters:
mode - Set true to use custom mouse. Set false to use parental mouse coordinates.
See Also:
setMouseCoords(int, int), updateLocalMouse()

setMouseCoords

public void setMouseCoords(int x,
                           int y)
Allows the user to specify custom mouse coordinates. The method useCustomMouse(true) must be called before this has any affect. It is the user's responsibility to constantly update these mouse coordinates.

Parameters:
x - the x coordinate of the mouse relative to this shape
y - the y coordinate of the mouse relative to this shape

getFocused

public MyGUIObject getFocused()
Returns a reference to the MyGUIObject that currently has focus. It will return null if no element is currently tracked.

Returns:
returns a reference to the MyGUIObject that currently has focus.
See Also:
get(int), getFocusIndex()

getFocusIndex

public int getFocusIndex()
Returns the id/index of the currently focused element. If no element has focus then -1 will be returned. 0 is a valid index/id for an element. You may need to check that id returned doesn't reference a group object that contains other elments, because there may be another focused child inside it.

Overrides:
getFocusIndex in class MyGUIObject
Returns:
the id or index of the current focused element.
See Also:
getFocused(), get(int)

get

public MyGUIObject get(int index)
Return an object based on the supplied index or id.

Parameters:
index - the index or id of the object when it was added to the element array.
Returns:
returns a reference
See Also:
getFocused(), getFocusIndex()

isEmpty

public boolean isEmpty()
Returns true if there are no elements in the group.

Returns:
returns true if there are no elements in the group.
See Also:
isFull()

isFull

public boolean isFull()
Returns true if the element array is full. First checks the numElements value for spare length at the end of the array, and then checks for null slots created by the remove() method.

Returns:
returns true if the element array is full
See Also:
isEmpty(), remove(int)

mousePressed

public void mousePressed()
Notifies children of the mousePressed event. When this method is called a single element may MyGUIGroup be given focus. Focus is a state necessary for a GUI element to perform actions. Elements with higher indexes will get focus priority over lower indexes. Higher index elements are also drawn last and so will appear on-top of other objects. The focus needs to be decided prior to passing mousePressed as mousePressed may rely on the state of focusIndex before it can work properly.

The method first filters based on the _visible and _disabled states. If either of these are true then no action will be taken, stopping the child elements from receiving this event.

The focus index is cleared, set to -1. It then loops backwards through the element array calling checkForHit() on each element and testing _disabled and _visible for each object. If checkForHit() is true, and the element is not disabled and is visible then the element will be given focus and the loop stopped. Only one element may have focus.

The array is looped through again this time to pass the mousePressed() call onto all the visible and active children. This is required so objects know when the mouse has been released outside their boundary.

Overrides:
mousePressed in class MyGUIObject
See Also:
MyGUIObject.mousePressed(), MyGUIObject.checkForHit(), MyGUIObject._visible, MyGUIObject._disabled

mouseReleased

public void mouseReleased()
Notifies children of the mouseReleased event. The method also filters non visible and disabled children, stopping them from receiving this event.

Overrides:
mouseReleased in class MyGUIObject
See Also:
MyGUIObject.mouseReleased(), MyGUIObject._visible, MyGUIObject._disabled

mouseDragged

public void mouseDragged()
Notifies children of the mouseDragged event. Like mouseReleased() the method also filters visible and disabled children, stopping them from receiving this event.

Overrides:
mouseDragged in class MyGUIObject
See Also:
MyGUIObject.mouseDragged(), MyGUIObject._visible, MyGUIObject._disabled

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Notifies the focus child of the keyPressed event. Unlike mouse events, KeyEvents will only be sent to the object that has focus.

Overrides:
keyPressed in class MyGUIObject
See Also:
MyGUIObject.keyPressed(KeyEvent), KeyEvent

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Notifies the focus child of the keyReleased event. Unlike mouse events, KeyEvents will only be sent to the object that has focus.

Overrides:
keyReleased in class MyGUIObject
See Also:
MyGUIObject.keyReleased(KeyEvent), KeyEvent

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Notifies the focus child of the keyTyped event. Unlike mouse events, KeyEvents will only be sent to the object that has focus.

Overrides:
keyTyped in class MyGUIObject
See Also:
MyGUIObject.keyTyped(KeyEvent), KeyEvent

draw

public void draw()
Registered method that tells its children to draw. This draw method performs several tasks. Firstly it changes the drawing matrix by translating, rotating and then scaling. Secondly it updates the local mouse coordinates relative to the translation, rotatation and scaled applied to its parent (see updateLocalMouse()). Thirdly it loops through all its child elements and calls their draw methods. Finally it calls the draw method of the element that has focus (if any) which means that the object that has focus will be drawn on top of everything else.

Overrides:
draw in class MyGUIObject
See Also:
updateLocalMouse()

updateLocalMouse

public void updateLocalMouse()
Calculates the local relative mouse coordinates. By local this means the tmouseX and tmouseY coordinates are set relative to the _x, _y position of this object. These are then used in public boolean checkForHit(); Note, the values are actually relative to the parent. You may need to multiply these values by scale if the current object has been scaled and you need the onscreen position.

This only applies if customMouse state is not set to true. If it is set, tmouseX and tmouseY are not updated and instead values used/set by setMouseCoords().

Overrides:
updateLocalMouse in class MyGUIObject
See Also:
useCustomMouse(boolean), setMouseCoords(int, int), MyGUIObject.checkForHit()

hasFocus

public boolean hasFocus()
Returns true if the object has focus. This method checks with its parent to see if this object has focus. If it doesn't, then it returns false. Compatable parent objects will keep a list of their children and which children have focus, this method calls _parent.getFocusIndex() and compares the focus index with the id/index of this object.

Returns:
returns true if the element has focus, false if it does not.
See Also:
MyGUIObject.getFocusIndex(), getFocusIndex(), MyGUIObject._id

isDisabled

public boolean isDisabled()
Checks the _disabled variable and its parent. This maintains the hierarchical structure where disabling a parent will also indirectly disable its children.

Returns:
returns true if disabled, false if enabled (normal state).
See Also:
MyGUIObject._disabled

isDragged

public boolean isDragged()
Returns constant state of mouse clicked compared to this object. If the mouse is considered permenantly pressed or dragged. The state should only be initialised after the object has gained focus.

Returns:
returns true if clicked/dragged and false otherwise.
See Also:
MyGUIObject.hover, MyGUIObject.mousePressed(), MyGUIObject.hasFocus()

drawStates

public void drawStates()
Interface method called by draw(). If you using the default draw() method then all your draw code for objects should go in this drawStates() method. You should build in drawing routines for all the standard states. For a button there are six states that I have identified: There are a range of basic colours that can be used to visually identify these states to the end user. See the MyGUIStyle class for more details.

See Also:
MyGUIStyle, MyGUIObject.draw(), MyGUIObject._disabled, MyGUIObject.hasFocus(), MyGUIObject.hover, MyGUIObject.dragged

setID

public void setID(int newID)
Sets the unique id to the specified integer. This value usually matches the array entry of the parent object 'storing' it. The _id is used to check whether an element has focus or not. If the ID is not set it risks being considered as 0, and may accidently gain focus. If an element does not have a parent then it's _id should be set to -1 (an invalid array location).

Parameters:
newID - The new ID of the object.
See Also:
MyGUIObject._id, MyGUIObject.hasFocus(), MyGUIObject.getFocusIndex()

setParent

public void setParent(MyGUIObject parent)
Tells the object who its parent is. A new object must be told what its parent is using this method. I've done this to cut down on the number of variables people have to supply in the constructor.

Parameters:
parent - the parent MyGUIObject of this object. Usually a MyGUIGroup object.
See Also:
MyGUIGroup

setActionCommand

public void setActionCommand(java.lang.String command)
Sets the descriptive action command when an ActionEvent is generated. This method allows a user to set a custom action command string, for example on a button a user could set this to "Save". Later, when a MyGUIActionEvent is generated this string can be compared using if(e.getActionCommand().equals("Save")). This is most useful when you have several GUI elements that you want to execute the same piece of code by assinging them the same action command. Otherwise, it might be easier to use if(e.getSource() == button), providing you have itemized your elements in that format.

Parameters:
command - The string value used to identify this action command.
See Also:
MyGUIActionEvent, MyGUIObject._actionCommand

enable

public void enable()
Activates this object so it is able to receive mouse and keyboard events. Its the opposite of disabled(). The method sets the _disabled attribute to false.

See Also:
MyGUIObject.disable(), MyGUIObject._disabled

disable

public void disable()
Disables this object so that it not longer receives mouse or keyboard events. Its counter method is enable. The attribute _disabled is used by MyGUIGroup to block mouseEvent and keyEvent methods from reaching an object. The draw methods of MyGUIObjects should reflect the disabled state by using the MyGUIStyle.disabled colour, which by default is a tinted greyed version of the buttonFace colour.

See Also:
MyGUIObject.enable(), MyGUIObject._disabled

rotate

public void rotate(float degs)
Increases/decreases the _rotation attribute by the supplied amount. You may also use guiObject._rotation += degs; since _rotation is a public variable. The value is always normalized to lie within 0 < angle < 360.

Parameters:
degs - the value in degrees to alter the rotation by
See Also:
MyGUIObject._rotation, MyGUIObject.rotateRadians(float), MyGUIObject.normalize(float, float, float)

rotateRadians

public void rotateRadians(float rads)
Increases/decreases the _rotation attribute by the given amount. It converts the supplied value from radians into degrees. The value is always normalized to lie within 0 < angle < 360.

Parameters:
rads - the value in radiands to alter the rotation by
See Also:
MyGUIObject._rotation, MyGUIObject.rotate(float), MyGUIObject.normalize(float, float, float)

normalize

protected float normalize(float n,
                          float min,
                          float max)
Normalization function that ensures a value always lies within min/max. Unlike PApplet.constrain this method will loop a value, like an angle 370 degrees will change to 10 degrees. This is the main intention for the method.

Parameters:
n - the number you want to normalize
min - the minimum boundary value
max - the maximum boundary value
Returns:
returns a normalized value that lies within min <= n <= max

checkForHit

public boolean checkForHit()
Defines the bounding box or 'hitzone' and returns true if the mouse is in contact. The method is used to check the hover state and whether the element can gain focus. This method calls updateLocalMouse() to set relative mouse coordinates tmouseX and tmouseY before peforming the check. You should write your own custom method if yo had an odd shaped shape that you want to calculate the position for.

This default checkForHit methods checks the bounding box of a shape (-width/2, _y-width/2, _width/2, _height/2) taking into account when rotatation and scale.

See Also:
MyGUIObject._width, MyGUIObject._height, MyGUIObject.updateLocalMouse()

getStyle

public MyGUIStyle getStyle()
Returns the currently assigned style. Each MyGUIObject takes its own style object from its parent. This means that if you modify it for a single object you will probably affect the whole hierarchy. To change the specific style for a single object try creating a new MyGUIStyle variable and then use setStyle(MyGUIStyle)

Returns:
returns a reference to the currently assigned MyGUIStyle style
See Also:
MyGUIStyle, MyGUIObject.setStyle(MyGUIStyle), MyGUIObject._style