com.groovemanager.gui.custom
Class DrawedRectangle

java.lang.Object
  extended by com.groovemanager.gui.custom.DrawedRectangle

public class DrawedRectangle
extends java.lang.Object

This class is a helper class for often moved and size-changed drawed Rectangles to avoid repainting if it is not needed and to keep the state consistent at any time.

Author:
Manu Robledo

Field Summary
protected  org.eclipse.swt.graphics.GC gc
          The Graphics Context used for drawing operations
protected  boolean isErased
          Current status of this Rectangle: visible (isErased == false) or not visible (isErased == true).
protected  org.eclipse.swt.graphics.Rectangle rect
          The current coordinates of this Rectangle
protected  boolean redrawAfterRelease
          Indicates whether this Rectangle should be redrawn after a call to release()
protected  org.eclipse.swt.graphics.Rectangle temp
          Temporary object for reuse
 
Constructor Summary
DrawedRectangle(org.eclipse.swt.graphics.GC gc)
          Constructs a new DrawedRectangle in invisible state using the given Graphics Context with the coordinates 0,0 and width/height 0
DrawedRectangle(org.eclipse.swt.graphics.Rectangle rect, org.eclipse.swt.graphics.GC gc)
          Constructs a new DrawedRectangle with the coordinates and width/height of the given Rectangle using the given Graphics Context for drawing operations
DrawedRectangle(org.eclipse.swt.graphics.Rectangle rect, org.eclipse.swt.graphics.GC gc, boolean isErased)
          Constructs a new DrawedRectangle with the coordinates and width/height of the given Rectangle using the given Graphics Context for drawing operations in the state indicated by isErased
 
Method Summary
 void addBottom(int pixels)
          Increase this Rectangle´s height by adding the given amount of pixels to the bottom
 void addLeft(int pixels)
          Add the given amount of pixels to this Rectangle´s width on the left side
 void addRight(int pixels)
          Increase this Rectangle´s width by adding the given amount of pixels to the right side
 void addTop(int pixels)
          Increase this Rectangle´s height by adding the given amount of pixels to the top
 void block()
          Block this Rectangle so it is not being redrawn after each change.
 void draw()
          Make this Rectangle visible on the screen if it is not already
protected  void drawRectangle(org.eclipse.swt.graphics.Rectangle r)
          Internal method for drawing a Rectangle on the screen
 void erase()
          Delete this Rectangle from the screen if it is currently visible
protected  void eraseRectangle(org.eclipse.swt.graphics.Rectangle r)
          Internal method for erasing a visible Rectangle from the screen
 void moveDown(int pixels)
          Move this Rectangle down by the given amount of pixels
 void moveLeft(int pixels)
          Move this Rectangle to the left by the given amount of pixels
 void moveRight(int pixels)
          Move this Rectangle to the right by the given amount of pixels
 void moveUp(int pixels)
          Move this Rectangle up by the given amount of pixels
 void release()
          Release this Rectangle after it has been blocked by a call to block().
 void removeBottom(int pixels)
          Decrease this Rectangle´s height by removing the given amount of pixels from the bottom
 void removeLeft(int pixels)
          Decrease this Rectangle´s widthby removing the given amount of pixels from the left side
 void removeRight(int pixels)
          Decrease this Rectangle´s width by removing the given amount of pixels from the right side
 void removeTop(int pixels)
          Decrease this Rectangle´s height by removing the given amount of pixels from the top
 void setBottom(int y)
          Set the y-coordinate of this Rectangle´s bottom border
 void setErased(boolean erased)
          Set the state of this Rectangle
 void setHeight(int height)
          Set this Rectangle´s height
 void setLeft(int x)
          Set the x-coordinate of this Rectangle´s left border
 void setRight(int x)
          Set the x-coordinate of this Rectangle´s right border
 void setTo(int x, int y, int width, int height)
          Set the new coordinates, width and height for this Rectangle
 void setTop(int y)
          Set the y-coordinate of this Rectangle´s top border
 void setWidth(int width)
          Set this Rectangle´s width
 void setXPosition(int x)
          Move this Rectangle to the given x-ccordinate
 void setYPosition(int y)
          Move this Rectangle to the given y-ccordinate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gc

protected org.eclipse.swt.graphics.GC gc
The Graphics Context used for drawing operations


isErased

protected boolean isErased
Current status of this Rectangle: visible (isErased == false) or not visible (isErased == true).


rect

protected org.eclipse.swt.graphics.Rectangle rect
The current coordinates of this Rectangle


redrawAfterRelease

protected boolean redrawAfterRelease
Indicates whether this Rectangle should be redrawn after a call to release()


temp

protected org.eclipse.swt.graphics.Rectangle temp
Temporary object for reuse

Constructor Detail

DrawedRectangle

public DrawedRectangle(org.eclipse.swt.graphics.GC gc)
Constructs a new DrawedRectangle in invisible state using the given Graphics Context with the coordinates 0,0 and width/height 0

Parameters:
gc - The Graphics Context to use for drawing operations

DrawedRectangle

public DrawedRectangle(org.eclipse.swt.graphics.Rectangle rect,
                       org.eclipse.swt.graphics.GC gc)
Constructs a new DrawedRectangle with the coordinates and width/height of the given Rectangle using the given Graphics Context for drawing operations

Parameters:
rect - The Rectangle defining coordinates and width/height of this Rectangle
gc - The Graphics Context to use for drawing operations

DrawedRectangle

public DrawedRectangle(org.eclipse.swt.graphics.Rectangle rect,
                       org.eclipse.swt.graphics.GC gc,
                       boolean isErased)
Constructs a new DrawedRectangle with the coordinates and width/height of the given Rectangle using the given Graphics Context for drawing operations in the state indicated by isErased

Parameters:
rect - The Rectangle defining coordinates and width/height of this Rectangle
gc - The Graphics Context to use for drawing operations
isErased - The current state of the Rectangle
Method Detail

addBottom

public void addBottom(int pixels)
Increase this Rectangle´s height by adding the given amount of pixels to the bottom

Parameters:
pixels - The amount of pixels to add

addLeft

public void addLeft(int pixels)
Add the given amount of pixels to this Rectangle´s width on the left side

Parameters:
pixels - The amount of pixels to add

addRight

public void addRight(int pixels)
Increase this Rectangle´s width by adding the given amount of pixels to the right side

Parameters:
pixels - The amount of pixels to add

addTop

public void addTop(int pixels)
Increase this Rectangle´s height by adding the given amount of pixels to the top

Parameters:
pixels - The amount of pixels to add

block

public void block()
Block this Rectangle so it is not being redrawn after each change. Usually a call to this method will be followed by a number of calls to methods changing this Rectangle´s position and size. After finishing these operations, a call to release() will set the Rectangle back into its usual behaviour.

See Also:
release()

draw

public void draw()
Make this Rectangle visible on the screen if it is not already


drawRectangle

protected void drawRectangle(org.eclipse.swt.graphics.Rectangle r)
Internal method for drawing a Rectangle on the screen

Parameters:
r - The Rectangel to draw

erase

public void erase()
Delete this Rectangle from the screen if it is currently visible


eraseRectangle

protected void eraseRectangle(org.eclipse.swt.graphics.Rectangle r)
Internal method for erasing a visible Rectangle from the screen

Parameters:
r - The Rectangle to erase

moveDown

public void moveDown(int pixels)
Move this Rectangle down by the given amount of pixels

Parameters:
pixels - The amount of pixels to move

moveLeft

public void moveLeft(int pixels)
Move this Rectangle to the left by the given amount of pixels

Parameters:
pixels - The amount of pixels to move

moveRight

public void moveRight(int pixels)
Move this Rectangle to the right by the given amount of pixels

Parameters:
pixels - The amount of pixels to move

moveUp

public void moveUp(int pixels)
Move this Rectangle up by the given amount of pixels

Parameters:
pixels - The amount of pixels to move

release

public void release()
Release this Rectangle after it has been blocked by a call to block().

See Also:
block()

removeBottom

public void removeBottom(int pixels)
Decrease this Rectangle´s height by removing the given amount of pixels from the bottom

Parameters:
pixels - The amount of pixels to remove

removeLeft

public void removeLeft(int pixels)
Decrease this Rectangle´s widthby removing the given amount of pixels from the left side

Parameters:
pixels - The amount of pixels to remove

removeRight

public void removeRight(int pixels)
Decrease this Rectangle´s width by removing the given amount of pixels from the right side

Parameters:
pixels - The amount of pixels to remove.

removeTop

public void removeTop(int pixels)
Decrease this Rectangle´s height by removing the given amount of pixels from the top

Parameters:
pixels - The amount of pixels to remove

setBottom

public void setBottom(int y)
Set the y-coordinate of this Rectangle´s bottom border

Parameters:
y - The new y-coordinate

setErased

public void setErased(boolean erased)
Set the state of this Rectangle

Parameters:
erased - true, if this Rectangle is erased and therefore NOT visible on the screen, false otherwise.

setHeight

public void setHeight(int height)
Set this Rectangle´s height

Parameters:
height - The new height

setLeft

public void setLeft(int x)
Set the x-coordinate of this Rectangle´s left border

Parameters:
x - The new x-coordinate

setRight

public void setRight(int x)
Set the x-coordinate of this Rectangle´s right border

Parameters:
x - The new x-coordinate

setTo

public void setTo(int x,
                  int y,
                  int width,
                  int height)
Set the new coordinates, width and height for this Rectangle

Parameters:
x - The new x-coordinate
y - The new y-coordinate
width - The new width
height - The new height

setTop

public void setTop(int y)
Set the y-coordinate of this Rectangle´s top border

Parameters:
y - The new y-coordinate

setWidth

public void setWidth(int width)
Set this Rectangle´s width

Parameters:
width - The new width

setXPosition

public void setXPosition(int x)
Move this Rectangle to the given x-ccordinate

Parameters:
x - The new x-coordinate

setYPosition

public void setYPosition(int y)
Move this Rectangle to the given y-ccordinate

Parameters:
y - The new y-coordinate