use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class GeoServerLayerUpdateTool method createUI.
/**
* Creates the ui.
*/
private void createUI() {
panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(GeoServerLayerUpdateTool.class, "GeoServerLayerUpdateTool.title")));
button = new ToolButton(Localisation.getString(GeoServerLayerUpdateTool.class, "GeoServerLayerUpdateTool.layer"), "tool/layerupdate.png");
button.setEnabled(true);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ConfigureLayerStyleDialog dlg = new ConfigureLayerStyleDialog();
Map<String, List<StyleWrapper>> styleMap = geoServerLayerUpdate.getStyleMap(connection);
if (dlg.populate(styleMap, layerList)) {
geoServerLayerUpdate.updateLayerStyle(dlg.getUpdatedLayerStyles());
}
}
});
panel.add(button);
panel.setPreferredSize(new Dimension(PANEL_WIDTH, ToolPanel.TOOL_PANEL_HEIGHT));
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class ExportHTML method save.
/**
* Save all html to folder.
*
* @param destinationFolder the destination folder
* @param filename the filename
* @param sldDataList the sld data list
* @param backgroundColour the background colour
*/
public static void save(File destinationFolder, String filename, List<SLDDataInterface> sldDataList, Color backgroundColour) {
if (!destinationFolder.exists()) {
destinationFolder.mkdirs();
}
InputStream inputStream = ExportHTML.class.getResourceAsStream(HTML_TEMPLATE);
if (inputStream == null) {
ConsoleManager.getInstance().error(ExportHTML.class, "Failed to find html template");
} else {
String htmlTemplate = null;
BufferedReader reader = null;
File file = null;
try {
file = stream2file(inputStream);
reader = new BufferedReader(new FileReader(file));
String line = null;
StringBuilder stringBuilder = new StringBuilder();
String ls = System.getProperty("line.separator");
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append(ls);
}
htmlTemplate = stringBuilder.toString();
} catch (Exception e) {
ConsoleManager.getInstance().exception(ExportHTML.class, e);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
ConsoleManager.getInstance().exception(ExportHTML.class, e);
}
}
}
StringBuilder sb = new StringBuilder();
sb.append(" <tr>\n");
sb.append(" <th>Layer Name</th>\n");
sb.append(" <th>Legend</th>\n");
sb.append(" </tr>\n");
for (SLDDataInterface sldData : sldDataList) {
StyleWrapper styleWrapper = sldData.getStyle();
String layerName = styleWrapper.getStyle();
sb.append(" <tr>\n");
sb.append(String.format(" <td>%s</td>\n", layerName));
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
if (sld != null) {
String showHeading = null;
String showFilename = null;
List<String> legendFileNameList = new ArrayList<String>();
boolean result = LegendManager.getInstance().saveLegendImage(sld, destinationFolder, layerName, showHeading, showFilename, legendFileNameList);
if (result) {
String legendFilename = legendFileNameList.get(0);
sb.append(String.format(" <td><img src=\"%s\" alt=\"%s\" ></td>\n", legendFilename, layerName));
}
}
sb.append(" </tr>\n");
}
if (htmlTemplate != null) {
htmlTemplate = htmlTemplate.replace(TEMPLATE_INSERT_CODE, sb.toString());
PrintWriter out;
try {
File f = new File(destinationFolder, filename);
out = new PrintWriter(f);
out.println(htmlTemplate);
out.close();
} catch (FileNotFoundException e) {
ConsoleManager.getInstance().exception(ExportHTML.class, e);
}
}
if (file != null) {
file.delete();
}
}
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class VectorReader method createVectorSLDData.
/**
* Creates the vector sld.
*
* @param vectorFile the vector file
* @return the styled layer descriptor
*/
@Override
public SLDDataInterface createVectorSLDData(File vectorFile) {
if (vectorFile == null) {
return null;
}
Map<String, Object> map = null;
try {
map = DataSourceProperties.encodeFilename(vectorFile.toURI().toURL().toString());
} catch (MalformedURLException e) {
ConsoleManager.getInstance().exception(this, e);
return null;
}
StyledLayerDescriptor sld = createSLDData(map, null);
SLDData sldData = null;
if (sld != null) {
File sldFilename = ExternalFilenames.createSLDFilename(vectorFile);
StyleWrapper styleWrapper = new StyleWrapper(sldFilename.getName());
String sldContents = sldWriter.encodeSLD(null, sld);
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 VectorReader method createVectorSLDData.
/*
* (non-Javadoc)
*
* @see com.sldeditor.tool.vector.VectorReaderInterface#createVectorSLDData(com.sldeditor.common.data.DatabaseConnection, java.lang.String)
*/
@Override
public SLDDataInterface createVectorSLDData(DatabaseConnection databaseConnection, String featureClass) {
if ((databaseConnection == null) || (featureClass == null)) {
return null;
}
Map<String, Object> map = DatabaseConnectionManager.getInstance().getDBConnectionParams(databaseConnection);
StyledLayerDescriptor sld = createSLDData(map, featureClass);
SLDData sldData = null;
if (sld != null) {
File sldFilename = null;
StyleWrapper styleWrapper = new StyleWrapper(featureClass);
String sldContents = sldWriter.encodeSLD(null, sld);
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 GeoServerLayerTest method testGetStyle.
/**
* Test method for {@link com.sldeditor.common.data.GeoServerLayer#getStyle()}.
* Test method for {@link com.sldeditor.common.data.GeoServerLayer#setStyle(com.sldeditor.common.data.StyleWrapper)}.
*/
@Test
public void testGetStyle() {
StyleWrapper styleWrapper = new StyleWrapper();
styleWrapper.setStyle("style");
styleWrapper.setStyle("workspace");
GeoServerLayer layer = new GeoServerLayer();
layer.setStyle(styleWrapper);
assertEquals(styleWrapper, layer.getStyle());
}
Aggregations