/** * Basic checks for cloning. */ @Test public void testCloning() throws CloneNotSupportedException { 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) o1.clone(); assertTrue(o1 != o2); assertTrue(o1.getClass() == o2.getClass()); assertTrue(o1.equals(o2)); o1.addDomainCrosshair(new Crosshair(3.21)); o1.addRangeCrosshair(new Crosshair(4.32)); assertFalse(o1.equals(o2)); }
/** * Basic checks for cloning. */ @Test public void testCloning() throws CloneNotSupportedException { 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) o1.clone(); assertTrue(o1 != o2); assertTrue(o1.getClass() == o2.getClass()); assertTrue(o1.equals(o2)); o1.addDomainCrosshair(new Crosshair(3.21)); o1.addRangeCrosshair(new Crosshair(4.32)); assertFalse(o1.equals(o2)); }
public void addRangeCrosshair(int axisIdx, Crosshair crosshair) { while (rangeCrosshairs.size() < axisIdx + 1) { rangeCrosshairs.add(new ArrayList<Crosshair>()); } rangeCrosshairs.get(axisIdx).add(crosshair); crosshair.addPropertyChangeListener(this); }
public void removeRangeCrosshair(int axisIdx, Crosshair crosshair) { if (rangeCrosshairs.size() > axisIdx) { ArrayList<Crosshair> crosshairsForRange = rangeCrosshairs.get(axisIdx); crosshairsForRange.remove(crosshair); crosshair.removePropertyChangeListener(this); } }
/** * Clears all range crosshairs on all axes. */ @Override public void clearRangeCrosshairs() { for (List<Crosshair> crosshairsForRange : rangeCrosshairs) { for (Crosshair crosshair : crosshairsForRange) { crosshair.removePropertyChangeListener(this); } } rangeCrosshairs.clear(); }
public MyDemoPane() { XYDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); this.chartViewer = new ChartViewer(chart); this.chartViewer.addChartMouseListener(this); getChildren().add(this.chartViewer); CrosshairOverlayFX crosshairOverlay = new CrosshairOverlayFX(); this.xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); this.xCrosshair.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[]{2.0f, 2.0f}, 0)); this.xCrosshair.setLabelVisible(true); this.yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); this.yCrosshair.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[] {2.0f, 2.0f}, 0)); this.yCrosshair.setLabelVisible(true); crosshairOverlay.addDomainCrosshair(xCrosshair); crosshairOverlay.addRangeCrosshair(yCrosshair); Platform.runLater(() -> { this.chartViewer.getCanvas().addOverlay(crosshairOverlay); }); }
/** * 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); }
/** * Clears all the domain crosshairs from the overlay and sends an * {@link OverlayChangeEvent} to all registered listeners. */ public void clearDomainCrosshairs() { if (this.xCrosshairs.isEmpty()) { return; // nothing to do } List crosshairs = getDomainCrosshairs(); for (int i = 0; i < crosshairs.size(); i++) { Crosshair c = (Crosshair) crosshairs.get(i); this.xCrosshairs.remove(c); c.removePropertyChangeListener(this); } fireOverlayChanged(); }
/** * Adds a crosshair against the range axis and sends an * {@link OverlayChangeEvent} to all registered listeners. * * @param crosshair the crosshair (<code>null</code> not permitted). */ public void addRangeCrosshair(Crosshair crosshair) { ParamChecks.nullNotPermitted(crosshair, "crosshair"); this.yCrosshairs.add(crosshair); crosshair.addPropertyChangeListener(this); fireOverlayChanged(); }
/** * Clears all the range crosshairs from the overlay and sends an * {@link OverlayChangeEvent} to all registered listeners. */ public void clearRangeCrosshairs() { if (this.yCrosshairs.isEmpty()) { return; // nothing to do } 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(); }
/** * Returns a string that can be used as the label for a crosshair. * * @param crosshair the crosshair (<code>null</code> not permitted). * * @return The label (possibly <code>null</code>). */ @Override public String generateLabel(Crosshair crosshair) { Object[] v = new Object[] {this.numberFormat.format( crosshair.getValue())}; String result = MessageFormat.format(this.labelTemplate, v); return result; }
/** * Clears all the domain crosshairs from the overlay and sends an * {@link OverlayChangeEvent} to all registered listeners. */ public void clearDomainCrosshairs() { if (this.xCrosshairs.isEmpty()) { return; // nothing to do } List<Crosshair> crosshairs = getDomainCrosshairs(); for (Crosshair c : crosshairs) { this.xCrosshairs.remove(c); c.removePropertyChangeListener(this); } fireOverlayChanged(); }
/** * Adds a crosshair against the range axis and sends an * {@link OverlayChangeEvent} to all registered listeners. * * @param crosshair the crosshair ({@code null} not permitted). */ public void addRangeCrosshair(Crosshair crosshair) { Args.nullNotPermitted(crosshair, "crosshair"); this.yCrosshairs.add(crosshair); crosshair.addPropertyChangeListener(this); fireOverlayChanged(); }
/** * Clears all the range crosshairs from the overlay and sends an * {@link OverlayChangeEvent} to all registered listeners. */ public void clearRangeCrosshairs() { if (this.yCrosshairs.isEmpty()) { return; // nothing to do } List<Crosshair> crosshairs = getRangeCrosshairs(); for (Crosshair c : crosshairs) { this.yCrosshairs.remove(c); c.removePropertyChangeListener(this); } fireOverlayChanged(); }
/** * Returns a string that can be used as the label for a crosshair. * * @param crosshair the crosshair ({@code null} not permitted). * * @return The label (possibly {@code null}). */ @Override public String generateLabel(Crosshair crosshair) { Object[] v = new Object[] {this.numberFormat.format( crosshair.getValue())}; String result = MessageFormat.format(this.labelTemplate, v); return result; }
/** * 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) TestUtils.serialised(o1); assertEquals(o1, o2); }
/** * Adds a crosshair against the domain axis. * * @param crosshair the crosshair. */ public void addDomainCrosshair(Crosshair crosshair) { if (crosshair == null) { throw new IllegalArgumentException("Null 'crosshair' argument."); } this.xCrosshairs.add(crosshair); crosshair.addPropertyChangeListener(this); }
public void removeDomainCrosshair(Crosshair crosshair) { if (crosshair == null) { throw new IllegalArgumentException("Null 'crosshair' argument."); } if (this.xCrosshairs.remove(crosshair)) { crosshair.removePropertyChangeListener(this); fireOverlayChanged(); } }
public void clearDomainCrosshairs() { if (this.xCrosshairs.isEmpty()) { return; // nothing to do } List crosshairs = getDomainCrosshairs(); for (int i = 0; i < crosshairs.size(); i++) { Crosshair c = (Crosshair) crosshairs.get(i); this.xCrosshairs.remove(c); c.removePropertyChangeListener(this); } fireOverlayChanged(); }
/** * Adds a crosshair against the range axis. * * @param crosshair the crosshair. */ public void addRangeCrosshair(Crosshair crosshair) { if (crosshair == null) { throw new IllegalArgumentException("Null 'crosshair' argument."); } this.yCrosshairs.add(crosshair); crosshair.addPropertyChangeListener(this); }
public void removeRangeCrosshair(Crosshair crosshair) { if (crosshair == null) { throw new IllegalArgumentException("Null 'crosshair' argument."); } if (this.yCrosshairs.remove(crosshair)) { crosshair.removePropertyChangeListener(this); fireOverlayChanged(); } }
public void clearRangeCrosshairs() { if (this.yCrosshairs.isEmpty()) { return; // nothing to do } 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(); }