Merge remote-tracking branch 'omaha/omaha_16.2.2' into master_16.2.2

Former-commit-id: ac1209596d11cac91eade6c44284310260a59e7c
This commit is contained in:
Shawn.Hooper 2016-06-01 15:05:08 -04:00
commit d02d9ddacc
5 changed files with 156 additions and 120 deletions

View file

@ -20,6 +20,8 @@
package com.raytheon.uf.viz.d2d.ui.dialogs;
import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.ComponentColorModel;
import java.awt.image.IndexColorModel;
@ -28,7 +30,7 @@ import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXB;
@ -98,6 +100,8 @@ import com.raytheon.viz.ui.editor.AbstractEditor;
* Dec 09, 2014 11982 D. Friedman Fix print-to-file
* Jan 11, 2016 5242 kbisanz Replaced calls to deprecated LocalizationFile methods
* May 13, 2016 5653 randerso Fixed print scaling
* Handle empty printer list
* Code cleanup
*
* </pre>
*
@ -112,7 +116,7 @@ public class PrintDialog extends CaveSWTDialog {
private final String SETTINGS_FILENAME = "printSettings";
private ArrayList<PrinterData> printerDataStore = null;
private List<PrinterData> printerDataStore = null;
private PrinterData printToFileData = null;
@ -163,7 +167,7 @@ public class PrintDialog extends CaveSWTDialog {
public boolean magnificationAdjusted = false;
public Map<String, Double> magnificationStore = new HashMap<String, Double>();
public Map<String, Double> magnificationStore = new HashMap<>();
}
private class DensityInformationStorage {
@ -171,7 +175,7 @@ public class PrintDialog extends CaveSWTDialog {
public boolean densityAdjusted = false;
public Map<String, Double> densityStore = new HashMap<String, Double>();
public Map<String, Double> densityStore = new HashMap<>();
}
private class PrinterSettings {
@ -221,7 +225,7 @@ public class PrintDialog extends CaveSWTDialog {
}
private void createPrintToGroup() {
ArrayList<String> availablePrinters = this.getAvailablePrinters();
List<String> availablePrinters = this.getAvailablePrinters();
Group group = new Group(this.shell, SWT.SHADOW_ETCHED_IN);
GridData gridData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
@ -232,73 +236,72 @@ public class PrintDialog extends CaveSWTDialog {
group.setLayout(gridLayout);
group.setText("Print To");
Button button = new Button(group, SWT.RADIO);
button.setText("Printer");
button.setSelection(true);
button.addSelectionListener(new SelectionAdapter() {
printerRadioButton = new Button(group, SWT.RADIO);
printerRadioButton.setText("Printer");
printerRadioButton.setSelection(true);
printerRadioButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (printerRadioButton.getSelection()) {
selectedPrinterCombo.setEnabled(true);
destinationFileText.setEnabled(false);
destinationFileText.setText("");
destinationFileText.setToolTipText("~ NO FILE SELECTED ~");
browseButton.setEnabled(false);
okButton.setEnabled(selectedPrinterCombo
.getSelectionIndex() >= 0);
}
}
});
this.printerRadioButton = button;
Combo combo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
selectedPrinterCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
gridData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
combo.setLayoutData(gridData);
selectedPrinterCombo.setLayoutData(gridData);
if (availablePrinters != null) {
Iterator<String> printerIterator = availablePrinters.iterator();
while (printerIterator.hasNext()) {
combo.add(printerIterator.next());
}
combo.select(0);
for (String printer : availablePrinters) {
selectedPrinterCombo.add(printer);
}
this.selectedPrinterCombo = combo;
selectedPrinterCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
okButton.setEnabled(selectedPrinterCombo.getSelectionIndex() >= 0);
}
});
// filler
new Label(group, SWT.NONE);
button = new Button(group, SWT.RADIO);
button.setText("File");
button.addSelectionListener(new SelectionAdapter() {
fileRadioButton = new Button(group, SWT.RADIO);
fileRadioButton.setText("File");
fileRadioButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (fileRadioButton.getSelection()) {
selectedPrinterCombo.setEnabled(false);
destinationFileText.setEnabled(true);
browseButton.setEnabled(true);
okButton.setEnabled(!destinationFileText.getText()
.isEmpty());
}
}
});
this.fileRadioButton = button;
Text text = new Text(group, SWT.BORDER);
destinationFileText = new Text(group, SWT.BORDER | SWT.READ_ONLY);
gridData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
GC gc = new GC(text);
GC gc = new GC(destinationFileText);
int textWidth = gc.getFontMetrics().getAverageCharWidth() * 30;
gc.dispose();
gridData.minimumWidth = textWidth;
text.setLayoutData(gridData);
text.setEnabled(false);
this.destinationFileText = text;
destinationFileText.setLayoutData(gridData);
destinationFileText.setEnabled(false);
button = new Button(group, SWT.PUSH);
button.setText("Browse ...");
button.addSelectionListener(new SelectionAdapter() {
browseButton = new Button(group, SWT.PUSH);
browseButton.setText("Browse ...");
browseButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
selectDestinationFile(destinationFileText.getText());
}
});
button.setEnabled(false);
this.browseButton = button;
browseButton.setEnabled(false);
}
private void createPrintInAndOrientationGroups() {
@ -311,28 +314,24 @@ public class PrintDialog extends CaveSWTDialog {
group.setLayout(new GridLayout(1, true));
group.setText("Print In");
Button button = new Button(group, SWT.RADIO);
button.setText("Color");
button.setSelection(true);
colorRadioButton = button;
colorRadioButton = new Button(group, SWT.RADIO);
colorRadioButton.setText("Color");
colorRadioButton.setSelection(true);
button = new Button(group, SWT.RADIO);
button.setText("Grayscale");
this.grayscaleRadioButton = button;
grayscaleRadioButton = new Button(group, SWT.RADIO);
grayscaleRadioButton.setText("Grayscale");
group = new Group(this.shell, SWT.SHADOW_ETCHED_IN);
group.setLayoutData(gridData);
group.setLayout(new GridLayout(1, true));
group.setText("Orientation");
button = new Button(group, SWT.RADIO);
button.setText("Portrait");
button.setSelection(true);
portraitRadioButton = button;
portraitRadioButton = new Button(group, SWT.RADIO);
portraitRadioButton.setText("Portrait");
portraitRadioButton.setSelection(true);
button = new Button(group, SWT.RADIO);
button.setText("Landscape");
this.landscapeRadioButton = button;
landscapeRadioButton = new Button(group, SWT.RADIO);
landscapeRadioButton.setText("Landscape");
}
private void createRemainingPrintingSettingsSection() {
@ -353,14 +352,10 @@ public class PrintDialog extends CaveSWTDialog {
label.setLayoutData(gridData);
label.setText("Scale %:");
Spinner spinner = new Spinner(leftComp, SWT.READ_ONLY | SWT.BORDER);
scaleSpinner = new Spinner(leftComp, SWT.READ_ONLY | SWT.BORDER);
gridData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
spinner.setLayoutData(gridData);
spinner.setMinimum(0);
spinner.setMaximum(9999);
spinner.setSelection(100);
spinner.setIncrement(1);
this.scaleSpinner = spinner;
scaleSpinner.setLayoutData(gridData);
scaleSpinner.setValues(100, 0, 999, 0, 1, 10);
this.fitToPageBtn = new Button(leftComp, SWT.CHECK);
gridData = new GridData(SWT.RIGHT, SWT.DEFAULT, true, false);
@ -381,15 +376,10 @@ public class PrintDialog extends CaveSWTDialog {
label.setLayoutData(gridData);
label.setText("Copies:");
spinner = new Spinner(leftComp, SWT.READ_ONLY | SWT.BORDER);
copiesSpinner = new Spinner(leftComp, SWT.READ_ONLY | SWT.BORDER);
gridData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
spinner.setLayoutData(gridData);
spinner.setMinimum(1);
spinner.setMaximum(9999);
spinner.setSelection(0);
spinner.setIncrement(1);
this.copiesSpinner = spinner;
copiesSpinner.setLayoutData(gridData);
copiesSpinner.setValues(1, 1, 9999, 0, 1, 10);
Composite rightComp = new Composite(comp, SWT.NONE);
gridData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
@ -401,22 +391,23 @@ public class PrintDialog extends CaveSWTDialog {
label.setLayoutData(gridData);
label.setText("Mag:");
Combo combo = new Combo(rightComp, SWT.READ_ONLY | SWT.DROP_DOWN);
magnificationCombo = new Combo(rightComp, SWT.READ_ONLY | SWT.DROP_DOWN);
gridData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
combo.setLayoutData(gridData);
magnificationCombo.setLayoutData(gridData);
/* Get The Magnification Values. */
for (int i = 0; i < MagnificationPopulator.getMagnifications().length; i++) {
combo.add(MagnificationPopulator.getMagnifications()[i]);
magnificationCombo
.add(MagnificationPopulator.getMagnifications()[i]);
}
String currentMagnification = this.getCurrentMagnification();
for (int i = 0; i < MagnificationPopulator.getMagnifications().length; i++) {
if (currentMagnification.equals(MagnificationPopulator
.getMagnifications()[i])) {
combo.select(i);
magnificationCombo.select(i);
break;
}
}
combo.addSelectionListener(new SelectionAdapter() {
magnificationCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
okButton.setEnabled(false);
@ -426,27 +417,26 @@ public class PrintDialog extends CaveSWTDialog {
cancelButton.setEnabled(true);
}
});
this.magnificationCombo = combo;
label = new Label(rightComp, SWT.NONE);
gridData = new GridData(SWT.RIGHT, SWT.CENTER, true, false);
label.setLayoutData(gridData);
label.setText("Density:");
combo = new Combo(rightComp, SWT.READ_ONLY | SWT.DROP_DOWN);
densityCombo = new Combo(rightComp, SWT.READ_ONLY | SWT.DROP_DOWN);
gridData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
combo.setLayoutData(gridData);
densityCombo.setLayoutData(gridData);
for (int i = 0; i < DensityPopulator.getDensityLabels().length; i++) {
combo.add(DensityPopulator.getDensityLabels()[i]);
densityCombo.add(DensityPopulator.getDensityLabels()[i]);
}
String currentDensity = this.getCurrentDensity();
for (int i = 0; i < DensityPopulator.getDensityLabels().length; i++) {
if (currentDensity.equals(DensityPopulator.getDensityLabels()[i])) {
combo.select(i);
densityCombo.select(i);
break;
}
}
combo.addSelectionListener(new SelectionAdapter() {
densityCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
okButton.setEnabled(false);
@ -456,7 +446,6 @@ public class PrintDialog extends CaveSWTDialog {
cancelButton.setEnabled(true);
}
});
this.densityCombo = combo;
rightComp = new Composite(comp, SWT.NONE);
gridData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
@ -466,28 +455,27 @@ public class PrintDialog extends CaveSWTDialog {
label = new Label(rightComp, SWT.NONE);
label.setText("Paper:");
combo = new Combo(rightComp, SWT.READ_ONLY | SWT.DROP_DOWN);
Combo paperCombo = new Combo(rightComp, SWT.READ_ONLY | SWT.DROP_DOWN);
gridData = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
combo.setLayoutData(gridData);
combo.add("DEFAULT");
combo.setEnabled(false);
combo.select(0);
paperCombo.setLayoutData(gridData);
paperCombo.add("DEFAULT");
paperCombo.setEnabled(false);
paperCombo.select(0);
// TODO: implement paper settings
invertCheckbox = new Button(comp, SWT.CHECK);
gridData = new GridData();
gridData.horizontalAlignment = SWT.CENTER;
Button button = new Button(comp, SWT.CHECK);
button.setLayoutData(gridData);
button.setText("Invert Black/White");
button.setSelection(true);
this.invertCheckbox = button;
invertCheckbox.setLayoutData(gridData);
invertCheckbox.setText("Invert Black/White");
invertCheckbox.setSelection(true);
gridData = new GridData();
gridData.horizontalAlignment = SWT.CENTER;
button = new Button(comp, SWT.CHECK);
button.setLayoutData(gridData);
button.setText("Manual Feed");
button.setEnabled(false);
Button manualFeedCheckbox = new Button(comp, SWT.CHECK);
manualFeedCheckbox.setLayoutData(gridData);
manualFeedCheckbox.setText("Manual Feed");
manualFeedCheckbox.setEnabled(false);
// TODO: implement manual feed
}
@ -496,10 +484,10 @@ public class PrintDialog extends CaveSWTDialog {
GridData gridData = new GridData();
gridData.horizontalAlignment = SWT.CENTER;
gridData.widthHint = buttonWidth;
Button button = new Button(this.shell, SWT.PUSH);
button.setLayoutData(gridData);
button.setText("OK");
button.addSelectionListener(new SelectionAdapter() {
okButton = new Button(this.shell, SWT.PUSH);
okButton.setLayoutData(gridData);
okButton.setText("OK");
okButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
okButton.setEnabled(false);
@ -511,15 +499,15 @@ public class PrintDialog extends CaveSWTDialog {
close();
}
});
this.okButton = button;
okButton.setEnabled(false);
gridData = new GridData();
gridData.horizontalAlignment = SWT.CENTER;
gridData.widthHint = buttonWidth;
button = new Button(this.shell, SWT.PUSH);
button.setLayoutData(gridData);
button.setText("Cancel");
button.addSelectionListener(new SelectionAdapter() {
cancelButton = new Button(this.shell, SWT.PUSH);
cancelButton.setLayoutData(gridData);
cancelButton.setText("Cancel");
cancelButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
okButton.setEnabled(false);
@ -528,7 +516,6 @@ public class PrintDialog extends CaveSWTDialog {
close();
}
});
this.cancelButton = button;
}
private void selectDestinationFile(String fileName) {
@ -563,6 +550,7 @@ public class PrintDialog extends CaveSWTDialog {
String destinationFile = filterPath + selectedFile;
this.destinationFileText.setText(destinationFile);
this.destinationFileText.setToolTipText(destinationFile);
this.okButton.setEnabled(true);
}
private void updateMagnification() {
@ -689,7 +677,10 @@ public class PrintDialog extends CaveSWTDialog {
printerSettings.printInGrayscale = true;
}
if (this.landscapeRadioButton.getSelection()) {
printerSettings.selectedPrinter.orientation = PrinterData.LANDSCAPE;
// TODO: restore this line if we ever get Landscape printing working
// on the LX workstations
// printerSettings.selectedPrinter.orientation =
// PrinterData.LANDSCAPE;
printerSettings.printInLandscape = true;
}
@ -706,6 +697,22 @@ public class PrintDialog extends CaveSWTDialog {
private void print(PrinterSettings printerSettings) {
AbstractEditor editor = (AbstractEditor) EditorUtil.getActiveEditor();
BufferedImage bi = editor.screenshot();
// TODO: remove this block if we ever get Landscape printing working
// on the LX workstations
if (printerSettings.printInLandscape) {
AffineTransform transform = AffineTransform
.getQuadrantRotateInstance(1);
transform.concatenate(AffineTransform.getTranslateInstance(0.0,
-bi.getHeight()));
AffineTransformOp transformOp = new AffineTransformOp(transform,
AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
bi = transformOp.filter(
bi,
new BufferedImage(bi.getHeight(), bi.getWidth(), bi
.getType()));
}
if (printerSettings.invert) {
// Only invert gray pixels, not colored pixels, awt doesn't not have
// a good filter for this.
@ -765,13 +772,22 @@ public class PrintDialog extends CaveSWTDialog {
int scaledImageHeight = Math.round(scale * bi.getHeight()
* printerDPI.y / screenDPI.y);
Point offset = new Point(0, 0);
Point initialOffset = new Point(0, 0);
int xPages = (int) Math.ceil((double) scaledImageWidth
/ printArea.width);
int yPages = (int) Math.ceil((double) scaledImageHeight
/ printArea.height);
// Compute offset to center image in page(s)
initialOffset.x = ((xPages * printArea.width) - scaledImageWidth) / 2;
initialOffset.y = ((yPages * printArea.height) - scaledImageHeight) / 2;
Point offset = new Point(initialOffset.x, initialOffset.y);
Point remaining = new Point(scaledImageWidth, scaledImageHeight);
if (printer.startJob("CAVE")) {
while (remaining.x > 0 && remaining.y > 0) {
if (printer.startPage()) {
GC gc = new GC(printer);
gc.setClipping(printArea);
Transform transform = new Transform(gc.getDevice());
transform.translate(offset.x, offset.y);
@ -791,7 +807,7 @@ public class PrintDialog extends CaveSWTDialog {
offset.x -= printArea.width;
if (remaining.x <= 0) {
remaining.x = scaledImageWidth;
offset.x = 0;
offset.x = initialOffset.x;
remaining.y -= printArea.height;
offset.y -= printArea.height;
}
@ -824,14 +840,11 @@ public class PrintDialog extends CaveSWTDialog {
return currentDensity.toString();
}
private ArrayList<String> getAvailablePrinters() {
private List<String> getAvailablePrinters() {
PrinterData[] printers = Printer.getPrinterList();
if (printers == null || printers.length <= 0) {
return null;
}
ArrayList<String> availablePrinters = new ArrayList<String>();
this.printerDataStore = new ArrayList<PrinterData>();
List<String> availablePrinters = new ArrayList<>(printers.length);
this.printerDataStore = new ArrayList<>(printers.length);
for (int i = 0; i < printers.length; i++) {
/* Do Not Include "Print to File" In The Printer List. */
if (printers[i].name.equalsIgnoreCase("print to file")) {
@ -1024,10 +1037,22 @@ public class PrintDialog extends CaveSWTDialog {
}
if (idx > -1) {
selectedPrinterCombo.select(idx);
} else {
selectedPrinterCombo.deselectAll();
}
}
if (settings.isUsePrinterFile()) {
printerRadioButton.setSelection(false);
fileRadioButton.setSelection(true);
} else {
printerRadioButton.setSelection(true);
fileRadioButton.setSelection(false);
if (selectedPrinterCombo.getSelectionIndex() >= 0) {
okButton.setEnabled(true);
}
}
printerRadioButton.setSelection(!settings.isUsePrinterFile());
fileRadioButton.setSelection(settings.isUsePrinterFile());
}
}
}

View file

@ -203,13 +203,14 @@ public class AlarmAlertDlg extends CaveSWTDialog {
* Sets the shell location.
*/
private void setLocation() {
int shellSizeX = getShell().getSize().x;
int shellSizeY = getShell().getSize().y;
Rectangle bounds = getParent().getMonitor().getBounds();
int locationX = bounds.x + bounds.width - shellSizeX;
int locationY = bounds.y + bounds.height - shellSizeY;
shell.setLocation(locationX, locationY);
return;
if (shell != null) {
int shellSizeX = getShell().getSize().x;
int shellSizeY = getShell().getSize().y;
Rectangle bounds = getParent().getMonitor().getBounds();
int locationX = bounds.x + bounds.width - shellSizeX;
int locationY = bounds.y + bounds.height - shellSizeY;
shell.setLocation(locationX, locationY);
}
}
@Override

View file

@ -83,6 +83,7 @@ import com.raytheon.uf.edex.plugin.pointset.netcdf.description.TriangulationDesc
* Aug 11, 2015 4709 bsteffen Initial creation
* Jan 21, 2016 5208 bsteffen Decode scale, offset, units, long_name when
* they are present and extra validation.
* May 20, 2016 5664 bsteffen Close files.
*
* </pre>
*
@ -109,8 +110,9 @@ public class PointSetNetcdfDecoder {
if (levelFactory == null) {
levelFactory = LevelFactory.getInstance();
}
NetcdfFile netcdfFile = null;
try {
NetcdfFile netcdfFile = NetcdfFile.open(file.getAbsolutePath());
netcdfFile = NetcdfFile.open(file.getAbsolutePath());
Map<String, String> locationCache = new HashMap<String, String>();
List<PointSetRecord> records = new ArrayList<>();
for (ProductDescription description : descriptions
@ -131,6 +133,14 @@ public class PointSetNetcdfDecoder {
} catch (InvalidDescriptionException | IOException | StorageException e) {
logger.error("Unable to decode pointset from file: {}",
file.getName(), e);
} finally {
if (netcdfFile != null) {
try {
netcdfFile.close();
} catch (IOException e) {
logger.warn("Error closing file: {}", file.getName());
}
}
}
return EMPTY_POINTSET_ARRAY;
}