public class ValueGridPortrayal2D extends FieldPortrayal2D
Like other FieldPortrayal2Ds, this class uses an underlying SimplePortrayal2D to draw each separate element in the grid. A default SimplePortrayal2D is provided which draws squares. In the default, the color for the square is determined by looking up the value of the square in a user-provided color-table, or if there is none, by interpolating it between two user-provided colors. See the setColorTable() and setLevels() methods.
Here's a trick you might consider in specifying interpolations. Rather than draw from white to red (for example), you might consider setting the backdrop of the display to white, and then instead draw from FULLY TRANSPARENT white to FULLY OPAQUE red. That is, from Color(0,0,0,0) to Color(255,0,0,255). Fully transparent colors are not drawn; and not drawing at all is significantly faster than drawing for no reason! Plus you can stack multiple ValueGridPortrayal2Ds on top of one another and let the transparency bleed through for a nice effect. The alpha channel is your friend.
By default the min Level and the max Level are the same (1.0), and the alpha values for both are 0 (totally transparent). Thus if you want a range, you must specify it. This is intentional, because this way if you want to use a color table instead (say, to specify three colors for the integers 0, 1, and 2), you can specify them, and ALL other grid values will be automatically transparent.
If you would like more control over the color of your values (perhaps to implement a nonlinear function of the colors), you can override the getColor() function to define your own custom color.
You can also provide your own custom SimplePortrayal2D (use setPortrayalForAll(...) ) to draw elements as you see fit rather than as rectangles. Your SimplePortrayal2D should expect objects passed to its draw method to be of type MutableDouble. Do not hold onto this array -- it will be reused. The 'location' passed into the DrawInfo2D handed to the SimplePortryal2D is a MutableInt2D.
Modifier and Type | Field and Description |
---|---|
protected MutableInt2D |
locationToPass |
protected MutableDouble |
valueToPass |
DEFAULT, DONT_USE_BUFFER, USE_BUFFER
classPortrayals, field, immutableField, portrayalForAll, portrayalForNonNull, portrayalForNull, portrayalForRemainder, portrayals
Constructor and Description |
---|
ValueGridPortrayal2D() |
ValueGridPortrayal2D(java.lang.String valueName) |
Modifier and Type | Method and Description |
---|---|
Portrayal |
getDefaultPortrayal()
Should return a portrayal which can portray any object regardless of
whether it's valid or not
|
java.awt.geom.Point2D.Double |
getLocationPosition(java.lang.Object location,
DrawInfo2D info)
Returns the position on-screen of the provided location in the underlying field.
|
ColorMap |
getMap() |
java.lang.Object |
getPositionLocation(java.awt.geom.Point2D.Double position,
DrawInfo2D info)
Returns the Location, in the parlance of the underlying Field, of the given position.
|
Double2D |
getScale(DrawInfo2D info)
Returns the width and height, in pixels, of 1.0 x 1.0 units in the underlying field.
|
java.lang.String |
getValueName() |
LocationWrapper |
getWrapper(double val,
Int2D loc) |
protected void |
hitOrDraw(java.awt.Graphics2D graphics,
DrawInfo2D info,
Bag putInHere)
Instead of overriding the draw and hitObjects methods, you can optionally override
this method to provide both the draw(...) and hitObjects(...)
functionality in a single method, as it's common that these two methods have nearly
identical code.
|
double |
newValue(int x,
int y,
double value)
This method is called by the default inspector to filter new values set by the user.
|
void |
setBorder(boolean on)
Turns border lines on or off.
|
void |
setBorderColor(java.awt.Color val)
Sets the border color.
|
void |
setBorderLineFraction(double val)
Sets the border line fraction.
|
void |
setBorderLineMinMaxWidth(double min,
double max)
Sets the minimum and maximum width of a border line in pixels.
|
void |
setField(java.lang.Object field)
Sets the field, and sets the dirtyField flag to true.
|
void |
setGridColor(java.awt.Color val)
Sets the grid color.
|
void |
setGridLineFraction(double val)
Sets the grid line fraction.
|
void |
setGridLineMinMaxWidth(double min,
double max)
Sets the minimum and maximum width of a grid line in pixels.
|
void |
setGridLines(boolean on)
Turns grid lines on or off.
|
void |
setGridMinSpacing(double val)
Sets the grid min spacing.
|
void |
setGridModulus(int val)
Sets the grid modulus.
|
void |
setMap(ColorMap m) |
void |
setValueName(java.lang.String name) |
draw, getBuffering, getClipLocation, getObjectPosition, getRelativeObjectPosition, hitObjects, setBuffering, setObjectPosition
getDefaultNullPortrayal, getField, getInspector, getName, getObjectLocation, getPortrayalForAll, getPortrayalForNonNull, getPortrayalForNull, getPortrayalForObject, getPortrayalForRemainder, getStatus, isDirtyField, isImmutableField, reset, setDirtyField, setImmutableField, setObjectLocation, setPortrayalForAll, setPortrayalForClass, setPortrayalForNonNull, setPortrayalForNull, setPortrayalForObject, setPortrayalForRemainder, setSelected, setSelected
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getInspector, getName, getStatus, setSelected
protected final MutableDouble valueToPass
protected final MutableInt2D locationToPass
public ValueGridPortrayal2D()
public ValueGridPortrayal2D(java.lang.String valueName)
public ColorMap getMap()
public void setMap(ColorMap m)
public void setField(java.lang.Object field)
FieldPortrayal
setField
in class FieldPortrayal
public java.lang.String getValueName()
public void setValueName(java.lang.String name)
public double newValue(int x, int y, double value)
public Double2D getScale(DrawInfo2D info)
FieldPortrayal2D
getScale
in class FieldPortrayal2D
public java.lang.Object getPositionLocation(java.awt.geom.Point2D.Double position, DrawInfo2D info)
FieldPortrayal2D
getPositionLocation
in class FieldPortrayal2D
public java.awt.geom.Point2D.Double getLocationPosition(java.lang.Object location, DrawInfo2D info)
FieldPortrayal2D
getLocationPosition
in class FieldPortrayal2D
public Portrayal getDefaultPortrayal()
FieldPortrayal
getDefaultPortrayal
in class FieldPortrayal2D
protected void hitOrDraw(java.awt.Graphics2D graphics, DrawInfo2D info, Bag putInHere)
FieldPortrayal2D
hitOrDraw
in class FieldPortrayal2D
public LocationWrapper getWrapper(double val, Int2D loc)
public void setGridLines(boolean on)
public void setGridColor(java.awt.Color val)
public void setGridModulus(int val)
public void setGridMinSpacing(double val)
public void setGridLineFraction(double val)
public void setGridLineMinMaxWidth(double min, double max)
public void setBorder(boolean on)
public void setBorderColor(java.awt.Color val)
public void setBorderLineFraction(double val)
public void setBorderLineMinMaxWidth(double min, double max)