⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 legendpropertyeditpanel.java

📁 jfreechart安装程序和使用说明
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        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) {
            Legend legend = chart.getLegend();
            if(legend == null) {
                legend = new StandardLegend();
                chart.setLegend(legend);
            }
            if (legend instanceof StandardLegend) {
                // only supports StandardLegend at present
                StandardLegend standard = (StandardLegend) legend;
                standard.setOutlineStroke(getOutlineStroke());
                standard.setOutlinePaint(getOutlinePaint());
                standard.setBackgroundPaint(getBackgroundPaint());
                standard.setItemFont(getSeriesFont());
                standard.setItemPaint(getSeriesPaint());
            }
            else {
                // raise exception - unrecognised legend
            }
        }
        else {
            chart.setLegend(null);
        }
    }

}

⌨️ 快捷键说明

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