📄 svgpropertyitem.java
字号:
setAttributeValue(propertyName, fvalues); }else if(propertyType.equals("child")){ setChildValue(propertyName, fvalues); } frame.getScrollPane().getSVGCanvas().delayedRepaint(); } }; frame.enqueue(runnable); frame.setModified(true); //the undo/redo action that will be used to undo or redo the changes of the value for this property SVGUndoRedoAction action=new SVGUndoRedoAction(""){ public void undo(){ //sets the old value if(propertyType.equals("style")){ setStylePropertyValue(propertyName, oldValues); }else if(propertyType.equals("attribute")){ setAttributeValue(propertyName, oldValues); }else if(propertyType.equals("child")){ setChildValue(propertyName, oldValues); } //redraws the window properties.handleProperties(properties.getSelectedNodes()); } public void redo(){ //sets the new value if(propertyType.equals("style")){ setStylePropertyValue(propertyName, newValues); }else if(propertyType.equals("attribute")){ setAttributeValue(propertyName, newValues); }else if(propertyType.equals("child")){ setChildValue(propertyName, newValues); } //redraws the window properties.handleProperties(properties.getSelectedNodes()); } }; //creates the undo/redo list so that actions can be added to it SVGUndoRedoActionList actionlist=new SVGUndoRedoActionList(undoredoproperties); actionlist.add(action); if(properties.getSVGEditor().getUndoRedo()!=null){ properties.getSVGEditor().getUndoRedo().addActionList(frame, actionlist); } } } /** * @param name the name of the property in the style attribute * @return the value of he property */ public String getStylePropertyValue(String name){ //clears the map associating a node to its value propertyValues.clear(); if(nodeList!=null){ String value=""; Element element=null; //for each node in the list for(Iterator it=nodeList.iterator(); it.hasNext();){ try{element=(Element)it.next();}catch (Exception ex){element=null;} value=properties.getSVGEditor().getSVGToolkit().getStyleProperty(element, name); if(value==null || (value!=null && value.equals(""))){ value=defaultPropertyValue; } if(element!=null){ propertyValues.put(element, value); } } } //the value that will be returned String returnedValue=""; //if the list contains a single element, its value will be returned, otherwise the empty string is returned if(nodeList.size()==1){ try{ returnedValue=(String)propertyValues.get(nodeList.getFirst()); }catch (Exception ex){returnedValue="";} } return returnedValue; } /** * @param name the name of the attribute * @return the value of the attribute */ public String getAttributeValue(String name){ //clears the map associating a node to its value propertyValues.clear(); String value=""; Element element=null; //for each node in the list for(Iterator it=nodeList.iterator(); it.hasNext();){ try{ element=(Element)it.next(); }catch (Exception ex){element=null;} if(element!=null && name!=null && ! name.equals("")){ value=element.getAttribute(name); } if(value==null || (value!=null && value.equals(""))){ value=defaultPropertyValue; } if(element!=null){ propertyValues.put(element, value); } } //the value that will be returned String returnedValue=""; //if the list contains a single element, its value will be returned, otherwise the empty string is returned if(nodeList.size()==1){ try{ returnedValue=(String)propertyValues.get(nodeList.getFirst()); }catch (Exception ex){returnedValue="";} } return returnedValue; } /** * @param name the name of the child node * @return the value of the child node */ public String getChildValue(String name){ //clears the map associating a node to its value propertyValues.clear(); String value=""; Node node=null, cur=null; //for each node in the list for(Iterator it=nodeList.iterator(); it.hasNext();){ try{node=(Node)it.next();}catch (Exception ex){node=null;} if(node!=null && name!=null && ! name.equals("")){ //for each child of the given element, tests if the name of these children is equals to the parameter string for(cur=node.getFirstChild(); cur!=null; cur=cur.getNextSibling()){ if(cur.getNodeName().equals(name)){ value=cur.getNodeValue(); break; } } } if(value==null || (value!=null && value.equals(""))){ value=defaultPropertyValue; } if(node!=null){ //value=getSVGEditor().getSVGToolkit().normalizeTextNodeValue(value); propertyValues.put(node, value); } } //the value that will be returned String returnedValue=""; //if the list contains a single element, its value will be returned, otherwise the empty string is returned if(nodeList.size()==1){ try{returnedValue=(String)propertyValues.get(nodeList.getFirst());}catch (Exception ex){returnedValue="";} } return returnedValue; } /** * sets the value of a property in the style attribute * @param name the name of the property * @param values the map associating a node to its value of the property */ public void setStylePropertyValue(String name, LinkedHashMap values){ if(nodeList!=null){ Element element=null; String value="", oldValue=""; //for each node in the list for(Iterator it=nodeList.iterator(); it.hasNext();){ try{ element=(Element)it.next(); value=(String)values.get(element); oldValue=(String)propertyValues.get(element); }catch (Exception ex){element=null;value=null;oldValue="";} if(element!=null && name!=null && ! name.equals("") && value!=null && ! value.equals(oldValue)){ properties.getSVGEditor().getSVGToolkit().setStyleProperty(element, name, value); } } } generalPropertyValue=getStylePropertyValue(name); } /** * sets the value of the given attribute * @param name the name of the attribute * @param values the map associating a node to its value of the property */ public void setAttributeValue(String name, LinkedHashMap values){ if(nodeList!=null){ Element element=null; String value="", oldValue=""; //for each node in the list for(Iterator it=nodeList.iterator(); it.hasNext();){ try{ element=(Element)it.next(); value=(String)values.get(element); oldValue=(String)propertyValues.get(element); }catch (Exception ex){element=null;value=null;oldValue="";} if(element!=null && name!=null && ! name.equals("") && value!=null && ! value.equals(oldValue)){ //sets the value of the attribute element.setAttribute(name, value); } } } generalPropertyValue=getAttributeValue(name); } /** * sets the value of the child with the given name * @param name the name of the child node * @param values the map associating a node to its value of the property */ public void setChildValue(String name, LinkedHashMap values){ if(nodeList!=null){ Element element=null; String value="", oldValue=""; //for each node in the list for(Iterator it=nodeList.iterator(); it.hasNext();){ try{ element=(Element)it.next(); value=(String)values.get(element); oldValue=(String)propertyValues.get(element); }catch (Exception ex){element=null;value=null;oldValue="";} if(element!=null && name!=null && ! name.equals("") && value!=null && ! value.equals(oldValue)){ //checks all the child nodes of the element to find the text node, if it is found, sets its value for(Node cur=element.getFirstChild(); cur!=null; cur=cur.getNextSibling()){ if(cur.getNodeName().equals(name)){ //sets the value of the node cur.setNodeValue(value); break; } } } } } generalPropertyValue=getChildValue(name); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -