jcontrol.io
Interface Graphics

All Known Subinterfaces:
XGraphics
All Known Implementing Classes:
AbstractGraphics, BufferGraphics, Display, XDisplay

public interface Graphics

Interface definition for graphics devices. (Offscreen images, displays, ...)


Field Summary
static int AND
          Drawmode.
static int INVERSE
          Drawmode.
static int NORMAL
          Drawmode.
static int OR
          Drawmode.
static int XOR
          Drawmode.
 
Method Summary
 void clearRect(int x, int y, int width, int height)
          Clears the specified rectangle by filling it with the background color of the current drawing surface.
 int drawChar(char c, int i, int j)
          Draws a single character to the Display.
 void drawImage(Object drawable, int x, int y)
          Draws an image to the specified coordinates.
 void drawImage(Object drawable, int x, int y, int width, int height, int xoff, int yoff)
          Draws an subimage to the specified coordinates.
 void drawLine(int x1, int y1, int x2, int y2)
          Draws a line on the graphics device.
 void drawRect(int x, int y, int width, int height)
          Draws a rectangular frame.
 int drawString(String s, int x, int y)
          Draws a String to the graphics device.
 int drawString(String str, int x, int y, int width, int height, int xoff, int yoff)
          Draws a String to the graphics device.
 void fillRect(int x, int y, int width, int height)
          Draws a filled rectangle.
 int getDrawMode()
          Returns the current Drawmode.
 int getFontHeight()
          Returns the height of the currently used font in pixels.
 int getPixel(int x, int y)
          Returns a single pixels color on the graphics device.
 int getTextWidth(String s)
          Returns the width of graphical text in pixels, this is dependent from the currently used font.
 void setBackground(int color)
          Sets the background color (for text etc.).
 void setColor(int color)
          Sets the foreground color.
 void setDrawMode(int mode)
          Sets the drawing mode.
 void setFont(Object newfont)
          Sets the font to use.
 void setPixel(int x, int y)
          Sets a single pixel on the graphics device to foreground color.
 

Field Detail

NORMAL

static final int NORMAL
Drawmode. Normal overwrite mode (default).

See Also:
setDrawMode(int), Constant Field Values

AND

static final int AND
Drawmode. Logical AND combination of the source pixles (of the command) and the old pixels (on the display), the pixels are set if both are set, reset otherwise.

See Also:
setDrawMode(int), Constant Field Values

OR

static final int OR
Drawmode. Logical OR combination of the source pixles (of the command) and the old pixels (on the display), the pixels are reset if both are reset, set otherwise.

See Also:
setDrawMode(int), Constant Field Values

XOR

static final int XOR
Drawmode. Logical XOR combination of the source pixles (of the command) and the old pixels (on the display), the pixels are reset if both are equal, set otherwise.

See Also:
setDrawMode(int), Constant Field Values

INVERSE

static final int INVERSE
Drawmode. Inversed source pixels (of the command), swaps foreground and background color, can be combined with AND, OR or XOR. Useful for deleting a part of a drawing or inverted text.

See Also:
setDrawMode(int), Constant Field Values
Method Detail

setColor

void setColor(int color)
Sets the foreground color.

Parameters:
color -

setBackground

void setBackground(int color)
Sets the background color (for text etc.).

Parameters:
color -

setDrawMode

void setDrawMode(int mode)
Sets the drawing mode.

Parameters:
mode - drawmode constant or combination of drawmodes

Possible drawmodes:

  • NORMAL (no change)
  • INVERSE (swaps foreground and background color)
  • AND (logical combination with display pixles, can be combined with INVERSE)
  • OR (logical combination with display pixles, can be combined with INVERSE)
  • XOR (logical combination with display pixles, can be combined with INVERSE)
See Also:
#setFGColor(int)

getDrawMode

int getDrawMode()
Returns the current Drawmode.

See Also:
setDrawMode(int)

setPixel

void setPixel(int x,
              int y)
Sets a single pixel on the graphics device to foreground color.

Parameters:
x - the horizontal coordinate.
y - the vertical coordinate.
See Also:
setColor(int)

getPixel

int getPixel(int x,
             int y)
Returns a single pixels color on the graphics device.

Parameters:
x - the horizontal coordinate.
y - the vertical coordinate.
Returns:
the color of the pixel

drawLine

void drawLine(int x1,
              int y1,
              int x2,
              int y2)
Draws a line on the graphics device.

Parameters:
x1 - the horizontal coordinate of starting point.
y1 - the vertical coordinate of starting point.
x2 - the horizontal coordinate of ending point.
y2 - the vertical coordinate of ending point.

drawRect

void drawRect(int x,
              int y,
              int width,
              int height)
Draws a rectangular frame.

Parameters:
x - the horizontal coordinate
y - the vertical coordinate
width - rectangle width
height - rectangle height

fillRect

void fillRect(int x,
              int y,
              int width,
              int height)
Draws a filled rectangle.

Parameters:
x - the horizontal coordinate
y - the vertical coordinate
width - rectangle width
height - rectangle height

clearRect

void clearRect(int x,
               int y,
               int width,
               int height)
Clears the specified rectangle by filling it with the background color of the current drawing surface. The current drawmode is not used.

Parameters:
x - the horizontal coordinate
y - the vertical coordinate
width - rectangle width
height - rectangle height

drawImage

void drawImage(Object drawable,
               int x,
               int y)
Draws an image to the specified coordinates. The image is drawn by its natural size, it may be cropped to the graphics device boundaries. The image object to draw can be of several types:

Parameters:
drawable - the image to draw
x - the horizontal coordinate
y - the vertical coordinate

drawImage

void drawImage(Object drawable,
               int x,
               int y,
               int width,
               int height,
               int xoff,
               int yoff)
Draws an subimage to the specified coordinates. The image is drawn by its natural size, it may be cropped to the graphics device boundaries. The source image may be shifted and cropped to a specified subimage.

Parameters:
drawable - the image to draw
x - the horizontal coordinate
y - the vertical coordinate
width - the width of the sub image within the source image
height - the height of the sub image within the source image
xoff - horizontal offset of the sub image within the source image
yoff - vertical offset of the sub image within the source image
See Also:
drawImage(Object, int, int)

setFont

void setFont(Object newfont)
Sets the font to use.

Parameters:
newfont - the font to use, possible values: constants defined in the implementing class or a instance of Resource specifying the font, the resource has to be in JCFD format (use FontEdit of the JControl toolware to generate).
See Also:
drawString(java.lang.String s, int x, int y)

getFontHeight

int getFontHeight()
Returns the height of the currently used font in pixels.

Returns:
the height of the current font
See Also:
setFont(Object), getTextWidth(String)

drawString

int drawString(String s,
               int x,
               int y)
Draws a String to the graphics device.

Parameters:
s - the String to draw (in some fonts only a few special characters are supported, e.g. german umlauts)
x - the horizontal coordinate of the strings upper left corner
y - the vertical coordinate of the strings upper left corner
Returns:
the number of horizontal pixels consumed by the text (depends on current font)
See Also:
setFont(Object)

drawString

int drawString(String str,
               int x,
               int y,
               int width,
               int height,
               int xoff,
               int yoff)
Draws a String to the graphics device. The text area may be shifted and cropped to a specified rectangle.

Parameters:
str - the String to draw (in some fonts only a few special characters are supported, e.g. german umlauts)
x - the horizontal coordinate of the strings upper left corner
y - the vertical coordinate of the strings upper left corner
width - the width of the text rectangle
height - the height of the text rectangle
xoff - horizontal offset of the text within the rectangle
yoff - vertical offset of the text within the rectangle
Returns:
the number of horizontal pixels consumed by the text (depends on current font)
See Also:
setFont(Object), drawString(String, int, int)

getTextWidth

int getTextWidth(String s)
Returns the width of graphical text in pixels, this is dependent from the currently used font. Behaves exacly like drawString() but omits drawing.

Parameters:
s - the String which width is to be calculated
Returns:
the text width in pixels if this text would be drawn
See Also:
drawString(String, int, int)

drawChar

int drawChar(char c,
             int i,
             int j)
Draws a single character to the Display.

Parameters:
c - the charater to draw (only a few special characters are supported, e.g. german umlauts)
x - the horizontal coordinate of the chars upper left corner
y - the vertical coordinate of the chars upper left corner
Returns:
the number of horizontal pixels consumed by the text
See Also:
setFont(Object), drawString(String, int, int)