javamorph
Class CPolygonDecorator

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

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

Version:
1.1
Author:
claus.erhard.wimmer@googlemail.com
Program: JavaMorph V 1.1.
Class: CPolygonDecorator.
License: GPLv2.
Description: Draw the polygon to the parent component.
Hint: User can move polygon points by mouse. Used to merge the pictures selectively. Pixel operations performed on one of the both ratio matrixes.

Field Summary
private  double[][] clip
          Smoothed clip polygon matrix.
static Color CURSOR_COLOR
          Color of the polygon point move cursor.
private  File f_clip
          File to save a debug copy of the clip matrix to.
private  File f_poly
          File to save the polygon to after shutdown.
private  BufferedImage image
          Picture of the own side.
private  int index
          Index of the current polygon point which has the cursor.
private  CFrame parent
          Parent component to draw the polygon to.
private  Vector<Point> polygon
          Collection of the polygon's points.
static Color POLYGON_COLOR
          Color of the polygon lines.
private  Point pos
          Fine position of the mouse pointer in picture pixels.
 
Constructor Summary
CPolygonDecorator(CFrame parent, Vector<Point> polygon, BufferedImage image, File f_poly, double[][] clip, File f_clip)
          Constructor.
 
Method Summary
 void clip()
          Ensures that the cursor points to a valid polygon point.
private  void drawLine(Point p1, Point p2)
          Draw a line between two polygon points into the clip matrix.
private  void fill()
          Fill the inner of the polygon with ratio 1.0.
 void genClip()
          Provide the clip matrix.
private  int getIndex(Point p)
          Seek the index of that one mesh point which is nearest to the mouse cursor.
 void init()
          Create a default polygon, depending on configuration coordinates, when initialization by file isn't possible of isn't intended.
 void load()
          Load the polygon from file.
 void mouseClicked(MouseEvent e)
          Due to Java API.
 void mouseDragged(MouseEvent e)
          The user is moving a polygon point.
 void mouseEntered(MouseEvent e)
          Due to Java API.
 void mouseExited(MouseEvent e)
          Due to Java API.
 void mouseMoved(MouseEvent e)
          Detect the current edit able polygon point before & during moving.
 void mousePressed(MouseEvent e)
          Due to Java API.
 void mouseReleased(MouseEvent e)
          Due to Java API.
 void paint(Graphics g)
          Draw the polygon to the parent JComponent.
 void run()
          Save-on-shutdown-thread.
private  void smoothCircle(Point p)
          Perform actually smooth for one pixel
private  void smoothLine(Point p1, Point p2)
          Smooth the contour of the clip matrix as dilatation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POLYGON_COLOR

public static final Color POLYGON_COLOR
Color of the polygon lines.


CURSOR_COLOR

public static final Color CURSOR_COLOR
Color of the polygon point move cursor.


parent

private CFrame parent
Parent component to draw the polygon to.


index

private int index
Index of the current polygon point which has the cursor.


polygon

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


image

private BufferedImage image
Picture of the own side.


clip

private double[][] clip
Smoothed clip polygon matrix.


f_poly

private File f_poly
File to save the polygon to after shutdown.


f_clip

private File f_clip
File to save a debug copy of the clip matrix to.


pos

private Point pos
Fine position of the mouse pointer in picture pixels.

Constructor Detail

CPolygonDecorator

public CPolygonDecorator(CFrame parent,
                         Vector<Point> polygon,
                         BufferedImage image,
                         File f_poly,
                         double[][] clip,
                         File f_clip)
Constructor.

Parameters:
parent - Parent JComponent to paint to.
polygon - Points of the clip polygon.
image - Picture of the own side.
f_poly - File to save the polygon to after shutdown.
clip - Smoothed clip matrix.
f_clip - File to store a debug copy of the to.
Method Detail

clip

public void clip()
Ensures that the cursor points to a valid polygon point.


paint

public void paint(Graphics g)
Draw the polygon to the parent JComponent.

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

mouseDragged

public void mouseDragged(MouseEvent e)
The user is moving a polygon point.

Specified by:
mouseDragged in interface MouseMotionListener

mouseMoved

public void mouseMoved(MouseEvent e)
Detect the current edit able polygon point before & during moving.

Specified by:
mouseMoved in interface MouseMotionListener

genClip

public void genClip()
Provide the clip matrix. Calculates Ratio matrix of row / column.


run

public void run()
Save-on-shutdown-thread.

Specified by:
run in interface Runnable

load

public void load()
Load the polygon from file.


init

public void init()
Create a default polygon, depending on configuration coordinates, when initialization by file isn't possible of isn't intended.


fill

private void fill()
Fill the inner of the polygon with ratio 1.0.


drawLine

private void drawLine(Point p1,
                      Point p2)
Draw a line between two polygon points into the clip matrix.

Parameters:
p1 - First point.
p2 - Second point. |x| |x1| |x2 - x1| 0.0 <= p <= 1.0 | | = | | + p * | | resolution depends on longer |y| |y1| |y2 - y1| orthogonal difference. Line is orthogonal pixel proof.

smoothLine

private void smoothLine(Point p1,
                        Point p2)
Smooth the contour of the clip matrix as dilatation. Work on the contour of clip & write to shadow.

Parameters:
p1 - First point.
p2 - Second point.

smoothCircle

private void smoothCircle(Point p)
Perform actually smooth for one pixel

Parameters:
p - The current pixel.

mouseClicked

public void mouseClicked(MouseEvent e)
Due to Java API. Perform polygon 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 p)
Seek the index of that one mesh point which is nearest to the mouse cursor.

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