Java Code Examples for org.jfree.ui.RectangleAnchor#BOTTOM_LEFT

The following examples show how to use org.jfree.ui.RectangleAnchor#BOTTOM_LEFT . 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: Crosshair.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new crosshair value with the specified value and line style.
 *
 * @param value  the value.
 * @param paint  the line paint (<code>null</code> not permitted).
 * @param stroke  the line stroke (<code>null</code> not permitted).
 */
public Crosshair(double value, Paint paint, Stroke stroke) {
    ParamChecks.nullNotPermitted(paint, "paint");
    ParamChecks.nullNotPermitted(stroke, "stroke");
    this.visible = true;
    this.value = value;
    this.paint = paint;
    this.stroke = stroke;
    this.labelVisible = false;
    this.labelGenerator = new StandardCrosshairLabelGenerator();
    this.labelAnchor = RectangleAnchor.BOTTOM_LEFT;
    this.labelXOffset = 3.0;
    this.labelYOffset = 3.0;
    this.labelFont = new Font("Tahoma", Font.PLAIN, 12);
    this.labelPaint = Color.black;
    this.labelBackgroundPaint = new Color(0, 0, 255, 63);
    this.labelOutlineVisible = true;
    this.labelOutlinePaint = Color.black;
    this.labelOutlineStroke = new BasicStroke(0.5f);
    this.pcs = new PropertyChangeSupport(this);
}
 
Example 2
Source File: Crosshair.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new crosshair value with the specified value and line style.
 *
 * @param value  the value.
 * @param paint  the line paint (<code>null</code> not permitted).
 * @param stroke  the line stroke (<code>null</code> not permitted).
 */
public Crosshair(double value, Paint paint, Stroke stroke) {
    ParamChecks.nullNotPermitted(paint, "paint");
    ParamChecks.nullNotPermitted(stroke, "stroke");
    this.visible = true;
    this.value = value;
    this.paint = paint;
    this.stroke = stroke;
    this.labelVisible = false;
    this.labelGenerator = new StandardCrosshairLabelGenerator();
    this.labelAnchor = RectangleAnchor.BOTTOM_LEFT;
    this.labelXOffset = 3.0;
    this.labelYOffset = 3.0;
    this.labelFont = new Font("Tahoma", Font.PLAIN, 12);
    this.labelPaint = Color.black;
    this.labelBackgroundPaint = new Color(0, 0, 255, 63);
    this.labelOutlineVisible = true;
    this.labelOutlinePaint = Color.black;
    this.labelOutlineStroke = new BasicStroke(0.5f);
    this.pcs = new PropertyChangeSupport(this);
}
 
Example 3
Source File: Crosshair.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new crosshair value with the specified value and line style.
 *
 * @param value  the value.
 * @param paint  the line paint (<code>null</code> not permitted).
 * @param stroke  the line stroke (<code>null</code> not permitted).
 */
public Crosshair(double value, Paint paint, Stroke stroke) {
    ParamChecks.nullNotPermitted(paint, "paint");
    ParamChecks.nullNotPermitted(stroke, "stroke");
    this.visible = true;
    this.value = value;
    this.paint = paint;
    this.stroke = stroke;
    this.labelVisible = false;
    this.labelGenerator = new StandardCrosshairLabelGenerator();
    this.labelAnchor = RectangleAnchor.BOTTOM_LEFT;
    this.labelXOffset = 3.0;
    this.labelYOffset = 3.0;
    this.labelFont = new Font("Tahoma", Font.PLAIN, 12);
    this.labelPaint = Color.black;
    this.labelBackgroundPaint = new Color(0, 0, 255, 63);
    this.labelOutlineVisible = true;
    this.labelOutlinePaint = Color.black;
    this.labelOutlineStroke = new BasicStroke(0.5f);
    this.pcs = new PropertyChangeSupport(this);
}
 
Example 4
Source File: CrosshairOverlay.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
private RectangleAnchor flipAnchorH(RectangleAnchor anchor) {
    RectangleAnchor result = anchor;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = RectangleAnchor.TOP_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = RectangleAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = RectangleAnchor.RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = RectangleAnchor.LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = RectangleAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = RectangleAnchor.BOTTOM_LEFT;
    }
    return result;
}
 
Example 5
Source File: Crosshair.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new crosshair value with the specified value and line style.
 *
 * @param value  the value.
 * @param paint  the line paint (<code>null</code> not permitted).
 * @param stroke  the line stroke (<code>null</code> not permitted).
 */
public Crosshair(double value, Paint paint, Stroke stroke) {
    ParamChecks.nullNotPermitted(paint, "paint");
    ParamChecks.nullNotPermitted(stroke, "stroke");
    this.visible = true;
    this.value = value;
    this.paint = paint;
    this.stroke = stroke;
    this.labelVisible = false;
    this.labelGenerator = new StandardCrosshairLabelGenerator();
    this.labelAnchor = RectangleAnchor.BOTTOM_LEFT;
    this.labelXOffset = 3.0;
    this.labelYOffset = 3.0;
    this.labelFont = new Font("Tahoma", Font.PLAIN, 12);
    this.labelPaint = Color.black;
    this.labelBackgroundPaint = new Color(0, 0, 255, 63);
    this.labelOutlineVisible = true;
    this.labelOutlinePaint = Color.black;
    this.labelOutlineStroke = new BasicStroke(0.5f);
    this.pcs = new PropertyChangeSupport(this);
}
 
Example 6
Source File: CrosshairOverlay.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
private RectangleAnchor flipAnchorV(RectangleAnchor anchor) {
    RectangleAnchor result = anchor;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = RectangleAnchor.BOTTOM_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = RectangleAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.TOP)) {
        result = RectangleAnchor.BOTTOM;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM)) {
        result = RectangleAnchor.TOP;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = RectangleAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = RectangleAnchor.TOP_RIGHT;
    }
    return result;
}
 
Example 7
Source File: CrosshairOverlay.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
private RectangleAnchor flipAnchorV(RectangleAnchor anchor) {
    RectangleAnchor result = anchor;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = RectangleAnchor.BOTTOM_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = RectangleAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.TOP)) {
        result = RectangleAnchor.BOTTOM;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM)) {
        result = RectangleAnchor.TOP;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = RectangleAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = RectangleAnchor.TOP_RIGHT;
    }
    return result;
}
 
Example 8
Source File: Crosshair.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new crosshair value with the specified value and line style.
 *
 * @param value  the value.
 * @param paint  the line paint (<code>null</code> not permitted).
 * @param stroke  the line stroke (<code>null</code> not permitted).
 */
public Crosshair(double value, Paint paint, Stroke stroke) {
    ParamChecks.nullNotPermitted(paint, "paint");
    ParamChecks.nullNotPermitted(stroke, "stroke");
    this.visible = true;
    this.value = value;
    this.paint = paint;
    this.stroke = stroke;
    this.labelVisible = false;
    this.labelGenerator = new StandardCrosshairLabelGenerator();
    this.labelAnchor = RectangleAnchor.BOTTOM_LEFT;
    this.labelXOffset = 3.0;
    this.labelYOffset = 3.0;
    this.labelFont = new Font("Tahoma", Font.PLAIN, 12);
    this.labelPaint = Color.black;
    this.labelBackgroundPaint = new Color(0, 0, 255, 63);
    this.labelOutlineVisible = true;
    this.labelOutlinePaint = Color.black;
    this.labelOutlineStroke = new BasicStroke(0.5f);
    this.pcs = new PropertyChangeSupport(this);
}
 
Example 9
Source File: CrosshairOverlay.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
private RectangleAnchor flipAnchorV(RectangleAnchor anchor) {
    RectangleAnchor result = anchor;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = RectangleAnchor.BOTTOM_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = RectangleAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.TOP)) {
        result = RectangleAnchor.BOTTOM;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM)) {
        result = RectangleAnchor.TOP;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = RectangleAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = RectangleAnchor.TOP_RIGHT;
    }
    return result;
}
 
Example 10
Source File: CrosshairOverlay.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
private RectangleAnchor flipAnchorH(RectangleAnchor anchor) {
    RectangleAnchor result = anchor;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = RectangleAnchor.TOP_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = RectangleAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = RectangleAnchor.RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = RectangleAnchor.LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = RectangleAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = RectangleAnchor.BOTTOM_LEFT;
    }
    return result;
}
 
Example 11
Source File: CrosshairOverlay.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
private RectangleAnchor flipAnchorH(RectangleAnchor anchor) {
    RectangleAnchor result = anchor;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = RectangleAnchor.TOP_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = RectangleAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = RectangleAnchor.RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = RectangleAnchor.LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = RectangleAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = RectangleAnchor.BOTTOM_LEFT;
    }
    return result;
}
 
Example 12
Source File: Crosshair.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new crosshair value with the specified value and line style.
 *
 * @param value  the value.
 * @param paint  the line paint (<code>null</code> not permitted).
 * @param stroke  the line stroke (<code>null</code> not permitted).
 */
public Crosshair(double value, Paint paint, Stroke stroke) {
    ParamChecks.nullNotPermitted(paint, "paint");
    ParamChecks.nullNotPermitted(stroke, "stroke");
    this.visible = true;
    this.value = value;
    this.paint = paint;
    this.stroke = stroke;
    this.labelVisible = false;
    this.labelGenerator = new StandardCrosshairLabelGenerator();
    this.labelAnchor = RectangleAnchor.BOTTOM_LEFT;
    this.labelXOffset = 3.0;
    this.labelYOffset = 3.0;
    this.labelFont = new Font("Tahoma", Font.PLAIN, 12);
    this.labelPaint = Color.black;
    this.labelBackgroundPaint = new Color(0, 0, 255, 63);
    this.labelOutlineVisible = true;
    this.labelOutlinePaint = Color.black;
    this.labelOutlineStroke = new BasicStroke(0.5f);
    this.pcs = new PropertyChangeSupport(this);
}
 
Example 13
Source File: CategoricalChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public RectangleAnchor asRectangleAnchor() {
  switch ( this ) {
    case RIGHT:
      return RectangleAnchor.RIGHT;
    case TOP_RIGHT:
      return RectangleAnchor.TOP_RIGHT;
    case TOP:
      return RectangleAnchor.TOP;
    case TOP_LEFT:
      return RectangleAnchor.TOP_LEFT;
    case LEFT:
      return RectangleAnchor.LEFT;
    case BOTTOM_LEFT:
      return RectangleAnchor.BOTTOM_LEFT;
    case BOTTOM:
      return RectangleAnchor.BOTTOM;
    case BOTTOM_RIGHT:
      return RectangleAnchor.BOTTOM_RIGHT;
    default:
      return null;
  }
}
 
Example 14
Source File: CrosshairOverlay.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
private RectangleAnchor flipAnchorH(RectangleAnchor anchor) {
    RectangleAnchor result = anchor;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = RectangleAnchor.TOP_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = RectangleAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = RectangleAnchor.RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = RectangleAnchor.LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = RectangleAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = RectangleAnchor.BOTTOM_LEFT;
    }
    return result;
}
 
Example 15
Source File: CategoryLabelPositionTest.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Check that the equals() method can distinguish all fields.
 */
@Test
public void testEquals() {
    CategoryLabelPosition p1 = new CategoryLabelPosition(
            RectangleAnchor.BOTTOM_LEFT, TextBlockAnchor.CENTER_RIGHT,
            TextAnchor.BASELINE_LEFT, Math.PI / 4.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    CategoryLabelPosition p2 = new CategoryLabelPosition(
            RectangleAnchor.BOTTOM_LEFT, TextBlockAnchor.CENTER_RIGHT,
            TextAnchor.BASELINE_LEFT, Math.PI / 4.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));

    p1 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER_RIGHT, TextAnchor.BASELINE_LEFT,
            Math.PI / 4.0, CategoryLabelWidthType.RANGE, 0.44f);
    assertFalse(p1.equals(p2));
    p2 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER_RIGHT, TextAnchor.BASELINE_LEFT,
            Math.PI / 4.0, CategoryLabelWidthType.RANGE, 0.44f);
    assertTrue(p1.equals(p2));

    p1 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.BASELINE_LEFT, Math.PI / 4.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertFalse(p1.equals(p2));
    p2 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.BASELINE_LEFT, Math.PI / 4.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertTrue(p1.equals(p2));

    p1 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 4.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertFalse(p1.equals(p2));
    p2 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 4.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertTrue(p1.equals(p2));

    p1 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 6.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertFalse(p1.equals(p2));
    p2 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 6.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertTrue(p1.equals(p2));

    p1 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 6.0,
            CategoryLabelWidthType.CATEGORY, 0.44f);
    assertFalse(p1.equals(p2));
    p2 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 6.0,
            CategoryLabelWidthType.CATEGORY, 0.44f);
    assertTrue(p1.equals(p2));

    p1 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER,  Math.PI / 6.0,
            CategoryLabelWidthType.CATEGORY, 0.55f);
    assertFalse(p1.equals(p2));
    p2 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 6.0,
            CategoryLabelWidthType.CATEGORY, 0.55f);
    assertTrue(p1.equals(p2));
}
 
Example 16
Source File: CrosshairOverlay.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Calculates the anchor point for a label.
 *
 * @param line  the line for the crosshair.
 * @param anchor  the anchor point.
 * @param deltaX  the x-offset.
 * @param deltaY  the y-offset.
 *
 * @return The anchor point.
 */
private Point2D calculateLabelPoint(Line2D line, RectangleAnchor anchor,
        double deltaX, double deltaY) {
    double x, y;
    boolean left = (anchor == RectangleAnchor.BOTTOM_LEFT 
            || anchor == RectangleAnchor.LEFT 
            || anchor == RectangleAnchor.TOP_LEFT);
    boolean right = (anchor == RectangleAnchor.BOTTOM_RIGHT 
            || anchor == RectangleAnchor.RIGHT 
            || anchor == RectangleAnchor.TOP_RIGHT);
    boolean top = (anchor == RectangleAnchor.TOP_LEFT 
            || anchor == RectangleAnchor.TOP 
            || anchor == RectangleAnchor.TOP_RIGHT);
    boolean bottom = (anchor == RectangleAnchor.BOTTOM_LEFT
            || anchor == RectangleAnchor.BOTTOM
            || anchor == RectangleAnchor.BOTTOM_RIGHT);
    Rectangle rect = line.getBounds();
    
    // we expect the line to be vertical or horizontal
    if (line.getX1() == line.getX2()) {  // vertical
        x = line.getX1();
        y = (line.getY1() + line.getY2()) / 2.0;
        if (left) {
            x = x - deltaX;
        }
        if (right) {
            x = x + deltaX;
        }
        if (top) {
            y = Math.min(line.getY1(), line.getY2()) + deltaY;
        }
        if (bottom) {
            y = Math.max(line.getY1(), line.getY2()) - deltaY;
        }
    }
    else {  // horizontal
        x = (line.getX1() + line.getX2()) / 2.0;
        y = line.getY1();
        if (left) {
            x = Math.min(line.getX1(), line.getX2()) + deltaX;
        }
        if (right) {
            x = Math.max(line.getX1(), line.getX2()) - deltaX;
        }
        if (top) {
            y = y - deltaY;
        }
        if (bottom) {
            y = y + deltaY;
        }
    }
    return new Point2D.Double(x, y);
}
 
Example 17
Source File: CrosshairOverlay.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Calculates the anchor point for a label.
 *
 * @param line  the line for the crosshair.
 * @param anchor  the anchor point.
 * @param deltaX  the x-offset.
 * @param deltaY  the y-offset.
 *
 * @return The anchor point.
 */
private Point2D calculateLabelPoint(Line2D line, RectangleAnchor anchor,
        double deltaX, double deltaY) {
    double x, y;
    boolean left = (anchor == RectangleAnchor.BOTTOM_LEFT 
            || anchor == RectangleAnchor.LEFT 
            || anchor == RectangleAnchor.TOP_LEFT);
    boolean right = (anchor == RectangleAnchor.BOTTOM_RIGHT 
            || anchor == RectangleAnchor.RIGHT 
            || anchor == RectangleAnchor.TOP_RIGHT);
    boolean top = (anchor == RectangleAnchor.TOP_LEFT 
            || anchor == RectangleAnchor.TOP 
            || anchor == RectangleAnchor.TOP_RIGHT);
    boolean bottom = (anchor == RectangleAnchor.BOTTOM_LEFT
            || anchor == RectangleAnchor.BOTTOM
            || anchor == RectangleAnchor.BOTTOM_RIGHT);
    Rectangle rect = line.getBounds();
    
    // we expect the line to be vertical or horizontal
    if (line.getX1() == line.getX2()) {  // vertical
        x = line.getX1();
        y = (line.getY1() + line.getY2()) / 2.0;
        if (left) {
            x = x - deltaX;
        }
        if (right) {
            x = x + deltaX;
        }
        if (top) {
            y = Math.min(line.getY1(), line.getY2()) + deltaY;
        }
        if (bottom) {
            y = Math.max(line.getY1(), line.getY2()) - deltaY;
        }
    }
    else {  // horizontal
        x = (line.getX1() + line.getX2()) / 2.0;
        y = line.getY1();
        if (left) {
            x = Math.min(line.getX1(), line.getX2()) + deltaX;
        }
        if (right) {
            x = Math.max(line.getX1(), line.getX2()) - deltaX;
        }
        if (top) {
            y = y - deltaY;
        }
        if (bottom) {
            y = y + deltaY;
        }
    }
    return new Point2D.Double(x, y);
}
 
Example 18
Source File: CategoryLabelPositionTest.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Check that the equals() method can distinguish all fields.
 */
@Test
public void testEquals() {
    CategoryLabelPosition p1 = new CategoryLabelPosition(
            RectangleAnchor.BOTTOM_LEFT, TextBlockAnchor.CENTER_RIGHT,
            TextAnchor.BASELINE_LEFT, Math.PI / 4.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    CategoryLabelPosition p2 = new CategoryLabelPosition(
            RectangleAnchor.BOTTOM_LEFT, TextBlockAnchor.CENTER_RIGHT,
            TextAnchor.BASELINE_LEFT, Math.PI / 4.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));

    p1 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER_RIGHT, TextAnchor.BASELINE_LEFT,
            Math.PI / 4.0, CategoryLabelWidthType.RANGE, 0.44f);
    assertFalse(p1.equals(p2));
    p2 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER_RIGHT, TextAnchor.BASELINE_LEFT,
            Math.PI / 4.0, CategoryLabelWidthType.RANGE, 0.44f);
    assertTrue(p1.equals(p2));

    p1 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.BASELINE_LEFT, Math.PI / 4.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertFalse(p1.equals(p2));
    p2 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.BASELINE_LEFT, Math.PI / 4.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertTrue(p1.equals(p2));

    p1 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 4.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertFalse(p1.equals(p2));
    p2 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 4.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertTrue(p1.equals(p2));

    p1 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 6.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertFalse(p1.equals(p2));
    p2 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 6.0,
            CategoryLabelWidthType.RANGE, 0.44f);
    assertTrue(p1.equals(p2));

    p1 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 6.0,
            CategoryLabelWidthType.CATEGORY, 0.44f);
    assertFalse(p1.equals(p2));
    p2 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 6.0,
            CategoryLabelWidthType.CATEGORY, 0.44f);
    assertTrue(p1.equals(p2));

    p1 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER,  Math.PI / 6.0,
            CategoryLabelWidthType.CATEGORY, 0.55f);
    assertFalse(p1.equals(p2));
    p2 = new CategoryLabelPosition(RectangleAnchor.TOP,
            TextBlockAnchor.CENTER, TextAnchor.CENTER, Math.PI / 6.0,
            CategoryLabelWidthType.CATEGORY, 0.55f);
    assertTrue(p1.equals(p2));
}
 
Example 19
Source File: CrosshairOverlay.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates the anchor point for a label.
 *
 * @param line  the line for the crosshair.
 * @param anchor  the anchor point.
 * @param deltaX  the x-offset.
 * @param deltaY  the y-offset.
 *
 * @return The anchor point.
 */
private Point2D calculateLabelPoint(Line2D line, RectangleAnchor anchor,
        double deltaX, double deltaY) {
    double x, y;
    boolean left = (anchor == RectangleAnchor.BOTTOM_LEFT 
            || anchor == RectangleAnchor.LEFT 
            || anchor == RectangleAnchor.TOP_LEFT);
    boolean right = (anchor == RectangleAnchor.BOTTOM_RIGHT 
            || anchor == RectangleAnchor.RIGHT 
            || anchor == RectangleAnchor.TOP_RIGHT);
    boolean top = (anchor == RectangleAnchor.TOP_LEFT 
            || anchor == RectangleAnchor.TOP 
            || anchor == RectangleAnchor.TOP_RIGHT);
    boolean bottom = (anchor == RectangleAnchor.BOTTOM_LEFT
            || anchor == RectangleAnchor.BOTTOM
            || anchor == RectangleAnchor.BOTTOM_RIGHT);
    Rectangle rect = line.getBounds();
    
    // we expect the line to be vertical or horizontal
    if (line.getX1() == line.getX2()) {  // vertical
        x = line.getX1();
        y = (line.getY1() + line.getY2()) / 2.0;
        if (left) {
            x = x - deltaX;
        }
        if (right) {
            x = x + deltaX;
        }
        if (top) {
            y = Math.min(line.getY1(), line.getY2()) + deltaY;
        }
        if (bottom) {
            y = Math.max(line.getY1(), line.getY2()) - deltaY;
        }
    }
    else {  // horizontal
        x = (line.getX1() + line.getX2()) / 2.0;
        y = line.getY1();
        if (left) {
            x = Math.min(line.getX1(), line.getX2()) + deltaX;
        }
        if (right) {
            x = Math.max(line.getX1(), line.getX2()) - deltaX;
        }
        if (top) {
            y = y - deltaY;
        }
        if (bottom) {
            y = y + deltaY;
        }
    }
    return new Point2D.Double(x, y);
}
 
Example 20
Source File: CrosshairOverlay.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Calculates the anchor point for a label.
 *
 * @param line  the line for the crosshair.
 * @param anchor  the anchor point.
 * @param deltaX  the x-offset.
 * @param deltaY  the y-offset.
 *
 * @return The anchor point.
 */
private Point2D calculateLabelPoint(Line2D line, RectangleAnchor anchor,
        double deltaX, double deltaY) {
    double x, y;
    boolean left = (anchor == RectangleAnchor.BOTTOM_LEFT 
            || anchor == RectangleAnchor.LEFT 
            || anchor == RectangleAnchor.TOP_LEFT);
    boolean right = (anchor == RectangleAnchor.BOTTOM_RIGHT 
            || anchor == RectangleAnchor.RIGHT 
            || anchor == RectangleAnchor.TOP_RIGHT);
    boolean top = (anchor == RectangleAnchor.TOP_LEFT 
            || anchor == RectangleAnchor.TOP 
            || anchor == RectangleAnchor.TOP_RIGHT);
    boolean bottom = (anchor == RectangleAnchor.BOTTOM_LEFT
            || anchor == RectangleAnchor.BOTTOM
            || anchor == RectangleAnchor.BOTTOM_RIGHT);
    Rectangle rect = line.getBounds();
    
    // we expect the line to be vertical or horizontal
    if (line.getX1() == line.getX2()) {  // vertical
        x = line.getX1();
        y = (line.getY1() + line.getY2()) / 2.0;
        if (left) {
            x = x - deltaX;
        }
        if (right) {
            x = x + deltaX;
        }
        if (top) {
            y = Math.min(line.getY1(), line.getY2()) + deltaY;
        }
        if (bottom) {
            y = Math.max(line.getY1(), line.getY2()) - deltaY;
        }
    }
    else {  // horizontal
        x = (line.getX1() + line.getX2()) / 2.0;
        y = line.getY1();
        if (left) {
            x = Math.min(line.getX1(), line.getX2()) + deltaX;
        }
        if (right) {
            x = Math.max(line.getX1(), line.getX2()) - deltaX;
        }
        if (top) {
            y = y - deltaY;
        }
        if (bottom) {
            y = y + deltaY;
        }
    }
    return new Point2D.Double(x, y);
}