📄 renderthread.java
字号:
/*Copyright (c) 2001, 2002, 2003 Flo Ledermann <flo@subnet.at>This file is part of parvis - a parallel coordiante based data visualisationtool written in java. You find parvis and additional information on itswebsite at http://www.mediavirus.org/parvis.parvis is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.parvis is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with parvis (in the file LICENSE.txt); if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/package org.mediavirus.parvis.gui;import java.awt.*;import java.awt.image.*;import org.mediavirus.parvis.model.Brush;/** * * @author Flo Ledermann flo@subnet.at * @version 0.2 */class RenderThread extends Thread { /* flags to control rendering */ /** whether we are in quality rendering mode */ boolean quality = false; /** whether we should do progressive rendering */ boolean progressive = false; /* flags to indicate thread state */ /** the thread is currently doing some work */ boolean isWorking = false; /** the thread is waiting but there is work to do */ boolean doWork = false; /** the last rendering loop has been interrupted */ boolean wasInterrupted = false; /** the 2nd pass of progressive rendering has been interrupted */ boolean progressiveInterrupted = false; /** thread is in second pass of progressive rendering */ boolean secondPass = false; /** the quality settings of the thread have changed */ boolean qualitychanged = false; /** start and stop axis of the region to be rendered */ int startAxis, stopAxis; /** start and stop axis of the quality rendering in progressive mode */ int progressiveStartAxis, progressiveStopAxis; /** the last region that was rendered successfully */ int lastStart = 0; int lastStop = 0; /** ids of the brushed records */ //int ids[] = null; /** the result image */ BufferedImage renderedImage = null; /** the stroke setting for painting records */ Stroke stroke = new BasicStroke(); /** the color setting for painting records */ Color color = Color.black; /** our parents ui delegate */ BasicParallelDisplayUI ui = null; /** our parent compontent */ ParallelDisplay comp = null; Brush brush = null; /** * Creates a new RenderThread for the given ui delegate. * * @param ui The BasicParallelDisplayUI this thread should render. */ RenderThread(BasicParallelDisplayUI ui){ this.ui = ui; this.setPriority(Thread.MIN_PRIORITY); } /** * Helper function to set the component to get the data. * * @param comp The ParallelDisplay component this thread renders. */ void setCurrentComponent(ParallelDisplay comp){ this.comp = comp; } /** * Toggles brush mode for this thread. If brush mode is true, this thread * renders the overlay image with brushed records. * * @param brushMode A boolean indicating whether this thread renders the brush display. */ void setBrush(Brush brush){ this.brush = brush; } /** * Sets the render quality and progressive mode settings of this thread. * * @param quality A boolean indicating whether this thread should render optimized for * quality (true) or speed (false). * @param progressive A boolean indicating whether this thread should render in progressive * mode. If set to true, the image is rendered in two passes: the first pass optimized * for speed (preview), the socond pass optimized for quality. If set to false, the * quality parameter determines rendering quality. */ void setQuality(boolean quality, boolean progressive){ this.progressive = progressive; if (progressive) this.quality = false; else { if (this.quality != quality){ qualitychanged = true; this.quality = quality; } } } /** * Sets the region that this thread should render. This method invalidates the given * region and tells the renderer to include it in the next rendering loop. If there is * another invalidated region, the region rendered in the next pass is expanded to include * all areas that are now invalidated. * * @param startAxis The start axis of the region to be rendered. * @param stopAxis The end axis of the region to be rendered. */ synchronized void setRegion(int startAxis, int stopAxis){ if (wasInterrupted || ((isWorking || doWork) && !secondPass) || (isWorking && secondPass && doWork)){ // old render area still invalid -> expand if (startAxis < this.startAxis) this.startAxis = startAxis; if (stopAxis > this.stopAxis) this.stopAxis = stopAxis; if (startAxis < this.progressiveStartAxis) this.progressiveStartAxis = startAxis; if (stopAxis > this.progressiveStopAxis) this.progressiveStopAxis = stopAxis; } else if (progressiveInterrupted || (isWorking || doWork)){ this.startAxis = startAxis; this.stopAxis = stopAxis; if (startAxis < this.progressiveStartAxis) this.progressiveStartAxis = startAxis; if (stopAxis > this.progressiveStopAxis) this.progressiveStopAxis = stopAxis; } else { this.startAxis = startAxis; this.stopAxis = stopAxis; this.progressiveStartAxis = startAxis; this.progressiveStopAxis = stopAxis; } //this.ids = ids.clone(); //System.out.println("RenderThread: setting repaint axes: " + this.startAxis + ", " + this.stopAxis); } /** * Sets the style how records are painted. * * @param stroke A Stroke object containing information about line style, width etc. * @param color The Color to be used to paint the records. */ void setStyle(Stroke stroke, Color color){ this.stroke = stroke; this.color = color; } /** * Indicates whether this thread is doing some work right now. * * @return true if this thread is currently rendering. */ synchronized boolean isWorking(){ return isWorking; } /** * Returns the last rendered image this thread has finished rendering. Note that the image contains * only those pixels between the last startAxis and stopAxis. All other pixels are transparent. * * @return A BufferedImage with the rendered area. */ public BufferedImage getRenderedImage(){ return renderedImage; } /** * Returns the start axis of the rendered image. * * @return The start axis of the rendered image. */ public int getRenderedRegionStart(){ return lastStart; } /** * Returns the stop axis of the rendered image. * * @return The stop axis of the rendered image.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -