java类java.beans.PropertyEditor的实例源码

FormCustomEditor.java 文件源码 项目:incubator-netbeans 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Used by PropertyAction to mimic property sheet behavior - trying to invoke
 * PropertyEnv listener of the current property editor (we can't create our
 * own PropertyEnv instance).
 * 
 * @return current value
 * @throws java.beans.PropertyVetoException if someone vetoes this change.
 */
public Object commitChanges() throws PropertyVetoException {
    int currentIndex = editorsCombo.getSelectedIndex();
    PropertyEditor currentEditor = currentIndex > -1 ? allEditors[currentIndex] : null;
    if (currentEditor instanceof ExPropertyEditor) {
        // we can only guess - according to the typical pattern the propetry
        // editor itself or the custom editor usually implement the listener
        // registered in PropertyEnv
        PropertyChangeEvent evt = new PropertyChangeEvent(
                this, PropertyEnv.PROP_STATE, null, PropertyEnv.STATE_VALID);
        if (currentEditor instanceof VetoableChangeListener) {
            ((VetoableChangeListener)currentEditor).vetoableChange(evt);
        }
        Component currentCustEd = currentIndex > -1 ? allCustomEditors[currentIndex] : null;
        if (currentCustEd instanceof VetoableChangeListener) {
            ((VetoableChangeListener)currentCustEd).vetoableChange(evt);
        }
        if (currentEditor instanceof PropertyChangeListener) {
            ((PropertyChangeListener)currentEditor).propertyChange(evt);
        }
        if (currentCustEd instanceof PropertyChangeListener) {
            ((PropertyChangeListener)currentCustEd).propertyChange(evt);
        }
    }
    return commitChanges0();
}
OsgiPropertyEditorRegistrar.java 文件源码 项目:gemini.blueprint 阅读 23 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked")
private void createEditors(Properties configuration) {

    boolean trace = log.isTraceEnabled();
    // load properties using this class class loader
    ClassLoader classLoader = getClass().getClassLoader();

    for (Map.Entry<Object, Object> entry : configuration.entrySet()) {
        // key represents type
        Class<?> key;
        // value represents property editor
        Class<?> editorClass;
        try {
            key = classLoader.loadClass((String) entry.getKey());
            editorClass = classLoader.loadClass((String) entry.getValue());
        } catch (ClassNotFoundException ex) {
            throw (RuntimeException) new IllegalArgumentException("Cannot load class").initCause(ex);
        }

        Assert.isAssignable(PropertyEditor.class, editorClass);

        if (trace)
            log.trace("Adding property editor[" + editorClass + "] for type[" + key + "]");
        editors.put(key, (Class<? extends PropertyEditor>) editorClass);
    }
}
FontChooserDialog.java 文件源码 项目:MaxSim 阅读 24 收藏 0 点赞 0 评论 0
public static Font show(Font initialFont) {
    PropertyEditor pe = PropertyEditorManager.findEditor(Font.class);
    if (pe == null) {
        throw new RuntimeException("Could not find font editor component.");
    }
    pe.setValue(initialFont);
    DialogDescriptor dd = new DialogDescriptor(
            pe.getCustomEditor(),
            "Choose Font");
    DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
    if (dd.getValue() == DialogDescriptor.OK_OPTION) {
        Font f = (Font)pe.getValue();
        return f;
    }
    return initialFont;
}
ValuePropertyEditor.java 文件源码 项目:incubator-netbeans 阅读 28 收藏 0 点赞 0 评论 0
private static PropertyEditor findThePropertyEditor(Class clazz) {
    PropertyEditor pe;
    if (Object.class.equals(clazz)) {
        pe = null;
    } else {
        pe = PropertyEditorManager.findEditor(clazz);
        if (pe == null) {
            Class sclazz = clazz.getSuperclass();
            if (sclazz != null) {
                pe = findPropertyEditor(sclazz);
            }
        }
    }
    classesWithPE.put(clazz, pe != null);
    return pe;
}
ValuePropertyEditor.java 文件源码 项目:incubator-netbeans 阅读 29 收藏 0 点赞 0 评论 0
boolean setValueWithMirror(Object value, Object valueMirror) {
    this.currentValue = value;
    Class clazz = valueMirror.getClass();
    PropertyEditor propertyEditor = findPropertyEditor(clazz);
    propertyEditor = testPropertyEditorOnValue(propertyEditor, valueMirror);
    if (propertyEditor == null) {
        return false;
    }
    boolean doAttach = false;
    mirrorClass = clazz;
    delegatePropertyEditor = propertyEditor;
    if (env != null && propertyEditor instanceof ExPropertyEditor) {
        doAttach = true;
    }
    delegateValue = valueMirror;
    delegatePropertyEditor.setValue(valueMirror);
    if (doAttach) {
        ((ExPropertyEditor) delegatePropertyEditor).attachEnv(env);
    }
    return doAttach;
}
RevisionNode.java 文件源码 项目:incubator-netbeans 阅读 21 收藏 0 点赞 0 评论 0
@Override
public PropertyEditor getPropertyEditor() {
    return new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            if (text instanceof String) {
                try {
                    entry.setMessage(!text.equals("") ? text : null);
                } catch (IOException ex) {
                    History.LOG.log(Level.WARNING, null, ex);
                }
                return;
            }
            throw new java.lang.IllegalArgumentException(text);
        }
        @Override
        public String getAsText() {
            return te.getDisplayValue();
        }
    };
}
RendererPropertyDisplayer.java 文件源码 项目:incubator-netbeans 阅读 22 收藏 0 点赞 0 评论 0
public void setRadioButtonMax(int i) {
    if (i != radioButtonMax) {
        Dimension oldPreferredSize = null;

        if (isShowing()) {
            oldPreferredSize = getPreferredSize();
        }

        int old = radioButtonMax;
        radioButtonMax = i;

        if (oldPreferredSize != null) {
            //see if the change will affect anything
            PropertyEditor ed = PropUtils.getPropertyEditor(prop);
            String[] tags = ed.getTags();

            if (tags != null) {
                if ((tags.length >= i) != (tags.length >= old)) {
                    firePropertyChange("preferredSize", oldPreferredSize, getPreferredSize()); //NOI18N
                }
            }
        }
    }
}
SheetTable.java 文件源码 项目:incubator-netbeans 阅读 28 收藏 0 点赞 0 评论 0
@Override
public void actionPerformed(ActionEvent ae) {
    int i = getSelectedRow();

    if (i != -1) {
        FeatureDescriptor fd = getPropertySetModel().getFeatureDescriptor(i);

        if (fd instanceof Property) {
            java.beans.PropertyEditor ped = PropUtils.getPropertyEditor((Property) fd);
            System.err.println(ped.getClass().getName());
        } else {
            System.err.println("PropertySets - no editor"); //NOI18N
        }
    } else {
        System.err.println("No selection"); //NOI18N
    }
}
JspRuntimeLibrary.java 文件源码 项目:lams 阅读 22 收藏 0 点赞 0 评论 0
public static Object getValueFromBeanInfoPropertyEditor(
               Class attrClass, String attrName, String attrValue,
           Class propertyEditorClass) 
throws JasperException 
   {
try {
    PropertyEditor pe = (PropertyEditor)propertyEditorClass.newInstance();
    pe.setAsText(attrValue);
    return pe.getValue();
} catch (Exception ex) {
    throw new JasperException(
               Localizer.getMessage("jsp.error.beans.property.conversion",
                 attrValue, attrClass.getName(), attrName,
                 ex.getMessage()));
}
   }
EditablePropertyDisplayer.java 文件源码 项目:incubator-netbeans 阅读 28 收藏 0 点赞 0 评论 0
PropertyEditor getPropertyEditor() { //package private for unit tests

        PropertyEditor result;

        if (editor != null) {
            return editor;
        }

        if (getInplaceEditor() != null) {
            result = getInplaceEditor().getPropertyEditor();
        } else {
            result = PropUtils.getPropertyEditor(getProperty());
        }

        editor = result;

        return result;
    }
PropertyEditorRegistrySupport.java 文件源码 项目:lams 阅读 25 收藏 0 点赞 0 评论 0
private PropertyEditor getPropertyEditor(Class<?> requiredType) {
    // Special case: If no required type specified, which usually only happens for
    // Collection elements, or required type is not assignable to registered type,
    // which usually only happens for generic properties of type Object -
    // then return PropertyEditor if not registered for Collection or array type.
    // (If not registered for Collection or array, it is assumed to be intended
    // for elements.)
    if (this.registeredType == null ||
            (requiredType != null &&
            (ClassUtils.isAssignable(this.registeredType, requiredType) ||
            ClassUtils.isAssignable(requiredType, this.registeredType))) ||
            (requiredType == null &&
            (!Collection.class.isAssignableFrom(this.registeredType) && !this.registeredType.isArray()))) {
        return this.propertyEditor;
    }
    else {
        return null;
    }
}
ModelProperty.java 文件源码 项目:incubator-netbeans 阅读 22 收藏 0 点赞 0 评论 0
public PropertyEditor getPropertyEditor() {
    if (mdl.getPropertyEditorClass() != null) {
        try {
            //System.err.println("ModelProperty creating a " 
            //+ mdl.getPropertyEditorClass());
            Constructor c = mdl.getPropertyEditorClass().getConstructor();
            c.setAccessible(true);

            return (PropertyEditor) c.newInstance(new Object[0]);
        } catch (Exception e) {
            Exceptions.printStackTrace(e);

            return new PropUtils.NoPropertyEditorEditor();
        }
    }

    return super.getPropertyEditor();
}
PropertyEditorRegistry.java 文件源码 项目:neoscada 阅读 29 收藏 0 点赞 0 评论 0
/**
 * @param requiredType
 * @param propertyPath
 * @return
 */
public PropertyEditor findCustomEditor ( final Class<?> requiredType, final String propertyPath )
{
    // first try to find exact match
    String key = requiredType.getCanonicalName () + ":" + propertyPath;
    PropertyEditor pe = this.propertyEditors.get ( key );
    // 2nd: try to find for class only
    if ( pe == null )
    {
        key = requiredType.getCanonicalName () + ":";
        pe = this.propertyEditors.get ( key );
    }
    // 3rd: try to get internal
    if ( pe == null )
    {
        pe = PropertyEditorManager.findEditor ( requiredType );
    }
    return pe;
}
JspRuntimeLibrary.java 文件源码 项目:lazycat 阅读 26 收藏 0 点赞 0 评论 0
public static Object getValueFromPropertyEditorManager(Class<?> attrClass, String attrName, String attrValue)
        throws JasperException {
    try {
        PropertyEditor propEditor = PropertyEditorManager.findEditor(attrClass);
        if (propEditor != null) {
            propEditor.setAsText(attrValue);
            return propEditor.getValue();
        } else {
            throw new IllegalArgumentException(
                    Localizer.getMessage("jsp.error.beans.propertyeditor.notregistered"));
        }
    } catch (IllegalArgumentException ex) {
        throw new JasperException(Localizer.getMessage("jsp.error.beans.property.conversion", attrValue,
                attrClass.getName(), attrName, ex.getMessage()));
    }
}
SuiteCustomizerLibraries.java 文件源码 项目:incubator-netbeans 阅读 21 收藏 0 点赞 0 评论 0
@Override
public PropertyEditor getPropertyEditor() {
    if (editor == null) {
        editor = super.getPropertyEditor();
    }
    return editor;
}
BiFeatureNode.java 文件源码 项目:incubator-netbeans 阅读 24 收藏 0 点赞 0 评论 0
@Override
public PropertyEditor getPropertyEditor() {
    return new PropertyEditorSupport() {
        @Override
        public java.awt.Component getCustomEditor() {
            return new CustomCodeEditor(CodePropertySupportRW.this);
        }

        @Override
        public boolean supportsCustomEditor() {
            return true;
        }
    };            
}
BeanPropertyUtil.java 文件源码 项目:spring-seed 阅读 22 收藏 0 点赞 0 评论 0
private static Object getValueFromPropertyEditorManager(Class attrClass, String attrValue) {
    PropertyEditor propEditor = PropertyEditorManager.findEditor(attrClass);
    if (propEditor != null) {
        propEditor.setAsText(attrValue);
        return propEditor.getValue();
    } else {
        throw new IllegalArgumentException("beans property editor not registered");
    }
}
PropertyText.java 文件源码 项目:etomica 阅读 19 收藏 0 点赞 0 评论 0
public PropertyText(PropertyEditor pe) {
        super(pe.getAsText());
        editor = pe;
        addKeyListener(this);
        addFocusListener(this);
        editor.addPropertyChangeListener(this);
//      setBorder(PropertySheet.EMPTY_BORDER);
    }
TestPropertyEditor.java 文件源码 项目:jdk8u-jdk 阅读 20 收藏 0 点赞 0 评论 0
private static void test(Class<?> type, Class<? extends PropertyEditor> expected) {
    PropertyEditor actual = PropertyEditorManager.findEditor(type);
    if ((actual == null) && (expected != null)) {
        throw new Error("expected editor is not found");
    }
    if ((actual != null) && !actual.getClass().equals(expected)) {
        throw new Error("found unexpected editor");
    }
}
PEAnnotationProcessorTest.java 文件源码 项目:incubator-netbeans 阅读 22 收藏 0 点赞 0 评论 0
public void testPERegistered() {
    NodeOp.registerPropertyEditors();
    PropertyEditor pEditor = PropertyEditorManager.findEditor(Double[].class);
    assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", pEditor.getClass().getName());
    pEditor = PropertyEditorManager.findEditor(Integer.class);
    assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", pEditor.getClass().getName());
    pEditor = PropertyEditorManager.findEditor(char[][].class);
    assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", pEditor.getClass().getName());
    pEditor = PropertyEditorManager.findEditor(short.class);
    assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", pEditor.getClass().getName());
}
ResourceSupport.java 文件源码 项目:incubator-netbeans 阅读 21 收藏 0 点赞 0 评论 0
private static String getStringValue(FormProperty prop, Object value) {
    if (value instanceof String)
        return (String) value;

    PropertyEditor prEd = prop.getCurrentEditor();
    prEd.setValue(value);
    return prEd.getAsText(); // [this does not work correctly with IconEditor...]
}
TypeConverterDelegate.java 文件源码 项目:lams 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Find a default editor for the given type.
 * @param requiredType the type to find an editor for
 * @return the corresponding editor, or {@code null} if none
 */
private PropertyEditor findDefaultEditor(Class<?> requiredType) {
    PropertyEditor editor = null;
    if (requiredType != null) {
        // No custom editor -> check BeanWrapperImpl's default editors.
        editor = this.propertyEditorRegistry.getDefaultEditor(requiredType);
        if (editor == null && !String.class.equals(requiredType)) {
            // No BeanWrapper default editor -> check standard JavaBean editor.
            editor = BeanUtils.findEditorByConvention(requiredType);
        }
    }
    return editor;
}
ValuePropertyEditor.java 文件源码 项目:incubator-netbeans 阅读 37 收藏 0 点赞 0 评论 0
/**
 * Test if the property editor can act on the provided value. We can never be sure. :-(
 * @param propertyEditor
 * @param valueMirror
 * @return the property editor, or <code>null</code>
 */
private static PropertyEditor testPropertyEditorOnValue(PropertyEditor propertyEditor, Object valueMirror) {
    propertyEditor.setValue(valueMirror);
    Object value = propertyEditor.getValue();
    if (value != valueMirror && (value == null || !value.equals(valueMirror))) {
        // Returns something that we did not set. Give up.
        return null;
    }
    return propertyEditor;
}
JspRuntimeLibrary.java 文件源码 项目:lazycat 阅读 33 收藏 0 点赞 0 评论 0
public static Object getValueFromBeanInfoPropertyEditor(Class<?> attrClass, String attrName, String attrValue,
        Class<?> propertyEditorClass) throws JasperException {
    try {
        PropertyEditor pe = (PropertyEditor) propertyEditorClass.newInstance();
        pe.setAsText(attrValue);
        return pe.getValue();
    } catch (Exception ex) {
        throw new JasperException(Localizer.getMessage("jsp.error.beans.property.conversion", attrValue,
                attrClass.getName(), attrName, ex.getMessage()));
    }
}
PropertyEditorRegistrySupport.java 文件源码 项目:lams 阅读 24 收藏 0 点赞 0 评论 0
/**
 * Get custom editor for the given type. If no direct match found,
 * try custom editor for superclass (which will in any case be able
 * to render a value as String via {@code getAsText}).
 * @param requiredType the type to look for
 * @return the custom editor, or {@code null} if none found for this type
 * @see java.beans.PropertyEditor#getAsText()
 */
private PropertyEditor getCustomEditor(Class<?> requiredType) {
    if (requiredType == null || this.customEditors == null) {
        return null;
    }
    // Check directly registered editor for type.
    PropertyEditor editor = this.customEditors.get(requiredType);
    if (editor == null) {
        // Check cached editor for type, registered for superclass or interface.
        if (this.customEditorCache != null) {
            editor = this.customEditorCache.get(requiredType);
        }
        if (editor == null) {
            // Find editor for superclass or interface.
            for (Iterator<Class<?>> it = this.customEditors.keySet().iterator(); it.hasNext() && editor == null;) {
                Class<?> key = it.next();
                if (key.isAssignableFrom(requiredType)) {
                    editor = this.customEditors.get(key);
                    // Cache editor for search type, to avoid the overhead
                    // of repeated assignable-from checks.
                    if (this.customEditorCache == null) {
                        this.customEditorCache = new HashMap<Class<?>, PropertyEditor>();
                    }
                    this.customEditorCache.put(requiredType, editor);
                }
            }
        }
    }
    return editor;
}
OsgiPropertyEditorRegistrar.java 文件源码 项目:gemini.blueprint 阅读 29 收藏 0 点赞 0 评论 0
public void registerCustomEditors(PropertyEditorRegistry registry) {
    for (Map.Entry<Class<?>, Class<? extends PropertyEditor>> entry : editors.entrySet()) {
        Class<?> type = entry.getKey();
        PropertyEditor editorInstance;
        editorInstance = BeanUtils.instantiate(entry.getValue());
        registry.registerCustomEditor(type, editorInstance);
    }

    // register non-externalized types
    registry.registerCustomEditor(Dictionary.class, new CustomMapEditor(Hashtable.class));
    registry.registerCustomEditor(Properties.class, new PropertiesEditor());
    registry.registerCustomEditor(Class.class, new ClassEditor(userClassLoader));
    registry.registerCustomEditor(Class[].class, new ClassArrayEditor(userClassLoader));
}
DynamicParsers.java 文件源码 项目:X4J 阅读 37 收藏 0 点赞 0 评论 0
@Override
public Object parseImp(String input, ParserHelper helper) {
    PropertyEditor editor = findEditor(helper.getRawTargetClass());
    if (editor == null) {
        return TRY_NEXT;
    }
    editor.setAsText(input);
    return editor.getValue();
}
OutlineView.java 文件源码 项目:incubator-netbeans 阅读 26 收藏 0 点赞 0 评论 0
private boolean openCustomEditor(ActionEvent e) {
    if (getSelectedRowCount() != 1 || getSelectedColumnCount() != 1) {
        return false;
    }
    int row = getSelectedRow();
    if (row < 0) return false;
    int column = getSelectedColumn();
    if (column < 0) return false;
    Object o = getValueAt(row, column);
    if (!(o instanceof Node.Property)) {
        return false;
    }
    Node.Property p = (Node.Property) o;
    if (!Boolean.TRUE.equals(p.getValue("suppressCustomEditor"))) { //NOI18N
        PropertyPanel panel = new PropertyPanel(p);
        @SuppressWarnings("deprecation")
        PropertyEditor ed = panel.getPropertyEditor();

        if ((ed != null) && ed.supportsCustomEditor()) {
            Action act = panel.getActionMap().get("invokeCustomEditor"); //NOI18N

            if (act != null) {
                act.actionPerformed(null);

                return true;
            }
        }
    }
    return false;
}
Folder.java 文件源码 项目:Pogamut3 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Initializes folder from the properties object.
 * @param props
 */
protected void loadFromProperties(Properties props, String prefix) throws IntrospectionException {
    Enumeration<String> keys = (Enumeration<String>) props.propertyNames();
    prefix = prefix + getName() + ".";
    // load properties in this folder
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        if (key.startsWith(prefix)) {
            String posfix = key.replaceFirst(prefix, "");
            if (!posfix.contains(".")) {
                // the posfix represents a name of a property
                Property prop = getProperty(posfix);
                if (prop == null) {
                    continue;
                }
                // exploit the JavaBeans property editors to convert the values from text
                PropertyEditor editor = PropertyEditorManager.findEditor(prop.getType());
                if (editor == null) {
                    continue;
                }
                editor.setAsText(props.getProperty(key));
                prop.setValue(editor.getValue());

            }
        }
        ;
    }

    // load all subfolders
    for (Folder folder : getFolders()) {
        folder.loadFromProperties(props, prefix);
    }

}
DiffNode.java 文件源码 项目:incubator-netbeans 阅读 20 收藏 0 点赞 0 评论 0
@Override
public PropertyEditor getPropertyEditor() {
    try {
        return new DiffNode.DiffPropertyEditor(getValue());
    } catch (Exception e) {
        return super.getPropertyEditor();
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号