Logo
Distributed Genetic Programming Framework
print print

File org.jfree.experimental.chart.swt.editor.SWTStrokeCanvas.java

Here you can find all the information about the file org.jfree.experimental.chart.swt.editor.SWTStrokeCanvas.java. You may explore it here or download it onto your local disk.
/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
 *
 * Project Info:  http://www.jfree.org/jfreechart/index.html
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 * USA.  
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * --------------------
 * SWTStrokeCanvas.java
 * --------------------
 * (C) Copyright 2006, by Henry Proudhon and Contributors.
 *
 * Original Author:  Henry Proudhon (henry.proudhon AT insa-lyon.fr);
 * Contributor(s):   David Gilbert (for Object Refinery Limited);
 *
 * Changes
 * -------
 * 01-Aug-2006 : New class (HP);
 * 
 */


package org.jfree.experimental.chart.swt.editor;

import java.awt.BasicStroke;
import java.awt.Stroke;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;

/**
 * A control for displaying a <code>Stroke</code> sample.
 */

class SWTStrokeCanvas extends Canvas {
    
    /**
     * Creates a new instance.
     * 
     * @param parent  the parent.
     * @param style  the style.
     * @param image  the image.
     */

    public SWTStrokeCanvas(Composite parent, int style, Image image) {
        this(parent, style);
    }

    /**
     * Creates a new instance.
     * 
     * @param parent  the parent.
     * @param style  the style.
     */

    public SWTStrokeCanvas(Composite parent, int style) {
        super(parent, style);
        addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                BasicStroke stroke = (BasicStroke) getStroke();
                if (stroke != null) {
                    int x, y;
                    Rectangle rect = getClientArea();
                    x = (rect.width - 100) / 2;
                    y = (rect.height - 16) / 2;
                    Transform swtTransform = new Transform(e.gc.getDevice()); 
                    e.gc.getTransform(swtTransform);
                    swtTransform.translate(x, y);
                    e.gc.setTransform(swtTransform);
                    swtTransform.dispose();
                    e.gc.setBackground(getDisplay().getSystemColor(
                            SWT.COLOR_BLACK));
                    e.gc.setLineWidth((int) stroke.getLineWidth());
                    e.gc.drawLine(10, 8, 90, 8);
                }
            }
        });
    }
    
    /**
     * Sets the stroke.
     * 
     * @param stroke  the stroke.
     */

    public void setStroke(Stroke stroke) {
        if (stroke instanceof BasicStroke) {
            this.setData( stroke );
        }
        else { 
            throw new RuntimeException(
                "Can only handle 'Basic Stroke' at present.");
        }
    }

    /**
     * Returns the stroke.
     * 
     * @return The stroke.
     */

    public BasicStroke getStroke() {
        return (BasicStroke) this.getData();
    }
}

File Information:

file name:SWTStrokeCanvas.java
package:org.jfree.experimental.chart.swt.editor
qualified name:org.jfree.experimental.chart.swt.editor.SWTStrokeCanvas.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/jfree/experimental/chart/swt/editor/SWTStrokeCanvas.java
size:4.048 KB (4146 B)
uploaded: 2012-05-02 03:11:24 GMT+0000
last update: 2006-08-25 12:16:46 GMT+0000
last access: 2012-11-21 18:41:09 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2012-05-02 03:10:45 GMT+0000 served at 2014-10-30 14:25:20 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo