Search in sources :

Example 11 with RenderSymbolInterface

use of com.sldeditor.datasource.RenderSymbolInterface in project sldeditor by robward-scisys.

the class SLDTree method leafSelected.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.tree.SLDTreeUpdatedInterface#leafSelected()
     */
@Override
public void leafSelected() {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) symbolTree.getLastSelectedPathComponent();
    DefaultMutableTreeNode parent = null;
    if (node != null) {
        Object nodeInfo = node.getUserObject();
        if (nodeInfo != null) {
            Class<?> classSelected = nodeInfo.getClass();
            SLDTreeItemInterface treeItem = TreeItemMap.getInstance().getValue(classSelected);
            if (treeItem != null) {
                treeItem.itemSelected(node, nodeInfo);
            }
            if (displayPanel != null) {
                Controller.getInstance().setPopulating(true);
                Class<?> parentClass = null;
                if (node.getParent() != null) {
                    parent = (DefaultMutableTreeNode) node.getParent();
                    parentClass = parent.getUserObject().getClass();
                    // Check to see if node represents a fill
                    if (classSelected == FillImpl.class) {
                        // Check to see if fill has been selected
                        Symbolizer symbolizer = (Symbolizer) parent.getUserObject();
                        if (!SLDTreeLeafFactory.getInstance().hasFill(symbolizer)) {
                            parentClass = null;
                            classSelected = null;
                        }
                    } else if (classSelected == StrokeImpl.class) {
                        // Check to see if stroke has been selected
                        Symbolizer symbolizer = (Symbolizer) parent.getUserObject();
                        if (!SLDTreeLeafFactory.getInstance().hasStroke(symbolizer)) {
                            parentClass = null;
                            classSelected = null;
                        }
                    }
                }
                displayPanel.show(parentClass, classSelected);
                Controller.getInstance().setPopulating(false);
            }
            if (renderList != null) {
                for (RenderSymbolInterface render : renderList) {
                    render.renderSymbol();
                }
            }
        }
    }
    if (treeTools != null) {
        treeTools.setButtonState(parent, node, this.currentGeometryType);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface) StrokeImpl(org.geotools.styling.StrokeImpl) SLDTreeItemInterface(com.sldeditor.ui.tree.item.SLDTreeItemInterface) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer)

Example 12 with RenderSymbolInterface

use of com.sldeditor.datasource.RenderSymbolInterface in project sldeditor by robward-scisys.

the class SingleSymbolUI method createSymbolSelectionPanel.

/**
 * Creates the symbol selection panel.
 *
 * @return the j panel
 */
public JPanel createSymbolSelectionPanel() {
    JPanel symbolPanel = new JPanel();
    symbolPanel.setLayout(new GridLayout(2, 1));
    RenderSymbolInterface renderSymbol = RenderPanelFactory.getRenderer(SingleSymbolUI.class.getName());
    symbolPanel.add((Component) renderSymbol);
    JPanel symbolTreePanel = getSymbolTree();
    symbolPanel.add(symbolTreePanel);
    return symbolPanel;
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface)

Example 13 with RenderSymbolInterface

use of com.sldeditor.datasource.RenderSymbolInterface in project sldeditor by robward-scisys.

the class SingleSymbolUI method getSymbolizerDetailsPanel.

/**
 * Gets the symbolizer details panel.
 *
 * @return the marker details panel
 */
private JPanel getSymbolizerDetailsPanel() {
    if (panelSymbolizerDetails == null) {
        List<RenderSymbolInterface> rendererList = new ArrayList<RenderSymbolInterface>();
        rendererList.add(RenderPanelFactory.getRenderer(SingleSymbolUI.class.getName()));
        rendererList.add(LegendManager.getInstance().getRendererUpdate());
        rendererList.add(SLDEditorFile.getInstance());
        rendererList.add(RenderPanelFactory.getMapRenderer());
        panelSymbolizerDetails = new SymbolizerDetailsPanel(rendererList, getSymbolTree());
    }
    return panelSymbolizerDetails;
}
Also used : RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface) ArrayList(java.util.ArrayList) SymbolizerDetailsPanel(com.sldeditor.ui.detail.SymbolizerDetailsPanel)

Example 14 with RenderSymbolInterface

use of com.sldeditor.datasource.RenderSymbolInterface in project sldeditor by robward-scisys.

the class SLDTreeTools method moveItem.

/**
 * Move item within a list. The direction parameter determines which way the item is moved.
 *
 * @param moveUp the move up flags (true), or down (false)
 */
public void moveItem(boolean moveUp) {
    if (symbolTree == null) {
        return;
    }
    if (treeModel == null) {
        return;
    }
    if (sldTree == null) {
        return;
    }
    TreePath path = symbolTree.getSelectionPath();
    if (path == null) {
        return;
    }
    DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    if (lastNode == null) {
        return;
    }
    Object obj = lastNode.getUserObject();
    if (obj == null) {
        return;
    }
    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) lastNode.getParent();
    if (parentNode == null) {
        return;
    }
    Object parentObj = parentNode.getUserObject();
    if (parentObj == null) {
        return;
    }
    // Calculate index offset value based on direction
    int direction = moveUp ? -1 : 1;
    // Store current state of the SLD before the move
    // CHECKSTYLE:OFF
    Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    if (obj instanceof StyledLayer) {
        StyledLayerDescriptor sld = (StyledLayerDescriptor) parentObj;
        // NamedLayerImpl.equals() doesn't work in the way I
        // want it to, so indexOf() does not work
        boolean found = false;
        int index = 0;
        for (StyledLayer styledLayer : sld.layers()) {
            if (styledLayer == obj) {
                found = true;
                break;
            } else {
                index++;
            }
        }
        if (found && ((index + direction) >= 0) && (index + direction) < sld.layers().size()) {
            StyledLayer styledLayer = sld.layers().remove(index);
            sld.layers().add(index + direction, styledLayer);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    } else if (obj instanceof Style) {
        if (parentObj instanceof NamedLayerImpl) {
            NamedLayerImpl namedLayer = (NamedLayerImpl) parentObj;
            int index = namedLayer.styles().indexOf(obj);
            if (((index + direction) >= 0) && (index + direction) < namedLayer.styles().size()) {
                Style style = namedLayer.styles().remove(index);
                namedLayer.styles().add(index + direction, style);
                treeModel.removeNodeFromParent(lastNode);
                treeModel.insertNodeInto(lastNode, parentNode, index + direction);
            } else {
                return;
            }
        }
    } else if (obj instanceof FeatureTypeStyle) {
        Style style = (Style) parentObj;
        int index = style.featureTypeStyles().indexOf(obj);
        if (((index + direction) >= 0) && (index + direction) < style.featureTypeStyles().size()) {
            FeatureTypeStyle fts = style.featureTypeStyles().remove(index);
            style.featureTypeStyles().add(index + direction, fts);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    } else if (obj instanceof Rule) {
        FeatureTypeStyle fts = (FeatureTypeStyle) parentObj;
        int index = fts.rules().indexOf(obj);
        if (((index + direction) >= 0) && (index + direction) < fts.rules().size()) {
            Rule rule = fts.rules().remove(index);
            fts.rules().add(index + direction, rule);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    } else if (obj instanceof Symbolizer) {
        Rule rule = (Rule) parentObj;
        int index = rule.symbolizers().indexOf(obj);
        if (((index + direction) >= 0) && (index + direction) < rule.symbolizers().size()) {
            Symbolizer symbolizer = rule.symbolizers().remove(index);
            rule.symbolizers().add(index + direction, symbolizer);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    }
    // Refresh the tree structure. Not very efficient but gets result wanted.
    // The node has been moved in the tree above. Now going to refresh model.
    treeModel.nodeStructureChanged(lastNode);
    // Get path for item moved
    TreePath newNodePath = getPath(lastNode);
    int[] selectedRows = new int[1];
    selectedRows[0] = symbolTree.getRowForPath(newNodePath);
    // Find the row of item moved
    // Now clear tree structure and re-populate, inefficient but it means
    // that all items are expanded as required.
    SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
    // Make item moved selected again
    symbolTree.setSelectionRows(selectedRows);
    // Re-render the symbol
    if (renderList != null) {
        for (RenderSymbolInterface render : renderList) {
            render.renderSymbol();
        }
    }
    // Store current state of the SLD after the move
    Object newValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    UndoManager.getInstance().addUndoEvent(new UndoEvent(sldTree.getUndoObject(), getClass().getName(), oldValueObj, newValueObj));
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TreePath(javax.swing.tree.TreePath) RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Aggregations

RenderSymbolInterface (com.sldeditor.datasource.RenderSymbolInterface)14 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)5 Test (org.junit.Test)5 PointSymbolizer (org.geotools.styling.PointSymbolizer)4 UndoEvent (com.sldeditor.common.undo.UndoEvent)3 SLDTree (com.sldeditor.ui.tree.SLDTree)3 SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)3 ArrayList (java.util.ArrayList)3 LineSymbolizer (org.geotools.styling.LineSymbolizer)3 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)3 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)3 Symbolizer (org.geotools.styling.Symbolizer)3 TreeSelectionData (com.sldeditor.TreeSelectionData)2 SLDData (com.sldeditor.common.data.SLDData)2 SymbolizerDetailsPanel (com.sldeditor.ui.detail.SymbolizerDetailsPanel)2 PopulateDetailsInterface (com.sldeditor.ui.iface.PopulateDetailsInterface)2 File (java.io.File)2 URL (java.net.URL)2 TreePath (javax.swing.tree.TreePath)2