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

📄 nodepropertyreader.java

📁 对eclipse gef进行封装,可以生成图形化编辑器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************
 * $Header: /cvsroot/EOS6/work_dir/niegy/com.primeton.studio.gef.ui/src/com/primeton/studio/gef/ui/properties/NodePropertyReader.java,v 1.2 2006/12/16 09:04:42 niegy Exp $
 * $Revision: 1.2 $
 * $Date: 2006/12/16 09:04:42 $
 *
 *==============================================================================
 *
 * Copyright (c) 2001-2006 Primeton Technologies, Ltd.
 * All rights reserved. 
 * 
 * Created on 2006-10-30
 *******************************************************************************/


package com.primeton.studio.gef.ui.properties;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;

import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.primeton.studio.gef.ui.util.XmlUtil;

/**
 * TODO此处填写 class 信息
 *
 * @author niegy (mailto:niegy@primeton.com)
 */
/*
 * 修改历史
 * $Log: NodePropertyReader.java,v $
 * Revision 1.2  2006/12/16 09:04:42  niegy
 * 重构代码
 *
 * Revision 1.1  2006/11/22 07:07:38  niegy
 * 增加table
 *
 * Revision 1.1  2006/11/17 03:15:13  niegy
 * create
 * 
 */
public class NodePropertyReader {
    public static final String TYPE_STRING = "String";
    public static final String TYPE_PROPOSAL = "Proposal";
    public static final String TYPE_BOOLEAN = "Boolean";
    public static final String TYPE_INTEGER = "Int";
    public static final String TYPE_ZINTEGER = "ZInt";
    public static final String TYPE_ACTIONS = "Options";
    public static final String TYPE_DIALOG = "Dialog";
    public static final int MAXNUMBER = 5000;
    public static final int MINNUMBER = -5000;
    
    private static final String[] FONTNAME_LIST = getFontNameList();
    
    private static String[] getFontNameList() {
        Display display= Display.getCurrent();
        if (display == null) {
            display= Display.getDefault();
        }
        FontData[] data = display.getFontList(null, true);
        ArrayList result = new ArrayList();
        for (int i = 0; i < data.length; i++) {
            String fontName = data[i].getName();;
            if (!result.contains(fontName))
                result.add(fontName);
        }
        return (String[])result.toArray(new String[result.size()]);
    }
    
    public class ElementAttribute {
        public String name;     //attribute name
        public String displayName;  //attribute display name
        public String description;  //attribute description
        public String type;     //attribute type: String|Boolean|Integer|StringList|Dialog
        public String[] options;//if type is StringList, this field stores the data
//      public String dialogType;   //if type is Dialog, this field stores the type of dialog: color|font|entity|class|...
        public String category; //attribute category
    }
       
    protected static NodePropertyReader instance;
    protected HashMap propertyMap;
    
    protected NodePropertyReader() {
        propertyMap = new HashMap();
    }
    
    public static NodePropertyReader getInstance() {
        if (instance == null) {
            instance = new NodePropertyReader();
        }
        return instance;
    }
    
    private class BooleanLabelProvider extends LabelProvider {
        public String getText(Object element) {
            String[] values = new String[] { "false", "true" };
            return values[((Integer) element).intValue()];
        }
    }
    
    public Object getPropertyValue(String filePath, String name,
            IPropertyObject obj, Object id) {
        ElementAttribute attribute = getElementAttribute(filePath, name, id);
        if (attribute != null) {
            PropertyElement element = (PropertyElement)obj.getEditableValue();
            String value = getString(element.getAttribute((String)id));
            if (TYPE_BOOLEAN.equalsIgnoreCase(attribute.type)) {
                return ("true".equalsIgnoreCase(value)) ? new Integer(1) : new Integer(0);  
            }
            else if (TYPE_ACTIONS.equalsIgnoreCase(attribute.type)) {
                if(obj instanceof Element){
                    com.primeton.studio.gef.core.Element nodeElement = ((com.primeton.studio.gef.ui.properties.Element)obj).getElement();    
                    for (int i = 0; i < attribute.options.length; i++) {
                        if (attribute.options[i].equalsIgnoreCase(value)) {
                            return new Integer(i);
                        }
                    }
                    return new Integer(0); 
                }else{              
                    if (attribute.options != null) { 
                        for (int i = 0; i < attribute.options.length; i++) {
                            if (attribute.options[i].equalsIgnoreCase(value)) {
                                return new Integer(i);
                            }
                        }
                    }
                    return new Integer(0); 
                }
            }
            else if(TYPE_INTEGER.equalsIgnoreCase(attribute.type)){
                return value;
            }
            return value;
        }
        return null;
    }
    
    public ElementAttribute getElementAttribute(String filePath, String tagName, Object attributeID) {
        HashMap attributeMap = getAttributeMap(filePath, tagName);
        return (ElementAttribute)attributeMap.get(attributeID);
    }
    
    public boolean setPropertyValue(String filePath, String name,
            IPropertyObject obj, Object id, Object value) {
        // TODO Auto-generated method stub
        ElementAttribute attribute = getElementAttribute(filePath, name, id);
        if (attribute != null) {
            PropertyElement element = (PropertyElement)obj.getEditableValue();          
            if (TYPE_BOOLEAN.equalsIgnoreCase(attribute.type)) {
                if (((Integer)value).intValue() == 1)
                    element.setAttribute((String)id, "true");
                else {
                    element.setAttribute((String)id, "false");
                }
                return true;
            }
            else if (TYPE_ACTIONS.equalsIgnoreCase(attribute.type)) {
                String result = "";
                 if(obj instanceof Element){
                     com.primeton.studio.gef.core.Element nodeElement = ((Element)obj).getElement();
                     try {
                         result = attribute.options[((Integer)value).intValue()];
                         element.setAttribute((String)id, result);
                         return true;
                     } catch (Exception e) {
                         return false;

⌨️ 快捷键说明

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