Search in sources :

Example 11 with StyleWrapper

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));
}
Also used : JPanel(javax.swing.JPanel) ActionListener(java.awt.event.ActionListener) ToolButton(com.sldeditor.tool.ToolButton) StyleWrapper(com.sldeditor.common.data.StyleWrapper) ActionEvent(java.awt.event.ActionEvent) Dimension(java.awt.Dimension) Map(java.util.Map)

Example 12 with StyleWrapper

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();
        }
    }
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 13 with StyleWrapper

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;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) MalformedURLException(java.net.MalformedURLException) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) File(java.io.File)

Example 14 with StyleWrapper

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;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) File(java.io.File)

Example 15 with StyleWrapper

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());
}
Also used : GeoServerLayer(com.sldeditor.common.data.GeoServerLayer) StyleWrapper(com.sldeditor.common.data.StyleWrapper) Test(org.junit.Test)

Aggregations

StyleWrapper (com.sldeditor.common.data.StyleWrapper)59 SLDData (com.sldeditor.common.data.SLDData)35 Test (org.junit.Test)31 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)15 File (java.io.File)14 SLDDataInterface (com.sldeditor.common.SLDDataInterface)12 ArrayList (java.util.ArrayList)12 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)10 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)9 List (java.util.List)9 GeoServerLayer (com.sldeditor.common.data.GeoServerLayer)8 IOException (java.io.IOException)8 GeoServerInput (com.sldeditor.extension.filesystem.geoserver.GeoServerInput)7 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 GeoServerStyleNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode)5 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)5 HashMap (java.util.HashMap)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)4 NamedLayer (org.geotools.styling.NamedLayer)4