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

📄 meterplot.java

📁 大家打开看看啊, 很有用的东西
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     *
     * @return The paint.
     */
    public Paint getWarningPaint() {
        return this.warningPaint;
    }

    /**
     * Sets the paint used to display the 'warning' range.
     * <P>
     * If you set this to null, it will revert to the default color.
     *
     * @param paint The paint.
     */
    public void setWarningPaint(Paint paint) {
        this.warningPaint = (paint == null) ? DEFAULT_WARNING_PAINT : paint;
        notifyListeners(new PlotChangeEvent(this));
    }

    /**
     * Returns the paint used to display the 'critical' range.
     *
     * @return The paint.
     */
    public Paint getCriticalPaint() {
        return this.criticalPaint;
    }

    /**
     * Sets the paint used to display the 'critical' range.
     * <P>
     * If you set this to null, it will revert to the default color.
     *
     * @param paint The paint.
     */
    public void setCriticalPaint(Paint paint) {
        this.criticalPaint = (paint == null) ? DEFAULT_CRITICAL_PAINT : paint;
        notifyListeners(new PlotChangeEvent(this));
    }

    /**
     * Returns the tick label type.  Defined by the constants: NO_LABELS,
     * VALUE_LABELS.
     *
     * @return The tick label type.
     */
    public int getTickLabelType() {
        return this.tickLabelType;
    }

    /**
     * Sets the tick label type.
     *
     * @param type  the type of tick labels - either <code>NO_LABELS</code> or
     *      <code>VALUE_LABELS</code>
     */
    public void setTickLabelType(int type) {

        // check the argument...
        if ((type != NO_LABELS) && (type != VALUE_LABELS)) {
            throw new IllegalArgumentException(
                "MeterPlot.setLabelType(int): unrecognised type.");
        }

        // make the change...
        if (tickLabelType != type) {
            this.tickLabelType = type;
            notifyListeners(new PlotChangeEvent(this));
        }

    }

    /**
     * Returns the tick label font.
     *
     * @return The tick label font.
     */
    public Font getTickLabelFont() {
        return this.tickLabelFont;
    }

    /**
     * Sets the tick label font and notifies registered listeners that the plot has been changed.
     *
     * @param font  The new tick label font.
     */
    public void setTickLabelFont(Font font) {

        // check arguments...
        if (font == null) {
            throw new IllegalArgumentException(
                "MeterPlot.setTickLabelFont(...): null font not allowed.");
        }

        // make the change...
        if (!this.tickLabelFont.equals(font)) {
            this.tickLabelFont = font;
            notifyListeners(new PlotChangeEvent(this));
        }

    }

    /**
     * Returns a flag that controls whether or not a rectangular border is drawn around the plot
     * area.
     *
     * @return A flag.
     */
    public boolean getDrawBorder() {
        return this.drawBorder;
    }

    /**
     * Sets the flag that controls whether or not a rectangular border is drawn around the plot
     * area.
     * <P>
     * Note:  it looks like the true setting needs some work to provide some insets.
     *
     * @param draw The flag.
     */
    public void setDrawBorder(boolean draw) {
        this.drawBorder = draw;
    }

    /**
     * Returns the meter angle.
     *
     * @return the meter angle.
     */
    public int getMeterAngle() {
        return this.meterAngle;
    }

    /**
     * Sets the range through which the dial's needle is free to rotate.
     *
     * @param angle  the angle.
     */
    public void setMeterAngle(int angle) {
        this.meterAngle = angle;
        notifyListeners(new PlotChangeEvent(this));
    }

    /**
     * Returns the color of the border for the dial.
     *
     * @return the color of the border for the dial.
     */
    public Color getDialBorderColor() {
        return this.dialBorderColor;
    }

    /**
     * Sets the color for the border of the dial.
     *
     * @param color  the color.
     */
    public void setDialBorderColor(Color color) {
        this.dialBorderColor = color;
    }

    /**
     * Returns the primary dataset for the plot.
     * 
     * @return The primary dataset (possibly <code>null</code>).
     */
    public MeterDataset getDataset() {
        return this.dataset;
    }
    
    /**
     * Sets the dataset for the plot, replacing the existing dataset if there is one.
     * 
     * @param dataset  the dataset (<code>null</code> permitted).
     */
    public void setDataset(MeterDataset dataset) {
        
        // if there is an existing dataset, remove the plot from the list of change listeners...
        MeterDataset existing = this.dataset;
        if (existing != null) {
            existing.removeChangeListener(this);
        }

        // set the new dataset, and register the chart as a change listener...
        this.dataset = dataset;
        if (dataset != null) {
            setDatasetGroup(dataset.getGroup());
            dataset.addChangeListener(this);
        }

        // send a dataset change event to self...
        DatasetChangeEvent event = new DatasetChangeEvent(this, dataset);
        datasetChanged(event);
        
    }



    /**
     * Returns the dataset for the plot, cast as a MeterDataset.
     * <P>
     * Provided for convenience.
     *
     * @return the dataset for the plot, cast as a MeterDataset.
     */
    public MeterDataset getMeterDataset() {
        return (MeterDataset) getDataset();
    }

    /**
     * Returns a list of legend item labels.
     *
     * @return the legend item labels.
     *
     * @deprecated use getLegendItems().
     */
    public List getLegendItemLabels() {
        return null;
    }

    /**
     * Returns null.
     *
     * @return null.
     */
    public LegendItemCollection getLegendItems() {
        return null;
    }

    /**
     * Draws the plot on a Java 2D graphics device (such as the screen or a printer).
     *
     * @param g2  The graphics device.
     * @param plotArea  The area within which the plot should be drawn.
     * @param info  Collects info about the drawing.
     */
    public void draw(Graphics2D g2, Rectangle2D plotArea, ChartRenderingInfo info) {

        if (info != null) {
            info.setPlotArea(plotArea);
        }

        // adjust for insets...
        Insets insets = getInsets();
        if (insets != null) {
            plotArea.setRect(plotArea.getX() + insets.left,
                             plotArea.getY() + insets.top,
                             plotArea.getWidth() - insets.left - insets.right,
                             plotArea.getHeight() - insets.top - insets.bottom);
        }

        plotArea.setRect(plotArea.getX() + 4,
                         plotArea.getY() + 4,
                         plotArea.getWidth() - 8,
                         plotArea.getHeight() - 8);

        // draw the background
        if (drawBorder) {
            drawBackground(g2, plotArea);
        }

        // adjust the plot area by the interior spacing value
        double gapHorizontal = (2 * DEFAULT_BORDER_SIZE);
        double gapVertical = (2 * DEFAULT_BORDER_SIZE);
        double meterX = plotArea.getX() + gapHorizontal / 2;
        double meterY = plotArea.getY() + gapVertical / 2;
        double meterW = plotArea.getWidth() - gapHorizontal;
        double meterH = plotArea.getHeight() - gapVertical
                        + ((meterAngle <= 180) && (dialType != DIALTYPE_CIRCLE)
                           ? plotArea.getHeight() / 1.25 : 0);

        double min = Math.min(meterW, meterH) / 2;
        meterX = (meterX + meterX + meterW) / 2 - min;
        meterY = (meterY + meterY + meterH) / 2 - min;
        meterW = 2 * min;
        meterH = 2 * min;

        Rectangle2D meterArea = new Rectangle2D.Double(meterX,
                                                       meterY,
                                                       meterW,
                                                       meterH);

        Rectangle2D.Double originalArea = new Rectangle2D.Double(meterArea.getX() - 4,
                                                                 meterArea.getY() - 4,
                                                                 meterArea.getWidth() + 8,
                                                                 meterArea.getHeight() + 8);

        double meterMiddleX = meterArea.getCenterX();
        double meterMiddleY = meterArea.getCenterY();

        // plot the data (unless the dataset is null)...
        MeterDataset data = getMeterDataset();
        if (data != null) {
            double dataMin = data.getMinimumValue().doubleValue();
            double dataMax = data.getMaximumValue().doubleValue();
            minMeterValue = dataMin;

            meterCalcAngle = 180 + ((meterAngle - 180) / 2);
            meterRange = dataMax - dataMin;

            Shape savedClip = g2.getClip();
            g2.clip(originalArea);
            Composite originalComposite = g2.getComposite();
            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
                                                       getForegroundAlpha()));

            drawArc(g2, originalArea, dataMin, dataMax, this.dialBackgroundPaint, 1);
            drawTicks(g2, meterArea, dataMin, dataMax);
            drawArcFor(g2, meterArea, data, MeterDataset.FULL_DATA);
            drawArcFor(g2, meterArea, data, MeterDataset.NORMAL_DATA);
            drawArcFor(g2, meterArea, data, MeterDataset.WARNING_DATA);
            drawArcFor(g2, meterArea, data, MeterDataset.CRITICAL_DATA);

            if (data.isValueValid()) {

                double dataVal = data.getValue().doubleValue();
                drawTick(g2, meterArea, dataVal, true, this.valuePaint, true, data.getUnits());

                g2.setPaint(this.needlePaint);
                g2.setStroke(new BasicStroke(2.0f));

                double radius = (meterArea.getWidth() / 2) + DEFAULT_BORDER_SIZE + 15;
                double valueAngle = calculateAngle(dataVal);
                double valueP1 = meterMiddleX + (radius * Math.cos(Math.PI * (valueAngle / 180)));
                double valueP2 = meterMiddleY - (radius * Math.sin(Math.PI * (valueAngle / 180)));

                Polygon arrow = new Polygon();
                if ((valueAngle > 135 && valueAngle < 225)
                    || (valueAngle < 45 && valueAngle > -45)) {

                    double valueP3 = (meterMiddleY - DEFAULT_CIRCLE_SIZE / 4);
                    double valueP4 = (meterMiddleY + DEFAULT_CIRCLE_SIZE / 4);
                    arrow.addPoint((int) meterMiddleX, (int) valueP3);
                    arrow.addPoint((int) meterMiddleX, (int) valueP4);

                }
                else {
                    arrow.addPoint((int) (meterMiddleX - DEFAULT_CIRCLE_SIZE / 4),

⌨️ 快捷键说明

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