package com.ximple.eofms.filter; import java.util.List; import java.util.TreeMap; import javax.swing.event.EventListenerList; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.geotools.feature.Feature; import org.geotools.feature.FeatureType; import org.geotools.feature.FeatureTypeBuilder; import org.geotools.feature.IllegalAttributeException; import org.geotools.feature.SchemaException; import com.vividsolutions.jts.geom.GeometryFactory; import com.ximple.eofms.util.DefaultColorTable; import com.ximple.eofms.util.FeatureTypeBuilderUtil; import com.ximple.eofms.util.TWD97GeometryConverterDecorator; import com.ximple.io.dgn7.Element; import com.ximple.io.dgn7.EllipseElement; import com.ximple.io.dgn7.FrammeAttributeData; import com.ximple.io.dgn7.UserAttributeData; public class CreateEllipseShapeStrategy implements CreateFeatureTypeStrategy { static final Log logger = LogFactory.getLog(CreateShapeStrategy.class); GeometryFactory geometryFactory = new GeometryFactory(); TreeMap typeBuilders = new TreeMap(); TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator(); // Create the listener list protected EventListenerList listenerList = new EventListenerList(); public CreateEllipseShapeStrategy() { } protected FrammeAttributeData getFeatureLinkage(Element element) { if (!element.hasUserAttributeData()) return null; List usrDatas = element.getUserAttributeData(); for (UserAttributeData anUsrData : usrDatas) { if (anUsrData instanceof FrammeAttributeData) { return (FrammeAttributeData) anUsrData; } } return null; } public FeatureType createFeatureElement(String featureName) throws SchemaException { if (!typeBuilders.containsKey(featureName)) { FeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createEllipseFeatureTypeBuilder(featureName); typeBuilders.put(featureName, typeBuilder); } return typeBuilders.get(featureName).getFeatureType(); } public Feature createFeature(FeatureType featureType, Element element) throws IllegalAttributeException { DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); FrammeAttributeData fLinkage = getFeatureLinkage(element); Feature feature = null; if (fLinkage == null) return null; if (element instanceof EllipseElement) { EllipseElement shapeElement = (EllipseElement) element; convertDecorator.setConverter(shapeElement); feature = featureType.create(new Object[]{ convertDecorator.toGeometry(geometryFactory), fLinkage.getFsc(), (long) fLinkage.getUfid(), (short) fLinkage.getComponentID(), (short) 0, (short) shapeElement.getLevelIndex(), colorTable.getColorCode(shapeElement.getColorIndex()), (short) shapeElement.getWeight(), (short) shapeElement.getLineStyle() }); } return feature; } public void addCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) { listenerList.add(CreateFeatureTypeEventListener.class, listener); } public void removeCreateFeatureTypeEventListener(CreateFeatureTypeEventListener listener) { listenerList.remove(CreateFeatureTypeEventListener.class, listener); } protected void fireFeatureTypeEvent(FeatureTypeEvent evt) { Object[] listeners = listenerList.getListenerList(); for (int i = 0; i < listeners.length; i += 2) { if (listeners[i] == CreateFeatureTypeEventListener.class) { ((CreateFeatureTypeEventListener) listeners[i + 1]).createFeatureTypeOccurred(evt); } } } }