krut.KRUT_GUI
Class ScreenMarkerLine

java.lang.Object
  extended by krut.KRUT_GUI.ScreenMarkerLine

public class ScreenMarkerLine
extends java.lang.Object

This is a class to draw lines that usually look like they are drawn directly on the screen. It can be used to mark an area of the screen. At the moment, only straight lines can be drawn. The drawing is performed very crudly by using an undecorated JFrame to draw a series of pixels, lines, or rectangular shapes over a snapshot that has been taken of the background. These drawings are aligned and added up to a line of the specified dimensions. This class is almost, but not entirely, finished. It is not currently used in the Krut program.


Field Summary
static int HORIZONTAL
          The horizontal orientation for this class.
 java.awt.Color marker
           
 java.awt.Color safeColor
           
static int VERTICAL
          The vertical orientation for this class.
 
Constructor Summary
ScreenMarkerLine()
          Creates a new instance of ScreenMarkerLine with no size and orientation HORIZONTAL.
ScreenMarkerLine(java.awt.Rectangle bounds, int orientation)
          Creates a new instance of ScreenMarkerLine with the given bounds and orientation, provided they are valid, with one segment and no gap size.
ScreenMarkerLine(java.awt.Rectangle bounds, int orientation, int segmentSize, int gapSize)
          Creates a new instance of ScreenMarkerLine with the given parameters, provided they are valid.
 
Method Summary
 void createLine()
          Create the JFrame that the line is drawn in.
 java.awt.Rectangle getBounds()
          Get the bounds for this line.
 int getGapSize()
          Gives the gap size in the orientation of the line.
 int getLength()
          Returns the length of the line.
 int getSegmentSize()
          Gives the segment size in the orientation of the line.
 int getWidth()
          Returns the width of the line.
 void hold(long ms)
          Used as a place to wait for sync in the updating of the graphics.
 int moveLine(int x, int y)
          Moves the top left corner of the line to the position (x, y) and updates the line once.
 int setBounds(java.awt.Rectangle bounds)
          Sets the bounds of this line.
 void setFrame(javax.swing.JFrame inFrame)
          This is just for testing.
 int setGapSize(int size)
          Sets the gap size in the orientation of the line.
 int setOrientation(int orientation)
          Sets the orientation of this line.
 int setSegmentSize(int size)
          Sets the segment size in the orientation of the line.
 void updateLineGraphics()
          This takes a new snapshot of the background, and fills in the line segments.
 void wakeUp()
          Called by the user to start capturing images.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

marker

public java.awt.Color marker

safeColor

public java.awt.Color safeColor

HORIZONTAL

public static final int HORIZONTAL
The horizontal orientation for this class.

See Also:
Constant Field Values

VERTICAL

public static final int VERTICAL
The vertical orientation for this class.

See Also:
Constant Field Values
Constructor Detail

ScreenMarkerLine

public ScreenMarkerLine()
Creates a new instance of ScreenMarkerLine with no size and orientation HORIZONTAL.


ScreenMarkerLine

public ScreenMarkerLine(java.awt.Rectangle bounds,
                        int orientation)
Creates a new instance of ScreenMarkerLine with the given bounds and orientation, provided they are valid, with one segment and no gap size.

Parameters:
bounds - Should be a Rectangle with only positive integer values.
orientation - Should be either HORIZONTAL or VERTICAL.

ScreenMarkerLine

public ScreenMarkerLine(java.awt.Rectangle bounds,
                        int orientation,
                        int segmentSize,
                        int gapSize)
Creates a new instance of ScreenMarkerLine with the given parameters, provided they are valid.

Parameters:
bounds - Should be a Rectangle with only positive integer values.
orientation - Should be either HORIZONTAL or VERTICAL.
segmentSize - Should be a positive integer larger than 0.
gapSize - Should be a positive integer no larger than the orientation.
Method Detail

hold

public void hold(long ms)
Used as a place to wait for sync in the updating of the graphics.

Parameters:
ms - The time to wait in ms. If 0 is given, the wait will be indefinite (until a notifyAll).

wakeUp

public void wakeUp()
Called by the user to start capturing images. Also wakes up users waiting for the grabber to finish. This method is called once when the last frame is captured, and once more when all video data are written to the temp file.


getLength

public int getLength()
Returns the length of the line.


getWidth

public int getWidth()
Returns the width of the line.


setSegmentSize

public int setSegmentSize(int size)
Sets the segment size in the orientation of the line. If the requested segment size is 0 or negative, the line length will be set as the new segment size. The segment size perpendicular to the orientation of the line will always be the same as the line width.

Parameters:
size - The requested segment size in the orientation of the line.
Returns:
The segment size that was set.

getSegmentSize

public int getSegmentSize()
Gives the segment size in the orientation of the line.

Returns:
The segment size of the line.

setGapSize

public int setGapSize(int size)
Sets the gap size in the orientation of the line. If the gap size is larger than the segment size, the gap size will be set to the same as the segment size. The gap size perpendicular to the orientation of the line will always be zero.

Parameters:
size - The requested gap size in the orientation of the line.
Returns:
The gap size that was set.

getGapSize

public int getGapSize()
Gives the gap size in the orientation of the line.

Returns:
The gap size of the line.

moveLine

public int moveLine(int x,
                    int y)
Moves the top left corner of the line to the position (x, y) and updates the line once.

Parameters:
x - The new x position of the line. Should be a positive integer.
y - The new y position of the line. Should be a positive integer.
Returns:
0 if the move was succesful, -1 if the move was not succesful.

setBounds

public int setBounds(java.awt.Rectangle bounds)
Sets the bounds of this line. The bounds should all be positive integers, otherwise they will be changed to 0.

Parameters:
bounds - The requested new bounds for the line.
Returns:
0 if everything was fine, -1 if one or more of the bounds were changed.

getBounds

public java.awt.Rectangle getBounds()
Get the bounds for this line.

Returns:
A Rectangle containting the bounds for this ScreenMarkerLine.

setOrientation

public int setOrientation(int orientation)
Sets the orientation of this line. The orientation should be one of HORIZONTAL or VERTICAL, otherwise the orientation will be set to VERTICAL. Changing the orientation will remove the current segment size and gap size.

Parameters:
orientation - The requested orientation.
Returns:
The orientation that was set.

updateLineGraphics

public void updateLineGraphics()
This takes a new snapshot of the background, and fills in the line segments.


setFrame

public void setFrame(javax.swing.JFrame inFrame)
This is just for testing.


createLine

public void createLine()
Create the JFrame that the line is drawn in.