0

I'm making a paint application, and for the input of the shapes that were saved, I came across an issue.

You see, I am using a while loop to run through each line of a string saved by the program at an earlier time. I also have identifiers of what it is currently inputting. I had the program output the List of the shapes as what they are. Meaning, that each shape would output like java.awt.geom.Ellipse2D$Float@15990000.

Now I need some sort of way to turn that String, back into a shape. Either that, or have some sort of way to save it as a shape, in an easier way, that would allow me to add it right back to the List

Any and all help would be welcomed.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
The_Steve13
  • 119
  • 2
  • 11
  • 6
    Consider serializing your list of Shapes. – Hovercraft Full Of Eels Sep 18 '12 at 01:16
  • @HovercraftFullOfEels and how would I do that? – The_Steve13 Sep 18 '12 at 01:16
  • 1
    It allows you to store the desired information as binary data, and then allowing you at a later time to read the binary data and unmarshal it back into objects. Telling the details would involve me re-writing tutorials that are already out there, and so I invite you to Google some and to check them out. Note that the text information that you're currently displaying, `java.awt.geom.Ellipse2D$Float@15990000` is simply the default result returned by calling `toString()` and does not hold enough info to allow you to reproduce your shapes. – Hovercraft Full Of Eels Sep 18 '12 at 01:20
  • There are also text-based solutions involving XML such as XMLEncoder for Java Beans and JAXB, but each has its limitations. – Hovercraft Full Of Eels Sep 18 '12 at 01:26

1 Answers1

1

You could use SVG or a subset of it for the format of the saved files. If you use SVG, you can check (or use) Batik - it can transform SVG into Java2D objects.

This might be also interesting: how to capture graphics primitives from Graphics2D into SVG

Community
  • 1
  • 1
lbalazscs
  • 17,474
  • 7
  • 42
  • 50