diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/data/BufferSlicer.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/data/BufferSlicer.java index 609dcfb86f..238846b4b5 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/data/BufferSlicer.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/data/BufferSlicer.java @@ -22,7 +22,6 @@ package com.raytheon.uf.viz.core.data; import java.awt.Rectangle; import java.nio.Buffer; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.nio.ShortBuffer; @@ -47,7 +46,8 @@ import java.nio.ShortBuffer; public class BufferSlicer { /** - * Given a Buffer, a Rectangle for the Buffer, and a totalBounds + * Slices a Buffer represented by a 2D bounds totalBounds into a Buffer + * represented by bounds dataBounds. * * @param data * @param dataBounds @@ -57,72 +57,138 @@ public class BufferSlicer { */ public static Buffer slice(Buffer data, Rectangle dataBounds, Rectangle totalBounds) { + if (dataBounds.getMinX() < totalBounds.getMinX() + || dataBounds.getMinY() < totalBounds.getMinY() + || dataBounds.getMaxX() > totalBounds.getMaxX() + || dataBounds.getMaxY() > totalBounds.getMaxY()) { + throw new RuntimeException( + "Data bounds defines region outside of buffer's total bounds"); + } + + data = duplicate(data); int dataSize = dataBounds.width * dataBounds.height; if (dataSize == totalBounds.width * totalBounds.height) { return data; } - Buffer newData = null; - // Get our new Buffer object if (data instanceof ByteBuffer) { - if (data.isDirect()) { - newData = ByteBuffer.allocateDirect(dataSize).order( - ByteOrder.nativeOrder()); - } else { - newData = ByteBuffer.allocate(dataSize); - } + return slice((ByteBuffer) data, dataBounds, totalBounds, dataSize); } else if (data instanceof ShortBuffer) { - if (data.isDirect()) { - newData = ByteBuffer.allocateDirect(dataSize * 2) - .order(ByteOrder.nativeOrder()).asShortBuffer(); - } else { - newData = ShortBuffer.allocate(dataSize); - } + return slice((ShortBuffer) data, dataBounds, totalBounds, dataSize); } else if (data instanceof IntBuffer) { - if (data.isDirect()) { - newData = ByteBuffer.allocateDirect(dataSize * 4) - .order(ByteOrder.nativeOrder()).asIntBuffer(); - } else { - newData = IntBuffer.allocate(dataSize); - } + return slice((IntBuffer) data, dataBounds, totalBounds, dataSize); } else if (data instanceof FloatBuffer) { - if (data.isDirect()) { - newData = ByteBuffer.allocateDirect(dataSize * 4) - .order(ByteOrder.nativeOrder()).asFloatBuffer(); - } else { - newData = FloatBuffer.allocate(dataSize); - } + return slice((FloatBuffer) data, dataBounds, totalBounds, dataSize); } else { - // Unsupported type - return data; + throw new RuntimeException( + "Unhandled buffer passed in: " + data != null ? data + .getClass().getSimpleName() : null); + } + } + + private static Buffer duplicate(Buffer data) { + if (data instanceof ByteBuffer) { + return ((ByteBuffer) data).duplicate(); + } else if (data instanceof ShortBuffer) { + return ((ShortBuffer) data).duplicate(); + } else if (data instanceof IntBuffer) { + return ((IntBuffer) data).duplicate(); + } else if (data instanceof FloatBuffer) { + return ((FloatBuffer) data).duplicate(); + } else { + throw new RuntimeException( + "Unhandled buffer passed in: " + data != null ? data + .getClass().getSimpleName() : null); + } + } + + private static ByteBuffer slice(ByteBuffer data, Rectangle dataBounds, + Rectangle totalBounds, int dataSize) { + ByteBuffer newData = null; + // Get our new Buffer object + if (data.isDirect()) { + newData = ByteBuffer.allocateDirect(dataSize).order(data.order()); + } else { + newData = ByteBuffer.allocate(dataSize); } - // Synchronize on the data buffer if multi threads slicing same buffer - // at the same time - synchronized (data) { - newData.position(0); - for (int i = 0; i < dataBounds.height; ++i) { - data.position((dataBounds.y * totalBounds.width + dataBounds.x) - + i * totalBounds.width); - if (data instanceof ByteBuffer) { - byte[] bytes = new byte[dataBounds.width]; - ((ByteBuffer) data).get(bytes); - ((ByteBuffer) newData).put(bytes); - } else if (data instanceof ShortBuffer) { - short[] shorts = new short[dataBounds.width]; - ((ShortBuffer) data).get(shorts); - ((ShortBuffer) newData).put(shorts); - } else if (data instanceof IntBuffer) { - int[] ints = new int[dataBounds.width]; - ((IntBuffer) data).get(ints); - ((IntBuffer) newData).put(ints); - } else { - // FloatBuffer by default - float[] floats = new float[dataBounds.width]; - ((FloatBuffer) data).get(floats); - ((FloatBuffer) newData).put(floats); - } - } + newData.position(0); + byte[] bytes = new byte[dataBounds.width]; + for (int i = 0; i < dataBounds.height; ++i) { + data.position((dataBounds.y * totalBounds.width + dataBounds.x) + i + * totalBounds.width); + data.get(bytes); + newData.put(bytes); } - return newData.rewind(); + newData.rewind(); + return newData; + } + + private static ShortBuffer slice(ShortBuffer data, Rectangle dataBounds, + Rectangle totalBounds, int dataSize) { + ShortBuffer newData = null; + // Get our new Buffer object + if (data.isDirect()) { + newData = ByteBuffer.allocateDirect(dataSize * 2) + .order(data.order()).asShortBuffer(); + } else { + newData = ShortBuffer.allocate(dataSize); + } + + newData.position(0); + short[] shorts = new short[dataBounds.width]; + for (int i = 0; i < dataBounds.height; ++i) { + data.position((dataBounds.y * totalBounds.width + dataBounds.x) + i + * totalBounds.width); + data.get(shorts); + newData.put(shorts); + } + newData.rewind(); + return newData; + } + + private static IntBuffer slice(IntBuffer data, Rectangle dataBounds, + Rectangle totalBounds, int dataSize) { + IntBuffer newData = null; + // Get our new Buffer object + if (data.isDirect()) { + newData = ByteBuffer.allocateDirect(dataSize * 4) + .order(data.order()).asIntBuffer(); + } else { + newData = IntBuffer.allocate(dataSize); + } + + newData.position(0); + int[] ints = new int[dataBounds.width]; + for (int i = 0; i < dataBounds.height; ++i) { + data.position((dataBounds.y * totalBounds.width + dataBounds.x) + i + * totalBounds.width); + data.get(ints); + newData.put(ints); + } + newData.rewind(); + return newData; + } + + private static FloatBuffer slice(FloatBuffer data, Rectangle dataBounds, + Rectangle totalBounds, int dataSize) { + FloatBuffer newData = null; + // Get our new Buffer object + if (data.isDirect()) { + newData = ByteBuffer.allocateDirect(dataSize * 4) + .order(data.order()).asFloatBuffer(); + } else { + newData = FloatBuffer.allocate(dataSize); + } + + newData.position(0); + float[] floats = new float[dataBounds.width]; + for (int i = 0; i < dataBounds.height; ++i) { + data.position((dataBounds.y * totalBounds.width + dataBounds.x) + i + * totalBounds.width); + data.get(floats); + newData.put(floats); + } + newData.rewind(); + return newData; } } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/AbstractRenderableDisplay.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/AbstractRenderableDisplay.java index b6c67c5540..312afa1c3c 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/AbstractRenderableDisplay.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/AbstractRenderableDisplay.java @@ -39,7 +39,6 @@ import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.AbstractGraphicsFactoryAdapter; import com.raytheon.uf.viz.core.GraphicsFactory; -import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.uf.viz.core.IDisplayPaneContainer; import com.raytheon.uf.viz.core.IExtent; import com.raytheon.uf.viz.core.IGraphicsTarget; @@ -247,6 +246,7 @@ public abstract class AbstractRenderableDisplay implements IRenderableDisplay { this.descriptor = (AbstractDescriptor) desc; this.descriptor.getResourceList().addPostAddListener(this.listener); this.descriptor.getResourceList().addPostRemoveListener(this.listener); + this.descriptor.setRenderableDisplay(this); customizeResourceList(this.descriptor.getResourceList()); } @@ -478,7 +478,7 @@ public abstract class AbstractRenderableDisplay implements IRenderableDisplay { } @Override - public void clear(IDisplayPane parentPane) { + public void clear() { } @@ -562,7 +562,6 @@ public abstract class AbstractRenderableDisplay implements IRenderableDisplay { @Override public void setContainer(IDisplayPaneContainer container) { this.container = container; - this.descriptor.setRenderableDisplay(this); } @Override diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/IRenderableDisplay.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/IRenderableDisplay.java index 2eb4d07d95..a0f364e34c 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/IRenderableDisplay.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/IRenderableDisplay.java @@ -25,7 +25,6 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.Rectangle; import com.raytheon.uf.viz.core.AbstractGraphicsFactoryAdapter; -import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.uf.viz.core.IDisplayPaneContainer; import com.raytheon.uf.viz.core.IExtent; import com.raytheon.uf.viz.core.IGraphicsTarget; @@ -266,7 +265,7 @@ public interface IRenderableDisplay extends IRenderable { /** * Triggers the clearing of the RenderableDisplay */ - public void clear(IDisplayPane parentPane); + public void clear(); /** * Set the background color of the display diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/tile/BufferTileImageCreator.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/tile/BufferTileImageCreator.java new file mode 100644 index 0000000000..6efffbfcba --- /dev/null +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/tile/BufferTileImageCreator.java @@ -0,0 +1,95 @@ +package com.raytheon.uf.viz.core.tile; + +import java.awt.Rectangle; +import java.nio.Buffer; + +import org.geotools.coverage.grid.GeneralGridGeometry; + +import com.raytheon.uf.viz.core.DrawableImage; +import com.raytheon.uf.viz.core.IGraphicsTarget; +import com.raytheon.uf.viz.core.IGraphicsTarget.RasterMode; +import com.raytheon.uf.viz.core.IMesh; +import com.raytheon.uf.viz.core.PixelCoverage; +import com.raytheon.uf.viz.core.data.BufferSlicer; +import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback; +import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.drawables.ext.colormap.IColormappedImageExtension; +import com.raytheon.uf.viz.core.exception.VizException; +import com.raytheon.uf.viz.core.map.IMapMeshExtension; +import com.raytheon.uf.viz.core.rsc.capabilities.ColorMapCapability; +import com.raytheon.uf.viz.core.tile.TileSetRenderable.TileImageCreator; + +/** + * {@link TileImageCreator} for {@link TileSetRenderable} that creates image + * tiles for Buffers. Only supports single level tiling + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 29, 2012            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ +public class BufferTileImageCreator implements TileImageCreator { + + private class BufferColorMapRetrievalCallback implements + IColorMapDataRetrievalCallback { + + private Rectangle slice; + + private BufferColorMapRetrievalCallback(Rectangle slice) { + this.slice = slice; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback# + * getColorMapData() + */ + @Override + public ColorMapData getColorMapData() throws VizException { + return new ColorMapData(BufferSlicer.slice(buffer, slice, + bufferBounds), new int[] { slice.width, slice.height }); + } + + } + + private Buffer buffer; + + private Rectangle bufferBounds; + + private ColorMapCapability cmapCapability; + + public BufferTileImageCreator(Buffer buffer, Rectangle bufferBounds, + ColorMapCapability cmapCapability) { + this.buffer = buffer; + this.bufferBounds = bufferBounds; + this.cmapCapability = cmapCapability; + } + + @Override + public DrawableImage createTileImage(IGraphicsTarget target, Tile tile, + GeneralGridGeometry targetGeometry) throws VizException { + if (tile.tileLevel != 0) { + throw new VizException(getClass().getSimpleName() + + " only supports single level tiled data"); + } + + IImage image = target + .getExtension(IColormappedImageExtension.class) + .initializeRaster( + new BufferColorMapRetrievalCallback(tile.getRectangle()), + cmapCapability.getColorMapParameters()); + IMesh mesh = target.getExtension(IMapMeshExtension.class) + .constructMesh(tile.tileGeometry, targetGeometry); + return new DrawableImage(image, new PixelCoverage(mesh), + RasterMode.ASYNCHRONOUS); + } +} diff --git a/cave/com.raytheon.uf.viz.cwat/src/com/raytheon/uf/viz/cwat/CWATResource.java b/cave/com.raytheon.uf.viz.cwat/src/com/raytheon/uf/viz/cwat/CWATResource.java index ff7e4aff62..d5e5b13916 100644 --- a/cave/com.raytheon.uf.viz.cwat/src/com/raytheon/uf/viz/cwat/CWATResource.java +++ b/cave/com.raytheon.uf.viz.cwat/src/com/raytheon/uf/viz/cwat/CWATResource.java @@ -49,7 +49,6 @@ import com.raytheon.uf.viz.core.rsc.AbstractVizResource; import com.raytheon.uf.viz.core.rsc.IResourceDataChanged; import com.raytheon.uf.viz.core.rsc.LoadProperties; import com.raytheon.uf.viz.core.rsc.capabilities.ColorMapCapability; -import com.raytheon.uf.viz.core.status.StatusConstants; import com.raytheon.uf.viz.core.style.ParamLevelMatchCriteria; import com.raytheon.uf.viz.core.style.StyleManager; import com.raytheon.uf.viz.core.style.StyleRule; @@ -79,7 +78,8 @@ import com.vividsolutions.jts.geom.Coordinate; public class CWATResource extends AbstractVizResource implements IResourceDataChanged { - private static final transient IUFStatusHandler statusHandler = UFStatus.getHandler(CWATResource.class); + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(CWATResource.class); public String icao; @@ -206,9 +206,7 @@ public class CWATResource extends if (gridDisplay == null) { gridDisplay = new GriddedImageDisplay2(ShortBuffer.wrap(record - .getDataArray()), record.getGridGeometry(), this, - target.getViewType()); - gridDisplay.init(target); + .getDataArray()), record.getGridGeometry(), this); this.previousDataTime = displayedDataTime; griddedDisplayMap.put(displayedDataTime, gridDisplay); } @@ -298,7 +296,7 @@ public class CWATResource extends for (DataTime dTime : griddedDisplayMap.keySet()) { GriddedImageDisplay2 gDisplay = griddedDisplayMap.get(dTime); if (gDisplay != null) { - gDisplay.reproject(); + gDisplay.project(descriptor.getGridGeometry()); } } } diff --git a/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/map/D2DMapRenderableDisplay.java b/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/map/D2DMapRenderableDisplay.java index 09ba95ba72..9fe528c9fb 100644 --- a/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/map/D2DMapRenderableDisplay.java +++ b/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/map/D2DMapRenderableDisplay.java @@ -31,7 +31,6 @@ import javax.xml.bind.annotation.XmlRootElement; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; -import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.uf.viz.core.IGraphicsTarget; import com.raytheon.uf.viz.core.VizConstants; import com.raytheon.uf.viz.core.drawables.AbstractDescriptor; @@ -267,8 +266,7 @@ public class D2DMapRenderableDisplay extends MapRenderableDisplay implements } @Override - public void clear(IDisplayPane parentPane) { - super.clear(parentPane); + public void clear() { descriptor.getResourceList().clear(); File scaleFile = MapScales.getInstance().getScaleByName(getScale()) .getFile(); diff --git a/cave/com.raytheon.uf.viz.vil/src/com/raytheon/uf/viz/vil/VILResource.java b/cave/com.raytheon.uf.viz.vil/src/com/raytheon/uf/viz/vil/VILResource.java index 378d5591e5..5709136242 100644 --- a/cave/com.raytheon.uf.viz.vil/src/com/raytheon/uf/viz/vil/VILResource.java +++ b/cave/com.raytheon.uf.viz.vil/src/com/raytheon/uf/viz/vil/VILResource.java @@ -49,7 +49,6 @@ import com.raytheon.uf.viz.core.rsc.AbstractVizResource; import com.raytheon.uf.viz.core.rsc.IResourceDataChanged; import com.raytheon.uf.viz.core.rsc.LoadProperties; import com.raytheon.uf.viz.core.rsc.capabilities.ColorMapCapability; -import com.raytheon.uf.viz.core.status.StatusConstants; import com.raytheon.uf.viz.core.style.ParamLevelMatchCriteria; import com.raytheon.uf.viz.core.style.StyleManager; import com.raytheon.uf.viz.core.style.StyleRule; @@ -79,7 +78,8 @@ import com.vividsolutions.jts.geom.Coordinate; public class VILResource extends AbstractVizResource implements IResourceDataChanged { - private static final transient IUFStatusHandler statusHandler = UFStatus.getHandler(VILResource.class); + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(VILResource.class); public String icao; @@ -218,9 +218,7 @@ public class VILResource extends gridDisplay = griddedDisplayMap.get(displayedDataTime); if (gridDisplay == null) { gridDisplay = new GriddedImageDisplay2(FloatBuffer.wrap(record - .getDataArray()), record.getGridGeometry(), this, - target.getViewType()); - gridDisplay.init(target); + .getDataArray()), record.getGridGeometry(), this); this.previousDataTime = displayedDataTime; griddedDisplayMap.put(displayedDataTime, gridDisplay); } @@ -334,7 +332,7 @@ public class VILResource extends for (DataTime dTime : griddedDisplayMap.keySet()) { GriddedImageDisplay2 gDisplay = griddedDisplayMap.get(dTime); if (gDisplay != null) { - gDisplay.reproject(); + gDisplay.project(descriptor.getGridGeometry()); } } } diff --git a/cave/com.raytheon.uf.viz.xy/src/com/raytheon/uf/viz/xy/graph/AbstractXyRenderableDisplay.java b/cave/com.raytheon.uf.viz.xy/src/com/raytheon/uf/viz/xy/graph/AbstractXyRenderableDisplay.java index 7e7f9e5cec..4f5e889919 100644 --- a/cave/com.raytheon.uf.viz.xy/src/com/raytheon/uf/viz/xy/graph/AbstractXyRenderableDisplay.java +++ b/cave/com.raytheon.uf.viz.xy/src/com/raytheon/uf/viz/xy/graph/AbstractXyRenderableDisplay.java @@ -29,7 +29,6 @@ import javax.xml.bind.annotation.XmlRootElement; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; -import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.uf.viz.core.IExtent; import com.raytheon.uf.viz.core.IGraphicsTarget; import com.raytheon.uf.viz.core.VizConstants; @@ -136,8 +135,8 @@ public abstract class AbstractXyRenderableDisplay extends } @Override - public void clear(IDisplayPane parentPane) { - super.clear(parentPane); + public void clear() { + super.clear(); IWorkbenchPage page = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); page.closeEditor(getEditor(), false); diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/AbstractGLColorMapDataFormat.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/AbstractGLColorMapDataFormat.java index 400584ccdf..a9a5513424 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/AbstractGLColorMapDataFormat.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/AbstractGLColorMapDataFormat.java @@ -56,6 +56,26 @@ public abstract class AbstractGLColorMapDataFormat { */ public abstract int getTextureInternalFormat(); + /** + * Gets the absolute minimum value a pixel can have in this format. For + * example, the minimum value for an unsigned byte is 0, signed byte is + * -127, etc. {@link Double#NaN} can be returned in case no absolute minimum + * exists (such as case with floats and doubles) + * + * @return + */ + public abstract double getDataFormatMin(); + + /** + * Gets the absolute maximum value a pixel can have in this format. For + * example, the minimum value for an unsigned byte is 255, signed byte is + * 128, etc. {@link Double#NaN} can be returned in case no absolute maximum + * exists (such as case with floats and doubles) + * + * @return + */ + public abstract double getDataFormatMax(); + /** * Create a buffer object for specified data for copying data from out of GL * diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLByteDataFormat.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLByteDataFormat.java index 85f46d781b..0f80cca621 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLByteDataFormat.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLByteDataFormat.java @@ -66,6 +66,28 @@ public class GLByteDataFormat extends AbstractGLColorMapDataFormat { return GL.GL_LUMINANCE8; } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat# + * getDataFormatMin() + */ + @Override + public double getDataFormatMin() { + return 0; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat# + * getDataFormatMax() + */ + @Override + public double getDataFormatMax() { + return 0xFF; + } + /* * (non-Javadoc) * diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLColorMapData.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLColorMapData.java index 84b53ec68c..2704e0bba8 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLColorMapData.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLColorMapData.java @@ -43,7 +43,7 @@ import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback.ColorMapData */ public class GLColorMapData { - private AbstractGLColorMapDataFormat dataFormat; + private final AbstractGLColorMapDataFormat dataFormat; private Buffer data; @@ -55,8 +55,8 @@ public class GLColorMapData { public GLColorMapData(ColorMapData cmData, AbstractGLColorMapDataFormat dataFormat) { - this.dimensions = cmData.getDimensions(); this.dataFormat = dataFormat; + this.dimensions = cmData.getDimensions(); this.dataType = cmData.getDataType(); this.textureType = dataFormat.getTextureType(); this.data = dataFormat.formatForGL(cmData.getBuffer(), this); @@ -94,6 +94,14 @@ public class GLColorMapData { return dataFormat.getCopyBackTextureType(); } + public double getDataFormatMin() { + return dataFormat.getDataFormatMin(); + } + + public double getDataFormatMax() { + return dataFormat.getDataFormatMax(); + } + public Buffer getCopybackBuffer() { return dataFormat.getCopybackBuffer(this); } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLFloatDataFormat.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLFloatDataFormat.java index c56aba75a3..040665765b 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLFloatDataFormat.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLFloatDataFormat.java @@ -58,6 +58,28 @@ public class GLFloatDataFormat extends AbstractGLColorMapDataFormat { return GL.GL_FLOAT; } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat# + * getDataFormatMin() + */ + @Override + public double getDataFormatMin() { + return Double.NaN; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat# + * getDataFormatMax() + */ + @Override + public double getDataFormatMax() { + return Double.NaN; + } + @Override public FloatBuffer getCopybackBuffer(GLColorMapData data) { int width = data.getDimensionSize(0); diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLHalfFloatDataFormat.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLHalfFloatDataFormat.java index c6d0875a7e..5580d4458f 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLHalfFloatDataFormat.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLHalfFloatDataFormat.java @@ -67,6 +67,28 @@ public class GLHalfFloatDataFormat extends AbstractGLColorMapDataFormat { return GL.GL_HALF_FLOAT_ARB; } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat# + * getDataFormatMin() + */ + @Override + public double getDataFormatMin() { + return Double.NaN; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat# + * getDataFormatMax() + */ + @Override + public double getDataFormatMax() { + return Double.NaN; + } + @Override public ShortBuffer getCopybackBuffer(GLColorMapData data) { int width = getAlignedWidth(data.getDimensionSize(0)); diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLIntDataFormat.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLIntDataFormat.java index a9b55f1df2..3404bf60d5 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLIntDataFormat.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLIntDataFormat.java @@ -63,6 +63,28 @@ public class GLIntDataFormat extends AbstractGLColorMapDataFormat { return GL.GL_UNSIGNED_INT; } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat# + * getDataFormatMin() + */ + @Override + public double getDataFormatMin() { + return Integer.MIN_VALUE; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat# + * getDataFormatMax() + */ + @Override + public double getDataFormatMax() { + return Integer.MAX_VALUE; + } + @Override public IntBuffer getCopybackBuffer(GLColorMapData data) { int width = data.getDimensionSize(0); diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLShortDataFormat.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLShortDataFormat.java index bcbb01caa1..0181426897 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLShortDataFormat.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLShortDataFormat.java @@ -62,6 +62,28 @@ public class GLShortDataFormat extends AbstractGLColorMapDataFormat { return GL.GL_UNSIGNED_SHORT; } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat# + * getDataFormatMin() + */ + @Override + public double getDataFormatMin() { + return Short.MIN_VALUE; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat# + * getDataFormatMax() + */ + @Override + public double getDataFormatMax() { + return Short.MAX_VALUE; + } + /* * (non-Javadoc) * diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLSignedByteDataFormat.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLSignedByteDataFormat.java index dd4c4f4993..882a2cf705 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLSignedByteDataFormat.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLSignedByteDataFormat.java @@ -72,6 +72,28 @@ public class GLSignedByteDataFormat extends GLByteDataFormat { } } + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.dataformat.GLByteDataFormat#getDataFormatMin() + */ + @Override + public double getDataFormatMin() { + return Byte.MIN_VALUE; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.dataformat.GLByteDataFormat#getDataFormatMax() + */ + @Override + public double getDataFormatMax() { + return Byte.MAX_VALUE; + } + /* * (non-Javadoc) * diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLUnsignedShortDataFormat.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLUnsignedShortDataFormat.java index 8f430b8054..c2e47d5d06 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLUnsignedShortDataFormat.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLUnsignedShortDataFormat.java @@ -53,6 +53,28 @@ public class GLUnsignedShortDataFormat extends GLShortDataFormat { return GL.GL_UNSIGNED_SHORT; } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat# + * getDataFormatMin() + */ + @Override + public double getDataFormatMin() { + return 0; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat# + * getDataFormatMax() + */ + @Override + public double getDataFormatMax() { + return 0xFFFF; + } + /* * (non-Javadoc) * diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLCMTextureData.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLCMTextureData.java index d6fc718a9f..ca0ded7561 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLCMTextureData.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLCMTextureData.java @@ -192,6 +192,14 @@ public class GLCMTextureData implements IImageCacheable { return data.getTextureInternalFormat(); } + public double getDataMin() { + return data.getDataFormatMin(); + } + + public double getDataMax() { + return data.getDataFormatMax(); + } + public int getTexId() { if (isLoaded()) { ImageCache.getInstance(CacheType.TEXTURE).put(this); diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLColormappedImage.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLColormappedImage.java index fdc594669b..ceea37b2ef 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLColormappedImage.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLColormappedImage.java @@ -140,6 +140,26 @@ public class GLColormappedImage extends AbstractGLImage implements return data.getTexId(); } + /** + * the absolute minimum value of a pixel in this image. {@link Double#NaN} + * if no absolute minimum exists + * + * @return + */ + public double getDataMin() { + return data.getDataMin(); + } + + /** + * the absolute maximum value of a pixel in this image. {@link Double#NaN} + * if no absolute maximum exists + * + * @return + */ + public double getDataMax() { + return data.getDataMax(); + } + /* * (non-Javadoc) * diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormappedImageExtension.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormappedImageExtension.java index 8b15f26afe..a0f8b7a01b 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormappedImageExtension.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormappedImageExtension.java @@ -208,9 +208,18 @@ public class GLColormappedImageExtension extends AbstractGLSLImagingExtension program.setUniform("colorMapSz", colorMapParameters.getColorMap() .getSize()); - int textureType = ((GLColormappedImage) image).getTextureType(); - program.setUniform("isFloat", textureType == GL.GL_FLOAT - || textureType == GL.GL_HALF_FLOAT_ARB ? 1 : 0); + int textureType = image.getTextureType(); + boolean isFloat = textureType == GL.GL_FLOAT + || textureType == GL.GL_HALF_FLOAT_ARB; + double dataMin = colorMapParameters.getDataMin(); + double dataMax = colorMapParameters.getDataMax(); + if (isFloat == false) { + // get format from image and get data min/max from it + dataMin = image.getDataMin(); + dataMax = image.getDataMax(); + } + + program.setUniform("isFloat", isFloat); program.setUniform("logarithmic", colorMapParameters.isLogarithmic() ? 1 : 0); program.setUniform("logFactor", colorMapParameters.getLogFactor()); @@ -218,8 +227,8 @@ public class GLColormappedImageExtension extends AbstractGLSLImagingExtension program.setUniform("applyMask", colorMapParameters.isUseMask() ? 1 : 0); - program.setUniform("naturalMin", colorMapParameters.getDataMin()); - program.setUniform("naturalMax", colorMapParameters.getDataMax()); + program.setUniform("naturalMin", dataMin); + program.setUniform("naturalMax", dataMax); program.setUniform("cmapMin", colorMapParameters.getColorMapMin()); program.setUniform("cmapMax", colorMapParameters.getColorMapMax()); diff --git a/cave/com.raytheon.viz.core/src/com/raytheon/viz/core/rsc/displays/GriddedImageDisplay2.java b/cave/com.raytheon.viz.core/src/com/raytheon/viz/core/rsc/displays/GriddedImageDisplay2.java index 7bb157d123..954ef0b82b 100644 --- a/cave/com.raytheon.viz.core/src/com/raytheon/viz/core/rsc/displays/GriddedImageDisplay2.java +++ b/cave/com.raytheon.viz.core/src/com/raytheon/viz/core/rsc/displays/GriddedImageDisplay2.java @@ -19,48 +19,40 @@ **/ package com.raytheon.viz.core.rsc.displays; -import java.awt.Rectangle; import java.nio.Buffer; -import java.nio.FloatBuffer; -import java.nio.ShortBuffer; import org.geotools.coverage.grid.GridGeometry2D; -import com.raytheon.uf.common.datastorage.StorageException; -import com.raytheon.uf.viz.core.IGraphicsTarget; -import com.raytheon.uf.viz.core.data.IDataPreparer; -import com.raytheon.uf.viz.core.data.prep.CMDataPreparerManager; -import com.raytheon.uf.viz.core.drawables.IImage; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.map.IMapDescriptor; import com.raytheon.uf.viz.core.rsc.AbstractVizResource; import com.raytheon.uf.viz.core.rsc.capabilities.ColorMapCapability; -import com.raytheon.viz.core.rsc.hdf5.AbstractTileSet; +import com.raytheon.uf.viz.core.rsc.capabilities.ImagingCapability; +import com.raytheon.uf.viz.core.tile.BufferTileImageCreator; +import com.raytheon.uf.viz.core.tile.TileSetRenderable; /** - * TODO Add Description + * + * Gridded Buffer object, just a convenience class for thing already using it. + * Just extends {@link TileSetRenderable} and uses the + * {@link BufferTileImageCreator} as the {@link TileImageCreator} for the + * {@link TileSetRenderable}. Also projects on construction as convenience so + * creators don't have to * *
+ * 
  * SOFTWARE HISTORY
+ * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * Oct 27, 2008            randerso     Initial creation
- * Feb 01, 2011 #4237      ekladstrup   Rewrite to extend AbstractTileSet
+ * Dec 11, 2012            mschenke     Initial creation
+ * 
  * 
* - * @author randerso - * @version 2.0 + * @author mschenke + * @version 1.0 */ - -public class GriddedImageDisplay2 extends AbstractTileSet { - - private Buffer data; - - private DataType dataType = null; - - private static enum DataType { - BYTE, FLOAT, INT, SHORT - } +public class GriddedImageDisplay2 extends TileSetRenderable { /** * @@ -75,12 +67,13 @@ public class GriddedImageDisplay2 extends AbstractTileSet { */ public GriddedImageDisplay2(int size, Buffer data, GridGeometry2D gridGeometry, - AbstractVizResource rsc, - String viewType) throws VizException { - super(1, size, gridGeometry, rsc, viewType); - this.setMapDescriptor(rsc.getDescriptor()); - this.data = data; - setDataType(); + AbstractVizResource rsc) + throws VizException { + super(rsc.getCapability(ImagingCapability.class), gridGeometry, + new BufferTileImageCreator(data, gridGeometry.getGridRange2D() + .getBounds(), + rsc.getCapability(ColorMapCapability.class)), 1, size); + project(rsc.getDescriptor().getGridGeometry()); } /** @@ -93,166 +86,9 @@ public class GriddedImageDisplay2 extends AbstractTileSet { * @throws VizException */ public GriddedImageDisplay2(Buffer data, GridGeometry2D gridGeometry, - AbstractVizResource rsc, - String viewType) throws VizException { - super(1, 512, gridGeometry, rsc, viewType); - this.setMapDescriptor(rsc.getDescriptor()); - this.data = data; - setDataType(); - } - - private void setDataType() { - Object arr = data.array(); - - if (arr instanceof byte[]) { - dataType = DataType.BYTE; - } else if (arr instanceof float[]) { - dataType = DataType.FLOAT; - } else if (arr instanceof int[]) { - dataType = DataType.INT; - } else if (arr instanceof short[]) { - dataType = DataType.SHORT; - } - } - - @Override - protected void preloadDataObject(int level) throws StorageException { - // TODO Auto-generated method stub - - } - - @Override - public boolean hasDataPreloaded(int level) { - // TODO Auto-generated method stub - if (level == 1) { - return true; - } - return false; - } - - @Override - protected IImage createTile(IGraphicsTarget target, int level, int i, int j) + AbstractVizResource rsc) throws VizException { - - if (dataType == null) { - throw new VizException("Unsupported buffer type used"); - } - - // tile bounds - Rectangle rect = this.tileSet.getTileSet().get(level)[i][j] - .getRectangle(); - // total width - int width = gridGeometry[level].getGridRange().getSpan(0); - IImage image = null; - switch (dataType) { - case BYTE: { - throw new VizException("Unsupported buffer type used (BYTE)"); - // image = createByteTile(target, rect, width, i, j); - // break; - } - case FLOAT: { - image = createFloatTile(target, rect, width, i, j); - break; - } - case INT: { - throw new VizException("Unsupported buffer type used (INT)"); - // image = createIntTile(target, rect, width, i, j); - // break; - } - case SHORT: { - // throw new VizException("Unsupported buffer type used (SHORT)"); - image = createShortTile(target, rect, width, i, j); - break; - } - } - return image; + this(512, data, gridGeometry, rsc); } - private IImage createShortTile(IGraphicsTarget target, Rectangle rect, - int width, int i, int j) { - // buffer to copy into - short[] dest = new short[rect.width * rect.height]; - ShortBuffer srcBuff = (ShortBuffer) data; - - short[] tmp = new short[rect.width]; - int initSize = tileSize * j * width; - - for (int r = 0; r < rect.height; r++) { - int curY = (r * width) + initSize; - synchronized (this) { - srcBuff.position(curY + rect.x); - - srcBuff.get(tmp); - } - - for (int destIndex = r * rect.width; destIndex < (r * rect.width) - + rect.width; ++destIndex) { - dest[destIndex] = tmp[destIndex - (r * rect.width)]; - } - } - - ShortBuffer destBuff = ShortBuffer.wrap(dest); - - return generateImage(destBuff, target, rect); - } - - private IImage createIntTile(IGraphicsTarget target, Rectangle rect, - int width, int i, int j) { - return null; - } - - private IImage createFloatTile(IGraphicsTarget target, Rectangle rect, - int width, int i, int j) { - - // buffer to copy into - FloatBuffer destBuff = FloatBuffer.allocate(rect.width * rect.height); - FloatBuffer srcBuff = (FloatBuffer) data; - - float[] tmp = new float[rect.width]; - int initSize = tileSize * j * width; - - for (int r = 0; r < rect.height; r++) { - int curY = (r * width) + initSize; - synchronized (this) { - srcBuff.position(curY + rect.x); - - srcBuff.get(tmp); - } - - destBuff.put(tmp); - } - - return generateImage(destBuff, target, rect); - } - - private IImage createByteTile(IGraphicsTarget target, Rectangle rect, - int width, int i, int j) { - return null; - } - - protected IImage generateImage(Buffer tileData, IGraphicsTarget target, - Rectangle rect) { - - // create image at i,j index - int[] dims = { rect.width, rect.height }; - IDataPreparer preparer = CMDataPreparerManager.getDataPreparer( - tileData, rect, dims); - - return target.initializeRaster(preparer, - rsc.getCapability(ColorMapCapability.class) - .getColorMapParameters()); - } - - @Override - public void cancelRequest(int level, int i, int j) { - // TODO Auto-generated method stub - - } - - /** - * @return the data - */ - public Buffer getData() { - return data; - } } \ No newline at end of file diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/rsc/general/AbstractGridResource.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/rsc/general/AbstractGridResource.java index 4308109a39..d3665b9583 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/rsc/general/AbstractGridResource.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/rsc/general/AbstractGridResource.java @@ -476,8 +476,7 @@ public abstract class AbstractGridResource .getColorMapParameters(); data.convert(params.getImageUnit()); GriddedImageDisplay2 imageRenderable = new GriddedImageDisplay2( - data.getScalarData(), gridGeometry, this, "2D"); - imageRenderable.init(target); + data.getScalarData(), gridGeometry, this); renderable = imageRenderable; break; case BARB: @@ -730,7 +729,8 @@ public abstract class AbstractGridResource protected boolean projectRenderable(IRenderable renderable, CoordinateReferenceSystem crs) throws VizException { if (renderable instanceof GriddedImageDisplay2) { - ((GriddedImageDisplay2) renderable).reproject(); + ((GriddedImageDisplay2) renderable).project(descriptor + .getGridGeometry()); return true; } else if (renderable instanceof AbstractGriddedDisplay) { ((AbstractGriddedDisplay) renderable).reproject(); diff --git a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/FFGGridResource.java b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/FFGGridResource.java index d85b19f8b1..0d6903a552 100644 --- a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/FFGGridResource.java +++ b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/FFGGridResource.java @@ -298,10 +298,7 @@ public class FFGGridResource extends } if (gridDisplay == null) { - gridDisplay = new GriddedImageDisplay2(buf, gridGeometry, this, - target.getViewType()); - gridDisplay.init(target); - + gridDisplay = new GriddedImageDisplay2(buf, gridGeometry, this); } gridDisplay.paint(target, paintProps); diff --git a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/MeanArealPrecipResource.java b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/MeanArealPrecipResource.java index 7314a9a6fc..351035a3a8 100644 --- a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/MeanArealPrecipResource.java +++ b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/MeanArealPrecipResource.java @@ -38,9 +38,9 @@ import org.geotools.coverage.grid.GridGeometry2D; import org.geotools.coverage.grid.InvalidGridGeometryException; import org.opengis.referencing.crs.CoordinateReferenceSystem; -import com.raytheon.uf.common.dataplugin.shef.tables.Colorvalue; import com.raytheon.uf.common.colormap.Color; import com.raytheon.uf.common.colormap.ColorMap; +import com.raytheon.uf.common.dataplugin.shef.tables.Colorvalue; import com.raytheon.uf.common.geospatial.MapUtil; import com.raytheon.uf.common.hydro.spatial.HRAPCoordinates; import com.raytheon.uf.common.hydro.spatial.HRAPSubGrid; @@ -231,17 +231,17 @@ public class MeanArealPrecipResource extends meanAreaNodes = (ArrayList) GeoUtil.getInstance() .getGeoAreaLinesegs(areaType); if (extent != null) { - compute_mean_areal_precip(buf, meanAreaNodes, xor, yor, max_columns, - max_rows); + compute_mean_areal_precip(buf, meanAreaNodes, xor, yor, + max_columns, max_rows); try { subGrid = new HRAPSubGrid(extent); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } - + gridGeometry = MapUtil.getGridGeometry(subGrid); - + try { project(gridGeometry.getCoordinateReferenceSystem()); } catch (InvalidGridGeometryException e) { @@ -516,9 +516,7 @@ public class MeanArealPrecipResource extends // target.setUseBuiltinColorbar(false); if (gridDisplay == null) { - gridDisplay = new GriddedImageDisplay2(buf2, gridGeometry, this, - target.getViewType()); - gridDisplay.init(target); + gridDisplay = new GriddedImageDisplay2(buf2, gridGeometry, this); } gridDisplay.paint(target, paintProps); @@ -590,11 +588,12 @@ public class MeanArealPrecipResource extends if ((buf2 == null) || (gridGeometry == null)) { noData = true; } - + StringBuilder sb = new StringBuilder(); sb.append(dman.getAccumInterval() + " hr Accumulated Best Estimate QPE Ending " - + HydroConstants.DISPLAY_DATE_FORMAT.format(dman.getDataDate())+"z (in)"); + + HydroConstants.DISPLAY_DATE_FORMAT.format(dman.getDataDate()) + + "z (in)"); if (noData) { sb.append(" No Data Available"); @@ -649,7 +648,7 @@ public class MeanArealPrecipResource extends @Override public void project(CoordinateReferenceSystem crs) throws VizException { if (gridDisplay != null) { - gridDisplay.reproject(); + gridDisplay.project(descriptor.getGridGeometry()); } } } diff --git a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/RFCGriddedBasinFFGResource.java b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/RFCGriddedBasinFFGResource.java index 67479e3502..d1761f6da1 100644 --- a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/RFCGriddedBasinFFGResource.java +++ b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/RFCGriddedBasinFFGResource.java @@ -387,9 +387,7 @@ public class RFCGriddedBasinFFGResource extends } if (gridDisplay == null) { - gridDisplay = new GriddedImageDisplay2(buf, gridGeometry, this, - target.getViewType()); - gridDisplay.init(target); + gridDisplay = new GriddedImageDisplay2(buf, gridGeometry, this); } gridDisplay.paint(target, paintProps); diff --git a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/XmrgResource.java b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/XmrgResource.java index 497bbf41f0..66a0078ef8 100644 --- a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/XmrgResource.java +++ b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/XmrgResource.java @@ -235,13 +235,14 @@ public class XmrgResource extends name = "FFG No Data Available"; } else { name = "FFG " + res.getResolution() + " " + hours + " " - + hourStr + " " + sdf.format(dataDate)+"z (in)" + noData; + + hourStr + " " + sdf.format(dataDate) + "z (in)" + + noData; } } else { name = dman.getAccumInterval() + " hr Accumulated Best Estimate QPE Ending " + HydroConstants.DISPLAY_DATE_FORMAT.format(dman - .getDataDate()) +"z (in)"+ noData; + .getDataDate()) + "z (in)" + noData; } return name; } @@ -484,9 +485,7 @@ public class XmrgResource extends } if (gridDisplay == null) { - gridDisplay = new GriddedImageDisplay2(buf, gridGeometry, this, - target.getViewType()); - gridDisplay.init(target); + gridDisplay = new GriddedImageDisplay2(buf, gridGeometry, this); } GriddedImagePaintProperties giProps = new GriddedImagePaintProperties( diff --git a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/DisplayMeanArealPrecipResource.java b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/DisplayMeanArealPrecipResource.java index 6bfdf71f8a..d2e610c217 100644 --- a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/DisplayMeanArealPrecipResource.java +++ b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/DisplayMeanArealPrecipResource.java @@ -40,9 +40,9 @@ import org.geotools.coverage.grid.GridGeometry2D; import org.geotools.coverage.grid.InvalidGridGeometryException; import org.opengis.referencing.crs.CoordinateReferenceSystem; -import com.raytheon.uf.common.dataplugin.shef.tables.Colorvalue; import com.raytheon.uf.common.colormap.Color; import com.raytheon.uf.common.colormap.ColorMap; +import com.raytheon.uf.common.dataplugin.shef.tables.Colorvalue; import com.raytheon.uf.common.geospatial.MapUtil; import com.raytheon.uf.common.hydro.spatial.HRAPCoordinates; import com.raytheon.uf.common.hydro.spatial.HRAPSubGrid; @@ -375,9 +375,7 @@ public class DisplayMeanArealPrecipResource extends if (mode.contains(DisplayMode.Image)) { if (gridDisplay == null) { - gridDisplay = new GriddedImageDisplay2(buf2, gridGeometry, - this, target.getViewType()); - gridDisplay.init(target); + gridDisplay = new GriddedImageDisplay2(buf2, gridGeometry, this); } gridDisplay.paint(target, paintProps); diff --git a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/PlotGriddedPrecipResource.java b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/PlotGriddedPrecipResource.java index 4ceb7bc37b..675ecc61f3 100644 --- a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/PlotGriddedPrecipResource.java +++ b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/PlotGriddedPrecipResource.java @@ -479,9 +479,7 @@ public class PlotGriddedPrecipResource extends if (mode.contains(DisplayMode.Image)) { if (gridDisplay == null) { - gridDisplay = new GriddedImageDisplay2(buf, gridGeometry, this, - target.getViewType()); - gridDisplay.init(target); + gridDisplay = new GriddedImageDisplay2(buf, gridGeometry, this); // gridDisplay.setColorMapParameters(getCapability( // ColorMapCapability.class).getColorMapParameters()); } diff --git a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/PlotGriddedTempResource.java b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/PlotGriddedTempResource.java index 1bd05b9319..290f3bd526 100644 --- a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/PlotGriddedTempResource.java +++ b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/PlotGriddedTempResource.java @@ -452,9 +452,7 @@ public class PlotGriddedTempResource extends if (mode.contains(DisplayMode.Image)) { if (gridDisplay == null) { - gridDisplay = new GriddedImageDisplay2(buf, gridGeometry, this, - target.getViewType()); - gridDisplay.init(target); + gridDisplay = new GriddedImageDisplay2(buf, gridGeometry, this); // gridDisplay.setColorMapParameters(getCapability( // ColorMapCapability.class).getColorMapParameters()); } diff --git a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/TimeLapseResource.java b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/TimeLapseResource.java index 0a84e064fc..713dc29f0c 100644 --- a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/TimeLapseResource.java +++ b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/TimeLapseResource.java @@ -41,9 +41,9 @@ import org.eclipse.swt.graphics.RGB; import org.geotools.coverage.grid.GridGeometry2D; import org.opengis.referencing.crs.CoordinateReferenceSystem; -import com.raytheon.uf.common.dataplugin.shef.tables.Colorvalue; import com.raytheon.uf.common.colormap.Color; import com.raytheon.uf.common.colormap.ColorMap; +import com.raytheon.uf.common.dataplugin.shef.tables.Colorvalue; import com.raytheon.uf.common.geospatial.MapUtil; import com.raytheon.uf.common.hydro.spatial.HRAPCoordinates; import com.raytheon.uf.common.hydro.spatial.HRAPSubGrid; @@ -350,8 +350,7 @@ public class TimeLapseResource extends if (gridDisplay == null) { GriddedImageData dat = dataMap.get(displayedDate); gridDisplay = new GriddedImageDisplay2(dat.buff, dat.geometry, - this, target.getViewType()); - gridDisplay.init(target); + this); bufferMap.put(displayedDate, gridDisplay); // project(gridGeometry.getCoordinateReferenceSystem()); @@ -389,7 +388,7 @@ public class TimeLapseResource extends for (DataTime dTime : bufferMap.keySet()) { GriddedImageDisplay2 gDisplay = bufferMap.get(dTime); if (gDisplay != null) { - gDisplay.reproject(); + gDisplay.project(descriptor.getGridGeometry()); } } } diff --git a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/XmrgResource.java b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/XmrgResource.java index c54baac536..197ae8667a 100644 --- a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/XmrgResource.java +++ b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/XmrgResource.java @@ -122,7 +122,7 @@ public class XmrgResource extends private static final GeometryFactory gf = new GeometryFactory(); - private static final double MILLICVT = 25.4; + private static final double MILLICVT = 25.4; private XmrgFile xmrg; @@ -464,10 +464,7 @@ public class XmrgResource extends if (mode.contains(DisplayMode.Image)) { if (gridDisplay == null) { - gridDisplay = new GriddedImageDisplay2(buf, gridGeometry, this, - target.getViewType()); - gridDisplay.init(target); - + gridDisplay = new GriddedImageDisplay2(buf, gridGeometry, this); } GriddedImagePaintProperties giProps = new GriddedImagePaintProperties( @@ -582,11 +579,11 @@ public class XmrgResource extends } else if (s > 0 && s <= 24) { s = 0; } - if ((cv_use.equalsIgnoreCase("Locbias") || cv_use.equalsIgnoreCase("height") || cv_use.equalsIgnoreCase("locspan") || - tempsval == -1)) - { + if ((cv_use.equalsIgnoreCase("Locbias") + || cv_use.equalsIgnoreCase("height") + || cv_use.equalsIgnoreCase("locspan") || tempsval == -1)) { f = (float) parameters.getDataToDisplayConverter() - .convert(s); + .convert(s); } else { f = (float) (s / 100 / MILLICVT); } diff --git a/cave/com.raytheon.viz.skewT/src/com/raytheon/viz/skewt/SkewtDisplay.java b/cave/com.raytheon.viz.skewT/src/com/raytheon/viz/skewt/SkewtDisplay.java index 9b122d86ae..1f2ea4dd51 100644 --- a/cave/com.raytheon.viz.skewT/src/com/raytheon/viz/skewt/SkewtDisplay.java +++ b/cave/com.raytheon.viz.skewT/src/com/raytheon/viz/skewt/SkewtDisplay.java @@ -63,7 +63,6 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; import com.raytheon.uf.common.serialization.ISerializableObject; -import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.uf.viz.core.IGraphicsTarget; import com.raytheon.uf.viz.core.PixelExtent; import com.raytheon.uf.viz.core.VizConstants; @@ -324,8 +323,8 @@ public class SkewtDisplay extends AbstractRenderableDisplay implements } @Override - public void clear(IDisplayPane parentPane) { - super.clear(parentPane); + public void clear() { + super.clear(); IWorkbenchPage page = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); page.closeEditor(getEditor(), false); diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/UiUtil.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/UiUtil.java index 122c1dd8cd..6079521aeb 100644 --- a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/UiUtil.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/UiUtil.java @@ -339,9 +339,18 @@ public class UiUtil { } + /** + * Gets the currently active window + * + * @return + */ + public static IWorkbenchWindow getCurrentWindow() { + return VizWorkbenchManager.getInstance().getCurrentWindow(); + } + /** * Given the editor id and the renderable displays, create or open an editor - * with the given displays + * with the given displays on the active window * * @param editor * @param displays @@ -349,10 +358,28 @@ public class UiUtil { */ public static AbstractEditor createOrOpenEditor(String editor, IRenderableDisplay... displays) { + return createOrOpenEditor(getCurrentWindow(), editor, displays); + } + + /** + * Given the editor id and the renderable displays, create or open an editor + * with the given displays on the specified window + * + * @param windowToLoadTo + * @param editor + * @param displays + * @return the created or opened editor + */ + public static AbstractEditor createOrOpenEditor( + IWorkbenchWindow windowToLoadTo, String editor, + IRenderableDisplay... displays) { String editorName = (editor == null ? "com.raytheon.viz.ui.glmap.GLMapEditor" : editor); + if (windowToLoadTo == null) { + windowToLoadTo = getCurrentWindow(); + } // Check the current editor first - IEditorPart ep = EditorUtil.getActiveEditor(); + IEditorPart ep = EditorUtil.getActiveEditor(windowToLoadTo); if (ep instanceof AbstractEditor) { AbstractEditor currentEditor = (AbstractEditor) ep; if (currentEditor != null @@ -364,8 +391,7 @@ public class UiUtil { } } - IWorkbenchPage activePage = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow().getActivePage(); + IWorkbenchPage activePage = windowToLoadTo.getActivePage(); IEditorReference[] references = new IEditorReference[0]; if (activePage != null) { references = activePage.getEditorReferences(); @@ -374,18 +400,12 @@ public class UiUtil { for (IEditorReference ref : references) { if (editorName.equals(ref.getId())) { IEditorPart editorPart = ref.getEditor(false); - // IMultiPaneEditor multiPane = editorPart instanceof - // IMultiPaneEditor ? (IMultiPaneEditor) editorPart - // : null; if (editorPart instanceof AbstractEditor) { AbstractEditor aEditor = (AbstractEditor) editorPart; aEditor = makeCompatible(aEditor, displays); if (aEditor != null) { - - PlatformUI.getWorkbench().getActiveWorkbenchWindow() - .getActivePage().bringToTop(editorPart); + activePage.bringToTop(aEditor); return aEditor; - } } } @@ -393,7 +413,7 @@ public class UiUtil { // If we get here, the editor isn't there, or has a different number of // panes... construct it - return createEditor(editorName, displays); + return createEditor(windowToLoadTo, editorName, displays); } private static AbstractEditor makeCompatible(AbstractEditor currentEditor, @@ -428,7 +448,8 @@ public class UiUtil { } /** - * Given the editor id and displays, create the editor + * Opens a new editor with the specified displays on the currently active + * window * * @param editor * @param displays @@ -436,13 +457,28 @@ public class UiUtil { */ public static AbstractEditor createEditor(String editor, IRenderableDisplay... displays) { + return createEditor(getCurrentWindow(), editor, displays); + } + + /** + * Opens a new editor with the specified displays on the specified window + * + * @param windowToLoadTo + * @param editor + * @param displays + * @return + */ + public static AbstractEditor createEditor(IWorkbenchWindow windowToLoadTo, + String editor, IRenderableDisplay... displays) { String editorName = (editor == null ? "com.raytheon.viz.ui.glmap.GLMapEditor" : editor); + if (windowToLoadTo == null) { + windowToLoadTo = getCurrentWindow(); + } AbstractEditor aEditor = null; EditorInput cont = new EditorInput(displays); try { - IWorkbenchPage activePage = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow().getActivePage(); + IWorkbenchPage activePage = windowToLoadTo.getActivePage(); if (activePage != null) { aEditor = (AbstractEditor) activePage.openEditor(cont, editorName); diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/PaneManager.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/PaneManager.java index 2acb011996..bab3b5b57b 100644 --- a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/PaneManager.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/PaneManager.java @@ -512,9 +512,6 @@ public class PaneManager extends InputAdapter implements IMultiPaneEditor { registerHandlers(pane); } catch (VizException e) { statusHandler.handle(Priority.PROBLEM, "Error adding pane", e); - if (pane != null) { - pane.dispose(); - } } if (pane != null) { diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/VizDisplayPane.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/VizDisplayPane.java index 783764cb15..ecb872265a 100644 --- a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/VizDisplayPane.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/VizDisplayPane.java @@ -903,7 +903,7 @@ public class VizDisplayPane implements IDisplayPane { @Override public void clear() { - renderableDisplay.clear(this); + renderableDisplay.clear(); } /** diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/perspectives/AbstractVizPerspectiveManager.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/perspectives/AbstractVizPerspectiveManager.java index ad6665cf48..5636abbd62 100644 --- a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/perspectives/AbstractVizPerspectiveManager.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/perspectives/AbstractVizPerspectiveManager.java @@ -114,7 +114,7 @@ public abstract class AbstractVizPerspectiveManager implements if (mgr != null) { for (AbstractModalTool tool : mgr.getToolManager() .getSelectedModalTools()) { - if (tool != null) { + if (tool != null && tool.getCurrentEditor() != part) { tool.deactivate(); tool.setEditor((IDisplayPaneContainer) part); tool.activate(); diff --git a/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/FileLocker.java b/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/FileLocker.java index 5cc0038443..498b777666 100644 --- a/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/FileLocker.java +++ b/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/FileLocker.java @@ -172,88 +172,90 @@ public class FileLocker { if (file.isDirectory()) { return false; } - try { - // Get executing thread - Thread myThread = Thread.currentThread(); - LockedFile lock = null; - // synchronize on the locks map while operating on map - synchronized (locks) { - lock = locks.get(file); - if (lock == null) { - // New lock, allocate and add and return - lock = allocateLock(locker, file, type, myThread); - locks.put(file, lock); - return true; + // Get executing thread + Thread myThread = Thread.currentThread(); + LockedFile lock = null; + // synchronize on the locks map while operating on map + + boolean grabbedLock = false; + synchronized (locks) { + lock = locks.get(file); + if (lock == null) { + lock = new LockedFile(); + locks.put(file, lock); + grabbedLock = true; + } + } + + synchronized (lock) { + if (grabbedLock) { + // We were able to grab the lock file ourselves + return allocateLock(locker, file, type, myThread, lock); + } else if (lock.lockingThread == myThread + || (type == lock.lockType && type == Type.READ)) { + // Locked on same thread to avoid indefinite waiting. If + // there are issues on how locked, they will be known + lock.lockers.add(locker); + return true; + } + } + + // Should not reach this point when block = false + if (block) { + // Wait for lock to be released + LockWaiter waiter = new LockWaiter(); + Deque lws = null; + // become a waiter on the file, ensures when file is unlocked by + // other Thread, they don't delete the lock file + synchronized (waiters) { + lws = waiters.get(file); + if (lws == null) { + lws = new ArrayDeque(); + waiters.put(file, lws); } + lws.add(waiter); } - // File is currently locked, check for Thread compatibility - // Synchronize on the lock while checking lock - synchronized (lock) { - if (lock.lockingThread == myThread - || (type == lock.lockType && type == Type.READ)) { - // Locked on same thread to avoid indefinite waiting. If - // there are issues on how locked, they will be known - lock.lockers.add(locker); - return true; - } - } - - // Should not reach this point when block = false - if (block) { - // Wait for lock to be released - LockWaiter waiter = new LockWaiter(); - Deque lws = null; - // become a waiter on the file - synchronized (waiters) { - lws = waiters.get(file); - if (lws == null) { - lws = new ArrayDeque(); - waiters.put(file, lws); - } - lws.add(waiter); + while (true) { + // Sleep + try { + Thread.sleep(10); + } catch (InterruptedException e) { + // Ignore } - while (true) { - // Sleep - try { - Thread.sleep(10); - } catch (InterruptedException e) { - // Ignore - } - - synchronized (locks) { - lock = locks.get(file); - if (lock == null) { - // File ready for grabbing - synchronized (lws) { - if (lws.peek() == waiter) { - lws.poll(); - return lockInternal(locker, file, type, - false); - } + grabbedLock = false; + synchronized (locks) { + lock = locks.get(file); + if (lock == null) { + // File ready for grabbing + synchronized (lws) { + if (lws.peek() == waiter) { + lws.poll(); + lock = new LockedFile(); + locks.put(file, lock); + grabbedLock = true; } - } else { - synchronized (lock) { - if (lock.lockFile.exists() == false - || (System.currentTimeMillis() - - lock.lockFile.lastModified() > MAX_WAIT)) { - System.err - .println("Releasing lock since: " - + (lock.lockFile.exists() ? "Lock has been allocated for more than " - + (MAX_WAIT / 1000) - + "s" - : "Lock file no longer exists!")); - locks.remove(file); - } + } + } else if (lock.lockFile != null) { + synchronized (lock) { + if ((System.currentTimeMillis() - lock.lockFile + .lastModified()) > MAX_WAIT) { + System.err + .println("Releasing lock since: " + + "Lock has been allocated for more than " + + (MAX_WAIT / 1000) + "s"); + locks.remove(file); } } } } + if (grabbedLock) { + // We were able to grab the lock file ourselves + allocateLock(locker, file, type, myThread, lock); + return true; + } } - } catch (Throwable t) { - UFStatus.getHandler().handle(Priority.PROBLEM, - "Error locking file: " + file, t); } return false; } @@ -313,10 +315,8 @@ public class FileLocker { * @throws FileNotFoundException * @throws IOException */ - private synchronized LockedFile allocateLock(Object locker, File file, - Type type, Thread thread) throws FileNotFoundException, IOException { - LockedFile lock = new LockedFile(); - + private boolean allocateLock(Object locker, File file, Type type, + Thread thread, LockedFile lock) { // Set tht thread of the lock and add lock allocator lock.lockingThread = Thread.currentThread(); lock.lockers.add(locker); @@ -327,22 +327,27 @@ public class FileLocker { // If we can't write to the parent directory of the file we are locking, // can't do any locking if (parentDir.canWrite() == false) { - return lock; + return false; } + boolean gotLock = false; File lockFile = new File(parentDir, "." + file.getName() + "_LOCK"); - boolean gotLock = lockFile.createNewFile(); - if (!gotLock) { - long waitInterval = 500; - long tryCount = MAX_WAIT / waitInterval; - for (int i = 0; !gotLock && i < tryCount; ++i) { - try { - Thread.sleep(waitInterval); - } catch (InterruptedException e) { - // Ignore + try { + gotLock = lockFile.createNewFile(); + if (!gotLock) { + long waitInterval = 500; + long tryCount = MAX_WAIT / waitInterval; + for (int i = 0; !gotLock && i < tryCount; ++i) { + try { + Thread.sleep(waitInterval); + } catch (InterruptedException e) { + // Ignore + } + gotLock = lockFile.createNewFile(); } - gotLock = lockFile.createNewFile(); } + } catch (IOException e) { + e.printStackTrace(); } if (!gotLock) { @@ -351,11 +356,10 @@ public class FileLocker { Thread.dumpStack(); } lock.lockFile = lockFile; - return lock; + return gotLock; } - private synchronized void unallocateLock(LockedFile lock) - throws IOException { + private void unallocateLock(LockedFile lock) throws IOException { if (lock.lockFile != null) { lock.lockFile.delete(); }