|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.webcompmath.draw.RationalLabel
public class RationalLabel
RationalLabels provide a way to label an axis with fractions, with an optional constant factor such as pi. The class adjusts for special cases:
1) the numerator is zero
2) the denominator is one (and hence no fraction is needed)
3) there is a factor and the numerator is 1; in this case, the factor is placed in the numerator (i.e., it shows pi/2 instead of 1/2 pi)
4) if it is negative and a fraction is needed, the minus sign is placed in front of the fractions (not in the numerator)
To use, create a RationalLabel, then call its drawFraction method. You can also use getBounds to find out how big it will be (useful when labeling an axis to avoid crowding labels too close together).
Nested Class Summary | |
---|---|
static class |
RationalLabel.HJust
Specify the horizontal justification for the rational label |
static class |
RationalLabel.VJust
Specify the vertical justification for the rational label |
Field Summary | |
---|---|
static java.lang.String |
pi
Used to represent pi |
Constructor Summary | |
---|---|
RationalLabel()
Default Constructor |
|
RationalLabel(Fraction frac,
java.lang.String factorString)
Construct a rational label. |
Method Summary | |
---|---|
void |
drawFraction(java.awt.Graphics2D g2,
int x,
int y,
RationalLabel.HJust hJust,
RationalLabel.VJust vJust)
Draws the rational label. |
java.awt.geom.Rectangle2D |
getBounds(java.awt.Graphics2D g2)
This method returns a bounding rectangle for the rational label. |
java.lang.String |
getFactorString()
Get the factor |
Fraction |
getFrac()
Get the fraction |
boolean |
isRationalText()
Get whether to use text or typeset label |
void |
setFactorString(java.lang.String factorString)
Set the factor (does nothing if argument is null) |
void |
setFrac(Fraction frac)
Set the fraction (does nothing if argument is null) |
void |
setRationalText(boolean rationalText)
Set whether to use text or typeset label |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String pi
Constructor Detail |
---|
public RationalLabel()
public RationalLabel(Fraction frac, java.lang.String factorString)
frac
- the fraction to use for the labelfactorString
- the constant factor, usually "", but might be "e" or piMethod Detail |
---|
public java.lang.String getFactorString()
public void setFactorString(java.lang.String factorString)
factorString
- The factorString to set.public Fraction getFrac()
public void setFrac(Fraction frac)
frac
- The frac to set.public boolean isRationalText()
public void setRationalText(boolean rationalText)
rationalText
- true for text, false for typeset (default)public java.awt.geom.Rectangle2D getBounds(java.awt.Graphics2D g2)
g2
- the graphics context
public void drawFraction(java.awt.Graphics2D g2, int x, int y, RationalLabel.HJust hJust, RationalLabel.VJust vJust)
g2
- the graphics contextx
- the x coordinate of the pointy
- the y coordinate of the pointhJust
- the horizontal justification, CENTER, LEFT, or RIGHTvJust
- the vertical justification, CENTER, TOP, or BOTTOM
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |