Merge "VLab Issue #5421 - Capture frames with date and time in file name" into field_14.4.1

Former-commit-id: 703b8197de [formerly a2bf9ed474 [formerly 2a888aa22e77a3069b4ee88d7c9ebbaae2e90524]]
Former-commit-id: a2bf9ed474
Former-commit-id: 11f5ee56be
This commit is contained in:
Ana Rivera 2014-12-12 20:41:08 +00:00 committed by Gerrit Code Review
commit fa94f95d1e
7 changed files with 172 additions and 61 deletions

View file

@ -7,6 +7,7 @@ Bundle-Vendor: RAYTHEON
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Require-Bundle: com.raytheon.uf.viz.core;bundle-version="1.14.0", Require-Bundle: com.raytheon.uf.viz.core;bundle-version="1.14.0",
com.raytheon.viz.core.graphing,
com.raytheon.viz.ui;bundle-version="1.14.0", com.raytheon.viz.ui;bundle-version="1.14.0",
gov.noaa.nws.ncep.ui.nsharp, gov.noaa.nws.ncep.ui.nsharp,
com.raytheon.uf.common.sounding, com.raytheon.uf.common.sounding,

View file

@ -24,9 +24,10 @@ import gov.noaa.nws.ncep.ui.nsharp.display.NsharpEditor;
import gov.noaa.nws.ncep.ui.nsharp.display.rsc.NsharpResourceHandler; import gov.noaa.nws.ncep.ui.nsharp.display.rsc.NsharpResourceHandler;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.Calendar;
import java.util.List; import java.util.LinkedHashMap;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.uf.viz.core.IDisplayPane;
import com.raytheon.uf.viz.core.datastructure.LoopProperties; import com.raytheon.uf.viz.core.datastructure.LoopProperties;
import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.exception.VizException;
@ -40,58 +41,68 @@ import com.raytheon.viz.ui.editor.AbstractEditor;
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Jul 26, 2006 chammack Initial Creation. * Unknown bsteffen Initial creation
* Unknown cchen Modifications
* Dec 8, 2014 DR16713 jgerth Incorporate date and time
* *
* </pre> * </pre>
* *
* @author chammack * @author bsteffen
* @version 1 * @version 1
*/ */
public class NSharpSaveScreenAction extends ExportImageHandler { public class NSharpSaveScreenAction extends ExportImageHandler {
@Override @Override
protected BufferedImage captureCurrentFrames(AbstractEditor editor) { protected LinkedHashMap<DataTime, BufferedImage> captureCurrentFrames(AbstractEditor editor) {
return editor.getActiveDisplayPane().getTarget().screenshot(); NsharpResourceHandler handler = ((NsharpEditor) editor).getRscHandler();
LinkedHashMap<DataTime, BufferedImage> dtbiHash = new LinkedHashMap<DataTime, BufferedImage>();
DataTime[] dataTimes = handler.getSkewtPaneRsc().getDescriptor().getFramesInfo().getFrameTimes();
if (dataTimes == null || dataTimes.length == 0) {
dtbiHash.put(buildFakeTime(0), editor.getActiveDisplayPane().getTarget().screenshot());
} else {
dtbiHash.put(dataTimes[handler.getCurrentIndex()], editor.getActiveDisplayPane().getTarget().screenshot());
}
return dtbiHash;
} }
@Override @Override
protected List<BufferedImage> captureAllFrames(AbstractEditor editor) protected LinkedHashMap<DataTime, BufferedImage> captureAllFrames(AbstractEditor editor)
throws VizException { throws VizException {
if(!(editor instanceof NsharpEditor)){ if(!(editor instanceof NsharpEditor)){
return super.captureAllFrames(editor); return super.captureAllFrames(editor);
} }
NsharpResourceHandler handler = ((NsharpEditor) editor).getRscHandler(); NsharpResourceHandler handler = ((NsharpEditor) editor).getRscHandler();
int startIndex = 0; int startIndex = 0;
int endIndex = handler .getFrameCount(); // Chin NsharpFrameIndexUtil.getFrameCount(handler); int endIndex = handler.getFrameCount();
return captureFrames(editor, startIndex, endIndex); return captureFrames(editor, startIndex, endIndex);
} }
@Override @Override
protected List<BufferedImage> captureFrames(AbstractEditor editor, protected LinkedHashMap<DataTime, BufferedImage> captureFrames(AbstractEditor editor,
int startIndex, int endIndex) throws VizException { int startIndex, int endIndex) throws VizException {
if(!(editor instanceof NsharpEditor)){ if(!(editor instanceof NsharpEditor)){
return super.captureFrames(editor, startIndex, endIndex); return super.captureFrames(editor, startIndex, endIndex);
} }
LinkedHashMap<DataTime, BufferedImage> dtbiHash = new LinkedHashMap<DataTime, BufferedImage>();
IDisplayPane pane = editor.getActiveDisplayPane(); IDisplayPane pane = editor.getActiveDisplayPane();
NsharpResourceHandler handler = ((NsharpEditor) editor).getRscHandler(); NsharpResourceHandler handler = ((NsharpEditor) editor).getRscHandler();
// save the frame we are on; // save the frame we are on;
int startingIndex = handler.getCurrentIndex(); // Chin NsharpFrameIndexUtil.getCurrentIndex(handler); int startingIndex = handler.getCurrentIndex();
List<BufferedImage> images = new ArrayList<BufferedImage>(); LoopProperties loopProperties = ((AbstractEditor) editor).getLoopProperties();
LoopProperties loopProperties = ((AbstractEditor) editor)
.getLoopProperties();
renderPane(pane, loopProperties); renderPane(pane, loopProperties);
DataTime[] dataTimes = handler.getSkewtPaneRsc().getDescriptor().getFramesInfo().getFrameTimes();
for (int i = startIndex; i < endIndex; i++) { for (int i = startIndex; i < endIndex; i++) {
//Chin NsharpFrameIndexUtil.setCurrentIndex(handler, i); if (handler.setCurrentIndex(i) == false) {
if(handler.setCurrentIndex(i)== false) continue;
continue; }
pane.refresh(); pane.refresh();
renderPane(pane, loopProperties); renderPane(pane, loopProperties);
images.add(captureCurrentFrames(editor)); dtbiHash.put(dataTimes[i], editor.getActiveDisplayPane().getTarget().screenshot());
} }
handler.setCurrentIndex(startingIndex); // Chin NsharpFrameIndexUtil.setCurrentIndex(handler, startingIndex); handler.setCurrentIndex(startingIndex);
pane.refresh(); pane.refresh();
renderPane(pane, loopProperties); renderPane(pane, loopProperties);
return images; return dtbiHash;
} }
} }

View file

@ -39,6 +39,7 @@ import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.viz.image.export.options.ImageExportOptions; import com.raytheon.uf.viz.image.export.options.ImageExportOptions;
import com.raytheon.uf.viz.image.export.options.ImageExportOptions.DateTimeSelection;
import com.raytheon.uf.viz.image.export.options.ImageExportOptions.FrameSelection; import com.raytheon.uf.viz.image.export.options.ImageExportOptions.FrameSelection;
import com.raytheon.uf.viz.image.export.options.ImageExportOptions.ImageFormat; import com.raytheon.uf.viz.image.export.options.ImageExportOptions.ImageFormat;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog; import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
@ -54,6 +55,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* ------------- -------- ----------- -------------------------- * ------------- -------- ----------- --------------------------
* Jan 20, 2014 2312 bsteffen Initial creation * Jan 20, 2014 2312 bsteffen Initial creation
* Mar 10, 2014 2867 bsteffen Better frame range validation. * Mar 10, 2014 2867 bsteffen Better frame range validation.
* Dec 4, 2014 DR16713 jgerth Support for date/time selection
* *
* </pre> * </pre>
* *
@ -67,6 +69,8 @@ public class ImageExportDialog extends CaveSWTDialog {
protected Text locationText; protected Text locationText;
protected Button datetimeButton;
protected Button selectedFramesButton; protected Button selectedFramesButton;
protected Button currentFramesButton; protected Button currentFramesButton;
@ -132,6 +136,13 @@ public class ImageExportDialog extends CaveSWTDialog {
selectDestinationFile(); selectDestinationFile();
} }
}); });
datetimeButton = new Button(group, SWT.CHECK);
datetimeButton.setLayoutData(gridData);
datetimeButton.setText("Include date and time in file name");
datetimeButton
.setSelection(options.getDateTimeSelection() == DateTimeSelection.DATETIME);
datetimeButton
.setToolTipText("Append the date and time to the file name when Animate is not selected.");
} }
protected void initializeFramesGroup(Group group) { protected void initializeFramesGroup(Group group) {
@ -209,6 +220,9 @@ public class ImageExportDialog extends CaveSWTDialog {
frameDelayText.setEnabled(animatedButton.getSelection()); frameDelayText.setEnabled(animatedButton.getSelection());
firstFrameDwellText.setEnabled(animatedButton.getSelection()); firstFrameDwellText.setEnabled(animatedButton.getSelection());
lastFrameDwellText.setEnabled(animatedButton.getSelection()); lastFrameDwellText.setEnabled(animatedButton.getSelection());
datetimeButton.setEnabled(!animatedButton.getSelection());
datetimeButton.setSelection(false);
} }
}); });
gridData = new GridData(); gridData = new GridData();
@ -362,6 +376,9 @@ public class ImageExportDialog extends CaveSWTDialog {
} else { } else {
options.setImageFormat(ImageFormat.SEQUENCE); options.setImageFormat(ImageFormat.SEQUENCE);
} }
if (datetimeButton.getSelection()) {
options.setDateTimeSelection(DateTimeSelection.DATETIME);
}
if (validate()) { if (validate()) {
setReturnValue(options); setReturnValue(options);
close(); close();

View file

@ -20,12 +20,13 @@
package com.raytheon.uf.viz.image.export.handler; package com.raytheon.uf.viz.image.export.handler;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.Calendar;
import java.util.List; import java.util.LinkedHashMap;
import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Rectangle;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.uf.viz.core.IDisplayPane;
import com.raytheon.uf.viz.core.IDisplayPaneContainer; import com.raytheon.uf.viz.core.IDisplayPaneContainer;
import com.raytheon.uf.viz.core.IGraphicsTarget; import com.raytheon.uf.viz.core.IGraphicsTarget;
@ -53,6 +54,7 @@ import com.raytheon.viz.ui.editor.AbstractEditor;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------- -------- ----------- -------------------------- * ------------- -------- ----------- --------------------------
* Jan 20, 2014 2312 bsteffen Move to image export plugin. * Jan 20, 2014 2312 bsteffen Move to image export plugin.
* Dec 4, 2014 DR16713 jgerth Incorporate date and time
* *
* </pre> * </pre>
* *
@ -61,11 +63,18 @@ import com.raytheon.viz.ui.editor.AbstractEditor;
*/ */
public abstract class AbstractImageCaptureHandler extends AbstractHandler { public abstract class AbstractImageCaptureHandler extends AbstractHandler {
protected BufferedImage captureCurrentFrames(AbstractEditor editor) { protected LinkedHashMap<DataTime, BufferedImage> captureCurrentFrames(AbstractEditor editor) {
return editor.screenshot(); LinkedHashMap<DataTime, BufferedImage> dtbiHash = new LinkedHashMap<DataTime, BufferedImage>();
DataTime[] dataTimes = editor.getActiveDisplayPane().getDescriptor().getFramesInfo().getFrameTimes();
if (dataTimes == null || dataTimes.length == 0) {
dtbiHash.put(buildFakeTime(0), editor.screenshot());
} else {
dtbiHash.put(dataTimes[editor.getActiveDisplayPane().getDescriptor().getFramesInfo().getFrameIndex()], editor.screenshot());
}
return dtbiHash;
} }
protected List<BufferedImage> captureAllFrames(AbstractEditor editor) protected LinkedHashMap<DataTime, BufferedImage> captureAllFrames(AbstractEditor editor)
throws VizException { throws VizException {
int startIndex = 0; int startIndex = 0;
int endIndex = editor.getActiveDisplayPane().getDescriptor() int endIndex = editor.getActiveDisplayPane().getDescriptor()
@ -76,28 +85,31 @@ public abstract class AbstractImageCaptureHandler extends AbstractHandler {
return captureFrames(editor, startIndex, endIndex); return captureFrames(editor, startIndex, endIndex);
} }
protected List<BufferedImage> captureFrames(AbstractEditor editor, protected LinkedHashMap<DataTime, BufferedImage> captureFrames(AbstractEditor editor,
int startIndex, int endIndex) throws VizException { int startIndex, int endIndex) throws VizException {
LinkedHashMap<DataTime, BufferedImage> dtbiHash = new LinkedHashMap<DataTime, BufferedImage>();
if (startIndex < 0) { if (startIndex < 0) {
startIndex = 0; startIndex = 0;
} }
List<BufferedImage> images = new ArrayList<BufferedImage>(endIndex int origIndex = editor.getActiveDisplayPane().getDescriptor().getFramesInfo().getFrameIndex();
- startIndex); DataTime[] dataTimes = editor.getActiveDisplayPane().getDescriptor().getFramesInfo().getFrameTimes();
int origIndex = editor.getActiveDisplayPane().getDescriptor()
.getFramesInfo().getFrameIndex();
for (int i = startIndex; i < endIndex; i++) { for (int i = startIndex; i < endIndex; i++) {
for (IDisplayPane pane : editor.getDisplayPanes()) { for (IDisplayPane pane : editor.getDisplayPanes()) {
setFrameIndex(pane.getDescriptor(), i); setFrameIndex(pane.getDescriptor(), i);
pane.refresh(); pane.refresh();
renderPane(pane, editor.getLoopProperties()); renderPane(pane, editor.getLoopProperties());
} }
images.add(editor.screenshot()); if (dataTimes != null && dataTimes.length > 0) {
dtbiHash.put(dataTimes[i], editor.screenshot());
} else {
dtbiHash.put(buildFakeTime(i), editor.screenshot());
}
} }
for (IDisplayPane pane : editor.getDisplayPanes()) { for (IDisplayPane pane : editor.getDisplayPanes()) {
setFrameIndex(pane.getDescriptor(), origIndex); setFrameIndex(pane.getDescriptor(), origIndex);
pane.refresh(); pane.refresh();
} }
return images; return dtbiHash;
} }
private void setFrameIndex(IDescriptor desc, int index) { private void setFrameIndex(IDescriptor desc, int index) {
@ -136,6 +148,20 @@ public abstract class AbstractImageCaptureHandler extends AbstractHandler {
} }
} }
/**
* Build a fake time when a time is not associated with a frame. The fake
* time is the number of milliseconds since the Epoch based on the integer
* frame number.
*
* @param the frame number
* @return the fake DataTime based on the frame number
*/
protected DataTime buildFakeTime(int i) {
Calendar c = TimeUtil.newGmtCalendar();
c.setTimeInMillis(i);
return new DataTime(c);
}
@Override @Override
public void setEnabled(Object obj) { public void setEnabled(Object obj) {
IDisplayPaneContainer container = EditorUtil.getActiveVizContainer(); IDisplayPaneContainer container = EditorUtil.getActiveVizContainer();

View file

@ -23,9 +23,15 @@ package com.raytheon.uf.viz.image.export.handler;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import javax.imageio.IIOImage; import javax.imageio.IIOImage;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
@ -53,9 +59,11 @@ import org.w3c.dom.Node;
import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.image.export.dialog.ImageExportDialog; import com.raytheon.uf.viz.image.export.dialog.ImageExportDialog;
import com.raytheon.uf.viz.image.export.options.ImageExportOptions; import com.raytheon.uf.viz.image.export.options.ImageExportOptions;
import com.raytheon.uf.viz.image.export.options.ImageExportOptions.DateTimeSelection;
import com.raytheon.uf.viz.image.export.options.ImageExportOptions.FrameSelection; import com.raytheon.uf.viz.image.export.options.ImageExportOptions.FrameSelection;
import com.raytheon.uf.viz.image.export.options.ImageExportOptions.ImageFormat; import com.raytheon.uf.viz.image.export.options.ImageExportOptions.ImageFormat;
import com.raytheon.viz.ui.EditorUtil; import com.raytheon.viz.ui.EditorUtil;
@ -70,6 +78,7 @@ import com.raytheon.viz.ui.editor.AbstractEditor;
* ------------- -------- ----------- -------------------------- * ------------- -------- ----------- --------------------------
* Jul 26, 2006 chammack Initial Creation. * Jul 26, 2006 chammack Initial Creation.
* Jan 20, 2014 2312 bsteffen Move to image export plugin, animation. * Jan 20, 2014 2312 bsteffen Move to image export plugin, animation.
* Dec 4, 2014 DR16713 jgerth Support for date and time in file name
* *
* </pre> * </pre>
* *
@ -80,6 +89,8 @@ public class ExportImageHandler extends AbstractImageCaptureHandler {
private static final transient IUFStatusHandler statusHandler = UFStatus private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(ExportImageHandler.class); .getHandler(ExportImageHandler.class);
private static final String DATE_TIME_FORMAT = "yyyyMMdd_HHmmss";
@Override @Override
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart part = EditorUtil.getActiveEditor(); IEditorPart part = EditorUtil.getActiveEditor();
@ -138,17 +149,17 @@ public class ExportImageHandler extends AbstractImageCaptureHandler {
} }
} }
List<BufferedImage> images = null; LinkedHashMap<DataTime, BufferedImage> dtbiHash = new LinkedHashMap<DataTime, BufferedImage>();
try { try {
switch (options.getFrameSelection()) { switch (options.getFrameSelection()) {
case CURRENT: case CURRENT:
images = Arrays.asList(captureCurrentFrames(editor)); dtbiHash = captureCurrentFrames(editor);
break; break;
case ALL: case ALL:
images = captureAllFrames(editor); dtbiHash = captureAllFrames(editor);
break; break;
case USER: case USER:
images = captureFrames(editor, options.getFirstFrameIndex(), dtbiHash = captureFrames(editor, options.getFirstFrameIndex(),
options.getLastFrameIndex()); options.getLastFrameIndex());
break; break;
} }
@ -158,8 +169,8 @@ public class ExportImageHandler extends AbstractImageCaptureHandler {
return null; return null;
} }
if (!images.isEmpty()) { if (!dtbiHash.isEmpty()) {
new SaveImageJob(options, images); new SaveImageJob(options, dtbiHash);
} }
return null; return null;
} }
@ -175,10 +186,14 @@ public class ExportImageHandler extends AbstractImageCaptureHandler {
} }
public void saveImages(IProgressMonitor monitor, public void saveImages(IProgressMonitor monitor,
ImageExportOptions options, List<BufferedImage> images) { ImageExportOptions options, Map<DataTime, BufferedImage> dtbiHash) {
monitor.beginTask("Saving Images", images.size()); monitor.beginTask("Saving Images", dtbiHash.size());
String path = options.getFileLocation().getAbsolutePath(); String path = options.getFileLocation().getAbsolutePath();
String ppath = path;
SimpleDateFormat sdf = new SimpleDateFormat(DATE_TIME_FORMAT);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
NumberFormat twoDigit = new DecimalFormat("00");
String suffix = path.substring(path.lastIndexOf('.') + 1); String suffix = path.substring(path.lastIndexOf('.') + 1);
String basePath = path.substring(0, path.lastIndexOf('.')); String basePath = path.substring(0, path.lastIndexOf('.'));
@ -192,33 +207,47 @@ public class ExportImageHandler extends AbstractImageCaptureHandler {
FileImageOutputStream stream = null; FileImageOutputStream stream = null;
try { try {
if (images.size() == 1) { if (options.getImageFormat() == ImageFormat.SEQUENCE) {
stream = new FileImageOutputStream(options.getFileLocation()); int i = 0;
writer.setOutput(stream); for (Map.Entry<DataTime, BufferedImage> entry : dtbiHash.entrySet()) {
writer.write(images.get(0)); i++;
stream.close(); BufferedImage bi = entry.getValue();
stream = null; if (options.getDateTimeSelection() == DateTimeSelection.DATETIME) {
monitor.worked(1); DataTime key = entry.getKey();
} else if (options.getImageFormat() == ImageFormat.SEQUENCE) { Date validTime = key.getValidTimeAsDate();
for (int i = 0; i < images.size(); i++) { if (validTime != null && !isFakeTime(key)) {
BufferedImage bi = images.get(i); path = basePath + "-" + sdf.format(validTime) + "." + suffix;
/* Allow GC to collect image after write. */ if (path.equals(ppath)) {
images.set(i, null); path = basePath + "-" + sdf.format(validTime) + "-" + twoDigit.format(i).toString() + "." + suffix;
path = basePath + "-" + (i + 1) + "." + suffix; }
} else {
path = basePath + "-" + twoDigit.format(i).toString() + "." + suffix;
}
} else if (dtbiHash.size() > 1) {
path = basePath + "-" + twoDigit.format(i).toString() + "." + suffix;
} else {
path = basePath + "." + suffix;
}
ppath = path;
stream = new FileImageOutputStream(new File(path)); stream = new FileImageOutputStream(new File(path));
writer.setOutput(stream); writer.setOutput(stream);
writer.write(bi); writer.write(bi);
stream.close(); stream.close();
stream = null; stream = null;
if (monitor.isCanceled()) { if (monitor.isCanceled()) {
dtbiHash.clear();
break; break;
} }
monitor.worked(1); monitor.worked(1);
} }
dtbiHash.clear();
} else if (options.getImageFormat() == ImageFormat.ANIMATION) { } else if (options.getImageFormat() == ImageFormat.ANIMATION) {
stream = new FileImageOutputStream(options.getFileLocation()); stream = new FileImageOutputStream(options.getFileLocation());
writer.setOutput(stream); writer.setOutput(stream);
writer.prepareWriteSequence(null); writer.prepareWriteSequence(null);
List<BufferedImage> images = new ArrayList<BufferedImage>();
images.addAll(dtbiHash.values());
dtbiHash.clear();
for (int i = 0; i < images.size(); i++) { for (int i = 0; i < images.size(); i++) {
BufferedImage bi = images.get(i); BufferedImage bi = images.get(i);
/* Allow GC to collect image after write. */ /* Allow GC to collect image after write. */
@ -229,14 +258,12 @@ public class ExportImageHandler extends AbstractImageCaptureHandler {
if (i == 0) { if (i == 0) {
configureAnimation(metadata, configureAnimation(metadata,
options.getFirstFrameDwell(), true); options.getFirstFrameDwell(), true);
} else if (i == images.size() - 1) { } else if (i == images.size() - 1) {
configureAnimation(metadata, configureAnimation(metadata,
options.getLastFrameDwell(), false); options.getLastFrameDwell(), false);
} else { } else {
configureAnimation(metadata, options.getFrameDelay(), configureAnimation(metadata, options.getFrameDelay(),
false); false);
} }
IIOImage ii = new IIOImage(bi, null, metadata); IIOImage ii = new IIOImage(bi, null, metadata);
writer.writeToSequence(ii, null); writer.writeToSequence(ii, null);
@ -313,23 +340,36 @@ public class ExportImageHandler extends AbstractImageCaptureHandler {
} }
/**
* There may be cases in which a valid time is not associated with a frame.
* In such cases, a valid time is set to a number of milliseconds from the
* Epoch time based on the frame number. Here we check if that is one of
* those such cases.
*
* @param a DataTime
* @return true if the DataTime is close to the Epoch time
*/
public boolean isFakeTime(DataTime dt) {
return dt.getValidTime().getTimeInMillis() < 1000;
}
protected class SaveImageJob extends Job { protected class SaveImageJob extends Job {
protected final ImageExportOptions options; protected final ImageExportOptions options;
protected final List<BufferedImage> images; protected final LinkedHashMap<DataTime, BufferedImage> dtbiHash;
protected SaveImageJob(ImageExportOptions options, protected SaveImageJob(ImageExportOptions options,
List<BufferedImage> images) { LinkedHashMap<DataTime, BufferedImage> dtbiHash) {
super("Saving image"); super("Saving image");
this.options = options; this.options = options;
this.images = images; this.dtbiHash = dtbiHash;
this.schedule(); this.schedule();
} }
@Override @Override
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
saveImages(monitor, options, images); saveImages(monitor, options, dtbiHash);
return Status.OK_STATUS; return Status.OK_STATUS;
} }

View file

@ -61,6 +61,7 @@ import com.raytheon.viz.ui.editor.AbstractEditor;
* Aug 08, 2008 703 randerso fixed bug, changed to scale to fit paper * Aug 08, 2008 703 randerso fixed bug, changed to scale to fit paper
* and rotate if necessary * and rotate if necessary
* Jan 20, 2014 2312 bsteffen Move to image export plugin. * Jan 20, 2014 2312 bsteffen Move to image export plugin.
* Dec 4, 2014 DR16713 jgerth Support for date and time in file name
* *
* </pre> * </pre>
* *
@ -116,7 +117,7 @@ public class PrintImageCaptureHandler extends AbstractImageCaptureHandler {
switch (pd.getScope()) { switch (pd.getScope()) {
case PrinterData.ALL_PAGES: { case PrinterData.ALL_PAGES: {
try { try {
for (BufferedImage bi : captureAllFrames(editor)) { for (BufferedImage bi : captureAllFrames(editor).values()) {
printImage(printer, display, bi); printImage(printer, display, bi);
} }
} catch (VizException e) { } catch (VizException e) {
@ -128,7 +129,7 @@ public class PrintImageCaptureHandler extends AbstractImageCaptureHandler {
case PrinterData.PAGE_RANGE: { case PrinterData.PAGE_RANGE: {
try { try {
for (BufferedImage bi : captureFrames(editor, for (BufferedImage bi : captureFrames(editor,
pd.getStartPage() - 1, pd.getEndPage())) { pd.getStartPage() - 1, pd.getEndPage()).values()) {
printImage(printer, display, bi); printImage(printer, display, bi);
} }
} catch (VizException e) { } catch (VizException e) {

View file

@ -37,6 +37,7 @@ import com.raytheon.uf.viz.core.datastructure.LoopProperties;
* ------------- -------- ----------- -------------------------- * ------------- -------- ----------- --------------------------
* Jan 20, 2014 2312 bsteffen Initial creation * Jan 20, 2014 2312 bsteffen Initial creation
* Mar 10, 2014 2867 bsteffen Better frame range validation. * Mar 10, 2014 2867 bsteffen Better frame range validation.
* Dec 4, 2014 DR16713 jgerth Support for date/time selection
* *
* </pre> * </pre>
* *
@ -46,6 +47,10 @@ import com.raytheon.uf.viz.core.datastructure.LoopProperties;
public class ImageExportOptions { public class ImageExportOptions {
public static enum DateTimeSelection {
DATETIME, SEQUENTIAL;
}
public static enum FrameSelection { public static enum FrameSelection {
ALL, CURRENT, USER; ALL, CURRENT, USER;
} }
@ -85,6 +90,8 @@ public class ImageExportOptions {
private FrameSelection frameSelection = FrameSelection.CURRENT; private FrameSelection frameSelection = FrameSelection.CURRENT;
private DateTimeSelection dateTimeSelection = DateTimeSelection.SEQUENTIAL;
private int firstFrameIndex = 0; private int firstFrameIndex = 0;
private int lastFrameIndex = 0; private int lastFrameIndex = 0;
@ -118,6 +125,14 @@ public class ImageExportOptions {
this.imageFormat = imageFormat; this.imageFormat = imageFormat;
} }
public DateTimeSelection getDateTimeSelection() {
return dateTimeSelection;
}
public void setDateTimeSelection(DateTimeSelection dts) {
this.dateTimeSelection = dts;
}
public FrameSelection getFrameSelection() { public FrameSelection getFrameSelection() {
return frameSelection; return frameSelection;
} }