The enum classes (LengthUnit, AngleUnit) are straight Java Enums and
ripe for the taking. The literal classes (Color, Length, and Angle) are
all implemented as Visage classes. Doing a straight conversion to Java
would not be hard at all, and would save you the trouble of doing a
clean room implementation of the color algorithms and length conversions
from scratch (which is what I had to do).
I also kept the license as New BSD to promote code sharing, so you are
free to take those classes and reuse/convert them for Leonardo. In fact
I encourage you to do so, because that makes the job of wrapping
Leonardo with Visage that much easier! :)
What you are a not getting is the literal syntax support. You would
need to use the Java constructors to create objects instead. For example:
Color.rgb(16, 16, 16)
instead of #0F0F0F
or
Length.valueOf(16, LengthUnit.CENTIMETERS)
rather than 16cm
Although this is the unique value proposition of Visage... we can add
to the language to make things simpler and more elegant than you can do
purely with Java APIs.
Here is a link to the right folder in the source tree to get you started:
http://code.google.com/p/visage/source/browse/#hg%2Fsrc%2Fshare%2Fcla...
Cheers,
--Steve
On 1/3/11 7:46 PM, Josh Marinacci wrote:
> This is awesome stuff. How much is implemented in the parser and how much is a Java api? I may have to steal this for Leonardo, since it needs unit and angle support soon.
> - Josh
> On Jan 1, 2011, at 1:53 PM, Stephen Chin wrote:
>> I finished off the implementation of Angle literals, which was partially done in the previous check-in.
>> Here is the changelist in case you are interested in reviewing the changes (although remember most of the work was done in the previous check-in):
>> http://code.google.com/p/visage/source/detail?r=0164367eb49f5f2c1efcf...
>> And here is a little bit about Angle literals:
>> Angle instances can be specified as degrees, radians, or turns. For precise calculations, they are stored in the given unit type as a double value.
>> Angles can be easily created using angle literals; for example, a 90 degree Angle instance can be defined in several ways:
>> Angle a = 90deg;
>> Angle a = .25turn;
>> Angle a = Angle.valueOf(Math.PI / 2, AngleUnit.RADIAN);</pre></code>
>> Angle instances are immutable, and are therefore replaced rather than modified. To create a new Angle instance, either use a time literal, or use the Angle.valueOf(value, unit) factory method.
>> Angles support operator overloading of all the usual suspects (+, -, *, /, etc.) They also have a custom formatter to let you specify precision.
>> Happy New Year!
>> Cheers,
>> --
>> --Steve
>> blog: http://steveonjava.com/
> Blasting forth in three part harmony!
--
--Steve
blog:
http://steveonjava.com/