javamorph
Class CMeshDecorator

java.lang.Object
  extended by javamorph.CMeshDecorator
All Implemented Interfaces:
MouseListener, MouseMotionListener, Runnable, EventListener, IDecorator

public class CMeshDecorator
extends Object
implements IDecorator, MouseListener, MouseMotionListener, Runnable

Version:
1.1
Author:
claus.erhard.wimmer@googlemail.com
Program: JavaMorph V 1.1.
Class: CMeshDecorator.
License: GPLv2.
Description: Pattern to draw the mesh to CFrame.
Hint: Contains the mesh editing functionality.

Field Summary
static Color CURSOR_COLOR
          Draw color of the mesh point move cursor crosss.
private  File f_mesh
          File to store the mesh to after program shutdown.
private  BufferedImage image
          Input picture of the own side.
private static int index
          Index of those mesh point which is nearest to the mouse pointer.
private  Vector<Point> mesh
          Collection of the mesh's points.
static Color MESH_COLOR
          Draw color of the mesh's lines.
private  CFrame parent
          Parent component to draw the mesh to.
private  Point pos
          Fine value of the mouse pointer's position.
 
Constructor Summary
CMeshDecorator(CFrame parent, Vector<Point> mesh, BufferedImage image, File f_mesh)
          Constructor.
 
Method Summary
 void clip()
          Ensure that the cursor is situated inside the bounds of the mesh while drawing.
private  int getIndex(Point p0)
          Seek the index of that one mesh point which is nearest to the mouse cursor.
 void init()
          If mesh creation from file is not possible or not intended: Create an grid mesh controlled by configuration values.
 void load()
          Load the mesh on startup from file.
 void mouseClicked(MouseEvent e)
          Due to Java API.
 void mouseDragged(MouseEvent e)
          Move a mesh point with the mouse.
 void mouseEntered(MouseEvent e)
          Due to Java API.
 void mouseExited(MouseEvent e)
          Due to Java API.
 void mouseMoved(MouseEvent e)
          Detect where the mouse is before and while moving the mesh point.
 void mousePressed(MouseEvent e)
          Due to Java API.
 void mouseReleased(MouseEvent e)
          Due to Java API.
 void paint(Graphics g)
          Decorator API.
 void run()
          Save-on-exit-thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MESH_COLOR

public static final Color MESH_COLOR
Draw color of the mesh's lines.


CURSOR_COLOR

public static final Color CURSOR_COLOR
Draw color of the mesh point move cursor crosss.


parent

private CFrame parent
Parent component to draw the mesh to.


index

private static int index
Index of those mesh point which is nearest to the mouse pointer.


mesh

private Vector<Point> mesh
Collection of the mesh's points.


image

private BufferedImage image
Input picture of the own side.


f_mesh

private File f_mesh
File to store the mesh to after program shutdown.


pos

private Point pos
Fine value of the mouse pointer's position.

Constructor Detail

CMeshDecorator

public CMeshDecorator(CFrame parent,
                      Vector<Point> mesh,
                      BufferedImage image,
                      File f_mesh)
Constructor.

Parameters:
parent - Parent JComponent to paint to.
mesh - Pictures of the mesh.
image - Picture of the own side.
f_mesh - File to store the mesh to after shutdown.
Method Detail

clip

public void clip()
Ensure that the cursor is situated inside the bounds of the mesh while drawing.


paint

public void paint(Graphics g)
Decorator API. Draw this mesh to the graphics context of the CFrame.

Specified by:
paint in interface IDecorator
Parameters:
g - Graphics context of the JComponent.

mouseDragged

public void mouseDragged(MouseEvent e)
Move a mesh point with the mouse.

Specified by:
mouseDragged in interface MouseMotionListener

mouseMoved

public void mouseMoved(MouseEvent e)
Detect where the mouse is before and while moving the mesh point.

Specified by:
mouseMoved in interface MouseMotionListener

run

public void run()
Save-on-exit-thread. Save the mesh.

Specified by:
run in interface Runnable

load

public void load()
Load the mesh on startup from file.


init

public void init()
If mesh creation from file is not possible or not intended: Create an grid mesh controlled by configuration values.


mouseClicked

public void mouseClicked(MouseEvent e)
Due to Java API. Perform mesh point operation depending on edit state.

Specified by:
mouseClicked in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Due to Java API.

Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Due to Java API.

Specified by:
mouseExited in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Due to Java API.

Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Due to Java API.

Specified by:
mouseReleased in interface MouseListener

getIndex

private int getIndex(Point p0)
Seek the index of that one mesh point which is nearest to the mouse cursor.

Parameters:
p0 - on screen, scaled to picture coordinates.
Returns:
Index in point collection.