org.alchemy.core
Class AlcModule

java.lang.Object
  extended by org.alchemy.core.AlcModule
All Implemented Interfaces:
AlcConstants

public abstract class AlcModule
extends java.lang.Object
implements AlcConstants

The Alchemy Module Class

This is an 'abstract class' that must be extended to create an Alchemy module.

This class takes care of basic functionality such as module loading and passing on mouse and other events. It also has access to a bunch of other useful classes such as AlcCanvas, AlcMath etc...


Field Summary
protected static AlcCanvas canvas
          Access to the Alchemy canvas
protected static AlcColorSelector colorSelector
          Access to the Alchemy color selector
protected static AlcMath math
          Access to the Alchemy math class
protected static AlcAbstractToolBar toolBar
          Access to the Alchemy toolBar
 
Fields inherited from interface org.alchemy.core.AlcConstants
COLOR_UI_BG, COLOR_UI_BOX, COLOR_UI_END, COLOR_UI_HIGHLIGHT, COLOR_UI_LINE, COLOR_UI_LINE_ALPHA, COLOR_UI_START, CURSOR_ARROW, CURSOR_BLANK, CURSOR_CIRCLE, CURSOR_CROSS, CURSOR_EYEDROPPER, CURSOR_HAND, CURSOR_MOVE, CURSOR_TEXT, CURSOR_WAIT, DIR_DESKTOP, DIR_HOME, DIR_SEPARATOR, DIR_TEMP, FONT_LARGE, FONT_LARGE_BOLD, FONT_MEDIUM, FONT_MEDIUM_BOLD, FONT_SMALL, FONT_SMALL_BOLD, FONT_SMALLER, JAVA_VERSION, JAVA_VERSION_NAME, KEY_MODIFIER, LOCALE, MATH_DEG_TO_RAD, MATH_HALF_PI, MATH_PI, MATH_QUARTER_PI, MATH_RAD_TO_DEG, MATH_THIRD_PI, MATH_TWO_PI, MODULE_AFFECT, MODULE_CREATE, OS_LINUX, OS_MAC, OS_NAME, OS_OTHER, OS_WINDOWS, PEN_CURSOR, PEN_ERASER, PEN_STYLUS, STYLE_BOTH, STYLE_CLIP, STYLE_FILL, STYLE_STROKE, TOOLKIT, USER_NAME
 
Constructor Summary
AlcModule()
           
 
Method Summary
protected  void affect()
          Apply affect.
protected  void cleared()
          Called when the canvas is cleared.
protected  void commited()
          Called after all shapes are commited to the buffer.
protected  void deselect()
          Called when the module is deselected.
protected  java.lang.ClassLoader getClassLoader()
          Returns the classloader to load resources from the plugin .zip
protected  java.lang.String getDescription()
          Get the description of this module as defined in it's plugin.xml file.
protected  java.lang.String getIconName()
          Get the icon name as defined in it's plugin.xml file.
protected  java.net.URL getIconUrl()
          Get the Icon URL from within the module's .zip file.
protected  int getIndex()
          Get the index of this module in either the 'creates' or 'affects' arraylist
protected  boolean getLoaded()
          Loaded state of this module
protected  int getModuleType()
          Get the type of module
protected  java.lang.String getName()
          Get the name of this module as defined in it's plugin.xml file.
 void keyPressed(java.awt.event.KeyEvent e)
          Called when a key is pressed, only when the module is active.
 void keyReleased(java.awt.event.KeyEvent e)
          Called when a key is released, only when the module is active.
 void keyTyped(java.awt.event.KeyEvent e)
          Called when a key is typed, only when the module is active.
 void mouseClicked(java.awt.event.MouseEvent e)
          Called when the mouse is clicked, only if the module is active.
 void mouseDragged(java.awt.event.MouseEvent e)
          Called when the mouse is Dragged, only if the module is active.
 void mouseEntered(java.awt.event.MouseEvent e)
          Called when the mouse enters the canvas, only if the module is active.
 void mouseExited(java.awt.event.MouseEvent e)
          Called when the mouse exits the canvas, only if the module is active.
 void mouseMoved(java.awt.event.MouseEvent e)
          Called when the mouse is moved, only if the module is active.
 void mousePressed(java.awt.event.MouseEvent e)
          Called when the mouse is pressed, only if the module is active.
 void mouseReleased(java.awt.event.MouseEvent e)
          Called when the mouse is released, only if the module is active.
protected  void reselect()
          Called when the module is reselected in the menu.
protected  void setup()
          Called when the module is first selected in the menu.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

canvas

protected static AlcCanvas canvas
Access to the Alchemy canvas


toolBar

protected static AlcAbstractToolBar toolBar
Access to the Alchemy toolBar


math

protected static AlcMath math
Access to the Alchemy math class


colorSelector

protected static AlcColorSelector colorSelector
Access to the Alchemy color selector

Constructor Detail

AlcModule

public AlcModule()
Method Detail

setup

protected void setup()
Called when the module is first selected in the menu.

It will only be called once, so is useful for doing stuff like loading interface elements into the menu bar etc....

This function should be used instead of a constructor.


reselect

protected void reselect()
Called when the module is reselected in the menu. i.e. the module is turned off then on again.


deselect

protected void deselect()
Called when the module is deselected.


cleared

protected void cleared()
Called when the canvas is cleared.

You might sometimes need to use this function if for example you are counting the number of shapes and you want to know when to reset the count to zero.


commited

protected void commited()
Called after all shapes are commited to the buffer.

To keep things speedy, shapes are committed to an image buffer when possible so they do not need to be redraw each and every time. When this happens, the shape will be moved to the shapes array and seemingly dissappear. This function is used to warn each module of dissappearing shapes.


affect

protected void affect()
Apply affect.

Called for every active affect module, before the canvas is redrawn. This is used by affect modules to 'affect' a shape i.e. apply some sort of change to it. Typically the affect module will work with all shapes in the canvas.createShapes array then either replace them or add new shapes to the canvas.affectShapes array.


getName

protected java.lang.String getName()
Get the name of this module as defined in it's plugin.xml file.
 // Will return the text from the XML node below:
 <parameter id="name" value="This is my name"/> 
 
 

Returns:
The module's name

getIndex

protected int getIndex()
Get the index of this module in either the 'creates' or 'affects' arraylist

Returns:
The index of the module

getModuleType

protected int getModuleType()
Get the type of module

Returns:
The type of module - either AlcConstants.MODULE_CREATE or AlcConstants.MODULE_AFFECT

getLoaded

protected boolean getLoaded()
Loaded state of this module

Returns:
If the module has been loaded or not

getClassLoader

protected java.lang.ClassLoader getClassLoader()
Returns the classloader to load resources from the plugin .zip

Returns:
ClassLoader reference to this modules .zip

getIconName

protected java.lang.String getIconName()
Get the icon name as defined in it's plugin.xml file.
 // Will return the name of the icon file below:
 <parameter id="icon" value="icon.png" />
 
 

Returns:
This modules icon name

getIconUrl

protected java.net.URL getIconUrl()
Get the Icon URL from within the module's .zip file.
 // Will return a URL object to the icon file below:
 <parameter id="icon" value="icon.png" />
 
 

Returns:
URL linking to this modules icon file

getDescription

protected java.lang.String getDescription()
Get the description of this module as defined in it's plugin.xml file.
 // Will return the text from the XML node below:
 <parameter id="description" value="This is where the description lives!" />
 
 

Returns:
Text description of this module

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Called when the mouse is pressed, only if the module is active.

Parameters:
e - The MouseEvent containing location data.

Useful things you can do with the MouseEvent passed in:

 // Get the x location
 int x = e.getX();
 // Get the y location
 int y = e.getY();
 // Get the location as a point
 Point p = e.getPoint();
 

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Called when the mouse is moved, only if the module is active.

Parameters:
e - The MouseEvent containing location data.

Useful things you can do with the MouseEvent passed in:

 // Get the x location
 int x = e.getX();
 // Get the y location
 int y = e.getY();
 // Get the location as a point
 Point p = e.getPoint();
 

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Called when the mouse is clicked, only if the module is active.

Parameters:
e - The MouseEvent containing location data.

Useful things you can do with the MouseEvent passed in:

 // Get the x location
 int x = e.getX();
 // Get the y location
 int y = e.getY();
 // Get the location as a point
 Point p = e.getPoint();
 

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Called when the mouse is Dragged, only if the module is active.

Parameters:
e - The MouseEvent containing location data.

Useful things you can do with the MouseEvent passed in:

 // Get the x location
 int x = e.getX();
 // Get the y location
 int y = e.getY();
 // Get the location as a point
 Point p = e.getPoint();
 

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Called when the mouse is released, only if the module is active.

Parameters:
e - The MouseEvent containing location data.

Useful things you can do with the MouseEvent passed in:

 // Get the x location
 int x = e.getX();
 // Get the y location
 int y = e.getY();
 // Get the location as a point
 Point p = e.getPoint();
 

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Called when the mouse enters the canvas, only if the module is active.

Parameters:
e - The MouseEvent containing location data.

Useful things you can do with the MouseEvent passed in:

 // Get the x location
 int x = e.getX();
 // Get the y location
 int y = e.getY();
 // Get the location as a point
 Point p = e.getPoint();
 

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Called when the mouse exits the canvas, only if the module is active.

Parameters:
e - The MouseEvent containing location data.

Useful things you can do with the MouseEvent passed in:

 // Get the x location
 int x = e.getX();
 // Get the y location
 int y = e.getY();
 // Get the location as a point
 Point p = e.getPoint();
 

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Called when a key is pressed, only when the module is active.

Parameters:
e - The KeyEvent containing key data.

Useful things you can do with the KeyEvent passed in:

 // Get the character of the key pressed eg "A" 
 char keyChar = e.getKeyChar();
 // Get the key code of the key pressed eg 68
 int keyCode = e.getKeyCode();
 // Get the text of the key pressed eg "F1"
 String keyText = e.getKeyText(keyCode);
 

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Called when a key is released, only when the module is active.

Parameters:
e - The KeyEvent containing key data.

Useful things you can do with the KeyEvent passed in:

 // Get the character of the key pressed eg "A" 
 char keyChar = e.getKeyChar();
 // Get the key code of the key pressed eg 68
 int keyCode = e.getKeyCode();
 // Get the text of the key pressed eg "F1"
 String keyText = e.getKeyText(keyCode);
 

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Called when a key is typed, only when the module is active.

Parameters:
e - The KeyEvent containing key data.

Useful things you can do with the KeyEvent passed in:

 // Get the character of the key pressed eg "A" 
 char keyChar = e.getKeyChar();
 // Get the key code of the key pressed eg 68
 int keyCode = e.getKeyCode();
 // Get the text of the key pressed eg "F1"
 String keyText = e.getKeyText(keyCode);