changeset 23 | 98ccebc37403 |
parent 21 | 2a9601315dfc |
child 26 | dc7c549001d5 |
21:2a9601315dfc | 23:98ccebc37403 |
---|---|
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 package javax.microedition.lcdui; |
17 package javax.microedition.lcdui; |
18 |
18 |
19 import org.eclipse.swt.graphics.GC; |
19 import org.eclipse.swt.graphics.GC; |
26 import com.nokia.mid.ui.DirectGraphics; |
26 import com.nokia.mid.ui.DirectGraphics; |
27 |
27 |
28 /** |
28 /** |
29 * Implementation of LCDUI <code>Graphics</code> class. |
29 * Implementation of LCDUI <code>Graphics</code> class. |
30 */ |
30 */ |
31 public class Graphics { |
31 public class Graphics |
32 { |
|
32 |
33 |
33 /** |
34 /** |
34 * Constant for horizontal center alignment of the text. |
35 * Constant for horizontal center alignment of the text. |
35 */ |
36 */ |
36 public static final int HCENTER = 1; |
37 public static final int HCENTER = 1; |
109 private com.nokia.mj.impl.rt.support.Finalizer finalizer; |
110 private com.nokia.mj.impl.rt.support.Finalizer finalizer; |
110 // serialization lock for command buffering and flush |
111 // serialization lock for command buffering and flush |
111 private final Object flushLock = new Object(); |
112 private final Object flushLock = new Object(); |
112 private Canvas canvasParent; |
113 private Canvas canvasParent; |
113 private CustomItem customItemParent; |
114 private CustomItem customItemParent; |
114 |
115 |
115 //Constructor |
116 //Constructor |
116 Graphics() { |
117 Graphics() |
117 finalizer = ((finalizer != null) ? finalizer |
118 { |
118 : new com.nokia.mj.impl.rt.support.Finalizer() { |
119 finalizer = ((finalizer != null) ? finalizer |
119 public void finalizeImpl() { |
120 : new com.nokia.mj.impl.rt.support.Finalizer() |
120 if (finalizer != null) { |
121 { |
121 finalizer = null; |
122 public void finalizeImpl() |
122 if (!ESWTUIThreadRunner.isDisposed()) { |
123 { |
123 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
124 if(finalizer != null) |
124 public void run() { |
125 { |
125 dispose(); |
126 finalizer = null; |
126 } |
127 if(!ESWTUIThreadRunner.isDisposed()) |
127 }); |
128 { |
128 |
129 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
130 { |
|
131 public void run() |
|
132 { |
|
133 dispose(); |
|
129 } |
134 } |
130 } |
135 }); |
131 } |
136 |
132 }); |
137 } |
138 } |
|
139 } |
|
140 }); |
|
133 } |
141 } |
134 /** |
142 /** |
135 * Set the parent image of this Graphics. |
143 * Set the parent image of this Graphics. |
136 * |
144 * |
137 * @param image an image |
145 * @param image an image |
138 */ |
146 */ |
139 void eswtSetParentImage(final Image image) { |
147 void eswtSetParentImage(final Image image) |
140 if(buffered) { |
148 { |
149 if(buffered) |
|
150 { |
|
141 return; |
151 return; |
142 } |
152 } |
143 if (parentImage != image) { |
153 if(parentImage != image) |
154 { |
|
144 parentImage = image; |
155 parentImage = image; |
145 |
156 |
146 if (gc == null) { |
157 if(gc == null) |
158 { |
|
147 gc = new GraphicsContext(); |
159 gc = new GraphicsContext(); |
148 } |
160 } |
149 else { |
161 else |
162 { |
|
150 gc.releaseTarget(); |
163 gc.releaseTarget(); |
151 } |
164 } |
152 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
165 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
153 public void run() { |
166 { |
167 public void run() |
|
168 { |
|
154 org.eclipse.swt.graphics.Image eswtImage = Image.getESWTImage(image); |
169 org.eclipse.swt.graphics.Image eswtImage = Image.getESWTImage(image); |
155 |
170 |
156 if (eswtImage != null) { |
171 if(eswtImage != null) |
172 { |
|
157 gc.bindTarget(Internal_GfxPackageSupport.getImage(eswtImage)); |
173 gc.bindTarget(Internal_GfxPackageSupport.getImage(eswtImage)); |
158 Rectangle clipRect = eswtImage.getBounds(); |
174 Rectangle clipRect = eswtImage.getBounds(); |
159 setClip(0, 0, clipRect.width, clipRect.height); |
175 setClip(0, 0, clipRect.width, clipRect.height); |
160 } |
176 } |
161 reset(); |
177 reset(); |
162 }}); |
178 } |
179 }); |
|
163 } |
180 } |
164 } |
181 } |
165 |
182 |
166 /** |
183 /** |
167 * Initializes this instance of Graphics to use command buffer. |
184 * Initializes this instance of Graphics to use command buffer. |
168 * |
185 * |
169 * Can be called in a non-UI thread. Not thread-safe. |
186 * Can be called in a non-UI thread. Not thread-safe. |
170 * |
187 * |
171 * @param x The x-coordinate of clip |
188 * @param x The x-coordinate of clip |
172 * @param y The y-coordinate of clip |
189 * @param y The y-coordinate of clip |
173 * @param width The width of clip |
190 * @param width The width of clip |
174 * @param height The height of clip |
191 * @param height The height of clip |
175 */ |
192 */ |
176 void initBuffered(final Canvas parent, final int x, final int y, final int width, final int height) { |
193 void initBuffered(final Canvas parent, final int x, final int y, final int width, final int height) |
177 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
194 { |
178 public void run() { |
195 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
179 cmdBuffer = new JavaCommandBuffer(); |
196 { |
180 if (gc == null) { |
197 public void run() |
181 gc = new GraphicsContext(); |
198 { |
182 } |
199 cmdBuffer = new JavaCommandBuffer(); |
183 gc.bindTarget(cmdBuffer); |
200 if(gc == null) |
184 setClip(x, y, width, height); |
201 { |
185 reset(); |
202 gc = new GraphicsContext(); |
186 buffered = true; |
203 } |
187 javax.microedition.lcdui.Graphics.this.canvasParent = parent; |
204 gc.bindTarget(cmdBuffer); |
188 }}); |
205 setClip(x, y, width, height); |
189 } |
206 reset(); |
190 |
207 buffered = true; |
208 javax.microedition.lcdui.Graphics.this.canvasParent = parent; |
|
209 } |
|
210 }); |
|
211 } |
|
212 |
|
191 /** |
213 /** |
192 * Initializes this instance of Graphics to use command buffer. |
214 * Initializes this instance of Graphics to use command buffer. |
193 * |
215 * |
194 * Can be called in a non-UI thread. Not thread-safe. |
216 * Can be called in a non-UI thread. Not thread-safe. |
195 * |
217 * |
196 * @param x The x-coordinate of clip |
218 * @param x The x-coordinate of clip |
197 * @param y The y-coordinate of clip |
219 * @param y The y-coordinate of clip |
198 * @param width The width of clip |
220 * @param width The width of clip |
199 * @param height The height of clip |
221 * @param height The height of clip |
200 */ |
222 */ |
201 void initBuffered(CustomItem parent, int x, int y, int width, int height) { |
223 void initBuffered(CustomItem parent, int x, int y, int width, int height) |
224 { |
|
202 cmdBuffer = new JavaCommandBuffer(); |
225 cmdBuffer = new JavaCommandBuffer(); |
203 if (gc == null) { |
226 if(gc == null) |
227 { |
|
204 gc = new GraphicsContext(); |
228 gc = new GraphicsContext(); |
205 } |
229 } |
206 gc.bindTarget(cmdBuffer); |
230 gc.bindTarget(cmdBuffer); |
207 setClip(x, y, width, height); |
231 setClip(x, y, width, height); |
208 reset(); |
232 reset(); |
209 buffered = true; |
233 buffered = true; |
210 this.customItemParent = parent; |
234 this.customItemParent = parent; |
211 } |
235 } |
212 |
236 |
213 /** |
237 /** |
214 * Resets the command buffer contents. |
238 * Resets the command buffer contents. |
215 * |
239 * |
216 * This is safe to call only in the UI thread. |
240 * This is safe to call only in the UI thread. |
217 */ |
241 */ |
218 void resetCommandBuffer() { |
242 void resetCommandBuffer() |
243 { |
|
219 gc.releaseTarget(); |
244 gc.releaseTarget(); |
220 cmdBuffer.reset(); |
245 cmdBuffer.reset(); |
221 gc.bindTarget(cmdBuffer); |
246 gc.bindTarget(cmdBuffer); |
222 // write settings which were active before flush |
247 // write settings which were active before flush |
223 // if they are not the same as defaults |
248 // if they are not the same as defaults |
224 gc.setFont(Font.getESWTFont(currentFont).handle); |
249 gc.setFont(Font.getESWTFont(currentFont).handle); |
225 gc.setBackgroundColor(currentColor, false); |
250 gc.setBackgroundColor(currentColor, false); |
226 gc.setForegroundColor(currentColor, false); |
251 gc.setForegroundColor(currentColor, false); |
227 if ((translateX != 0) || (translateY != 0)) { |
252 if((translateX != 0) || (translateY != 0)) |
253 { |
|
228 gc.translate(translateX, translateY); |
254 gc.translate(translateX, translateY); |
229 } |
255 } |
230 |
256 |
231 // Note that if called in a non-UI thread then the size of the |
257 // Note that if called in a non-UI thread then the size of the |
232 // Canvas or CustomItem can change between getting the height and |
258 // Canvas or CustomItem can change between getting the height and |
233 // getting the width. Those are modified by the UI thread and there |
259 // getting the width. Those are modified by the UI thread and there |
234 // is no synchronization. |
260 // is no synchronization. |
235 int w = 0; |
261 int w = 0; |
236 int h = 0; |
262 int h = 0; |
237 if(canvasParent != null) { |
263 if(canvasParent != null) |
264 { |
|
238 w = canvasParent.getWidth(); |
265 w = canvasParent.getWidth(); |
239 h = canvasParent.getHeight(); |
266 h = canvasParent.getHeight(); |
240 } else { |
267 } |
268 else |
|
269 { |
|
241 w = customItemParent.getContentWidth(); |
270 w = customItemParent.getContentWidth(); |
242 h = customItemParent.getContentHeight(); |
271 h = customItemParent.getContentHeight(); |
243 } |
272 } |
244 |
273 |
245 if((currentClip[0] != 0) && (currentClip[1] != 0) && |
274 if((currentClip[0] != 0) && (currentClip[1] != 0) && |
246 (currentClip[2] != w) && (currentClip[2] != h)) { |
275 (currentClip[2] != w) && (currentClip[2] != h)) |
276 { |
|
247 gc.setClip(currentClip[0], currentClip[1], currentClip[2], currentClip[3], false); |
277 gc.setClip(currentClip[0], currentClip[1], currentClip[2], currentClip[3], false); |
248 } |
278 } |
249 if (currentStrokeSyle != SOLID) { |
279 if(currentStrokeSyle != SOLID) |
280 { |
|
250 gc.setStrokeStyle(GraphicsContext.STROKE_DOT); |
281 gc.setStrokeStyle(GraphicsContext.STROKE_DOT); |
251 } |
282 } |
252 } |
283 } |
253 |
284 |
254 /** |
285 /** |
255 * Returns the current command buffer or null. |
286 * Returns the current command buffer or null. |
256 * |
287 * |
257 * This method is thread-safe. |
288 * This method is thread-safe. |
258 */ |
289 */ |
259 JavaCommandBuffer getCommandBuffer() { |
290 JavaCommandBuffer getCommandBuffer() |
291 { |
|
260 return cmdBuffer; |
292 return cmdBuffer; |
261 } |
293 } |
262 |
294 |
263 /** |
295 /** |
264 * Get the parent image of this Graphics. |
296 * Get the parent image of this Graphics. |
265 */ |
297 */ |
266 Image getParentImage() { |
298 Image getParentImage() |
299 { |
|
267 return parentImage; |
300 return parentImage; |
268 } |
301 } |
269 |
302 |
270 /** |
303 /** |
271 * Set Graphics context to a target - the GC is coming from paint event. |
304 * Set Graphics context to a target - the GC is coming from paint event. |
272 * |
305 * |
273 * @param eswtGC |
306 * @param eswtGC |
274 */ |
307 */ |
275 void eswtSetGC(final GC eswtGC) { |
308 void eswtSetGC(final GC eswtGC) |
276 if(buffered) { |
309 { |
310 if(buffered) |
|
311 { |
|
277 return; |
312 return; |
278 } |
313 } |
279 gc = eswtGC.getGCData().internalGc; |
314 gc = eswtGC.getGCData().internalGc; |
280 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
315 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
281 public void run() { |
316 { |
317 public void run() |
|
318 { |
|
282 Rectangle clipRect = eswtGC.getClipping(); |
319 Rectangle clipRect = eswtGC.getClipping(); |
283 setClip(clipRect.x, clipRect.y, clipRect.width, clipRect.height); |
320 setClip(clipRect.x, clipRect.y, clipRect.width, clipRect.height); |
284 reset(); |
321 reset(); |
285 }}); |
322 } |
323 }); |
|
286 } |
324 } |
287 |
325 |
288 /** |
326 /** |
289 * Disposes Graphics context resources. |
327 * Disposes Graphics context resources. |
290 */ |
328 */ |
291 void dispose() { |
329 void dispose() |
292 if (parentImage != null) { |
330 { |
331 if(parentImage != null) |
|
332 { |
|
293 parentImage = null; |
333 parentImage = null; |
294 } |
334 } |
295 if(gc != null) { |
335 if(gc != null) |
296 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
336 { |
297 public void run() { |
337 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
338 { |
|
339 public void run() |
|
340 { |
|
298 gc.dispose(); |
341 gc.dispose(); |
299 }}); |
342 } |
300 gc = null; |
343 }); |
301 } |
344 gc = null; |
302 if (cmdBuffer != null) { |
345 } |
303 cmdBuffer = null; |
346 if(cmdBuffer != null) |
347 { |
|
348 cmdBuffer = null; |
|
304 } |
349 } |
305 } |
350 } |
306 |
351 |
307 /** |
352 /** |
308 * Resets Graphics state to initial. |
353 * Resets Graphics state to initial. |
309 */ |
354 */ |
310 void reset() { |
355 void reset() |
356 { |
|
311 setColor(0, 0, 0); |
357 setColor(0, 0, 0); |
312 setFont(Font.getDefaultFont()); |
358 setFont(Font.getDefaultFont()); |
313 setStrokeStyle(Graphics.SOLID); |
359 setStrokeStyle(Graphics.SOLID); |
314 this.translateX = 0; |
360 this.translateX = 0; |
315 this.translateY = 0; |
361 this.translateY = 0; |
316 } |
362 } |
317 |
363 |
318 /** |
364 /** |
319 * Cleans the Canvas background. |
365 * Cleans the Canvas background. |
320 */ |
366 */ |
321 void cleanBackground(Rectangle area) { |
367 void cleanBackground(Rectangle area) |
368 { |
|
322 int savedColor = currentColor; |
369 int savedColor = currentColor; |
323 setColor(255, 255, 255); |
370 setColor(255, 255, 255); |
324 fillRect(area.x, area.y, area.width, area.height); |
371 fillRect(area.x, area.y, area.width, area.height); |
325 setColor(savedColor); |
372 setColor(savedColor); |
326 } |
373 } |
327 |
374 |
328 /** |
375 /** |
329 * Cleans the Canvas background. |
376 * Cleans the Canvas background. |
330 */ |
377 */ |
331 void cleanBackground(int x, int y, int w, int h) { |
378 void cleanBackground(int x, int y, int w, int h) |
379 { |
|
332 int savedColor = currentColor; |
380 int savedColor = currentColor; |
333 setColor(255, 255, 255); |
381 setColor(255, 255, 255); |
334 fillRect(x, y, w, h); |
382 fillRect(x, y, w, h); |
335 setColor(savedColor); |
383 setColor(savedColor); |
336 } |
384 } |
337 |
385 |
338 /** |
386 /** |
339 * Sets flag indicating that we are in Canvas.paint() callback |
387 * Sets flag indicating that we are in Canvas.paint() callback |
340 */ |
388 */ |
341 void beginPaint() { |
389 void beginPaint() |
390 { |
|
342 paintCallBack = true; |
391 paintCallBack = true; |
343 } |
392 } |
344 |
393 |
345 /** |
394 /** |
346 * Sets flag indicating that we are exiting Canvas.paint() callback |
395 * Sets flag indicating that we are exiting Canvas.paint() callback |
347 */ |
396 */ |
348 void endPaint() { |
397 void endPaint() |
398 { |
|
349 paintCallBack = false; |
399 paintCallBack = false; |
350 } |
400 } |
351 |
401 |
352 /** |
402 /** |
353 * Provides the serialization lock for buffer writing and flushing |
403 * Provides the serialization lock for buffer writing and flushing |
354 * @return lock used for synchronizing command buffer access |
404 * @return lock used for synchronizing command buffer access |
355 */ |
405 */ |
356 Object getLock() { |
406 Object getLock() |
407 { |
|
357 return flushLock; |
408 return flushLock; |
358 } |
409 } |
359 |
410 |
360 /** |
411 /** |
361 * Sets coordinate translation. Translations are cumulative. |
412 * Sets coordinate translation. Translations are cumulative. |
362 * |
413 * |
363 * @param xDelta x-shift for coordinates. |
414 * @param xDelta x-shift for coordinates. |
364 * @param yDelta y-shift for coordinates. |
415 * @param yDelta y-shift for coordinates. |
365 */ |
416 */ |
366 public void translate(int xDelta, int yDelta) { |
417 public void translate(int xDelta, int yDelta) |
367 synchronized(flushLock) { |
418 { |
368 if(!buffered) { |
419 synchronized(flushLock) |
420 { |
|
421 if(!buffered) |
|
422 { |
|
369 final int xDelta_ = xDelta; |
423 final int xDelta_ = xDelta; |
370 final int yDelta_ = yDelta; |
424 final int yDelta_ = yDelta; |
371 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
425 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
372 public void run() { |
426 { |
427 public void run() |
|
428 { |
|
373 gc.translate(xDelta_, yDelta_); |
429 gc.translate(xDelta_, yDelta_); |
374 }}); |
430 } |
375 } else { |
431 }); |
432 } |
|
433 else |
|
434 { |
|
376 gc.translate(xDelta, yDelta); |
435 gc.translate(xDelta, yDelta); |
377 } |
436 } |
378 } |
437 } |
379 translateX += xDelta; |
438 translateX += xDelta; |
380 translateY += yDelta; |
439 translateY += yDelta; |
383 /** |
442 /** |
384 * Returns current X-shift of coordinate translation. |
443 * Returns current X-shift of coordinate translation. |
385 * |
444 * |
386 * @return Current X-shift of coordinate translation. |
445 * @return Current X-shift of coordinate translation. |
387 */ |
446 */ |
388 public int getTranslateX() { |
447 public int getTranslateX() |
448 { |
|
389 return translateX; |
449 return translateX; |
390 } |
450 } |
391 |
451 |
392 /** |
452 /** |
393 * Returns current Y-shift of coordinate translation. |
453 * Returns current Y-shift of coordinate translation. |
394 * |
454 * |
395 * @return current Y-shift of coordinate translation. |
455 * @return current Y-shift of coordinate translation. |
396 */ |
456 */ |
397 public int getTranslateY() { |
457 public int getTranslateY() |
458 { |
|
398 return translateY; |
459 return translateY; |
399 } |
460 } |
400 |
461 |
401 /** |
462 /** |
402 * Returns current color in 0x00RRGGBB format. |
463 * Returns current color in 0x00RRGGBB format. |
403 * |
464 * |
404 * @return Current color in 0x00RRGGBB format. |
465 * @return Current color in 0x00RRGGBB format. |
405 */ |
466 */ |
406 public int getColor() { |
467 public int getColor() |
468 { |
|
407 return currentColor; |
469 return currentColor; |
408 } |
470 } |
409 |
471 |
410 /** |
472 /** |
411 * Returns red component of current color. |
473 * Returns red component of current color. |
412 * |
474 * |
413 * @return Red component of current color in the range of 0-255. |
475 * @return Red component of current color in the range of 0-255. |
414 */ |
476 */ |
415 public int getRedComponent() { |
477 public int getRedComponent() |
478 { |
|
416 return currentColor >> 16; |
479 return currentColor >> 16; |
417 } |
480 } |
418 |
481 |
419 /** |
482 /** |
420 * Returns green component of current color. |
483 * Returns green component of current color. |
421 * |
484 * |
422 * @return Green component of current color in the range of 0-255. |
485 * @return Green component of current color in the range of 0-255. |
423 */ |
486 */ |
424 public int getGreenComponent() { |
487 public int getGreenComponent() |
488 { |
|
425 return (currentColor >> 8) & COMPONENT_MASK; |
489 return (currentColor >> 8) & COMPONENT_MASK; |
426 } |
490 } |
427 |
491 |
428 /** |
492 /** |
429 * Returns blue component of current color. |
493 * Returns blue component of current color. |
430 * |
494 * |
431 * @return Blue component of current color in the range of 0-255. |
495 * @return Blue component of current color in the range of 0-255. |
432 */ |
496 */ |
433 public int getBlueComponent() { |
497 public int getBlueComponent() |
498 { |
|
434 return currentColor & COMPONENT_MASK; |
499 return currentColor & COMPONENT_MASK; |
435 } |
500 } |
436 |
501 |
437 /** |
502 /** |
438 * Returns current grayscale color. |
503 * Returns current grayscale color. |
439 * |
504 * |
440 * @return Returns current grayscale color in the range 0-255. |
505 * @return Returns current grayscale color in the range 0-255. |
441 */ |
506 */ |
442 public int getGrayScale() { |
507 public int getGrayScale() |
508 { |
|
443 return (getRedComponent() + getGreenComponent() + getBlueComponent()) / 3; |
509 return (getRedComponent() + getGreenComponent() + getBlueComponent()) / 3; |
444 } |
510 } |
445 |
511 |
446 /** |
512 /** |
447 * Sets the current color by color components for red, green and blue. |
513 * Sets the current color by color components for red, green and blue. |
448 * |
514 * |
449 * @param r - red component of the color to be set. |
515 * @param r - red component of the color to be set. |
450 * @param g - green component of the color to be set. |
516 * @param g - green component of the color to be set. |
451 * @param b - blue component of the color to be set. |
517 * @param b - blue component of the color to be set. |
452 */ |
518 */ |
453 public void setColor(int r, int g, int b) { |
519 public void setColor(int r, int g, int b) |
454 if (r < 0 || r > 255 || |
520 { |
455 g < 0 || g > 255 || |
521 if(r < 0 || r > 255 || |
456 b < 0 || b > 255 ) { |
522 g < 0 || g > 255 || |
457 throw new IllegalArgumentException(); |
523 b < 0 || b > 255) |
458 } |
524 { |
459 synchronized(flushLock) { |
525 throw new IllegalArgumentException(); |
460 if(!buffered) { |
526 } |
527 synchronized(flushLock) |
|
528 { |
|
529 if(!buffered) |
|
530 { |
|
461 final int r_ = r; |
531 final int r_ = r; |
462 final int g_ = g; |
532 final int g_ = g; |
463 final int b_ = b; |
533 final int b_ = b; |
464 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
534 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
465 public void run() { |
535 { |
536 public void run() |
|
537 { |
|
466 gc.setForegroundColor(r_, g_, b_); |
538 gc.setForegroundColor(r_, g_, b_); |
467 gc.setBackgroundColor(r_, g_, b_); |
539 gc.setBackgroundColor(r_, g_, b_); |
468 }}); |
540 } |
469 } else { |
541 }); |
542 } |
|
543 else |
|
544 { |
|
470 gc.setForegroundColor(r, g, b); |
545 gc.setForegroundColor(r, g, b); |
471 gc.setBackgroundColor(r, g, b); |
546 gc.setBackgroundColor(r, g, b); |
472 } |
547 } |
473 } |
548 } |
474 currentColor = ((r << 16) | (g << 8) | b) & RGB_MASK; |
549 currentColor = ((r << 16) | (g << 8) | b) & RGB_MASK; |
477 /** |
552 /** |
478 * Sets the current color. |
553 * Sets the current color. |
479 * |
554 * |
480 * @param RGB - color to be set in the form of 0x00RRGGBB. |
555 * @param RGB - color to be set in the form of 0x00RRGGBB. |
481 */ |
556 */ |
482 public void setColor(int RGB) { |
557 public void setColor(int RGB) |
558 { |
|
483 int maskedRGB = RGB & RGB_MASK; |
559 int maskedRGB = RGB & RGB_MASK; |
484 final int r = maskedRGB >> 16; |
560 final int r = maskedRGB >> 16; |
485 final int g = (maskedRGB >> 8) & COMPONENT_MASK; |
561 final int g = (maskedRGB >> 8) & COMPONENT_MASK; |
486 final int b = maskedRGB & COMPONENT_MASK; |
562 final int b = maskedRGB & COMPONENT_MASK; |
487 synchronized(flushLock) { |
563 synchronized(flushLock) |
488 if(!buffered) { |
564 { |
489 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
565 if(!buffered) |
490 public void run() { |
566 { |
567 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
|
568 { |
|
569 public void run() |
|
570 { |
|
491 gc.setForegroundColor(r, g, b); |
571 gc.setForegroundColor(r, g, b); |
492 gc.setBackgroundColor(r, g, b); |
572 gc.setBackgroundColor(r, g, b); |
493 }}); |
573 } |
494 } else { |
574 }); |
575 } |
|
576 else |
|
577 { |
|
495 gc.setForegroundColor(r, g, b); |
578 gc.setForegroundColor(r, g, b); |
496 gc.setBackgroundColor(r, g, b); |
579 gc.setBackgroundColor(r, g, b); |
497 } |
580 } |
498 } |
581 } |
499 currentColor = maskedRGB; |
582 currentColor = maskedRGB; |
502 /** |
585 /** |
503 * Sets gray-scale color. |
586 * Sets gray-scale color. |
504 * |
587 * |
505 * @param val - gray-scale value to be set in the range of 0-255. |
588 * @param val - gray-scale value to be set in the range of 0-255. |
506 */ |
589 */ |
507 public void setGrayScale(int val) { |
590 public void setGrayScale(int val) |
508 if ( (val < 0) || (val > 255)) { |
591 { |
509 throw new IllegalArgumentException(); |
592 if((val < 0) || (val > 255)) |
593 { |
|
594 throw new IllegalArgumentException(); |
|
510 } |
595 } |
511 final int col = val & COMPONENT_MASK; |
596 final int col = val & COMPONENT_MASK; |
512 synchronized(flushLock) { |
597 synchronized(flushLock) |
513 if(!buffered) { |
598 { |
514 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
599 if(!buffered) |
515 public void run() { |
600 { |
601 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
|
602 { |
|
603 public void run() |
|
604 { |
|
516 gc.setForegroundColor(col, col, col); |
605 gc.setForegroundColor(col, col, col); |
517 gc.setBackgroundColor(col, col, col); |
606 gc.setBackgroundColor(col, col, col); |
518 }}); |
607 } |
519 } else { |
608 }); |
609 } |
|
610 else |
|
611 { |
|
520 gc.setForegroundColor(col, col, col); |
612 gc.setForegroundColor(col, col, col); |
521 gc.setBackgroundColor(col, col, col); |
613 gc.setBackgroundColor(col, col, col); |
522 } |
614 } |
523 } |
615 } |
524 currentColor = ((col << 16) | (col << 8) | col) & RGB_MASK; |
616 currentColor = ((col << 16) | (col << 8) | col) & RGB_MASK; |
527 /** |
619 /** |
528 * Returns the current font. |
620 * Returns the current font. |
529 * |
621 * |
530 * @return Current font. |
622 * @return Current font. |
531 */ |
623 */ |
532 public Font getFont() { |
624 public Font getFont() |
625 { |
|
533 return currentFont; |
626 return currentFont; |
534 } |
627 } |
535 |
628 |
536 /** |
629 /** |
537 * Sets the font to be used for string rendering. |
630 * Sets the font to be used for string rendering. |
538 * |
631 * |
539 * @param newFont - the font to be used for string rendering. |
632 * @param newFont - the font to be used for string rendering. |
540 */ |
633 */ |
541 public void setFont(Font newFont) { |
634 public void setFont(Font newFont) |
542 synchronized(flushLock) { |
635 { |
543 if(!buffered) { |
636 synchronized(flushLock) |
637 { |
|
638 if(!buffered) |
|
639 { |
|
544 final Font newFont_ = newFont; |
640 final Font newFont_ = newFont; |
545 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
641 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
546 public void run() { |
642 { |
643 public void run() |
|
644 { |
|
547 gc.setFont(Font.getESWTFont(newFont_).handle); |
645 gc.setFont(Font.getESWTFont(newFont_).handle); |
548 }}); |
646 } |
549 } else { |
647 }); |
648 } |
|
649 else |
|
650 { |
|
550 gc.setFont(Font.getESWTFont(newFont).handle); |
651 gc.setFont(Font.getESWTFont(newFont).handle); |
551 } |
652 } |
552 } |
653 } |
553 currentFont = newFont; |
654 currentFont = newFont; |
554 } |
655 } |
556 /** |
657 /** |
557 * Returns left bound of clip rectangle. |
658 * Returns left bound of clip rectangle. |
558 * |
659 * |
559 * @return Left bound of clip rectangle. |
660 * @return Left bound of clip rectangle. |
560 */ |
661 */ |
561 public int getClipX() { |
662 public int getClipX() |
663 { |
|
562 return currentClip[0]; |
664 return currentClip[0]; |
563 } |
665 } |
564 |
666 |
565 /** |
667 /** |
566 * Returns top bound of clip rectangle. |
668 * Returns top bound of clip rectangle. |
567 * |
669 * |
568 * @return Top bound of clip rectangle. |
670 * @return Top bound of clip rectangle. |
569 */ |
671 */ |
570 public int getClipY() { |
672 public int getClipY() |
673 { |
|
571 return currentClip[1]; |
674 return currentClip[1]; |
572 } |
675 } |
573 |
676 |
574 /** |
677 /** |
575 * Returns width of clip rectangle. |
678 * Returns width of clip rectangle. |
576 * |
679 * |
577 * @return Width of clip rectangle. |
680 * @return Width of clip rectangle. |
578 */ |
681 */ |
579 public int getClipWidth() { |
682 public int getClipWidth() |
683 { |
|
580 return currentClip[2]; |
684 return currentClip[2]; |
581 } |
685 } |
582 |
686 |
583 /** |
687 /** |
584 * Returns height of clip rectangle. |
688 * Returns height of clip rectangle. |
585 * |
689 * |
586 * @return Height of clip rectangle. |
690 * @return Height of clip rectangle. |
587 */ |
691 */ |
588 public int getClipHeight() { |
692 public int getClipHeight() |
693 { |
|
589 return currentClip[3]; |
694 return currentClip[3]; |
590 } |
695 } |
591 |
696 |
592 /** |
697 /** |
593 * Intersects current clip rectangle with the specified one. |
698 * Intersects current clip rectangle with the specified one. |
598 * current one. |
703 * current one. |
599 * @param w - width of the clip rectangle to intersect with the current one. |
704 * @param w - width of the clip rectangle to intersect with the current one. |
600 * @param h - height of the clip rectangle to intersect with the current |
705 * @param h - height of the clip rectangle to intersect with the current |
601 * one. |
706 * one. |
602 */ |
707 */ |
603 public void clipRect(int x, int y, int w, int h) { |
708 public void clipRect(int x, int y, int w, int h) |
604 final int cx2 = Math.min( currentClip[0] + currentClip[2], x + w ); |
709 { |
605 final int cy2 = Math.min( currentClip[1] + currentClip[3], y + h ); |
710 final int cx2 = Math.min(currentClip[0] + currentClip[2], x + w); |
711 final int cy2 = Math.min(currentClip[1] + currentClip[3], y + h); |
|
606 // setting of clip to Java Graphics |
712 // setting of clip to Java Graphics |
607 currentClip[0] = Math.max( x, currentClip[0]); |
713 currentClip[0] = Math.max(x, currentClip[0]); |
608 currentClip[1] = Math.max( y, currentClip[1]); |
714 currentClip[1] = Math.max(y, currentClip[1]); |
609 currentClip[2] = cx2 - currentClip[0]; |
715 currentClip[2] = cx2 - currentClip[0]; |
610 currentClip[3] = cy2 - currentClip[1]; |
716 currentClip[3] = cy2 - currentClip[1]; |
611 synchronized(flushLock) { |
717 synchronized(flushLock) |
612 if(!buffered) { |
718 { |
613 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
719 if(!buffered) |
614 public void run() { |
720 { |
721 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
|
722 { |
|
723 public void run() |
|
724 { |
|
615 gc.setClip(currentClip[0], currentClip[1], currentClip[2], currentClip[3], false); |
725 gc.setClip(currentClip[0], currentClip[1], currentClip[2], currentClip[3], false); |
616 }}); |
726 } |
617 } else { |
727 }); |
728 } |
|
729 else |
|
730 { |
|
618 gc.setClip(currentClip[0], currentClip[1], currentClip[2], currentClip[3], false); |
731 gc.setClip(currentClip[0], currentClip[1], currentClip[2], currentClip[3], false); |
619 } |
732 } |
620 } |
733 } |
621 } |
734 } |
622 |
735 |
626 * @param x - left bound of the new clip rectangle. |
739 * @param x - left bound of the new clip rectangle. |
627 * @param y - top bound of the new clip rectangle. |
740 * @param y - top bound of the new clip rectangle. |
628 * @param w - width of the new clip rectangle. |
741 * @param w - width of the new clip rectangle. |
629 * @param h - height of the new clip rectangle. |
742 * @param h - height of the new clip rectangle. |
630 */ |
743 */ |
631 public void setClip(int x, int y, int w, int h) { |
744 public void setClip(int x, int y, int w, int h) |
632 synchronized(flushLock) { |
745 { |
633 if(!buffered) { |
746 synchronized(flushLock) |
747 { |
|
748 if(!buffered) |
|
749 { |
|
634 final int x_ = x; |
750 final int x_ = x; |
635 final int y_ = y; |
751 final int y_ = y; |
636 final int w_ = w; |
752 final int w_ = w; |
637 final int h_ = h; |
753 final int h_ = h; |
638 |
754 |
639 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
755 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
640 public void run() { |
756 { |
757 public void run() |
|
758 { |
|
641 gc.setClip(x_, y_, w_, h_, false); |
759 gc.setClip(x_, y_, w_, h_, false); |
642 }}); |
760 } |
643 } else { |
761 }); |
762 } |
|
763 else |
|
764 { |
|
644 gc.setClip(x, y, w, h, false); |
765 gc.setClip(x, y, w, h, false); |
645 } |
766 } |
646 } |
767 } |
647 currentClip[0] = x; |
768 currentClip[0] = x; |
648 currentClip[1] = y; |
769 currentClip[1] = y; |
656 * @param xStart - X-coordinate of line starting point. |
777 * @param xStart - X-coordinate of line starting point. |
657 * @param yStart - Y-coordinate of line starting point. |
778 * @param yStart - Y-coordinate of line starting point. |
658 * @param xEnd - X-coordinate of line end point. |
779 * @param xEnd - X-coordinate of line end point. |
659 * @param yEnd - Y-coordinate of line end point. |
780 * @param yEnd - Y-coordinate of line end point. |
660 */ |
781 */ |
661 public void drawLine(int xStart, int yStart, int xEnd, int yEnd) { |
782 public void drawLine(int xStart, int yStart, int xEnd, int yEnd) |
662 synchronized(flushLock) { |
783 { |
663 if(!buffered) { |
784 synchronized(flushLock) |
785 { |
|
786 if(!buffered) |
|
787 { |
|
664 final int xs_ = xStart; |
788 final int xs_ = xStart; |
665 final int ys_ = yStart; |
789 final int ys_ = yStart; |
666 final int xe_ = xEnd; |
790 final int xe_ = xEnd; |
667 final int ye_ = yEnd; |
791 final int ye_ = yEnd; |
668 |
792 |
669 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
793 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
670 public void run() { |
794 { |
795 public void run() |
|
796 { |
|
671 gc.drawLine(xs_, ys_, xe_, ye_); |
797 gc.drawLine(xs_, ys_, xe_, ye_); |
672 }}); |
798 } |
673 } else { |
799 }); |
800 } |
|
801 else |
|
802 { |
|
674 gc.drawLine(xStart, yStart, xEnd, yEnd); |
803 gc.drawLine(xStart, yStart, xEnd, yEnd); |
675 } |
804 } |
676 } |
805 } |
677 } |
806 } |
678 |
807 |
682 * @param x - x coordinate of top left corner |
811 * @param x - x coordinate of top left corner |
683 * @param y - y coordinate of top left corner |
812 * @param y - y coordinate of top left corner |
684 * @param w - width of the rectangle |
813 * @param w - width of the rectangle |
685 * @param h - height of the rectangle |
814 * @param h - height of the rectangle |
686 */ |
815 */ |
687 public void fillRect(int x, int y, int w, int h) { |
816 public void fillRect(int x, int y, int w, int h) |
688 if ((w < 0) || (h < 0)) { |
817 { |
818 if((w < 0) || (h < 0)) |
|
819 { |
|
689 return; |
820 return; |
690 } |
821 } |
691 synchronized(flushLock) { |
822 synchronized(flushLock) |
692 if(!buffered) { |
823 { |
824 if(!buffered) |
|
825 { |
|
693 final int x_ = x; |
826 final int x_ = x; |
694 final int y_ = y; |
827 final int y_ = y; |
695 final int w_ = w; |
828 final int w_ = w; |
696 final int h_ = h; |
829 final int h_ = h; |
697 |
830 |
698 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
831 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
699 public void run() { |
832 { |
833 public void run() |
|
834 { |
|
700 gc.fillRect(x_, y_, w_, h_); |
835 gc.fillRect(x_, y_, w_, h_); |
701 }}); |
836 } |
702 } else { |
837 }); |
838 } |
|
839 else |
|
840 { |
|
703 gc.fillRect(x, y, w, h); |
841 gc.fillRect(x, y, w, h); |
704 } |
842 } |
705 } |
843 } |
706 } |
844 } |
707 |
845 |
711 * @param x - x coordinate of top left corner |
849 * @param x - x coordinate of top left corner |
712 * @param y - y coordinate of top left corner |
850 * @param y - y coordinate of top left corner |
713 * @param w - width of the rectangle |
851 * @param w - width of the rectangle |
714 * @param h - height of the rectangle |
852 * @param h - height of the rectangle |
715 */ |
853 */ |
716 public void drawRect(int x, int y, int w, int h) { |
854 public void drawRect(int x, int y, int w, int h) |
717 if ((w < 0) || (h < 0)) { |
855 { |
856 if((w < 0) || (h < 0)) |
|
857 { |
|
718 return; |
858 return; |
719 } |
859 } |
720 synchronized(flushLock) { |
860 synchronized(flushLock) |
721 if(!buffered) { |
861 { |
862 if(!buffered) |
|
863 { |
|
722 final int x_ = x; |
864 final int x_ = x; |
723 final int y_ = y; |
865 final int y_ = y; |
724 final int w_ = w; |
866 final int w_ = w; |
725 final int h_ = h; |
867 final int h_ = h; |
726 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
868 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
727 public void run() { |
869 { |
870 public void run() |
|
871 { |
|
728 gc.drawRect(x_, y_, w_, h_); |
872 gc.drawRect(x_, y_, w_, h_); |
729 }}); |
873 } |
730 } else { |
874 }); |
875 } |
|
876 else |
|
877 { |
|
731 gc.drawRect(x, y, w, h); |
878 gc.drawRect(x, y, w, h); |
732 } |
879 } |
733 } |
880 } |
734 } |
881 } |
735 |
882 |
741 * @param w - width of the rectangle |
888 * @param w - width of the rectangle |
742 * @param h - height of the rectangle |
889 * @param h - height of the rectangle |
743 * @param arcW - arc width for corner rounding. |
890 * @param arcW - arc width for corner rounding. |
744 * @param arcH - arc height for corner rounding. |
891 * @param arcH - arc height for corner rounding. |
745 */ |
892 */ |
746 public void drawRoundRect(int x, int y, int w, int h, int arcW, int arcH) { |
893 public void drawRoundRect(int x, int y, int w, int h, int arcW, int arcH) |
747 if ((w < 0) || (h < 0) || (arcW < 0) || (arcH < 0)) { |
894 { |
895 if((w < 0) || (h < 0) || (arcW < 0) || (arcH < 0)) |
|
896 { |
|
748 return; |
897 return; |
749 } |
898 } |
750 synchronized(flushLock) { |
899 synchronized(flushLock) |
751 if(!buffered) { |
900 { |
901 if(!buffered) |
|
902 { |
|
752 final int x_ = x; |
903 final int x_ = x; |
753 final int y_ = y; |
904 final int y_ = y; |
754 final int w_ = w; |
905 final int w_ = w; |
755 final int h_ = h; |
906 final int h_ = h; |
756 final int arcW_ = arcW; |
907 final int arcW_ = arcW; |
757 final int arcH_ = arcH; |
908 final int arcH_ = arcH; |
758 |
909 |
759 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
910 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
760 public void run() { |
911 { |
912 public void run() |
|
913 { |
|
761 gc.drawRoundRect(x_, y_, w_, h_, arcW_, arcH_); |
914 gc.drawRoundRect(x_, y_, w_, h_, arcW_, arcH_); |
762 }}); |
915 } |
763 } else { |
916 }); |
917 } |
|
918 else |
|
919 { |
|
764 gc.drawRoundRect(x, y, w, h, arcW, arcH); |
920 gc.drawRoundRect(x, y, w, h, arcW, arcH); |
765 } |
921 } |
766 } |
922 } |
767 } |
923 } |
768 |
924 |
774 * @param w - width of the rectangle |
930 * @param w - width of the rectangle |
775 * @param h - height of the rectangle |
931 * @param h - height of the rectangle |
776 * @param arcW - arc width for corner rounding. |
932 * @param arcW - arc width for corner rounding. |
777 * @param arcH - arc height for corner rounding. |
933 * @param arcH - arc height for corner rounding. |
778 */ |
934 */ |
779 public void fillRoundRect(int x, int y, int w, int h, int arcW, int arcH) { |
935 public void fillRoundRect(int x, int y, int w, int h, int arcW, int arcH) |
780 if ((w < 0) || (h < 0) || (arcW < 0) || (arcH < 0)) { |
936 { |
937 if((w < 0) || (h < 0) || (arcW < 0) || (arcH < 0)) |
|
938 { |
|
781 return; |
939 return; |
782 } |
940 } |
783 synchronized(flushLock) { |
941 synchronized(flushLock) |
784 if(!buffered) { |
942 { |
943 if(!buffered) |
|
944 { |
|
785 final int x_ = x; |
945 final int x_ = x; |
786 final int y_ = y; |
946 final int y_ = y; |
787 final int w_ = w; |
947 final int w_ = w; |
788 final int h_ = h; |
948 final int h_ = h; |
789 final int arcW_ = arcW; |
949 final int arcW_ = arcW; |
790 final int arcH_ = arcH; |
950 final int arcH_ = arcH; |
791 |
951 |
792 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
952 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
793 public void run() { |
953 { |
954 public void run() |
|
955 { |
|
794 gc.fillRoundRect(x_, y_, w_, h_, arcW_, arcH_); |
956 gc.fillRoundRect(x_, y_, w_, h_, arcW_, arcH_); |
795 }}); |
957 } |
796 } else { |
958 }); |
959 } |
|
960 else |
|
961 { |
|
797 gc.fillRoundRect(x, y, w, h, arcW, arcH); |
962 gc.fillRoundRect(x, y, w, h, arcW, arcH); |
798 } |
963 } |
799 } |
964 } |
800 } |
965 } |
801 |
966 |
809 * @param w - width of the rectangle to contain the arc. |
974 * @param w - width of the rectangle to contain the arc. |
810 * @param h - height of the rectangle to contain the arc. |
975 * @param h - height of the rectangle to contain the arc. |
811 * @param startAngle - starting angle of the arc in degrees. |
976 * @param startAngle - starting angle of the arc in degrees. |
812 * @param arcAngle - angle to spread the arc in degrees. |
977 * @param arcAngle - angle to spread the arc in degrees. |
813 */ |
978 */ |
814 public void fillArc(int x, int y, int w, int h, int startAngle, int arcAngle) { |
979 public void fillArc(int x, int y, int w, int h, int startAngle, int arcAngle) |
815 if ((w < 0) || (h < 0)) { |
980 { |
981 if((w < 0) || (h < 0)) |
|
982 { |
|
816 return; |
983 return; |
817 } |
984 } |
818 synchronized(flushLock) { |
985 synchronized(flushLock) |
819 if(!buffered) { |
986 { |
987 if(!buffered) |
|
988 { |
|
820 final int x_ = x; |
989 final int x_ = x; |
821 final int y_ = y; |
990 final int y_ = y; |
822 final int w_ = w; |
991 final int w_ = w; |
823 final int h_ = h; |
992 final int h_ = h; |
824 final int startAngle_ = startAngle; |
993 final int startAngle_ = startAngle; |
825 final int arcAngle_ = arcAngle; |
994 final int arcAngle_ = arcAngle; |
826 |
995 |
827 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
996 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
828 public void run() { |
997 { |
998 public void run() |
|
999 { |
|
829 gc.fillArc(x_, y_, w_, h_, startAngle_, arcAngle_); |
1000 gc.fillArc(x_, y_, w_, h_, startAngle_, arcAngle_); |
830 }}); |
1001 } |
831 } else { |
1002 }); |
1003 } |
|
1004 else |
|
1005 { |
|
832 gc.fillArc(x, y, w, h, startAngle, arcAngle); |
1006 gc.fillArc(x, y, w, h, startAngle, arcAngle); |
833 } |
1007 } |
834 } |
1008 } |
835 } |
1009 } |
836 |
1010 |
844 * @param w - width of the rectangle to contain the arc. |
1018 * @param w - width of the rectangle to contain the arc. |
845 * @param h - height of the rectangle to contain the arc. |
1019 * @param h - height of the rectangle to contain the arc. |
846 * @param startAngle - starting angle of the arc in degrees. |
1020 * @param startAngle - starting angle of the arc in degrees. |
847 * @param arcAngle - angle to spread the arc in degrees. |
1021 * @param arcAngle - angle to spread the arc in degrees. |
848 */ |
1022 */ |
849 public void drawArc(int x, int y, int w, int h, int startAngle, int arcAngle) { |
1023 public void drawArc(int x, int y, int w, int h, int startAngle, int arcAngle) |
850 if ((w < 0) || (h < 0)) { |
1024 { |
1025 if((w < 0) || (h < 0)) |
|
1026 { |
|
851 return; |
1027 return; |
852 } |
1028 } |
853 synchronized(flushLock) { |
1029 synchronized(flushLock) |
854 if(!buffered) { |
1030 { |
1031 if(!buffered) |
|
1032 { |
|
855 final int x_ = x; |
1033 final int x_ = x; |
856 final int y_ = y; |
1034 final int y_ = y; |
857 final int w_ = w; |
1035 final int w_ = w; |
858 final int h_ = h; |
1036 final int h_ = h; |
859 final int startAngle_ = startAngle; |
1037 final int startAngle_ = startAngle; |
860 final int arcAngle_ = arcAngle; |
1038 final int arcAngle_ = arcAngle; |
861 |
1039 |
862 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
1040 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
863 public void run() { |
1041 { |
1042 public void run() |
|
1043 { |
|
864 gc.drawArc(x_, y_, w_, h_, startAngle_, arcAngle_); |
1044 gc.drawArc(x_, y_, w_, h_, startAngle_, arcAngle_); |
865 }}); |
1045 } |
866 } else { |
1046 }); |
1047 } |
|
1048 else |
|
1049 { |
|
867 gc.drawArc(x, y, w, h, startAngle, arcAngle); |
1050 gc.drawArc(x, y, w, h, startAngle, arcAngle); |
868 } |
1051 } |
869 } |
1052 } |
870 } |
1053 } |
871 |
1054 |
878 * @param anch - anchor, specifies the way to locate the text around the anchor |
1061 * @param anch - anchor, specifies the way to locate the text around the anchor |
879 * point. May be the combination of Graphics.TOP, |
1062 * point. May be the combination of Graphics.TOP, |
880 * Graphics.BOTTOM, Graphics.BASELINE, Graphics.LEFT, |
1063 * Graphics.BOTTOM, Graphics.BASELINE, Graphics.LEFT, |
881 * Graphics.RIGHT, Graphics.HCENTER. |
1064 * Graphics.RIGHT, Graphics.HCENTER. |
882 */ |
1065 */ |
883 public void drawString(String string, int xPos, int yPos, int anch) { |
1066 public void drawString(String string, int xPos, int yPos, int anch) |
884 if (string == null) { |
1067 { |
1068 if(string == null) |
|
1069 { |
|
885 throw new NullPointerException( |
1070 throw new NullPointerException( |
886 MsgRepository.GRAPHICS_EXCEPTION_STRING_IS_NULL); |
1071 MsgRepository.GRAPHICS_EXCEPTION_STRING_IS_NULL); |
887 } |
1072 } |
888 |
1073 |
889 if (!checkTextAnchors(anch)) { |
1074 if(!checkTextAnchors(anch)) |
1075 { |
|
890 throw new IllegalArgumentException( |
1076 throw new IllegalArgumentException( |
891 MsgRepository.GRAPHICS_EXCEPTION_INVALID_ANCHOR); |
1077 MsgRepository.GRAPHICS_EXCEPTION_INVALID_ANCHOR); |
892 } |
1078 } |
893 |
1079 |
894 final int alignments = GraphicsContext.ALIGNMENT_TOP | GraphicsContext.ALIGNMENT_LEFT; |
1080 final int alignments = GraphicsContext.ALIGNMENT_TOP | GraphicsContext.ALIGNMENT_LEFT; |
895 final int[] boundingBox = new int[4]; |
1081 final int[] boundingBox = new int[4]; |
896 final String localStr = string; |
1082 final String localStr = string; |
897 |
1083 |
898 if (paintCallBack) { |
1084 if(paintCallBack) |
1085 { |
|
899 gc.getTextBoundingBox(boundingBox, string, alignments, 0); |
1086 gc.getTextBoundingBox(boundingBox, string, alignments, 0); |
900 } |
1087 } |
901 else { |
1088 else |
902 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
1089 { |
903 public void run() { |
1090 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
1091 { |
|
1092 public void run() |
|
1093 { |
|
904 FontUtils fu = new FontUtils(Font.getESWTFont(currentFont).handle); |
1094 FontUtils fu = new FontUtils(Font.getESWTFont(currentFont).handle); |
905 fu.getBoundingRect(boundingBox, localStr); |
1095 fu.getBoundingRect(boundingBox, localStr); |
906 } |
1096 } |
907 }); |
1097 }); |
908 } |
1098 } |
912 // boundingBox[RECT_WIDTH] - the width of the text bounding box |
1102 // boundingBox[RECT_WIDTH] - the width of the text bounding box |
913 // boundingBox[RECT_HEIGHT] - the height of the text bounding box |
1103 // boundingBox[RECT_HEIGHT] - the height of the text bounding box |
914 |
1104 |
915 // Arrange vertical alignments |
1105 // Arrange vertical alignments |
916 int y = yPos; |
1106 int y = yPos; |
917 if (isFlag(anch, Graphics.BOTTOM)) { |
1107 if(isFlag(anch, Graphics.BOTTOM)) |
1108 { |
|
918 y = yPos - boundingBox[GraphicsContext.RECT_HEIGHT]; |
1109 y = yPos - boundingBox[GraphicsContext.RECT_HEIGHT]; |
919 } |
1110 } |
920 if (isFlag(anch, Graphics.BASELINE)) { |
1111 if(isFlag(anch, Graphics.BASELINE)) |
1112 { |
|
921 y = yPos - currentFont.getBaselinePosition(); |
1113 y = yPos - currentFont.getBaselinePosition(); |
922 } |
1114 } |
923 |
1115 |
924 // Arrange horizontal alignments |
1116 // Arrange horizontal alignments |
925 int x = xPos; |
1117 int x = xPos; |
926 if (isFlag(anch, Graphics.RIGHT)) { |
1118 if(isFlag(anch, Graphics.RIGHT)) |
1119 { |
|
927 x = xPos - boundingBox[GraphicsContext.RECT_WIDTH]; |
1120 x = xPos - boundingBox[GraphicsContext.RECT_WIDTH]; |
928 } |
1121 } |
929 if (isFlag(anch, Graphics.HCENTER)) { |
1122 if(isFlag(anch, Graphics.HCENTER)) |
1123 { |
|
930 x = xPos - boundingBox[GraphicsContext.RECT_WIDTH] / 2; |
1124 x = xPos - boundingBox[GraphicsContext.RECT_WIDTH] / 2; |
931 } |
1125 } |
932 synchronized(flushLock) { |
1126 synchronized(flushLock) |
933 if(!buffered) { |
1127 { |
1128 if(!buffered) |
|
1129 { |
|
934 final int x_ = x; |
1130 final int x_ = x; |
935 final int y_ = y; |
1131 final int y_ = y; |
936 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
1132 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
937 public void run() { |
1133 { |
1134 public void run() |
|
1135 { |
|
938 gc.drawString(localStr, x_, y_, true); |
1136 gc.drawString(localStr, x_, y_, true); |
939 }}); |
1137 } |
940 } else { |
1138 }); |
1139 } |
|
1140 else |
|
1141 { |
|
941 gc.drawString(localStr, x, y, true); |
1142 gc.drawString(localStr, x, y, true); |
942 } |
1143 } |
943 } |
1144 } |
944 } |
1145 } |
945 |
1146 |
946 private static boolean isFlag(int anchor, int flag) { |
1147 private static boolean isFlag(int anchor, int flag) |
1148 { |
|
947 return (anchor & flag) != 0; |
1149 return (anchor & flag) != 0; |
948 } |
1150 } |
949 |
1151 |
950 /** |
1152 /** |
951 * Draws a string with specified color and font. |
1153 * Draws a string with specified color and font. |
959 * anchor point. May be the combination of Graphics.TOP, |
1161 * anchor point. May be the combination of Graphics.TOP, |
960 * Graphics.BOTTOM, Graphics.BASELINE, Graphics.LEFT, |
1162 * Graphics.BOTTOM, Graphics.BASELINE, Graphics.LEFT, |
961 * Graphics.RIGHT, Graphics.HCENTER. |
1163 * Graphics.RIGHT, Graphics.HCENTER. |
962 */ |
1164 */ |
963 public void drawSubstring(java.lang.String string, int offset, int length, |
1165 public void drawSubstring(java.lang.String string, int offset, int length, |
964 int xPos, int yPos, int anch) { |
1166 int xPos, int yPos, int anch) |
1167 { |
|
965 drawString(string.substring(offset, length), xPos, yPos, anch); |
1168 drawString(string.substring(offset, length), xPos, yPos, anch); |
966 } |
1169 } |
967 |
1170 |
968 /** |
1171 /** |
969 * Draws a character with specified color and font. |
1172 * Draws a character with specified color and font. |
974 * @param anch - anchor, specifies the way to locate the text around the |
1177 * @param anch - anchor, specifies the way to locate the text around the |
975 * anchor point. May be the combination of Graphics.TOP, |
1178 * anchor point. May be the combination of Graphics.TOP, |
976 * Graphics.BOTTOM, Graphics.BASELINE, Graphics.LEFT, |
1179 * Graphics.BOTTOM, Graphics.BASELINE, Graphics.LEFT, |
977 * Graphics.RIGHT, Graphics.HCENTER. |
1180 * Graphics.RIGHT, Graphics.HCENTER. |
978 */ |
1181 */ |
979 public void drawChar(char c, int xPos, int yPos, int anch) { |
1182 public void drawChar(char c, int xPos, int yPos, int anch) |
1183 { |
|
980 drawString(String.valueOf(c), xPos, yPos, anch); |
1184 drawString(String.valueOf(c), xPos, yPos, anch); |
981 } |
1185 } |
982 |
1186 |
983 /** |
1187 /** |
984 * Draws characters from array with specified color and font. |
1188 * Draws characters from array with specified color and font. |
992 * anchor point. May be the combination of Graphics.TOP, |
1196 * anchor point. May be the combination of Graphics.TOP, |
993 * Graphics.BOTTOM, Graphics.BASELINE, Graphics.LEFT, |
1197 * Graphics.BOTTOM, Graphics.BASELINE, Graphics.LEFT, |
994 * Graphics.RIGHT, Graphics.HCENTER. |
1198 * Graphics.RIGHT, Graphics.HCENTER. |
995 */ |
1199 */ |
996 public void drawChars(char[] ch, int offset, int length, |
1200 public void drawChars(char[] ch, int offset, int length, |
997 int xPos, int yPos, int anch) { |
1201 int xPos, int yPos, int anch) |
998 if (ch == null) { |
1202 { |
1203 if(ch == null) |
|
1204 { |
|
999 throw new NullPointerException( |
1205 throw new NullPointerException( |
1000 MsgRepository.GRAPHICS_EXCEPTION_ARRAY_IS_NULL); |
1206 MsgRepository.GRAPHICS_EXCEPTION_ARRAY_IS_NULL); |
1001 } |
1207 } |
1002 String str = null; |
1208 String str = null; |
1003 try { |
1209 try |
1210 { |
|
1004 str = String.valueOf(ch, offset, length); |
1211 str = String.valueOf(ch, offset, length); |
1005 } |
1212 } |
1006 catch (Exception e) { |
1213 catch(Exception e) |
1214 { |
|
1007 throw new ArrayIndexOutOfBoundsException( |
1215 throw new ArrayIndexOutOfBoundsException( |
1008 MsgRepository.GRAPHICS_EXCEPTION_ARRAY_OUT_OF_BOUNDS); |
1216 MsgRepository.GRAPHICS_EXCEPTION_ARRAY_OUT_OF_BOUNDS); |
1009 } |
1217 } |
1010 |
1218 |
1011 drawString(str, xPos, yPos, anch); |
1219 drawString(str, xPos, yPos, anch); |
1012 } |
1220 } |
1013 |
1221 |
1014 /** |
1222 /** |
1015 * Checks if anchors combination is valid. |
1223 * Checks if anchors combination is valid. |
1016 */ |
1224 */ |
1017 private boolean checkTextAnchors(int anch) { |
1225 private boolean checkTextAnchors(int anch) |
1226 { |
|
1018 boolean retVal = false; |
1227 boolean retVal = false; |
1019 |
1228 |
1020 int vertMask = Graphics.TOP | Graphics.BASELINE | Graphics.BOTTOM; |
1229 int vertMask = Graphics.TOP | Graphics.BASELINE | Graphics.BOTTOM; |
1021 int horMask = Graphics.LEFT | Graphics.RIGHT | Graphics.HCENTER; |
1230 int horMask = Graphics.LEFT | Graphics.RIGHT | Graphics.HCENTER; |
1022 |
1231 |
1023 if (anch == 0) { |
1232 if(anch == 0) |
1233 { |
|
1024 return true; |
1234 return true; |
1025 } |
1235 } |
1026 |
1236 |
1027 if ((anch & ~(vertMask | horMask)) != 0) { |
1237 if((anch & ~(vertMask | horMask)) != 0) |
1238 { |
|
1028 return false; |
1239 return false; |
1029 } |
1240 } |
1030 |
1241 |
1031 int vertAchor = anch & vertMask; |
1242 int vertAchor = anch & vertMask; |
1032 int horAchor = anch & horMask; |
1243 int horAchor = anch & horMask; |
1033 |
1244 |
1034 if ((vertAchor == Graphics.TOP) |
1245 if((vertAchor == Graphics.TOP) |
1035 || (vertAchor == Graphics.BASELINE) |
1246 || (vertAchor == Graphics.BASELINE) |
1036 || (vertAchor == Graphics.BOTTOM)) { |
1247 || (vertAchor == Graphics.BOTTOM)) |
1248 { |
|
1037 retVal = true; |
1249 retVal = true; |
1038 } |
1250 } |
1039 |
1251 |
1040 if ((horAchor == Graphics.LEFT) |
1252 if((horAchor == Graphics.LEFT) |
1041 || (vertAchor == Graphics.RIGHT) |
1253 || (vertAchor == Graphics.RIGHT) |
1042 || (vertAchor == Graphics.HCENTER)) { |
1254 || (vertAchor == Graphics.HCENTER)) |
1255 { |
|
1043 retVal = true; |
1256 retVal = true; |
1044 } |
1257 } |
1045 |
1258 |
1046 return retVal; |
1259 return retVal; |
1047 } |
1260 } |
1053 * @param xPos - X-coordinate of the anchor point. |
1266 * @param xPos - X-coordinate of the anchor point. |
1054 * @param yPos - Y-coordinate of the anchor point. |
1267 * @param yPos - Y-coordinate of the anchor point. |
1055 * @param anch - anchor value. |
1268 * @param anch - anchor value. |
1056 */ |
1269 */ |
1057 public void drawImage(javax.microedition.lcdui.Image image, int xPos, |
1270 public void drawImage(javax.microedition.lcdui.Image image, int xPos, |
1058 int yPos, int anch) { |
1271 int yPos, int anch) |
1059 |
1272 { |
1060 if (image == null) { |
1273 |
1274 if(image == null) |
|
1275 { |
|
1061 throw new NullPointerException( |
1276 throw new NullPointerException( |
1062 MsgRepository.IMAGE_EXCEPTION_IS_NULL); |
1277 MsgRepository.IMAGE_EXCEPTION_IS_NULL); |
1063 } |
1278 } |
1064 if (!checkImageAnchors(anch)) { |
1279 if(!checkImageAnchors(anch)) |
1280 { |
|
1065 throw new IllegalArgumentException( |
1281 throw new IllegalArgumentException( |
1066 MsgRepository.GRAPHICS_EXCEPTION_INVALID_ANCHOR); |
1282 MsgRepository.GRAPHICS_EXCEPTION_INVALID_ANCHOR); |
1067 } |
1283 } |
1068 |
1284 |
1069 int y = yPos; |
1285 int y = yPos; |
1070 if (isFlag(anch, Graphics.VCENTER)) { |
1286 if(isFlag(anch, Graphics.VCENTER)) |
1287 { |
|
1071 y = yPos - image.getHeight() / 2; |
1288 y = yPos - image.getHeight() / 2; |
1072 } |
1289 } |
1073 if (isFlag(anch, Graphics.BOTTOM)) { |
1290 if(isFlag(anch, Graphics.BOTTOM)) |
1291 { |
|
1074 y = yPos - image.getHeight(); |
1292 y = yPos - image.getHeight(); |
1075 } |
1293 } |
1076 |
1294 |
1077 int x = xPos; |
1295 int x = xPos; |
1078 if (isFlag(anch, Graphics.HCENTER)) { |
1296 if(isFlag(anch, Graphics.HCENTER)) |
1297 { |
|
1079 x = xPos - image.getWidth() / 2; |
1298 x = xPos - image.getWidth() / 2; |
1080 } |
1299 } |
1081 if (isFlag(anch, Graphics.RIGHT)) { |
1300 if(isFlag(anch, Graphics.RIGHT)) |
1301 { |
|
1082 x = xPos - image.getWidth(); |
1302 x = xPos - image.getWidth(); |
1083 } |
1303 } |
1084 |
1304 |
1085 synchronized(flushLock) { |
1305 synchronized(flushLock) |
1086 if(!buffered) { |
1306 { |
1307 if(!buffered) |
|
1308 { |
|
1087 final int x_ = x; |
1309 final int x_ = x; |
1088 final int y_ = y; |
1310 final int y_ = y; |
1089 final org.eclipse.swt.internal.qt.graphics.Image image_ = |
1311 final org.eclipse.swt.internal.qt.graphics.Image image_ = |
1090 Internal_GfxPackageSupport.getImage(Image.getESWTImage(image)); |
1312 Internal_GfxPackageSupport.getImage(Image.getESWTImage(image)); |
1091 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
1313 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
1092 public void run() { |
1314 { |
1315 public void run() |
|
1316 { |
|
1093 gc.drawImage(image_, x_, y_); |
1317 gc.drawImage(image_, x_, y_); |
1094 }}); |
1318 } |
1095 } else { |
1319 }); |
1320 } |
|
1321 else |
|
1322 { |
|
1096 gc.drawImage(Internal_GfxPackageSupport.getImage(Image.getESWTImage(image)), x, y); |
1323 gc.drawImage(Internal_GfxPackageSupport.getImage(Image.getESWTImage(image)), x, y); |
1097 } |
1324 } |
1098 } |
1325 } |
1099 } |
1326 } |
1100 |
1327 |
1101 /** |
1328 /** |
1102 * Checks if anchors combination is valid. |
1329 * Checks if anchors combination is valid. |
1103 */ |
1330 */ |
1104 private boolean checkImageAnchors(int anch) { |
1331 private boolean checkImageAnchors(int anch) |
1332 { |
|
1105 boolean retVal = false; |
1333 boolean retVal = false; |
1106 |
1334 |
1107 int vertMask = Graphics.TOP | Graphics.VCENTER | Graphics.BOTTOM; |
1335 int vertMask = Graphics.TOP | Graphics.VCENTER | Graphics.BOTTOM; |
1108 int horMask = Graphics.LEFT | Graphics.RIGHT | Graphics.HCENTER; |
1336 int horMask = Graphics.LEFT | Graphics.RIGHT | Graphics.HCENTER; |
1109 |
1337 |
1110 if (anch == 0) { |
1338 if(anch == 0) |
1339 { |
|
1111 return true; |
1340 return true; |
1112 } |
1341 } |
1113 |
1342 |
1114 if ((anch & ~(vertMask | horMask)) != 0) { |
1343 if((anch & ~(vertMask | horMask)) != 0) |
1344 { |
|
1115 return false; |
1345 return false; |
1116 } |
1346 } |
1117 |
1347 |
1118 int vertAchor = anch & vertMask; |
1348 int vertAchor = anch & vertMask; |
1119 int horAchor = anch & horMask; |
1349 int horAchor = anch & horMask; |
1120 |
1350 |
1121 if ((vertAchor == Graphics.TOP) |
1351 if((vertAchor == Graphics.TOP) |
1122 || (vertAchor == Graphics.VCENTER) |
1352 || (vertAchor == Graphics.VCENTER) |
1123 || (vertAchor == Graphics.BOTTOM)) { |
1353 || (vertAchor == Graphics.BOTTOM)) |
1354 { |
|
1124 retVal = true; |
1355 retVal = true; |
1125 } |
1356 } |
1126 |
1357 |
1127 if ((horAchor == Graphics.LEFT) |
1358 if((horAchor == Graphics.LEFT) |
1128 || (vertAchor == Graphics.RIGHT) |
1359 || (vertAchor == Graphics.RIGHT) |
1129 || (vertAchor == Graphics.HCENTER)) { |
1360 || (vertAchor == Graphics.HCENTER)) |
1361 { |
|
1130 retVal = true; |
1362 retVal = true; |
1131 } |
1363 } |
1132 |
1364 |
1133 return retVal; |
1365 return retVal; |
1134 } |
1366 } |
1138 * |
1370 * |
1139 * @param newStyle - new style, valid values are Graphics.SOLID and |
1371 * @param newStyle - new style, valid values are Graphics.SOLID and |
1140 * Graphics.DOTTED. |
1372 * Graphics.DOTTED. |
1141 * @throws IllegalArgumentException if the new style value is invalid. |
1373 * @throws IllegalArgumentException if the new style value is invalid. |
1142 */ |
1374 */ |
1143 public void setStrokeStyle(int newStyle) { |
1375 public void setStrokeStyle(int newStyle) |
1144 if (newStyle == currentStrokeSyle) { |
1376 { |
1377 if(newStyle == currentStrokeSyle) |
|
1378 { |
|
1145 return; |
1379 return; |
1146 } |
1380 } |
1147 if (newStyle == SOLID) { |
1381 if(newStyle == SOLID) |
1148 synchronized(flushLock) { |
1382 { |
1149 if(!buffered) { |
1383 synchronized(flushLock) |
1150 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
1384 { |
1151 public void run() { |
1385 if(!buffered) |
1386 { |
|
1387 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
|
1388 { |
|
1389 public void run() |
|
1390 { |
|
1152 gc.setStrokeStyle(GraphicsContext.STROKE_SOLID); |
1391 gc.setStrokeStyle(GraphicsContext.STROKE_SOLID); |
1153 }}); |
1392 } |
1154 } else { |
1393 }); |
1394 } |
|
1395 else |
|
1396 { |
|
1155 gc.setStrokeStyle(GraphicsContext.STROKE_SOLID); |
1397 gc.setStrokeStyle(GraphicsContext.STROKE_SOLID); |
1156 } |
1398 } |
1157 } |
1399 } |
1158 } else { |
1400 } |
1159 if (newStyle == DOTTED) { |
1401 else |
1160 synchronized(flushLock) { |
1402 { |
1161 if(!buffered) { |
1403 if(newStyle == DOTTED) |
1162 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
1404 { |
1163 public void run() { |
1405 synchronized(flushLock) |
1406 { |
|
1407 if(!buffered) |
|
1408 { |
|
1409 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
|
1410 { |
|
1411 public void run() |
|
1412 { |
|
1164 gc.setStrokeStyle(GraphicsContext.STROKE_DOT); |
1413 gc.setStrokeStyle(GraphicsContext.STROKE_DOT); |
1165 }}); |
1414 } |
1166 } else { |
1415 }); |
1416 } |
|
1417 else |
|
1418 { |
|
1167 gc.setStrokeStyle(GraphicsContext.STROKE_DOT); |
1419 gc.setStrokeStyle(GraphicsContext.STROKE_DOT); |
1168 } |
1420 } |
1169 } |
1421 } |
1170 } else { |
1422 } |
1423 else |
|
1424 { |
|
1171 throw new IllegalArgumentException( |
1425 throw new IllegalArgumentException( |
1172 MsgRepository.GRAPHICS_EXCEPTION_ILLEGAL_STROKE_STYLE); |
1426 MsgRepository.GRAPHICS_EXCEPTION_ILLEGAL_STROKE_STYLE); |
1173 } |
1427 } |
1174 } |
1428 } |
1175 currentStrokeSyle = newStyle; |
1429 currentStrokeSyle = newStyle; |
1178 /** |
1432 /** |
1179 * Returns current stroke style. |
1433 * Returns current stroke style. |
1180 * |
1434 * |
1181 * @return Current stroke style. |
1435 * @return Current stroke style. |
1182 */ |
1436 */ |
1183 public int getStrokeStyle() { |
1437 public int getStrokeStyle() |
1438 { |
|
1184 return currentStrokeSyle; |
1439 return currentStrokeSyle; |
1185 } |
1440 } |
1186 |
1441 |
1187 /** |
1442 /** |
1188 * Returns the color that will be used if the specified color is requested. |
1443 * Returns the color that will be used if the specified color is requested. |
1189 * |
1444 * |
1190 * @param color - color to use in 0x00RRGGBB form. |
1445 * @param color - color to use in 0x00RRGGBB form. |
1191 * @return Color that will be actually used in 0x00RRGGBB form. |
1446 * @return Color that will be actually used in 0x00RRGGBB form. |
1192 */ |
1447 */ |
1193 public int getDisplayColor(int color) { |
1448 public int getDisplayColor(int color) |
1449 { |
|
1194 return color & RGB_MASK; |
1450 return color & RGB_MASK; |
1195 } |
1451 } |
1196 |
1452 |
1197 /** |
1453 /** |
1198 * Renders 0xAARRGGBB pixels. |
1454 * Renders 0xAARRGGBB pixels. |
1214 int scanlength, |
1470 int scanlength, |
1215 int x, |
1471 int x, |
1216 int y, |
1472 int y, |
1217 int w, |
1473 int w, |
1218 int h, |
1474 int h, |
1219 boolean alpha) { |
1475 boolean alpha) |
1220 |
1476 { |
1221 if (rgb == null) { |
1477 |
1478 if(rgb == null) |
|
1479 { |
|
1222 throw new NullPointerException( |
1480 throw new NullPointerException( |
1223 MsgRepository.IMAGE_EXCEPTION_DATA_IS_NULL); |
1481 MsgRepository.IMAGE_EXCEPTION_DATA_IS_NULL); |
1224 } |
1482 } |
1225 synchronized(flushLock) { |
1483 synchronized(flushLock) |
1226 if(!buffered) { |
1484 { |
1485 if(!buffered) |
|
1486 { |
|
1227 final int[] rgb_ = rgb; |
1487 final int[] rgb_ = rgb; |
1228 final int offset_ = offset; |
1488 final int offset_ = offset; |
1229 final int scanlength_ = scanlength; |
1489 final int scanlength_ = scanlength; |
1230 final int x_ = x; |
1490 final int x_ = x; |
1231 final int y_ = y; |
1491 final int y_ = y; |
1232 final int w_ = w; |
1492 final int w_ = w; |
1233 final int h_ = h; |
1493 final int h_ = h; |
1234 final boolean alpha_ = alpha; |
1494 final boolean alpha_ = alpha; |
1235 |
1495 |
1236 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
1496 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
1237 public void run() { |
1497 { |
1498 public void run() |
|
1499 { |
|
1238 gc.drawRGB(rgb_, offset_, scanlength_, x_, y_, w_, h_, alpha_); |
1500 gc.drawRGB(rgb_, offset_, scanlength_, x_, y_, w_, h_, alpha_); |
1239 }}); |
1501 } |
1240 } else { |
1502 }); |
1503 } |
|
1504 else |
|
1505 { |
|
1241 gc.drawRGB(rgb, offset, scanlength, x, y, w, h, alpha); |
1506 gc.drawRGB(rgb, offset, scanlength, x, y, w, h, alpha); |
1242 } |
1507 } |
1243 } |
1508 } |
1244 } |
1509 } |
1245 |
1510 |
1256 public void fillTriangle(int xPos1, |
1521 public void fillTriangle(int xPos1, |
1257 int yPos1, |
1522 int yPos1, |
1258 int xPos2, |
1523 int xPos2, |
1259 int yPos2, |
1524 int yPos2, |
1260 int xPos3, |
1525 int xPos3, |
1261 int yPos3) { |
1526 int yPos3) |
1527 { |
|
1262 final int[] points = {xPos1, yPos1, xPos2, yPos2, xPos3, yPos3}; |
1528 final int[] points = {xPos1, yPos1, xPos2, yPos2, xPos3, yPos3}; |
1263 synchronized(flushLock) { |
1529 synchronized(flushLock) |
1264 if(!buffered) { |
1530 { |
1265 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
1531 if(!buffered) |
1266 public void run() { |
1532 { |
1533 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
|
1534 { |
|
1535 public void run() |
|
1536 { |
|
1267 gc.fillPolygon(points); |
1537 gc.fillPolygon(points); |
1268 }}); |
1538 } |
1269 } else { |
1539 }); |
1540 } |
|
1541 else |
|
1542 { |
|
1270 gc.fillPolygon(points); |
1543 gc.fillPolygon(points); |
1271 } |
1544 } |
1272 } |
1545 } |
1273 } |
1546 } |
1274 |
1547 |
1287 int yFrom, |
1560 int yFrom, |
1288 int w, |
1561 int w, |
1289 int h, |
1562 int h, |
1290 int xTo, |
1563 int xTo, |
1291 int yTo, |
1564 int yTo, |
1292 int anch) { |
1565 int anch) |
1293 |
1566 { |
1294 if (this.parentImage == null) { |
1567 |
1568 if(this.parentImage == null) |
|
1569 { |
|
1295 // this Graphics belongs to a screen device. |
1570 // this Graphics belongs to a screen device. |
1296 throw new IllegalStateException( |
1571 throw new IllegalStateException( |
1297 MsgRepository.GRAPHICS_EXCEPTION_DESTINATION_IS_SCREEN); |
1572 MsgRepository.GRAPHICS_EXCEPTION_DESTINATION_IS_SCREEN); |
1298 } |
1573 } |
1299 |
1574 |
1300 if (!javax.microedition.lcdui.Image.validateRegion(parentImage |
1575 if(!javax.microedition.lcdui.Image.validateRegion(parentImage |
1301 .getWidth(), parentImage.getHeight(), xFrom, yFrom, w, h)) { |
1576 .getWidth(), parentImage.getHeight(), xFrom, yFrom, w, h)) |
1577 { |
|
1302 throw new IllegalArgumentException( |
1578 throw new IllegalArgumentException( |
1303 MsgRepository.IMAGE_EXCEPTION_INVALID_REGION); |
1579 MsgRepository.IMAGE_EXCEPTION_INVALID_REGION); |
1304 } |
1580 } |
1305 |
1581 |
1306 // Arrange vertical alignments |
1582 // Arrange vertical alignments |
1307 int destY = yTo; |
1583 int destY = yTo; |
1308 if (isFlag(anch, Graphics.BOTTOM)) { |
1584 if(isFlag(anch, Graphics.BOTTOM)) |
1585 { |
|
1309 destY = yTo - h; |
1586 destY = yTo - h; |
1310 } |
1587 } |
1311 if (isFlag(anch, Graphics.VCENTER)) { |
1588 if(isFlag(anch, Graphics.VCENTER)) |
1589 { |
|
1312 destY = yTo - h / 2; |
1590 destY = yTo - h / 2; |
1313 } |
1591 } |
1314 |
1592 |
1315 // Arrange horizontal alignments |
1593 // Arrange horizontal alignments |
1316 int destX = xTo; |
1594 int destX = xTo; |
1317 if (isFlag(anch, Graphics.RIGHT)) { |
1595 if(isFlag(anch, Graphics.RIGHT)) |
1596 { |
|
1318 destX = xTo - w; |
1597 destX = xTo - w; |
1319 } |
1598 } |
1320 if (isFlag(anch, Graphics.HCENTER)) { |
1599 if(isFlag(anch, Graphics.HCENTER)) |
1600 { |
|
1321 destX = xTo - w / 2; |
1601 destX = xTo - w / 2; |
1322 } |
1602 } |
1323 |
1603 |
1324 synchronized(flushLock) { |
1604 synchronized(flushLock) |
1325 if(!buffered) { |
1605 { |
1606 if(!buffered) |
|
1607 { |
|
1326 final int x1 = xFrom; |
1608 final int x1 = xFrom; |
1327 final int y1 = yFrom; |
1609 final int y1 = yFrom; |
1328 final int width = w; |
1610 final int width = w; |
1329 final int height = h; |
1611 final int height = h; |
1330 final int x2 = destX; |
1612 final int x2 = destX; |
1331 final int y2 = destY; |
1613 final int y2 = destY; |
1332 |
1614 |
1333 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
1615 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
1334 public void run() { |
1616 { |
1617 public void run() |
|
1618 { |
|
1335 gc.copyArea(x1, y1, width, height, x2, y2); |
1619 gc.copyArea(x1, y1, width, height, x2, y2); |
1336 }}); |
1620 } |
1337 } else { |
1621 }); |
1622 } |
|
1623 else |
|
1624 { |
|
1338 gc.copyArea(xFrom, yFrom, w, h, destX, destY); |
1625 gc.copyArea(xFrom, yFrom, w, h, destX, destY); |
1339 } |
1626 } |
1340 } |
1627 } |
1341 } |
1628 } |
1342 |
1629 |
1361 int width, |
1648 int width, |
1362 int height, |
1649 int height, |
1363 int transform, |
1650 int transform, |
1364 int xDst, |
1651 int xDst, |
1365 int yDst, |
1652 int yDst, |
1366 int anch) { |
1653 int anch) |
1367 |
1654 { |
1368 if (srcImage == null) { |
1655 |
1656 if(srcImage == null) |
|
1657 { |
|
1369 throw new NullPointerException( |
1658 throw new NullPointerException( |
1370 MsgRepository.IMAGE_EXCEPTION_IS_NULL); |
1659 MsgRepository.IMAGE_EXCEPTION_IS_NULL); |
1371 } |
1660 } |
1372 if (srcImage == parentImage) { |
1661 if(srcImage == parentImage) |
1662 { |
|
1373 throw new IllegalArgumentException( |
1663 throw new IllegalArgumentException( |
1374 MsgRepository.GRAPHICS_EXCEPTION_SAME_SOURCE_AND_DESTINATION); |
1664 MsgRepository.GRAPHICS_EXCEPTION_SAME_SOURCE_AND_DESTINATION); |
1375 } |
1665 } |
1376 if (!javax.microedition.lcdui.Image.validateTransform(transform)) { |
1666 if(!javax.microedition.lcdui.Image.validateTransform(transform)) |
1667 { |
|
1377 throw new IllegalArgumentException( |
1668 throw new IllegalArgumentException( |
1378 MsgRepository.IMAGE_EXCEPTION_INVALID_TRANSFORM); |
1669 MsgRepository.IMAGE_EXCEPTION_INVALID_TRANSFORM); |
1379 } |
1670 } |
1380 if (!checkImageAnchors(anch)) { |
1671 if(!checkImageAnchors(anch)) |
1672 { |
|
1381 throw new IllegalArgumentException( |
1673 throw new IllegalArgumentException( |
1382 MsgRepository.GRAPHICS_EXCEPTION_INVALID_ANCHOR); |
1674 MsgRepository.GRAPHICS_EXCEPTION_INVALID_ANCHOR); |
1383 } |
1675 } |
1384 if (!javax.microedition.lcdui.Image.validateRegion(srcImage.getWidth(), |
1676 if(!javax.microedition.lcdui.Image.validateRegion(srcImage.getWidth(), |
1385 srcImage.getHeight(), xSrc, ySrc, width, height)) { |
1677 srcImage.getHeight(), xSrc, ySrc, width, height)) |
1678 { |
|
1386 throw new IllegalArgumentException( |
1679 throw new IllegalArgumentException( |
1387 MsgRepository.IMAGE_EXCEPTION_INVALID_REGION); |
1680 MsgRepository.IMAGE_EXCEPTION_INVALID_REGION); |
1388 } |
1681 } |
1389 |
1682 |
1390 // Arrange vertical alignments |
1683 // Arrange vertical alignments |
1391 int y = yDst; |
1684 int y = yDst; |
1392 if (isFlag(anch, Graphics.VCENTER)) { |
1685 if(isFlag(anch, Graphics.VCENTER)) |
1686 { |
|
1393 y = yDst - srcImage.getHeight() / 2; |
1687 y = yDst - srcImage.getHeight() / 2; |
1394 } |
1688 } |
1395 if (isFlag(anch, Graphics.BOTTOM)) { |
1689 if(isFlag(anch, Graphics.BOTTOM)) |
1690 { |
|
1396 y = yDst - srcImage.getHeight(); |
1691 y = yDst - srcImage.getHeight(); |
1397 } |
1692 } |
1398 |
1693 |
1399 // Arrange horizontal alignments |
1694 // Arrange horizontal alignments |
1400 int x = xDst; |
1695 int x = xDst; |
1401 if (isFlag(anch, Graphics.HCENTER)) { |
1696 if(isFlag(anch, Graphics.HCENTER)) |
1697 { |
|
1402 x = xDst - srcImage.getWidth() / 2; |
1698 x = xDst - srcImage.getWidth() / 2; |
1403 } |
1699 } |
1404 if (isFlag(anch, Graphics.RIGHT)) { |
1700 if(isFlag(anch, Graphics.RIGHT)) |
1701 { |
|
1405 x = xDst - srcImage.getWidth(); |
1702 x = xDst - srcImage.getWidth(); |
1406 } |
1703 } |
1407 |
1704 |
1408 final int gcTransform = Image.getCgTransformValue(transform); |
1705 final int gcTransform = Image.getCgTransformValue(transform); |
1409 synchronized(flushLock) { |
1706 synchronized(flushLock) |
1410 if(!buffered) { |
1707 { |
1708 if(!buffered) |
|
1709 { |
|
1411 final int localXDst = x; |
1710 final int localXDst = x; |
1412 final int localYDst = y; |
1711 final int localYDst = y; |
1413 final int localW = width; |
1712 final int localW = width; |
1414 final int localH = height; |
1713 final int localH = height; |
1415 final int localXSrc = xSrc; |
1714 final int localXSrc = xSrc; |
1416 final int localYSrc = ySrc; |
1715 final int localYSrc = ySrc; |
1417 final org.eclipse.swt.internal.qt.graphics.Image localImage = |
1716 final org.eclipse.swt.internal.qt.graphics.Image localImage = |
1418 Internal_GfxPackageSupport.getImage(Image.getESWTImage(srcImage)); |
1717 Internal_GfxPackageSupport.getImage(Image.getESWTImage(srcImage)); |
1419 ESWTUIThreadRunner.safeSyncExec(new Runnable() { |
1718 ESWTUIThreadRunner.safeSyncExec(new Runnable() |
1420 public void run() { |
1719 { |
1720 public void run() |
|
1721 { |
|
1421 gc.drawImage(localImage, localXDst, localYDst, localW, localH, localXSrc, localYSrc, localW, localH, gcTransform); |
1722 gc.drawImage(localImage, localXDst, localYDst, localW, localH, localXSrc, localYSrc, localW, localH, gcTransform); |
1422 }}); |
1723 } |
1423 } else { |
1724 }); |
1424 gc.drawImage(Internal_GfxPackageSupport.getImage(Image.getESWTImage(srcImage)), |
1725 } |
1726 else |
|
1727 { |
|
1728 gc.drawImage(Internal_GfxPackageSupport.getImage(Image.getESWTImage(srcImage)), |
|
1425 x, y, width, height, xSrc, ySrc, width, height, gcTransform); |
1729 x, y, width, height, xSrc, ySrc, width, height, gcTransform); |
1426 } |
1730 } |
1427 } |
1731 } |
1428 } |
1732 } |
1429 |
1733 |
1430 /** |
1734 /** |
1431 * Return DirectGraphics associated with this instance. |
1735 * Return DirectGraphics associated with this instance. |
1432 */ |
1736 */ |
1433 DirectGraphics getDirectGraphics() { |
1737 DirectGraphics getDirectGraphics() |
1434 if (directGraphics == null) { |
1738 { |
1739 if(directGraphics == null) |
|
1740 { |
|
1435 directGraphics = new DirectGraphicsImpl(this); |
1741 directGraphics = new DirectGraphicsImpl(this); |
1436 } |
1742 } |
1437 return directGraphics; |
1743 return directGraphics; |
1438 } |
1744 } |
1439 |
1745 |
1440 /** |
1746 /** |
1441 * Return native graphic context. |
1747 * Return native graphic context. |
1442 */ |
1748 */ |
1443 GraphicsContext getGc() { |
1749 GraphicsContext getGc() |
1750 { |
|
1444 return gc; |
1751 return gc; |
1445 } |
1752 } |
1446 |
1753 |
1447 } |
1754 } |