use of org.geotools.styling.Extent in project sldeditor by robward-scisys.
the class ExtentModelTest method testGetExtentList.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.featuretypeconstraint.ExtentModel#getExtentList()}.
* Test method for
* {@link com.sldeditor.ui.detail.config.featuretypeconstraint.ExtentModel#removeEntries(int, int)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.featuretypeconstraint.ExtentModel#populate(org.geotools.styling.Extent[])}.
*/
@Test
public void testGetExtentList() {
TestModelUpdate testUpdate = new TestModelUpdate();
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
ExtentModel model = new ExtentModel(testUpdate);
Extent[] extentArray = null;
model.populate(extentArray);
extentArray = new Extent[5];
extentArray[0] = styleFactory.createExtent("extent 1", "1 1 1 1");
extentArray[1] = styleFactory.createExtent("extent 2", "2 2 2 2");
extentArray[2] = styleFactory.createExtent("extent 3", "3 3 3 3");
extentArray[3] = styleFactory.createExtent("extent 4", "4 4 4 4");
extentArray[4] = styleFactory.createExtent("extent 5", "5 5 5 5");
model.populate(extentArray);
List<Extent> actualList = model.getExtentList();
assertEquals(5, actualList.size());
assertTrue(actualList.get(2).getName().compareTo("extent 3") == 0);
assertFalse(testUpdate.hasExtentUpdatedBeenCalled());
model.removeEntries(-1, 2);
assertFalse(testUpdate.hasExtentUpdatedBeenCalled());
model.removeEntries(2, 22);
assertFalse(testUpdate.hasExtentUpdatedBeenCalled());
model.removeEntries(22, 2);
assertFalse(testUpdate.hasExtentUpdatedBeenCalled());
model.removeEntries(2, 2);
assertTrue(testUpdate.hasExtentUpdatedBeenCalled());
actualList = model.getExtentList();
assertEquals(4, actualList.size());
assertTrue(actualList.get(2).getName().compareTo("extent 4") == 0);
}
use of org.geotools.styling.Extent in project sldeditor by robward-scisys.
the class FeatureTypeConstraintModelTest method testPopulate.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.featuretypeconstraint.FeatureTypeConstraintModel#populate(java.util.List)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.featuretypeconstraint.FeatureTypeConstraintModel#removeEntries(int, int)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.featuretypeconstraint.FeatureTypeConstraintModel#getFeatureTypeConstraint(int)}.
*/
@Test
public void testPopulate() {
TestModelUpdate testUpdate = new TestModelUpdate();
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
FeatureTypeConstraintModel model = new FeatureTypeConstraintModel(testUpdate);
List<FeatureTypeConstraint> ftcList = null;
model.populate(ftcList);
ftcList = new ArrayList<FeatureTypeConstraint>();
ftcList.add(styleFactory.createFeatureTypeConstraint("ftc1", Filter.INCLUDE, new Extent[0]));
ftcList.add(styleFactory.createFeatureTypeConstraint("ftc2", Filter.INCLUDE, new Extent[0]));
ftcList.add(styleFactory.createFeatureTypeConstraint("ftc3", Filter.INCLUDE, new Extent[0]));
ftcList.add(styleFactory.createFeatureTypeConstraint("ftc4", Filter.INCLUDE, new Extent[0]));
ftcList.add(styleFactory.createFeatureTypeConstraint("ftc5", Filter.INCLUDE, new Extent[0]));
model.populate(ftcList);
List<FeatureTypeConstraint> actualList = model.getFeatureTypeConstraint();
assertEquals(5, actualList.size());
assertTrue(actualList.get(2).getFeatureTypeName().compareTo("ftc3") == 0);
assertFalse(testUpdate.hasFTCUpdatedBeenCalled());
model.removeEntries(-1, 2);
assertFalse(testUpdate.hasFTCUpdatedBeenCalled());
model.removeEntries(2, 22);
assertFalse(testUpdate.hasFTCUpdatedBeenCalled());
model.removeEntries(22, 2);
assertFalse(testUpdate.hasFTCUpdatedBeenCalled());
model.removeEntries(2, 2);
assertTrue(testUpdate.hasFTCUpdatedBeenCalled());
actualList = model.getFeatureTypeConstraint();
assertEquals(4, actualList.size());
assertTrue(actualList.get(2).getFeatureTypeName().compareTo("ftc4") == 0);
assertNull(model.getFeatureTypeConstraint(-1));
assertNull(model.getFeatureTypeConstraint(6));
FeatureTypeConstraint actualFTC = model.getFeatureTypeConstraint(1);
assertTrue(actualFTC.getFeatureTypeName().compareTo("ftc2") == 0);
}
use of org.geotools.styling.Extent in project sldeditor by robward-scisys.
the class ExtentModel method getValueAt.
/*
* (non-Javadoc)
*
* @see javax.swing.table.TableModel#getValueAt(int, int)
*/
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
if ((rowIndex < 0) || (rowIndex >= getRowCount())) {
return null;
}
if ((columnIndex < 0) || (columnIndex >= getColumnCount())) {
return null;
}
Extent extent = extentList.get(rowIndex);
String[] components = extent.getValue().split(" ");
if (components != null) {
switch(columnIndex) {
case COL_NAME:
return extent.getName();
case COL_MINX:
if (components.length > 0) {
return components[0];
}
break;
case COL_MINY:
if (components.length > 1) {
return components[1];
}
break;
case COL_MAXX:
if (components.length > 2) {
return components[2];
}
break;
case COL_MAXY:
if (components.length > 3) {
return components[3];
}
break;
default:
break;
}
}
return null;
}
use of org.geotools.styling.Extent in project sldeditor by robward-scisys.
the class ExtentModel method setValueAt.
/**
* Sets the value at.
*
* @param aValue the a value
* @param rowIndex the row index
* @param columnIndex the column index
*/
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if ((rowIndex < 0) || (rowIndex >= getRowCount())) {
return;
}
if ((columnIndex < 0) || (columnIndex >= getColumnCount())) {
return;
}
Extent extent = extentList.get(rowIndex);
if (columnIndex == COL_NAME) {
extent.setName((String) aValue);
} else {
String[] components = extent.getValue().split(" ");
if (components.length != 4) {
components = new String[4];
components[0] = "0";
components[1] = "0";
components[2] = "0";
components[3] = "0";
}
Double value = 0.0;
try {
value = Double.valueOf((String) aValue);
switch(columnIndex) {
case COL_MINX:
components[0] = value.toString();
break;
case COL_MINY:
components[1] = value.toString();
break;
case COL_MAXX:
components[2] = value.toString();
break;
case COL_MAXY:
components[3] = value.toString();
break;
default:
break;
}
} catch (NumberFormatException e) {
// Ignore
}
String encodedExtent = String.format("%s %s %s %s", components[0], components[1], components[2], components[3]);
extent.setValue(encodedExtent);
}
this.fireTableDataChanged();
if (parentObj != null) {
parentObj.extentUpdated();
}
}
use of org.geotools.styling.Extent in project sldeditor by robward-scisys.
the class ExtentModel method updateExtent.
/**
* Update extents of a feature type constraint.
*
* @param ftc the feature type constraint to update
*/
public void updateExtent(FeatureTypeConstraint ftc) {
if (ftc == null) {
return;
}
if (!extentList.isEmpty()) {
Extent[] extentArray = new Extent[extentList.size()];
int index = 0;
for (Extent extent : extentList) {
Extent newExtent = styleFactory.createExtent(extent.getName(), extent.getValue());
extentArray[index] = newExtent;
index++;
}
ftc.setExtents(extentArray);
}
}
Aggregations