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();
}
}
}
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);
}
Aggregations