
Signature
And loving it,
-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)
> I have a java.awt.geom.Area object that I need to transmit over the
> network but when I try to do so using a ObjectOutputStream and NIO it
> complains that the object is not serializable. Which makes sense
> (seeing it isn't) but how do I transmit this object? Is there a trick
> to it? I tried wrapping it in a serializable object but it didn't like
> that either.
Wrapping a non-serializable object in a serializable one is like trying
to attach wheels to a bolted down picnic table and expecting it to roll
easier :-) Anyway, you figured that out on your own.
There is no way to make Area serializable unless you make your own type
of Area that is serializable. Also, any non-transient reference within
your serializable area class has to be serializable. It becomes a
large mess. My suggestion, if its at all possible, is to instead
serialize the data you need to recreate the Area.
I'm actually surprised that most of the Shape classes aren't
serializable, but there you have it. Either lack of foresight, or
specific design decision. You might open a feature request to sun, but
I doubt it'll get much traction.

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Matt Humphrey - 21 Nov 2007 21:33 GMT
...
> I'm actually surprised that most of the Shape classes aren't serializable,
> but there you have it. Either lack of foresight, or specific design
> decision. You might open a feature request to sun, but I doubt it'll get
> much traction.
It may be possible to store the segments produced by Area's path iterator
and later reconstitute the area with them. Get the values from the path
iterator and store in your own kind of object. To reconstruct, pass the
segments to GeneralPath move/curve/line operations. This little program
shows how to read the segments. I don't pick off the winding rule here.
public static void main (String args []) {
Area area = new Area ();
area.add(new Area (new Rectangle2D.Double (0, 0, 20.0, 30.0)));
area.add(new Area (new Ellipse2D.Double (-10, -10, 20.0, 20.0)));
PathIterator pi = area.getPathIterator(new AffineTransform ());
double [] pt= new double [6];
while (! pi.isDone()) {
int code = pi.currentSegment(pt);
switch (code) {
case PathIterator.SEG_CLOSE:
System.out.println ("Close "); break;
case PathIterator.SEG_CUBICTO:
System.out.println ("Cubic to (" + pt[0] + "," + pt[1]
+ ") (" + pt[2] + "," + pt[3]
+ ") (" + pt[4] + "," + pt[5] + ")"); break;
case PathIterator.SEG_LINETO:
System.out.println ("Line to (" + pt[0] + "," + pt[1] +
")"); break;
case PathIterator.SEG_MOVETO:
System.out.println ("Move to (" + pt[0] + "," + pt[1] +
")"); break;
case PathIterator.SEG_QUADTO:
System.out.println ("Quad to (" + pt[0] + "," + pt[1]
+ ") (" + pt[2] + "," + pt[3] + ")"); break;
default: System.out.println ("??");
}
pi.next ();
}
Matt Humphrey http://www.iviz.com/
Mark Thornton - 21 Nov 2007 21:43 GMT
> I'm actually surprised that most of the Shape classes aren't
> serializable, but there you have it. Either lack of foresight, or
> specific design decision. You might open a feature request to sun, but
> I doubt it'll get much traction.
As of Java 6 most of the non abstract shapes are Serializable, Area
being one of the few exceptions. The previous lack of Serilizability was
an oversight, which regrettably took rather too long to fix.
Mark Thornton
> I have a java.awt.geom.Area object that I need to transmit over the
> network but when I try to do so using a ObjectOutputStream and NIO it
> complains that the object is not serializable. Which makes sense
> (seeing it isn't) but how do I transmit this object? Is there a trick
> to it? I tried wrapping it in a serializable object but it didn't like
> that either.
Maybe you can use Ted Neward's Serializable Adapter approach:
http://www.javageeks.com/Papers/SerializableAdapter/SerializableAdapter.html
Arne
>I have a java.awt.geom.Area object that I need to transmit over the network
>but when I try to do so using a ObjectOutputStream and NIO it complains that
>the object is not serializable.
Ideas:
try subclassing it and marking that subclass serializable.
Extract all the juice out of an Area and plop it into a
SerializableArea.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com