1 39 40 package org.jfree.experimental.swt; 41 42 import org.eclipse.swt.SWT; 43 import org.eclipse.swt.events.PaintEvent; 44 import org.eclipse.swt.events.PaintListener; 45 import org.eclipse.swt.graphics.Color; 46 import org.eclipse.swt.widgets.Canvas; 47 import org.eclipse.swt.widgets.Composite; 48 49 52 public class SWTPaintCanvas extends Canvas 53 { 54 private Color myColor; 55 56 63 public SWTPaintCanvas(Composite parent, int style, Color color) { 64 this(parent, style); 65 this.setColor(color); 66 } 67 68 74 public SWTPaintCanvas(Composite parent, int style) { 75 super(parent, style); 76 addPaintListener(new PaintListener() { 77 public void paintControl(PaintEvent e) { 78 e.gc.setForeground(e.gc.getDevice().getSystemColor( 79 SWT.COLOR_BLACK)); 80 e.gc.setBackground(myColor); 81 e.gc.fillRectangle(getClientArea()); 82 e.gc.drawRectangle(getClientArea().x, getClientArea().y, 83 getClientArea().width - 1, getClientArea().height - 1); 84 } 85 }); 86 } 87 88 93 public void setColor(Color color) { 94 if (this.myColor != null) { 95 myColor.dispose(); 96 } 97 this.myColor = color; 99 } 100 101 106 public Color getColor() { 107 return myColor; 108 } 109 110 115 public void setBackground(Color c) { 116 return; 117 } 118 119 124 public void setForeground(Color c) { 125 return; 126 } 127 128 131 public void dispose() { 132 myColor.dispose(); 133 } 134 } 135 | Popular Tags |