001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * -------------------
028: * SwtPaintCanvas.java
029: * -------------------
030: * (C) Copyright 2000-2005, by Object Refinery Limited.
031: *
032: * Original Author: Henry Proudhon (henry.proudhon AT insa-lyon.fr);
033: * Contributor(s):
034: *
035: * Changes
036: * -------
037: * 4 Aug 2006 : New class (HP);
038: */
039:
040: package org.jfree.experimental.swt;
041:
042: import org.eclipse.swt.SWT;
043: import org.eclipse.swt.events.PaintEvent;
044: import org.eclipse.swt.events.PaintListener;
045: import org.eclipse.swt.graphics.Color;
046: import org.eclipse.swt.widgets.Canvas;
047: import org.eclipse.swt.widgets.Composite;
048:
049: /**
050: * A paint canvas.
051: */
052: public class SWTPaintCanvas extends Canvas {
053: private Color myColor;
054:
055: /**
056: * Creates a new instance.
057: *
058: * @param parent the parent.
059: * @param style the style.
060: * @param color the color.
061: */
062: public SWTPaintCanvas(Composite parent, int style, Color color) {
063: this (parent, style);
064: this .setColor(color);
065: }
066:
067: /**
068: * Creates a new instance.
069: *
070: * @param parent the parent.
071: * @param style the style.
072: */
073: public SWTPaintCanvas(Composite parent, int style) {
074: super (parent, style);
075: addPaintListener(new PaintListener() {
076: public void paintControl(PaintEvent e) {
077: e.gc.setForeground(e.gc.getDevice().getSystemColor(
078: SWT.COLOR_BLACK));
079: e.gc.setBackground(myColor);
080: e.gc.fillRectangle(getClientArea());
081: e.gc.drawRectangle(getClientArea().x,
082: getClientArea().y, getClientArea().width - 1,
083: getClientArea().height - 1);
084: }
085: });
086: }
087:
088: /**
089: * Sets the color.
090: *
091: * @param color the color.
092: */
093: public void setColor(Color color) {
094: if (this .myColor != null) {
095: myColor.dispose();
096: }
097: //this.myColor = new Color( getDisplay(), color.getRGB() );
098: this .myColor = color;
099: }
100:
101: /**
102: * Returns the color.
103: *
104: * @return The color.
105: */
106: public Color getColor() {
107: return myColor;
108: }
109:
110: /**
111: * Overridden to do nothing.
112: *
113: * @param c the color.
114: */
115: public void setBackground(Color c) {
116: return;
117: }
118:
119: /**
120: * Overridden to do nothing.
121: *
122: * @param c the color.
123: */
124: public void setForeground(Color c) {
125: return;
126: }
127:
128: /**
129: * Frees resources.
130: */
131: public void dispose() {
132: myColor.dispose();
133: }
134: }
|