use of com.sldeditor.tool.batchupdatefont.BatchUpdateFontData in project sldeditor by robward-scisys.
the class BatchUpdateFontModelTest method testLoadData.
/**
* Test method for {@link com.sldeditor.tool.batchupdatefont.BatchUpdateFontModel#loadData(java.util.List)}.
*/
@Test
public void testLoadData() {
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
sld.layers().add(namedLayer);
String expectedNamedLayer = "namedLayer";
namedLayer.setName(expectedNamedLayer);
Style style = DefaultSymbols.createNewStyle();
String expectedStyleLayer = "style";
style.setName(expectedStyleLayer);
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedFeatureTypeStyleLayer = "feature type style";
fts.setName(expectedFeatureTypeStyleLayer);
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
fts.rules().add(rule);
String expectedRule = "rule";
rule.setName(expectedRule);
String expectedSymbolizer = "text symbolizer";
TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
symbolizer.setName(expectedSymbolizer);
rule.symbolizers().add(symbolizer);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
symbolizer.setFont(font);
SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
String sldContents = sldWriter.encodeSLD(null, sld);
String expectedWorkspace = "workspace";
String expectedStyle = "layer.sld";
StyleWrapper styleWrapper = new StyleWrapper(expectedWorkspace, expectedStyle);
SLDData data = new SLDData(styleWrapper, sldContents);
File testFile = new File("test.sld");
data.setSLDFile(testFile);
SLDEditorFile.getInstance().setSldFile(testFile);
SLDEditorFile.getInstance().setSLDData(data);
BatchUpdateFontData testObj = new BatchUpdateFontData(sld, data);
SelectedSymbol.getInstance().setSld(sld);
testObj.setNamedLayer(expectedNamedLayer);
testObj.setStyle(expectedStyleLayer);
testObj.setFeatureTypeStyle(expectedFeatureTypeStyleLayer);
testObj.setRule(rule);
testObj.setSymbolizer(symbolizer);
testObj.setFont(font);
List<BatchUpdateFontData> dataList = new ArrayList<BatchUpdateFontData>();
dataList.add(testObj);
BatchUpdateFontModel model = new BatchUpdateFontModel();
model.loadData(dataList);
for (int col = 0; col < model.getColumnCount(); col++) {
assertFalse(model.hasValueBeenUpdated(0, col));
}
assertFalse(model.anyChanges());
assertFalse(model.saveData(null));
List<Font> actualFontlist = model.getFontEntries(new int[] { 0 });
assertEquals(1, actualFontlist.size());
assertEquals(1, model.getRowCount());
// Update font
String originalFontname = "New Font";
String originalFontStyle = "italic";
String originalFontWeight = "bold";
int originalFontSize = 16;
font = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
model.applyData(new int[] { 0 }, font);
assertTrue(model.hasValueBeenUpdated(0, 7));
assertTrue(model.hasValueBeenUpdated(0, 8));
assertTrue(model.hasValueBeenUpdated(0, 9));
assertTrue(model.hasValueBeenUpdated(0, 10));
assertTrue(model.anyChanges());
assertEquals(originalFontname, model.getValueAt(0, 7));
assertEquals(originalFontStyle, model.getValueAt(0, 8));
assertEquals(originalFontWeight, model.getValueAt(0, 9));
assertEquals(String.valueOf(originalFontSize), model.getValueAt(0, 10));
model.revertData();
assertFalse(model.anyChanges());
int expectedFontSize = 99;
model.applyData(new int[] { 0 }, expectedFontSize);
// Font size
assertTrue(model.hasValueBeenUpdated(0, 10));
assertEquals(expectedWorkspace, model.getValueAt(0, 0));
assertEquals(expectedStyle, model.getValueAt(0, 1));
assertEquals(expectedNamedLayer, model.getValueAt(0, 2));
assertEquals(expectedStyleLayer, model.getValueAt(0, 3));
assertEquals(expectedFeatureTypeStyleLayer, model.getValueAt(0, 4));
assertEquals(expectedRule, model.getValueAt(0, 5));
assertEquals(expectedSymbolizer, model.getValueAt(0, 6));
assertEquals("abc", model.getValueAt(0, 7));
assertEquals("normal", model.getValueAt(0, 8));
assertEquals("normal", model.getValueAt(0, 9));
assertEquals(String.valueOf(10 + expectedFontSize), model.getValueAt(0, 10));
assertNull(model.getValueAt(0, 42));
assertTrue(model.saveData(null));
SelectedSymbol.destroyInstance();
SLDEditorFile.destroyInstance();
model.setColumnRenderer(null);
JTable table = new JTable();
table.setModel(model);
model.setColumnRenderer(table.getColumnModel());
assertFalse(model.isCellEditable(0, 0));
assertEquals(Localisation.getString(BatchUpdateFontModel.class, "BatchUpdateFontModel.workspace"), model.getColumnName(0));
}
use of com.sldeditor.tool.batchupdatefont.BatchUpdateFontData in project sldeditor by robward-scisys.
the class BatchUpdateFontDataTest method testBatchUpdateFontData.
/**
* Test method for
* {@link com.sldeditor.tool.batchupdatefont.BatchUpdateFontData#BatchUpdateFontData(org.geotools.styling.StyledLayerDescriptor, com.sldeditor.common.SLDDataInterface)}.
*/
@Test
public void testBatchUpdateFontData() {
BatchUpdateFontData testObj = new BatchUpdateFontData(null, null);
assertNull(testObj.getName());
assertNull(testObj.getWorkspace());
assertNull(testObj.getSldData());
String expectedWorkspace = "workspace";
String expectedStyle = "layer.sld";
StyleWrapper styleWrapper = new StyleWrapper(expectedWorkspace, expectedStyle);
SLDData data = new SLDData(styleWrapper, null);
testObj = new BatchUpdateFontData(null, data);
assertEquals(testObj.getWorkspace(), expectedWorkspace);
assertEquals(testObj.getName(), expectedStyle);
assertEquals(testObj.getSldData(), data);
String expectedNamedLayer = "namedLayer";
testObj.setNamedLayer(expectedNamedLayer);
assertEquals(testObj.getNamedLayer(), expectedNamedLayer);
String expectedStyleLayer = "style";
testObj.setStyle(expectedStyleLayer);
assertEquals(testObj.getStyle(), expectedStyleLayer);
String expectedFeatureTypeStyleLayer = "feature type style";
testObj.setFeatureTypeStyle(expectedFeatureTypeStyleLayer);
assertEquals(testObj.getFeatureTypeStyle(), expectedFeatureTypeStyleLayer);
assertNull(testObj.getRule());
assertEquals(testObj.getRuleName(), "");
assertEquals(testObj.getSymbolizer(), "");
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
String expectedRule = "rule";
Rule rule = styleFactory.createRule();
rule.setName(expectedRule);
testObj.setRule(rule);
assertEquals(testObj.getRule(), rule);
assertEquals(testObj.getRuleName(), expectedRule);
String expectedSymbolizer = "text symbolizer";
TextSymbolizer symbolizer = styleFactory.createTextSymbolizer();
symbolizer.setName(expectedSymbolizer);
testObj.setSymbolizer(symbolizer);
testObj.setFont(symbolizer.getFont());
assertEquals(testObj.getSymbolizer(), expectedSymbolizer);
// Test with font == null
assertFalse(testObj.isFontNameSet());
assertFalse(testObj.isFontStyleSet());
assertFalse(testObj.isFontWeightSet());
assertFalse(testObj.isFontSizeSet());
assertEquals(testObj.getFontName(), "");
assertEquals(testObj.getFontStyle(), "");
assertEquals(testObj.getFontWeight(), "");
assertEquals(testObj.getFontSize(), "");
assertFalse(testObj.anyChanges());
testObj.revertToOriginal();
testObj.updateFont((Font) null);
assertFalse(testObj.updateFont((SLDWriterInterface) null));
testObj.setFont(null);
testObj.updateFontSize(45);
// Set font
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
String originalFontname = "Serif";
String originalFontStyle = "normal";
String originalFontWeight = "normal";
int originalFontSize = 24;
Font font = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
testObj.setFont(font);
assertTrue(testObj.isFontNameSet());
assertTrue(testObj.isFontStyleSet());
assertTrue(testObj.isFontWeightSet());
assertTrue(testObj.isFontSizeSet());
assertFalse(testObj.isFontNameUpdated());
assertFalse(testObj.isFontStyleUpdated());
assertFalse(testObj.isFontWeightUpdated());
assertFalse(testObj.isFontSizeUpdated());
assertFalse(testObj.anyChanges());
// Update with a different copy of the same font - no changes
Font unchangedFont = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
testObj.updateFont(unchangedFont);
assertFalse(testObj.isFontNameUpdated());
assertFalse(testObj.isFontStyleUpdated());
assertFalse(testObj.isFontWeightUpdated());
assertFalse(testObj.isFontSizeUpdated());
// Update with a different copy of the same font - changes
String expectedFontName = "NewFont";
String expectedFontStyle = "italic";
String expectedFontWeight = "bold";
int expectedFontSize = 12;
Font changedFont = styleFactory.createFont(ff.literal(expectedFontName), ff.literal(expectedFontStyle), ff.literal(expectedFontWeight), ff.literal(expectedFontSize));
testObj.updateFont(changedFont);
assertTrue(testObj.isFontNameUpdated());
assertTrue(testObj.isFontStyleUpdated());
assertTrue(testObj.isFontWeightUpdated());
assertTrue(testObj.isFontSizeUpdated());
assertTrue(testObj.anyChanges());
assertEquals(testObj.getFontName(), expectedFontName);
assertEquals(testObj.getFontStyle(), expectedFontStyle);
assertEquals(testObj.getFontWeight(), expectedFontWeight);
assertEquals(testObj.getFontSize(), String.valueOf(expectedFontSize));
assertEquals(testObj.getFont(), changedFont);
// Increment font size
int expectedIncreaseFontSize = 5;
testObj.updateFontSize(expectedIncreaseFontSize);
assertEquals(testObj.getFontSize(), String.valueOf(expectedFontSize + expectedIncreaseFontSize));
// Decrease font size
expectedIncreaseFontSize *= -1;
testObj.updateFontSize(expectedIncreaseFontSize);
assertEquals(testObj.getFontSize(), String.valueOf(expectedFontSize));
// Try setting the font size less than zero
expectedIncreaseFontSize = -100;
testObj.updateFontSize(expectedIncreaseFontSize);
assertEquals(testObj.getFontSize(), String.valueOf(1));
// Update font size when font size is a function
String expectedFieldname = "fieldname";
changedFont.setSize(ff.property(expectedFieldname));
testObj.updateFont(changedFont);
expectedIncreaseFontSize = 5;
testObj.updateFontSize(expectedIncreaseFontSize);
String expectedResult = String.format("(%s+%d)", expectedFieldname, expectedIncreaseFontSize);
String actualResult = testObj.getFontSize();
assertEquals(actualResult, expectedResult);
// Revert to original
testObj.revertToOriginal();
assertFalse(testObj.isFontNameUpdated());
assertFalse(testObj.isFontStyleUpdated());
assertFalse(testObj.isFontWeightUpdated());
assertFalse(testObj.isFontSizeUpdated());
assertFalse(testObj.anyChanges());
assertEquals(testObj.getFontName(), originalFontname);
assertEquals(testObj.getFontStyle(), originalFontStyle);
assertEquals(testObj.getFontWeight(), originalFontWeight);
assertEquals(testObj.getFontSize(), String.valueOf(originalFontSize));
// Update with the changed font again
testObj.updateFont(changedFont);
SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
symbolizer.fonts().add(changedFont);
assertFalse(testObj.updateFont(sldWriter));
}
use of com.sldeditor.tool.batchupdatefont.BatchUpdateFontData in project sldeditor by robward-scisys.
the class BatchUpdateFontUtilsTest method testContainsFonts.
/**
* Test method for {@link com.sldeditor.tool.batchupdatefont.BatchUpdateFontUtils#containsFonts(com.sldeditor.common.SLDDataInterface)}.
*/
@Test
public void testContainsFonts() {
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
SelectedSymbol.getInstance().createNewSLD(sld);
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
String expectedNameLayerValue = "named layer test value";
namedLayer.setName(expectedNameLayerValue);
Style style = DefaultSymbols.createNewStyle();
String expectedNameStyleValue = "style test value";
style.setName(expectedNameStyleValue);
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedNameFTSValue = "feature type style test value";
fts.setName(expectedNameFTSValue);
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
String expectedRuleValue = "rule test value";
rule.setName(expectedRuleValue);
TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
String expectedNameValue = "symbolizer test value";
symbolizer.setName(expectedNameValue);
rule.symbolizers().add(DefaultSymbols.createDefaultPointSymbolizer());
fts.rules().add(rule);
sld.layers().add(namedLayer);
SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
String sldContents = sldWriter.encodeSLD(null, sld);
SLDData sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), sldContents);
// Empty sld
List<BatchUpdateFontData> actualList = BatchUpdateFontUtils.containsFonts(null);
assertNull(actualList);
// No fonts
actualList = BatchUpdateFontUtils.containsFonts(sldData);
assertNull(actualList);
// With textsymbolizer
rule.symbolizers().add(symbolizer);
sldContents = sldWriter.encodeSLD(null, sld);
sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), sldContents);
actualList = BatchUpdateFontUtils.containsFonts(sldData);
assertEquals(1, actualList.size());
assertEquals(rule.getName(), actualList.get(0).getRuleName());
}
Aggregations