Search in sources :

Example 1 with Crosshair

use of org.jfree.chart.plot.Crosshair in project SIMVA-SoS by SESoS.

the class CrosshairOverlay method clearRangeCrosshairs.

/**
 * Clears all the range crosshairs from the overlay and sends an
 * {@link OverlayChangeEvent} to all registered listeners.
 */
public void clearRangeCrosshairs() {
    if (this.yCrosshairs.isEmpty()) {
        // nothing to do
        return;
    }
    List crosshairs = getRangeCrosshairs();
    for (int i = 0; i < crosshairs.size(); i++) {
        Crosshair c = (Crosshair) crosshairs.get(i);
        this.yCrosshairs.remove(c);
        c.removePropertyChangeListener(this);
    }
    fireOverlayChanged();
}
Also used : Crosshair(org.jfree.chart.plot.Crosshair) ArrayList(java.util.ArrayList) List(java.util.List) Paint(java.awt.Paint)

Example 2 with Crosshair

use of org.jfree.chart.plot.Crosshair in project SIMVA-SoS by SESoS.

the class CrosshairOverlayTest method testSerialization.

/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    CrosshairOverlay o1 = new CrosshairOverlay();
    o1.addDomainCrosshair(new Crosshair(99.9));
    o1.addRangeCrosshair(new Crosshair(1.23, new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue), new BasicStroke(1.1f)));
    CrosshairOverlay o2 = (CrosshairOverlay) TestUtilities.serialised(o1);
    assertEquals(o1, o2);
}
Also used : BasicStroke(java.awt.BasicStroke) Crosshair(org.jfree.chart.plot.Crosshair) GradientPaint(java.awt.GradientPaint) Test(org.junit.Test)

Example 3 with Crosshair

use of org.jfree.chart.plot.Crosshair in project jfreechart-fx by jfree.

the class CrosshairOverlayFX method paintOverlay.

@Override
public void paintOverlay(Graphics2D g2, ChartCanvas chartCanvas) {
    if (chartCanvas.getRenderingInfo() == null) {
        return;
    }
    Shape savedClip = g2.getClip();
    Rectangle2D dataArea = chartCanvas.getRenderingInfo().getPlotInfo().getDataArea();
    g2.clip(dataArea);
    JFreeChart chart = chartCanvas.getChart();
    XYPlot plot = (XYPlot) chart.getPlot();
    ValueAxis xAxis = plot.getDomainAxis();
    RectangleEdge xAxisEdge = plot.getDomainAxisEdge();
    Iterator iterator = getDomainCrosshairs().iterator();
    while (iterator.hasNext()) {
        Crosshair ch = (Crosshair) iterator.next();
        if (ch.isVisible()) {
            double x = ch.getValue();
            double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge);
            if (plot.getOrientation() == PlotOrientation.VERTICAL) {
                drawVerticalCrosshair(g2, dataArea, xx, ch);
            } else {
                drawHorizontalCrosshair(g2, dataArea, xx, ch);
            }
        }
    }
    ValueAxis yAxis = plot.getRangeAxis();
    RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
    iterator = getRangeCrosshairs().iterator();
    while (iterator.hasNext()) {
        Crosshair ch = (Crosshair) iterator.next();
        if (ch.isVisible()) {
            double y = ch.getValue();
            double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge);
            if (plot.getOrientation() == PlotOrientation.VERTICAL) {
                drawHorizontalCrosshair(g2, dataArea, yy, ch);
            } else {
                drawVerticalCrosshair(g2, dataArea, yy, ch);
            }
        }
    }
    g2.setClip(savedClip);
}
Also used : Shape(java.awt.Shape) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) Crosshair(org.jfree.chart.plot.Crosshair) Rectangle2D(java.awt.geom.Rectangle2D) Iterator(java.util.Iterator) JFreeChart(org.jfree.chart.JFreeChart) RectangleEdge(org.jfree.chart.ui.RectangleEdge)

Example 4 with Crosshair

use of org.jfree.chart.plot.Crosshair in project Course_Generator by patrovite.

the class JPanelAnalysisSpeed method initComponents.

private void initComponents() {
    setLayout(new java.awt.BorderLayout());
    // //-- Left - Toolbar
    // Create_Toolbar();
    // add(toolBar, java.awt.BorderLayout.WEST);
    // 
    // -- Bottom - Info
    jPanelSpeedInfo = new javax.swing.JPanel();
    jPanelSpeedInfo.setOpaque(true);
    jPanelSpeedInfo.setBackground(Color.WHITE);
    jPanelSpeedInfo.setLayout(new GridBagLayout());
    add(jPanelSpeedInfo, java.awt.BorderLayout.SOUTH);
    // -- Start speed/End speed/Speed/Distance
    // -- Start speed
    lbSpeedInfoStartSpeed = new javax.swing.JLabel();
    lbSpeedInfoStartSpeed.setOpaque(true);
    lbSpeedInfoStartSpeed.setBackground(Color.WHITE);
    lbSpeedInfoStartSpeed.setText(" " + bundle.getString("JPanelAnalysisSpeed.lbSpeedInfoStartSpeed.text") + "=0km/h ");
    lbSpeedInfoStartSpeed.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelSpeedInfo, lbSpeedInfoStartSpeed, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
    // -- End speed
    lbSpeedInfoEndSpeed = new javax.swing.JLabel();
    lbSpeedInfoEndSpeed.setOpaque(true);
    lbSpeedInfoEndSpeed.setBackground(Color.WHITE);
    lbSpeedInfoEndSpeed.setText(" " + bundle.getString("JPanelAnalysisSpeed.lbSpeedInfoEndSpeed.text") + "=0km/h ");
    lbSpeedInfoEndSpeed.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelSpeedInfo, lbSpeedInfoEndSpeed, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
    // -- Speed
    lbSpeedInfoSpeed = new javax.swing.JLabel();
    lbSpeedInfoSpeed.setOpaque(true);
    lbSpeedInfoSpeed.setBackground(Color.WHITE);
    lbSpeedInfoSpeed.setText(" " + bundle.getString("JPanelAnalysisSpeed.lbSpeedInfoSpeed.text") + "=0km/h ");
    lbSpeedInfoSpeed.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelSpeedInfo, lbSpeedInfoSpeed, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
    // -- Distance
    lbSpeedInfoDistance = new javax.swing.JLabel();
    lbSpeedInfoDistance.setOpaque(true);
    lbSpeedInfoDistance.setBackground(Color.WHITE);
    lbSpeedInfoDistance.setText(" " + bundle.getString("JPanelAnalysisSpeed.lbSpeedInfoDistance.text") + "=0.000km ");
    lbSpeedInfoDistance.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelSpeedInfo, lbSpeedInfoDistance, 3, 0, 1, 1, 1, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL);
    // -- Chart Speed/Dist & Time/Dist
    ChartPanelSpeed = new ChartPanel(chart, true, /* Properties */
    true, /* save */
    true, /* print */
    false, /* zoom */
    true);
    ChartPanelSpeed.setDomainZoomable(false);
    ChartPanelSpeed.setRangeZoomable(false);
    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.RED, new BasicStroke(0f));
    xCrosshair.setLabelBackgroundPaint(Color.WHITE);
    crosshairOverlay.addDomainCrosshair(xCrosshair);
    ChartPanelSpeed.addOverlay(crosshairOverlay);
    ChartPanelSpeed.setBackground(new java.awt.Color(255, 0, 51));
    ChartPanelSpeed.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            ChartEntity chartentity = event.getEntity();
            if (chartentity instanceof XYItemEntity) {
                XYItemEntity e = (XYItemEntity) chartentity;
                XYDataset d = e.getDataset();
                int s = e.getSeriesIndex();
                int i = e.getItem();
                double x = d.getXValue(s, i);
                xCrosshair.setValue(x);
                RefreshInfo(i);
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        }
    });
    add(ChartPanelSpeed, java.awt.BorderLayout.CENTER);
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) ChartPanel(org.jfree.chart.ChartPanel) GridBagLayout(java.awt.GridBagLayout) Crosshair(org.jfree.chart.plot.Crosshair) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) ChartMouseListener(org.jfree.chart.ChartMouseListener) XYItemEntity(org.jfree.chart.entity.XYItemEntity) JLabel(javax.swing.JLabel) CrosshairOverlay(org.jfree.chart.panel.CrosshairOverlay) XYDataset(org.jfree.data.xy.XYDataset) ChartEntity(org.jfree.chart.entity.ChartEntity) JPanel(javax.swing.JPanel)

Example 5 with Crosshair

use of org.jfree.chart.plot.Crosshair in project Course_Generator by patrovite.

the class JPanelAnalysisSpeedSlope method initComponents.

private void initComponents() {
    setLayout(new java.awt.BorderLayout());
    // -- Left - Toolbar
    Create_Toolbar();
    add(toolBar, java.awt.BorderLayout.WEST);
    // -- Bottom - Info
    jPanelSpeedSlopeInfo = new javax.swing.JPanel();
    jPanelSpeedSlopeInfo.setOpaque(true);
    jPanelSpeedSlopeInfo.setBackground(Color.WHITE);
    jPanelSpeedSlopeInfo.setLayout(new GridBagLayout());
    add(jPanelSpeedSlopeInfo, java.awt.BorderLayout.SOUTH);
    // -- Speed/Slope
    // -- Speed
    lbSpeedSlopeInfoSpeed = new javax.swing.JLabel();
    lbSpeedSlopeInfoSpeed.setOpaque(true);
    lbSpeedSlopeInfoSpeed.setBackground(Color.WHITE);
    lbSpeedSlopeInfoSpeed.setText(" " + bundle.getString("JPanelAnalysisSpeedSlope.lbSpeedSlopeInfoSpeed.text") + "=0km/h ");
    lbSpeedSlopeInfoSpeed.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelSpeedSlopeInfo, lbSpeedSlopeInfoSpeed, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
    // -- Slope
    lbSpeedSlopeInfoSlope = new javax.swing.JLabel();
    lbSpeedSlopeInfoSlope.setOpaque(true);
    lbSpeedSlopeInfoSlope.setBackground(Color.WHITE);
    lbSpeedSlopeInfoSlope.setText(" " + bundle.getString("JPanelAnalysisSpeedSlope.lbSpeedSlopeInfoSlope.text") + "=0.0% ");
    lbSpeedSlopeInfoSlope.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelSpeedSlopeInfo, lbSpeedSlopeInfoSlope, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL);
    // -- Chart Speed/Dist & Time/Dist
    ChartPanelSpeedSlope = new ChartPanel(chart, true, /* Properties */
    true, /* save */
    true, /* print */
    false, /* zoom */
    true);
    ChartPanelSpeedSlope.setDomainZoomable(false);
    ChartPanelSpeedSlope.setRangeZoomable(false);
    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.RED, new BasicStroke(0f));
    xCrosshair.setLabelBackgroundPaint(Color.WHITE);
    // yCrosshair = new Crosshair(Double.NaN, Color.RED, new
    // BasicStroke(0f));
    // yCrosshair.setLabelBackgroundPaint(Color.WHITE);
    crosshairOverlay.addDomainCrosshair(xCrosshair);
    // crosshairOverlay.addRangeCrosshair(yCrosshair);
    ChartPanelSpeedSlope.addOverlay(crosshairOverlay);
    ChartPanelSpeedSlope.setBackground(new java.awt.Color(255, 0, 51));
    ChartPanelSpeedSlope.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            ChartEntity chartentity = event.getEntity();
            if (chartentity instanceof XYItemEntity) {
                XYItemEntity e = (XYItemEntity) chartentity;
                XYDataset d = e.getDataset();
                int s = e.getSeriesIndex();
                int i = e.getItem();
                double x = d.getXValue(s, i);
                double y = d.getYValue(s, i);
                xCrosshair.setValue(x);
                // yCrosshair.setValue(y);
                RefreshInfo(i);
            // //Refresh the position on the data grid
            // TableMain.setRowSelectionInterval(i, i);
            // Rectangle rect = TableMain.getCellRect(i, 0, true);
            // TableMain.scrollRectToVisible(rect);
            // //Refresh the marker position on the map
            // RefreshCurrentPosMarker(Track.data.get(i).getLatitude(),
            // Track.data.get(i).getLongitude());
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        }
    });
    add(ChartPanelSpeedSlope, java.awt.BorderLayout.CENTER);
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) ChartPanel(org.jfree.chart.ChartPanel) GridBagLayout(java.awt.GridBagLayout) Crosshair(org.jfree.chart.plot.Crosshair) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) ChartMouseListener(org.jfree.chart.ChartMouseListener) XYItemEntity(org.jfree.chart.entity.XYItemEntity) JLabel(javax.swing.JLabel) CrosshairOverlay(org.jfree.chart.panel.CrosshairOverlay) XYDataset(org.jfree.data.xy.XYDataset) ChartEntity(org.jfree.chart.entity.ChartEntity) JPanel(javax.swing.JPanel)

Aggregations

Crosshair (org.jfree.chart.plot.Crosshair)11 BasicStroke (java.awt.BasicStroke)7 Color (java.awt.Color)5 GridBagLayout (java.awt.GridBagLayout)5 JLabel (javax.swing.JLabel)5 ChartMouseEvent (org.jfree.chart.ChartMouseEvent)5 ChartMouseListener (org.jfree.chart.ChartMouseListener)5 ChartPanel (org.jfree.chart.ChartPanel)5 ChartEntity (org.jfree.chart.entity.ChartEntity)5 XYItemEntity (org.jfree.chart.entity.XYItemEntity)5 CrosshairOverlay (org.jfree.chart.panel.CrosshairOverlay)5 XYDataset (org.jfree.data.xy.XYDataset)5 JPanel (javax.swing.JPanel)4 GradientPaint (java.awt.GradientPaint)2 Paint (java.awt.Paint)2 Shape (java.awt.Shape)2 Rectangle2D (java.awt.geom.Rectangle2D)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2