arcgissamples\cartography\CustomLineSymbol.java
/* Copyright 2010 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions. * */ package arcgissamples.cartography; import java.io.IOException; import com.esri.arcgis.display.IColor; import com.esri.arcgis.display.ILineSymbol; import com.esri.arcgis.display.ISymbol; import com.esri.arcgis.display.RgbColor; import com.esri.arcgis.display.SimpleLineSymbol; import com.esri.arcgis.display.esriSimpleLineStyle; import com.esri.arcgis.geometry.IGeometry; import com.esri.arcgis.geometry.IPolygon; import com.esri.arcgis.geometry.ITransformation; import com.esri.arcgis.system.IClone; import com.esri.arcgis.interop.AutomationException; /** * Sample application to demonstrate creation of a custom line symbol. * The class implements IClone, ISymbol, ILineSymbol. */ public class CustomLineSymbol implements IClone, ISymbol, ILineSymbol { private static final long serialVersionUID = 1L; int HDC; ITransformation transformation; double width; IColor color; IColor backgroundColor; SimpleLineSymbol simpleLineSymbol1; SimpleLineSymbol simpleLineSymbol2; /** * Default constructor. */ CustomLineSymbol() { try { this.width = 4.0; RgbColor clr = new RgbColor(); clr.setRGB(0x0000FF); // red this.color = clr; RgbColor backgroundClr = new RgbColor(); backgroundClr.setRGB(0x00FF00); // green this.backgroundColor = backgroundClr; // this.simpleLineSymbol1 = new SimpleLineSymbol(); this.simpleLineSymbol1.setStyle(esriSimpleLineStyle.esriSLSSolid); // second step this.simpleLineSymbol2 = new SimpleLineSymbol(); this.simpleLineSymbol2.setStyle(esriSimpleLineStyle.esriSLSDashDot); } catch(IOException e){ // never happened } } // IClone interface /** * @see IClone#esri_clone */ public IClone esri_clone() throws IOException, AutomationException { // create a new CustomLineSymbol CustomLineSymbol lineSymbol = new CustomLineSymbol(); // set size and color lineSymbol.setWidth(getWidth()); lineSymbol.setColor(getColor()); return lineSymbol; } /** * @see IClone#assign */ public void assign(IClone iClone) { // no implement } /** * @see IClone#isEqual */ public boolean isEqual(IClone clone) throws IOException, AutomationException { // no need to go further if two objects are of different types if (!(clone instanceof CustomLineSymbol)) return false; // QI for ILineSymbol from IClone ILineSymbol lineSymbol = (ILineSymbol) clone; if (lineSymbol.getWidth() == getWidth() && lineSymbol.getColor().getRGB() == getColor().getRGB()) return true; return false; } /** * @see IClone#isIdentical */ public boolean isIdentical(IClone clone) { if (!(clone instanceof CustomLineSymbol)) return false; return clone.equals(this); } // ISymbol interface /** * @see ISymbol#setupDC */ public void setupDC(int i, ITransformation tran) { this.HDC = i; this.transformation = tran; } /** * @see ISymbol#resetDC */ public void resetDC() { // NO IMPL } /** * @see ISymbol#draw */ public void draw(IGeometry geometry) throws IOException, AutomationException { if (geometry == null) return; // first step this.simpleLineSymbol1.setWidth(this.width); this.simpleLineSymbol1.setColor(this.backgroundColor); this.simpleLineSymbol1.setupDC(this.HDC, this.transformation); this.simpleLineSymbol1.draw(geometry); this.simpleLineSymbol1.resetDC(); // second step this.simpleLineSymbol2.setWidth(1.0); this.simpleLineSymbol2.setColor(this.color); this.simpleLineSymbol2.setupDC(this.HDC, this.transformation); this.simpleLineSymbol2.draw(geometry); this.simpleLineSymbol2.resetDC(); } /** * @see ISymbol#queryBoundary */ public void queryBoundary(int i, ITransformation tran, IGeometry geometry, IPolygon polygon) { // NO IMPL } /** * @see ISymbol#getROP2 * @return int */ public int getROP2() { // NO IMPL return 1; } /** * @see ISymbol#setROP2 * @param i */ public void setROP2(int i) { // NO IMPL } // ILineSymbol interface /** * @see ILineSymbol#getColor * @return IColor */ public IColor getColor() { return this.color; } /** * @see ILineSymbol#setColor */ public void setColor(IColor clr) { this.color = clr; } /** * @see ILineSymbol#getWidth */ public double getWidth() { return this.width; } /** * @see ILineSymbol#setWidth */ public void setWidth(double v) { this.width = v; } }