Hello ForumI am trying to make a custom renderer as a Java add-in. I made the following very simple code, which paints all polygons green. The strange thing is, that each time i compile this program, it will work the first time I try it out in ArcMap. If I close restart ArcMap, then all polygons get painted in red by this Add-in, which I guess is a sort of fall back behaviour.No error is catched, and the printlines in the draw method are both printed to the console. I make the greenFillSymbol new each time. So I do not understand this behaviour at all.My question is, if anyone out there is actually making Java Add-ins for Desktop extensions?It may be, that I should revert to C++, and wait for another version of ArcGIS before changing to Java.I have attached the sorce.Best RegardsMarianne Wiese
package dk.geus;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.IOException;
import com.esri.arcgis.carto.*;
import com.esri.arcgis.display.*;
import com.esri.arcgis.geodatabase.*;
import com.esri.arcgis.geometry.*;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.system.*;
import com.esri.arcgis.interop.extn.ArcGISExtension;
@ArcGISExtension
public class LegendRenderer implements IFeatureRenderer {
private static final long serialVersionUID = 1L;
public LegendRenderer() { }
public SimpleFillSymbol greenSymbol() {
SimpleFillSymbol greenFillSymbol = null;
try {
greenFillSymbol = new SimpleFillSymbol();
greenFillSymbol.setStyle(esriSimpleFillStyle.esriSFSSolid);
greenFillSymbol.getOutline().setWidth(0.4);
IColor greenColor = new RgbColor();
greenColor.setRGB(0x00ff00);
greenFillSymbol.setColor(greenColor);
} catch (Exception e) {
e.printStackTrace();
}
return greenFillSymbol;
}
// Available only for specific geometry types
public boolean canRender(IFeatureClass fc, IDisplay display) throws IOException, AutomationException {
if (fc.getShapeType() == esriGeometryType.esriGeometryPolygon)
return true;
else
return false;
}
// Could be used for query filter
public void prepareFilter(IFeatureClass fc, IQueryFilter qFilter)throws IOException, AutomationException { }
// How to render
public void draw(IFeatureCursor featureCursor, int drawPhase, IDisplay display, ITrackCancel trackCancel) throws IOException,AutomationException {
System.out.println("Hello, here I am");
try {
IFeature feature = featureCursor.nextFeature();
display.setSymbol(greenSymbol());
do{
display.drawPolygon(feature.getShape());
feature = featureCursor.nextFeature();
}while (feature != null);
System.out.println("Hello, here I was");
} catch (Exception e) {
System.out.println(e.getMessage());
}
return;
}
public ISymbol getSymbolByFeature(IFeature arg0) throws IOException,AutomationException {
return null;
}
public boolean isRenderPhase(int drawPhase) throws IOException,AutomationException {
if (drawPhase == esriDrawPhase.esriDPGeography) return true;
else return false;
}
public void setExclusionSetByRef(IFeatureIDSet featureIDSet)throws IOException, AutomationException { }
public void writeExternal(ObjectOutput out) throws IOException { }
public void readExternal(ObjectInput in) throws IOException,ClassNotFoundException { }
}