[cairo-commit] cairo-java/src/java/org/freedesktop/cairo PathElementType.java, NONE, 1.1 PathElement.java, NONE, 1.1 Path.java, NONE, 1.1 PathIterator.java, NONE, 1.1

Jeffrey Morgan commit at pdx.freedesktop.org
Wed May 11 09:12:31 PDT 2005


Committed by: kuzman

Update of /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo
In directory gabe:/tmp/cvs-serv3691/src/java/org/freedesktop/cairo

Added Files:
	PathElementType.java PathElement.java Path.java 
	PathIterator.java 
Log Message:
Beginning of the work to add path_t to our bindings - this is incomplete at this time.

--- NEW FILE: PathElementType.java ---
/*
 * Java-Gnome Bindings Library
*
* Copyright 1998-2005 the Java-Gnome Team, all rights reserved.
*
* The Java-Gnome bindings library is free software distributed under
* the terms of the GNU Library General Public License version 2.
*/
package org.freedesktop.cairo;

import org.gnu.javagnome.Enum;

class PathElementType extends Enum {

    static final private int _MOVE_TO = 0;
    static final public PathElementType MOVE_TO = new PathElementType (_MOVE_TO);
    static final private int _LINE_TO = 1;
    static final public PathElementType LINE_TO = new PathElementType (_LINE_TO);
    static final private int _CURVE_TO = 2;
    static final public PathElementType CURVE_TO = new PathElementType (_CURVE_TO);
    static final private int _CLOSE_PATH = 2;
    static final public PathElementType CLOSE_PATH = new PathElementType (_CLOSE_PATH);
    static final private PathElementType[] theInterned = new PathElementType[] {
        MOVE_TO, LINE_TO, CURVE_TO, CLOSE_PATH
    };
    static private java.util.Hashtable theInternedExtras;
    static final private PathElementType theSacrificialOne = new PathElementType (0);
    static public PathElementType intern (int value) {
        if (value < theInterned.length) {
            return theInterned[value];
        }
        theSacrificialOne.value_ = value;
        if (theInternedExtras == null) {
            theInternedExtras = new java.util.Hashtable();
        }
        PathElementType already = (PathElementType) theInternedExtras.get(theSacrificialOne);
        if (already == null) {
            already = new PathElementType(value);
            theInternedExtras.put(already, already);
        }
        return already;
    }

    private PathElementType(int value) {
        value_ = value;
    }

    public boolean test (PathElementType other) {
        return (value_ & other.value_) == other.value_;
    }
}

--- NEW FILE: PathElement.java ---
/*
 * Java-Gnome Bindings Library
*
* Copyright 1998-2005 the Java-Gnome Team, all rights reserved.
*
* The Java-Gnome bindings library is free software distributed under
* the terms of the GNU Library General Public License version 2.
*/
package org.freedesktop.cairo;

import org.gnu.javagnome.Handle;

public class PathElement extends CairoObject {
    
    private int length;
    private Point[] points;
    private PathElementType type;
    
    PathElement(Handle hndl) {
        super(hndl);
        length = get_length(getHandle());
        type = PathElementType.intern(get_type(getHandle()));
        if (length > 1) {
            points = new Point[length - 1];
            for (int i = 1; i < length; i++) {
                double[] coor = get_point(getHandle(), i - 1);
                points[i-1] = new Point(coor[0], coor[1]);
            }
        }
    }
    
    public PathElementType getType() {
        return type;
    }
    
    public Point getPoint(int index) {
        if (index > length)
            return null;
        return points[index];
    }
    
    
    native static final private int get_length(Handle obj);
    native static final private double[] get_point(Handle ojb, int index);
    native static final private int get_type(Handle obj);
}

--- NEW FILE: Path.java ---
/*
 * Java-Gnome Bindings Library
*
* Copyright 1998-2005 the Java-Gnome Team, all rights reserved.
*
* The Java-Gnome bindings library is free software distributed under
* the terms of the GNU Library General Public License version 2.
*/
package org.freedesktop.cairo;

import java.util.Iterator;

import org.gnu.javagnome.Handle;

public class Path extends CairoObject {
    
    public Path(PathElement[] elements) {
        super(alloc());
        if (null != elements) 
            for (int i = 0; i < elements.length; i++)
                add_data(getHandle(), elements[i].getHandle());
    }
    
    Path(Handle hndl) {
        super(hndl);
    }
    
    protected void finalize() throws Throwable {
        cairo_path_destroy(getHandle());
        super.finalize();
    }

    public Iterator iterator() {
        Handle[] hndls = get_all_data(getHandle());
        if (hndls == null)
            return new PathIterator(null);
        PathElement[] elements = new PathElement[hndls.length];
        for (int i = 0; i < hndls.length; i++)
            elements[i] = new PathElement(hndls[i]);
        return new PathIterator(elements);
    }

    public boolean add(PathElement pe) {
        add_data(getHandle(), pe.getHandle());
        return false;
    }

    public PathElement get(int index) {
        return new PathElement(get_data(getHandle(), index));
    }

    native static final private Handle alloc();
    native static final private Handle get_data(Handle obj, int index);
    native static final private Handle[] get_all_data(Handle obj);
    native static final private void add_data(Handle obj, Handle data);
    native static final private void cairo_path_destroy(Handle obj);
}

--- NEW FILE: PathIterator.java ---
/*
 * Java-Gnome Bindings Library
*
* Copyright 1998-2005 the Java-Gnome Team, all rights reserved.
*
* The Java-Gnome bindings library is free software distributed under
* the terms of the GNU Library General Public License version 2.
*/
package org.freedesktop.cairo;

import java.util.Iterator;

class PathIterator implements Iterator {
    
    private PathElement[] elements;
    private int currentElement;
    
    PathIterator(PathElement[] elements) {
        this.elements = elements;
        currentElement = 0;
    }

    public boolean hasNext() {
        return currentElement <= elements.length - 1;
    }

    public Object next() {
        if (hasNext())
            return elements[currentElement];
        return null;
    }

    public void remove() {
        throw new UnsupportedOperationException("Not supported");
    }

}




More information about the cairo-commit mailing list