⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svgvisualresourcetoolkit.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        suffix=bundle.getString("vresource_duplicatednodesuffix");                    }catch (Exception ex){}                }                                //creating the new id                String id=resource.getAttribute("id");                id=frame.getId(id+suffix);                                //setting the id                resource.setAttribute("id", id);            }        }                return resource;    }        /**     * removes the given resource node     * @param frame the current frame     * @param resourceNode the resource node     */    protected void removeVisualResource(SVGFrame frame, Element resourceNode){            if(frame!=null && resourceNode!=null){            Element parentNode=(Element)resourceNode.getParentNode();                        if(parentNode!=null){            	                //removing the node from its parent                parentNode.removeChild(resourceNode);            }        }    }        /**     * appends the givn resource node to the given parent node     * @param frame a frame      * @param parentNode a parent node     * @param resourceNode a resource node     */    protected void appendVisualResource(SVGFrame frame, Element parentNode, Element resourceNode){                if(frame!=null && parentNode!=null && resourceNode!=null){            String id=resourceNode.getAttribute("id");                        if(! frame.checkId(id)){                                id=frame.getId(id);            }            //removing the node from its parent            parentNode.appendChild(resourceNode);        }    }        /**     * whether the given node can be removed or not     * @param frame the current frame     * @param resourceNode the resource node     * @return whether the given node can be removed or not     */    protected boolean canRemoveVisualResource(SVGFrame frame, Element resourceNode){                if(frame!=null && resourceNode!=null){            String id=resourceNode.getAttribute("id");                        if(! frame.isResourceUsed(id)){                                return true;            }        }                return false;    }        /**     * imports a resource node from the resource store     * @param frame the current frame     * @param parentNode the parentNode     * @param nodeToBeImported the node that should be imported     * @return the imported node     */    protected Element importVisualResource(SVGFrame frame, Element parentNode, Element nodeToBeImported){                Element resourceNode=null;        Document visualResourceStore=getVisualResources().getVisualResourceStore();        ResourceBundle bundle=getVisualResources().getBundle();                if(frame!=null && parentNode!=null && visualResourceStore!=null && nodeToBeImported!=null){              final Element defs=getVisualResources().getDefs(frame);            if(defs!=null){                                Document doc=defs.getOwnerDocument();                resourceNode=(Element)doc.importNode(nodeToBeImported, true);                                //getting the base string for the id                String baseId=resourceNode.getNodeName(), importedLabel="";                if(bundle!=null){                                        try{                        importedLabel=bundle.getString("labelimported");                        baseId="vresourcename_".concat(baseId);                        baseId=bundle.getString(baseId);                        baseId=importedLabel.concat(baseId);                        baseId=baseId.replaceAll("\\s+", "");                    }catch (Exception ex){baseId=resourceNode.getNodeName();}                }                                String id=frame.getId(baseId);                resourceNode.setAttribute("id", id);            }        }                return resourceNode;    }        /**     * gets the attribute node of the parent node given its name or creates it if it does not exist     * @param frame the current frame     * @param parentNode the parent node     * @param name the name of the attribute     * @param value the value of the attribute if it is created     * @return the attribute node     */    public Node getVisualResourceAttributeNode(SVGFrame frame, Element parentNode, String name, String value){                Node attNode=null;                if(frame!=null && parentNode!=null && name!=null && ! name.equals("")){            //gets the attribute node if it exists            attNode=parentNode.getAttributeNode(name);            if(attNode==null){                                //if the attribute node does not exist, it is created                if(value==null){                                        value="";                }                                attNode=parentNode.getOwnerDocument().createAttribute(name);                attNode.setNodeValue(value);                //appends the element to the resource node                parentNode.setAttributeNode((Attr)attNode);            }        }        return attNode;    }        /**     * creates a child of a resource node given its parent     * @param frame the current frame     * @param parentNode the parentNode to which the child will be appended     * @return the element corresponding to a child of a resource whose name is nodeName     */    protected Element createVisualResourceChildStructure(SVGFrame frame, Node parentNode){                Element resourceChild=null;                if(frame!=null && parentNode!=null){                        //creates the resource child            if(parentNode.getNodeName().equals("linearGradient") || parentNode.getNodeName().equals("radialGradient")){        		String svgNS=SVGDOMImplementation.SVG_NAMESPACE_URI;                resourceChild=parentNode.getOwnerDocument().createElementNS(svgNS, "stop");                resourceChild.setAttributeNS(null, "offset", "0%");                resourceChild.setAttributeNS(null, "style", "stop-color:#000000;stop-opacity:1.0;");            }        }                return resourceChild;    }        /**     * appends a child of a resource node to its parent     * @param frame the current frame     * @param parentNode the parentNode to which the child will be appended     * @param childNode the child of a resource node     */    protected void appendVisualResourceChild(SVGFrame frame, Node parentNode, Node childNode){        if(frame!=null && parentNode!=null && childNode!=null){                        //creates the resource child            if(parentNode.getNodeName().equals("linearGradient") || parentNode.getNodeName().equals("radialGradient")){                //appends the element to the resource node                parentNode.appendChild(childNode);            }        }    }        /**     * removes the child node from the dom     * @param frame a frame     * @param childNode the node to be removed     */    protected void removeVisualResourceChild(SVGFrame frame, Node childNode){                if(frame!=null && childNode!=null){                        final Node parentNode=childNode.getParentNode();            final Node fchildNode=childNode;                        if(parentNode!=null){                                parentNode.removeChild(fchildNode);            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -