Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The way I did it is to identify the methods that I needed from the original Path class and then simply override those methods as follows:</p> <pre><code>public class CustomPath extends Path implements Serializable { private static final long serialVersionUID = -5974912367682897467L; private ArrayList&lt;PathAction&gt; actions = new ArrayList&lt;CustomPath.PathAction&gt;(); private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{ in.defaultReadObject(); drawThisPath(); } @Override public void moveTo(float x, float y) { actions.add(new ActionMove(x, y)); super.moveTo(x, y); } @Override public void lineTo(float x, float y){ actions.add(new ActionLine(x, y)); super.lineTo(x, y); } private void drawThisPath(){ for(PathAction p : actions){ if(p.getType().equals(PathActionType.MOVE_TO)){ super.moveTo(p.getX(), p.getY()); } else if(p.getType().equals(PathActionType.LINE_TO)){ super.lineTo(p.getX(), p.getY()); } } } public interface PathAction { public enum PathActionType {LINE_TO,MOVE_TO}; public PathActionType getType(); public float getX(); public float getY(); } public class ActionMove implements PathAction, Serializable{ private static final long serialVersionUID = -7198142191254133295L; private float x,y; public ActionMove(float x, float y){ this.x = x; this.y = y; } @Override public PathActionType getType() { return PathActionType.MOVE_TO; } @Override public float getX() { return x; } @Override public float getY() { return y; } } public class ActionLine implements PathAction, Serializable{ private static final long serialVersionUID = 8307137961494172589L; private float x,y; public ActionLine(float x, float y){ this.x = x; this.y = y; } @Override public PathActionType getType() { return PathActionType.LINE_TO; } @Override public float getX() { return x; } @Override public float getY() { return y; } } } </code></pre> <p>In my example I need "moveTo" and "lineTo", so in this case I simply hold the drawing information in a list. This list contains the drawing information (what I call "action") needed by Path in order to restore the drawing as it looked like before the object was serialized. Then when I deserialize my objects of type CustomPath i make sure to let <a href="http://java.sun.com/developer/technicalArticles/Programming/serialization/">the default serialization protocol</a> call "drawThisPath", so the path is redrawn.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload