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

📄 dialpointer.java

📁 用于制作报表的中间件控件,纯java编写,还附带有数据库操作的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
         */
        public Stroke getStroke() {
            return this.stroke;
        }
        
        /**
         * Sets the stroke and sends a {@link DialLayerChangeEvent} to all 
         * registered listeners.
         * 
         * @param stroke  the stroke (<code>null</code> not permitted).
         * 
         * @see #getStroke()
         */
        public void setStroke(Stroke stroke) {
            if (stroke == null) {
                throw new IllegalArgumentException("Null 'stroke' argument.");
            }
            this.stroke = stroke;
            notifyListeners(new DialLayerChangeEvent(this));
        }
        
        /**
         * Draws the pointer.
         * 
         * @param g2  the graphics target.
         * @param plot  the plot.
         * @param frame  the dial's reference frame.
         * @param view  the dial's view.
         */
        public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
            Rectangle2D view) {
        
            g2.setPaint(this.paint);
            g2.setStroke(this.stroke);
            Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, 
                    this.radius, this.radius);

            double value = plot.getValue(this.datasetIndex);
            DialScale scale = plot.getScaleForDataset(this.datasetIndex);
            double angle = scale.valueToAngle(value);
        
            Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
            Point2D pt = arc.getEndPoint();
        
            Line2D line = new Line2D.Double(frame.getCenterX(), 
                    frame.getCenterY(), pt.getX(), pt.getY());
            g2.draw(line);
        }
        
        /**
         * Tests this pointer 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 DialPointer.Pin)) {
                return false;
            }
            DialPointer.Pin that = (DialPointer.Pin) obj;
            if (!PaintUtilities.equal(this.paint, that.paint)) {
                return false;
            }
            if (!this.stroke.equals(that.stroke)) {
                return false;
            }
            return super.equals(obj);
        }
        
        /**
         * Returns a hash code for this instance.
         * 
         * @return A hash code.
         */
        public int hashCode() {
            int result = super.hashCode();
            result = HashUtilities.hashCode(result, this.paint);
            result = HashUtilities.hashCode(result, this.stroke);
            return result;
        }
        
        /**
         * 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.paint, stream);
            SerialUtilities.writeStroke(this.stroke, 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.paint = SerialUtilities.readPaint(stream);
            this.stroke = SerialUtilities.readStroke(stream);
        }
        
    }
    
    /**
     * A dial pointer.
     */
    public static class Pointer extends DialPointer {
        
        /** For serialization. */
        static final long serialVersionUID = -4180500011963176960L;
        
        /**
         * The radius that defines the width of the pointer at the base.
         */
        private double widthRadius;
    
        /**
         * Creates a new instance.
         */
        public Pointer() {
            this(0);
        }
        
        /**
         * Creates a new instance.
         * 
         * @param datasetIndex  the dataset index.
         */
        public Pointer(int datasetIndex) {
            super(datasetIndex);
            this.widthRadius = 0.05;
        }
        
        /**
         * Returns the width radius.
         * 
         * @return The width radius.
         * 
         * @see #setWidthRadius(double)
         */
        public double getWidthRadius() {
            return this.widthRadius;
        }
        
        /**
         * Sets the width radius and sends a {@link DialLayerChangeEvent} to 
         * all registered listeners.
         * 
         * @param radius  the radius
         * 
         * @see #getWidthRadius()
         */
        public void setWidthRadius(double radius) {
            this.widthRadius = radius;
            notifyListeners(new DialLayerChangeEvent(this));
        }
        
        /**
         * Draws the pointer.
         * 
         * @param g2  the graphics target.
         * @param plot  the plot.
         * @param frame  the dial's reference frame.
         * @param view  the dial's view.
         */
        public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
                Rectangle2D view) {
        
            g2.setPaint(Color.blue);
            g2.setStroke(new BasicStroke(1.0f));
            Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, 
                    this.radius, this.radius);
            Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, 
                    this.widthRadius, this.widthRadius);
            double value = plot.getValue(this.datasetIndex);
            DialScale scale = plot.getScaleForDataset(this.datasetIndex);
            double angle = scale.valueToAngle(value);
        
            Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN);
            Point2D pt1 = arc1.getEndPoint();
            Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0, 
                    Arc2D.OPEN);
            Point2D pt2 = arc2.getStartPoint();
            Point2D pt3 = arc2.getEndPoint();
            Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0, 
                    Arc2D.OPEN);
            Point2D pt4 = arc3.getStartPoint();
        
            GeneralPath gp = new GeneralPath();
            gp.moveTo((float) pt1.getX(), (float) pt1.getY());
            gp.lineTo((float) pt2.getX(), (float) pt2.getY());
            gp.lineTo((float) pt4.getX(), (float) pt4.getY());
            gp.lineTo((float) pt3.getX(), (float) pt3.getY());
            gp.closePath();
            g2.setPaint(Color.gray);
            g2.fill(gp);
        
            g2.setPaint(Color.black);
            Line2D line = new Line2D.Double(frame.getCenterX(), 
                    frame.getCenterY(), pt1.getX(), pt1.getY());
            g2.draw(line);
        
            line.setLine(pt2, pt3);
            g2.draw(line);
        
            line.setLine(pt3, pt1);
            g2.draw(line);
        
            line.setLine(pt2, pt1);
            g2.draw(line);
        
            line.setLine(pt2, pt4);
            g2.draw(line);

            line.setLine(pt3, pt4);
            g2.draw(line);
        }
        
        /**
         * Tests this pointer 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 DialPointer.Pointer)) {
                return false;
            }
            DialPointer.Pointer that = (DialPointer.Pointer) obj;
            
            if (this.widthRadius != that.widthRadius) {
                return false;
            }
            return super.equals(obj);
        }
        
        /**
         * Returns a hash code for this instance.
         * 
         * @return A hash code.
         */
        public int hashCode() {
            int result = super.hashCode();
            result = HashUtilities.hashCode(result, this.widthRadius);
            return result;
        }
       
    }

}

⌨️ 快捷键说明

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