1 23 package org.objectweb.clif.scenario.util.isac.loadprofile.gui; 24 25 import java.util.Vector ; 26 27 import org.apache.log4j.Category; 28 import org.eclipse.swt.SWT; 29 import org.eclipse.swt.graphics.Color; 30 import org.eclipse.swt.graphics.GC; 31 import org.eclipse.swt.widgets.Canvas; 32 import org.eclipse.swt.widgets.Composite; 33 import org.objectweb.clif.scenario.util.isac.loadprofile.GroupDescription; 34 import org.objectweb.clif.scenario.util.isac.loadprofile.Point; 35 import org.objectweb.clif.scenario.util.isac.loadprofile.RampDescription; 36 37 43 public class DrawableCanvas extends Canvas { 44 static Category cat = Category.getInstance(DrawableCanvas.class.getName()) ; 46 public static final int SELECTION_SIZE = 8 ; 48 private static final int SELECTION_COLOR = SWT.COLOR_BLACK ; 50 public static final int BACK_COLOR = SWT.COLOR_WHITE ; 52 53 57 62 public DrawableCanvas(Composite parent, int style) { 63 super(parent, style); 64 this.setBackground(parent.getDisplay().getSystemColor(BACK_COLOR)) ; 65 } 66 67 71 76 public void drawRamp(RampDescription c, Color color) { 77 switch (c.getType()) { 79 case RampDescription.LINE : 80 this.drawLineRamp(c, color) ; 81 break ; 82 case RampDescription.ARC : 83 this.drawArcRamp(c, color) ; 84 break ; 85 case RampDescription.CRENEL_HV : 86 this.drawCrenelHVRamp(c,color) ; 87 break ; 88 case RampDescription.CRENEL_VH : 89 this.drawCrenelVHRamp(c,color) ; 90 break ; 91 default : 92 cat.warn("UNKNOW RAMP TYPE : " + c.getType()) ; 93 } 94 } 95 96 101 private void drawCrenelHVRamp(RampDescription rd, Color c) { 102 this.drawCrenelHV(rd.getStart(), rd.getEnd(), c) ; 104 } 105 106 111 private void drawCrenelVHRamp(RampDescription rd, Color c) { 112 this.drawCrenelVH(rd.getStart(), rd.getEnd(), c) ; 114 } 115 116 121 private void drawLineRamp(RampDescription c, Color color) { 122 GC gc = new GC(this) ; 124 gc.setForeground(color) ; 125 gc.drawLine((int)c.getStart().x, (int)c.getStart().y, (int)c.getEnd().x, (int)c.getEnd().y) ; 126 gc.dispose() ; 127 } 128 129 134 private void drawArcRamp(RampDescription c, Color color) { 135 } 137 138 145 public void drawArrow(Point p, int size, int orientation, Color color) { 146 Point p1 = new Point(0,0); 148 Point p2 = new Point(0,0) ; 149 Point p3 = new Point(0,0) ; 150 if (orientation == 0) { 151 p1.x = p.x - (size / 2) ; 152 p1.y = p.y ; 153 p2.x = p.x + (size/2) ; 154 p2.y = p.y ; 155 p3.x = p.x ; 156 p3.y = p.y - size ; 157 } else if (orientation == 1) { 158 p1.x = p.x ; 159 p1.y = p.y - (size / 2) ; 160 p2.x = p.x ; 161 p2.y = p.y + (size / 2) ; 162 p3.x = p.x + size ; 163 p3.y = p.y ; 164 } else 165 return ; 166 GC gc = new GC(this) ; 168 gc.setBackground(color) ; 169 gc.fillPolygon(new int[]{(int)p1.x,(int)p1.y,(int)p2.x,(int)p2.y,(int)p3.x,(int)p3.y}) ; 170 gc.dispose() ; 171 } 172 173 179 public void drawString(Point p, String text, Color color) { 180 GC gc = new GC(this) ; 182 gc.setForeground(color) ; 183 gc.drawString(text, (int)p.x, (int)p.y) ; 184 gc.dispose() ; 185 } 186 187 193 public void drawLine(Point p, Point q, Color color) { 194 GC gc = new GC(this) ; 196 gc.setForeground(color) ; 197 gc.drawLine((int)p.x, (int)p.y, (int)q.x, (int)q.y) ; 198 gc.dispose() ; 199 } 200 201 206 public void eraseLine(Point p, Point q) { 207 this.drawLine(p, q, this.getDisplay().getSystemColor(BACK_COLOR)) ; 209 } 210 211 217 private void drawCrenelHV(Point p, Point q, Color c) { 218 Point intersection = new Point(q.x-1, p.y) ; 220 this.drawLine(p,intersection,c) ; 222 this.drawLine(intersection,q,c) ; 223 } 224 225 231 private void drawCrenelVH(Point p, Point q, Color c) { 232 Point intersection = new Point(p.x+1, q.y) ; 234 this.drawLine(p,intersection,c) ; 236 this.drawLine(intersection,q,c) ; 237 } 238 239 243 248 public void selectPoint(Point p, boolean fill) { 249 GC gc = new GC(this) ; 251 if (!fill) { 252 gc.setForeground(this.getDisplay().getSystemColor(SELECTION_COLOR)) ; 253 gc.drawRectangle((int)p.x - (SELECTION_SIZE / 2), (int)p.y - (SELECTION_SIZE / 2), SELECTION_SIZE, SELECTION_SIZE) ; 255 } 256 else { 257 gc.setBackground(this.getDisplay().getSystemColor(SELECTION_COLOR)) ; 258 gc.fillRectangle((int)p.x - (SELECTION_SIZE / 2), (int)p.y - (SELECTION_SIZE / 2), SELECTION_SIZE, SELECTION_SIZE) ; 260 } 261 gc.dispose() ; 262 } 263 264 268 public void eraseSelectionPoint(Point p) { 269 GC gc = new GC(this) ; 271 gc.setForeground(this.getDisplay().getSystemColor(BACK_COLOR)) ; 272 gc.drawRectangle((int)p.x - (SELECTION_SIZE / 2), (int)p.y - (SELECTION_SIZE / 2), SELECTION_SIZE, SELECTION_SIZE) ; 273 gc.dispose() ; 274 } 275 276 280 public void selectGroup(GroupDescription g) { 281 Vector ramps = g.getRamps() ; 283 for (int i=0;i<ramps.size();i++) 285 this.selectRamp((RampDescription)ramps.elementAt(i)) ; 286 } 287 288 292 private void selectRamp(RampDescription c) { 293 switch (c.getType()) { 295 case RampDescription.LINE : 296 this.selectLineRamp(c) ; 297 break ; 298 case RampDescription.ARC : 299 this.selectArcRamp(c) ; 300 break ; 301 case RampDescription.CRENEL_HV : 302 case RampDescription.CRENEL_VH : 303 this.selectCrenelXXRamp(c) ; 304 default : 305 cat.warn("UNKNOW RAMP TYPE : " + c.getType()) ; 306 } 307 } 308 309 313 private void selectLineRamp(RampDescription c) { 314 this.selectPoint(c.getStart(), false) ; 316 this.selectPoint(c.getEnd(), false) ; 317 } 318 319 323 private void selectCrenelXXRamp(RampDescription c) { 324 this.selectPoint(c.getStart(), false) ; 326 this.selectPoint(c.getEnd(), false) ; 327 } 328 329 333 private void selectArcRamp(RampDescription c) { 334 } 336 } 337 | Popular Tags |