use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class LegendManagerTest method testSLD2.
/**
* Create test SLD
*
* @return the styled layer descriptor
*/
private StyledLayerDescriptor testSLD2() {
String sldContents = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<StyledLayerDescriptor version=\"1.0.0\" " + " xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" " + " xmlns=\"http://www.opengis.net/sld\" " + " xmlns:sld=\"http://www.opengis.net/sld\" " + " xmlns:ogc=\"http://www.opengis.net/ogc\" " + " xmlns:gml=\"http://www.opengis.net/gml\" " + " xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<NamedLayer>" + " <Name>Attribute-based polygon</Name>" + " <UserStyle>" + " <Title>SLD Cook Book: Attribute-based polygon</Title>" + " <FeatureTypeStyle>" + " <Rule>" + " <Name>SmallPop</Name>" + " <Title>Less Than 200,000</Title>" + " <ogc:Filter>" + " <ogc:PropertyIsLessThan>" + " <ogc:PropertyName>pop</ogc:PropertyName>" + " <ogc:Literal>200000</ogc:Literal>" + " </ogc:PropertyIsLessThan>" + " </ogc:Filter>" + " <PolygonSymbolizer>" + " <Fill>" + " <CssParameter name=\"fill\">#66FF66</CssParameter>" + " </Fill>" + " </PolygonSymbolizer>" + " </Rule>" + " <Rule>" + " <Name>MediumPop</Name>" + " <Title>200,000 to 500,000</Title>" + " <ogc:Filter>" + " <ogc:And>" + " <ogc:PropertyIsGreaterThanOrEqualTo>" + " <ogc:PropertyName>pop</ogc:PropertyName>" + " <ogc:Literal>200000</ogc:Literal>" + " </ogc:PropertyIsGreaterThanOrEqualTo>" + " <ogc:PropertyIsLessThan>" + " <ogc:PropertyName>pop</ogc:PropertyName>" + " <ogc:Literal>500000</ogc:Literal>" + " </ogc:PropertyIsLessThan>" + " </ogc:And>" + " </ogc:Filter>" + " <PolygonSymbolizer>" + " <Fill>" + " <CssParameter name=\"fill\">#33CC33</CssParameter>" + " </Fill>" + " </PolygonSymbolizer>" + " </Rule>" + " <Rule>" + " <Name>LargePop</Name>" + " <Title>Greater Than 500,000</Title>" + " <ogc:Filter>" + " <ogc:PropertyIsGreaterThan>" + " <ogc:PropertyName>pop</ogc:PropertyName>" + " <ogc:Literal>500000</ogc:Literal>" + " </ogc:PropertyIsGreaterThan>" + " </ogc:Filter>" + " <PolygonSymbolizer>" + " <Fill>" + " <CssParameter name=\"fill\">#009900</CssParameter>" + " </Fill>" + " </PolygonSymbolizer>" + " </Rule>" + " </FeatureTypeStyle>" + " </UserStyle>" + " </NamedLayer>" + "</StyledLayerDescriptor>";
SLDData sldData = new SLDData(new StyleWrapper(null, "test.sld"), sldContents);
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
return sld;
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class RasterReader method createRasterSLDData.
/**
* Creates the raster sld.
*
* @param rasterFile the raster file
* @return the styled layer descriptor
*/
@Override
public SLDDataInterface createRasterSLDData(File rasterFile) {
if (rasterFile == null) {
return null;
}
StyledLayerDescriptor sld = null;
AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile);
AbstractGridCoverage2DReader reader = null;
try {
reader = format.getReader(rasterFile);
} catch (UnsupportedOperationException e) {
ConsoleManager.getInstance().error(this, Localisation.getField(RasterTool.class, "RasterReader.unknownFormat") + rasterFile.getAbsolutePath());
return null;
}
BufferedImage img = null;
try {
img = ImageIO.read(rasterFile);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
return null;
}
WritableRaster raster = img.getRaster();
Style style = createRGBStyle(reader, raster);
sld = sf.createStyledLayerDescriptor();
NamedLayer namedLayer = sf.createNamedLayer();
namedLayer.addStyle(style);
sld.addStyledLayer(namedLayer);
File sldFilename = ExternalFilenames.createSLDFilename(rasterFile);
StyleWrapper styleWrapper = new StyleWrapper(sldFilename.getName());
String sldContents = sldWriter.encodeSLD(null, sld);
SLDData sldData = new SLDData(styleWrapper, sldContents);
sldData.setSLDFile(sldFilename);
sldData.setReadOnly(false);
return sldData;
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class GeoServerStyleTree method getSelectedStyle.
/**
* Gets the selected style.
*
* @return the selected style
*/
public StyleWrapper getSelectedStyle() {
StyleWrapper selectedStyle = null;
TreePath selectedStylePath = geoserverStyleTree.getSelectionPath();
if ((selectedStylePath != null) && (selectedStylePath.getPathCount() == 3)) {
selectedStyle = new StyleWrapper();
selectedStyle.setWorkspace((String) ((DefaultMutableTreeNode) selectedStylePath.getPathComponent(1)).getUserObject());
selectedStyle.setStyle((String) ((DefaultMutableTreeNode) selectedStylePath.getPathComponent(2)).getUserObject());
}
return selectedStyle;
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class GeoServerStyleTree method populate.
/**
* Populate.
*
* @param geoserverName the geoserver name
* @param styleMap the style map
*/
public void populate(String geoserverName, Map<String, List<StyleWrapper>> styleMap) {
populating = true;
CardLayout cardLayout = (CardLayout) styleCardPanel.getLayout();
cardLayout.show(styleCardPanel, EMPTY_PANEL);
setButtonState(false);
// this removes all nodes
rootNode.removeAllChildren();
if (styleMap == null) {
rootNode.setUserObject(NOT_CONNECTED);
} else {
rootNode.setUserObject((geoserverName != null) ? geoserverName : CONNECTED_GEOSERVER);
for (String workspaceName : styleMap.keySet()) {
List<StyleWrapper> styleList = styleMap.get(workspaceName);
DefaultMutableTreeNode workspaceNode = new DefaultMutableTreeNode(workspaceName);
// It is key to invoke this on the TreeModel, and NOT DefaultMutableTreeNode
treeModel.insertNodeInto(workspaceNode, rootNode, rootNode.getChildCount());
for (StyleWrapper styleWrapper : styleList) {
LayerStyleNode childNode = new LayerStyleNode(styleWrapper);
// It is key to invoke this on the TreeModel, and NOT DefaultMutableTreeNode
treeModel.insertNodeInto(childNode, workspaceNode, workspaceNode.getChildCount());
}
}
}
// this notifies the listeners and changes the GUI
treeModel.reload();
populating = false;
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class ConfigureLayerStyleDialog method createUI.
/**
* Creates the ui.
*/
private void createUI() {
JPanel panel = new JPanel();
getContentPane().add(panel, BorderLayout.CENTER);
panel.setLayout(new BorderLayout(0, 0));
table = new JTable(dataModel);
dataModel.setColumnRenderer(table.getColumnModel());
ListSelectionModel selectionModel = table.getSelectionModel();
selectionModel.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
// Get selected rows and find the selected style.
// If the selected layers all don't use the same style
// then set to null
int[] selectedRows = table.getSelectedRows();
StyleWrapper selectedLayerStyle = null;
boolean isUniqueStyle = true;
for (int index = 0; index < selectedRows.length; index++) {
GeoServerLayer layer = dataModel.getLayer(selectedRows[index]);
if (selectedLayerStyle == null) {
selectedLayerStyle = layer.getStyle();
} else if (isUniqueStyle) {
if (selectedLayerStyle.compareTo(layer.getStyle()) != 0) {
isUniqueStyle = false;
}
}
}
geoServerStyleTree.select(isUniqueStyle ? selectedLayerStyle : null);
}
});
JScrollPane scrollPane = new JScrollPane(table);
panel.add(scrollPane, BorderLayout.CENTER);
//
// Button panel
//
JPanel buttonPanel = new JPanel();
FlowLayout flowLayout = (FlowLayout) buttonPanel.getLayout();
flowLayout.setAlignment(FlowLayout.TRAILING);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
JButton btnOk = new JButton(Localisation.getString(ConfigureLayerStyleDialog.class, "common.ok"));
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
okButtonPressed = false;
updatedLayerList = dataModel.getUpdatedLayers();
if (!updatedLayerList.isEmpty()) {
okButtonPressed = true;
}
setVisible(false);
}
});
buttonPanel.add(btnOk);
JButton btnCancel = new JButton(Localisation.getString(ConfigureLayerStyleDialog.class, "common.cancel"));
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
okButtonPressed = false;
setVisible(false);
}
});
buttonPanel.add(btnCancel);
geoServerStyleTree = new GeoServerStyleTree(this);
getContentPane().add(geoServerStyleTree, BorderLayout.EAST);
}
Aggregations