Search in sources :

Example 1 with ImageFilter

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();
}
Also used : DummyExternalSLDFile(com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile) StyledLayer(org.geotools.styling.StyledLayer) ImageFilter(com.sldeditor.ui.legend.filechooser.ImageFilter) IOException(java.io.IOException) Clipboard(java.awt.datatransfer.Clipboard) Image(java.awt.Image) LegendPanelImage(com.sldeditor.ui.legend.LegendPanelImage) DummyExternalSLDFile(com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile) File(java.io.File) StringSelection(java.awt.datatransfer.StringSelection) Test(org.junit.jupiter.api.Test)

Example 2 with ImageFilter

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;
}
Also used : ImageFilter(com.sldeditor.ui.legend.filechooser.ImageFilter) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Aggregations

ImageFilter (com.sldeditor.ui.legend.filechooser.ImageFilter)2 File (java.io.File)2 DummyExternalSLDFile (com.sldeditor.test.unit.datasource.impl.DummyExternalSLDFile)1 LegendPanelImage (com.sldeditor.ui.legend.LegendPanelImage)1 Image (java.awt.Image)1 Clipboard (java.awt.datatransfer.Clipboard)1 StringSelection (java.awt.datatransfer.StringSelection)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 StyledLayer (org.geotools.styling.StyledLayer)1 Test (org.junit.jupiter.api.Test)1