|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.aplu.util.GPanel
public class GPanel
Simple graphics window of default size 501x501 pixels (client drawing area)
using a coordinate system with x-axis from left to right, y-axis from bottom to top
(called window coordinates, default range 0..1, 0..1).
The drawing methods perform all drawings in an offscreen buffer
and automatically repaint it on the screen, so the graphics is shown step-by-step.
A current graph position is used, that remembers the end position of the last
drawing process and where new drawings start.
By default the window may be resized by mouse dragging as long as resizable(false) isn't called.
Resizing transforms the current graphics content through an affine transformation from
the offscreen buffer. In this process, some graphics resolution is lost.
If pixel accuracy is needed, set the window coordinates to 500, 500.
Clicking the title bar's close button will terminate the application by calling
System.exit(0)
unless an ExitListener is registered.
More than one GPanel may be instantiated. They are automatically positioned two-by-two.
All constructors and Swing methods are invoked by the Event Dispatch Thread (EDT).
Therefore GPanel is no longer derived from JPanel, but contains a JPanel now (has-a relation).
If you need some special methods from the internal JPanel, call getPane().
Do not mix with Graphics or Graphics2D methods. Use GWindow instead.
GPane
,
GWindow
Field Summary | |
---|---|
static int |
APPLETFRAME
Mode for a GPanel used as standalone window in a applet. |
static int |
EMBEDDED
Mode for a GPanel embedded in a top-level window (no longer supported). |
static Fullscreen |
FULLSCREEN
Instance of class Fullscreen. |
static int |
NOTITLEBAR
Mode for a GPanel with no title bar. |
static int |
STANDARD
Mode for a standard GPanel. |
Constructor Summary | |
---|---|
GPanel()
Construct a GPanel and show the window. |
|
GPanel(boolean visible)
Same as GPanel() with given visibility. |
|
GPanel(double xmin,
double xmax,
double ymin,
double ymax)
Construct a GPanel with given window coordinates |
|
GPanel(double xmin,
double xmax,
double ymin,
double ymax,
boolean visible)
Same as GPanel() with given window coordinates and visibility. |
|
GPanel(int mode)
Construct a GPanel for special purposes. |
|
GPanel(int mode,
Size size)
Same as GPanel() with given mode and window size (client area). |
|
GPanel(javax.swing.JMenuBar menuBar)
Same as GPanel() but show given menuBar. |
|
GPanel(javax.swing.JMenuBar menuBar,
boolean visible)
Same as GPanel() with given menuBar and visibility. |
|
GPanel(javax.swing.JMenuBar menuBar,
double xmin,
double xmax,
double ymin,
double ymax)
Same as GPanel(xmin, xmax, ymin, ymax) with given menuBar. |
|
GPanel(javax.swing.JMenuBar menuBar,
double xmin,
double xmax,
double ymin,
double ymax,
boolean visible)
Same as GPanel() with given menuBar, window coordinates and visibility. |
|
GPanel(Size size)
Same as GPanel() with given window size (client area). |
|
GPanel(Size size,
java.lang.String title,
javax.swing.JMenuBar menuBar,
double xmin,
double xmax,
double ymin,
double ymax,
boolean visible)
Same as GPanel() with given window size (client area), title, menuBar, window coordinates and visibility. |
|
GPanel(java.lang.String title)
Same as GPanel() with given title. |
|
GPanel(java.lang.String title,
boolean visible)
Same as GPanel() with given title and visibility. |
|
GPanel(java.lang.String title,
double xmin,
double xmax,
double ymin,
double ymax)
Same as GPanel(xmin, xmax, ymin, ymax) with given title. |
|
GPanel(java.lang.String title,
double xmin,
double xmax,
double ymin,
double ymax,
boolean visible)
Same as GPanel() with given title, window coordinates and visibility. |
|
GPanel(java.lang.String title,
javax.swing.JMenuBar menuBar)
Same as GPanel() with given title and menuBar. |
|
GPanel(java.lang.String title,
javax.swing.JMenuBar menuBar,
boolean visible)
Same as GPanel() with given title, menuBar and visibility. |
|
GPanel(java.lang.String title,
javax.swing.JMenuBar menuBar,
double xmin,
double xmax,
double ymin,
double ymax)
Same as GPanel(xmin, xmax, ymin, ymax) with given title and menuBar. |
|
GPanel(java.lang.String title,
javax.swing.JMenuBar menuBar,
double xmin,
double xmax,
double ymin,
double ymax,
boolean visible)
Same as GPanel() with given title, menuBar, window coordinates and visibility. |
Method Summary | |
---|---|
void |
add(java.awt.Component comp)
Append the specified component to the container. |
void |
addExitListener(ExitListener exitListener)
Register an ExitListener to get a notification when the close button is clicked. |
void |
addMouseListener(java.awt.event.MouseListener listener)
Invoke the internal JPanels addMouseListener(). |
void |
addMouseMotionListener(java.awt.event.MouseMotionListener listener)
Invoke the internal JPanels addMouseMotionListener(). |
void |
addMouseWheelListener(java.awt.event.MouseWheelListener listener)
Invoke the internal JPanels addMouseWheelListener(). |
void |
addStatusBar(int height)
Add a status window attached at the bottom of the GPanel window. |
void |
applyTransform(java.awt.geom.AffineTransform at)
Apply the given AffineTransform to offscreen buffer. |
void |
arc(double radius,
double startAngle,
double extendAngle)
Draw an arc with center at the current graph position and given radius in window coordinates. |
java.awt.Color |
bgColor(java.awt.Color color)
Set the background color. |
void |
circle(double radius)
Draw a circle with center at the current graph position and given radius in horizontal window coordinates. |
void |
clear()
Clear the graphics window (fully paint with background color) (and the offscreen buffer used by the window). |
void |
clearStore(java.awt.Color color)
Clear store buffer by uniformly painting it with with given color. |
java.awt.Color |
color(java.awt.Color color)
Set the given new color and return the previous color |
static void |
delay(int time)
Delay execution for the given amount of time ( in ms ). |
void |
disableClose(boolean b)
Disable/enable the title bar's closing button. |
void |
dispose()
Release all used system resources (offscreen buffer, graphics context) and unblock getKeyWait() and getKeyCodeWait(). |
void |
draw(double x,
double y)
Draw a line from current graph position to given window coordinates and set the graph position to the endpoint. |
void |
draw(java.awt.geom.Point2D.Double pt)
Draw a line from current graph position to given point (in window coordinates) and set the graph position to the endpoint. |
boolean |
enableRepaint(boolean doRepaint)
Enable or disable the automatic repaint in graphics methods. |
void |
erase()
Same as clear() but let the current graph position unchanged. |
void |
fillArc(double radius,
int startAngle,
int extendAngle)
Draw a filled arc with center at the current graph position and given radius in window coordinates. |
void |
fillCircle(double radius)
Draw a filled circle with center at the current graph position and given radius in window coordinates using the current color. |
void |
fillGeneralPath(java.awt.geom.GeneralPath gp)
Fill a figure defined by the given GeneralPath (using window coordinates) using the current color. |
void |
fillPolygon(double[] x,
double[] y)
Draw a filled polygon with given corner coordinates in window coordinates using the current color. |
void |
fillPolygon(java.awt.geom.Point2D.Double[] corner)
Draw a filled polygon with given corner points in window coordinates using the current color. |
void |
fillRectangle(double width,
double height)
Draw a filled rectangle with center at the current graph position and given width and height in window coordinates using the current color. |
void |
fillRectangle(double x1,
double y1,
double x2,
double y2)
Draw a filled rectangle with given opposite corners in window coordinates using the current color. |
void |
fillRectangle(java.awt.geom.Point2D.Double pt1,
java.awt.geom.Point2D.Double pt2)
Draw a filled rectangle with given opposite corner points in window coordinates using the current color. |
void |
fillTriangle(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Draw a filled triangle with given corner coordinates in window coordinates using the current color. |
void |
fillTriangle(java.awt.geom.Point2D.Double pt1,
java.awt.geom.Point2D.Double pt2,
java.awt.geom.Point2D.Double pt3)
Draw a filled triangle with given corners in window coordinates using the current color. |
void |
font(java.awt.Font font)
Select the given font for all following text operations. |
void |
generalPath(java.awt.geom.GeneralPath gp)
Draw a figure defined by the given GeneralPath (using window coordinates). |
java.lang.String |
getAbout()
Return copywrite information |
java.awt.Color |
getBgColor()
Return the current background color. |
char |
getKey()
Return the unicode character associated with last key typed. |
int |
getKeyCode()
Return the keycode associated with last key pressed. |
int |
getKeyCodeWait()
Wait until a key is typed and return the keycode associated with last key pressed. |
char |
getKeyWait()
Wait until a key is typed and return the unicode character associated with it. |
int |
getModifiers()
Return the modifiers associated with last key pressed. |
java.lang.String |
getModifiersText()
Return the modifiers text description associated with last key pressed. |
java.awt.Graphics2D |
getOffG2D()
Return the Graphics2D context of the offscreen buffer |
GPane |
getPane()
Return the GPane container that holds the graphics. |
java.awt.Color |
getPixelColor(double x,
double y)
Return the color of the pixel at given window coordinates. |
java.awt.Color |
getPixelColor(java.awt.geom.Point2D.Double pt)
Return the color of the pixel at given point (in window coordinates). |
java.awt.geom.Point2D.Double |
getPos()
Return reference to point of current graph position (in window coordinates). |
double |
getPosX()
Return window coordinate x of current graph position. |
double |
getPosY()
Return window coordinate y of current graph position. |
java.lang.String |
getVersion()
Return version information |
GWindow |
getWindow()
Return a reference to the GWindow used by the GPanel. |
boolean |
image(java.lang.String imagePath,
double x,
double y)
Show the GIF image from given file path at given window coordinates (specifies lowerleft corner of image). |
boolean |
image(java.lang.String imagePath,
java.awt.geom.Point2D.Double pt)
Show the GIF image from given file path at given point(in window coordinates) (specifies lowerleft corner of image). |
boolean |
image(java.net.URL imageUrl,
double x,
double y)
Show the GIF image from URL at given window coordinates (specifies lowerleft corner of image). |
boolean |
image(java.net.URL imageUrl,
java.awt.geom.Point2D.Double pt)
Show the GIF image from given URL at given point(in window coordinates) (specifies lowerleft corner of image). |
double |
imageHeight()
Return the height (vertical size) of the last loaded GIF image (in window coordinates). |
double |
imageHeight(java.lang.String imagePath)
Return the height (vertical size) of the GIF image from the given path (in window coordinates). |
double |
imageHeight(java.net.URL imageUrl)
Return the height (vertical size) of the GIF image from the given URL (in window coordinates). |
double |
imageWidth()
Return the width (horizontal size) of the last loaded GIF image (in window coordinates). |
double |
imageWidth(java.lang.String imagePath)
Return the width (horizontal size) of the GIF image from the given path (in window coordinates). |
double |
imageWidth(java.net.URL imageUrl)
Return the width (horizontal size) of the GIF image from the given URL (in window coordinates). |
boolean |
isReady()
Test if GPanel is fully initialized. |
boolean |
kbhit()
Return true, if a key was typed since the last call to getChar() or getCharWait(). |
void |
line(double x1,
double y1,
double x2,
double y2)
Draw a line with given window coordinates and set the graph position to the endpoint. |
void |
line(java.awt.geom.Point2D.Double pt1,
java.awt.geom.Point2D.Double pt2)
Draw a line with given points (in window coordinates) and set the graph position to the endpoint. |
void |
lineWidth(int width)
Set the current line width in pixels. |
void |
move(double x,
double y)
Set the current graph position to given window coordinates (without drawing anything). |
void |
move(int x,
int y)
Same as move(double x, double y) |
void |
move(java.awt.geom.Point2D.Double pt)
Set the current graph position to given point (in window coordinates) (without drawing anything). |
void |
point(double x,
double y)
Draw a single point at the given window coordinates. |
void |
point(java.awt.geom.Point2D.Double pt)
Draw a single point at the given pt (in window coordinates). |
void |
polygon(double[] x,
double[] y)
Draw a polygon with given corner coordinates in window coordinates. |
void |
polygon(java.awt.geom.Point2D.Double[] corner)
Draw a polygon with given corner points in window coordinates. |
void |
pos(double x,
double y)
Same as move(double x, double y). |
void |
pos(java.awt.geom.Point2D.Double pt)
Same as move(Point2D.Double pt). |
boolean |
print(GPrintable gp)
Same as print(GPrintable gp, double scale) with scale = 1. |
boolean |
print(GPrintable gp,
double scale)
Print the graphics context to an attached printer with the given magnification scale factor. |
boolean |
printScreen()
Same printScreen(double scale) with scale = 1. |
boolean |
printScreen(double scale)
Print the current screen view to an attached printer with the given magnification scale factor. |
void |
recallGraphics()
Copy graphics from store buffer to offscreen buffer and render it on the screen window (if enableRepaint(true)). |
void |
rectangle(double width,
double height)
Draw a rectangle with center at the current graph position and given width and height in window coordinates. |
void |
rectangle(double x1,
double y1,
double x2,
double y2)
Draw a rectangle with given opposite corners in window coordinates. |
void |
rectangle(java.awt.geom.Point2D.Double pt1,
java.awt.geom.Point2D.Double pt2)
Draw a rectangle with given opposite corner points in window coordinates. |
void |
repaint()
Invoke the internal JPanels repaint(). |
void |
resizable(boolean b)
Enable/disable resizing of the window by mouse dragging. |
void |
setFocusable(boolean focusable)
Set the focusable state to the specified value. |
void |
setPaintMode()
Set the paint mode of the graphics context to overwrite with current color. |
void |
setStatusText(java.lang.String text)
Replace the text in the status bar by the given text using the current JOptionPane font and color. |
void |
setStatusText(java.lang.String text,
java.awt.Font font,
java.awt.Color color)
Replace the text in the status bar by the given text using the given font and text color. |
void |
setXORMode(java.awt.Color c)
Sets the paint mode to alternate between the current color and the given color. |
void |
showStatusBar(boolean show)
Show or hide the status bar. |
void |
storeGraphics()
Create a store buffer and copy current graphics to it. |
void |
text(char c)
Draw a char at the current graph position. |
void |
text(double x,
double y,
char c)
Draw a char at the given position. |
void |
text(double x,
double y,
java.lang.String str)
Draw a string at the given position. |
void |
text(java.lang.String str)
Draw a string at the current graph position. |
void |
title(java.lang.String title)
Set the title in the window's title bar. |
java.awt.Point |
toUser(double windowX,
double windowY)
Return reference to point in user coordinate of given window coordinates. |
java.awt.Point |
toUser(java.awt.geom.Point2D.Double windowPt)
Return reference to point in user coordinate of given point in window coordinate. |
int |
toUserHeight(double windowHeight)
Return user coordinates increment y of given window coordinates increment y. |
int |
toUserWidth(double windowWidth)
Return user coordinates increment x of given window coordinates increment x. |
int |
toUserX(double windowX)
Return user coordinate x of given window coordinate x. |
int |
toUserY(double windowY)
Return user coordinate y of given window coordinate y. |
java.awt.geom.Point2D.Double |
toWindow(int userX,
int userY)
Return reference to point in window coordinates of given user coordinates. |
java.awt.geom.Point2D.Double |
toWindow(java.awt.Point userPt)
Return reference to point in window coordinates of given point in user coordinates. |
double |
toWindowHeight(int userHeight)
Return window coordinates increment y of given user coordinates increment y. |
double |
toWindowWidth(int userWidth)
Return window coordinates increment x of given user coordinates increment x. |
double |
toWindowX(int userX)
Return window coordinate x of given user coordinate x. |
double |
toWindowY(int userY)
Return window coordinate y of given user coordinate y. |
void |
triangle(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Draw a triangle with given corner coordinates in window coordinates. |
void |
triangle(java.awt.geom.Point2D.Double pt1,
java.awt.geom.Point2D.Double pt2,
java.awt.geom.Point2D.Double pt3)
Draw a triangle with given corners in window coordinates. |
void |
validate()
Validate the container. |
void |
visible(boolean isVisible)
Select if GPanel's window is visible or not. |
void |
window(double xmin,
double xmax,
double ymin,
double ymax)
Set window coordinates. |
void |
windowCenter()
Set the window position to the center of the screen. |
void |
windowPosition(int ulx,
int uly)
Set the window position (upper left corner in device coordinates). |
void |
windowSize(int width,
int height)
Set the size of the entire window (including title bar and borders) in device coordinates. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static int STANDARD
public static int EMBEDDED
public static int APPLETFRAME
public static int NOTITLEBAR
public static Fullscreen FULLSCREEN
Constructor Detail |
---|
public GPanel(int mode)
public GPanel(int mode, Size size)
public GPanel()
public GPanel(boolean visible)
public GPanel(Size size)
GPanel(new Size(width, height))
to set size to width/height.
public GPanel(javax.swing.JMenuBar menuBar)
public GPanel(javax.swing.JMenuBar menuBar, boolean visible)
public GPanel(java.lang.String title)
public GPanel(java.lang.String title, boolean visible)
public GPanel(java.lang.String title, javax.swing.JMenuBar menuBar)
public GPanel(java.lang.String title, javax.swing.JMenuBar menuBar, boolean visible)
public GPanel(double xmin, double xmax, double ymin, double ymax)
public GPanel(double xmin, double xmax, double ymin, double ymax, boolean visible)
public GPanel(javax.swing.JMenuBar menuBar, double xmin, double xmax, double ymin, double ymax)
public GPanel(javax.swing.JMenuBar menuBar, double xmin, double xmax, double ymin, double ymax, boolean visible)
public GPanel(java.lang.String title, double xmin, double xmax, double ymin, double ymax)
public GPanel(java.lang.String title, double xmin, double xmax, double ymin, double ymax, boolean visible)
public GPanel(java.lang.String title, javax.swing.JMenuBar menuBar, double xmin, double xmax, double ymin, double ymax)
public GPanel(java.lang.String title, javax.swing.JMenuBar menuBar, double xmin, double xmax, double ymin, double ymax, boolean visible)
public GPanel(Size size, java.lang.String title, javax.swing.JMenuBar menuBar, double xmin, double xmax, double ymin, double ymax, boolean visible)
Method Detail |
---|
public void addExitListener(ExitListener exitListener)
public void window(double xmin, double xmax, double ymin, double ymax)
public void visible(boolean isVisible)
public GWindow getWindow()
public boolean isReady()
public boolean print(GPrintable gp, double scale)
import ch.aplu.util.*;
public class PrintEx extends GPanel implements GPrintable
{
public PrintEx()
{
draw(); // Draw on screen
print(this); // Draw on printer
}
public void draw()
{
move(0, 0);
draw(1, 0);
draw(1, 1);
draw(0, 1);
draw(0, 0);
line(0, 1, 1, 0);
line(0, 0, 1, 1);
}
public static void main(String[] args)
{
new PrintEx();
}
}
public boolean print(GPrintable gp)
public boolean printScreen(double scale)
public boolean printScreen()
public java.awt.Color bgColor(java.awt.Color color)
public java.awt.Color getBgColor()
public void title(java.lang.String title)
public int toUserX(double windowX)
public int toUserY(double windowY)
public java.awt.Point toUser(java.awt.geom.Point2D.Double windowPt)
public java.awt.Point toUser(double windowX, double windowY)
public int toUserWidth(double windowWidth)
public int toUserHeight(double windowHeight)
public double toWindowX(int userX)
public double toWindowY(int userY)
public java.awt.geom.Point2D.Double toWindow(java.awt.Point userPt)
public java.awt.geom.Point2D.Double toWindow(int userX, int userY)
public double toWindowWidth(int userWidth)
public double toWindowHeight(int userHeight)
public void lineWidth(int width)
public java.awt.Color color(java.awt.Color color)
public void line(double x1, double y1, double x2, double y2)
public void line(java.awt.geom.Point2D.Double pt1, java.awt.geom.Point2D.Double pt2)
public void draw(double x, double y)
public void draw(java.awt.geom.Point2D.Double pt)
public void move(double x, double y)
public void move(int x, int y)
public void pos(double x, double y)
public void move(java.awt.geom.Point2D.Double pt)
public void pos(java.awt.geom.Point2D.Double pt)
public double getPosX()
public double getPosY()
public java.awt.geom.Point2D.Double getPos()
public void clear()
public void erase()
public void circle(double radius)
public void fillCircle(double radius)
public void rectangle(double width, double height)
public void rectangle(double x1, double y1, double x2, double y2)
public void rectangle(java.awt.geom.Point2D.Double pt1, java.awt.geom.Point2D.Double pt2)
public void fillRectangle(double width, double height)
public void fillRectangle(double x1, double y1, double x2, double y2)
public void fillRectangle(java.awt.geom.Point2D.Double pt1, java.awt.geom.Point2D.Double pt2)
public void arc(double radius, double startAngle, double extendAngle)
public void fillArc(double radius, int startAngle, int extendAngle)
public void polygon(double[] x, double[] y)
public void polygon(java.awt.geom.Point2D.Double[] corner)
public void fillPolygon(double[] x, double[] y)
public void fillPolygon(java.awt.geom.Point2D.Double[] corner)
public void triangle(double x1, double y1, double x2, double y2, double x3, double y3)
public void triangle(java.awt.geom.Point2D.Double pt1, java.awt.geom.Point2D.Double pt2, java.awt.geom.Point2D.Double pt3)
public void fillTriangle(double x1, double y1, double x2, double y2, double x3, double y3)
public void fillTriangle(java.awt.geom.Point2D.Double pt1, java.awt.geom.Point2D.Double pt2, java.awt.geom.Point2D.Double pt3)
public void generalPath(java.awt.geom.GeneralPath gp)
public void fillGeneralPath(java.awt.geom.GeneralPath gp)
public void text(java.lang.String str)
public void text(char c)
public void text(double x, double y, java.lang.String str)
public void text(double x, double y, char c)
public void font(java.awt.Font font)
public void point(double x, double y)
public void point(java.awt.geom.Point2D.Double pt)
public boolean image(java.lang.String imagePath, double x, double y)
public boolean image(java.lang.String imagePath, java.awt.geom.Point2D.Double pt)
public boolean image(java.net.URL imageUrl, double x, double y)
public boolean image(java.net.URL imageUrl, java.awt.geom.Point2D.Double pt)
public double imageWidth(java.lang.String imagePath)
public double imageWidth(java.net.URL imageUrl)
public double imageWidth()
public double imageHeight(java.lang.String imagePath)
public double imageHeight(java.net.URL imageUrl)
public double imageHeight()
public void applyTransform(java.awt.geom.AffineTransform at)
public boolean enableRepaint(boolean doRepaint)
public void setPaintMode()
public void setXORMode(java.awt.Color c)
public void windowPosition(int ulx, int uly)
public void windowCenter()
public void windowSize(int width, int height)
public void resizable(boolean b)
public java.awt.Graphics2D getOffG2D()
public void dispose()
public void disableClose(boolean b)
public void storeGraphics()
recallGraphics()
,
clearStore(java.awt.Color)
public void recallGraphics()
storeGraphics()
,
clearStore(java.awt.Color)
public void clearStore(java.awt.Color color)
storeGraphics()
,
recallGraphics()
public java.lang.String getVersion()
public java.lang.String getAbout()
public java.awt.Color getPixelColor(double x, double y)
public java.awt.Color getPixelColor(java.awt.geom.Point2D.Double pt)
public void setFocusable(boolean focusable)
public void repaint()
public void addMouseListener(java.awt.event.MouseListener listener)
public void addMouseMotionListener(java.awt.event.MouseMotionListener listener)
public void addMouseWheelListener(java.awt.event.MouseWheelListener listener)
public boolean kbhit()
public char getKey()
public int getKeyCode()
public char getKeyWait()
public int getKeyCodeWait()
public int getModifiers()
public java.lang.String getModifiersText()
public void add(java.awt.Component comp)
public void validate()
public GPane getPane()
public static void delay(int time)
public void addStatusBar(int height)
public void setStatusText(java.lang.String text)
public void setStatusText(java.lang.String text, java.awt.Font font, java.awt.Color color)
public void showStatusBar(boolean show)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |