/** * Creates a new annotation to be displayed at the specified (x, y) * location. * * @param x the x-coordinate (in data space). * @param y the y-coordinate (in data space). * @param title the title (<code>null</code> not permitted). * @param anchor the title anchor (<code>null</code> not permitted). */ public XYTitleAnnotation(double x, double y, Title title, RectangleAnchor anchor) { if (title == null) { throw new IllegalArgumentException("Null 'title' argument."); } if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.coordinateType = XYCoordinateType.RELATIVE; this.x = x; this.y = y; this.maxWidth = 0.0; this.maxHeight = 0.0; this.title = title; this.anchor = anchor; }
/** * Some checks for the equals() method. */ public void testEquals() { // use the TextTitle class because it is a concrete subclass Title t1 = new TextTitle(); Title t2 = new TextTitle(); assertEquals(t1, t2); t1.setPosition(RectangleEdge.LEFT); assertFalse(t1.equals(t2)); t2.setPosition(RectangleEdge.LEFT); assertTrue(t1.equals(t2)); t1.setHorizontalAlignment(HorizontalAlignment.RIGHT); assertFalse(t1.equals(t2)); t2.setHorizontalAlignment(HorizontalAlignment.RIGHT); assertTrue(t1.equals(t2)); t1.setVerticalAlignment(VerticalAlignment.BOTTOM); assertFalse(t1.equals(t2)); t2.setVerticalAlignment(VerticalAlignment.BOTTOM); assertTrue(t1.equals(t2)); }
/** * Returns the nth legend for a chart, or <code>null</code>. * * @param index the legend index (zero-based). * * @return The legend (possibly <code>null</code>). * * @see #addLegend(LegendTitle) */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
/** * Sets the title list for the chart (completely replaces any existing * titles) and sends a {@link ChartChangeEvent} to all registered * listeners. * * @param subtitles the new list of subtitles (<code>null</code> not * permitted). * * @see #getSubtitles() */ public void setSubtitles(List subtitles) { if (subtitles == null) { throw new NullPointerException("Null 'subtitles' argument."); } setNotify(false); clearSubtitles(); Iterator iterator = subtitles.iterator(); while (iterator.hasNext()) { Title t = (Title) iterator.next(); if (t != null) { addSubtitle(t); } } setNotify(true); // this fires a ChartChangeEvent }
/** * Returns the nth legend for a chart, or {@code null}. * * @param index the legend index (zero-based). * * @return The legend (possibly {@code null}). * * @see #addLegend(LegendTitle) */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
/** * Sets the title list for the chart (completely replaces any existing * titles) and sends a {@link ChartChangeEvent} to all registered * listeners. * * @param subtitles the new list of subtitles ({@code null} not * permitted). * * @see #getSubtitles() */ public void setSubtitles(List subtitles) { if (subtitles == null) { throw new NullPointerException("Null 'subtitles' argument."); } setNotify(false); clearSubtitles(); Iterator iterator = subtitles.iterator(); while (iterator.hasNext()) { Title t = (Title) iterator.next(); if (t != null) { addSubtitle(t); } } setNotify(true); // this fires a ChartChangeEvent }
/** * Creates a new annotation to be displayed at the specified (x, y) * location. * * @param x the x-coordinate (in data space). * @param y the y-coordinate (in data space). * @param title the title (<code>null</code> not permitted). * @param anchor the title anchor (<code>null</code> not permitted). */ public XYTitleAnnotation(double x, double y, Title title, RectangleAnchor anchor) { super(); if (title == null) { throw new IllegalArgumentException("Null 'title' argument."); } if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.coordinateType = XYCoordinateType.RELATIVE; this.x = x; this.y = y; this.maxWidth = 0.0; this.maxHeight = 0.0; this.title = title; this.anchor = anchor; }
/** * Returns the nth legend for a chart, or <code>null</code>. * * @param index the legend index (zero-based). * * @return The legend (possibly <code>null</code>). */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
/** * Returns the nth legend for a chart, or <code>null</code>. * * @param index the legend index (zero-based). * @return The legend (possibly <code>null</code>). * @see #addLegend(LegendTitle) */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
/** * Sets the title list for the chart (completely replaces any existing titles) and sends a {@link ChartChangeEvent} * to all registered listeners. * * @param subtitles the new list of subtitles (<code>null</code> not permitted). * @see #getSubtitles() */ public void setSubtitles(List subtitles) { if (subtitles == null) { throw new NullPointerException("Null 'subtitles' argument."); } setNotify(false); clearSubtitles(); Iterator iterator = subtitles.iterator(); while (iterator.hasNext()) { Title t = (Title) iterator.next(); if (t != null) { addSubtitle(t); } } setNotify(true); // this fires a ChartChangeEvent }
/** * Problem that the equals(...) method distinguishes all fields. */ public void testEquals() { // use the TextTitle class because it is a concrete subclass Title t1 = new TextTitle(); Title t2 = new TextTitle(); assertEquals(t1, t2); t1.setPosition(RectangleEdge.LEFT); assertFalse(t1.equals(t2)); t2.setPosition(RectangleEdge.LEFT); assertTrue(t1.equals(t2)); t1.setHorizontalAlignment(HorizontalAlignment.RIGHT); assertFalse(t1.equals(t2)); t2.setHorizontalAlignment(HorizontalAlignment.RIGHT); assertTrue(t1.equals(t2)); t1.setVerticalAlignment(VerticalAlignment.BOTTOM); assertFalse(t1.equals(t2)); t2.setVerticalAlignment(VerticalAlignment.BOTTOM); assertTrue(t1.equals(t2)); t1.setSpacer(new Spacer(Spacer.ABSOLUTE, 5.0, 10.0, 15.0, 20.0)); assertFalse(t1.equals(t2)); t2.setSpacer(new Spacer(Spacer.ABSOLUTE, 5.0, 10.0, 15.0, 20.0)); assertTrue(t1.equals(t2)); }
/** * Returns a chart subtitle. * * @param index the index of the chart subtitle (zero based). * * @return a chart subtitle. */ public Title getSubtitle(int index) { // check arguments... if ((index < 0) || (index == getSubtitleCount())) { throw new IllegalArgumentException("JFreeChart.getSubtitle(...): index out of range."); } return (Title) this.subtitles.get(index); }
/** * Adds a chart subtitle, and notifies registered listeners that the chart has been modified. * * @param subtitle the subtitle. */ public void addSubtitle(Title subtitle) { if (subtitle != null) { this.subtitles.add(subtitle); subtitle.addChangeListener(this); fireChartChanged(); } }
/** * Adds a chart subtitle, and notifies registered listeners that the chart * has been modified. * * @param subtitle the subtitle (<code>null</code> not permitted). * * @see #getSubtitle(int) */ public void addSubtitle(Title subtitle) { if (subtitle == null) { throw new IllegalArgumentException("Null 'subtitle' argument."); } this.subtitles.add(subtitle); subtitle.addChangeListener(this); fireChartChanged(); }
/** * Clears all subtitles from the chart and sends a {@link ChartChangeEvent} * to all registered listeners. * * @see #addSubtitle(Title) */ public void clearSubtitles() { Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title t = (Title) iterator.next(); t.removeChangeListener(this); } this.subtitles.clear(); fireChartChanged(); }
/** * Clones the object, and takes care of listeners. * Note: caller shall register its own listeners on cloned graph. * * @return A clone. * * @throws CloneNotSupportedException if the chart is not cloneable. */ public Object clone() throws CloneNotSupportedException { JFreeChart chart = (JFreeChart) super.clone(); chart.renderingHints = (RenderingHints) this.renderingHints.clone(); // private boolean borderVisible; // private transient Stroke borderStroke; // private transient Paint borderPaint; if (this.title != null) { chart.title = (TextTitle) this.title.clone(); chart.title.addChangeListener(chart); } chart.subtitles = new ArrayList(); for (int i = 0; i < getSubtitleCount(); i++) { Title subtitle = (Title) getSubtitle(i).clone(); chart.subtitles.add(subtitle); subtitle.addChangeListener(chart); } if (this.plot != null) { chart.plot = (Plot) this.plot.clone(); chart.plot.addChangeListener(chart); } chart.progressListeners = new EventListenerList(); chart.changeListeners = new EventListenerList(); return chart; }
/** * Adds a subtitle at a particular position in the subtitle list, and sends * a {@link ChartChangeEvent} to all registered listeners. * * @param index the index (in the range 0 to {@link #getSubtitleCount()}). * @param subtitle the subtitle to add (<code>null</code> not permitted). * * @since 1.0.6 */ public void addSubtitle(int index, Title subtitle) { if (index < 0 || index > getSubtitleCount()) { throw new IllegalArgumentException( "The 'index' argument is out of range."); } ParamChecks.nullNotPermitted(subtitle, "subtitle"); this.subtitles.add(index, subtitle); subtitle.addChangeListener(this); fireChartChanged(); }
/** * Clones the object, and takes care of listeners. * Note: caller shall register its own listeners on cloned graph. * * @return A clone. * * @throws CloneNotSupportedException if the chart is not cloneable. */ @Override public Object clone() throws CloneNotSupportedException { JFreeChart chart = (JFreeChart) super.clone(); chart.renderingHints = (RenderingHints) this.renderingHints.clone(); // private boolean borderVisible; // private transient Stroke borderStroke; // private transient Paint borderPaint; if (this.title != null) { chart.title = (TextTitle) this.title.clone(); chart.title.addChangeListener(chart); } chart.subtitles = new ArrayList(); for (int i = 0; i < getSubtitleCount(); i++) { Title subtitle = (Title) getSubtitle(i).clone(); chart.subtitles.add(subtitle); subtitle.addChangeListener(chart); } if (this.plot != null) { chart.plot = (Plot) this.plot.clone(); chart.plot.addChangeListener(chart); } chart.progressListeners = new EventListenerList(); chart.changeListeners = new EventListenerList(); return chart; }
/** * Applies the attributes of this theme to the specified title. * * @param title the title. */ protected void applyToTitle(Title title) { if (title instanceof TextTitle) { TextTitle tt = (TextTitle) title; tt.setFont(this.largeFont); tt.setPaint(this.subtitlePaint); } else if (title instanceof LegendTitle) { LegendTitle lt = (LegendTitle) title; if (lt.getBackgroundPaint() != null) { lt.setBackgroundPaint(this.legendBackgroundPaint); } lt.setItemFont(this.regularFont); lt.setItemPaint(this.legendItemPaint); if (lt.getWrapper() != null) { applyToBlockContainer(lt.getWrapper()); } } else if (title instanceof PaintScaleLegend) { PaintScaleLegend psl = (PaintScaleLegend) title; psl.setBackgroundPaint(this.legendBackgroundPaint); ValueAxis axis = psl.getAxis(); if (axis != null) { applyToValueAxis(axis); } } else if (title instanceof CompositeTitle) { CompositeTitle ct = (CompositeTitle) title; BlockContainer bc = ct.getContainer(); List blocks = bc.getBlocks(); Iterator iterator = blocks.iterator(); while (iterator.hasNext()) { Block b = (Block) iterator.next(); if (b instanceof Title) { applyToTitle((Title) b); } } } }
/** * Applies the attributes of this theme to the specified block. * * @param b the block. */ protected void applyToBlock(Block b) { if (b instanceof Title) { applyToTitle((Title) b); } else if (b instanceof LabelBlock) { LabelBlock lb = (LabelBlock) b; lb.setFont(this.regularFont); lb.setPaint(this.legendItemPaint); } }