use of org.jfree.ui.TextAnchor in project SIMVA-SoS by SESoS.
the class CyclicNumberAxis method refreshVerticalTicks.
/**
* Builds a list of ticks for the axis. This method is called when the
* axis is at the left or right of the chart (so the axis is "vertical").
*
* @param g2 the graphics device.
* @param dataArea the data area.
* @param edge the edge.
*
* @return A list of ticks.
*/
protected List refreshVerticalTicks(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
List result = new java.util.ArrayList();
result.clear();
Font tickLabelFont = getTickLabelFont();
g2.setFont(tickLabelFont);
if (isAutoTickUnitSelection()) {
selectAutoTickUnit(g2, dataArea, edge);
}
double unit = getTickUnit().getSize();
double cycleBound = getCycleBound();
double currentTickValue = Math.ceil(cycleBound / unit) * unit;
double upperValue = getRange().getUpperBound();
boolean cycled = false;
boolean boundMapping = this.boundMappedToLastCycle;
this.boundMappedToLastCycle = true;
NumberTick lastTick = null;
float lastY = 0.0f;
if (upperValue == cycleBound) {
currentTickValue = calculateLowestVisibleTickValue();
cycled = true;
this.boundMappedToLastCycle = true;
}
while (currentTickValue <= upperValue) {
// Cycle when necessary
boolean cyclenow = false;
if ((currentTickValue + unit > upperValue) && !cycled) {
cyclenow = true;
}
double yy = valueToJava2D(currentTickValue, dataArea, edge);
String tickLabel;
NumberFormat formatter = getNumberFormatOverride();
if (formatter != null) {
tickLabel = formatter.format(currentTickValue);
} else {
tickLabel = getTickUnit().valueToString(currentTickValue);
}
float y = (float) yy;
TextAnchor anchor;
TextAnchor rotationAnchor;
double angle = 0.0;
if (isVerticalTickLabels()) {
if (edge == RectangleEdge.LEFT) {
anchor = TextAnchor.BOTTOM_CENTER;
if ((lastTick != null) && (lastY == y) && (currentTickValue != cycleBound)) {
anchor = isInverted() ? TextAnchor.BOTTOM_LEFT : TextAnchor.BOTTOM_RIGHT;
result.remove(result.size() - 1);
result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
this.internalMarkerWhenTicksOverlap = true;
anchor = isInverted() ? TextAnchor.BOTTOM_RIGHT : TextAnchor.BOTTOM_LEFT;
}
rotationAnchor = anchor;
angle = -Math.PI / 2.0;
} else {
anchor = TextAnchor.BOTTOM_CENTER;
if ((lastTick != null) && (lastY == y) && (currentTickValue != cycleBound)) {
anchor = isInverted() ? TextAnchor.BOTTOM_RIGHT : TextAnchor.BOTTOM_LEFT;
result.remove(result.size() - 1);
result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
this.internalMarkerWhenTicksOverlap = true;
anchor = isInverted() ? TextAnchor.BOTTOM_LEFT : TextAnchor.BOTTOM_RIGHT;
}
rotationAnchor = anchor;
angle = Math.PI / 2.0;
}
} else {
if (edge == RectangleEdge.LEFT) {
anchor = TextAnchor.CENTER_RIGHT;
if ((lastTick != null) && (lastY == y) && (currentTickValue != cycleBound)) {
anchor = isInverted() ? TextAnchor.BOTTOM_RIGHT : TextAnchor.TOP_RIGHT;
result.remove(result.size() - 1);
result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
this.internalMarkerWhenTicksOverlap = true;
anchor = isInverted() ? TextAnchor.TOP_RIGHT : TextAnchor.BOTTOM_RIGHT;
}
rotationAnchor = anchor;
} else {
anchor = TextAnchor.CENTER_LEFT;
if ((lastTick != null) && (lastY == y) && (currentTickValue != cycleBound)) {
anchor = isInverted() ? TextAnchor.BOTTOM_LEFT : TextAnchor.TOP_LEFT;
result.remove(result.size() - 1);
result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
this.internalMarkerWhenTicksOverlap = true;
anchor = isInverted() ? TextAnchor.TOP_LEFT : TextAnchor.BOTTOM_LEFT;
}
rotationAnchor = anchor;
}
}
CycleBoundTick tick = new CycleBoundTick(this.boundMappedToLastCycle, new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle);
if (currentTickValue == cycleBound) {
this.internalMarkerCycleBoundTick = tick;
}
result.add(tick);
lastTick = tick;
lastY = y;
if (currentTickValue == cycleBound) {
this.internalMarkerCycleBoundTick = tick;
}
currentTickValue += unit;
if (cyclenow) {
currentTickValue = calculateLowestVisibleTickValue();
upperValue = cycleBound;
cycled = true;
this.boundMappedToLastCycle = false;
}
}
this.boundMappedToLastCycle = boundMapping;
return result;
}
use of org.jfree.ui.TextAnchor in project SIMVA-SoS by SESoS.
the class CyclicNumberAxis method refreshTicksHorizontal.
/**
* Builds a list of ticks for the axis. This method is called when the
* axis is at the top or bottom of the chart (so the axis is "horizontal").
*
* @param g2 the graphics device.
* @param dataArea the data area.
* @param edge the edge.
*
* @return A list of ticks.
*/
@Override
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
List result = new java.util.ArrayList();
Font tickLabelFont = getTickLabelFont();
g2.setFont(tickLabelFont);
if (isAutoTickUnitSelection()) {
selectAutoTickUnit(g2, dataArea, edge);
}
double unit = getTickUnit().getSize();
double cycleBound = getCycleBound();
double currentTickValue = Math.ceil(cycleBound / unit) * unit;
double upperValue = getRange().getUpperBound();
boolean cycled = false;
boolean boundMapping = this.boundMappedToLastCycle;
this.boundMappedToLastCycle = false;
CycleBoundTick lastTick = null;
float lastX = 0.0f;
if (upperValue == cycleBound) {
currentTickValue = calculateLowestVisibleTickValue();
cycled = true;
this.boundMappedToLastCycle = true;
}
while (currentTickValue <= upperValue) {
// Cycle when necessary
boolean cyclenow = false;
if ((currentTickValue + unit > upperValue) && !cycled) {
cyclenow = true;
}
double xx = valueToJava2D(currentTickValue, dataArea, edge);
String tickLabel;
NumberFormat formatter = getNumberFormatOverride();
if (formatter != null) {
tickLabel = formatter.format(currentTickValue);
} else {
tickLabel = getTickUnit().valueToString(currentTickValue);
}
float x = (float) xx;
TextAnchor anchor;
TextAnchor rotationAnchor;
double angle = 0.0;
if (isVerticalTickLabels()) {
if (edge == RectangleEdge.TOP) {
angle = Math.PI / 2.0;
} else {
angle = -Math.PI / 2.0;
}
anchor = TextAnchor.CENTER_RIGHT;
// If tick overlap when cycling, update last tick too
if ((lastTick != null) && (lastX == x) && (currentTickValue != cycleBound)) {
anchor = isInverted() ? TextAnchor.TOP_RIGHT : TextAnchor.BOTTOM_RIGHT;
result.remove(result.size() - 1);
result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
this.internalMarkerWhenTicksOverlap = true;
anchor = isInverted() ? TextAnchor.BOTTOM_RIGHT : TextAnchor.TOP_RIGHT;
}
rotationAnchor = anchor;
} else {
if (edge == RectangleEdge.TOP) {
anchor = TextAnchor.BOTTOM_CENTER;
if ((lastTick != null) && (lastX == x) && (currentTickValue != cycleBound)) {
anchor = isInverted() ? TextAnchor.BOTTOM_LEFT : TextAnchor.BOTTOM_RIGHT;
result.remove(result.size() - 1);
result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
this.internalMarkerWhenTicksOverlap = true;
anchor = isInverted() ? TextAnchor.BOTTOM_RIGHT : TextAnchor.BOTTOM_LEFT;
}
rotationAnchor = anchor;
} else {
anchor = TextAnchor.TOP_CENTER;
if ((lastTick != null) && (lastX == x) && (currentTickValue != cycleBound)) {
anchor = isInverted() ? TextAnchor.TOP_LEFT : TextAnchor.TOP_RIGHT;
result.remove(result.size() - 1);
result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
this.internalMarkerWhenTicksOverlap = true;
anchor = isInverted() ? TextAnchor.TOP_RIGHT : TextAnchor.TOP_LEFT;
}
rotationAnchor = anchor;
}
}
CycleBoundTick tick = new CycleBoundTick(this.boundMappedToLastCycle, new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle);
if (currentTickValue == cycleBound) {
this.internalMarkerCycleBoundTick = tick;
}
result.add(tick);
lastTick = tick;
lastX = x;
currentTickValue += unit;
if (cyclenow) {
currentTickValue = calculateLowestVisibleTickValue();
upperValue = cycleBound;
cycled = true;
this.boundMappedToLastCycle = true;
}
}
this.boundMappedToLastCycle = boundMapping;
return result;
}
use of org.jfree.ui.TextAnchor in project SIMVA-SoS by SESoS.
the class LogAxis method refreshTicksHorizontal.
/**
* Returns a list of ticks for an axis at the top or bottom of the chart.
*
* @param g2 the graphics device ({@code null} not permitted).
* @param dataArea the data area ({@code null} not permitted).
* @param edge the edge ({@code null} not permitted).
*
* @return A list of ticks.
*/
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
Range range = getRange();
List ticks = new ArrayList();
Font tickLabelFont = getTickLabelFont();
g2.setFont(tickLabelFont);
TextAnchor textAnchor;
if (edge == RectangleEdge.TOP) {
textAnchor = TextAnchor.BOTTOM_CENTER;
} else {
textAnchor = TextAnchor.TOP_CENTER;
}
if (isAutoTickUnitSelection()) {
selectAutoTickUnit(g2, dataArea, edge);
}
int minorTickCount = this.tickUnit.getMinorTickCount();
double unit = getTickUnit().getSize();
double index = Math.ceil(calculateLog(getRange().getLowerBound()) / unit);
double start = index * unit;
double end = calculateLog(getUpperBound());
double current = start;
boolean hasTicks = (this.tickUnit.getSize() > 0.0) && !Double.isInfinite(start);
while (hasTicks && current <= end) {
double v = calculateValueNoINF(current);
if (range.contains(v)) {
ticks.add(new LogTick(TickType.MAJOR, v, createTickLabel(v), textAnchor));
}
// add minor ticks (for gridlines)
double next = Math.pow(this.base, current + this.tickUnit.getSize());
for (int i = 1; i < minorTickCount; i++) {
double minorV = v + i * ((next - v) / minorTickCount);
if (range.contains(minorV)) {
ticks.add(new LogTick(TickType.MINOR, minorV, null, textAnchor));
}
}
current = current + this.tickUnit.getSize();
}
return ticks;
}
use of org.jfree.ui.TextAnchor in project SIMVA-SoS by SESoS.
the class CategoryTickTest method testHashCode.
/**
* Two objects that are equal are required to return the same hashCode.
*/
@Test
public void testHashCode() {
Comparable c1 = "C1";
TextBlock tb1 = new TextBlock();
tb1.addLine(new TextLine("Block 1"));
tb1.addLine(new TextLine("Block 2"));
TextBlockAnchor tba1 = TextBlockAnchor.CENTER;
TextAnchor ta1 = TextAnchor.CENTER;
CategoryTick t1 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
CategoryTick t2 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
assertTrue(t1.equals(t2));
int h1 = t1.hashCode();
int h2 = t2.hashCode();
assertEquals(h1, h2);
}
use of org.jfree.ui.TextAnchor in project SIMVA-SoS by SESoS.
the class PolarPlot method refreshAngleTicks.
/**
* Generates a list of tick values for the angular tick marks.
*
* @return A list of {@link NumberTick} instances.
*
* @since 1.0.10
*/
protected List refreshAngleTicks() {
List ticks = new ArrayList();
for (double currentTickVal = 0.0; currentTickVal < 360.0; currentTickVal += this.angleTickUnit.getSize()) {
TextAnchor ta = calculateTextAnchor(currentTickVal);
NumberTick tick = new NumberTick(new Double(currentTickVal), this.angleTickUnit.valueToString(currentTickVal), ta, TextAnchor.CENTER, 0.0);
ticks.add(tick);
}
return ticks;
}
Aggregations