legendpropertyeditpanel.java

来自「JfreeChart 常用图表例子」· Java 代码 · 共 443 行 · 第 1/2 页

JAVA
443
字号
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. * * Project Info:  http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it  * under the terms of the GNU Lesser General Public License as published by  * the Free Software Foundation; either version 2.1 of the License, or  * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public  * License for more details. * * You should have received a copy of the GNU Lesser General Public License  * along with this library; if not, write to the Free Software Foundation,  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * * [Java is a trademark or registered trademark of Sun Microsystems, Inc.  * in the United States and other countries.] * * ---------------------------- * LegendPropertyEditPanel.java * ---------------------------- * (C) Copyright 2000-2004, by Object Refinery Limited. * * Original Author:  David Gilbert; * Contributor(s):   Arnaud Lelievre; *                   Daniel Gredler; * * $Id: LegendPropertyEditPanel.java,v 1.5 2005/03/29 12:56:52 mungady Exp $ * * Changes (from 24-Aug-2001) * -------------------------- * 24-Aug-2001 : Added standard source header. Fixed DOS encoding problem (DG); * 07-Nov-2001 : Separated the JCommon Class Library classes, JFreeChart now  *               requires jcommon.jar (DG); * 25-Jun-2002 : Revised header, removed redundant code (DG); * 08-Sep-2003 : Added internationalization via use of properties  *               resourceBundle (RFE 690236) (AL);  * 24-Aug-2004 : Applied patch 1014378 (DG); * */package org.jfree.chart.ui;import java.awt.BasicStroke;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Font;import java.awt.Paint;import java.awt.Stroke;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ResourceBundle;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JColorChooser;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import org.jfree.chart.JFreeChart;import org.jfree.chart.OldLegend;import org.jfree.chart.DefaultOldLegend;import org.jfree.layout.LCBLayout;import org.jfree.ui.FontChooserPanel;import org.jfree.ui.FontDisplayField;import org.jfree.ui.PaintSample;import org.jfree.ui.StrokeChooserPanel;import org.jfree.ui.StrokeSample;/** * A panel for editing the properties of a {@link OldLegend}. */class LegendPropertyEditPanel extends JPanel implements ActionListener {    /** Whether or not to display the legend on the chart. */    private boolean showLegend;    /** The checkbox to indicate whether or not to display the legend. */    private JCheckBox showLegendCheckBox;    /** The stroke (pen) used to draw the legend outline. */    private StrokeSample outlineStroke;    /** The button used to select the legend outline stroke. */    private JButton selectOutlineStrokeButton;    /** The paint (color) used to draw the legend outline. */    private PaintSample outlinePaint;    /** The button used to select the legend outline color. */    private JButton selectOutlinePaintButton;    /** The paint (color) used to fill the legend background. */    private PaintSample backgroundPaint;    /** The button used to select the legend background color. */    private JButton selectBackgroundPaintButton;    /** The font used to draw the series names. */    private Font seriesFont;    /** The button used to select the series name font. */    private JButton selectSeriesFontButton;    /** The paint (color) used to draw the series names. */    private PaintSample seriesPaint;    /** The button used to select the series name paint. */    private JButton selectSeriesPaintButton;    /** An array of strokes (pens) to select from. */    private StrokeSample[] availableStrokeSamples;    /** A field for displaying the series label font. */    private FontDisplayField fontDisplayField;    /** The resourceBundle for the localization. */    protected static ResourceBundle localizationResources         = ResourceBundle.getBundle("org.jfree.chart.ui.LocalizationBundle");    /**     * Standard constructor: builds a panel based on the specified legend.     * If the specified legend is <tt>null</tt>, the panel will reflect the     * fact that no legend is to be displayed.     *     * @param legend    the legend, which should be changed.     */    public LegendPropertyEditPanel(OldLegend legend) {        DefaultOldLegend l = (legend != null             ? (DefaultOldLegend) legend : new DefaultOldLegend());        this.showLegend = (legend != null);        this.outlineStroke = new StrokeSample(l.getOutlineStroke());        this.outlinePaint = new PaintSample(l.getOutlinePaint());        this.backgroundPaint = new PaintSample(l.getBackgroundPaint());        this.seriesFont = l.getItemFont();        this.seriesPaint = new PaintSample(l.getItemPaint());        this.availableStrokeSamples = new StrokeSample[4];        this.availableStrokeSamples[0]             = new StrokeSample(new BasicStroke(1.0f));        this.availableStrokeSamples[1]             = new StrokeSample(new BasicStroke(2.0f));        this.availableStrokeSamples[2]             = new StrokeSample(new BasicStroke(3.0f));        this.availableStrokeSamples[3]             = new StrokeSample(new BasicStroke(4.0f));        setLayout(new BorderLayout());        JPanel general = new JPanel(new BorderLayout());        general.setBorder(            BorderFactory.createTitledBorder(                BorderFactory.createEtchedBorder(),                 localizationResources.getString("General")            )        );        JPanel interior = new JPanel(new LCBLayout(6));        interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));        interior.add(            new JLabel(localizationResources.getString("Show_Legend"))        );        this.showLegendCheckBox = new JCheckBox();        this.showLegendCheckBox.setSelected(this.showLegend);        this.showLegendCheckBox.setActionCommand("ShowLegend");        this.showLegendCheckBox.addActionListener(this);        interior.add(new JPanel());        interior.add(this.showLegendCheckBox);        interior.add(new JLabel(localizationResources.getString("Outline")));        interior.add(this.outlineStroke);        this.selectOutlineStrokeButton             = new JButton(localizationResources.getString("Select..."));        this.selectOutlineStrokeButton.setActionCommand("OutlineStroke");        this.selectOutlineStrokeButton.addActionListener(this);        interior.add(this.selectOutlineStrokeButton);        interior.add(            new JLabel(localizationResources.getString("Outline_Paint"))        );        this.selectOutlinePaintButton             = new JButton(localizationResources.getString("Select..."));        this.selectOutlinePaintButton.setActionCommand("OutlinePaint");        this.selectOutlinePaintButton.addActionListener(this);        interior.add(this.outlinePaint);        interior.add(this.selectOutlinePaintButton);        interior.add(new JLabel(localizationResources.getString("Background")));        this.selectBackgroundPaintButton = new JButton(            localizationResources.getString("Select...")        );        this.selectBackgroundPaintButton.setActionCommand("BackgroundPaint");        this.selectBackgroundPaintButton.addActionListener(this);        interior.add(this.backgroundPaint);        interior.add(this.selectBackgroundPaintButton);        interior.add(            new JLabel(localizationResources.getString("Series_label_font"))        );        this.selectSeriesFontButton             = new JButton(localizationResources.getString("Select..."));        this.selectSeriesFontButton.setActionCommand("SeriesFont");        this.selectSeriesFontButton.addActionListener(this);        this.fontDisplayField = new FontDisplayField(this.seriesFont);        interior.add(this.fontDisplayField);        interior.add(this.selectSeriesFontButton);        interior.add(            new JLabel(localizationResources.getString("Series_label_paint"))        );        this.selectSeriesPaintButton 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?