Search in sources :

Example 46 with StyleWrapper

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

Example 47 with StyleWrapper

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;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) AbstractGridCoverage2DReader(org.geotools.coverage.grid.io.AbstractGridCoverage2DReader) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) WritableRaster(java.awt.image.WritableRaster) AbstractGridFormat(org.geotools.coverage.grid.io.AbstractGridFormat) Style(org.geotools.styling.Style) NamedLayer(org.geotools.styling.NamedLayer) File(java.io.File)

Example 48 with StyleWrapper

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;
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyleWrapper(com.sldeditor.common.data.StyleWrapper)

Example 49 with StyleWrapper

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;
}
Also used : CardLayout(java.awt.CardLayout) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyleWrapper(com.sldeditor.common.data.StyleWrapper)

Example 50 with StyleWrapper

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);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) GeoServerLayer(com.sldeditor.common.data.GeoServerLayer) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) ListSelectionModel(javax.swing.ListSelectionModel) ListSelectionListener(javax.swing.event.ListSelectionListener) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) StyleWrapper(com.sldeditor.common.data.StyleWrapper) JTable(javax.swing.JTable)

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