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

📄 renderthread.java

📁 一个java版本数据分析显示程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    public int getRenderedRegionStop(){        return lastStop;    }    /**     * The main method of this thread. Runs an infinite loop, waiting for rendering data and      * rendering the data in one or two passes (in progressive mode).     * In low quality mode and the first pass of progressive mode, the thread ignores      * interruptions received during rendering. In second pass progressive mode rendering     * can be interrupted after each record, for example if new data is available or some area     * has been invalidated.     *     * Do not interfere with the thread directly, use render() to signalize that there is something     * new to render.     */    public void run(){        while(true){            synchronized(this){                isWorking = false;                // wait for next rendering to be queued                do {                    try {                        if (! doWork){                            System.out.println("RenderThread: waiting...");                            this.wait();                        }                        //System.out.println("RenderThread: exit waiting.");                    }                    catch (InterruptedException iex){                        System.out.println("RenderThread: interruptedExcpetion.");                        //rendering has been cancelled                    }                }                while (this.interrupted());                isWorking = true;                doWork = false;                renderedImage = null;                qualitychanged = false;            }            //System.out.println("RenderThread: run loop start...");            boolean progress = true;            while (comp != null && progress){                String modestr;                                if (progressive && quality){                    secondPass = true;                                        //System.out.println("RenderThread: starting progressive paint...");                    modestr = "[quality]";                                        //2nd pass: lower priority, keep response time low                    this.yield();                }                else {                    secondPass = false;                                        //System.out.println("RenderThread: starting paint...");                    modestr = "[preview]";                }                // this is the main rendering routine                comp.fireProgressEvent(new ProgressEvent(comp, ProgressEvent.PROGRESS_START, 0.0f, "rendering " + modestr));                BufferedImage img = new BufferedImage(comp.getWidth(), comp.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);                Graphics2D g2 = (Graphics2D)img.getGraphics();                                // render all records                int i = 0;                float brushVal = 0.0f;                Color bgcol = comp.getBackground();                color = comp.getColorPreference("recordColor");                if (brush != null){                    color = brush.getColor();                    bgcol = new Color((int)(0.1*color.getRed()+0.9*bgcol.getRed()), (int)(0.1*color.getGreen()+0.9*bgcol.getGreen()), (int)(0.1*color.getBlue()+0.9*bgcol.getBlue()));                }                setupRendering(g2, quality, stroke, color);                                for (; i<comp.getNumRecords(); i++){                    if (i % 300 == 0){                        comp.fireProgressEvent(new ProgressEvent(comp, ProgressEvent.PROGRESS_UPDATE, ((float)i)/comp.getNumRecords(), "rendering " + modestr));                    }                    if ((brush == null) || (brushVal = brush.getBrushValue(i)) > 0.0f){                        // select records in brushmode, render all in normal mode                        //skip soft edges                        if (!quality && (brush != null) && brushVal < 0.8) continue;                        if ((brush != null) && quality){                            Color col = new Color((int)(color.getRed()*brushVal + bgcol.getRed()*(1-brushVal)), (int)(color.getGreen()*brushVal + bgcol.getGreen()*(1-brushVal)), (int)(color.getBlue()*brushVal + bgcol.getBlue()*(1-brushVal)), (int)(255 * brushVal));                            //System.out.println("Brush value: " + brushVal + " alpha: " + col.getAlpha());                            g2.setColor(col);                        }                                                    if (secondPass) {                            ui.drawRecord(g2, comp, i, progressiveStartAxis, progressiveStopAxis);                        }                        else {                            ui.drawRecord(g2, comp, i, startAxis, stopAxis);                        }                        if (qualitychanged || secondPass){                            //2nd pass: lower priority, keep response time low                            this.yield();                            if (this.interrupted()){                                progressiveInterrupted = true;                                //System.out.println("### breaking!");                                break;                            }                        }                    }                }                if (i==comp.getNumRecords()){                    //finished all records                    wasInterrupted = false;                    renderedImage = img;                    if (secondPass){                        lastStart = progressiveStartAxis;                        lastStop = progressiveStopAxis;                        progressiveInterrupted = false;                    }                    else {                        lastStart = startAxis;                        lastStop = stopAxis;                    }                    comp.fireProgressEvent(new ProgressEvent(comp, ProgressEvent.PROGRESS_FINISH, 1.0f, "rendering " + modestr));                    comp.repaint();                    //System.out.println("RenderThread: paint finished...");                    if (progressive){                        if (quality) {                            quality = false;                            progress = false;                        }                        else {                            quality = true;                        }                    }                    else {                        progress = false;                    }                }                else {                    // we have been interrupted                    //System.out.println("RenderThread: paint interrupted...");                    progress = false;                    if ( secondPass ){                        //2nd pass progressive -> throw away                        wasInterrupted = false;                        quality = false;                    }                }                secondPass = false;            }        }    }            /**     * Starts the rendering. The region to be rendered must be set with setRegion(). If     * there is a high quality rendering in progress it is interrupted.     */    synchronized void render(){        //System.out.println(this.getName() + ".render() called");        if (this.isWorking){            this.interrupt();        }        this.doWork = true;        this.notify();    }        /**     * Throws away the result image and initializes the thread for new rendering.     */    void reset(){        //throw away image        renderedImage = null;    }    /**     * Helper function to set up the graphics object for rendering.     */    private void setupRendering(Graphics2D g2, boolean quality, Stroke stroke, Color color){                RenderingHints qualityHints = new RenderingHints(null);        if (quality) {            qualityHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);            qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);            AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f);            g2.setComposite(ac);            g2.setStroke(stroke);            g2.setColor(color);        }        else {            qualityHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);            qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);                        g2.setStroke(new BasicStroke());            //strip out alpha            g2.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));        }        g2.setRenderingHints(qualityHints);    }}

⌨️ 快捷键说明

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