⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 circledtextannotation.java

📁 网上期货交易的外挂原码,可实现自动交易功能,自动添加模块
💻 JAVA
字号:
package com.jsystemtrader.chart;

import java.awt.*;
import java.awt.geom.*;

import org.jfree.chart.annotations.*;
import org.jfree.chart.axis.*;
import org.jfree.chart.plot.*;
import org.jfree.text.*;
import org.jfree.ui.*;

/**
 * Defines the shape of the markers which show order executions. In this
 * implementation, the shape is a solid circle with a letter "L", "S", or "F"
 * inside the circle, designating the "long", "short", and "flat" positions
 * resulting from order executions.
 */
public class CircledTextAnnotation extends XYTextAnnotation {
    private final int radius;
    private Color color;
    private final Stroke circleStroke = new BasicStroke(1);

    public CircledTextAnnotation(String text, double x, double y, int radius) {
        super(text, x, y);
        this.radius = radius;
    }

    public void setBkColor(Color color) {
        this.color = color;
    }

    public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis,
                     int rendererIndex, PlotRenderingInfo info) {

        PlotOrientation orientation = plot.getOrientation();
        RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
        RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);

        float anchorX = (float) domainAxis.valueToJava2D(getX(), dataArea, domainEdge);
        float anchorY = (float) rangeAxis.valueToJava2D(getY(), dataArea, rangeEdge);

        if (orientation == PlotOrientation.HORIZONTAL) {
            float tempAnchor = anchorX;
            anchorX = anchorY;
            anchorY = tempAnchor;
        }

        g2.setColor(color);
        double x = anchorX - radius;
        double y = anchorY - radius;
        double width = radius * 2.0;
        double height = radius * 2.0;

        g2.fill(new Ellipse2D.Double(x, y, width, height));

        g2.setColor(Color.WHITE);
        g2.setStroke(circleStroke);
        g2.drawOval( (int) x, (int) y, (int) width, (int) height);

        g2.setFont(getFont());
        g2.setPaint(getPaint());
        TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(),
                                        getRotationAnchor());
        Shape hotspot = TextUtilities.calculateRotatedStringBounds(getText(), g2, anchorX, anchorY, getTextAnchor(),
                getRotationAngle(), getRotationAnchor());

        String toolTip = getToolTipText();
        String url = getURL();
        if (toolTip != null || url != null) {
            addEntity(info, hotspot, rendererIndex, toolTip, url);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -