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

📄 svgproperties.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
						defineList.add(cur);											//adds all the predefined "tab" nodes to the map						for(tab=cur.getFirstChild(); tab!=null; tab=tab.getNextSibling()){						    							if(tab.getNodeName().equals("tab")){								try{name=((Element)tab).getAttribute("name");}catch (Exception ex){name="";}															if(name!=null && ! name.equals("")){								    								    tabMap.put(name, tab.cloneNode(true));								}							}						}					}				}							//removes all the "define" nodes from the root node				for(Iterator it=defineList.iterator(); it.hasNext();){				    					try{root.removeChild((Node)it.next());}catch (Exception ex){}				}								defineList.clear();				//the list of the "tab" nodes to add to the "module" node				LinkedList tabList=new LinkedList();				Node use=null;							//appends the tab nodes to the node that define a link to a predefined tab				for(cur=root.getFirstChild(); cur!=null; cur=cur.getNextSibling()){									if(cur.getNodeName().equals("module")){											//gets the "use" nodes defined in the "module" node and the "tab" nodes that will be used to replace them						for(use=cur.getFirstChild(); use!=null; use=use.getNextSibling()){						    							if(use.getNodeName().equals("use")){							    								try{name=((Element)use).getAttribute("name");}catch(Exception ex){name="";}															//adds the tab node to the list								if(name!=null && !name.equals("")){								    									tab=(Node)tabMap.get(name);																		if(tab!=null){									    									    tabList.add(tab.cloneNode(true));									}								}															}else if(use.getNodeName().equals("tab")){							    								tabList.add(use.cloneNode(true));							}						}											//removes all the child nodes from the "module" node						for(tab=cur.getFirstChild(); tab!=null; tab=cur.getFirstChild()){						    							cur.removeChild(tab);						}												//appends all the "tab" nodes to the "module" node												for(Iterator it=tabList.iterator(); it.hasNext();){						    							try{cur.appendChild((Node)it.next());}catch (Exception ex){}						}					}										//initializes the list of "tab" nodes					tabList.clear();				}			}		}		return doc;	}		/**	 *  gets the subtree describing the properties that can be changed for the given list of nodes	 * @param list a list of nodes	 * @return the subtree	 */	protected Node getXMLProperties(LinkedList list){				Node subTree=null;				if(list !=null && list.size()>0){			Node current=null;			String name="";			Iterator it=list.iterator();						try{				current=(Node)it.next();				subTree=getXMLProperties(current);				name=current.getNodeName();			}catch (Exception ex){return null;}						while(it.hasNext()){			    				try{					current=(Node)it.next();				}catch (Exception ex){current=null;}								if(current!=null){										if(name!=null && ! name.equals(current.getNodeName())){					    					    subTree=intersectXMLProperties(subTree, getXMLProperties(current));					}										name=current.getNodeName();				}			}		}				return subTree;	}		/**	 * gets a subtree that contains the nodes that can be found in the node1 subtree AND in the node2 subtree	 * @param node1 a subtree	 * @param node2 a subtree	 * @return a subtree that contains the nodes that can be found in the node1 subtree AND in the node2 subtree	 */	protected Node intersectXMLProperties(Node node1, Node node2){	    		Node node=null;				if(node1!=null && node2!=null){		    			//clones the node			node=node1.cloneNode(false);						//removes all of its children			while(node.hasChildNodes()){			    			    node.removeChild(node.getFirstChild());			}						Node 	tab=null, ctab=null, tab2=null, 						property=null, cproperty=null, property2=null;			String name=null;						for(tab=node1.getFirstChild(); tab!=null; tab=tab.getNextSibling()){				if(tab.getNodeName().equals("tab")){				    					//for each tab in node1, tests if it is in node2					if((tab2=getTab(node2, tab))!=null){					    						//clones the node						ctab=tab.cloneNode(false);												//removes all of its children						while(ctab.hasChildNodes()){						    						    ctab.removeChild(ctab.getFirstChild());						}												node.appendChild(ctab);												//for each property in the current tab in node1, tests if it is in node2						for(property=tab.getFirstChild(); property!=null;property=property.getNextSibling()){														if((property2=getProperty(tab2, property))!=null){							    								//clones the node								cproperty=property.cloneNode(true);								//appends it to the tab								ctab.appendChild(cproperty);								}						}					}				}			}		}				return node;	}		/**	 * 	 * @param node a subtree	 * @param tab a node whose name is "tab"	 * @return the tab node whose attribute name is equal to the attribute name of the given tab or null if the node does not contain the tab	 */	protected Node getTab(Node node, Node tab){				if(node!=null && tab!=null && tab.getNodeName().equals("tab")){		    			Node tab2=null;			String tabName="";						//gets the value of the name attribute of the tab			try{				Element element=(Element)tab;				tabName=element.getAttribute("name");			}catch (Exception ex){tabName="";}						if(tabName!=null && ! tabName.equals("")){								String name="";				//for each tab in node2, test if it has the same name as the given tab				for(tab2=node.getFirstChild(); tab2!=null; tab2=tab2.getNextSibling()){										if(tab2.getNodeName().equals("tab")){					    						//gets the value of the name attribute of the tab						try{							Element element=(Element)tab2;							name=element.getAttribute("name");						}catch (Exception ex){name="";}												if(name!=null && name.equals(tabName)){						    						    return tab2;						}					}				}			}		}				return null;	}		/**	 * @param tab the tab in which the property is contained	 * @param property the property node	 * @return the property node whose attribute name is equal to the attribute name of the given property 	 * or null if the node does not contain the property	 */	protected Node getProperty(Node tab, Node property){				if(tab!=null && property!=null && property instanceof Element){						Node prop=null;			String propertyName="", propertyType="", propertyName2="", propertyType2="";						//gets the name and type of the given property			try{				Element element=(Element)property;				propertyName=element.getAttribute("name");				propertyType=element.getAttribute("type");			}catch (Exception ex){return null;}						if(propertyName!=null && ! propertyName.equals("") && propertyType!=null && ! propertyType.equals("")){				for(prop=tab.getFirstChild(); prop!=null; prop=prop.getNextSibling()){				    					//if the node is a property node					if(prop.getNodeName().equals("property")){						//gets the name and type of the current node						try{							Element element=(Element)prop;							propertyName2=element.getAttribute("name");							propertyType2=element.getAttribute("type");						}catch (Exception ex){propertyName2=null; propertyType2=null;}												//tests if the current property name and type are equal to the gievn property name and type						if(propertyName2!=null && propertyType2!=null 							&& propertyName2.equals(propertyName) && propertyType2.equals(propertyType)){						    								return prop;						}					}				}			}		}				return null;	}		/**	 * gets the subtree describing the properties that can be changed for the type of the given node	 * @param node a node	 * @return the subtree	 */	protected Node getXMLProperties(Node node){				if(docProperties!=null && node!=null){		    			String name=node.getNodeName();						if(name!=null && ! name.equals("")){			    				Document docPrp=(Document)docProperties.cloneNode(true);				Element root=docPrp.getDocumentElement();								if(root!=null){				    				    Node current=null;					String cname="";										//for each root child, searches the one whom value of the "name" attribute is the type of the given node					for(current=root.getFirstChild(); current!=null; current=current.getNextSibling()){					    						if(current.getNodeName().equals("module")){						    							cname=((Element)current).getAttribute("name");														if(cname!=null && cname.equals(name)){							    							    break;							}						}					}										if(current!=null){					    						return current;					}				}			}		}				return null;	}		/**	 * @param nodelist the list of the selected nodes	 * @param subTree a node 	 * @return the list of the property item objects	 */	protected LinkedList getPropertyList(LinkedList nodelist, Node subTree){				LinkedList list=new LinkedList();				if(subTree!=null){		    			Node cur=null;			SVGPropertyItem item=null;			//for each property node			for(cur=subTree.getFirstChild(); cur!=null; cur=cur.getNextSibling()){			    				//get the property item object				if(cur.getNodeName().equals("property")){				    					//get the property item object					item=getProperty(nodelist, cur);										//adds it to the list					if(item!=null)list.add(item);				}			}		}				if(list!=null && list.size()>0){		    		    return list;		}				return null;	}		/**	 * creates the property item object given a property node	 * @param nodelist the list of the selected nodes	 * @param property a property node	 * @return a SVGPropertyItem object	 */	protected SVGPropertyItem getProperty(LinkedList nodelist, Node property){				SVGPropertyItem propertyItem=null;				if(property!=null){						String type="", name="", valueType="", defaultValue="", constraint="";						//the attributes of the property node			type=((Element)property).getAttribute("type");			name=((Element)property).getAttribute("name");			valueType=((Element)property).getAttribute("valuetype");			defaultValue=((Element)property).getAttribute("defaultvalue");			constraint=((Element)property).getAttribute("constraint");						LinkedHashMap values=null;						if(property.hasChildNodes()){			    				//fills the map with the attributes of each possible value for the property item				values=new LinkedHashMap();				String itemName="", itemValue=""; 				Node cur;								for(cur=property.getFirstChild(); cur!=null; cur=cur.getNextSibling()){				    					if(cur.getNodeName().equals("item")){					    						//the attributes of the item						itemName=((Element)cur).getAttribute("name");						itemValue=((Element)cur).getAttribute("value");												if(itemName!=null && ! itemName.equals("") && itemValue!=null && !itemValue.equals("")){						    							values.put(itemName, itemValue);						}					}				}								//if the map is empty, it is set to null				if(values.size()<=0){				    				    values=null;				}			}						//creates the property item object			if(type!=null && name!=null && valueType!=null && ! type.equals("") && ! name.equals("") && ! valueType.equals("")){							    propertyItem=new SVGPropertyItem(this, nodelist, type, name, valueType, defaultValue, constraint, values);			}		}		return propertyItem;	}		/**	 * gets the name of the module	 * @return the name of the module	 */	public String getName(){	    		return idproperties;	}	/**	 * cancels all the actions that could be running	 */	public void cancelActions(){	}}

⌨️ 快捷键说明

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