1 6 package com.thoughtriver.open.vectorvisuals.persistence; 7 8 import java.awt.*; 9 import java.awt.geom.*; 10 import java.beans.*; 11 12 19 public class AreaPersistenceDelegate extends DefaultPersistenceDelegate { 20 21 24 @Override 25 protected Expression instantiate(final Object oldInstance, @SuppressWarnings ("unused") final Encoder out) { 26 Expression expression = null; 27 28 Area area = (Area) oldInstance; 29 if (area.isEmpty()) { 30 expression = new Expression(area, area.getClass(), "new", new Object [] {}); 31 } 32 else if (area.isRectangular()) { 33 expression = new Expression(area, area.getClass(), "new", new Object [] { 34 area.getBounds2D() 35 }); 36 } 37 else if (area.isPolygonal()) { 38 Polygon polygon = new Polygon(); 39 40 PathIterator iterator = area.getPathIterator(null); 41 float[] coords = new float[6]; 42 while (!iterator.isDone()) { 43 iterator.currentSegment(coords); 44 iterator.next(); 45 polygon.addPoint((int) coords[0], (int) coords[1]); 46 } 47 48 expression = new Expression(area, area.getClass(), "new", new Object [] { 49 polygon 50 }); 51 } 52 else { 53 throw new UnsupportedOperationException ("Persistence for this type of Area is not yet supported."); 54 } 55 56 return expression; 57 } 58 59 } 60 | Popular Tags |