Package: GenericTabItem

GenericTabItem

nameinstructionbranchcomplexitylinemethod
GenericTabItem(String, TabFolder, GenericTabItem.AllowedOverrunDirection)
M: 93 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 23 C: 0
0%
M: 1 C: 0
0%
addBackgroundFigure(TraceFigure)
M: 52 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
addFigure(TraceFigure)
M: 92 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
composePath(String, String)
M: 22 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
dispose()
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
disposeFigures()
M: 49 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
exportJPG(String)
M: 72 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
getCurrentFont()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getHorizontalSize()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getImage(String)
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getName()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getTabItem()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getVerticalSize()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getXMax()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getYMax()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isCanvasHorizontallyOverrun()
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
isCanvasOverrun()
M: 16 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
isCanvasVerticallyOverrun()
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * RT Trace Viewer Plugin
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.plugins.rttraceviewer.view;
23:
24: import java.io.File;
25:
26: import org.eclipse.draw2d.ColorConstants;
27: import org.eclipse.draw2d.Figure;
28: import org.eclipse.draw2d.FigureCanvas;
29: import org.eclipse.draw2d.Graphics;
30: import org.eclipse.draw2d.SWTGraphics;
31: import org.eclipse.draw2d.geometry.Rectangle;
32: import org.eclipse.jface.resource.ImageDescriptor;
33: import org.eclipse.swt.graphics.Font;
34: import org.eclipse.swt.graphics.GC;
35: import org.eclipse.swt.graphics.Image;
36: import org.eclipse.swt.graphics.ImageData;
37: import org.eclipse.swt.graphics.ImageLoader;
38: import org.eclipse.swt.graphics.Point;
39: import org.eclipse.swt.layout.FillLayout;
40: import org.eclipse.swt.widgets.TabFolder;
41: import org.eclipse.swt.widgets.TabItem;
42: import org.overture.ide.plugins.rttraceviewer.TracefileViewerPlugin;
43: import org.overture.ide.plugins.rttraceviewer.draw.TraceFigure;
44:
45: // Referenced classes of package org.overture.tracefile.viewer:
46: // TracefileViewerPlugin, tdCPU
47:
48: public class GenericTabItem
49: {        
50:         public enum AllowedOverrunDirection {Horizontal, Vertical, Both}
51:         
52: private TabItem theTabItem;
53: private FigureCanvas theCanvas;
54: private Figure theFigure;
55: private int xmax;
56: private int ymax;
57: private Font theFont;
58: static final boolean $assertionsDisabled = false;//!org.overture.tracefile.viewer.GenericTabItem.desiredAssertionStatus();
59: private AllowedOverrunDirection allowedDirection;
60:
61:
62: public GenericTabItem(String theName, TabFolder theFolder, AllowedOverrunDirection direction)
63: {
64: theTabItem = null;
65: theCanvas = null;
66: theFigure = null;
67: xmax = 0;
68: ymax = 0;
69: theFont = null;
70:
71:• if(!$assertionsDisabled && theName == null)
72: {
73: throw new AssertionError();
74: }
75:• if(!$assertionsDisabled && theFolder == null)
76: {
77: throw new AssertionError();
78: }
79: else
80: {
81:         theFigure = new Figure();
82:         
83:         theCanvas = new FigureCanvas(theFolder);
84:         theCanvas.setLayout(new FillLayout());
85:
86:         theCanvas.setContents(theFigure);
87:         theCanvas.setBackground(ColorConstants.white);
88:
89:         theCanvas.setScrollBarVisibility(FigureCanvas.ALWAYS);
90:         //theCanvas.setSize(theFolder.getSize());
91:         //theCanvas.setSize(3000,3000);
92:
93:         theTabItem = new TabItem(theFolder, 0);
94: theTabItem.setText(theName);
95: theTabItem.setControl(theCanvas);
96:
97: this.allowedDirection = direction;
98:
99: theFont = new Font(theTabItem.getDisplay(), "MS Gothic", 12, 0);
100: return;
101:
102: }
103: }
104:
105: public boolean isCanvasOverrun()
106: {         
107:         
108:•         if(this.allowedDirection == AllowedOverrunDirection.Horizontal)
109:                 return isCanvasVerticallyOverrun();
110:•         else if(this.allowedDirection == AllowedOverrunDirection.Vertical)
111:                 return isCanvasHorizontallyOverrun();
112:         else //Both, so we never overrun
113:                 return false;
114: }
115:
116: private boolean isCanvasHorizontallyOverrun()
117: {
118:         Point tabFolderSize = theTabItem.getParent().getSize();
119:         int tabFolderWidth = tabFolderSize.x;
120:         
121:•         return xmax > tabFolderWidth;
122: }
123:
124: private boolean isCanvasVerticallyOverrun(){
125:         
126:         Point tabFolderSize = theTabItem.getParent().getSize();
127:         int tabFolderHeight = tabFolderSize.y;
128:         
129:•         return ymax > tabFolderHeight;
130: }
131:
132: public Long getXMax()
133: {
134:         return new Long(xmax);
135: }
136:
137: public Long getYMax()
138: {
139:         return new Long(ymax);
140: }
141:
142: public String getName()
143: {
144: return theTabItem.getText();
145: }
146:
147: public Long getHorizontalSize()
148: {
149:         return new Long(theFigure.getSize().width);
150:         //return new Long(theCanvas.getSize().x);
151: }
152:
153: public Long getVerticalSize()
154: {         
155: return new Long(theFigure.getSize().height);
156:         //return new Long(theCanvas.getSize().y);
157: }
158:
159: public void addFigure(TraceFigure aFigure)
160: {         
161:• if(!$assertionsDisabled && aFigure == null)
162: throw new AssertionError();
163:• if(!$assertionsDisabled && theFigure == null)
164: {
165: throw new AssertionError();
166: } else
167: {
168:         //Update xmax and ymax
169: Rectangle rect = aFigure.getBounds();
170: int xfig = rect.x + rect.width - 2;
171:• xmax = xmax < xfig ? xfig : xmax;
172: int yfig = rect.y + rect.height - 2;
173:• ymax = ymax < yfig ? yfig : ymax;
174:
175: //Ensure that the canvas is only expanded not shrinked
176:• int newX = theFigure.getSize().width > xmax ? theFigure.getSize().width : xmax;
177:• int newY = theFigure.getSize().height > ymax ? theFigure.getSize().height : ymax;
178:
179: theFigure.setSize(newX, newY);
180: theFigure.add(aFigure);
181: }
182: }
183:
184: public void addBackgroundFigure(TraceFigure bFigure)
185: {
186:         //Add figure and dont update xmax and ymax
187:         //Ensure that the canvas is expanded if the background figure goes beyond
188: Rectangle rect = bFigure.getBounds();
189: int xfig = rect.x + rect.width;
190: int yfig = rect.y + rect.height;
191:• int newX = theFigure.getSize().width > xfig ? theFigure.getSize().width : xfig;
192:• int newY = theFigure.getSize().height > yfig ? theFigure.getSize().height : yfig;
193:
194: theFigure.setSize(newX, newY);
195: theFigure.add(bFigure, 0);
196: }
197:
198: public Font getCurrentFont()
199: {
200: return theFont;
201: }
202:
203: public void exportJPG(String fileName)
204: {
205: Image theImage = new Image(null, xmax + 50, ymax + 50);
206: GC theGC = new GC(theImage);
207: Graphics theGraphics = new SWTGraphics(theGC);
208: theFigure.paint(theGraphics);
209: theGraphics.fillRectangle(xmax + 50, 0, 10, ymax + 50);
210: ImageData imgData[] = new ImageData[1];
211: imgData[0] = theImage.getImageData();
212: ImageLoader theLoader = new ImageLoader();
213: theLoader.data = imgData;
214: theLoader.save((new StringBuilder(String.valueOf(fileName))).append(".jpg").toString(), 4);
215: theGraphics.dispose();
216: theGC.dispose();
217: theImage.dispose();
218: }
219:
220: public final Image getImage(String path)
221: {
222: ImageDescriptor theDescriptor = TracefileViewerPlugin.getImageDescriptor(path);
223: Image theImage = null;
224:• if(theDescriptor != null)
225: theImage = theDescriptor.createImage();
226: return theImage;
227: }
228:
229: public String composePath(String pp1, String pp2)
230: {
231: String res = pp1;
232: res = (new StringBuilder(String.valueOf(res))).append(File.separator).toString();
233: res = (new StringBuilder(String.valueOf(res))).append(pp2).toString();
234: return res;
235: }
236:
237: public void disposeFigures()
238: {
239:• if(!$assertionsDisabled && theFigure == null)
240: {
241: throw new AssertionError();
242: } else
243: {
244:                 //Force cleanup of special trace figures
245:•         for(Object child : theFigure.getChildren())
246:         {
247:•                 if(child instanceof TraceFigure)
248:                 {
249:                         ((TraceFigure)child).dispose();
250:                 }
251:         }
252:         
253: theCanvas.getViewport().setViewLocation(0, 0);
254: theFigure.removeAll();
255: theFigure.erase();
256: theFigure.setSize(0, 0);
257: xmax = 0;
258: ymax = 0;
259: return;
260: }
261: }
262:
263: public void dispose()
264: {
265: disposeFigures();
266: theCanvas.dispose();
267: theTabItem.dispose();
268:• if(theFont != null)
269: theFont.dispose();
270: }
271:
272: public TabItem getTabItem()
273: {
274:         return theTabItem;
275: }
276: }