RE: [OpenMap Users] Saving text to file.

From: Ratliff, Michelle W. <MICHELLE.W.RATLIFF_at_saic.com>
Date: Thu, 2 Apr 2009 13:03:11 -0400

Don,

   Thanks so much. I modified my openmap4.6.3 with the changes below
and
everything worked. I can now save any object drawn with the drawing
tool to
a file.

Appreciate your help,
Michelle Ratliff
SAIC IISBU
Columbia, MD



-----Original Message-----
From: OpenMap Support [mailto:openmap_at_bbn.com]
Sent: Wednesday, April 01, 2009 5:05 PM
To: Ratliff, Michelle W.
Cc: openmap-users_at_bbn.com
Subject: Re: [OpenMap Users] Saving text to file.

Hi Michelle,

Sorry, I forgot to mention that. I fixed the bug for the next version
of OpenMap and checked it into the OM5 beta available on the website
via svn (http://openmap.bbn.com/svn/openmap/trunk).

In addition to marking the textMatteStroke as transient, I modified
these methods in OMText:

     /**
      * Write this object to a stream.
      */
     private void writeObject(ObjectOutputStream oos) throws
IOException {
         oos.defaultWriteObject();

         // Write the Font. Take into account the font member could be
         // null, although this is unlikely it never hurts to
         // protect one's self.

         boolean writeFont = (f != OMText.DEFAULT_FONT);

         // First write a flag indicating if a Font is on the stream.
         oos.writeBoolean(writeFont);

         // Write the Font data if a font is on this object.
         if (writeFont) {
             oos.writeObject(f.getName());
             oos.writeInt(f.getSize());
             oos.writeInt(f.getStyle());
         }

         writeStroke(oos, stroke, OMGraphic.BASIC_STROKE);
         writeStroke(oos, textMatteStroke, DEFAULT_TEXT_MATTE_STROKE);
     }

     /**
      * Reconstitute from an ObjectInputStream.
      */
     private void readObject(ObjectInputStream ois)
             throws ClassNotFoundException, IOException {
         ois.defaultReadObject();

         // Get the flag form the stream
         boolean hasFont = ois.readBoolean();

         if (hasFont) {
             String name = (String) ois.readObject();
             int size = ois.readInt();
             int style = ois.readInt();
             f = new Font(name, style, size);
         } else {
             f = OMText.DEFAULT_FONT;
         }

         stroke = readStroke(ois, OMGraphic.BASIC_STROKE);
         textMatteStroke = readStroke(ois, DEFAULT_TEXT_MATTE_STROKE);
      }



I modified OMGraphic's methods, too:



     /**
      * Write this object to a stream.
      */
     private void writeObject(ObjectOutputStream oos) throws
IOException {
         oos.defaultWriteObject();

         // Now write the Stroke. Take into account the stroke member
         // could be null.
         writeStroke(oos, stroke, OMGraphic.BASIC_STROKE);
     }

     protected void writeStroke(ObjectOutputStream oos, Stroke stroke,
                                Stroke defStroke) throws IOException {

         boolean writeStroke = (stroke != defStroke) && stroke != null;

         if (writeStroke) {
             // First write a flag indicating if a Stroke is on the
             // stream.
             oos.writeBoolean(true);
             if (stroke instanceof BasicStroke) {
                 BasicStroke s = (BasicStroke) stroke;

                 // Then write flag indicating stroke is a BasicStroke
                 oos.writeBoolean(true);

                 // Write the Stroke data if a Stroke is on this
                 // object.
                 if (s != null) {
                     oos.writeFloat(s.getLineWidth());
                     oos.writeInt(s.getEndCap());
                     oos.writeInt(s.getLineJoin());
                     oos.writeFloat(s.getMiterLimit());
                     oos.writeObject(s.getDashArray());
                     oos.writeFloat(s.getDashPhase());
                 }
             } else if (stroke instanceof Serializable) {
                 oos.writeBoolean(false);
                 oos.writeObject((Serializable) stroke);
             }

         } else {
             oos.writeBoolean(false);
         }
     }

     /**
      * Read this object from a stream.
      */
     private void readObject(ObjectInputStream ois)
             throws ClassNotFoundException, IOException {
         ois.defaultReadObject();

         // Read the Stroke
         stroke = readStroke(ois, OMGraphic.BASIC_STROKE);
     }

     protected Stroke readStroke(ObjectInputStream ois, Stroke
defStroke)
             throws ClassNotFoundException, IOException {
         Stroke stroke = defStroke;

         // Get the flag indicating a stroke was streamed
         boolean streamHasStroke = ois.readBoolean();

         // Read and create the stroke
         if (streamHasStroke) {
             boolean isBasicStroke = ois.readBoolean();
             if (isBasicStroke) {
                 float linewidth = ois.readFloat();
                 int endcap = ois.readInt();
                 int linejoin = ois.readInt();
                 float miterlimit = ois.readFloat();
                 float dasharray[] = (float[]) ois.readObject();
                 float dashphase = ois.readFloat();
                 stroke = new BasicStroke(linewidth, endcap, linejoin,
miterlimit, dasharray, dashphase);
             } else {
                 stroke = (Stroke) ois.readObject();
             }
         }

         return stroke;
     }



Hope this helps,

Don

On Apr 1, 2009, at 3:39 PM, Ratliff, Michelle W. wrote:

> Don,
>
> Thanks but I'm not sure how to do this. Would I need to pull the
> OMText.java out of openmap and call my own version of it? Then
> traverse
> The list of objects I'm trying to save and see if text object is being
> saved? Is there any examples you can give me? Is openmap planning on
> fixing this bug in the near future?
>
> Thanks for any help,
> Michelle
>
> -----Original Message-----
> From: OpenMap Support [mailto:openmap_at_bbn.com]
> Sent: Thursday, March 12, 2009 4:14 PM
> To: Ratliff, Michelle W.
> Cc: openmap-users_at_bbn.com
> Subject: Re: [OpenMap Users] Saving text to file.
>
> Hi Michelle,
>
> Ahh, I see the problem. I think that's a bug, dealing with the
> matting stroke. The OMGraphic class breaks the regular stroke down
> into components for serialization, and that new stroke object was just
> added. It needs to be marked as transient and then handled explicitly
> in the readObject/writeObject methods.
>
> - Don
>
>
> On Mar 12, 2009, at 8:40 AM, Ratliff, Michelle W. wrote:
>
>> Hello,
>>
>> I'm trying to save all graphics drawn by the user to a file so that
>> the user can reload it at a later time. The text object is giving
>> me an
>> error when I try to use the 'save map' option in the Drawing Tool
>> Layer.
>> I'm getting a "NotSerializableException" on the BasicStroke for the
>> OMText component. Does anyone know how to make it serializable?
>>
>> Thanks for any assistance!
>> Michelle Ratliff
>> SAIC IISBU
>> 410-872-7092
>>
>> --
>> [To unsubscribe to this list send an email to "majdart_at_bbn.com"
>> with the following text in the BODY of the message "unsubscribe
>> openmap-users"]
>
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Don Dietrick, dietrick_at_bbn.com
> BBN Technologies, Cambridge MA
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
>
>
> --
> [To unsubscribe to this list send an email to "majdart_at_bbn.com"
> with the following text in the BODY of the message "unsubscribe
> openmap-users"]

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Don Dietrick, dietrick_at_bbn.com
BBN Technologies, Cambridge MA
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Thu Apr 02 2009 - 13:06:44 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:09 EDT