use of com.sldeditor.ui.legend.filechooser.ImageFilter in project sldeditor by robward-scisys.
the class LegendPanelImageTest method testRenderSymbol.
/**
* Test method for {@link com.sldeditor.ui.legend.LegendPanelImage#renderSymbol()}.
*/
@Test
void testRenderSymbol() {
TestLegendPanelImage testObj = new TestLegendPanelImage();
DummyExternalSLDFile external = new DummyExternalSLDFile();
SelectedSymbol.getInstance().setSld(external.getSLD());
testObj.renderSymbol();
testObj.setFilenameDisplayed(true);
testObj.showFilenamePressed();
testObj.setFilenameDisplayed(false);
testObj.showFilenamePressed();
testObj.setStyleNameDisplayed(true);
testObj.showStyleNamePressed();
testObj.setStyleNameDisplayed(false);
testObj.showStyleNamePressed();
// Empty style layer name
StyledLayer styledLayer = external.getSLD().layers().get(0);
styledLayer.setName(null);
testObj.setStyleNameDisplayed(true);
testObj.showStyleNamePressed();
File selectedFile = null;
try {
selectedFile = File.createTempFile("test", ".sld");
} catch (IOException e) {
fail(e.getMessage());
}
// Write legend image with no file filter
Image image = testObj.getImageIcon().getImage();
File f = null;
try {
f = testObj.writeLegendImage(null, selectedFile, image);
} catch (IOException e) {
fail(e.getMessage());
}
assertTrue(f.exists());
f.delete();
selectedFile.delete();
// Write legend image with file filter and no file suffix
try {
selectedFile = File.createTempFile("test", "test");
} catch (IOException e) {
fail(e.getMessage());
}
image = testObj.getImageIcon().getImage();
try {
f = testObj.writeLegendImage(new ImageFilter(ImageFileExtensionUtils.PNG), selectedFile, image);
} catch (IOException e) {
fail(e.getMessage());
}
assertTrue(f.exists());
f.delete();
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection stringSelection = new StringSelection("cleared clipboard");
c.setContents(stringSelection, null);
testObj.copyToClipboard();
c = Toolkit.getDefaultToolkit().getSystemClipboard();
assertTrue(c.isDataFlavorAvailable(DataFlavor.imageFlavor));
selectedFile.delete();
}
use of com.sldeditor.ui.legend.filechooser.ImageFilter in project sldeditor by robward-scisys.
the class LegendPanelImage method writeLegendImage.
/**
* Write legend image.
*
* @param fileFilter the file filter
* @param selectedFile the selected file
* @param image the image
* @return the file
* @throws IOException Signals that an I/O exception has occurred.
*/
protected File writeLegendImage(FileFilter fileFilter, File selectedFile, Image image) throws IOException {
String extension = ImageFilter.defaultExtension();
if (fileFilter != null) {
if (fileFilter instanceof ImageFilter) {
extension = ((ImageFilter) fileFilter).getFileExtension();
}
}
String fullExtension = "." + extension;
String fullPath = selectedFile.getCanonicalPath();
if (!fullPath.endsWith(fullExtension)) {
fullPath = fullPath + fullExtension;
}
File outputFile = new File(fullPath);
BufferedImage buffered = (BufferedImage) image;
LegendManager.getInstance().saveLegendImage(buffered, extension, outputFile);
return outputFile;
}
Aggregations