| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2005, 2013 IBM Corporation, Ericsson |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM - Initial API and implementation |
| 10 | * Bernd Hufmann - Updated for TMF |
| 11 | **********************************************************************/ |
| 12 | |
| 13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings; |
| 14 | |
| 15 | /** |
| 16 | * Interface for a graphical context. |
| 17 | * |
| 18 | * @version 1.0 |
| 19 | * @author sveyrier |
| 20 | * |
| 21 | */ |
| 22 | public interface IGC { |
| 23 | |
| 24 | /** |
| 25 | * Set the current line style |
| 26 | * |
| 27 | * @param style the new line style |
| 28 | */ |
| 29 | void setLineStyle(int style); |
| 30 | |
| 31 | /** |
| 32 | * Returns current the line style used in the graphical context |
| 33 | * |
| 34 | * @return the current line style |
| 35 | */ |
| 36 | int getLineStyle(); |
| 37 | |
| 38 | /** |
| 39 | * Returns the contents x coordinate that is at the upper left corner of the view |
| 40 | * |
| 41 | * @return the contents x coordinate |
| 42 | */ |
| 43 | int getContentsX(); |
| 44 | |
| 45 | /** |
| 46 | * Returns the contents y coordinate that is at the upper left corner of the view |
| 47 | * |
| 48 | * @return the contents y coordinate |
| 49 | */ |
| 50 | int getContentsY(); |
| 51 | |
| 52 | /** |
| 53 | * Returns the contents visible width |
| 54 | * |
| 55 | * @return the contents width |
| 56 | */ |
| 57 | int getVisibleWidth(); |
| 58 | |
| 59 | /** |
| 60 | * Returns the contents visible height |
| 61 | * |
| 62 | * @return the contents height |
| 63 | */ |
| 64 | int getVisibleHeight(); |
| 65 | |
| 66 | /** |
| 67 | * Translates the given contents x coordinate into view x coordinate |
| 68 | * |
| 69 | * @param x the x coordinate to translate |
| 70 | * @return the corresponding view x coordinate |
| 71 | */ |
| 72 | int contentsToViewX(int x); |
| 73 | |
| 74 | /** |
| 75 | * Translates the given contents y coordinate into view y coordinate |
| 76 | * |
| 77 | * @param y the y coordinate to translate |
| 78 | * @return the corresponding view y coordinate |
| 79 | */ |
| 80 | int contentsToViewY(int y); |
| 81 | |
| 82 | /** |
| 83 | * Draws a line, using the foreground color, between the points (x1, y1) and (x2, y2). |
| 84 | * |
| 85 | * @param x1 the first point's x coordinate |
| 86 | * @param y1 the first point's y coordinate |
| 87 | * @param x2 the second point's x coordinate |
| 88 | * @param y2 the second point's y coordinate |
| 89 | */ |
| 90 | void drawLine(int x1, int y1, int x2, int y2); |
| 91 | |
| 92 | /** |
| 93 | * Draws the outline of the rectangle specified by the arguments, using the receiver's foreground color. The left |
| 94 | * and right edges of the rectangle are at x and x + width. The top and bottom edges are at y and y + height. |
| 95 | * |
| 96 | * @param x the x coordinate of the rectangle to be drawn |
| 97 | * @param y the y coordinate of the rectangle to be drawn |
| 98 | * @param width the width of the rectangle to be drawn |
| 99 | * @param height the height of the rectangle to be drawn |
| 100 | */ |
| 101 | void drawRectangle(int x, int y, int width, int height); |
| 102 | |
| 103 | /** |
| 104 | * Draws a rectangle, based on the specified arguments, which has the appearance of the platform's focus rectangle |
| 105 | * if the platform supports such a notion, and otherwise draws a simple rectangle in the receiver's foreground |
| 106 | * color. |
| 107 | * |
| 108 | * @param x the x coordinate of the rectangle |
| 109 | * @param y the y coordinate of the rectangle |
| 110 | * @param width the width of the rectangle |
| 111 | * @param height the height of the rectangle |
| 112 | */ |
| 113 | void drawFocus(int x, int y, int width, int height); |
| 114 | |
| 115 | /** |
| 116 | * Fills the interior of the closed polygon which is defined by the specified array of integer coordinates, using |
| 117 | * the receiver's background color. The array contains alternating x and y values which are considered to represent |
| 118 | * points which are the vertices of the polygon. Lines are drawn between each consecutive pair, and between the |
| 119 | * first pair and last pair in the array. |
| 120 | * |
| 121 | * @param points an array of alternating x and y values which are the vertices of the polygon |
| 122 | */ |
| 123 | void fillPolygon(int[] points); |
| 124 | |
| 125 | /** |
| 126 | * Draws the closed polygon which is defined by the specified array of integer coordinates, using the receiver's |
| 127 | * foreground color. The array contains alternating x and y values which are considered to represent points which |
| 128 | * are the vertices of the polygon. Lines are drawn between each consecutive pair, and between the first pair and |
| 129 | * last pair in the array. |
| 130 | * |
| 131 | * @param points an array of alternating x and y values which are the vertices of the polygon |
| 132 | */ |
| 133 | void drawPolygon(int[] points); |
| 134 | |
| 135 | /** |
| 136 | * Fills the interior of the rectangle specified by the arguments, using the receiver's background color. |
| 137 | * |
| 138 | * @param x the x coordinate of the rectangle to be filled |
| 139 | * @param y the y coordinate of the rectangle to be filled |
| 140 | * @param width the width of the rectangle to be filled |
| 141 | * @param height the height of the rectangle to be filled |
| 142 | */ |
| 143 | void fillRectangle(int x, int y, int width, int height); |
| 144 | |
| 145 | /** |
| 146 | * Fills the interior of the specified rectangle with a gradient sweeping from left to right or top to bottom |
| 147 | * progressing from the graphical context gradient color to its background color. |
| 148 | * |
| 149 | * @param x the x coordinate of the rectangle to be filled |
| 150 | * @param y the y coordinate of the rectangle to be filled |
| 151 | * @param width the width of the rectangle to be filled, may be negative (inverts direction of gradient if |
| 152 | * horizontal) |
| 153 | * @param height the height of the rectangle to be filled, may be negative (inverts direction of gradient if |
| 154 | * horizontal) |
| 155 | * @param vertical if true sweeps from top to bottom, else sweeps from left to right |
| 156 | */ |
| 157 | void fillGradientRectangle(int x, int y, int width, int height, boolean vertical); |
| 158 | |
| 159 | /** |
| 160 | * Returns the given string width in pixels |
| 161 | * |
| 162 | * @param name the string |
| 163 | * @return the string width |
| 164 | */ |
| 165 | int textExtent(String name); |
| 166 | |
| 167 | /** |
| 168 | * Draws the given string, using the receiver's current font and foreground color. Tab expansion and carriage return |
| 169 | * processing are performed. If trans is true, then the background of the rectangular area where the text is being |
| 170 | * drawn will not be modified, otherwise it will be filled with the receiver's background color. |
| 171 | * |
| 172 | * @param string the string to be drawn |
| 173 | * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn |
| 174 | * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn |
| 175 | * @param trans if true the background will be transparent, otherwise it will be opaque |
| 176 | */ |
| 177 | void drawText(String string, int x, int y, boolean trans); |
| 178 | |
| 179 | /** |
| 180 | * Draws the given string, using the receiver's current font and foreground color. Tab expansion and carriage return |
| 181 | * processing are performed. The background of the rectangular area where the text is being drawn will be filled |
| 182 | * with the receiver's background color. |
| 183 | * |
| 184 | * @param string the string to be drawn |
| 185 | * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn |
| 186 | * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn |
| 187 | */ |
| 188 | void drawText(String string, int x, int y); |
| 189 | |
| 190 | /** |
| 191 | * Fills the interior of an oval, within the specified rectangular area, with the receiver's background color. |
| 192 | * |
| 193 | * @param x the x coordinate of the upper left corner of the oval to be filled |
| 194 | * @param y the y coordinate of the upper left corner of the oval to be filled |
| 195 | * @param width the width of the oval to be filled |
| 196 | * @param height the width of the oval to be filled |
| 197 | */ |
| 198 | void fillOval(int x, int y, int width, int height); |
| 199 | |
| 200 | /** |
| 201 | * Returns current the background color used in the graphical context |
| 202 | * |
| 203 | * @return the background color |
| 204 | */ |
| 205 | IColor getBackground(); |
| 206 | |
| 207 | /** |
| 208 | * Returns current the background color used in the graphical context |
| 209 | * |
| 210 | * @return the background color |
| 211 | */ |
| 212 | IColor getForeground(); |
| 213 | |
| 214 | /** |
| 215 | * Set the graphical context foreground color |
| 216 | * |
| 217 | * @param color the foreground color |
| 218 | */ |
| 219 | void setBackground(IColor color); |
| 220 | |
| 221 | /** |
| 222 | * Set the graphical context background color |
| 223 | * |
| 224 | * @param color the background color |
| 225 | */ |
| 226 | void setForeground(IColor color); |
| 227 | |
| 228 | /** |
| 229 | * Set the color to use when filling regions using gradient. The color will progess from the given color to the |
| 230 | * current background color |
| 231 | * |
| 232 | * @param color the gardiient color to use |
| 233 | */ |
| 234 | void setGradientColor(IColor color); |
| 235 | |
| 236 | /** |
| 237 | * Set the line width to use for drawing |
| 238 | * |
| 239 | * @param width the line width |
| 240 | */ |
| 241 | void setLineWidth(int width); |
| 242 | |
| 243 | /** |
| 244 | * Returns the current graphical context line width used for drawing |
| 245 | * |
| 246 | * @return the line width |
| 247 | */ |
| 248 | int getLineWidth(); |
| 249 | |
| 250 | /** |
| 251 | * Returns the LineDotD style constant |
| 252 | * |
| 253 | * @return the constant value |
| 254 | */ |
| 255 | int getLineDotStyle(); |
| 256 | |
| 257 | /** |
| 258 | * Returns the LineDash style constant |
| 259 | * |
| 260 | * @return the constant |
| 261 | */ |
| 262 | int getLineDashStyle(); |
| 263 | |
| 264 | /** |
| 265 | * Returns the LineSolid style constant |
| 266 | * |
| 267 | * @return the constant |
| 268 | */ |
| 269 | int getLineSolidStyle(); |
| 270 | |
| 271 | /** |
| 272 | * Draws the given string centered into the given rectangle. If the string cannot fit in the rectangle area, the |
| 273 | * string is truncated. If trans is true, then the background of the rectangular area where the text is being drawn |
| 274 | * will not be modified, otherwise it will be filled with the receiver's background color. |
| 275 | * |
| 276 | * @param name the string to draw |
| 277 | * @param x the x coordinate of the rectangle to draw the string |
| 278 | * @param y the y coordinate of the rectangle to draw the string |
| 279 | * @param width the width of the rectangle to draw the string |
| 280 | * @param height the height of the rectangle to draw the string |
| 281 | * @param trans if true the background will be transparent, otherwise it will be opaque |
| 282 | */ |
| 283 | void drawTextTruncatedCentred(String name, int x, int y, int width, int height, boolean trans); |
| 284 | |
| 285 | /** |
| 286 | * Draws the given string into the given rectangle (left justify) If the string cannot fit in the rectangle area, |
| 287 | * the string is truncated. If trans is true, then the background of the rectangular area where the text is being |
| 288 | * drawn will not be modified, otherwise it will be filled with the receiver's background color. |
| 289 | * |
| 290 | * @param name The text to put in the rectangle |
| 291 | * @param x the x coordinate of the rectangle to draw the string |
| 292 | * @param y the y coordinate of the rectangle to draw the string |
| 293 | * @param width the width of the rectangle to draw the string |
| 294 | * @param height the height of the rectangle to draw the string |
| 295 | * @param trans if true the background will be transparent, otherwise it will be opaque |
| 296 | */ |
| 297 | void drawTextTruncated(String name, int x, int y, int width, int height, boolean trans); |
| 298 | |
| 299 | /** |
| 300 | * Copies a the source image into a (potentially different sized) rectangular area in the graphical context. If the |
| 301 | * source image has smaller sizes, then the source area will be stretched to fit the destination area as it is |
| 302 | * copied. |
| 303 | * |
| 304 | * @param image the image to draw |
| 305 | * @param x the x coordinate in the destination to copy to |
| 306 | * @param y the y coordinate in the destination to copy to |
| 307 | * @param maxWith the width in pixels of the destination rectangle |
| 308 | * @param maxHeight the height in pixels of the destination rectangle |
| 309 | */ |
| 310 | void drawImage(IImage image, int x, int y, int maxWith, int maxHeight); |
| 311 | |
| 312 | /** |
| 313 | * Draws the outline of a circular or elliptical arc within the specified rectangular area. The resulting arc begins |
| 314 | * at startAngle and extends for arcAngle degrees, using the current color. Angles are interpreted such that 0 |
| 315 | * degrees is at the 3 o'clock position. A positive value indicates a counter-clockwise rotation while a negative |
| 316 | * value indicates a clockwise rotation. The center of the arc is the center of the rectangle whose origin is (x, y) |
| 317 | * and whose size is specified by the width and height arguments. The resulting arc covers an area width + 1 pixels |
| 318 | * wide by height + 1 pixels tall. |
| 319 | * |
| 320 | * @param x the x coordinate of the upper-left corner of the arc to be drawn |
| 321 | * @param y the y coordinate of the upper-left corner of the arc to be drawn |
| 322 | * @param width the width of the arc to be drawn |
| 323 | * @param height the height of the arc to be drawn |
| 324 | * @param startAngle the beginning angle |
| 325 | * @param endAngle the ending angle |
| 326 | */ |
| 327 | void drawArc(int x, int y, int width, int height, int startAngle, int endAngle); |
| 328 | |
| 329 | /** |
| 330 | * Set the current font used in the graphical context |
| 331 | * |
| 332 | * @param font the font to use |
| 333 | */ |
| 334 | void setFont(IFont font); |
| 335 | |
| 336 | /** |
| 337 | * Returns the font height given font |
| 338 | * |
| 339 | * @param font The font to check for |
| 340 | * @return the the font height |
| 341 | */ |
| 342 | int getFontHeight(IFont font); |
| 343 | |
| 344 | /** |
| 345 | * Returns the average character width for the given font |
| 346 | * |
| 347 | * @param font The font to check for |
| 348 | * @return the average width |
| 349 | */ |
| 350 | int getFontWidth(IFont font); |
| 351 | |
| 352 | /** |
| 353 | * Creates a color with the given RGB values |
| 354 | * |
| 355 | * @param r the red component |
| 356 | * @param g the green component |
| 357 | * @param b the blue component |
| 358 | * @return the color |
| 359 | */ |
| 360 | IColor createColor(int r, int g, int b); |
| 361 | |
| 362 | /** |
| 363 | * Returns the zoom factor applied in both x and y directions when drawing |
| 364 | * |
| 365 | * @return the zoom factor |
| 366 | */ |
| 367 | float getZoom(); |
| 368 | |
| 369 | /** |
| 370 | * Draws text with focus style. |
| 371 | * |
| 372 | * @param focus <code>true</code> if item has focus else <code>false</code> |
| 373 | */ |
| 374 | void setDrawTextWithFocusStyle(boolean focus); |
| 375 | } |