Issue #2140 Added getSafeName to abstractVizResource and a standardized resource painting method to AbstractRenderableDisplay.

Change-Id: I3d2541a057440a3813837a91bef4e86172d73e4c

Former-commit-id: 0f490c934d197bc45fea1fad2c034c47a2556988
This commit is contained in:
Ron Anderson 2013-07-29 18:12:24 -05:00
parent f3a8ccf158
commit 4aceedceb5
7 changed files with 171 additions and 128 deletions

View file

@ -65,6 +65,7 @@ import com.raytheon.uf.viz.core.rsc.sampling.SamplingResource;
* Oct 28, 2009 2354 bsteffen Moved logic for handling IMiddleClickCapableResource to the input handler so it uses configurable mouse preferences
* Jul 20, 2010 6187 bkowal The alpha level will always be reset for every
* resource when the paint method is called now.
* 06/24/2013 2140 randerso Changed to use standardized paint error handling
*
* </pre>
*
@ -172,13 +173,7 @@ public class MapRenderableDisplay extends AbstractRenderableDisplay implements
}
paintProps = calcPaintDataTime(paintProps, rsc);
try {
rsc.paint(target, paintProps);
} catch (Throwable e) {
pair.getProperties().setVisible(false);
throw new VizException("Paint error: " + e.getMessage()
+ ":: The resource has been disabled.", e);
}
paintResource(pair, target, paintProps);
}
}
target.clearClippingPlane();

View file

@ -66,6 +66,7 @@ import com.raytheon.uf.viz.core.rsc.ResourceList.RemoveListener;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 06, 2009 bgonzale Initial creation
* Jun 24, 2013 2140 randerso Added paintResource method
*
* </pre>
*
@ -147,14 +148,17 @@ public abstract class AbstractRenderableDisplay implements IRenderableDisplay {
this.initializedTarget = null;
}
@Override
public IExtent getExtent() {
return this.view.getExtent();
}
@Override
public int getWorldHeight() {
return descriptor.getGridGeometry().getGridRange().getHigh(1) + 1;
}
@Override
public int getWorldWidth() {
return descriptor.getGridGeometry().getGridRange().getHigh(0) + 1;
}
@ -273,6 +277,7 @@ public abstract class AbstractRenderableDisplay implements IRenderableDisplay {
/**
* @return the view
*/
@Override
public IView getView() {
return view;
}
@ -387,6 +392,7 @@ public abstract class AbstractRenderableDisplay implements IRenderableDisplay {
*
* @return zoom
*/
@Override
public double getZoom() {
return this.view.getZoom();
}
@ -415,6 +421,7 @@ public abstract class AbstractRenderableDisplay implements IRenderableDisplay {
target.setBackgroundColor(backgroundColor);
}
@Override
public void setup(IGraphicsTarget target) {
this.initializedTarget = target;
this.view.setupView(target);
@ -532,14 +539,17 @@ public abstract class AbstractRenderableDisplay implements IRenderableDisplay {
return null;
}
@Override
public void setSwapping(boolean swapping) {
this.swapping = swapping;
}
@Override
public boolean isSwapping() {
return this.swapping;
}
@Override
public Map<String, Object> getGlobalsMap() {
globals.put(VizConstants.FRAME_COUNT_ID, getDescriptor()
.getFramesInfo().getFrameCount());
@ -596,4 +606,23 @@ public abstract class AbstractRenderableDisplay implements IRenderableDisplay {
}
}
/**
* Standardized method to handle Paint Errors
*
* @param pair
* @param target
* @param paintProps
* @throws VizException
*/
protected void paintResource(ResourcePair pair, IGraphicsTarget target,
PaintProperties paintProps) throws VizException {
try {
pair.getResource().paint(target, paintProps);
} catch (Throwable e) {
pair.getProperties().setVisible(false);
throw new VizException("Paint error: " + e.getMessage()
+ ":: The resource [" + pair.getResource().getSafeName()
+ "] has been disabled.", e);
}
}
}

View file

@ -32,6 +32,9 @@ import org.eclipse.core.runtime.jobs.Job;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import com.raytheon.uf.common.geospatial.ReferencedCoordinate;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.viz.core.IDisplayPaneContainer;
import com.raytheon.uf.viz.core.IGraphicsTarget;
@ -64,6 +67,7 @@ import com.raytheon.uf.viz.core.rsc.capabilities.Capabilities;
* Feb 4, 2009 chammack Initial creation from original IVizResource
* Mar 3, 2009 2032 jsanchez Added getDescriptor and paintProps.
* Mar 29, 2013 1638 mschenke Fixed leak of data change listener
* Jun 24, 2013 2140 randerso Added getSafeName method
*
* </pre>
*
@ -74,6 +78,9 @@ import com.raytheon.uf.viz.core.rsc.capabilities.Capabilities;
@SuppressWarnings("unchecked")
public abstract class AbstractVizResource<T extends AbstractResourceData, D extends IDescriptor> {
protected static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(AbstractVizResource.class);
public enum ResourceStatus {
NEW, LOADING, INITIALIZED, DISPOSED
}
@ -143,7 +150,8 @@ public abstract class AbstractVizResource<T extends AbstractResourceData, D exte
private IResourceDataChanged changeListener = new IResourceDataChanged() {
@Override
public void resourceChanged(ChangeType type, Object object) {
if (type == ChangeType.DATA_REMOVE && object instanceof DataTime) {
if ((type == ChangeType.DATA_REMOVE)
&& (object instanceof DataTime)) {
remove((DataTime) object);
} else {
AbstractVizResource.this.resourceDataChanged(type, object);
@ -467,7 +475,7 @@ public abstract class AbstractVizResource<T extends AbstractResourceData, D exte
}
case LOADING: {
// still initializing, check for exceptions
if (initJob != null && initJob.exception != null) {
if ((initJob != null) && (initJob.exception != null)) {
VizException e = initJob.exception;
// Reset status and job
status = ResourceStatus.NEW;
@ -592,7 +600,7 @@ public abstract class AbstractVizResource<T extends AbstractResourceData, D exte
public final void registerListener(IDisposeListener listener) {
if (this instanceof IResourceGroup) {
for (ResourcePair rp : ((IResourceGroup) this).getResourceList()) {
if (rp != null && rp.getResource() != null) {
if ((rp != null) && (rp.getResource() != null)) {
rp.getResource().registerListener(listener);
}
}
@ -813,4 +821,23 @@ public abstract class AbstractVizResource<T extends AbstractResourceData, D exte
protected void setProperties(ResourceProperties properties) {
this.properties = properties;
}
/**
* Gets the resource name or class name if resource.getName() fails.
*
* This should only be used to get as good a name as possible for the
* resource in exceptional conditions.
*
* @return the safe resource name
*/
public final String getSafeName() {
String safeResourceName = this.getClass().getSimpleName();
try {
safeResourceName = this.getName();
} catch (Throwable e) {
// This means they just won't get as useful of a message.
statusHandler.handle(Priority.DEBUG, e.getLocalizedMessage(), e);
}
return safeResourceName;
}
}

View file

@ -53,6 +53,7 @@ import com.raytheon.uf.viz.xy.map.rsc.GraphResource;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 10, 2009 mschenke Initial creation
* 06/24/2013 2140 randerso Changed to use standardized paint error handling
*
* </pre>
*
@ -82,20 +83,20 @@ public abstract class AbstractXyRenderableDisplay extends
public void paint(IGraphicsTarget target, PaintProperties paintProps)
throws VizException {
super.paint(target, paintProps);
if (getDescriptor() instanceof XyGraphDescriptor == false) {
if ((getDescriptor() instanceof XyGraphDescriptor) == false) {
return;
}
GraphProperties gProps = new GraphProperties(paintProps);
gProps.setWorldExtent(worldExtent);
GraphResource gRsc = ((XyGraphDescriptor) getDescriptor())
.getGraphResource();
if (gRsc != null && gRsc.getStatus() == ResourceStatus.NEW) {
if ((gRsc != null) && (gRsc.getStatus() == ResourceStatus.NEW)) {
gRsc.init(target);
}
for (ResourcePair rp : getDescriptor().getResourceList()) {
AbstractVizResource<?, ?> rsc = rp.getResource();
if (rsc == null || rp.getProperties().isVisible() == false) {
if ((rsc == null) || (rp.getProperties().isVisible() == false)) {
continue;
}
if (rsc.hasCapability(ImagingCapability.class)) {
@ -103,14 +104,7 @@ public abstract class AbstractXyRenderableDisplay extends
.getAlpha());
}
gProps.setDataTime(descriptor.getTimeForResource(rsc));
try {
rsc.paint(target, gProps);
} catch (Throwable e) {
rp.getProperties().setVisible(false);
throw new VizException("Paint error: " + e.getMessage()
+ ":: The resource has been disabled.", e);
}
paintResource(rp, target, gProps);
}
}

View file

@ -44,6 +44,7 @@ import com.raytheon.uf.viz.core.rsc.ResourceList.RemoveListener;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 17, 2011 bsteffen Initial creation
* 06/24/2013 2140 randerso Changed to use standardized paint error handling
*
* </pre>
*
@ -94,7 +95,7 @@ public class HodographRenderableDisplay extends AbstractRenderableDisplay
private void addResource(ResourcePair rp) {
AbstractVizResource<?, ?> rsc = rp.getResource();
if (rsc != null && rsc instanceof IHodographResource) {
if ((rsc != null) && (rsc instanceof IHodographResource)) {
resources.add((IHodographResource) rsc);
}
}
@ -113,10 +114,10 @@ public class HodographRenderableDisplay extends AbstractRenderableDisplay
if (pair.getResource() == null) {
continue;
}
pair.getResource().paint(target, paintProps);
paintResource(pair, target, paintProps);
}
for (IHodographResource rsc : resources) {
if (rsc instanceof AbstractVizResource
if ((rsc instanceof AbstractVizResource)
&& !((AbstractVizResource<?, ?>) rsc).getProperties()
.isVisible()) {
continue;

View file

@ -48,6 +48,7 @@ import com.raytheon.uf.viz.core.exception.VizException;
* Mar 16, 2011 bsteffen Initial creation
* Jun 04, 2013 2041 bsteffen Improve exception handing in grid
* resources.
* Jun 24, 2013 2140 randerso Moved safe name code into AbstractVizResource
*
* </pre>
*
@ -84,7 +85,7 @@ class GridDataRequestJob extends Job {
}
public boolean shouldRequest() {
return gridData == null && exception == null;
return (gridData == null) && (exception == null);
}
}
@ -145,15 +146,15 @@ class GridDataRequestJob extends Job {
itr.remove();
if (r.gridData != null) {
return r.gridData;
} else if (r.pdos == null && pdos == null) {
} else if ((r.pdos == null) && (pdos == null)) {
request = r;
} else if (r.pdos != null && r.pdos.equals(pdos)) {
} else if ((r.pdos != null) && r.pdos.equals(pdos)) {
request = r;
}
}
}
requests.add(0, request);
if (request.exception != null && !request.exceptionHandled) {
if ((request.exception != null) && !request.exceptionHandled) {
handleExceptions();
}
}
@ -169,7 +170,7 @@ class GridDataRequestJob extends Job {
requests.size());
synchronized (requests) {
for (GridDataRequest request : requests) {
if (request.exception != null && !request.exceptionHandled) {
if ((request.exception != null) && !request.exceptionHandled) {
failedRequests.add(request);
}
}
@ -177,14 +178,7 @@ class GridDataRequestJob extends Job {
if (failedRequests.isEmpty()) {
return;
}
String safeResourceName = "Grid Resource";
try {
safeResourceName = resource.getName();
} catch (Throwable e) {
// This means they just won't get
// as useful of a message.
statusHandler.handle(Priority.DEBUG, e.getLocalizedMessage(), e);
}
String safeResourceName = resource.getSafeName();
boolean multiple = failedRequests.size() > 1;
GridDataRequest request = failedRequests.get(0);
// Only log one message as a PROBLEM

View file

@ -1,13 +1,12 @@
package gov.noaa.nws.ncep.viz.ui.display;
import gov.noaa.nws.ncep.viz.common.area.IGridGeometryProvider;
import gov.noaa.nws.ncep.viz.common.area.PredefinedArea;
import gov.noaa.nws.ncep.viz.common.area.PredefinedAreaFactory;
import gov.noaa.nws.ncep.viz.common.display.INatlCntrsPaneManager;
import gov.noaa.nws.ncep.viz.common.display.INatlCntrsRenderableDisplay;
import gov.noaa.nws.ncep.viz.common.display.INcPaneID;
import gov.noaa.nws.ncep.viz.common.display.NcDisplayType;
import gov.noaa.nws.ncep.viz.common.display.NcDisplayName.NcPaneName;
import gov.noaa.nws.ncep.viz.common.display.NcDisplayType;
import java.util.ArrayList;
import java.util.List;
@ -22,7 +21,6 @@ import org.geotools.coverage.grid.GeneralGridEnvelope;
import org.geotools.coverage.grid.GeneralGridGeometry;
import org.geotools.coverage.grid.GridGeometry2D;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.referencing.crs.DefaultEngineeringCRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import com.raytheon.uf.common.colormap.prefs.ColorMapParameters;
@ -66,6 +64,7 @@ import com.raytheon.viz.ui.editor.AbstractEditor;
* 11/18/2012 #630 ghull construct from areaProvider
* 04/10/2013 #958 qzhou Added displayWidth = 1000; Added shouldDisplay.
* 05/19/2013 #862 ghull add paneName, implement IAreaProviderCapable
* 06/24/2013 2140 randerso Changed to use standardized paint error handling
*
* </pre>
*
@ -75,22 +74,25 @@ import com.raytheon.viz.ui.editor.AbstractEditor;
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(name = "NC-NonMapRenderableDisplay")
@XmlRootElement
public class NCNonMapRenderableDisplay extends AbstractRenderableDisplay implements
AddListener, INatlCntrsRenderableDisplay, ISerializableObject {
public class NCNonMapRenderableDisplay extends AbstractRenderableDisplay
implements AddListener, INatlCntrsRenderableDisplay,
ISerializableObject {
@XmlElement
private NcPaneID paneId;
// private String paneName; // the rbd/displayName + the paneId if multipane
// private String paneName; // the rbd/displayName + the paneId if multipane
// either the RBD or the Display's paneManager
private INatlCntrsPaneManager paneContainer;
// the initial area that the display is set to. This is used for the unzoom.
// after the display is loaded the user may pan/zoom in which case the current
// area(gridGeometry,zoom,mapcenter) will be different than the initial area.
// after the display is loaded the user may pan/zoom in which case the
// current
// area(gridGeometry,zoom,mapcenter) will be different than the initial
// area.
//
// @XmlElement
// @XmlElement
private PredefinedArea initialArea;
public static final GenericResourceData legendRscData = new GenericResourceData(
@ -99,32 +101,33 @@ public class NCNonMapRenderableDisplay extends AbstractRenderableDisplay impleme
public static final GenericResourceData selectedRscData = new GenericResourceData(
NcSelectedPaneResource.class);
public NCNonMapRenderableDisplay() {
this(new NcPaneID(), new PixelExtent(0, 1000, 0, 1000));
}
public NCNonMapRenderableDisplay( NcPaneID pid, PixelExtent pe ) {
super( pe, new NCNonMapDescriptor() );
this.setPaneId( pid );
public NCNonMapRenderableDisplay(NcPaneID pid, PixelExtent pe) {
super(pe, new NCNonMapDescriptor());
this.setPaneId(pid);
}
@Override
public double[] getMapCenter() {
return getExtent().getCenter();
}
// this shouldn't be called from NCP but override as a sanity check since
// AbstractXYRenderableDisplay's setTabTitle() calls getEditor which assumes an XyEditor
// AbstractXYRenderableDisplay's setTabTitle() calls getEditor which assumes
// an XyEditor
public void setTabTitle(String tabTitle) {
// tabTitle = tabTitle;
// if (getEditor() != null) {
// getEditor().setTabTitle(tabTitle);
// }
// tabTitle = tabTitle;
// if (getEditor() != null) {
// getEditor().setTabTitle(tabTitle);
// }
}
@Override
public void dispose() {
if (this.descriptor != null ) {// && editorInstanceNum <= 1) {
if (this.descriptor != null) {// && editorInstanceNum <= 1) {
descriptor.getResourceList().clear();
this.descriptor.getResourceList().removePostAddListener(
this.listener);
@ -140,55 +143,50 @@ public class NCNonMapRenderableDisplay extends AbstractRenderableDisplay impleme
super.paint(target, paintProps);
float zoomLevel = paintProps.getZoomLevel();
LoopProperties loopProperties = paintProps.getLoopProperties();
// this.zoomLevel = zoomLevel;
// this.zoomLevel = zoomLevel;
// If no loop properties, use the default values. sanity check?
if (loopProperties == null ) {
if (loopProperties == null) {
loopProperties = new LoopProperties();
}
// Calculate the new map center
// this.mapCenter = descriptor.pixelToWorld(paintProps.getView()
// .getExtent().getCenter());
// this.mapCenter = descriptor.pixelToWorld(paintProps.getView()
// .getExtent().getCenter());
// ???? do we need this
// target.setupClippingPlane(getMapExtent());
// paintProps.setClippingPane(getMapExtent());
// target.setupClippingPlane(getMapExtent());
// paintProps.setClippingPane(getMapExtent());
int displayWidth = 1000; //(int) (((MapDescriptor) descriptor).getMapWidth() * zoomLevel);
int displayWidth = 1000; // (int) (((MapDescriptor)
// descriptor).getMapWidth() * zoomLevel);
List<ResourcePair> renderingList =
new ArrayList<ResourcePair>( descriptor.getResourceList());
List<ResourcePair> renderingList = new ArrayList<ResourcePair>(
descriptor.getResourceList());
for( ResourcePair pair : renderingList ) {
for (ResourcePair pair : renderingList) {
AbstractVizResource<?, ?> rsc = pair.getResource();
if( rsc == null ) {
if (rsc == null) {
continue;
}
// ResourceProperties properties = pair.getProperties();
// if ((rsc.getStatus() == ResourceStatus.NEW || properties.isDisplayable(displayWidth))
// if ((rsc.getStatus() == ResourceStatus.NEW ||
// properties.isDisplayable(displayWidth))
// && (!properties.isBlinking() || getCurrentBlinkState())) {
if (shouldDisplay(pair, displayWidth)) {
// always reset the alpha
paintProps.setAlpha(1.0f);
if( rsc.hasCapability(ImagingCapability.class)) {
if (rsc.hasCapability(ImagingCapability.class)) {
paintProps.setAlpha(rsc.getCapability(
ImagingCapability.class).getAlpha());
}
paintProps = calcPaintDataTime(paintProps, rsc);
try {
rsc.paint(target, paintProps);
} catch (Throwable e) {
pair.getProperties().setVisible(false);
throw new VizException("Paint error: " + e.getMessage()
+ ":: The resource has been disabled.", e);
}
paintResource(pair, target, paintProps);
}
}
target.clearClippingPlane();
@ -196,28 +194,29 @@ public class NCNonMapRenderableDisplay extends AbstractRenderableDisplay impleme
@Override
public NcPaneName getPaneName() {
if( getPaneManager().getPaneLayout().getNumberOfPanes() == 1 ) {
return new NcPaneName( getPaneManager().getDisplayName() );
}
else {
return new NcPaneName( getPaneManager().getDisplayName(), getPaneId() );
}
if (getPaneManager().getPaneLayout().getNumberOfPanes() == 1) {
return new NcPaneName(getPaneManager().getDisplayName());
} else {
return new NcPaneName(getPaneManager().getDisplayName(),
getPaneId());
}
}
@Override
public NcPaneID getPaneId() {
if( paneId == null ) {
if (paneId == null) {
paneId = new NcPaneID();
}
return paneId;
}
@Override
public void setPaneId( INcPaneID pid) {
public void setPaneId(INcPaneID pid) {
paneId = (NcPaneID) pid;
}
// TODO? if null then set to the descriptors gridGeom??
@Override
public NCNonMapDescriptor getDescriptor() {
if (super.getDescriptor() instanceof NCNonMapDescriptor) {
return (NCNonMapDescriptor) super.getDescriptor();
@ -232,16 +231,15 @@ public class NCNonMapRenderableDisplay extends AbstractRenderableDisplay impleme
//
@Override
public PredefinedArea getInitialArea() {
if( initialArea == null ) {
try {
initialArea =
PredefinedAreaFactory.getDefaultPredefinedAreaForDisplayType(
NcDisplayType.NTRANS_DISPLAY );
} catch (VizException e) {
}
public PredefinedArea getInitialArea() {
if (initialArea == null) {
try {
initialArea = PredefinedAreaFactory
.getDefaultPredefinedAreaForDisplayType(NcDisplayType.NTRANS_DISPLAY);
} catch (VizException e) {
}
}
}
return initialArea;
}
@ -264,24 +262,27 @@ public class NCNonMapRenderableDisplay extends AbstractRenderableDisplay impleme
}
@Override
public void setInitialArea( PredefinedArea area ) {
initialArea = area;
public void setInitialArea(PredefinedArea area) {
initialArea = area;
try {
// setPredefinedArea( initialArea );
getDescriptor().setGridGeometry( area.getGridGeometry() );
// setPredefinedArea( initialArea );
getDescriptor().setGridGeometry(area.getGridGeometry());
// if( initialArea.getMapCenter() == null ) {
// initialArea.setMapCenter( getMapCenter() );
// }
// if( initialArea.getMapCenter() == null ) {
// initialArea.setMapCenter( getMapCenter() );
// }
} catch (VizException e) {
System.out.println("Error setting initial area of renderable display:"+e.getMessage() );
System.out
.println("Error setting initial area of renderable display:"
+ e.getMessage());
}
// if this is actually called/needed then check that the crs is 2d Cartesian
// if this is actually called/needed then check that the crs is 2d
// Cartesian
// and set the extents.
// System.out.println("setInitialArea not implemented for non-map display");
// System.out.println("setInitialArea not implemented for non-map display");
}
@Override
@ -291,16 +292,17 @@ public class NCNonMapRenderableDisplay extends AbstractRenderableDisplay impleme
.constructSystemResourcePair(legendRscData));
resourceList.add(ResourcePair
.constructSystemResourcePair(selectedRscData));
resourceList.addPostAddListener( this );
resourceList.addPostAddListener(this);
}
@Override
public void notifyAdd( ResourcePair rp ) throws VizException {
public void notifyAdd(ResourcePair rp) throws VizException {
// TODO : any checks on the type of resource here.
AbstractNcPaneManager pm = NcEditorUtil.getNcPaneManager( (AbstractEditor)container );
if( pm != null ) {
pm.setDisplayAvailable( false );
AbstractNcPaneManager pm = NcEditorUtil
.getNcPaneManager((AbstractEditor) container);
if (pm != null) {
pm.setDisplayAvailable(false);
}
}
@ -359,23 +361,24 @@ public class NCNonMapRenderableDisplay extends AbstractRenderableDisplay impleme
&& !doNotDrawBecauseOfBlinking;
}
@Override
public void setPaneManager(INatlCntrsPaneManager pm) {
paneContainer = pm;
}
@Override
public void setPaneManager(INatlCntrsPaneManager pm) {
paneContainer = pm;
}
@Override
public void setContainer( IDisplayPaneContainer container ) {
super.setContainer( container );
@Override
public void setContainer(IDisplayPaneContainer container) {
super.setContainer(container);
if( container instanceof AbstractEditor ) {
INatlCntrsPaneManager pm = NcEditorUtil.getNcPaneManager( (AbstractEditor)container );
setPaneManager( pm );
}
}
if (container instanceof AbstractEditor) {
INatlCntrsPaneManager pm = NcEditorUtil
.getNcPaneManager((AbstractEditor) container);
setPaneManager(pm);
}
}
@Override
public INatlCntrsPaneManager getPaneManager() {
return paneContainer;
}
@Override
public INatlCntrsPaneManager getPaneManager() {
return paneContainer;
}
}