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

📄 standarddialscale.java

📁 java图形利器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *     * @see #setMinorTickCount(int)     */    public int getMinorTickCount() {        return this.minorTickCount;    }        /**     * Sets the number of minor tick marks between major tick marks.     *     * @param count  the count.     *     * @see #getMinorTickCount()     */    public void setMinorTickCount(int count) {        // TODO: validation        this.minorTickCount = count;        notifyListeners(new DialLayerChangeEvent(this));    }        /**     * Returns the length factor for the minor tick marks.  The value is     * subtracted from the tick radius to determine the inner starting point     * for the tick marks.     *     * @return The length factor.     *     * @see #setMinorTickLength(double)     */    public double getMinorTickLength() {        return this.minorTickLength;    }        /**     * Sets the length factor for the minor tick marks.     *     * @param length  the length.     *     * @see #getMinorTickLength()     */    public void setMinorTickLength(double length) {        // TODO: validation        this.minorTickLength = length;        notifyListeners(new DialLayerChangeEvent(this));    }        /**     * Returns the tick label offset.     *     * @return The tick label offset.     *     * @see #setTickLabelOffset(double)     */    public double getTickLabelOffset() {        return this.tickLabelOffset;    }        /**     * Sets the tick label offset.     *     * @param offset  the offset.     *     * @see #getTickLabelOffset()     */    public void setTickLabelOffset(double offset) {        this.tickLabelOffset = offset;        notifyListeners(new DialLayerChangeEvent(this));    }        /**     * Returns the font used to draw the tick labels.     *     * @return The font (never <code>null</code>).     *     * @see #setTickLabelFont(Font)     */    public Font getTickLabelFont() {        return this.tickLabelFont;    }        /**     * Sets the font used to display the tick labels.     *     * @param font  the font (<code>null</code> not permitted).     *     * @see #getTickLabelFont()     */    public void setTickLabelFont(Font font) {        if (font == null) {            throw new IllegalArgumentException("Null 'font' argument.");        }        this.tickLabelFont = font;        notifyListeners(new DialLayerChangeEvent(this));    }        /**     * Returns the paint used to draw the tick labels.     *     * @return The paint (<code>null</code> not permitted).     */    public Paint getTickLabelPaint() {        return this.tickLabelPaint;    }        /**     * Sets the paint used to draw the tick labels.     *     * @param paint  the paint (<code>null</code> not permitted).     */    public void setTickLabelPaint(Paint paint) {        // TODO: validation        this.tickLabelPaint = paint;        notifyListeners(new DialLayerChangeEvent(this));    }        /**     * Returns <code>true</code> if the tick labels should be displayed,     * and <code>false</code> otherwise.     *      * @return A boolean.     */    public boolean getTickLabelsVisible() {        return this.tickLabelsVisible;    }        /**     * Sets the flag that controls whether or not the tick labels are     * displayed, and sends a {@link DialLayerChangeEvent} to all registered     * listeners.     *      * @param visible  the new flag value.     */    public void setTickLabelsVisible(boolean visible) {        this.tickLabelsVisible = visible;        notifyListeners(new DialLayerChangeEvent(this));    }        /**     * Returns a flag that controls whether or not the first tick label is     * visible.     *      * @return A boolean.     */    public boolean getFirstTickLabelVisible() {        return this.firstTickLabelVisible;    }        /**     * Sets a flag that controls whether or not the first tick label is      * visible, and sends a {@link DialLayerChangeEvent} to all registered     * listeners.     *      * @param visible  the new flag value.     */    public void setFirstTickLabelVisible(boolean visible) {        this.firstTickLabelVisible = visible;        notifyListeners(new DialLayerChangeEvent(this));    }        /**     * Returns <code>true</code> to indicate that this layer should be      * clipped within the dial window.      *      * @return <code>true</code>.     */    public boolean isClippedToWindow() {        return true;    }        /**     * Draws the scale on the dial plot.     *     * @param g2  the graphics target (<code>null</code> not permitted).     * @param plot  the dial plot (<code>null</code> not permitted).     * @param frame  the reference frame that is used to construct the     *     geometry of the plot (<code>null</code> not permitted).     * @param view  the visible part of the plot (<code>null</code> not      *     permitted).     */    public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,             Rectangle2D view) {                Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,                 this.tickRadius, this.tickRadius);        Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame,                 this.tickRadius - this.minorTickLength,                 this.tickRadius - this.minorTickLength);        Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame,                 this.tickRadius - this.tickLabelOffset,                 this.tickRadius - this.tickLabelOffset);                boolean firstLabel = true;                Arc2D arc = new Arc2D.Double();        for (double v = this.lowerBound; v <= this.upperBound;                 v += this.majorTickIncrement) {            arc.setArc(arcRect, this.startAngle, valueToAngle(v)                     - this.startAngle, Arc2D.OPEN);            Point2D pt0 = arc.getEndPoint();            arc.setArc(arcRectInner, this.startAngle, valueToAngle(v)                     - this.startAngle, Arc2D.OPEN);            Point2D pt1 = arc.getEndPoint();            g2.setPaint(this.majorTickPaint);            g2.setStroke(this.majorTickStroke);            g2.draw(new Line2D.Double(pt0, pt1));            arc.setArc(arcRectForLabels, this.startAngle, valueToAngle(v)                     - this.startAngle, Arc2D.OPEN);            Point2D pt2 = arc.getEndPoint();                        if (tickLabelsVisible) {                if (!firstLabel || this.firstTickLabelVisible) {                    g2.setFont(this.tickLabelFont);                    TextUtilities.drawAlignedString(String.valueOf(v), g2,                             (float) pt2.getX(), (float) pt2.getY(),                             TextAnchor.CENTER);                }            }            firstLabel = false;                        // now do the minor tick marks            if (this.minorTickCount > 0) {                double minorTickIncrement = this.majorTickIncrement                         / (this.minorTickCount + 1);                for (int i = 0; i < this.minorTickCount; i++) {                    double vv = v + ((i + 1) * minorTickIncrement);                    if (vv >= this.upperBound) {                        break;                    }                    double angle = valueToAngle(vv);                                       arc.setArc(arcRect, this.startAngle, angle                             - this.startAngle, Arc2D.OPEN);                    pt0 = arc.getEndPoint();                    arc.setArc(arcRectInner, this.startAngle, angle                             - this.startAngle, Arc2D.OPEN);                    Point2D pt3 = arc.getEndPoint();                    g2.setStroke(new BasicStroke(1.0f));                    g2.draw(new Line2D.Double(pt0, pt3));                }            }                    }    }        /**     * Converts a data value to an angle against this scale.     *     * @param value  the data value.     *     * @return The angle (in degrees, using the same specification as Java's     *     Arc2D class).     */    public double valueToAngle(double value) {        double range = this.upperBound - this.lowerBound;        double unit = this.extent / range;        return this.startAngle + unit * (value - this.lowerBound);            }    public double angleToValue(double angle) {        return Double.NaN;  // FIXME    }    /**     * Tests this <code>StandardDialScale</code> for equality with an arbitrary     * object.     *     * @param obj  the object (<code>null</code> permitted).     *     * @return A boolean.     */    public boolean equals(Object obj) {        if (obj == this) {            return true;        }            if (!(obj instanceof StandardDialScale)) {            return false;        }        StandardDialScale that = (StandardDialScale) obj;        if (this.lowerBound != that.lowerBound) {            return false;        }        if (this.upperBound != that.upperBound) {            return false;        }        if (this.startAngle != that.startAngle) {            return false;        }        if (this.extent != that.extent) {            return false;        }        if (this.tickRadius != that.tickRadius) {            return false;        }        if (this.majorTickIncrement != that.majorTickIncrement) {            return false;        }        if (this.majorTickLength != that.majorTickLength) {            return false;        }        if (!PaintUtilities.equal(this.majorTickPaint, that.majorTickPaint)) {            return false;        }        if (!this.majorTickStroke.equals(that.majorTickStroke)) {            return false;        }        if (this.minorTickCount != that.minorTickCount) {            return false;        }        if (this.minorTickLength != that.minorTickLength) {            return false;        }        if (this.tickLabelOffset != that.tickLabelOffset) {            return false;        }        if (!this.tickLabelFont.equals(that.tickLabelFont)) {            return false;        }        if (!PaintUtilities.equal(this.tickLabelPaint, that.tickLabelPaint)) {            return false;        }        return true;    }    /**     * Returns a clone of this instance.     *      * @return A clone.     *      * @throws CloneNotSupportedException if this instance is not cloneable.     */    public Object clone() throws CloneNotSupportedException {         return super.clone();    }        /**     * Provides serialization support.     *     * @param stream  the output stream.     *     * @throws IOException  if there is an I/O error.     */    private void writeObject(ObjectOutputStream stream) throws IOException {        stream.defaultWriteObject();        SerialUtilities.writePaint(this.majorTickPaint, stream);        SerialUtilities.writeStroke(this.majorTickStroke, stream);        SerialUtilities.writePaint(this.tickLabelPaint, stream);    }    /**     * Provides serialization support.     *     * @param stream  the input stream.     *     * @throws IOException  if there is an I/O error.     * @throws ClassNotFoundException  if there is a classpath problem.     */    private void readObject(ObjectInputStream stream)             throws IOException, ClassNotFoundException {        stream.defaultReadObject();        this.majorTickPaint = SerialUtilities.readPaint(stream);        this.majorTickStroke = SerialUtilities.readStroke(stream);        this.tickLabelPaint = SerialUtilities.readPaint(stream);    }}

⌨️ 快捷键说明

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