DetailPaintThread.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.traceviewer.main;
00002 
00003 import java.util.Queue;
00004 import java.util.concurrent.atomic.AtomicInteger;
00005 
00006 import org.eclipse.swt.graphics.Color;
00007 import org.eclipse.swt.graphics.GC;
00008 import org.eclipse.swt.graphics.Image;
00009 import org.eclipse.swt.graphics.Device;
00010 import org.eclipse.swt.graphics.Point;
00011 
00012 import edu.rice.cs.hpc.traceviewer.data.db.BaseDataVisualization;
00013 import edu.rice.cs.hpc.traceviewer.data.db.TimelineDataSet;
00014 import edu.rice.cs.hpc.traceviewer.data.util.Constants;
00015 import edu.rice.cs.hpc.traceviewer.painter.BasePaintThread;
00016 import edu.rice.cs.hpc.traceviewer.painter.ImagePosition;
00017 import edu.rice.cs.hpc.traceviewer.spaceTimeData.SpaceTimeDataController;
00018 
00019 /*****************************************************************
00020  * 
00021  * Thread class to paint a set of data into a set of images
00022  * Once the object terminates, it will return the list of images to 
00023  * be visualized in a view
00024  *
00025  *****************************************************************/
00026 public class DetailPaintThread 
00027     extends BasePaintThread
00028 {
00029     final private boolean debugMode;
00030 
00031     final private Point maxTextSize;
00032 
00033     private Image lineFinal;
00034     private Image lineOriginal;
00035     private GC gcFinal;
00036     private GC gcOriginal;
00037     
00038     /****
00039      * constructor of the class, requiring a queue of list of data (per line) to be
00040      * visualized on a set of images. The queue can be thread-safe (in case of multithreaded)
00041      * or unsafe (case of single threaded) 
00042      * 
00043      * The class will return a list of images.
00044      * 
00045      * @param list : the queue of TimelineDataSet data
00046      * @param numLines
00047      * @param device : the display device used to create images. Cannot be null
00048      * @param width : the width of the view
00049      * @param maxTextSize : the maximum size of a letter for a given device
00050      * @param debugMode : flag whether we need to show text information
00051      */
00052     public DetailPaintThread( SpaceTimeDataController stData, Queue<TimelineDataSet> list, int numLines,
00053             AtomicInteger paintDone, Device device, int width, Point maxTextSize, boolean debugMode) {
00054         
00055         super(stData, list, numLines, paintDone, device, width);
00056         
00057         this.maxTextSize = maxTextSize;
00058         this.debugMode = debugMode;
00059     }
00060     
00061     private void paintText(GC gc, int odInitPixel, int odFinalPixel, int box_height, 
00062             int depth, Color color, int sampleCount) {
00063         if (!debugMode) {
00064             return;
00065         }
00066         final int box_width = odFinalPixel - odInitPixel;
00067         
00068         String decoration = String.valueOf(depth);
00069         
00070         String count = String.valueOf(sampleCount);
00071         if (sampleCount>DetailViewPaint.MAX_RECORDS_DISPLAY)
00072             count = DetailViewPaint.TOO_MANY_RECORDS;
00073         decoration +=  "(" + count + ")";
00074 
00075         // want 2 pixels on either side
00076         if((box_width - maxTextSize.x) >= 4) {
00077 
00078             // want 2 pixels on above and below
00079             if ((box_height - maxTextSize.y) >= 4) {
00080 
00081                 gc.setBackground(color);
00082 
00083                 // Pick the color of the text indicating sample depth. 
00084                 // If the background is suffciently light, pick black, otherwise white
00085                 if (color.getRed()+color.getBlue()+color.getGreen()>Constants.DARKEST_COLOR_FOR_BLACK_TEXT)
00086                     gc.setForeground(Constants.COLOR_BLACK);
00087                 else
00088                     gc.setForeground(Constants.COLOR_WHITE);
00089                 
00090                 Point textSize = gc.textExtent(decoration);
00091                 gc.drawText(decoration, odInitPixel+((box_width - textSize.x)/2), ((box_height - textSize.y)/2));
00092             }
00093         }
00094     }
00095 
00096     @Override
00097     protected void initPaint(Device device, int width, int height) {
00098 
00099         lineFinal = new Image(device, width, height);
00100         lineOriginal = new Image(device, width, 1);
00101         
00102         gcFinal = new GC(lineFinal);
00103         gcOriginal = new GC(lineOriginal);      
00104     }
00105 
00106     @Override
00107     protected void paint(int position, BaseDataVisualization data, int height) {
00108 
00109         // paint for the original image without text
00110         // this image will be needed for summary view to compute
00111         //  the number of colors-pixels
00112         paint(gcOriginal, data.x_start, data.x_end, 1, data.color);
00113         
00114         // paint the real image for detail view
00115         paint(gcFinal, data.x_start, data.x_end, height, data.color);
00116         
00117         // paint the text on the real image
00118         final DetailDataVisualization dataDetail = (DetailDataVisualization) data;
00119         paintText(gcFinal, data.x_start, data.x_end, height,
00120                 data.depth, data.color, dataDetail.sample_counts);      
00121     }
00122 
00123     @Override
00124     protected ImagePosition finalizePaint(int linenum) {
00125 
00126         gcOriginal.dispose();
00127         gcFinal.dispose();
00128         
00129         final ImagePosition imgPos = new DetailImagePosition(linenum, lineFinal, lineOriginal);
00130 
00131         return imgPos;
00132     }
00133 
00134     @Override
00135     protected int getNumberOfCreatedData() {
00136 
00137         return stData.getNumberOfLines();
00138     }   
00139 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1