BasePaintThread.java
Go to the documentation of this file.00001 package edu.rice.cs.hpc.traceviewer.painter;
00002
00003 import java.util.ArrayList;
00004 import java.util.List;
00005 import java.util.Queue;
00006 import java.util.concurrent.Callable;
00007 import java.util.concurrent.atomic.AtomicInteger;
00008
00009 import org.eclipse.core.runtime.Assert;
00010 import org.eclipse.swt.graphics.Color;
00011 import org.eclipse.swt.graphics.GC;
00012 import org.eclipse.swt.graphics.Device;
00013 import edu.rice.cs.hpc.traceviewer.data.db.BaseDataVisualization;
00014 import edu.rice.cs.hpc.traceviewer.data.db.TimelineDataSet;
00015 import edu.rice.cs.hpc.traceviewer.painter.ImagePosition;
00016 import edu.rice.cs.hpc.traceviewer.spaceTimeData.SpaceTimeDataController;
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 public abstract class BasePaintThread implements Callable<List<ImagePosition>> {
00027
00028 final protected Device device;
00029 final protected int width;
00030
00031 final private Queue<TimelineDataSet> list;
00032 final private List<ImagePosition> listOfImages;
00033 final private int numberOfTotalLines;
00034
00035 final protected SpaceTimeDataController stData;
00036 final private AtomicInteger timelineDone;
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 public BasePaintThread( SpaceTimeDataController stData, Queue<TimelineDataSet> list,
00052 int numberOfTotalLines, AtomicInteger paintDone,
00053 Device device, int width) {
00054
00055 Assert.isNotNull(device);
00056 Assert.isNotNull(list);
00057
00058 this.list = list;
00059 this.numberOfTotalLines = numberOfTotalLines;
00060 this.timelineDone = paintDone;
00061
00062 this.device = device;
00063 this.stData = stData;
00064
00065 this.width = width;
00066 listOfImages = new ArrayList<ImagePosition>(list.size());
00067 }
00068
00069 @Override
00070
00071
00072
00073
00074 public List<ImagePosition> call() throws Exception {
00075
00076 while( ! list.isEmpty()
00077 ||
00078 numberOfTotalLines>getNumberOfCreatedData()
00079 ||
00080 timelineDone.get()>0 )
00081 {
00082
00083
00084
00085
00086
00087
00088 TimelineDataSet setDataToPaint = list.poll();
00089 if (setDataToPaint == null) {
00090 Thread.sleep(40);
00091 continue;
00092 }
00093 final int height = setDataToPaint.getHeight();
00094 final int position = setDataToPaint.getLineNumber();
00095
00096
00097
00098
00099 initPaint(device, width, height);
00100
00101
00102
00103
00104
00105
00106 for(BaseDataVisualization data : setDataToPaint.getList())
00107 {
00108
00109
00110
00111 paint(position, data, height);
00112 }
00113
00114
00115
00116 final ImagePosition imgPos = finalizePaint(position);
00117
00118 listOfImages.add(imgPos);
00119 }
00120
00121 return listOfImages;
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 abstract protected void initPaint(Device device, int width, int height);
00133
00134
00135
00136
00137
00138
00139
00140
00141 abstract protected void paint(int position, BaseDataVisualization data, int height);
00142
00143
00144
00145
00146
00147
00148
00149 abstract protected ImagePosition finalizePaint(int linenum);
00150
00151 abstract protected int getNumberOfCreatedData();
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 protected void paint(GC gc, int p_start, int p_end, int height, Color color) {
00163
00164 int width = p_end - p_start;
00165 if (width <= 0)
00166 return;
00167
00168 gc.setBackground(color);
00169 gc.fillRectangle(p_start, 0, width, height);
00170 }
00171 }