java.lang.Objectorg.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
org.eclipse.swt.widgets.Canvas
com.gaborcselle.swt.Diagram
public class Diagram
A simple diagramming widget for SWT. The diagram rescales automatically when its size is changed (e.g. by resizing the window containing it).
Displays two axes (x and y) with labels.
In the diagram area, the user can draw lines, rectangles and text using drawX()
methods (drawLine(), drawRectangle() and drawText()).
Coordinates for range from (0.0, 0.0), which represents the lower left corner to (100.0, 100.0),
which represents for the upper right corner.
These coordinates are diagram coordinates: the actual physical coordinates change when
diagram is rescaled to a different size.
However, physical offsets can be given for all objects: The drawn objects are then shifted
right and up by the given number of pixels.
This widget will not dispose any Color or Font objects passed to it.
They must be disposed by the user.
An illustration of the diagram elements can be found at the authors' website.
Internals: All objects created with drawX() are stored in a list. When the
PaintEvent handler is called, these object's positions and sizes are scaled
according to the diagram area's current size and painted to the underlying Canvas
using the internal paintX() functions.
| Field Summary | |
|---|---|
static int |
VALIGN_CENTER
Constant for drawText(): Indicates that text should be drawn so that
given x / y coordinates are on left edge, in the middle of text. |
static int |
VALIGN_NORMAL
Constant for drawText(): Indicates that text should be drawn so that
given x / y coordinates are on left edge, in the bottom of the text. |
| Fields inherited from class org.eclipse.swt.widgets.Control |
|---|
handle |
| Constructor Summary | |
|---|---|
Diagram(org.eclipse.swt.widgets.Composite parent,
int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance. |
|
| Method Summary | |
|---|---|
void |
clear()
Clears all previously drawn objects in the diagram area. |
void |
drawLine(float x1,
float y1,
float x2,
float y2,
org.eclipse.swt.graphics.Color color,
int width)
Adds a line to the diagram. |
void |
drawLine(float x1,
float y1,
float x2,
float y2,
int xoffset,
int yoffset,
org.eclipse.swt.graphics.Color color,
int width)
Adds a line to the diagram and shifts it by the given offset. |
void |
drawRectangle(float x1,
float y1,
float x2,
float y2,
org.eclipse.swt.graphics.Color color)
Adds a rectangle to the diagram. |
void |
drawRectangle(float x1,
float y1,
float x2,
float y2,
int xoffset,
int yoffset,
org.eclipse.swt.graphics.Color color)
Adds a rectangle to the diagram and shifts it by the given offset. |
void |
drawText(java.lang.String text,
float x,
float y,
org.eclipse.swt.graphics.Font font,
int vAlign)
Adds text to the diagram. |
void |
drawText(java.lang.String text,
float x,
float y,
int xoffset,
int yoffset,
org.eclipse.swt.graphics.Font font,
int vAlign)
Adds text to the diagram and shifts it by the given offset. |
void |
setAxisDistance(int axisDistance)
Set the distance between the diagram axes and the labels. |
void |
setAxisLabelFont(org.eclipse.swt.graphics.Font axisLabelFont)
Set the font to be used to draw the axis labels. |
void |
setAxisLineWidth(int axisLineWidth)
Set the line width for the axes. |
void |
setBottomMargin(int bottomMargin)
The margin between the bottom edge of the diagram widget and the x axis labels. |
void |
setLeftMargin(int leftMargin)
The margin between the left edge of the diagram widget and the y axis labels. |
void |
setRightMargin(int rightMargin)
The margin between the right edge of the diagram widget and the right edge of the diagram area. |
void |
setTopMargin(int topMargin)
The margin between the top edge of the diagram widget and the top edge of the diagram area. |
void |
setXAxisLabelMax(java.lang.String xAxisLabelMax)
Set the label text next to the maximum marker on the x axis. |
void |
setXAxisLabelMin(java.lang.String xAxisLabelMin)
Set the label text next to the minimum marker on the x axis. |
void |
setYAxisLabelMax(java.lang.String yAxisLabelMax)
Set the label text next to the maximum marker on the y axis. |
void |
setYAxisLabelMin(java.lang.String yAxisLabelMin)
Set the label text next to the minimum marker on the y axis. |
| Methods inherited from class org.eclipse.swt.widgets.Canvas |
|---|
getCaret, scroll, setCaret, setFont |
| Methods inherited from class org.eclipse.swt.widgets.Composite |
|---|
changed, computeSize, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setFocus, setLayout, setLayoutDeferred, setTabList |
| Methods inherited from class org.eclipse.swt.widgets.Scrollable |
|---|
computeTrim, getClientArea, getHorizontalBar, getVerticalBar |
| Methods inherited from class org.eclipse.swt.widgets.Control |
|---|
addControlListener, addFocusListener, addHelpListener, addKeyListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addPaintListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBorderWidth, getBounds, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removePaintListener, removeTraverseListener, setBackground, setBounds, setBounds, setCapture, setCursor, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update |
| Methods inherited from class org.eclipse.swt.widgets.Widget |
|---|
addDisposeListener, addListener, dispose, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, setData, setData, toString |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int VALIGN_CENTER
drawText(): Indicates that text should be drawn so that
given x / y coordinates are on left edge, in the middle of text.
public static final int VALIGN_NORMAL
drawText(): Indicates that text should be drawn so that
given x / y coordinates are on left edge, in the bottom of the text.
| Constructor Detail |
|---|
public Diagram(org.eclipse.swt.widgets.Composite parent,
int style)
org.eclipse.swt.widgets.Canvas class for the meaning of the parameters.
| Method Detail |
|---|
public void drawText(java.lang.String text,
float x,
float y,
org.eclipse.swt.graphics.Font font,
int vAlign)
drawText(String, float, float, int, int, Font, int)
public void drawText(java.lang.String text,
float x,
float y,
int xoffset,
int yoffset,
org.eclipse.swt.graphics.Font font,
int vAlign)
paintText() when this diagram is painted.
text - The text to print on the diagram.x - x axis diagram coordinate of where text should be printedy - y axis diagram coordinate of where text should be printedxoffset - a physical x offset for where the text should be painted. Moves text to the right.yoffset - a physical y offset for where the text should be painted. Moves text up.font - The font with which the text should be drawn. Must be disposed by the user.vAlign - vertical alignment of the text to be drawn. Choices are VALIGN_CENTER and VALIGN_NORMAL.
public void drawLine(float x1,
float y1,
float x2,
float y2,
org.eclipse.swt.graphics.Color color,
int width)
drawLine(float, float, float, float, int, int, Color, int)
public void drawLine(float x1,
float y1,
float x2,
float y2,
int xoffset,
int yoffset,
org.eclipse.swt.graphics.Color color,
int width)
paintLine() when this diagram is painted.
x1 - x axis diagram coordinate of first line pointy1 - y axis diagram coordinate of first line pointx2 - x axis diagram coordinate of second line pointy2 - y axis diagram coordinate of second line pointxoffset - a physical x offset for where the line should be painted. Moves line to the right.yoffset - a physical y offset for where the rectangle should be painted. Moves line up.color - the color with which the line should be drawn. Color needs to be disposed by the user.width - the line width with which the line should be drawn.
public void drawRectangle(float x1,
float y1,
float x2,
float y2,
org.eclipse.swt.graphics.Color color)
drawRectangle(float, float, float, float, int, int, Color)
public void drawRectangle(float x1,
float y1,
float x2,
float y2,
int xoffset,
int yoffset,
org.eclipse.swt.graphics.Color color)
paintRectangle() when this diagram is painted.
x1 - x axis diagram coordinate of lower left cornery1 - y axis diagram coordinate of lower left cornerx2 - x axis diagram coordinate of upper right cornery2 - y axis diagram coordinate of upper right cornerxoffset - a physical x offset for where the rectangle should be painted. Moves rectangle to the right.yoffset - a physical y offset for where the rectangle should be painted. Moves rectangle up.color - public void clear()
public void setAxisDistance(int axisDistance)
axisDistance - The axisDistance to set.public void setAxisLabelFont(org.eclipse.swt.graphics.Font axisLabelFont)
axisLabelFont - The axisLabelFont to set.public void setBottomMargin(int bottomMargin)
bottomMargin - The bottomMargin to set.public void setLeftMargin(int leftMargin)
leftMargin - The leftMargin to set.public void setRightMargin(int rightMargin)
rightMargin - The rightMargin to set.public void setTopMargin(int topMargin)
topMargin - The topMargin to set.public void setXAxisLabelMax(java.lang.String xAxisLabelMax)
xAxisLabelMax - The xAxisLabelMax to set.public void setXAxisLabelMin(java.lang.String xAxisLabelMin)
xAxisLabelMin - The xAxisLabelMin to set.public void setYAxisLabelMax(java.lang.String yAxisLabelMax)
yAxisLabelMax - The yAxisLabelMax to set.public void setYAxisLabelMin(java.lang.String yAxisLabelMin)
yAxisLabelMin - The yAxisLabelMin to set.public void setAxisLineWidth(int axisLineWidth)
axisLineWidth - The axisLineWidth to set.