use of com.sldeditor.ui.tree.SLDTreeTools in project sldeditor by robward-scisys.
the class SLDTreeToolsTest method testAddNewThingNamedLayer.
/**
* Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#addNewThing()}.
*/
@Test
public void testAddNewThingNamedLayer() {
SLDTreeTools treeTools = new SLDTreeTools();
TestSLDTree sldTree = new TestSLDTree(null, treeTools);
treeTools.addNewThing(null);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
// Start off with just a top level SLD and no structure below it
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
SelectedSymbol.getInstance().setSld(sld);
sldTree.populateSLD();
sldTree.selectFirstSymbol();
DefaultMutableTreeNode rootNode = sldTree.getRootNode();
// Check it has no structure below just the root node
assertEquals(0, rootNode.getChildCount());
// Add a thing - a quick way of creating sld structure
// This should add a named layer and select it
treeTools.addNewThing(NamedLayer.class);
assertEquals(1, rootNode.getChildCount());
DefaultMutableTreeNode namedLayer = (DefaultMutableTreeNode) rootNode.getChildAt(0);
assertEquals(NamedLayerImpl.class, namedLayer.getUserObject().getClass());
// This should add a style and select it
assertEquals(0, namedLayer.getChildCount());
treeTools.addNewThing(null);
assertEquals(1, namedLayer.getChildCount());
DefaultMutableTreeNode styleLayer = (DefaultMutableTreeNode) namedLayer.getChildAt(0);
assertEquals(StyleImpl.class, styleLayer.getUserObject().getClass());
// This should add a feature type style and select it
assertEquals(0, styleLayer.getChildCount());
treeTools.addNewThing(null);
assertEquals(1, styleLayer.getChildCount());
DefaultMutableTreeNode featureTypeStyle = (DefaultMutableTreeNode) styleLayer.getChildAt(0);
assertEquals(FeatureTypeStyleImpl.class, featureTypeStyle.getUserObject().getClass());
// This should add a rule and select it
assertEquals(0, featureTypeStyle.getChildCount());
treeTools.addNewThing(null);
assertEquals(1, featureTypeStyle.getChildCount());
DefaultMutableTreeNode rule = (DefaultMutableTreeNode) featureTypeStyle.getChildAt(0);
assertEquals(RuleImpl.class, rule.getUserObject().getClass());
// This should do nothing
assertEquals(0, rule.getChildCount());
treeTools.addNewThing(null);
assertEquals(0, rule.getChildCount());
// Undo last add of rule to feature type style
UndoManager.getInstance().undo();
DefaultMutableTreeNode featureTypeStyleNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0);
assertEquals(FeatureTypeStyleImpl.class, featureTypeStyleNode.getUserObject().getClass());
assertEquals(0, featureTypeStyleNode.getChildCount());
// Undo last add of rule to feature type style
UndoManager.getInstance().redo();
featureTypeStyleNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0);
assertEquals(FeatureTypeStyleImpl.class, featureTypeStyleNode.getUserObject().getClass());
assertEquals(1, featureTypeStyleNode.getChildCount());
}
use of com.sldeditor.ui.tree.SLDTreeTools in project sldeditor by robward-scisys.
the class SLDTreeTest method testSLDTree.
/**
* Test method for {@link com.sldeditor.ui.tree.SLDTree#SLDTree(java.util.List)} using values.
* Test method for {@link
* com.sldeditor.ui.tree.SLDTree#addSymbolSelectedListener(com.sldeditor.ui.iface.SymbolizerSelectedInterface)}.
* Test method for {@link com.sldeditor.ui.tree.SLDTree#selectFirstSymbol()}. Test method for
* {@link com.sldeditor.ui.tree.SLDTree#selectTreeItem(com.sldeditor.TreeSelectionData)}. Test
* method for {@link com.sldeditor.ui.tree.SLDTree#getSelectedSymbolPanel()}. Test method for
* {@link com.sldeditor.ui.tree.SLDTree#leafSelected()}.
*/
@Test
public void testSLDTree() {
List<RenderSymbolInterface> renderList = null;
SLDTreeTools treeTools = new SLDTreeTools();
SLDTree tree1 = new SLDTree(renderList, treeTools);
String testsldfile = "/test/polygon_line_point.sld";
InputStream inputStream = SLDTreeTest.class.getResourceAsStream(testsldfile);
String sldContents = "";
if (inputStream == null) {
assertNotNull(inputStream, "Failed to find sld test file : " + testsldfile);
} else {
File f = null;
try {
f = SLDTestRunner.stream2file(inputStream);
sldContents = readFile(f.getAbsolutePath());
f.delete();
} catch (IOException e1) {
e1.printStackTrace();
}
}
SLDData sldData = new SLDData(null, sldContents);
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
SelectedSymbol.getInstance().setSld(sld);
try {
SymbolizerDetailsPanel symbolizerSelectedPanel = new SymbolizerDetailsPanel(null, null);
tree1.addSymbolSelectedListener(symbolizerSelectedPanel);
tree1.populateSLD();
// Nothing selected at this stage
tree1.leafSelected();
PopulateDetailsInterface panel = tree1.getSelectedSymbolPanel();
assertNull(panel);
// Select top level node
tree1.selectFirstSymbol();
tree1.leafSelected();
panel = tree1.getSelectedSymbolPanel();
assertEquals(EmptyPanel.class, panel.getClass());
// Select layer
TreeSelectionData selectedTreeData = new TreeSelectionData();
selectedTreeData.setLayerIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(NamedLayerDetails.class, panel.getClass());
// Select style
selectedTreeData.setStyleIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(StyleDetails.class, panel.getClass());
// Select feature type style
selectedTreeData.setFeatureTypeStyleIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(FeatureTypeStyleDetails.class, panel.getClass());
// Select rule
selectedTreeData.setRuleIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(RuleDetails.class, panel.getClass());
// Select polygon symbolizer
selectedTreeData.setSelectedPanel(PolygonSymbolizerDetails.class);
selectedTreeData.setSymbolizerIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(PolygonSymbolizerDetails.class, panel.getClass());
// Select line symbolizer
selectedTreeData.setSelectedPanel(LineSymbolizerDetails.class);
selectedTreeData.setRuleIndex(1);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(LineSymbolizerDetails.class, panel.getClass());
// Select point symbolizer
selectedTreeData.setSelectedPanel(PointSymbolizerDetails.class);
selectedTreeData.setRuleIndex(2);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(PointSymbolizerDetails.class, panel.getClass());
// Select text symbolizer
selectedTreeData.setSelectedPanel(TextSymbolizerDetails.class);
selectedTreeData.setSymbolizerIndex(1);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(TextSymbolizerDetails.class, panel.getClass());
// Select raster symbolizer
selectedTreeData.setSelectedPanel(RasterSymbolizerDetails.class);
selectedTreeData.setSymbolizerIndex(2);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(RasterSymbolizerDetails.class, panel.getClass());
// Select polygon symbolizer / fill
selectedTreeData.setSelectedPanel(PolygonFillDetails.class);
selectedTreeData.setSymbolizerIndex(0);
selectedTreeData.setSymbolizerDetailIndex(0);
selectedTreeData.setRuleIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(PolygonFillDetails.class, panel.getClass());
// Select polygon symbolizer / stroke
selectedTreeData.setSelectedPanel(StrokeDetails.class);
selectedTreeData.setSymbolizerDetailIndex(1);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(StrokeDetails.class, panel.getClass());
// Select point symbolizer / fill
selectedTreeData.setSelectedPanel(PointFillDetails.class);
selectedTreeData.setRuleIndex(2);
selectedTreeData.setSymbolizerIndex(0);
selectedTreeData.setSymbolizerDetailIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(PointFillDetails.class, panel.getClass());
// Select line symbolizer / stroke
selectedTreeData.setSelectedPanel(StrokeDetails.class);
selectedTreeData.setRuleIndex(1);
selectedTreeData.setSymbolizerIndex(0);
selectedTreeData.setSymbolizerDetailIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(StrokeDetails.class, panel.getClass());
// Error cases
selectedTreeData.setSymbolizerDetailIndex(-2);
assertFalse(tree1.selectTreeItem(selectedTreeData));
selectedTreeData.setSymbolizerDetailIndex(1);
assertFalse(tree1.selectTreeItem(selectedTreeData));
} catch (Exception e) {
e.printStackTrace();
assertTrue(false);
}
}
use of com.sldeditor.ui.tree.SLDTreeTools in project sldeditor by robward-scisys.
the class SLDTreeToolsTest method testAddNewText.
/**
* Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#addNewText()}.
*/
@Test
public void testAddNewText() {
SLDTreeTools treeTools = new SLDTreeTools();
TestSLDTree sldTree = new TestSLDTree(null, treeTools);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
// Start off with just a top level SLD and no structure below it
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
SelectedSymbol.getInstance().setSld(sld);
sldTree.populateSLD();
sldTree.selectFirstSymbol();
treeTools.addNewThing(NamedLayer.class);
treeTools.addNewThing(null);
treeTools.addNewThing(null);
treeTools.addNewThing(null);
DefaultMutableTreeNode rootNode = sldTree.getRootNode();
// Make sure we have a rule selected
DefaultMutableTreeNode rule = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
assertEquals(RuleImpl.class, rule.getUserObject().getClass());
assertEquals(0, rule.getChildCount());
treeTools.addNewText();
DefaultMutableTreeNode textNode = (DefaultMutableTreeNode) rule.getChildAt(0);
assertEquals(TextSymbolizerImpl.class, textNode.getUserObject().getClass());
}
use of com.sldeditor.ui.tree.SLDTreeTools in project sldeditor by robward-scisys.
the class SLDTreeToolsTest method testAddArrows.
/**
* Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#addSourceArrow()}. Test method for
* {@link com.sldeditor.ui.tree.SLDTreeTools#addDestArrow()}.
*/
@Test
public void testAddArrows() {
SLDTreeTools treeTools = new SLDTreeTools();
TestSLDTree sldTree = new TestSLDTree(null, treeTools);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
// Start off with just a top level SLD and no structure below it
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
SelectedSymbol.getInstance().setSld(sld);
sldTree.populateSLD();
sldTree.selectFirstSymbol();
treeTools.addNewThing(NamedLayer.class);
treeTools.addNewThing(null);
treeTools.addNewThing(null);
treeTools.addNewThing(null);
DefaultMutableTreeNode rootNode = sldTree.getRootNode();
// Make sure we have a rule selected
DefaultMutableTreeNode rule = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
assertEquals(RuleImpl.class, rule.getUserObject().getClass());
assertEquals(0, rule.getChildCount());
treeTools.addNewLine();
treeTools.addSourceArrow();
treeTools.addDestArrow();
DefaultMutableTreeNode lineNode = (DefaultMutableTreeNode) rule.getChildAt(0);
assertEquals(LineSymbolizerImpl.class, lineNode.getUserObject().getClass());
DefaultMutableTreeNode srcArrowNode = (DefaultMutableTreeNode) rule.getChildAt(1);
assertEquals(PointSymbolizerImpl.class, srcArrowNode.getUserObject().getClass());
DefaultMutableTreeNode destArrowNode = (DefaultMutableTreeNode) rule.getChildAt(2);
assertEquals(PointSymbolizerImpl.class, destArrowNode.getUserObject().getClass());
}
use of com.sldeditor.ui.tree.SLDTreeTools in project sldeditor by robward-scisys.
the class SLDTreeToolsTest method testMoveItemRules.
/**
* Check Rules Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#moveItem(boolean)}.
*/
@Test
public void testMoveItemRules() {
SLDTreeTools treeTools = new SLDTreeTools();
TestSLDTree sldTree = new TestSLDTree(null, treeTools);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
// Start off with just a top level SLD and no structure below it
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
SelectedSymbol.getInstance().setSld(sld);
sldTree.populateSLD();
sldTree.selectFirstSymbol();
treeTools.addNewThing(NamedLayer.class);
treeTools.addNewThing(null);
treeTools.addNewThing(null);
treeTools.addNewThing(null);
DefaultMutableTreeNode rootNode = sldTree.getRootNode();
DefaultMutableTreeNode rule1Node = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
RuleImpl rule1 = (RuleImpl) rule1Node.getUserObject();
String expectedRule1 = "rule 1";
rule1.setName(expectedRule1);
TreeSelectionData data = new TreeSelectionData();
data.setLayerIndex(0);
data.setStyleIndex(0);
data.setFeatureTypeStyleIndex(0);
sldTree.selectTreeItem(data);
treeTools.addNewThing(null);
DefaultMutableTreeNode rule2Node = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(1);
RuleImpl rule2 = (RuleImpl) rule2Node.getUserObject();
String expectedRule2 = "rule 2";
rule2.setName(expectedRule2);
// Have 2 styles
data = new TreeSelectionData();
data.setLayerIndex(0);
data.setStyleIndex(0);
data.setFeatureTypeStyleIndex(0);
data.setRuleIndex(1);
sldTree.selectTreeItem(data);
// Move style 2 so that they are reversed
treeTools.moveItem(true);
DefaultMutableTreeNode testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
RuleImpl testRule = (RuleImpl) testNode.getUserObject();
assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
// Try and move 'style 2' up to index -1 which is invalid, result should be same as last
// time
data.setRuleIndex(0);
sldTree.selectTreeItem(data);
treeTools.moveItem(true);
testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
testRule = (RuleImpl) testNode.getUserObject();
assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
// Move it back
data.setRuleIndex(0);
sldTree.selectTreeItem(data);
treeTools.moveItem(false);
testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(1);
testRule = (RuleImpl) testNode.getUserObject();
assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
// Move it beyond the end of the list, should be the same answer as before
data.setRuleIndex(1);
sldTree.selectTreeItem(data);
treeTools.moveItem(false);
testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(1);
testRule = (RuleImpl) testNode.getUserObject();
assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
// Undo the last valid move
UndoManager.getInstance().undo();
testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
testRule = (RuleImpl) testNode.getUserObject();
assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
// Redo the last valid move
UndoManager.getInstance().redo();
testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(1);
testRule = (RuleImpl) testNode.getUserObject();
assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
}
Aggregations