List of usage examples for org.jfree.chart.title TextTitle getPaint
public Paint getPaint()
From source file:daylightchart.options.chart.TitleOptions.java
/** * {@inheritDoc}// ww w .ja v a 2s . c o m * * @see BaseChartOptions#copyFromChart(org.jfree.chart.JFreeChart) */ @Override public void copyFromChart(final JFreeChart chart) { final TextTitle title = chart.getTitle(); if (title != null) { titleFont = title.getFont(); titlePaint = title.getPaint(); titleText = title.getText(); } }
From source file:net.sf.dynamicreports.test.jasper.chart.ChartTest.java
@Override public void test() { super.test(); numberOfPagesTest(1);/*from www.ja va2 s . com*/ chartCountTest("summary.chart1", 1); JFreeChart chart = getChart("summary.chart1", 0); TextTitle title = chart.getTitle(); Assert.assertEquals("title", "title", title.getText()); Assert.assertEquals("title color", Color.BLUE, title.getPaint()); Assert.assertEquals("title font", new Font("Arial", Font.BOLD, 10), title.getFont()); Assert.assertEquals("title position", RectangleEdge.RIGHT, title.getPosition()); TextTitle subtitle = (TextTitle) chart.getSubtitle(1); Assert.assertEquals("subtitle", "subtitle", subtitle.getText()); Assert.assertEquals("subtitle color", Color.CYAN, subtitle.getPaint()); Assert.assertEquals("subtitle font", new Font("Arial", Font.PLAIN, 10), subtitle.getFont()); LegendTitle legend = (LegendTitle) chart.getSubtitle(0); Assert.assertEquals("legend color", Color.BLUE, legend.getItemPaint()); Assert.assertEquals("legend backgroundcolor", Color.LIGHT_GRAY, legend.getBackgroundPaint()); Assert.assertEquals("legend font", new Font("Courier New", Font.PLAIN, 10), legend.getItemFont()); Assert.assertEquals("legend position", RectangleEdge.LEFT, legend.getPosition()); chartCountTest("summary.chart2", 1); chart = getChart("summary.chart2", 0); Assert.assertNull("legend", chart.getLegend()); Assert.assertEquals("plot orientation", PlotOrientation.HORIZONTAL, chart.getCategoryPlot().getOrientation()); Assert.assertEquals("plot series colors", Color.BLUE, chart.getPlot().getDrawingSupplier().getNextPaint()); Assert.assertEquals("plot series colors", Color.GREEN, chart.getPlot().getDrawingSupplier().getNextPaint()); Assert.assertEquals("plot series colors", Color.RED, chart.getPlot().getDrawingSupplier().getNextPaint()); }
From source file:daylightchart.sunchart.chart.SunChart.java
@SuppressWarnings("unchecked") private void createTitles(final ChartOptions chartOptions, final Font titleFont) { // Clear all titles and subtitles setTitle((TextTitle) null);// w w w . ja v a 2 s . c o m for (final Title subtitle : (List<Title>) getSubtitles()) { if (subtitle instanceof TextTitle) { removeSubtitle(subtitle); } } // Build new titles and legend final Location location = sunChartData.getLocation(); final boolean showTitle = chartOptions.getTitleOptions().getShowTitle(); if (location != null && showTitle) { final TextTitle title = new TextTitle(location.toString(), titleFont); setTitle(title); final Font subtitleFont = titleFont.deriveFont(Font.PLAIN); final TextTitle subtitle = new TextTitle(location.getDetails(), subtitleFont); subtitle.setPaint(title.getPaint()); addSubtitle(subtitle); } }
From source file:ch.zhaw.simulation.diagram.charteditor.DefaultTitleEditor.java
/** * Standard constructor: builds a panel for displaying/editing the * properties of the specified title./*from ww w .j av a2s . c o m*/ * * @param title * the title, which should be changed. */ public DefaultTitleEditor(Title title) { if (title == null) { this.showTitle = false; this.titleFont = SimulationDiagramTheme.DEFAULT_TITLE_FONT; this.titleField = new JTextField(); this.titlePaint = new PaintSample(Color.BLACK); } else { TextTitle t = (TextTitle) title; this.showTitle = title.isVisible(); this.titleFont = t.getFont(); this.titleField = new JTextField(t.getText()); this.titlePaint = new PaintSample(t.getPaint()); } System.out.println(this.titleFont.getName()); setLayout(new BorderLayout()); JPanel general = new JPanel(new BorderLayout()); general.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), localizationResources.getString("General"))); JPanel interior = new JPanel(new LCBLayout(4)); interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); interior.add(new JLabel(localizationResources.getString("Show_Title"))); this.showTitleCheckBox = new JCheckBox(); this.showTitleCheckBox.setSelected(this.showTitle); this.showTitleCheckBox.setActionCommand("ShowTitle"); this.showTitleCheckBox.addActionListener(this); interior.add(new JPanel()); interior.add(this.showTitleCheckBox); JLabel titleLabel = new JLabel(localizationResources.getString("Text")); interior.add(titleLabel); interior.add(this.titleField); interior.add(new JPanel()); JLabel fontLabel = new JLabel(localizationResources.getString("Font")); this.fontfield = new FontDisplayField(this.titleFont); this.selectFontButton = new JButton(localizationResources.getString("Select...")); this.selectFontButton.setActionCommand("SelectFont"); this.selectFontButton.addActionListener(this); interior.add(fontLabel); interior.add(this.fontfield); interior.add(this.selectFontButton); JLabel colorLabel = new JLabel(localizationResources.getString("Color")); this.selectPaintButton = new JButton(localizationResources.getString("Select...")); this.selectPaintButton.setActionCommand("SelectPaint"); this.selectPaintButton.addActionListener(this); interior.add(colorLabel); interior.add(this.titlePaint); interior.add(this.selectPaintButton); this.enableOrDisableControls(); general.add(interior); add(general, BorderLayout.NORTH); }
From source file:daylightchart.daylightchart.chart.DaylightChart.java
@SuppressWarnings("unchecked") private void createTitles(final ChartOptions chartOptions, final Font titleFont) { // Clear all titles and subtitles setTitle((TextTitle) null);// w w w .j a v a 2 s . c o m for (final Title subtitle : (List<Title>) getSubtitles()) { if (subtitle instanceof TextTitle) { removeSubtitle(subtitle); } } // Build new titles and legend final Location location = riseSetData.getLocation(); final boolean showTitle = chartOptions.getTitleOptions().getShowTitle(); if (location != null && showTitle) { final TextTitle title = new TextTitle(location.toString(), titleFont); setTitle(title); final Font subtitleFont = titleFont.deriveFont(Font.PLAIN); final TextTitle subtitle = new TextTitle(location.getDetails(), subtitleFont); subtitle.setPaint(title.getPaint()); addSubtitle(subtitle); } }
From source file:org.jfree.experimental.chart.swt.editor.SWTTitleEditor.java
/** * Standard constructor: builds a panel for displaying/editing the * properties of the specified title./*from ww w . jav a 2 s . c om*/ * * @param title the title, which should be changed. */ SWTTitleEditor(Composite parent, int style, Title title) { super(parent, style); FillLayout layout = new FillLayout(); layout.marginHeight = layout.marginWidth = 4; setLayout(layout); TextTitle t = (title != null ? (TextTitle) title : new TextTitle(localizationResources.getString("Title"))); this.showTitle = (title != null); this.titleFont = SWTUtils.toSwtFontData(getDisplay(), t.getFont(), true); this.titleColor = SWTUtils.toSwtColor(getDisplay(), t.getPaint()); Group general = new Group(this, SWT.NONE); general.setLayout(new GridLayout(3, false)); general.setText(localizationResources.getString("General")); // row 1 Label label = new Label(general, SWT.NONE); label.setText(localizationResources.getString("Show_Title")); GridData gridData = new GridData(); gridData.horizontalSpan = 2; label.setLayoutData(gridData); this.showTitleCheckBox = new Button(general, SWT.CHECK); this.showTitleCheckBox.setSelection(this.showTitle); this.showTitleCheckBox.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); this.showTitleCheckBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { SWTTitleEditor.this.showTitle = SWTTitleEditor.this.showTitleCheckBox.getSelection(); } }); // row 2 new Label(general, SWT.NONE).setText(localizationResources.getString("Text")); this.titleField = new Text(general, SWT.BORDER); this.titleField.setText(t.getText()); this.titleField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); new Label(general, SWT.NONE).setText(""); // row 3 new Label(general, SWT.NONE).setText(localizationResources.getString("Font")); this.fontField = new Text(general, SWT.BORDER); this.fontField.setText(this.titleFont.toString()); this.fontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); this.selectFontButton = new Button(general, SWT.PUSH); this.selectFontButton.setText(localizationResources.getString("Select...")); this.selectFontButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the font-change dialog FontDialog dlg = new FontDialog(getShell()); dlg.setText(localizationResources.getString("Font_Selection")); dlg.setFontList(new FontData[] { SWTTitleEditor.this.titleFont }); if (dlg.open() != null) { // Dispose of any fonts we have created if (SWTTitleEditor.this.font != null) { SWTTitleEditor.this.font.dispose(); } // Create the new font and set it into the title // label SWTTitleEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList()); //titleField.setFont(font); SWTTitleEditor.this.fontField.setText(SWTTitleEditor.this.font.getFontData()[0].toString()); SWTTitleEditor.this.titleFont = SWTTitleEditor.this.font.getFontData()[0]; } } }); // row 4 new Label(general, SWT.NONE).setText(localizationResources.getString("Color")); // Use a SwtPaintCanvas to show the color, note that we must set the // heightHint. final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, SWT.NONE, this.titleColor); GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, false); canvasGridData.heightHint = 20; colorCanvas.setLayoutData(canvasGridData); this.selectColorButton = new Button(general, SWT.PUSH); this.selectColorButton.setText(localizationResources.getString("Select...")); this.selectColorButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog ColorDialog dlg = new ColorDialog(getShell()); dlg.setText(localizationResources.getString("Title_Color")); dlg.setRGB(SWTTitleEditor.this.titleColor.getRGB()); RGB rgb = dlg.open(); if (rgb != null) { // create the new color and set it to the // SwtPaintCanvas SWTTitleEditor.this.titleColor = new Color(getDisplay(), rgb); colorCanvas.setColor(SWTTitleEditor.this.titleColor); } } }); }
From source file:com.rcp.wbw.demo.editor.SWTTitleEditor.java
/** * Standard constructor: builds a panel for displaying/editing the * properties of the specified title./*from w w w . j a v a 2 s . c o m*/ * * @param parent * the parent. * @param style * the style. * @param title * the title, which should be changed. * */ SWTTitleEditor(Composite parent, int style, Title title) { super(parent, style); FillLayout layout = new FillLayout(); layout.marginHeight = layout.marginWidth = 4; setLayout(layout); TextTitle t = (title != null ? (TextTitle) title : new TextTitle(localizationResources.getString("Title"))); this.showTitle = (title != null); this.titleFont = SWTUtils.toSwtFontData(getDisplay(), t.getFont(), true); this.titleColor = SWTUtils.toSwtColor(getDisplay(), t.getPaint()); Group general = new Group(this, SWT.NONE); general.setLayout(new GridLayout(3, false)); general.setText(localizationResources.getString("General")); // row 1 Label label = new Label(general, SWT.NONE); label.setText(localizationResources.getString("Show_Title")); GridData gridData = new GridData(); gridData.horizontalSpan = 2; label.setLayoutData(gridData); this.showTitleCheckBox = new Button(general, SWT.CHECK); this.showTitleCheckBox.setSelection(this.showTitle); this.showTitleCheckBox.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); this.showTitleCheckBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { SWTTitleEditor.this.showTitle = SWTTitleEditor.this.showTitleCheckBox.getSelection(); } }); // row 2 new Label(general, SWT.NONE).setText(localizationResources.getString("Text")); this.titleField = new Text(general, SWT.BORDER); this.titleField.setText(t.getText()); this.titleField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); new Label(general, SWT.NONE).setText(""); // row 3 new Label(general, SWT.NONE).setText(localizationResources.getString("Font")); this.fontField = new Text(general, SWT.BORDER); this.fontField.setText(this.titleFont.toString()); this.fontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); this.selectFontButton = new Button(general, SWT.PUSH); this.selectFontButton.setText(localizationResources.getString("Select...")); this.selectFontButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the font-change dialog FontDialog dlg = new FontDialog(getShell()); dlg.setText(localizationResources.getString("Font_Selection")); dlg.setFontList(new FontData[] { SWTTitleEditor.this.titleFont }); if (dlg.open() != null) { // Dispose of any fonts we have created if (SWTTitleEditor.this.font != null) { SWTTitleEditor.this.font.dispose(); } // Create the new font and set it into the title // label SWTTitleEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList()); // titleField.setFont(font); SWTTitleEditor.this.fontField.setText(SWTTitleEditor.this.font.getFontData()[0].toString()); SWTTitleEditor.this.titleFont = SWTTitleEditor.this.font.getFontData()[0]; } } }); // row 4 new Label(general, SWT.NONE).setText(localizationResources.getString("Color")); // Use a SwtPaintCanvas to show the color, note that we must set the // heightHint. final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, SWT.NONE, this.titleColor); GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, false); canvasGridData.heightHint = 20; colorCanvas.setLayoutData(canvasGridData); this.selectColorButton = new Button(general, SWT.PUSH); this.selectColorButton.setText(localizationResources.getString("Select...")); this.selectColorButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog ColorDialog dlg = new ColorDialog(getShell()); dlg.setText(localizationResources.getString("Title_Color")); dlg.setRGB(SWTTitleEditor.this.titleColor.getRGB()); RGB rgb = dlg.open(); if (rgb != null) { // create the new color and set it to the // SwtPaintCanvas SWTTitleEditor.this.titleColor = new Color(getDisplay(), rgb); colorCanvas.setColor(SWTTitleEditor.this.titleColor); } } }); }
From source file:com.bdaum.zoom.report.internal.wizards.ReportComponent.java
public void saveChartProperties(Report report) { JFreeChart chart = chartComposite.getChart(); if (chart != null) { Map<String, Object> properties = new HashMap<>(); TextTitle title = chart.getTitle(); if (title != null) { properties.put(TITLE, title.getText()); properties.put(TITLEFONT, title.getFont()); properties.put(TITLECOLOR, title.getPaint()); }//from ww w. j a v a2 s .c o m Plot plot = chart.getPlot(); properties.put(BGCOLOR, plot.getBackgroundPaint()); properties.put(OUTLINEPAINT, plot.getOutlinePaint()); properties.put(OUTLINESTROKE, plot.getOutlineStroke()); Axis domainAxis = null; Axis rangeAxis = null; if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; domainAxis = p.getDomainAxis(); rangeAxis = p.getRangeAxis(); properties.put(ORIENTATION, p.getOrientation()); } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; domainAxis = p.getDomainAxis(); rangeAxis = p.getRangeAxis(); properties.put(ORIENTATION, p.getOrientation()); } if (domainAxis != null) saveAxisProperties(domainAxis, "x", properties); //$NON-NLS-1$ if (rangeAxis != null) saveAxisProperties(rangeAxis, "y", properties); //$NON-NLS-1$ properties.put(ANTIALIAS, chart.getAntiAlias()); properties.put(CANVASPAINT, chart.getBackgroundPaint()); report.setProperties(properties); } }