Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.PathIterator;

public class Main {
    /**
     * Converts a {@link Shape} to TDL. 
     * @param s
     * @return a string containing a space separated list of the points
     * specifiying the shape
     */
    public static String shapeToXML(Shape s) {
        StringBuilder sb = new StringBuilder();

        PathIterator pi = s.getPathIterator(new AffineTransform());

        float[] coords = new float[6];

        while (!pi.isDone()) {
            pi.currentSegment(coords);

            sb.append(String.valueOf(coords[0]) + "," + String.valueOf(coords[1]));

            pi.next();

            if (!pi.isDone()) {
                sb.append(" ");
            }
        }

        return sb.toString();
    }
}