org.jfree.ui.TextAnchor Java Examples
The following examples show how to use
org.jfree.ui.TextAnchor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CategoryTickTest.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * 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); }
Example #2
Source File: CategoryLabelPositions.java From opensim-gui with Apache License 2.0 | 6 votes |
/** * Creates a new instance where the category labels angled upwards by the * specified amount. * * @param angle the rotation angle (should be < Math.PI / 2.0). * * @return A category label position specification. */ public static CategoryLabelPositions createUpRotationLabelPositions( double angle) { return new CategoryLabelPositions( new CategoryLabelPosition( RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_LEFT, TextAnchor.BOTTOM_LEFT, -angle, CategoryLabelWidthType.RANGE, 0.50f ), // TOP new CategoryLabelPosition( RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -angle, CategoryLabelWidthType.RANGE, 0.50f ), // BOTTOM new CategoryLabelPosition( RectangleAnchor.RIGHT, TextBlockAnchor.BOTTOM_RIGHT, TextAnchor.BOTTOM_RIGHT, -angle, CategoryLabelWidthType.RANGE, 0.50f ), // LEFT new CategoryLabelPosition( RectangleAnchor.LEFT, TextBlockAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, -angle, CategoryLabelWidthType.RANGE, 0.50f ) // RIGHT ); }
Example #3
Source File: CategoryLabelPositions.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Creates a new instance where the category labels angled downwards by the * specified amount. * * @param angle the rotation angle (should be < Math.PI / 2.0). * * @return A category label position specification. */ public static CategoryLabelPositions createDownRotationLabelPositions( double angle) { return new CategoryLabelPositions( new CategoryLabelPosition( RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_RIGHT, TextAnchor.BOTTOM_RIGHT, angle, CategoryLabelWidthType.RANGE, 0.50f), // TOP new CategoryLabelPosition( RectangleAnchor.TOP, TextBlockAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, angle, CategoryLabelWidthType.RANGE, 0.50f), // BOTTOM new CategoryLabelPosition( RectangleAnchor.RIGHT, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, angle, CategoryLabelWidthType.RANGE, 0.50f), // LEFT new CategoryLabelPosition( RectangleAnchor.LEFT, TextBlockAnchor.BOTTOM_LEFT, TextAnchor.BOTTOM_LEFT, angle, CategoryLabelWidthType.RANGE, 0.50f) // RIGHT ); }
Example #4
Source File: CategoryLabelPositions.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Creates a new instance where the category labels angled downwards by the * specified amount. * * @param angle the rotation angle (should be < Math.PI / 2.0). * * @return A category label position specification. */ public static CategoryLabelPositions createDownRotationLabelPositions( double angle) { return new CategoryLabelPositions( new CategoryLabelPosition( RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_RIGHT, TextAnchor.BOTTOM_RIGHT, angle, CategoryLabelWidthType.RANGE, 0.50f), // TOP new CategoryLabelPosition( RectangleAnchor.TOP, TextBlockAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, angle, CategoryLabelWidthType.RANGE, 0.50f), // BOTTOM new CategoryLabelPosition( RectangleAnchor.RIGHT, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, angle, CategoryLabelWidthType.RANGE, 0.50f), // LEFT new CategoryLabelPosition( RectangleAnchor.LEFT, TextBlockAnchor.BOTTOM_LEFT, TextAnchor.BOTTOM_LEFT, angle, CategoryLabelWidthType.RANGE, 0.50f) // RIGHT ); }
Example #5
Source File: CategoryLabelPosition.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * Creates a new position record. The item label anchor is a point * relative to the data item (dot, bar or other visual item) on a chart. * The item label is aligned by aligning the text anchor with the item * label anchor. * * @param categoryAnchor the category anchor (<code>null</code> not * permitted). * @param labelAnchor the label anchor (<code>null</code> not permitted). * @param rotationAnchor the rotation anchor (<code>null</code> not * permitted). * @param angle the rotation angle (<code>null</code> not permitted). * @param widthType the width type (<code>null</code> not permitted). * @param widthRatio the maximum label width as a percentage (of the * category space or the range space). */ public CategoryLabelPosition(RectangleAnchor categoryAnchor, TextBlockAnchor labelAnchor, TextAnchor rotationAnchor, double angle, CategoryLabelWidthType widthType, float widthRatio) { ParamChecks.nullNotPermitted(categoryAnchor, "categoryAnchor"); ParamChecks.nullNotPermitted(labelAnchor, "labelAnchor"); ParamChecks.nullNotPermitted(rotationAnchor, "rotationAnchor"); ParamChecks.nullNotPermitted(widthType, "widthType"); this.categoryAnchor = categoryAnchor; this.labelAnchor = labelAnchor; this.rotationAnchor = rotationAnchor; this.angle = angle; this.widthType = widthType; this.widthRatio = widthRatio; }
Example #6
Source File: CategoryLabelPositions.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * Creates a new instance where the category labels angled upwards by the * specified amount. * * @param angle the rotation angle (should be < Math.PI / 2.0). * * @return A category label position specification. */ public static CategoryLabelPositions createUpRotationLabelPositions( double angle) { return new CategoryLabelPositions( new CategoryLabelPosition( RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_LEFT, TextAnchor.BOTTOM_LEFT, -angle, CategoryLabelWidthType.RANGE, 0.50f), // TOP new CategoryLabelPosition( RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -angle, CategoryLabelWidthType.RANGE, 0.50f), // BOTTOM new CategoryLabelPosition( RectangleAnchor.RIGHT, TextBlockAnchor.BOTTOM_RIGHT, TextAnchor.BOTTOM_RIGHT, -angle, CategoryLabelWidthType.RANGE, 0.50f), // LEFT new CategoryLabelPosition( RectangleAnchor.LEFT, TextBlockAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, -angle, CategoryLabelWidthType.RANGE, 0.50f) // RIGHT ); }
Example #7
Source File: CrosshairOverlay.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Returns the text anchor that is used to align a label to its anchor * point. * * @param anchor the anchor. * * @return The text alignment point. */ private TextAnchor textAlignPtForLabelAnchorH(RectangleAnchor anchor) { TextAnchor result = TextAnchor.CENTER; if (anchor.equals(RectangleAnchor.TOP_LEFT)) { result = TextAnchor.BOTTOM_LEFT; } else if (anchor.equals(RectangleAnchor.TOP)) { result = TextAnchor.BOTTOM_CENTER; } else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) { result = TextAnchor.BOTTOM_RIGHT; } else if (anchor.equals(RectangleAnchor.LEFT)) { result = TextAnchor.HALF_ASCENT_LEFT; } else if (anchor.equals(RectangleAnchor.RIGHT)) { result = TextAnchor.HALF_ASCENT_RIGHT; } else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) { result = TextAnchor.TOP_LEFT; } else if (anchor.equals(RectangleAnchor.BOTTOM)) { result = TextAnchor.TOP_CENTER; } else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) { result = TextAnchor.TOP_RIGHT; } return result; }
Example #8
Source File: mcchartgenerator.java From openstock with GNU General Public License v3.0 | 5 votes |
public java.util.List<org.jfree.chart.annotations.XYAnnotation> adicionarplotohlc_anotacaotext(double x, double y) { org.jfree.chart.plot.XYPlot plot = (org.jfree.chart.plot.XYPlot) mcg_chart.getXYPlot(); org.jfree.chart.annotations.XYTextAnnotation tatexto = new org.jfree.chart.annotations.XYTextAnnotation("New Annotation", x, y); tatexto.setTextAnchor(TextAnchor.CENTER_LEFT); plot.addAnnotation(tatexto); java.util.List<org.jfree.chart.annotations.XYAnnotation> subannotations = new java.util.ArrayList<>(); subannotations.add(tatexto); return subannotations; }
Example #9
Source File: AbstractRendererTest.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Test that setting the negative item label position for ALL series does * in fact work. */ @Test public void testSetNegativeItemLabelPosition() { BarRenderer r = new BarRenderer(); r.setNegativeItemLabelPosition(new ItemLabelPosition( ItemLabelAnchor.INSIDE1, TextAnchor.BASELINE_LEFT)); assertEquals(new ItemLabelPosition( ItemLabelAnchor.INSIDE1, TextAnchor.BASELINE_LEFT), r.getNegativeItemLabelPosition(0, 0)); }
Example #10
Source File: CategoryTickTest.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() { CategoryTick t1 = new CategoryTick("C1", new TextBlock(), TextBlockAnchor.CENTER, TextAnchor.CENTER, 1.5f); CategoryTick t2 = (CategoryTick) TestUtilities.serialised(t1); assertEquals(t1, t2); }
Example #11
Source File: AbstractRendererTest.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Test that setting the positive item label position for ALL series does * in fact work. */ @Test public void testSetPositiveItemLabelPosition() { BarRenderer r = new BarRenderer(); r.setPositiveItemLabelPosition(new ItemLabelPosition( ItemLabelAnchor.INSIDE1, TextAnchor.BASELINE_LEFT)); assertEquals(new ItemLabelPosition( ItemLabelAnchor.INSIDE1, TextAnchor.BASELINE_LEFT), r.getPositiveItemLabelPosition(0, 0)); }
Example #12
Source File: CategoryTick.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * Creates a new tick. * * @param category the category. * @param label the label. * @param labelAnchor the label anchor. * @param rotationAnchor the rotation anchor. * @param angle the rotation angle (in radians). */ public CategoryTick(Comparable category, TextBlock label, TextBlockAnchor labelAnchor, TextAnchor rotationAnchor, double angle) { super("", TextAnchor.CENTER, rotationAnchor, angle); this.category = category; this.label = label; this.labelAnchor = labelAnchor; }
Example #13
Source File: Marker.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Constructs a new marker. * * @param paint the paint ({@code null} not permitted). * @param stroke the stroke ({@code null} not permitted). * @param outlinePaint the outline paint ({@code null} permitted). * @param outlineStroke the outline stroke ({@code null} permitted). * @param alpha the alpha transparency (must be in the range 0.0f to * 1.0f). * * @throws IllegalArgumentException if {@code paint} or * {@code stroke} is {@code null}, or {@code alpha} is * not in the specified range. */ protected Marker(Paint paint, Stroke stroke, Paint outlinePaint, Stroke outlineStroke, float alpha) { ParamChecks.nullNotPermitted(paint, "paint"); ParamChecks.nullNotPermitted(stroke, "stroke"); if (alpha < 0.0f || alpha > 1.0f) { throw new IllegalArgumentException( "The 'alpha' value must be in the range 0.0f to 1.0f"); } this.paint = paint; this.stroke = stroke; this.outlinePaint = outlinePaint; this.outlineStroke = outlineStroke; this.alpha = alpha; this.labelFont = new Font("SansSerif", Font.PLAIN, 9); this.labelPaint = Color.black; this.labelBackgroundColor = new Color(100, 100, 100, 100); this.labelAnchor = RectangleAnchor.TOP_LEFT; this.labelOffset = new RectangleInsets(3.0, 3.0, 3.0, 3.0); this.labelOffsetType = LengthAdjustmentType.CONTRACT; this.labelTextAnchor = TextAnchor.CENTER; this.listenerList = new EventListenerList(); }
Example #14
Source File: Axis.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
protected TextAnchor labelAnchorH(AxisLabelLocation location) { if (location.equals(AxisLabelLocation.HIGH_END)) { return TextAnchor.CENTER_RIGHT; } if (location.equals(AxisLabelLocation.MIDDLE)) { return TextAnchor.CENTER; } if (location.equals(AxisLabelLocation.LOW_END)) { return TextAnchor.CENTER_LEFT; } throw new RuntimeException("Unexpected AxisLabelLocation: " + location); }
Example #15
Source File: CategoryTickTest.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() { CategoryTick t1 = new CategoryTick("C1", new TextBlock(), TextBlockAnchor.CENTER, TextAnchor.CENTER, 1.5f); CategoryTick t2 = (CategoryTick) TestUtilities.serialised(t1); assertEquals(t1, t2); }
Example #16
Source File: CategoryLabelPosition.java From opensim-gui with Apache License 2.0 | 5 votes |
/** * Creates a new category label position record. * * @param categoryAnchor the category anchor (<code>null</code> not * permitted). * @param labelAnchor the label anchor (<code>null</code> not permitted). * @param widthType the width type (<code>null</code> not permitted). * @param widthRatio the maximum label width as a percentage (of the * category space or the range space). */ public CategoryLabelPosition(RectangleAnchor categoryAnchor, TextBlockAnchor labelAnchor, CategoryLabelWidthType widthType, float widthRatio) { // argument checking delegated... this( categoryAnchor, labelAnchor, TextAnchor.CENTER, 0.0, widthType, widthRatio ); }
Example #17
Source File: Marker.java From opensim-gui with Apache License 2.0 | 5 votes |
/** * Constructs a new marker. * * @param paint the paint (<code>null</code> not permitted). * @param stroke the stroke (<code>null</code> not permitted). * @param outlinePaint the outline paint (<code>null</code> permitted). * @param outlineStroke the outline stroke (<code>null</code> permitted). * @param alpha the alpha transparency (must be in the range 0.0f to * 1.0f). * * @throws IllegalArgumentException if <code>paint</code> or * <code>stroke</code> is <code>null</code>, or <code>alpha</code> is * not in the specified range. */ protected Marker(Paint paint, Stroke stroke, Paint outlinePaint, Stroke outlineStroke, float alpha) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } if (alpha < 0.0f || alpha > 1.0f) throw new IllegalArgumentException( "The 'alpha' value must be in the range 0.0f to 1.0f"); this.paint = paint; this.stroke = stroke; this.outlinePaint = outlinePaint; this.outlineStroke = outlineStroke; this.alpha = alpha; this.labelFont = new Font("SansSerif", Font.PLAIN, 9); this.labelPaint = Color.black; this.labelAnchor = RectangleAnchor.TOP_LEFT; this.labelOffset = new RectangleInsets(3.0, 3.0, 3.0, 3.0); this.labelOffsetType = LengthAdjustmentType.CONTRACT; this.labelTextAnchor = TextAnchor.CENTER; this.listenerList = new EventListenerList(); }
Example #18
Source File: AttrStringUtils.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
private static boolean isHorizontalCenter(TextAnchor anchor) { return anchor.equals(TextAnchor.TOP_CENTER) || anchor.equals(TextAnchor.CENTER) || anchor.equals(TextAnchor.HALF_ASCENT_CENTER) || anchor.equals(TextAnchor.BASELINE_CENTER) || anchor.equals(TextAnchor.BOTTOM_CENTER); }
Example #19
Source File: CategoryTickTest.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { CategoryTick t1 = new CategoryTick("C1", new TextBlock(), TextBlockAnchor.CENTER, TextAnchor.CENTER, 1.5f); CategoryTick t2 = (CategoryTick) t1.clone(); assertTrue(t1 != t2); assertTrue(t1.getClass() == t2.getClass()); assertTrue(t1.equals(t2)); }
Example #20
Source File: CrosshairOverlay.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * Returns the text anchor that is used to align a label to its anchor * point. * * @param anchor the anchor. * * @return The text alignment point. */ private TextAnchor textAlignPtForLabelAnchorH(RectangleAnchor anchor) { TextAnchor result = TextAnchor.CENTER; if (anchor.equals(RectangleAnchor.TOP_LEFT)) { result = TextAnchor.BOTTOM_LEFT; } else if (anchor.equals(RectangleAnchor.TOP)) { result = TextAnchor.BOTTOM_CENTER; } else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) { result = TextAnchor.BOTTOM_RIGHT; } else if (anchor.equals(RectangleAnchor.LEFT)) { result = TextAnchor.HALF_ASCENT_LEFT; } else if (anchor.equals(RectangleAnchor.RIGHT)) { result = TextAnchor.HALF_ASCENT_RIGHT; } else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) { result = TextAnchor.TOP_LEFT; } else if (anchor.equals(RectangleAnchor.BOTTOM)) { result = TextAnchor.TOP_CENTER; } else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) { result = TextAnchor.TOP_RIGHT; } return result; }
Example #21
Source File: StackedXYBarRenderer.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Creates a new renderer. * * @param margin the percentual amount of the bars that are cut away. */ public StackedXYBarRenderer(double margin) { super(margin); this.renderAsPercentages = false; // set the default item label positions, which will only be used if // the user requests visible item labels... ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER); setBasePositiveItemLabelPosition(p); setBaseNegativeItemLabelPosition(p); setPositiveItemLabelPositionFallback(null); setNegativeItemLabelPositionFallback(null); }
Example #22
Source File: CategoryTickTest.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() { CategoryTick t1 = new CategoryTick("C1", new TextBlock(), TextBlockAnchor.CENTER, TextAnchor.CENTER, 1.5f); CategoryTick t2 = (CategoryTick) TestUtilities.serialised(t1); assertEquals(t1, t2); }
Example #23
Source File: Axis.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
protected TextAnchor labelAnchorH(AxisLabelLocation location) { if (location.equals(AxisLabelLocation.HIGH_END)) { return TextAnchor.CENTER_RIGHT; } if (location.equals(AxisLabelLocation.MIDDLE)) { return TextAnchor.CENTER; } if (location.equals(AxisLabelLocation.LOW_END)) { return TextAnchor.CENTER_LEFT; } throw new RuntimeException("Unexpected AxisLabelLocation: " + location); }
Example #24
Source File: Tick.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Creates a new tick. * * @param text the formatted version of the tick value. * @param textAnchor the text anchor (<code>null</code> not permitted). * @param rotationAnchor the rotation anchor (<code>null</code> not * permitted). * @param angle the angle. */ public Tick(String text, TextAnchor textAnchor, TextAnchor rotationAnchor, double angle) { ParamChecks.nullNotPermitted(textAnchor, "textAnchor"); ParamChecks.nullNotPermitted(rotationAnchor, "rotationAnchor"); this.text = text; this.textAnchor = textAnchor; this.rotationAnchor = rotationAnchor; this.angle = angle; }
Example #25
Source File: TextAnnotationTest.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Some tests to ensure that change events are generated as expected. */ @Test public void testChangeEvents() { TextAnnotation a = new CategoryTextAnnotation("Test", "A", 1.0); a.addChangeListener(this); this.lastEvent = null; a.setText("B"); assertNotNull(this.lastEvent); this.lastEvent = null; a.setText("B"); assertNotNull(this.lastEvent); this.lastEvent = null; a.setFont(new Font("SansSerif", Font.PLAIN, 12)); assertNotNull(this.lastEvent); this.lastEvent = null; a.setPaint(Color.BLUE); assertNotNull(this.lastEvent); this.lastEvent = null; a.setTextAnchor(TextAnchor.CENTER_LEFT); assertNotNull(this.lastEvent); this.lastEvent = null; a.setRotationAnchor(TextAnchor.CENTER_LEFT); assertNotNull(this.lastEvent); this.lastEvent = null; a.setRotationAngle(123.4); assertNotNull(this.lastEvent); }
Example #26
Source File: PolarPlot.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example #27
Source File: AbstractRendererTest.java From openstock with GNU General Public License v3.0 | 5 votes |
@Test public void testEquals_ObjectList4() { BarRenderer r1 = new BarRenderer(); r1.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); BarRenderer r2 = new BarRenderer(); r2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); assertEquals(r1, r2); r2.setSeriesNegativeItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.INSIDE1, TextAnchor.CENTER)); assertNotEquals(r1, r2); }
Example #28
Source File: AttrStringUtils.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * A utility method that calculates the rotation anchor offsets for a * string. These offsets are relative to the text starting coordinate * (BASELINE_LEFT). * * @param g2 the graphics device. * @param text the text. * @param anchor the anchor point. * * @return The offsets. */ private static float[] deriveRotationAnchorOffsets(Graphics2D g2, AttributedString text, TextAnchor anchor) { float[] result = new float[2]; TextLayout layout = new TextLayout(text.getIterator(), g2.getFontRenderContext()); Rectangle2D bounds = layout.getBounds(); float ascent = layout.getAscent(); float halfAscent = ascent / 2.0f; float descent = layout.getDescent(); float leading = layout.getLeading(); float xAdj = 0.0f; float yAdj = 0.0f; if (isHorizontalLeft(anchor)) { xAdj = 0.0f; } else if (isHorizontalCenter(anchor)) { xAdj = (float) bounds.getWidth() / 2.0f; } else if (isHorizontalRight(anchor)) { xAdj = (float) bounds.getWidth(); } if (isTop(anchor)) { yAdj = descent + leading - (float) bounds.getHeight(); } else if (isHalfHeight(anchor)) { yAdj = descent + leading - (float) (bounds.getHeight() / 2.0); } else if (isHalfAscent(anchor)) { yAdj = -halfAscent; } else if (isBaseline(anchor)) { yAdj = 0.0f; } else if (isBottom(anchor)) { yAdj = descent + leading; } result[0] = xAdj; result[1] = yAdj; return result; }
Example #29
Source File: DateTickTest.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { Date d1 = new Date(0L); Date d2 = new Date(1L); String l1 = "Label 1"; String l2 = "Label 2"; TextAnchor ta1 = TextAnchor.CENTER; TextAnchor ta2 = TextAnchor.BASELINE_LEFT; DateTick t1 = new DateTick(d1, l1, ta1, ta1, Math.PI / 2.0); DateTick t2 = new DateTick(d1, l1, ta1, ta1, Math.PI / 2.0); assertTrue(t1.equals(t2)); t1 = new DateTick(d2, l1, ta1, ta1, Math.PI / 2.0); assertFalse(t1.equals(t2)); t2 = new DateTick(d2, l1, ta1, ta1, Math.PI / 2.0); assertTrue(t1.equals(t2)); t1 = new DateTick(d1, l2, ta1, ta1, Math.PI / 2.0); assertFalse(t1.equals(t2)); t2 = new DateTick(d1, l2, ta1, ta1, Math.PI / 2.0); assertTrue(t1.equals(t2)); t1 = new DateTick(d1, l1, ta2, ta1, Math.PI / 2.0); assertFalse(t1.equals(t2)); t2 = new DateTick(d1, l1, ta2, ta1, Math.PI / 2.0); assertTrue(t1.equals(t2)); t1 = new DateTick(d1, l1, ta1, ta2, Math.PI / 2.0); assertFalse(t1.equals(t2)); t2 = new DateTick(d1, l1, ta1, ta2, Math.PI / 2.0); assertTrue(t1.equals(t2)); t1 = new DateTick(d1, l1, ta1, ta1, Math.PI / 3.0); assertFalse(t1.equals(t2)); t2 = new DateTick(d1, l1, ta1, ta1, Math.PI / 3.0); assertTrue(t1.equals(t2)); t1 = new DateTick(TickType.MINOR, d1, l1, ta1, ta1, Math.PI); t2 = new DateTick(TickType.MAJOR, d1, l1, ta1, ta1, Math.PI); assertFalse(t1.equals(t2)); t2 = new DateTick(TickType.MINOR, d1, l1, ta1, ta1, Math.PI); assertTrue(t1.equals(t2)); }
Example #30
Source File: ItemLabelPosition.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Creates a new position record with default settings. */ public ItemLabelPosition() { this(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, 0.0); }