legendpropertyeditpanel.java

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

JAVA
443
字号
            = new JButton(localizationResources.getString("Select..."));        this.selectSeriesPaintButton.setActionCommand("SeriesPaint");        this.selectSeriesPaintButton.addActionListener(this);        interior.add(this.seriesPaint);        interior.add(this.selectSeriesPaintButton);        this.enableOrDisableControls();        general.add(interior);        add(general, BorderLayout.NORTH);    }    /**     * Returns the current outline stroke.     *     * @return The current outline stroke.     */    public Stroke getOutlineStroke() {        return this.outlineStroke.getStroke();    }    /**     * Returns the current outline paint.     *     * @return The current outline paint.     */    public Paint getOutlinePaint() {        return this.outlinePaint.getPaint();    }    /**     * Returns the current background paint.     *     * @return The current background paint.     */    public Paint getBackgroundPaint() {        return this.backgroundPaint.getPaint();    }    /**     * Returns the current series label font.     *     * @return The current series label font.     */    public Font getSeriesFont() {        return this.seriesFont;    }    /**     * Returns the current series label paint.     *     * @return The current series label paint.     */    public Paint getSeriesPaint() {        return this.seriesPaint.getPaint();    }    /**     * Handles user interactions with the panel.     *     * @param event  the event.     */    public void actionPerformed(ActionEvent event) {        String command = event.getActionCommand();        if (command.equals("OutlineStroke")) {            attemptModifyOutlineStroke();        }        else if (command.equals("OutlinePaint")) {            attemptModifyOutlinePaint();        }        else if (command.equals("BackgroundPaint")) {            attemptModifyBackgroundPaint();        }        else if (command.equals("SeriesFont")) {            attemptModifySeriesFont();        }        else if (command.equals("SeriesPaint")) {            attemptModifySeriesPaint();        }        else if (command.equals("ShowLegend")) {            attemptModifyShowLegend();        }    }    /**     * Allows the user the opportunity to change the outline stroke.     */    private void attemptModifyOutlineStroke() {        StrokeChooserPanel panel = new StrokeChooserPanel(            this.outlineStroke, this.availableStrokeSamples        );        int result = JOptionPane.showConfirmDialog(            this, panel,             localizationResources.getString("Pen_Stroke_Selection"),            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE        );        if (result == JOptionPane.OK_OPTION) {            this.outlineStroke.setStroke(panel.getSelectedStroke());        }    }    /**     * Allows the user the opportunity to change the outline paint.     */    private void attemptModifyOutlinePaint() {        Color c;        c = JColorChooser.showDialog(            this, localizationResources.getString("Outline_Color"),            Color.blue        );        if (c != null) {            this.outlinePaint.setPaint(c);        }    }    /**     * Allows the user the opportunity to change the background paint.     */    private void attemptModifyBackgroundPaint() {        Color c;        c = JColorChooser.showDialog(            this, localizationResources.getString("Background_Color"),            Color.blue        );        if (c != null) {            this.backgroundPaint.setPaint(c);        }    }    /**     * Allows the user the opportunity to change the series label font.     */    public void attemptModifySeriesFont() {        FontChooserPanel panel = new FontChooserPanel(this.seriesFont);        int result = JOptionPane.showConfirmDialog(            this, panel, localizationResources.getString("Font_Selection"),            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE        );        if (result == JOptionPane.OK_OPTION) {            this.seriesFont = panel.getSelectedFont();            this.fontDisplayField.setText(                this.seriesFont.getFontName() + ", " + this.seriesFont.getSize()            );        }    }    /**     * Allows the user the opportunity to change the series label paint.     */    private void attemptModifySeriesPaint() {        Color c;        c = JColorChooser.showDialog(            this, localizationResources.getString("Series_Label_Color"),            Color.blue        );        if (c != null) {            this.seriesPaint.setPaint(c);        }    }    /**     * Allow the user the opportunity to change whether the legend is     * displayed on the chart or not.     */    private void attemptModifyShowLegend() {        this.showLegend = this.showLegendCheckBox.isSelected();        this.enableOrDisableControls();    }    /**     * If we are supposed to show the legend, the controls are enabled.     * If we are not supposed to show the legend, the controls are disabled.     */    private void enableOrDisableControls() {        boolean enabled = (this.showLegend == true);        this.selectOutlineStrokeButton.setEnabled(enabled);        this.selectOutlinePaintButton.setEnabled(enabled);        this.selectBackgroundPaintButton.setEnabled(enabled);        this.selectSeriesFontButton.setEnabled(enabled);        this.selectSeriesPaintButton.setEnabled(enabled);    }    /**     * Sets the properties of the specified legend to match the properties     * defined on this panel.     *     * @param chart    the chart whose legend is to be modified.     */    public void setLegendProperties(JFreeChart chart) {        if (this.showLegend) {            OldLegend legend = chart.getOldLegend();            if (legend == null) {                legend = new DefaultOldLegend();                chart.setOldLegend(legend);            }            if (legend instanceof DefaultOldLegend) {                // only supports StandardLegend at present                DefaultOldLegend standard = (DefaultOldLegend) legend;                standard.setOutlineStroke(getOutlineStroke());                standard.setOutlinePaint(getOutlinePaint());                standard.setBackgroundPaint(getBackgroundPaint());                standard.setItemFont(getSeriesFont());                standard.setItemPaint(getSeriesPaint());            }            else {                // raise exception - unrecognised legend            }        }        else {            chart.setOldLegend(null);        }    }}

⌨️ 快捷键说明

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