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

📄 nodepropertyreader.java

📁 对eclipse gef进行封装,可以生成图形化编辑器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                     }  
                    
                 }else{
                    if (attribute.options != null) { 
                        try {
                            result = attribute.options[((Integer)value).intValue()];
                            element.setAttribute((String)id, result);
                            return true;
                        } catch (Exception e) {
                            return false;
                        }                
                    }  
                 }
            }
            else if(TYPE_INTEGER.equalsIgnoreCase(attribute.type)){     
                try {
                    int num = Integer.parseInt(String.valueOf(value));                      
                    if(Math.abs(num)>MAXNUMBER)
                    {
                        if(((String)value).startsWith("-"))
                            value = String.valueOf(MINNUMBER);
                        else
                            value = String.valueOf(MAXNUMBER);
                    }
                } catch (Exception e) {
                    return true;
                }                   
            }
            else if(TYPE_ZINTEGER.equalsIgnoreCase(attribute.type)){        
                try {
                    String temp = String.valueOf(value);
                    temp =  temp.replaceAll("-","");
                        
                    int num = Integer.parseInt(temp);
                    if(num>MAXNUMBER)
                        value = String.valueOf(MAXNUMBER);
                    else
                        value = temp;
                    
                } catch (Exception e) {
                    return true;
                }                   
            }      
            element.setAttribute((String)id, (String)value);
            return true;
        }
        return false;
    }
    
//    private void setCategory( PropertyDescriptor  descriptor,String categoryName, ArrayList propertyList){
//    	String[] names = categoryName.split("-");
//    	descriptor.setCategory(names[names.length-1]);
//    	if(names.length>1)
//    	{
//    		for (int i = names.length-1; i >= 0; i--) {
//    			PropertyDescriptor des = new PropertyDescriptor(names[i],names[i]);
//    			if(i-1>=0)
//    				des.setCategory(names[i-1]);
//    			
//    			propertyList.add(des);
//    			
//			}
//    	}
//    }
    public IPropertyDescriptor[] getPropertyDescriptors(String filePath, String name, IPropertyObject element) {
        HashMap attributeMap = getAttributeMap(filePath, name);        
        ArrayList propertyList = new ArrayList();
        for (Iterator iter = attributeMap.values().iterator(); iter.hasNext();) {
            ElementAttribute attribute = (ElementAttribute) iter.next();
            
            PropertyDescriptor  descriptor = null;
            if (TYPE_BOOLEAN.equalsIgnoreCase(attribute.type)) {
                descriptor = new ComboBoxPropertyDescriptorEx(attribute.name, attribute.displayName, 
                        new String[] { "false", "true"});
                descriptor.setDescription(attribute.description);
                descriptor.setCategory(getCategoryName(attribute.category));
                descriptor.setLabelProvider(new BooleanLabelProvider());   
            }
            else  if (TYPE_ACTIONS.equalsIgnoreCase(attribute.type)) {
                descriptor = new ComboBoxPropertyDescriptorEx(attribute.name, attribute.displayName, 
                		attribute.options);
                descriptor.setDescription(attribute.description);
                descriptor.setCategory(getCategoryName(attribute.category));
            }
            else if (TYPE_STRING.equalsIgnoreCase(attribute.type) || TYPE_INTEGER.equalsIgnoreCase(attribute.type)) {
                    descriptor = new TextPropertyDescriptorEx(attribute.name, attribute.displayName);
                    descriptor.setDescription(attribute.description);
                    descriptor.setCategory(getCategoryName(attribute.category));
            }
            else if("ReadOnly".equalsIgnoreCase(attribute.type)){
                descriptor = new PropertyDescriptor(attribute.name, attribute.displayName);
                descriptor.setDescription(attribute.description);
                descriptor.setCategory(getCategoryName(attribute.category));
            }
            else if("Int".equalsIgnoreCase(attribute.type)||
                    "ZInt".equalsIgnoreCase(attribute.type)){
                descriptor = new TextPropertyDescriptorEx(attribute.name, attribute.displayName);
                descriptor.setDescription(attribute.description);
                descriptor.setCategory(getCategoryName(attribute.category));
                
            }else if(attribute.type.equals("Label")){
                descriptor = new PropertyDescriptor(attribute.name, attribute.displayName);
                descriptor.setDescription(attribute.description);
                descriptor.setCategory(getCategoryName(attribute.category)); 
            }
            
            if (descriptor != null) {
                propertyList.add(descriptor);
            }
        }   
        return (IPropertyDescriptor[])propertyList.toArray(new IPropertyDescriptor[propertyList.size()]);
    }
    
    protected PropertyDescriptor getExtendedDialogDescriptor(ElementAttribute attribute, IPropertyObject object) {
        return null;
    }
    
    protected String getCategoryName(String categoryID) {
        if ("basic".equalsIgnoreCase(categoryID)) return "base";
        else if ("event".equalsIgnoreCase(categoryID)) return "event";
        else if ("extend".equalsIgnoreCase(categoryID)) return "extend";
        return categoryID;
    }
    
    public HashMap getAttributeMap(String filePath, String key) {
        HashMap map = (HashMap)propertyMap.get(key);
        if (map == null) {
            map = makeAttributeMap(filePath, key);
            propertyMap.put(key, map);
        }
        
        return map;
    }
    
    protected HashMap makeAttributeMap(String filePath, String tagName) {
        HashMap result = new HashMap();
        
        if (filePath == null || filePath.length() <= 0) return result;
        
        Document doc = XmlUtil.parseFile(filePath);
        try {
            NodeList list = XmlUtil.findNodes(doc, "taglib/tag");
            for (int i = 0; i < list.getLength(); i++) {
                Node node = list.item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    if (tagName.equalsIgnoreCase(XmlUtil.subElementValue((org.w3c.dom.Element)node, "name"))) {
                        Vector vector = XmlUtil.subElementList((org.w3c.dom.Element)node, "attribute");
                        for (Iterator iter = vector.iterator(); iter.hasNext();) {
                            org.w3c.dom.Element element = (org.w3c.dom.Element) iter.next();
                            
                            ElementAttribute attribute = new ElementAttribute();
                            attribute.name = getString(XmlUtil.subElementValue(element, "name"));
                            attribute.displayName = getString(XmlUtil.subElementValue(element, "displayName"));
                            attribute.description = getString(XmlUtil.subElementValue(element, "description"));
                            attribute.category = getString(XmlUtil.subElementValue(element, "category"));
                            attribute.type = getString(XmlUtil.subElementValue(element, "type"));
                            attribute.options = getString(XmlUtil.subElementValue(element, "options")).split(";");
                            result.put(attribute.name, attribute);
                        }
                        break;
                    }
                }
            }
        } catch (Exception e) {
//          e.printStackTrace();
        }
        return result;
    }
    
    protected String getString(String str) {
        if (str == null) return "";
        return str;
    }

}

⌨️ 快捷键说明

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