1 11 package org.eclipse.swt.internal.theme; 12 13 import org.eclipse.swt.*; 14 import org.eclipse.swt.graphics.*; 15 16 public class Theme { 17 18 Device device; 19 20 public Theme(Device device) { 21 this.device = device; 22 } 23 24 public Rectangle computeTrim(GC gc, DrawData data) { 25 checkTheme(); 26 if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 27 if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 28 if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); 29 return data.computeTrim(this, gc); 30 } 31 32 void checkTheme() { 33 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); 34 } 35 36 public void dispose () { 37 device = null; 38 } 39 40 public void drawBackground(GC gc, Rectangle bounds, DrawData data) { 41 checkTheme(); 42 if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 43 if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 44 if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 45 if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); 46 data.draw(this, gc, bounds); 47 } 48 49 public void drawFocus(GC gc, Rectangle bounds, DrawData data) { 50 checkTheme(); 51 if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 52 if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 53 if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 54 if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); 55 gc.drawFocus(bounds.x, bounds.y, bounds.width, bounds.height); 56 } 57 58 public void drawImage(GC gc, Rectangle bounds, DrawData data, Image image, int flags) { 59 checkTheme(); 60 if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 61 if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 62 if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 63 if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 64 if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); 65 data.drawImage(this, image, gc, bounds); 66 } 67 68 public void drawText(GC gc, Rectangle bounds, DrawData data, String text, int flags) { 69 checkTheme(); 70 if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 71 if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 72 if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 73 if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 74 if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); 75 data.drawText(this, text, flags, gc, bounds); 76 } 77 78 public Rectangle getBounds(int part, Rectangle bounds, DrawData data) { 79 checkTheme(); 80 if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 81 if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 82 return data.getBounds(part, bounds); 83 } 84 85 public int getSelection(Point offset, Rectangle bounds, RangeDrawData data) { 86 checkTheme(); 87 if (offset == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 88 if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 89 if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 90 return data.getSelection(offset, bounds); 91 } 92 93 public int hitBackground(Point position, Rectangle bounds, DrawData data) { 94 checkTheme(); 95 if (position == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 96 if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 97 if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 98 return data.hit(this, position, bounds); 99 } 100 101 public boolean isDisposed() { 102 return device == null; 103 } 104 105 public Rectangle measureText(GC gc, Rectangle bounds, DrawData data, String text, int flags) { 106 checkTheme(); 107 if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 108 if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 109 if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 110 if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); 111 return data.measureText(this, text, flags, gc, bounds); 112 } 113 } 114 | Popular Tags |