📄 svgpropertyitem.java
字号:
/* * Created on 2 juin 2004 * ============================================= GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 =============================================GLIPS Graffiti Editor, a SVG EditorCopyright (C) 2004 Jordi SUC, Philippe Gil, SARL ITRISThis library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 2.1 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USAContact : jordi.suc@itris.fr; philippe.gil@itris.fr ============================================= */package fr.itris.glips.svgeditor.properties;import java.util.*;import org.w3c.dom.*;import fr.itris.glips.svgeditor.*;import fr.itris.glips.svgeditor.canvas.*;import fr.itris.glips.svgeditor.undoredo.*;/** * @author Jordi SUC * * The class allowing to know the name and value of a property */public class SVGPropertyItem{ /** * the list of the selected nodes */ private LinkedList nodeList; /** * the type, the name and the value of the property, the constraint linked with this property the generalPopertyValue is the value that will be displayed for the whole nodes of the list */ private String propertyType, propertyName, propertyValueType, defaultPropertyValue="", propertyConstraint="", generalPropertyValue=""; /** * the labels associated with the property */ private String propertyLabel; /** * the map associating a node to the value of the property */ private LinkedHashMap propertyValues=new LinkedHashMap(); /** * the map associating one value name of the property to its value */ private LinkedHashMap valuesMap; /** * the map associating one value name of the property to its label */ private LinkedHashMap valuesLabelMap; /** * the undo/redo labels */ private String undoredoproperties=""; /** * the bundle used to get labels */ private ResourceBundle bundle=null; /** * the properties object */ private SVGProperties properties=null; /** * the constructor of the class * @param properties the properties object * @param nodeList the list of the nodes * @param propertyType the type of the property * @param propName the name of the property * @param propertyValueType the name of the widget that has to be used to modify the property * @param defaultPropertyValue the default value of the property * @param propertyConstraint whether the property is required or not * @param valuesMap the map associated the name of a value to its value */ public SVGPropertyItem(SVGProperties properties, LinkedList nodeList, String propertyType, String propName, String propertyValueType, String defaultPropertyValue, String propertyConstraint, LinkedHashMap valuesMap){ this.properties=properties; this.nodeList=nodeList; this.propertyType=propertyType; try{ this.propertyName=propName.substring(propName.indexOf("_")+1, propName.length()); }catch (Exception ex){this.propertyName=propName;} this.propertyValueType=propertyValueType; this.defaultPropertyValue=defaultPropertyValue; this.propertyConstraint=propertyConstraint; this.valuesMap=valuesMap; this.bundle=SVGEditor.getBundle(); //gets the property label from the resources if(bundle!=null){ try{ propertyLabel=bundle.getString(propName); undoredoproperties=bundle.getString("undoredoproperties"); }catch (Exception ex){} if(propertyLabel==null || (propertyLabel!=null && propertyLabel.equals(""))){ propertyLabel=this.propertyName; } } //fils the valuesLabelMap with the labels associated with each value name of a property if it exits if(valuesMap!=null && valuesMap.size()>0 && bundle!=null){ valuesLabelMap=new LinkedHashMap(); String name="", label=""; for(Iterator it=valuesMap.keySet().iterator(); it.hasNext();){ try{ name=(String)it.next(); }catch (Exception ex){name=null;} if(name!=null && ! name.equals("")){ try{ label=bundle.getString(name); }catch (Exception ex){label="";} //if no label has been found, the label is set to the name if(label==null || (label!=null && label.equals(""))){ label=name; } valuesLabelMap.put(name, label); } } } //sets the value of the property taking it from the node attributes if(propertyType!=null && this.propertyName!=null){ if(propertyType.equals("style")){ generalPropertyValue=getStylePropertyValue(this.propertyName); }else if (propertyType.equals("attribute")){ generalPropertyValue=getAttributeValue(this.propertyName); }else if (propertyType.equals("child")){ generalPropertyValue=getChildValue(this.propertyName); } } } /** * @return Returns the properties. */ public SVGProperties getProperties() { return properties; } /** * @return the list of the nodes */ public Collection getNodeList(){ return nodeList; } /** * @return the type of the property */ public String getPropertyType(){ return propertyType; } /** * @return the name of the property */ public String getPropertyName(){ return propertyName; } /** * @return the valueType of the property */ public String getPropertyValueType(){ return propertyValueType; } /** * @return the default value of the property */ public String getDefaultPropertyValue(){ return defaultPropertyValue; } /** * @return the property constraint (normal or required) */ public String getPropertyConstraint(){ return propertyConstraint; } /** * @return the value of the property */ public String getGeneralPropertyValue(){ return generalPropertyValue; } /** * returns the value of the property for a given node * @param node a node * @return the value of the property corresponding to the node */ public String getPropertyValue(Node node){ String val=""; if(node!=null){ try{ val=(String)propertyValues.get(node); }catch (Exception ex){} } return val; } /** * @return the label of the property */ public String getPropertyLabel(){ return propertyLabel; } /** * @return the map associating a value name of the property to its value */ public LinkedHashMap getPropertyValuesMap(){ return valuesMap; } /** * @return the map associating a value name of the property to its label */ public LinkedHashMap getPropertyValuesLabelMap(){ return valuesLabelMap; } /** * sets the value of the property, the value is taken from the value given by the widget * @param value the new value for the property */ public void changePropertyValue(String value){ if((value==null || (value!=null && value.equals("")) && (propertyConstraint!=null && propertyConstraint.equals("required")))){ value=defaultPropertyValue; } //the current SVGFrame final SVGFrame frame=properties.getSVGEditor().getFrameManager().getCurrentFrame(); if(frame!=null && propertyType!=null){ final SVGCanvas canvas=frame.getScrollPane().getSVGCanvas(); final LinkedHashMap oldPropertyValues=new LinkedHashMap(propertyValues); //creates a new values map associating a node to the current widgetPropertyValue LinkedHashMap values=new LinkedHashMap(); Node node=null; for(Iterator it=propertyValues.keySet().iterator(); it.hasNext();){ try{node=(Node)it.next();}catch(Exception ex){node=null;} if(node!=null){ values.put(node, value); } } //the maps that will be used for the undo/redo action final LinkedHashMap oldValues=new LinkedHashMap(propertyValues); final LinkedHashMap newValues=new LinkedHashMap(values); final LinkedHashMap fvalues=values; Runnable runnable=new Runnable(){ public void run(){ //sets the new value taken from the widget and gets the new value once set from the node if(propertyType.equals("style")){ setStylePropertyValue(propertyName, fvalues); }else if(propertyType.equals("attribute")){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -