使芯片可在晶片图jfree图表(javafx应用程序)中的鼠标点击事件中选择

时间:2017-01-31 20:31:10

标签: javafx jfreechart

我创建了wafermap图表。我想在鼠标点击时选择晶圆中的芯片(芯片)并插入标签以及从一个芯片到另一个芯片的线条。任何jfree图表专家?

wafermap chart

1 个答案:

答案 0 :(得分:0)

以下是晶圆图工具提示监听器的基本部分,这是选择芯片的一种形式。将以下内容添加到WaferMapPlot:

public String findChipAtPoint(double x, double y, Rectangle2D plotArea){
    double[] xValues = this.getChipXValues(plotArea, dataset.getMaxChipX()
         + 2, dataset.getChipSpace());
    double startX = xValues[1];
    double chipWidth = xValues[0];
    int ychips = this.dataset.getMaxChipY()+ 2;
    double[] yValues = this.getChipYValues(plotArea, ychips, 
         dataset.getChipSpace());
    double startY = yValues[1];
    double chipHeight = yValues[0];
    double chipSpace = dataset.getChipSpace();
    int chipX = (int)Math.floor((x - startX + chipWidth + chipSpace) / 
        (chipWidth + chipSpace));
    int chipY = (int)Math.floor((y - startY + chipHeight + chipSpace) / 
         (chipHeight + chipSpace));
    chipX = chipX - dataset.getXOffset() - 1;
    chipY = ychips - chipY - dataset.getYOffset() - 1;
    StringBuilder sb = new StringBuilder("(");
    Number value = dataset.getChipValue(chipX, chipY);
    if (value instanceof Double)
        value = value.intValue();
    sb.append(chipX).append(",").append(chipY).append(") ").append(
       (value == null) ? "" : value.toString());
    return sb.toString();
}

然后创建一个ChartPanel的子类,它将成为监听器:

public class WaferMapChartPanel extends ChartPanel {

WaferMapPlot waferPlot = null;
WaferMapDataset dataSet = null;

public WaferMapChartPanel(JFreeChart chart){
    super(chart);
    waferPlot = (WaferMapPlot)chart.getPlot();
    if (waferPlot != null)
        dataSet = waferPlot.getDataset();
}

 /**
 * Returns a string for the tooltip.
 * @param e  the mouse event.
 * @return A tool tip or <code>null</code> if no tooltip is available.
 */
@Override
public String getToolTipText(MouseEvent e) {
   if (waferPlot != null){
        Object source = e.getSource();
        if (source instanceof WaferMapChartPanel){
            WaferMapChartPanel chartSource= (WaferMapChartPanel)e.getSource();
            Rectangle2D plotArea = chartSource.getChartRenderingInfo().getPlotInfo().getPlotArea();
            Insets insets = this.getInsets();
            double x = (e.getX() - insets.left) / this.getScaleX();
            double y = (e.getY() - insets.top) / this.getScaleY();
            return waferPlot.findChipAtPoint(x, y, plotArea);
        }
    }
    return "";
}
}

这会创建骰子的x,y和bin的工具提示或您使用的任何值而不是bin。