package extends.layer.policy; import java.util.*; import com.bbn.openmap.layer.OMGraphicHandlerLayer; import com.bbn.openmap.event.LayerStatusEvent; import com.bbn.openmap.layer.policy.*; import com.bbn.openmap.event.ProjectionEvent; import com.bbn.openmap.omGraphics.OMGraphicList; import com.bbn.openmap.proj.Projection; import com.bbn.openmap.util.Debug; public class ProjChangePolicy_WithScaleRange extends ListResetPCPolicy { private float m_minScale; private float m_maxScale; /** * You MUST set a layer at some point. */ public ProjChangePolicy_WithScaleRange() { } /** * Don't pass in a null layer. */ public ProjChangePolicy_WithScaleRange(OMGraphicHandlerLayer layer) { this.layer = layer; } public void setScaleRange(float minScale, float maxScale) { m_minScale = minScale; m_maxScale = maxScale; } /* public float getMinScale() { return m_minScale; } */ public void projectionChanged(ProjectionEvent pe) { if (layer != null) { Projection proj = layer.setProjection(pe); // proj will be null if the projection hasn't changed, a // signal that work does not need to be done. if (proj != null) { layer.setList(null); float scale = proj.getScale(); if ((m_minScale < scale)&&(scale < m_maxScale)) { if (Debug.debugging("layer")) { Debug.output(getLayer().getName() + ": ProjChangePolicy_WithScaleRange projectionChanged with NEW projection, resetting list."); } layer.doPrepare(); } } else { if (Debug.debugging("layer")) { Debug.output(getLayer().getName() + ": ProjChangePolicy_WithScaleRange projectionChanged with OLD projection, repainting."); } if (!layer.isWorking()) { // This repaint may look redundant, but it handles // the situation where a layer is removed from a // map and readded when the projection doesn't // change. Since it already had the projection, // and remove() hasn't been called yet, the proj // == null. When the new layer is added, it // receives a projectionChanged call, and even // though it's all set, it still needs to call // repaint to have itself show up on the map. layer.repaint(); layer.fireStatusUpdate(LayerStatusEvent.FINISH_WORKING); } } } else { Debug.error("ProjChangePolicy_WithScaleRange.projectionChanged(): NULL layer, can't do anything."); } } }