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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations