|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.jdesktop.swingx.JXPanel
org.jdesktop.swingx.JXGraph
public class JXGraph
JXGraph
provides a component which can display one or more
plots on top of a graduated background (or grid.)
To help analyze the plots, this component allows the user to pan the view by left-clicking and dragging the mouse around. Using the mouse wheel, the user is also able to zoom in and out. Clicking the middle button resets the view to its original position.
All user input can be disabled by calling
setInputEnabled(boolean)
and passing false. This does not prevent
subclasses from registering their own event listeners, such as mouse or key
listeners.
Whenever a new instance of this component is created, the grid boundaries, or view, must be defined. The view is comprised of several elements whose descriptions are the following:
The default constructor defines a view bounds by -1.0
and
+1.0
on both axis, and centered on an origin at
(0, 0)
.
To simplify the API, the origin can be read and written with a
Point2D
instance (see getOrigin()
and
setOrigin(Point2D)
.)
Likewise, the view can be read and written with a
Rectangle2D
instance (see getView()
and
setView(Rectangle2D)
.) In this case, you need not to define the
maximum boundaries of the view. Instead, you need to set the origin of the
rectangle as the minimum boundaries. The width and the height of the
rectangle define the distance between the minimum and maximum boundaries. For
instance, to set the view to minX=-1.0, maxX=1.0, minY=-1.0 and maxY=1.0 you
can use the following rectangle:
new Rectangle2D.Double(-1.0d, -1.0d, 2.0d, 2.0d);
You can check the boundaries by calling Rectangle2D.getMaxX()
and Rectangle2D.getMaxY()
once your rectangle has been
created.
Alternatively, you can set the view and the origin at the same time by
calling the method setViewAndOrigin(Rectangle2D)
. Calling this
method will set the origin so as to center it in the view defined by the
rectangle.
By default, the component defines a spacing of 0.2 units between two
major grid lines. It also defines 4 minor grid lines between two major
grid lines. The spacing between major grid lines and the number of minor
grid lines can be accessed through the getters getMajorX()
,
getMajorY()
, getMinorCountX()
and
getMinorCountY()
.
You can change the number of grid lines at runtime by calling the setters
setMajorX(double)
, setMajorY(double)
,
setMinorCountX(int)
and setMinorCountY(int)
.
Although it provides sensible defaults, this component lets you change
its appearance in several ways. It is possible to modify the colors of the
graph by calling the setters setAxisColor(Color)
,
setMajorGridColor(Color)
and setMinorGridColor(Color)
.
You can also enable or disable given parts of the resulting graph by calling the following setters:
setAxisPainted(boolean)
: Defines whether the main axis (see
getOrigin()
) is painted.setBackgroundPainted(boolean)
: Defines whether the background
is painted (see JXPanel.setBackground(Color)
.)setGridPainted(boolean)
: Defines whether the grid is
painted.setTextPainted(boolean)
: Defines whether the axis labels are
painted.The following code snippet creates a new graph centered on
(0, 0)
, bound to the view [-1.0 1.0 -1.0 1.0]
, with
a major grid line every 0.5 units and a minor grid line count of 5:
Point2D origin = new Point2D.Double(0.0d, 0.0d); Rectangle2D view = new Rectangle2D.Double(-1.0d, 1.0d, 2.0d, 2.0d); JXGraph graph = new JXGraph(origin, view, 0.5d, 5, 0.5d, 5);
A plot is defined by a mathematical transformation that, given a value on
the graph's X axis, returns a value on the Y axis. The component draws the
result by plotting a spot of color at the coordinates defined by
(X, f(X))
where f()
is the aforementionned
mathematical transformation. Given the following transformation:
f(X) = X * 2.0
For X=1.0
, the component will show a spot of color at the
coordinates (1.0, 2.0)
.
Every plot drawn by the component must be a subclass of
JXGraph.Plot
. This abstract public class defines a single method to
be implemented by its children:
public double compute(double value)
The previous example can be defined by a concrete
JXGraph.Plot
as follow:
class TwiceTheValuePlot extends JXGraph.Plot { public double compute(double value) { return value * 2.0d; } }
Most of the time though, a plot requires supplementary parameters. For
instance, let's define the X axis of your graph as the mass of an object. To
compute the weight of the object given its mass, you need to use the
acceleration of gravity (w=m*g
where g
is the
acceleration.) To let the user modify this last parameter, to compute his
weight at the surface of the moon for instance, you need to add a parameter
to your plot.
While JXGraph.Plot
does not give you an API for such a
purpose, it does define an event dispatching API (see
Component.firePropertyChange(String, double, double)
.) Whenever a
plot is added to the graph, the component registers itself as a property
listener of the plot. If you take care of firing events whenever the user
changes a parameter of your plot, the graph will automatically update its
display. While not mandatory, it is highly recommended to leverage this
API.
To add a plot to the graph, simply call the method
addPlots(Color, JXGraph.Plot...)
. You can use it to add one or more
plots at the same time and associate them with a color. This color is used
when drawing the plots:
JXGraph.Plot plot = new TwiceTheValuePlot(); graph.addPlots(Color.BLUE, plot);
These two lines will display our previously defined plot in blue on
screen. Removing one or several plots is as simple as calling the method
removePlots(JXGraph.Plot...)
. You can also remove all plots at once
with removeAllPlots()
.
If you need to add more information on the graph you need to extend
it and override the method paintExtra(Graphics2D)
. This
method has a default empty implementation and is called after everything
has been drawn. Its sole parameter is a reference to the component's drawing
surface, as configured by setupGraphics(Graphics2D)
. By default, the
setup method activates antialising but it can be overriden to change the
drawing surface. (Translation, rotation, new rendering hints, etc.)
To properly draw on the graph you will need to perform a translation between the graph's coordinates and the screen's coordinates. The component defines 4 methods to assist you in this task:
xPixelToPosition(double)
: Converts a pixel coordinate on the
X axis into a world coordinate.xPositionToPixel(double)
: Converts a world coordinate on the
X axis into a pixel coordinate.yPixelToPosition(double)
: Converts a pixel coordinate on the
Y axis into a world coordinate.yPositionToPixel(double)
: Converts a world coordinate on the
Y axis into a pixel coordinate.If you have defined a graph view centered on the origin
(0, 0)
, the origin of the graph will be at the exact center of
the screen. That means the world coordinates (0, 0)
are
equivalent to the pixel coordinates (width / 2, height / 2)
.
Thus, calling xPositionToPixel(0.0d)
would give you the same
value as the expression getWidth() / 2.0d
.
Converting from world coordinates to pixel coordinates is mostly used to draw the result of a mathematical transformation. Converting from pixel coordinates to world coordinates is mostly used to get the position in the world of a mouse event.
JXGraph.Plot
,
Serialized FormNested Class Summary | |
---|---|
static class |
JXGraph.Plot
A plot represents a mathematical transformation used by JXGraph . |
Nested classes/interfaces inherited from class javax.swing.JPanel |
---|
JPanel.AccessibleJPanel |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary |
---|
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
JXGraph()
Creates a new graph display. |
|
JXGraph(double originX,
double originY,
double minX,
double maxX,
double minY,
double maxY,
double majorX,
int minorCountX,
double majorY,
int minorCountY)
Creates a new graph display with the specified view, origin and grid lines. |
|
JXGraph(Point2D origin,
Rectangle2D view)
Creates a new graph display with the specified view and origin. |
|
JXGraph(Point2D origin,
Rectangle2D view,
double majorX,
int minorCountX,
double majorY,
int minorCountY)
Creates a new graph display with the specified view, origin and grid lines. |
|
JXGraph(Rectangle2D view)
Creates a new graph display with the specified view. |
|
JXGraph(Rectangle2D view,
double majorX,
int minorCountX,
double majorY,
int minorCountY)
Creates a new graph display with the specified view and grid lines. |
Method Summary | |
---|---|
void |
addPlots(Color color,
JXGraph.Plot... plotList)
Adds one or more plots to the graph. |
Color |
getAxisColor()
Gets the main axis color of this component. |
Color |
getMajorGridColor()
Gets the major grid lines color of this component. |
double |
getMajorX()
Gets the distance, in graph units, between two major grid lines on the X axis. |
double |
getMajorY()
Gets the distance, in graph units, between two major grid lines on the Y axis. |
int |
getMinorCountX()
Gets the number of minor grid lines between two major grid lines on the X axis. |
int |
getMinorCountY()
Gets the number of minor grid lines between two major grid lines on the Y axis. |
Color |
getMinorGridColor()
Gets the minor grid lines color of this component. |
Point2D |
getOrigin()
Gets the origin coordinates of the graph. |
Dimension |
getPreferredSize()
If the preferredSize has been set to a
non-null value just returns it. |
Rectangle2D |
getView()
Gets the view of the graph. |
boolean |
isAxisPainted()
Defines whether or not the graph main axis is painted by this component. |
boolean |
isBackgroundPainted()
Defines whether or not the background painted by this component. |
boolean |
isGridPainted()
Defines whether or not grids lines are painted by this component. |
boolean |
isInputEnabled()
Defines whether or not user input is accepted and managed by this component. |
boolean |
isOpaque()
Returns true if this component is completely opaque. |
boolean |
isTextPainted()
Defines whether or not axis labels are painted by this component. |
protected void |
paintBackground(Graphics2D g2)
This method is called by the component whenever it needs to paint its background. |
protected void |
paintComponent(Graphics g)
Overridden to provide Painter support. |
protected void |
paintExtra(Graphics2D g2)
This painting method is meant to be overriden by subclasses of JXGraph . |
void |
removeAllPlots()
Removes all the plots currently associated with this graph. |
void |
removePlots(JXGraph.Plot... plotList)
Removes the specified plots from the graph. |
void |
resetView()
Resets the view to the default view if it has been changed by the user by panning and zooming. |
void |
setAxisColor(Color axisColor)
Sets the color of main axis on this component. |
void |
setAxisPainted(boolean axisPainted)
Enables or disables the painting of main axis depending on the value of the parameter. |
void |
setBackgroundPainted(boolean backPainted)
Enables or disables the painting of background depending on the value of the parameter. |
void |
setEnabled(boolean enabled)
Sets whether or not this component is enabled. |
void |
setGridPainted(boolean gridPainted)
Enables or disables the painting of grid lines depending on the value of the parameter. |
void |
setInputEnabled(boolean enabled)
Enables or disables user input on the component. |
void |
setMajorGridColor(Color majorGridColor)
Sets the color of major grid lines on this component. |
void |
setMajorX(double majorX)
Sets the distance, in graph units, between two major grid lines on the X axis. |
void |
setMajorY(double majorY)
Sets the distance, in graph units, between two major grid lines on the Y axis. |
void |
setMinorCountX(int minorCountX)
Sets the number of minor grid lines between two major grid lines on the X axis. |
void |
setMinorCountY(int minorCountY)
Sets the number of minor grid lines between two major grid lines on the Y axis. |
void |
setMinorGridColor(Color minorGridColor)
Sets the color of minor grid lines on this component. |
void |
setOrigin(Point2D origin)
Sets the origin of the graph. |
void |
setTextPainted(boolean textPainted)
Enables or disables the painting of axis labels depending on the value of the parameter. |
protected void |
setupGraphics(Graphics2D g2)
This method is called by the component prior to any drawing operation to configure the drawing surface. |
void |
setView(Rectangle2D bounds)
Sets the view of the graph. |
void |
setViewAndOrigin(Rectangle2D bounds)
Sets the view and the origin of the graph at the same time. |
protected double |
xPixelToPosition(double pixel)
Converts a pixel coordinate from the X axis into a graph position, in graph units. |
protected double |
xPositionToPixel(double position)
Converts a position, in graph units, from the X axis into a pixel coordinate. |
protected double |
yPixelToPosition(double pixel)
Converts a pixel coordinate from the Y axis into a graph position, in graph units. |
protected double |
yPositionToPixel(double position)
Converts a position, in graph units, from the Y axis into a pixel coordinate. |
Methods inherited from class javax.swing.JPanel |
---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public JXGraph()
Creates a new graph display. The following properties are automatically set:
(0, 0)
public JXGraph(Rectangle2D view)
Creates a new graph display with the specified view. The following properties are automatically set:
view
- the rectangle defining the view boundariespublic JXGraph(Rectangle2D view, double majorX, int minorCountX, double majorY, int minorCountY)
Creates a new graph display with the specified view and grid lines. The origin is set at the center of the view.
view
- the rectangle defining the view boundariesmajorX
- the spacing between two major grid lines on the X axisminorCountX
- the number of minor grid lines betweek two major
grid lines on the X axismajorY
- the spacing between two major grid lines on the Y axisminorCountY
- the number of minor grid lines betweek two major
grid lines on the Y axis
IllegalArgumentException
- if minX >= maxX or minY >= maxY or
minorCountX < 0 or minorCountY < 0 or
majorX <= 0.0 or majorY <= 0.0public JXGraph(Point2D origin, Rectangle2D view)
Creates a new graph display with the specified view and origin. The following properties are automatically set:
origin
- the coordinates of the main axis originview
- the rectangle defining the view boundariespublic JXGraph(Point2D origin, Rectangle2D view, double majorX, int minorCountX, double majorY, int minorCountY)
Creates a new graph display with the specified view, origin and grid lines.
origin
- the coordinates of the main axis originview
- the rectangle defining the view boundariesmajorX
- the spacing between two major grid lines on the X axisminorCountX
- the number of minor grid lines betweek two major
grid lines on the X axismajorY
- the spacing between two major grid lines on the Y axisminorCountY
- the number of minor grid lines betweek two major
grid lines on the Y axis
IllegalArgumentException
- if minX >= maxX or minY >= maxY or
minorCountX < 0 or minorCountY < 0 or
majorX <= 0.0 or majorY <= 0.0public JXGraph(double originX, double originY, double minX, double maxX, double minY, double maxY, double majorX, int minorCountX, double majorY, int minorCountY)
Creates a new graph display with the specified view, origin and grid lines.
originX
- the coordinate of the major X axisoriginY
- the coordinate of the major Y axisminX
- the minimum coordinate on the X axis for the viewmaxX
- the maximum coordinate on the X axis for the viewminY
- the minimum coordinate on the Y axis for the viewmaxY
- the maximum coordinate on the Y axis for the viewmajorX
- the spacing between two major grid lines on the X axisminorCountX
- the number of minor grid lines betweek two major
grid lines on the X axismajorY
- the spacing between two major grid lines on the Y axisminorCountY
- the number of minor grid lines betweek two major
grid lines on the Y axis
IllegalArgumentException
- if minX >= maxX or minY >= maxY or
minorCountX < 0 or minorCountY < 0 or
majorX <= 0.0 or majorY <= 0.0Method Detail |
---|
public boolean isOpaque()
An opaque component paints every pixel within its rectangular bounds. A non-opaque component paints only a subset of its pixels or none at all, allowing the pixels underneath it to "show through". Therefore, a component that does not fully paint its pixels provides a degree of transparency.
Subclasses that guarantee to always completely paint their contents should override this method and return true.
isOpaque
in class JComponent
JComponent.setOpaque(boolean)
public void setEnabled(boolean enabled)
Note: Disabling a component does not disable it's children.
Note: Disabling a lightweight component does not prevent it from receiving MouseEvents.
setEnabled
in class JComponent
enabled
- true if this component should be enabled, false otherwisesetInputEnabled(boolean)
public void setInputEnabled(boolean enabled)
Enables or disables user input on the component. When user input is enabled, panning, zooming and view resetting. Disabling input will prevent the user from modifying the currently displayed view.
Calling setEnabled(boolean)
disables the component in the
Swing hierarchy and invokes this method.
enabled
- true if user input must be enabled, false otherwisesetEnabled(boolean)
,
isInputEnabled()
public boolean isInputEnabled()
Defines whether or not user input is accepted and managed by this component. The component is always created with user input enabled.
setInputEnabled(boolean)
public boolean isTextPainted()
Defines whether or not axis labels are painted by this component. The component is always created with text painting enabled.
setTextPainted(boolean)
,
Component.getForeground()
public void setTextPainted(boolean textPainted)
Enables or disables the painting of axis labels depending on the value of the parameter. Text painting is enabled by default.
textPainted
- if true, axis labels are paintedisTextPainted()
,
JComponent.setForeground(Color)
public boolean isGridPainted()
Defines whether or not grids lines are painted by this component. The component is always created with grid lines painting enabled.
setGridPainted(boolean)
,
getMajorGridColor()
,
getMinorGridColor()
public void setGridPainted(boolean gridPainted)
Enables or disables the painting of grid lines depending on the value of the parameter. Grid painting is enabled by default.
gridPainted
- if true, axis labels are paintedisGridPainted()
,
setMajorGridColor(Color)
,
setMinorGridColor(Color)
public boolean isAxisPainted()
Defines whether or not the graph main axis is painted by this component. The component is always created with main axis painting enabled.
setTextPainted(boolean)
,
getAxisColor()
public void setAxisPainted(boolean axisPainted)
Enables or disables the painting of main axis depending on the value of the parameter. Axis painting is enabled by default.
axisPainted
- if true, axis labels are paintedisAxisPainted()
,
setAxisColor(Color)
public boolean isBackgroundPainted()
Defines whether or not the background painted by this component. The component is always created with background painting enabled. When background painting is disabled, background painting is deferred to the parent class.
setBackgroundPainted(boolean)
,
Component.getBackground()
public void setBackgroundPainted(boolean backPainted)
Enables or disables the painting of background depending on the value of the parameter. Background painting is enabled by default.
backPainted
- if true, axis labels are paintedisBackgroundPainted()
,
JXPanel.setBackground(Color)
public Color getMajorGridColor()
Gets the major grid lines color of this component.
setMajorGridColor(Color)
,
setGridPainted(boolean)
public void setMajorGridColor(Color majorGridColor)
Sets the color of major grid lines on this component. The color can be translucent.
majorGridColor
- the color to become this component's major grid
lines color
IllegalArgumentException
- if the specified color is nullgetMajorGridColor()
,
isGridPainted()
public Color getMinorGridColor()
Gets the minor grid lines color of this component.
setMinorGridColor(Color)
,
setGridPainted(boolean)
public void setMinorGridColor(Color minorGridColor)
Sets the color of minor grid lines on this component. The color can be translucent.
minorGridColor
- the color to become this component's minor grid
lines color
IllegalArgumentException
- if the specified color is nullgetMinorGridColor()
,
isGridPainted()
public Color getAxisColor()
Gets the main axis color of this component.
setAxisColor(Color)
,
setGridPainted(boolean)
public void setAxisColor(Color axisColor)
Sets the color of main axis on this component. The color can be translucent.
axisColor
- the color to become this component's main axis color
IllegalArgumentException
- if the specified color is nullgetAxisColor()
,
isAxisPainted()
public double getMajorX()
Gets the distance, in graph units, between two major grid lines on the X axis.
setMajorX(double)
,
getMajorY()
,
setMajorY(double)
,
getMinorCountX()
,
setMinorCountX(int)
public void setMajorX(double majorX)
Sets the distance, in graph units, between two major grid lines on the X axis.
majorX
- the requested spacing between two major grid lines on the
X axis
IllegalArgumentException
- if majorX is <= 0.0dgetMajorX()
,
getMajorY()
,
setMajorY(double)
,
getMinorCountX()
,
setMinorCountX(int)
public int getMinorCountX()
Gets the number of minor grid lines between two major grid lines on the X axis.
setMinorCountX(int)
,
getMinorCountY()
,
setMinorCountY(int)
,
getMajorX()
,
setMajorX(double)
public void setMinorCountX(int minorCountX)
Sets the number of minor grid lines between two major grid lines on the X axis.
minorCountX
- the number of minor grid lines between two major grid
lines on the X axis
IllegalArgumentException
- if minorCountX is < 0getMinorCountX()
,
getMinorCountY()
,
setMinorCountY(int)
,
getMajorX()
,
setMajorX(double)
public double getMajorY()
Gets the distance, in graph units, between two major grid lines on the Y axis.
setMajorY(double)
,
getMajorX()
,
setMajorX(double)
,
getMinorCountY()
,
setMinorCountY(int)
public void setMajorY(double majorY)
Sets the distance, in graph units, between two major grid lines on the Y axis.
majorY
- the requested spacing between two major grid lines on the
Y axis
IllegalArgumentException
- if majorY is <= 0.0dgetMajorY()
,
getMajorX()
,
setMajorX(double)
,
getMinorCountY()
,
setMinorCountY(int)
public int getMinorCountY()
Gets the number of minor grid lines between two major grid lines on the Y axis.
setMinorCountY(int)
,
getMinorCountX()
,
setMinorCountX(int)
,
getMajorY()
,
setMajorY(double)
public void setMinorCountY(int minorCountY)
Sets the number of minor grid lines between two major grid lines on the Y axis.
minorCountY
- the number of minor grid lines between two major grid
lines on the Y axis
IllegalArgumentException
- if minorCountY is < 0getMinorCountY()
,
getMinorCountX()
,
setMinorCountX(int)
,
getMajorY()
,
setMajorY(double)
public void setViewAndOrigin(Rectangle2D bounds)
Sets the view and the origin of the graph at the same time. The view minimum boundaries are defined by the location of the rectangle passed as parameter. The width and height of the rectangle define the distance between the minimum and maximum boundaries:
The origin is located at the center of the view. Its coordinates are defined by calling bounds.getCenterX() and bounds.getCenterY().
bounds
- the rectangle defining the graph's view and its origingetView()
,
setView(Rectangle2D)
,
getOrigin()
,
setOrigin(Point2D)
public void setView(Rectangle2D bounds)
Sets the view of the graph. The view minimum boundaries are defined by the location of the rectangle passed as parameter. The width and height of the rectangle define the distance between the minimum and maximum boundaries:
If the specified view is null, nothing happens.
Calling this method leaves the origin intact.
bounds
- the rectangle defining the graph's view and its origingetView()
,
setViewAndOrigin(Rectangle2D)
public Rectangle2D getView()
Gets the view of the graph. The returned rectangle defines the bounds of the view as follows:
setView(Rectangle2D)
,
setViewAndOrigin(Rectangle2D)
public void resetView()
Resets the view to the default view if it has been changed by the user
by panning and zooming. The default view is defined by the view last
specified in a constructor call or a call to the methods
setView(Rectangle2D)
and
setViewAndOrigin(Rectangle2D)
.
setView(Rectangle2D)
,
setViewAndOrigin(Rectangle2D)
public void setOrigin(Point2D origin)
Sets the origin of the graph. The coordinates of the origin are defined by the coordinates of the point passed as parameter.
If the specified view is null, nothing happens.
Calling this method leaves the view intact.
origin
- the coordinates of the new origingetOrigin()
,
setViewAndOrigin(Rectangle2D)
public Point2D getOrigin()
Gets the origin coordinates of the graph. The coordinates are
represented as an instance of Point2D
and stored in
double
format.
setOrigin(Point2D)
,
setViewAndOrigin(Rectangle2D)
public void addPlots(Color color, JXGraph.Plot... plotList)
Adds one or more plots to the graph. These plots are associated to a color used to draw them.
If plotList is null or empty, nothing happens.
This method is not thread safe and should be called only from the EDT.
color
- the color to be usd to draw the plotsplotList
- the list of plots to add to the graph
IllegalArgumentException
- if color is nullremovePlots(JXGraph.Plot...)
,
removeAllPlots()
public void removePlots(JXGraph.Plot... plotList)
Removes the specified plots from the graph. Plots to be removed
are identified by identity. This means you cannot remove a plot by
passing a clone or another instance of the same subclass of
JXGraph.Plot
.
If plotList is null or empty, nothing happens.
This method is not thread safe and should be called only from the EDT.
plotList
- the list of plots to be removed from the graphremoveAllPlots()
,
addPlots(Color, JXGraph.Plot...)
public void removeAllPlots()
Removes all the plots currently associated with this graph.
This method is not thread safe and should be called only from the EDT.
removePlots(JXGraph.Plot...)
,
addPlots(Color, JXGraph.Plot...)
public Dimension getPreferredSize()
preferredSize
has been set to a
non-null
value just returns it.
If the UI delegate's getPreferredSize
method returns a non null
value then return that;
otherwise defer to the component's layout manager.
getPreferredSize
in class JComponent
preferredSize
propertyJComponent.setPreferredSize(java.awt.Dimension)
,
ComponentUI
protected double yPositionToPixel(double position)
Converts a position, in graph units, from the Y axis into a pixel
coordinate. For instance, if you defined the origin so it appears at the
exact center of the view, calling
yPositionToPixel(getOriginY())
will return a value
approximately equal to getHeight() / 2.0
.
position
- the Y position to be converted into pixels
xPositionToPixel(double)
,
yPixelToPosition(double)
protected double xPositionToPixel(double position)
Converts a position, in graph units, from the X axis into a pixel
coordinate. For instance, if you defined the origin so it appears at the
exact center of the view, calling
xPositionToPixel(getOriginX())
will return a value
approximately equal to getWidth() / 2.0
.
position
- the X position to be converted into pixels
yPositionToPixel(double)
,
xPixelToPosition(double)
protected double xPixelToPosition(double pixel)
Converts a pixel coordinate from the X axis into a graph position, in
graph units. For instance, if you defined the origin so it appears at the
exact center of the view, calling
xPixelToPosition(getWidth() / 2.0)
will return a value
approximately equal to getOriginX()
.
pixel
- the X pixel coordinate to be converted into a graph position
yPixelToPosition(double)
,
xPositionToPixel(double)
protected double yPixelToPosition(double pixel)
Converts a pixel coordinate from the Y axis into a graph position, in
graph units. For instance, if you defined the origin so it appears at the
exact center of the view, calling
yPixelToPosition(getHeight() / 2.0)
will return a value
approximately equal to getOriginY()
.
pixel
- the Y pixel coordinate to be converted into a graph position
xPixelToPosition(double)
,
yPositionToPixel(double)
protected void paintComponent(Graphics g)
paintComponent
in class JXPanel
g
- the Graphics
object to protectJComponent.paint(java.awt.Graphics)
,
ComponentUI
protected void paintExtra(Graphics2D g2)
This painting method is meant to be overriden by subclasses of
JXGraph
. This method is called after all the painting
is done. By overriding this method, a subclass can display extra
information on top of the graph.
The graphics surface passed as parameter is configured by
setupGraphics(Graphics2D)
.
g2
- the graphics surface on which the graph is drawnsetupGraphics(Graphics2D)
,
xPixelToPosition(double)
,
yPixelToPosition(double)
,
xPositionToPixel(double)
,
yPositionToPixel(double)
protected void setupGraphics(Graphics2D g2)
This method is called by the component prior to any drawing operation to configure the drawing surface. The default implementation enables antialiasing on the graphics.
This method can be overriden by subclasses to modify the drawing surface before any painting happens.
g2
- the graphics surface to set uppaintExtra(Graphics2D)
,
paintBackground(Graphics2D)
protected void paintBackground(Graphics2D g2)
This method is called by the component whenever it needs to paint
its background. The default implementation fills the background with
a solid color as defined by Component.getBackground()
. Background painting
does not happen when isBackgroundPainted()
returns false.
It is recommended to subclasses to honor the contract defined by
isBackgroundPainted()
and setBackgroundPainted(boolean)
.
g2
- the graphics surface on which the background must be drawnsetupGraphics(Graphics2D)
,
paintExtra(Graphics2D)
,
isBackgroundPainted()
,
setBackgroundPainted(boolean)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |