Search in sources :

Example 1 with WorldImageFormat

use of org.geotools.gce.image.WorldImageFormat in project sldeditor by robward-scisys.

the class DetermineRasterFormatTest method testChoose.

/**
 * Test method for {@link
 * com.sldeditor.datasource.chooseraster.DetermineRasterFormat#choose(java.io.File,
 * com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface)}.
 */
@Test
public void testChoose() {
    AbstractGridFormat gridFormat = DetermineRasterFormat.choose(null, null);
    assertTrue(UnknownFormat.class == gridFormat.getClass());
    String testRasterFile = "/raster/sld/sld_cookbook_raster.tif";
    InputStream inputStream = SLDTreeTest.class.getResourceAsStream(testRasterFile);
    File f = null;
    if (inputStream == null) {
        assertNotNull(inputStream, "Failed to find raster test file : " + testRasterFile);
    } else {
        try {
            f = SLDTestRunner.stream2file(inputStream, ".tif");
            gridFormat = DetermineRasterFormat.choose(f, null);
            assertTrue(gridFormat != null);
            // Force to WorldImageFormat
            gridFormat = DetermineRasterFormat.choose(f, new ChooseRasterFormatInterface() {

                @Override
                public AbstractGridFormat showPanel(Set<AbstractGridFormat> formatList) {
                    WorldImageFormat wif = new WorldImageFormat();
                    return wif;
                }
            });
            assertTrue(WorldImageFormat.class == gridFormat.getClass());
        } catch (IOException e1) {
            e1.printStackTrace();
        } finally {
            f.delete();
        }
    }
}
Also used : WorldImageFormat(org.geotools.gce.image.WorldImageFormat) Set(java.util.Set) UnknownFormat(org.geotools.coverage.grid.io.UnknownFormat) InputStream(java.io.InputStream) AbstractGridFormat(org.geotools.coverage.grid.io.AbstractGridFormat) ChooseRasterFormatInterface(com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface) IOException(java.io.IOException) File(java.io.File) SLDTreeTest(com.sldeditor.test.unit.ui.tree.SLDTreeTest) Test(org.junit.jupiter.api.Test)

Example 2 with WorldImageFormat

use of org.geotools.gce.image.WorldImageFormat in project sldeditor by robward-scisys.

the class ChooseRasterFormatPanel method showPanel.

/*
     * (non-Javadoc)
     *
     * @see com.sldeditor.datasource.impl.chooseraster.ChooseRasterFormatInterface#showPanel(java.util.Set)
     */
@Override
public AbstractGridFormat showPanel(Set<AbstractGridFormat> formatList) {
    WorldImageFormat wif = new WorldImageFormat();
    DefaultListModel<String> listModel = new DefaultListModel<>();
    List<AbstractGridFormat> sortedFormatList = new ArrayList<>();
    for (AbstractGridFormat format : formatList) {
        if (format.getName().compareTo(wif.getName()) != 0) {
            sortedFormatList.add(format);
        }
    }
    // Sort formats alphabetically
    Collections.sort(sortedFormatList, new Comparator<AbstractGridFormat>() {

        @Override
        public int compare(final AbstractGridFormat object1, final AbstractGridFormat object2) {
            return object1.getName().compareTo(object2.getName());
        }
    });
    // Add WorldImageFormat to top of list
    sortedFormatList.add(0, wif);
    // Add format names to list component
    for (AbstractGridFormat format : sortedFormatList) {
        formatMap.put(format.getName(), format);
        listModel.addElement(format.getName());
    }
    formatListComponent.setModel(listModel);
    // Select WorldImageFormat
    formatListComponent.setSelectedIndex(0);
    setVisible(true);
    String selectedFormatName = formatListComponent.getSelectedValue();
    return formatMap.get(selectedFormatName);
}
Also used : WorldImageFormat(org.geotools.gce.image.WorldImageFormat) AbstractGridFormat(org.geotools.coverage.grid.io.AbstractGridFormat) ArrayList(java.util.ArrayList) DefaultListModel(javax.swing.DefaultListModel)

Aggregations

AbstractGridFormat (org.geotools.coverage.grid.io.AbstractGridFormat)2 WorldImageFormat (org.geotools.gce.image.WorldImageFormat)2 ChooseRasterFormatInterface (com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface)1 SLDTreeTest (com.sldeditor.test.unit.ui.tree.SLDTreeTest)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 DefaultListModel (javax.swing.DefaultListModel)1 UnknownFormat (org.geotools.coverage.grid.io.UnknownFormat)1 Test (org.junit.jupiter.api.Test)1