Issue #235 Added ability to capture multiple frames to NSharp
Change-Id: Ib6ab3acff6d9357679f4116493c1d3a97b57c2cc Former-commit-id:5cdcd5a261
[formerly5cdcd5a261
[formerly 447253e7cd0ea5ab64c020a4fe0822ffc3a01d3f]] Former-commit-id:6bfd8ccfee
Former-commit-id:512e0f1bd5
This commit is contained in:
parent
6164ad39b6
commit
e1eeef7827
7 changed files with 548 additions and 186 deletions
|
@ -34,6 +34,7 @@ Import-Package: com.raytheon.uf.common.dataplugin,
|
|||
com.raytheon.uf.viz.d2d.core.time,
|
||||
com.raytheon.viz.core.graphing,
|
||||
com.raytheon.viz.ui,
|
||||
com.raytheon.viz.ui.actions,
|
||||
com.raytheon.viz.ui.dialogs,
|
||||
com.raytheon.viz.ui.editor,
|
||||
com.raytheon.viz.ui.perspectives,
|
||||
|
@ -50,6 +51,7 @@ Import-Package: com.raytheon.uf.common.dataplugin,
|
|||
gov.noaa.nws.ncep.ui.nsharp.skewt.bkgd,
|
||||
gov.noaa.nws.ncep.ui.nsharp.skewt.rsc,
|
||||
gov.noaa.nws.ncep.viz.common.soundingQuery,
|
||||
gov.noaa.nws.ncep.viz.ui.display,
|
||||
javax.measure.converter,
|
||||
javax.measure.unit,
|
||||
org.eclipse.core.commands,
|
||||
|
@ -57,6 +59,7 @@ Import-Package: com.raytheon.uf.common.dataplugin,
|
|||
org.eclipse.swt,
|
||||
org.eclipse.swt.graphics,
|
||||
org.eclipse.swt.layout,
|
||||
org.eclipse.swt.printing,
|
||||
org.eclipse.swt.widgets,
|
||||
org.eclipse.ui,
|
||||
org.eclipse.ui.part,
|
||||
|
|
|
@ -31,4 +31,27 @@
|
|||
visible="false"/>
|
||||
</perspectiveExtension>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.handlers">
|
||||
<handler
|
||||
class="com.raytheon.uf.viz.d2d.nsharp.rsc.action.NSharpSaveScreenAction"
|
||||
commandId="com.raytheon.viz.ui.actions.saveScreen">
|
||||
<activeWhen>
|
||||
<with variable="activeEditorId">
|
||||
<equals value="gov.noaa.nws.ncep.ui.nsharp.skewt.NsharpSkewTEditor"/>
|
||||
</with>
|
||||
</activeWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="com.raytheon.uf.viz.d2d.nsharp.rsc.action.NSharpPrintScreenAction"
|
||||
commandId="com.raytheon.viz.ui.actions.printScreenAction">
|
||||
<activeWhen>
|
||||
<with variable="activeEditorId">
|
||||
<equals value="gov.noaa.nws.ncep.ui.nsharp.skewt.NsharpSkewTEditor"/>
|
||||
</with>
|
||||
</activeWhen>
|
||||
</handler>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,199 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
|
||||
package com.raytheon.uf.viz.d2d.nsharp.rsc.action;
|
||||
|
||||
import gov.noaa.nws.ncep.ui.nsharp.palette.NsharpPrintHandle;
|
||||
import gov.noaa.nws.ncep.ui.nsharp.skewt.NsharpSkewTDescriptor;
|
||||
import gov.noaa.nws.ncep.ui.nsharp.skewt.NsharpSkewTEditor;
|
||||
import gov.noaa.nws.ncep.ui.nsharp.skewt.rsc.NsharpSkewTResource;
|
||||
import gov.noaa.nws.ncep.ui.nsharp.skewt.rsc.NsharpSkewTResource.ElementStateProperty;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.swt.printing.PrintDialog;
|
||||
import org.eclipse.swt.printing.Printer;
|
||||
import org.eclipse.swt.printing.PrinterData;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
import com.raytheon.uf.viz.core.IDisplayPane;
|
||||
import com.raytheon.uf.viz.core.drawables.IDescriptor;
|
||||
import com.raytheon.uf.viz.core.drawables.IFrameCoordinator.FrameChangeMode;
|
||||
import com.raytheon.uf.viz.core.drawables.IFrameCoordinator.FrameChangeOperation;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.viz.ui.EditorUtil;
|
||||
import com.raytheon.viz.ui.actions.PrintScreenAction;
|
||||
|
||||
/**
|
||||
* Print the current map
|
||||
*
|
||||
* <pre>
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jul 26, 2006 chammack Initial Creation.
|
||||
* Aug 08, 2008 #703 randerso fixed bug, changed to scale to fit
|
||||
* paper and rotate if necessary
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author chammack
|
||||
* @version 1
|
||||
*/
|
||||
public class NSharpPrintScreenAction extends PrintScreenAction {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
|
||||
* ExecutionEvent)
|
||||
*/
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
NsharpSkewTEditor editor = null;
|
||||
IEditorPart part = EditorUtil.getActiveEditor();
|
||||
if (part instanceof NsharpSkewTEditor) {
|
||||
editor = (NsharpSkewTEditor) part;
|
||||
}
|
||||
if (editor == null) {
|
||||
return super.execute(event);
|
||||
}
|
||||
IDisplayPane pane = editor.getActiveDisplayPane();
|
||||
IDescriptor desc = pane.getDescriptor();
|
||||
|
||||
NsharpSkewTDescriptor ndesc = editor.getNsharpSkewTDescriptor();
|
||||
|
||||
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getShell();
|
||||
|
||||
// display the printer dialog to get print options
|
||||
PrintDialog pd = new PrintDialog(shell);
|
||||
String frameMode = event.getParameter("frameSelection");
|
||||
if (frameMode == null || frameMode.equalsIgnoreCase("current")) {
|
||||
// selection doesn't seem to work.
|
||||
pd.setScope(PrinterData.PAGE_RANGE);
|
||||
pd.setStartPage(getCurrentIndex(ndesc.getSkewtResource()) + 1);
|
||||
pd.setEndPage(getCurrentIndex(ndesc.getSkewtResource()) + 1);
|
||||
} else if (frameMode.equalsIgnoreCase("all")) {
|
||||
pd.setScope(PrinterData.ALL_PAGES);
|
||||
} else {
|
||||
throw new ExecutionException("Invalid frameMode: " + frameMode);
|
||||
}
|
||||
PrinterData printerData = pd.open();
|
||||
if (printerData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
NsharpPrintHandle handle = new NsharpPrintHandle();
|
||||
handle.createPrinter(printerData);
|
||||
if (handle.startJob()) {
|
||||
switch (pd.getScope()) {
|
||||
case PrinterData.ALL_PAGES: {
|
||||
try {
|
||||
printAllFrames(handle, editor);
|
||||
} catch (VizException e) {
|
||||
throw new ExecutionException(
|
||||
"Error occurred while writing image", e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PrinterData.PAGE_RANGE: {
|
||||
try {
|
||||
printFrames(handle, editor, pd.getStartPage() - 1,
|
||||
pd.getEndPage());
|
||||
} catch (VizException e) {
|
||||
throw new ExecutionException(
|
||||
"Error occurred while writing image", e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PrinterData.SELECTION: {
|
||||
printImage(handle, editor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
handle.endJob();
|
||||
|
||||
}
|
||||
handle.disposePrinter();
|
||||
return null;
|
||||
}
|
||||
|
||||
private int getCurrentIndex(NsharpSkewTResource rsc) {
|
||||
int index = rsc.getDataTimelineList().size();
|
||||
for (ElementStateProperty element : rsc.getDataTimelineList()) {
|
||||
index -= 1;
|
||||
if (element.getElementDescription().equals(
|
||||
rsc.getPickedStnInfoStr())) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void printAllFrames(NsharpPrintHandle printer,
|
||||
NsharpSkewTEditor editor) throws VizException {
|
||||
printFrames(printer, editor, 0, editor.getNsharpSkewTDescriptor()
|
||||
.getSkewtResource().getDataTimelineList().size());
|
||||
}
|
||||
|
||||
private void printFrames(NsharpPrintHandle printer,
|
||||
NsharpSkewTEditor editor, int startIndex, int endIndex)
|
||||
throws VizException {
|
||||
NsharpSkewTDescriptor ndesc = editor.getNsharpSkewTDescriptor();
|
||||
IDisplayPane pane = editor.getActiveDisplayPane();
|
||||
String picked = ndesc.getSkewtResource().getPickedStnInfoStr();
|
||||
if (getCurrentIndex(ndesc.getSkewtResource()) > startIndex) {
|
||||
ndesc.getFrameCoordinator().changeFrame(FrameChangeOperation.FIRST,
|
||||
FrameChangeMode.TIME_AND_SPACE);
|
||||
editor.getActiveDisplayPane().refresh();
|
||||
}
|
||||
renderPane(pane, editor.getLoopProperties());
|
||||
boolean first = true;
|
||||
for (int i = getCurrentIndex(ndesc.getSkewtResource()); i < endIndex; i++) {
|
||||
if (!first) {
|
||||
ndesc.getFrameCoordinator().changeFrame(
|
||||
FrameChangeOperation.NEXT,
|
||||
FrameChangeMode.TIME_AND_SPACE);
|
||||
pane.refresh();
|
||||
renderPane(pane, editor.getLoopProperties());
|
||||
}
|
||||
if (i >= startIndex) {
|
||||
printImage(printer, editor);
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
while (!ndesc.getSkewtResource().getPickedStnInfoStr().equals(picked)) {
|
||||
ndesc.getFrameCoordinator().changeFrame(FrameChangeOperation.NEXT,
|
||||
FrameChangeMode.TIME_AND_SPACE);
|
||||
pane.refresh();
|
||||
renderPane(pane, editor.getLoopProperties());
|
||||
}
|
||||
}
|
||||
|
||||
private void printImage(NsharpPrintHandle printer, NsharpSkewTEditor editor) {
|
||||
printer.printPage(editor.getNsharpSkewTDescriptor());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
|
||||
package com.raytheon.uf.viz.d2d.nsharp.rsc.action;
|
||||
|
||||
import gov.noaa.nws.ncep.ui.nsharp.skewt.NsharpSkewTDescriptor;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.raytheon.uf.viz.core.IDisplayPane;
|
||||
import com.raytheon.uf.viz.core.drawables.IDescriptor;
|
||||
import com.raytheon.uf.viz.core.drawables.IFrameCoordinator.FrameChangeMode;
|
||||
import com.raytheon.uf.viz.core.drawables.IFrameCoordinator.FrameChangeOperation;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.viz.ui.actions.SaveScreenAction;
|
||||
import com.raytheon.viz.ui.editor.AbstractEditor;
|
||||
|
||||
/**
|
||||
* Save the current screen to a file
|
||||
*
|
||||
* <pre>
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jul 26, 2006 chammack Initial Creation.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author chammack
|
||||
* @version 1
|
||||
*/
|
||||
public class NSharpSaveScreenAction extends SaveScreenAction {
|
||||
|
||||
@Override
|
||||
protected BufferedImage captureCurrentFrames(AbstractEditor editor) {
|
||||
return editor.getActiveDisplayPane().getTarget().screenshot();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<BufferedImage> captureAllFrames(AbstractEditor editor)
|
||||
throws VizException {
|
||||
IDescriptor desc = editor.getActiveDisplayPane().getDescriptor();
|
||||
if (!(desc instanceof NsharpSkewTDescriptor)) {
|
||||
return super.captureAllFrames(editor);
|
||||
}
|
||||
NsharpSkewTDescriptor ndesc = (NsharpSkewTDescriptor) desc;
|
||||
int startIndex = 0;
|
||||
int endIndex = ndesc.getSkewtResource().getDataTimelineList().size();
|
||||
return captureFrames(editor, startIndex, endIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<BufferedImage> captureFrames(AbstractEditor editor,
|
||||
int startIndex, int endIndex) throws VizException {
|
||||
IDisplayPane pane = editor.getActiveDisplayPane();
|
||||
IDescriptor desc = pane.getDescriptor();
|
||||
if (!(desc instanceof NsharpSkewTDescriptor)) {
|
||||
return super.captureFrames(editor, startIndex, endIndex);
|
||||
}
|
||||
NsharpSkewTDescriptor ndesc = (NsharpSkewTDescriptor) desc;
|
||||
// save the frame we are on;
|
||||
String picked = ndesc.getSkewtResource().getPickedStnInfoStr();
|
||||
List<BufferedImage> images = new ArrayList<BufferedImage>();
|
||||
|
||||
desc.getFrameCoordinator().changeFrame(FrameChangeOperation.FIRST,
|
||||
FrameChangeMode.TIME_AND_SPACE);
|
||||
pane.refresh();
|
||||
renderPane(pane, editor.getLoopProperties());
|
||||
for (int i = 0; i < endIndex; i++) {
|
||||
if (i >= startIndex) {
|
||||
images.add(captureCurrentFrames(editor));
|
||||
}
|
||||
if (i < endIndex - 1) {
|
||||
desc.getFrameCoordinator().changeFrame(
|
||||
FrameChangeOperation.NEXT,
|
||||
FrameChangeMode.TIME_AND_SPACE);
|
||||
pane.refresh();
|
||||
renderPane(pane, editor.getLoopProperties());
|
||||
}
|
||||
}
|
||||
while (!ndesc.getSkewtResource().getPickedStnInfoStr().equals(picked)) {
|
||||
desc.getFrameCoordinator().changeFrame(FrameChangeOperation.NEXT,
|
||||
FrameChangeMode.TIME_AND_SPACE);
|
||||
pane.refresh();
|
||||
renderPane(pane, editor.getLoopProperties());
|
||||
}
|
||||
return images;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
|
||||
import com.raytheon.uf.viz.core.IDisplayPane;
|
||||
|
@ -31,6 +32,9 @@ public abstract class AbstractScreenCaptureAction extends AbstractHandler {
|
|||
int startIndex = 0;
|
||||
int endIndex = editor.getActiveDisplayPane().getDescriptor()
|
||||
.getFramesInfo().getFrameCount();
|
||||
if(endIndex == 0){
|
||||
endIndex = 1;
|
||||
}
|
||||
return captureFrames(editor, startIndex, endIndex);
|
||||
}
|
||||
|
||||
|
@ -60,11 +64,18 @@ public abstract class AbstractScreenCaptureAction extends AbstractHandler {
|
|||
|
||||
private void setFrameIndex(IDescriptor desc, int index) {
|
||||
FramesInfo fi = desc.getFramesInfo();
|
||||
if(fi.getFrameTimes() == null || fi.getFrameCount() <= 1){
|
||||
return;
|
||||
}
|
||||
index = index % fi.getFrameCount();
|
||||
if(index < 0){
|
||||
index += fi.getFrameCount();
|
||||
}
|
||||
fi = new FramesInfo(fi.getFrameTimes(), index, fi.getTimeMap());
|
||||
desc.setFramesInfo(fi);
|
||||
}
|
||||
|
||||
private void renderPane(IDisplayPane pane, LoopProperties loopProperties)
|
||||
protected void renderPane(IDisplayPane pane, LoopProperties loopProperties)
|
||||
throws VizException {
|
||||
IGraphicsTarget target = pane.getTarget();
|
||||
IRenderableDisplay display = pane.getRenderableDisplay();
|
||||
|
|
|
@ -130,7 +130,7 @@ public class SaveScreenAction extends AbstractScreenCaptureAction {
|
|||
String frameMode = arg0.getParameter("frameSelection");
|
||||
|
||||
if (frameMode == null || frameMode.equalsIgnoreCase("current")) {
|
||||
BufferedImage bi = editor.screenshot();
|
||||
BufferedImage bi = captureCurrentFrames(editor);
|
||||
|
||||
try {
|
||||
writer.setOutput(new FileImageOutputStream(new File(path)));
|
||||
|
|
|
@ -65,8 +65,10 @@ public class NsharpPrintHandle {
|
|||
private static int HODO_X_ORIG= SKEWT_X_ORIG + SKEWT_WIDTH-130;
|
||||
private static int HODO_HEIGHT= 130;
|
||||
private static int HODO_WIDTH= HODO_HEIGHT;
|
||||
|
||||
|
||||
private Font printerFont;
|
||||
private Color printerForegroundColor, printerBackgroundColor;
|
||||
private Transform transform;
|
||||
|
||||
private static NsharpPrintHandle printHandle=null;
|
||||
public static NsharpPrintHandle getPrintHandle() {
|
||||
if(printHandle==null)
|
||||
|
@ -137,9 +139,12 @@ public class NsharpPrintHandle {
|
|||
}
|
||||
try{
|
||||
// Do the printing in a background thread so that spooling does not freeze the UI.
|
||||
printer = new Printer(data);
|
||||
print(printer);
|
||||
printer.dispose();
|
||||
createPrinter(data);
|
||||
if (startJob()) {
|
||||
printPage(NsharpSkewTEditor.getActiveNsharpEditor().getNsharpSkewTDescriptor());
|
||||
endJob();
|
||||
}
|
||||
disposePrinter();
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
|
@ -155,186 +160,198 @@ public class NsharpPrintHandle {
|
|||
|
||||
}
|
||||
|
||||
private void print(Printer printer) {
|
||||
String tabs;
|
||||
Font printerFont;
|
||||
Color printerForegroundColor, printerBackgroundColor;
|
||||
|
||||
NsharpSkewTDescriptor desc = NsharpSkewTEditor.getActiveNsharpEditor().getNsharpSkewTDescriptor();
|
||||
NsharpBackgroundResource bkRsc = desc.getSkewTBkGResource();
|
||||
|
||||
if (printer.startJob("NSHARP")) { // the string is the job name - shows up in the printer's job list
|
||||
Rectangle clientArea = printer.getClientArea();
|
||||
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
|
||||
Point dpi = printer.getDPI();
|
||||
|
||||
float dpiScaleX = dpi.x/72f;
|
||||
float dpiScaleY = dpi.y/72f;
|
||||
|
||||
Transform transform = new Transform(printer);
|
||||
transform.scale(dpiScaleX, dpiScaleY);
|
||||
|
||||
leftMargin = 72 + trim.x; // one inch from left side of paper
|
||||
rightMargin = clientArea.width - 72 + trim.x + trim.width; // one inch from right side of paper
|
||||
topMargin = 72 + trim.y; // one inch from top edge of paper
|
||||
bottomMargin = clientArea.height - 72 + trim.y + trim.height; // one inch from bottom edge of paper
|
||||
//System.out.println("leftMargin="+leftMargin+"rightMargin="+rightMargin+"topMargin"+topMargin+"bottomMargin"+bottomMargin);
|
||||
//leftMargin=54rightMargin=521topMargin54bottomMargin701
|
||||
/* Create a buffer for computing tab width. */
|
||||
int tabSize = 4; // is tab width a user setting in your UI?
|
||||
StringBuffer tabBuffer = new StringBuffer(tabSize);
|
||||
for (int i = 0; i < tabSize; i++) tabBuffer.append(' ');
|
||||
tabs = tabBuffer.toString();
|
||||
|
||||
/* Create printer GC, and create and set the printer font & foreground color. */
|
||||
gc = new GC(printer);
|
||||
int fontSize = (int) Math.round(5/dpiScaleY);
|
||||
fontSize = Math.max(1, fontSize);
|
||||
printerFont = new Font(printer, "Courier", fontSize, SWT.NORMAL);
|
||||
gc.setFont(printerFont);
|
||||
tabWidth = gc.stringExtent(tabs).x;
|
||||
lineHeight = gc.getFontMetrics().getHeight();
|
||||
|
||||
RGB rgb = new RGB(0,0,0);//Black
|
||||
printerForegroundColor = new Color(printer, rgb);
|
||||
gc.setForeground(printerForegroundColor);
|
||||
rgb = new RGB(255,255,255);//white
|
||||
printerBackgroundColor = new Color(printer, rgb);
|
||||
gc.setBackground(printerBackgroundColor);
|
||||
gc.setTransform(transform);
|
||||
printer.startPage();
|
||||
// Print SkewT square
|
||||
gc.drawRectangle(leftMargin+SKEWT_X_ORIG, topMargin, SKEWT_WIDTH, SKEWT_HEIGHT);
|
||||
// set view dimension
|
||||
WGraphics world = new WGraphics(leftMargin+SKEWT_X_ORIG, topMargin, leftMargin+SKEWT_X_ORIG+SKEWT_WIDTH, topMargin+SKEWT_HEIGHT);
|
||||
//set SKEWT virtual world coordinate.
|
||||
world.setWorldCoordinates(NsharpConstants.left, NsharpConstants.top,
|
||||
NsharpConstants.right, NsharpConstants.bottom);
|
||||
gc.setLineWidth(1);
|
||||
NsharpSkewTResource rsc = desc.getSkewtResource();
|
||||
|
||||
|
||||
try {
|
||||
gc.setClipping(leftMargin-30, topMargin-30, rightMargin+30, bottomMargin);
|
||||
gc.drawString(rsc.getPickedStnInfoStr(),leftMargin+SKEWT_X_ORIG, topMargin-20);
|
||||
rsc.printNsharpPressureLinesNumber(world, gc);
|
||||
rsc.printNsharpTempNumber(world, gc);
|
||||
rsc.printHeightMark(world, gc);
|
||||
rsc.printNsharpWind(world, gc);
|
||||
//set clipping
|
||||
gc.setClipping(leftMargin+SKEWT_X_ORIG, topMargin, SKEWT_WIDTH, SKEWT_HEIGHT);
|
||||
//print skewt background
|
||||
bkRsc.getSkewTBackground().paintForPrint(world, gc);
|
||||
gc.setLineWidth(2);
|
||||
gc.setLineStyle(SWT.LINE_SOLID);
|
||||
rsc.printNsharpPressureTempCurve( world, rsc.TEMP_TYPE, gc, rsc.getSoundingLys());
|
||||
rsc.printNsharpPressureTempCurve( world, rsc.DEWPOINT_TYPE, gc,rsc.getSoundingLys());
|
||||
|
||||
gc.setLineStyle(SWT.LINE_DASH);
|
||||
rsc.printNsharpWetbulbTraceCurve(world, gc);
|
||||
gc.setLineStyle(SWT.LINE_DASHDOTDOT);
|
||||
rsc.printNsharpParcelTraceCurve(world, gc);
|
||||
gc.setLineStyle(SWT.LINE_SOLID);
|
||||
//fill/cover this skewt area to be used by Hodo
|
||||
gc.fillRectangle(leftMargin+HODO_X_ORIG, topMargin, HODO_WIDTH, HODO_HEIGHT);
|
||||
} catch (VizException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
gc.setLineWidth(2);
|
||||
// Print Hodo square
|
||||
gc.drawRectangle(leftMargin+HODO_X_ORIG, topMargin, HODO_WIDTH, HODO_HEIGHT);
|
||||
|
||||
//set HODO view world
|
||||
world = new WGraphics(leftMargin+HODO_X_ORIG, topMargin, leftMargin+HODO_X_ORIG+HODO_WIDTH, topMargin+HODO_HEIGHT);
|
||||
//set HODO real world coordinate.
|
||||
world.setWorldCoordinates(-50, 90, 90, -50);
|
||||
|
||||
gc.setLineWidth(1);
|
||||
//print hodo background
|
||||
bkRsc.getHodoBackground().paintForPrint(world, gc);
|
||||
try {
|
||||
//print hodo
|
||||
gc.setLineStyle(SWT.LINE_SOLID);
|
||||
|
||||
rsc.printNsharpHodoWind(world, gc, rsc.getSoundingLys());
|
||||
} catch (VizException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
nsharpNative = getNsharpNativePtr();
|
||||
//reset clipping
|
||||
gc.setClipping(leftMargin-15, topMargin+SKEWT_HEIGHT, rightMargin-leftMargin+30,bottomMargin-topMargin+30);
|
||||
|
||||
gc.setLineWidth(2);
|
||||
//print thermodynamic data title and its box
|
||||
gc.drawString("THERMODYNAMIC PARAMETERS",leftMargin+50, topMargin+SKEWT_HEIGHT+20);
|
||||
//gc.drawRectangle(leftMargin-15, topMargin+SKEWT_HEIGHT+30, 220,280);
|
||||
gc.drawLine(leftMargin-15, topMargin+SKEWT_HEIGHT+30, leftMargin+205,topMargin+SKEWT_HEIGHT+30);
|
||||
//set clipping
|
||||
//gc.setClipping(leftMargin-16, topMargin+SKEWT_HEIGHT+30, 222,280);
|
||||
String textStr = printThermodynamicParametersBox1();
|
||||
//System.out.println(textStr);
|
||||
int curY= printText(textStr,leftMargin-12, topMargin+SKEWT_HEIGHT+35, leftMargin+205,topMargin+SKEWT_HEIGHT+295);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin+205,curY);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin-15,topMargin+SKEWT_HEIGHT+30);
|
||||
gc.drawLine(leftMargin+205, curY, leftMargin+205,topMargin+SKEWT_HEIGHT+30);
|
||||
String str1="", str2="", str3="";
|
||||
textStr = printThermodynamicParametersBox2();
|
||||
int gapIndex1 = textStr.indexOf("BOXLINE");
|
||||
str1= textStr.substring(0, gapIndex1);
|
||||
int gapIndex2 = textStr.indexOf("BOXLINE",gapIndex1+1);
|
||||
str2= textStr.substring( gapIndex1+("BOXLINE".length()),gapIndex2);
|
||||
str3= textStr.substring( gapIndex2+("BOXLINE".length()));
|
||||
int preY= curY;
|
||||
curY= printText(str1,leftMargin-12, curY+1, leftMargin+205,topMargin+SKEWT_HEIGHT+295);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin+205,curY);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin-15,preY);
|
||||
gc.drawLine(leftMargin+205, curY, leftMargin+205,preY);
|
||||
preY= curY;
|
||||
curY= printText(str2,leftMargin-12, curY+1, leftMargin+205,topMargin+SKEWT_HEIGHT+295);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin+205,curY);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin-15,preY);
|
||||
gc.drawLine(leftMargin+205, curY, leftMargin+205,preY);
|
||||
preY= curY;
|
||||
curY= printText(str3,leftMargin-12, curY+1, leftMargin+205,topMargin+SKEWT_HEIGHT+295);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin+205,curY);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin-15,preY);
|
||||
gc.drawLine(leftMargin+205, curY, leftMargin+205,preY);
|
||||
|
||||
textStr = "Output produced by: NCO-SIB AWIPS2 NSHARP\nNational SkewT-Hodograph Analysis and Research Program\n";
|
||||
printText(textStr,leftMargin-12, curY+100, leftMargin+300,curY+120);
|
||||
|
||||
|
||||
//print kinematic data title and its box
|
||||
gc.drawString("KINEMATIC PARAMETERS",leftMargin+280, topMargin+SKEWT_HEIGHT+20);
|
||||
gc.drawLine(leftMargin+225, topMargin+SKEWT_HEIGHT+30, leftMargin+445,topMargin+SKEWT_HEIGHT+30);
|
||||
textStr = printKinematicParametersBox();
|
||||
curY= printText(textStr,leftMargin+228,topMargin+SKEWT_HEIGHT+35, leftMargin+444,topMargin+SKEWT_HEIGHT+295);
|
||||
//System.out.println("curreny y = "+ curY);
|
||||
gc.drawLine(leftMargin+225, curY, leftMargin+445,curY);
|
||||
gc.drawLine(leftMargin+225, curY, leftMargin+225,topMargin+SKEWT_HEIGHT+30);
|
||||
gc.drawLine(leftMargin+445, curY, leftMargin+445,topMargin+SKEWT_HEIGHT+30);
|
||||
|
||||
// print STORM STRUCTURE PARAMETERS
|
||||
gc.drawString("STORM STRUCTURE PARAMETERS",leftMargin+280, curY+20);
|
||||
gc.drawLine(leftMargin+225, curY+30, leftMargin+445,curY+30);
|
||||
textStr = printStormStructureParametersBox();
|
||||
preY = curY+30;
|
||||
curY= printText(textStr,leftMargin+228,curY+35, leftMargin+444,topMargin+SKEWT_HEIGHT+295);
|
||||
gc.drawLine(leftMargin+225, curY, leftMargin+445,curY);
|
||||
gc.drawLine(leftMargin+225, curY, leftMargin+225,preY);
|
||||
gc.drawLine(leftMargin+445, curY, leftMargin+445,preY);
|
||||
|
||||
printer.endPage();
|
||||
printer.endJob();
|
||||
|
||||
/* Cleanup graphics resources used in printing */
|
||||
printerFont.dispose();
|
||||
printerForegroundColor.dispose();
|
||||
printerBackgroundColor.dispose();
|
||||
transform.dispose();
|
||||
gc.dispose();
|
||||
}
|
||||
public void createPrinter(PrinterData data){
|
||||
this.printer = new Printer(data);
|
||||
}
|
||||
|
||||
public boolean startJob(){
|
||||
String tabs;
|
||||
if (printer.startJob("NSHARP")) { // the string is the job name - shows up in the printer's job list
|
||||
Rectangle clientArea = printer.getClientArea();
|
||||
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
|
||||
Point dpi = printer.getDPI();
|
||||
|
||||
float dpiScaleX = dpi.x/72f;
|
||||
float dpiScaleY = dpi.y/72f;
|
||||
|
||||
transform = new Transform(printer);
|
||||
transform.scale(dpiScaleX, dpiScaleY);
|
||||
|
||||
leftMargin = 72 + trim.x; // one inch from left side of paper
|
||||
rightMargin = clientArea.width - 72 + trim.x + trim.width; // one inch from right side of paper
|
||||
topMargin = 72 + trim.y; // one inch from top edge of paper
|
||||
bottomMargin = clientArea.height - 72 + trim.y + trim.height; // one inch from bottom edge of paper
|
||||
//System.out.println("leftMargin="+leftMargin+"rightMargin="+rightMargin+"topMargin"+topMargin+"bottomMargin"+bottomMargin);
|
||||
//leftMargin=54rightMargin=521topMargin54bottomMargin701
|
||||
/* Create a buffer for computing tab width. */
|
||||
int tabSize = 4; // is tab width a user setting in your UI?
|
||||
StringBuffer tabBuffer = new StringBuffer(tabSize);
|
||||
for (int i = 0; i < tabSize; i++) tabBuffer.append(' ');
|
||||
tabs = tabBuffer.toString();
|
||||
|
||||
/* Create printer GC, and create and set the printer font & foreground color. */
|
||||
gc = new GC(printer);
|
||||
int fontSize = (int) Math.round(5/dpiScaleY);
|
||||
fontSize = Math.max(1, fontSize);
|
||||
printerFont = new Font(printer, "Courier", fontSize, SWT.NORMAL);
|
||||
gc.setFont(printerFont);
|
||||
tabWidth = gc.stringExtent(tabs).x;
|
||||
lineHeight = gc.getFontMetrics().getHeight();
|
||||
|
||||
RGB rgb = new RGB(0,0,0);//Black
|
||||
printerForegroundColor = new Color(printer, rgb);
|
||||
gc.setForeground(printerForegroundColor);
|
||||
rgb = new RGB(255,255,255);//white
|
||||
printerBackgroundColor = new Color(printer, rgb);
|
||||
gc.setBackground(printerBackgroundColor);
|
||||
gc.setTransform(transform);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void printPage(NsharpSkewTDescriptor desc){
|
||||
NsharpBackgroundResource bkRsc = desc.getSkewTBkGResource();
|
||||
printer.startPage();
|
||||
// Print SkewT square
|
||||
gc.drawRectangle(leftMargin+SKEWT_X_ORIG, topMargin, SKEWT_WIDTH, SKEWT_HEIGHT);
|
||||
// set view dimension
|
||||
WGraphics world = new WGraphics(leftMargin+SKEWT_X_ORIG, topMargin, leftMargin+SKEWT_X_ORIG+SKEWT_WIDTH, topMargin+SKEWT_HEIGHT);
|
||||
//set SKEWT virtual world coordinate.
|
||||
world.setWorldCoordinates(NsharpConstants.left, NsharpConstants.top,
|
||||
NsharpConstants.right, NsharpConstants.bottom);
|
||||
gc.setLineWidth(1);
|
||||
NsharpSkewTResource rsc = desc.getSkewtResource();
|
||||
|
||||
|
||||
try {
|
||||
gc.setClipping(leftMargin-30, topMargin-30, rightMargin+30, bottomMargin);
|
||||
gc.drawString(rsc.getPickedStnInfoStr(),leftMargin+SKEWT_X_ORIG, topMargin-20);
|
||||
rsc.printNsharpPressureLinesNumber(world, gc);
|
||||
rsc.printNsharpTempNumber(world, gc);
|
||||
rsc.printHeightMark(world, gc);
|
||||
rsc.printNsharpWind(world, gc);
|
||||
//set clipping
|
||||
gc.setClipping(leftMargin+SKEWT_X_ORIG, topMargin, SKEWT_WIDTH, SKEWT_HEIGHT);
|
||||
//print skewt background
|
||||
bkRsc.getSkewTBackground().paintForPrint(world, gc);
|
||||
gc.setLineWidth(2);
|
||||
gc.setLineStyle(SWT.LINE_SOLID);
|
||||
rsc.printNsharpPressureTempCurve( world, rsc.TEMP_TYPE, gc, rsc.getSoundingLys());
|
||||
rsc.printNsharpPressureTempCurve( world, rsc.DEWPOINT_TYPE, gc,rsc.getSoundingLys());
|
||||
|
||||
gc.setLineStyle(SWT.LINE_DASH);
|
||||
rsc.printNsharpWetbulbTraceCurve(world, gc);
|
||||
gc.setLineStyle(SWT.LINE_DASHDOTDOT);
|
||||
rsc.printNsharpParcelTraceCurve(world, gc);
|
||||
gc.setLineStyle(SWT.LINE_SOLID);
|
||||
//fill/cover this skewt area to be used by Hodo
|
||||
gc.fillRectangle(leftMargin+HODO_X_ORIG, topMargin, HODO_WIDTH, HODO_HEIGHT);
|
||||
} catch (VizException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
gc.setLineWidth(2);
|
||||
// Print Hodo square
|
||||
gc.drawRectangle(leftMargin+HODO_X_ORIG, topMargin, HODO_WIDTH, HODO_HEIGHT);
|
||||
|
||||
//set HODO view world
|
||||
world = new WGraphics(leftMargin+HODO_X_ORIG, topMargin, leftMargin+HODO_X_ORIG+HODO_WIDTH, topMargin+HODO_HEIGHT);
|
||||
//set HODO real world coordinate.
|
||||
world.setWorldCoordinates(-50, 90, 90, -50);
|
||||
|
||||
gc.setLineWidth(1);
|
||||
//print hodo background
|
||||
bkRsc.getHodoBackground().paintForPrint(world, gc);
|
||||
try {
|
||||
//print hodo
|
||||
gc.setLineStyle(SWT.LINE_SOLID);
|
||||
|
||||
rsc.printNsharpHodoWind(world, gc, rsc.getSoundingLys());
|
||||
} catch (VizException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
nsharpNative = getNsharpNativePtr();
|
||||
//reset clipping
|
||||
gc.setClipping(leftMargin-15, topMargin+SKEWT_HEIGHT, rightMargin-leftMargin+30,bottomMargin-topMargin+30);
|
||||
|
||||
gc.setLineWidth(2);
|
||||
//print thermodynamic data title and its box
|
||||
gc.drawString("THERMODYNAMIC PARAMETERS",leftMargin+50, topMargin+SKEWT_HEIGHT+20);
|
||||
//gc.drawRectangle(leftMargin-15, topMargin+SKEWT_HEIGHT+30, 220,280);
|
||||
gc.drawLine(leftMargin-15, topMargin+SKEWT_HEIGHT+30, leftMargin+205,topMargin+SKEWT_HEIGHT+30);
|
||||
//set clipping
|
||||
//gc.setClipping(leftMargin-16, topMargin+SKEWT_HEIGHT+30, 222,280);
|
||||
String textStr = printThermodynamicParametersBox1();
|
||||
//System.out.println(textStr);
|
||||
int curY= printText(textStr,leftMargin-12, topMargin+SKEWT_HEIGHT+35, leftMargin+205,topMargin+SKEWT_HEIGHT+295);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin+205,curY);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin-15,topMargin+SKEWT_HEIGHT+30);
|
||||
gc.drawLine(leftMargin+205, curY, leftMargin+205,topMargin+SKEWT_HEIGHT+30);
|
||||
String str1="", str2="", str3="";
|
||||
textStr = printThermodynamicParametersBox2();
|
||||
int gapIndex1 = textStr.indexOf("BOXLINE");
|
||||
str1= textStr.substring(0, gapIndex1);
|
||||
int gapIndex2 = textStr.indexOf("BOXLINE",gapIndex1+1);
|
||||
str2= textStr.substring( gapIndex1+("BOXLINE".length()),gapIndex2);
|
||||
str3= textStr.substring( gapIndex2+("BOXLINE".length()));
|
||||
int preY= curY;
|
||||
curY= printText(str1,leftMargin-12, curY+1, leftMargin+205,topMargin+SKEWT_HEIGHT+295);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin+205,curY);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin-15,preY);
|
||||
gc.drawLine(leftMargin+205, curY, leftMargin+205,preY);
|
||||
preY= curY;
|
||||
curY= printText(str2,leftMargin-12, curY+1, leftMargin+205,topMargin+SKEWT_HEIGHT+295);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin+205,curY);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin-15,preY);
|
||||
gc.drawLine(leftMargin+205, curY, leftMargin+205,preY);
|
||||
preY= curY;
|
||||
curY= printText(str3,leftMargin-12, curY+1, leftMargin+205,topMargin+SKEWT_HEIGHT+295);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin+205,curY);
|
||||
gc.drawLine(leftMargin-15, curY, leftMargin-15,preY);
|
||||
gc.drawLine(leftMargin+205, curY, leftMargin+205,preY);
|
||||
|
||||
textStr = "Output produced by: NCO-SIB AWIPS2 NSHARP\nNational SkewT-Hodograph Analysis and Research Program\n";
|
||||
printText(textStr,leftMargin-12, curY+100, leftMargin+300,curY+120);
|
||||
|
||||
|
||||
//print kinematic data title and its box
|
||||
gc.drawString("KINEMATIC PARAMETERS",leftMargin+280, topMargin+SKEWT_HEIGHT+20);
|
||||
gc.drawLine(leftMargin+225, topMargin+SKEWT_HEIGHT+30, leftMargin+445,topMargin+SKEWT_HEIGHT+30);
|
||||
textStr = printKinematicParametersBox();
|
||||
curY= printText(textStr,leftMargin+228,topMargin+SKEWT_HEIGHT+35, leftMargin+444,topMargin+SKEWT_HEIGHT+295);
|
||||
//System.out.println("curreny y = "+ curY);
|
||||
gc.drawLine(leftMargin+225, curY, leftMargin+445,curY);
|
||||
gc.drawLine(leftMargin+225, curY, leftMargin+225,topMargin+SKEWT_HEIGHT+30);
|
||||
gc.drawLine(leftMargin+445, curY, leftMargin+445,topMargin+SKEWT_HEIGHT+30);
|
||||
|
||||
// print STORM STRUCTURE PARAMETERS
|
||||
gc.drawString("STORM STRUCTURE PARAMETERS",leftMargin+280, curY+20);
|
||||
gc.drawLine(leftMargin+225, curY+30, leftMargin+445,curY+30);
|
||||
textStr = printStormStructureParametersBox();
|
||||
preY = curY+30;
|
||||
curY= printText(textStr,leftMargin+228,curY+35, leftMargin+444,topMargin+SKEWT_HEIGHT+295);
|
||||
gc.drawLine(leftMargin+225, curY, leftMargin+445,curY);
|
||||
gc.drawLine(leftMargin+225, curY, leftMargin+225,preY);
|
||||
gc.drawLine(leftMargin+445, curY, leftMargin+445,preY);
|
||||
|
||||
printer.endPage();
|
||||
}
|
||||
|
||||
public void endJob(){
|
||||
printer.endJob();
|
||||
|
||||
/* Cleanup graphics resources used in printing */
|
||||
printerFont.dispose();
|
||||
printerForegroundColor.dispose();
|
||||
printerBackgroundColor.dispose();
|
||||
transform.dispose();
|
||||
gc.dispose();
|
||||
}
|
||||
|
||||
public void disposePrinter(){
|
||||
printer.dispose();
|
||||
}
|
||||
|
||||
private int x, y;
|
||||
private int index, end;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue