当前位置: 首页>>代码示例>>Java>>正文


Java PropertyEditor.setValue方法代码示例

本文整理汇总了Java中java.beans.PropertyEditor.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyEditor.setValue方法的具体用法?Java PropertyEditor.setValue怎么用?Java PropertyEditor.setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.beans.PropertyEditor的用法示例。


在下文中一共展示了PropertyEditor.setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTheEditorHonoursSeparatorAttribute

import java.beans.PropertyEditor; //导入方法依赖的package包/类
public void testTheEditorHonoursSeparatorAttribute () throws Exception {
    NP np = new NP ();
    np.setValue ("item.separator", "-");
    
    PropertyEditor p = np.getPropertyEditor ();
    assertNotNull ("There is some editor", p);
    assertEquals ("It is StringArrayEditor", StringArrayEditor.class, p.getClass ());
    ((StringArrayEditor)p).readEnv (np);
    
    p.setAsText ("A-B");
    
    String[] value = (String[])p.getValue ();
    
    assertNotNull ("Values is there", value);
    if (value.length != 2 || !"A".equals (value[0]) || !"B".equals(value[1])) {
        fail ("Unexpected arrays: " + Arrays.asList (value));
    }
    
    p.setValue (new String[] { "X", "Y" });
    String t = np.getPropertyEditor ().getAsText ();
    if (!"X- Y".equals (t)) {
        fail ("Wrong text: " + t);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:StringArrayEditorTest.java

示例2: fontButtonActionPerformed

import java.beans.PropertyEditor; //导入方法依赖的package包/类
private void fontButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontButtonActionPerformed
PropertyEditor pe = PropertyEditorManager.findEditor(Font.class);
if (pe != null) {
    pe.setValue(termOptions.getFont());
    DialogDescriptor dd = new DialogDescriptor(pe.getCustomEditor(), FontChooser_title());

    String defaultFontString = FontChooser_defaultFont_label();
    dd.setOptions(new Object[]{DialogDescriptor.OK_OPTION,
	defaultFontString, DialogDescriptor.CANCEL_OPTION});  //NOI18N
    DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
    if (dd.getValue() == DialogDescriptor.OK_OPTION) {
	Font f = (Font) pe.getValue();
	termOptions.setFont(f);
	applyTermOptions();
    } else if (dd.getValue() == defaultFontString) {
	Font controlFont = UIManager.getFont("controlFont");			//NOI18N
	int fontSize = (controlFont == null) ? 12 : controlFont.getSize();
	termOptions.setFont(new Font("monospaced", Font.PLAIN, fontSize));	//NOI18N
    }
}
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:TermOptionsPanel.java

示例3: btnSelectFontActionPerformed

import java.beans.PropertyEditor; //导入方法依赖的package包/类
private void btnSelectFontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectFontActionPerformed
    PropertyEditor pe = PropertyEditorManager.findEditor(Font.class);
    if (pe != null) {
        pe.setValue(outputOptions.getFont());
        DialogDescriptor dd = new DialogDescriptor(pe.getCustomEditor(),
                NbBundle.getMessage(Controller.class,
                "LBL_Font_Chooser_Title"));                         //NOI18N
        String defaultFont = NbBundle.getMessage(Controller.class,
                "BTN_Defaul_Font");                                 //NOI18N
        dd.setOptions(new Object[]{DialogDescriptor.OK_OPTION,
                    defaultFont, DialogDescriptor.CANCEL_OPTION});  //NOI18N
        DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
        if (dd.getValue() == DialogDescriptor.OK_OPTION) {
            Font f = (Font) pe.getValue();
            outputOptions.setFont(f);
        } else if (dd.getValue() == defaultFont) {
            outputOptions.setFont(null);
        }
        updateFontField();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:OutputSettingsPanel.java

示例4: formatFieldValue

import java.beans.PropertyEditor; //导入方法依赖的package包/类
/**
 * Formats the field value based on registered PropertyEditors.
 * @see #getCustomEditor
 */
@Override
protected Object formatFieldValue(String field, Object value) {
	String fixedField = fixedField(field);
	// Try custom editor...
	PropertyEditor customEditor = getCustomEditor(fixedField);
	if (customEditor != null) {
		customEditor.setValue(value);
		String textValue = customEditor.getAsText();
		// If the PropertyEditor returned null, there is no appropriate
		// text representation for this value: only use it if non-null.
		if (textValue != null) {
			return textValue;
		}
	}
	if (this.conversionService != null) {
		// Try custom converter...
		TypeDescriptor fieldDesc = getPropertyAccessor().getPropertyTypeDescriptor(fixedField);
		TypeDescriptor strDesc = TypeDescriptor.valueOf(String.class);
		if (fieldDesc != null && this.conversionService.canConvert(fieldDesc, strDesc)) {
			return this.conversionService.convert(value, fieldDesc, strDesc);
		}
	}
	return value;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:AbstractPropertyBindingResult.java

示例5: show

import java.beans.PropertyEditor; //导入方法依赖的package包/类
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;
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:17,代码来源:FontChooserDialog.java

示例6: getJavaCodeString

import java.beans.PropertyEditor; //导入方法依赖的package包/类
@Override
public String getJavaCodeString(String parentStr, String[] paramsStr) {
    try {
        PropertyEditor pred = property.getPropertyEditor();
        pred.setValue(property.getValue());
        return pred.getJavaInitializationString();
    }
    catch (Exception ex) {} // should not happen
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:FormCodeSupport.java

示例7: getStringValue

import java.beans.PropertyEditor; //导入方法依赖的package包/类
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...]
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ResourceSupport.java

示例8: testPropertyEditorOnValue

import java.beans.PropertyEditor; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:ValuePropertyEditor.java

示例9: isModifiedValueLegal

import java.beans.PropertyEditor; //导入方法依赖的package包/类
public String isModifiedValueLegal() {
    boolean legal = true;
    String msg = null;
    PropertyEditor editor = getPropertyEditor();

    //        System.err.println("IS MODIFIED VALUE LEGAL");
    if (env != null) {
        legal = env.getState() != env.STATE_INVALID;

        System.err.println(" Attempting to validate env");

        if (legal && env.STATE_NEEDS_VALIDATION.equals(env.getState())) {
            msg = env.silentlySetState(env.STATE_VALID, getEnteredValue());

            //                System.err.println("  silentlySetState returned: " + msg);
            legal = msg == null;
        }
    } else if (editor instanceof EnhancedCustomPropertyEditor) {
        Object entered = ((EnhancedCustomPropertyEditor) editor).getPropertyValue();

        try {
            editor.setValue(entered);
        } catch (IllegalStateException ise) {
            legal = false;
            msg = PropUtils.findLocalizedMessage(ise, entered, getProperty().getDisplayName());
        }
    }

    if (!legal && (msg == null)) {
        //            System.err.println(" not legal, constructing message");
        msg = NbBundle.getMessage(
                CustomEditorDisplayer.class, "FMT_CannotUpdateProperty",editor.getValue(), getProperty().getDisplayName()); //NOI18N
    }

    return msg;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:CustomEditorDisplayer.java

示例10: getCreateLocaleComponent

import java.beans.PropertyEditor; //导入方法依赖的package包/类
/**
 * Provides a visual component (modal dialog) usable as a property
 * customizer that allows create a new locale file for given bundle (default
 * bundle name provided). The created locale should be written as a string
 * (locale suffix) to the given propery editor.
 */
@Override
public Component getCreateLocaleComponent(final PropertyEditor prEd, FileObject srcFile, String bundleName) {
    final PropertiesDataObject propertiesDO;
    try {
        propertiesDO = getPropertiesDataObject(srcFile, bundleName);
    }
    catch (DataObjectNotFoundException ex) {
        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
        return null;
    }
    final Dialog[] dialog = new Dialog[1];
    final LocalePanel localePanel = new LocalePanel();

    DialogDescriptor dialogDescriptor = new DialogDescriptor(
        localePanel,
        NbBundle.getBundle(PropertiesDataObject.class).getString("CTL_NewLocaleTitle"), // NOI18N
        true,
        DialogDescriptor.OK_CANCEL_OPTION,
        DialogDescriptor.OK_OPTION,
        new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                if (evt.getSource() == DialogDescriptor.OK_OPTION) {
                    String locale = localePanel.getLocale().toString();
                    org.netbeans.modules.properties.Util.createLocaleFile(
                            propertiesDO, locale, false);
                    prEd.setValue("_" + locale); // NOI18N
                }
                dialog[0].setVisible(false);
                dialog[0].dispose();
            }
        }
    );
    dialog[0] = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
    return dialog[0];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:43,代码来源:I18nServiceImpl.java

示例11: testNullValueSupport

import java.beans.PropertyEditor; //导入方法依赖的package包/类
public void testNullValueSupport() throws Exception {
    NP np = new NP();
    String defaultValue = "<null value>";
    String customValue = "Hello world!";
    np.setValue(ObjectEditor.PROP_NULL, defaultValue);
    
    PropertyEditor p = np.getPropertyEditor();
    assertNotNull("There is some editor", p);
    assertEquals("It is StringEditor", StringEditor.class, p.getClass());
    ((StringEditor) p).readEnv(np);
    
    p.setValue(null);
    String value = (String)p.getValue ();
    assertNull(value);
    assertEquals(defaultValue, p.getAsText());

    p.setValue(customValue);
    value = (String)p.getValue ();
    assertEquals(customValue, value);
    assertEquals(customValue, p.getAsText());

    np.setValue(ObjectEditor.PROP_NULL, Boolean.TRUE);
    ((StringEditor) p).readEnv(np);
    p.setValue(null);
    value = (String)p.getValue ();
    assertNull(value);
    assertFalse("we've better than default 'null' string", "null".equals(defaultValue));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:StringEditorTest.java

示例12: doConvertTextValue

import java.beans.PropertyEditor; //导入方法依赖的package包/类
/**
 * Convert the given text value using the given property editor.
 * @param oldValue the previous value, if available (may be {@code null})
 * @param newTextValue the proposed text value
 * @param editor the PropertyEditor to use
 * @return the converted value
 */
private Object doConvertTextValue(Object oldValue, String newTextValue, PropertyEditor editor) {
	try {
		editor.setValue(oldValue);
	}
	catch (Exception ex) {
		if (logger.isDebugEnabled()) {
			logger.debug("PropertyEditor [" + editor.getClass().getName() + "] does not support setValue call", ex);
		}
		// Swallow and proceed.
	}
	editor.setAsText(newTextValue);
	return editor.getValue();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:TypeConverterDelegate.java

示例13: getAsText

import java.beans.PropertyEditor; //导入方法依赖的package包/类
public String getAsText(final Object object) {
    final PropertyEditor editor = fetchFromPool();
    try {
        editor.setValue(object);
        return editor.getAsText();
    } finally {
        pool.putInPool(editor);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:ThreadSafePropertyEditor.java

示例14: switchFormToPlainValues

import java.beans.PropertyEditor; //导入方法依赖的package包/类
private void switchFormToPlainValues(String originalBundleName) {
    for (RADComponent metacomp : formModel.getAllComponents()) {
        for (FormProperty prop : getComponentResourceProperties(metacomp, VALID_RESOURCE_VALUE, false)) {
            Object value = getAutoValue(prop);
            if (value != null) {
                boolean fire = prop.isChangeFiring();
                prop.setChangeFiring(false); // suppress firing and converting
                try {
                    if (value instanceof I18nValue) {
                        I18nValue i18nValue = (I18nValue) value;
                        prop.setValue(new FormProperty.ValueWithEditor(
                                i18nValue.getValue(), prop.findDefaultEditor()));
                        i18nService.update(i18nValue, null,
                                           getSrcDataObject(),
                                           originalBundleName != null ? originalBundleName : getI18nBundleName(),
                                           null, true);
                    }
                    else if (value instanceof ResourceValue) {
                        ResourceValue resValue = (ResourceValue) value;
                        Object plainValue;
                        PropertyEditor prEd = prop.getCurrentEditor();
                        if (prEd instanceof ResourceWrapperEditor) {
                            prEd.setValue(value);
                            plainValue = ((ResourceWrapperEditor)prEd).getUnwrappedValue();
                        }
                        else {
                            plainValue = resValue.getValue();
                        }
                        prop.setValue(plainValue);
                        resourceService.update(resValue, null, getSourceFile(), designLocale);
                    }
                    addDroppedValue(prop, value); // it will keep data from all locales
                        // (there is no other way to remember this data for undo)
                }
                catch (Exception ex) {
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
                }
                prop.setChangeFiring(fire);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:43,代码来源:ResourceSupport.java

示例15: doConvertValue

import java.beans.PropertyEditor; //导入方法依赖的package包/类
/**
 * Convert the value to the required type (if necessary from a String),
 * using the given property editor.
 * @param oldValue the previous value, if available (may be {@code null})
 * @param newValue the proposed new value
 * @param requiredType the type we must convert to
 * (or {@code null} if not known, for example in case of a collection element)
 * @param editor the PropertyEditor to use
 * @return the new value, possibly the result of type conversion
 * @throws IllegalArgumentException if type conversion failed
 */
private Object doConvertValue(Object oldValue, Object newValue, Class<?> requiredType, PropertyEditor editor) {
	Object convertedValue = newValue;

	if (editor != null && !(convertedValue instanceof String)) {
		// Not a String -> use PropertyEditor's setValue.
		// With standard PropertyEditors, this will return the very same object;
		// we just want to allow special PropertyEditors to override setValue
		// for type conversion from non-String values to the required type.
		try {
			editor.setValue(convertedValue);
			Object newConvertedValue = editor.getValue();
			if (newConvertedValue != convertedValue) {
				convertedValue = newConvertedValue;
				// Reset PropertyEditor: It already did a proper conversion.
				// Don't use it again for a setAsText call.
				editor = null;
			}
		}
		catch (Exception ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("PropertyEditor [" + editor.getClass().getName() + "] does not support setValue call", ex);
			}
			// Swallow and proceed.
		}
	}

	Object returnValue = convertedValue;

	if (requiredType != null && !requiredType.isArray() && convertedValue instanceof String[]) {
		// Convert String array to a comma-separated String.
		// Only applies if no PropertyEditor converted the String array before.
		// The CSV String will be passed into a PropertyEditor's setAsText method, if any.
		if (logger.isTraceEnabled()) {
			logger.trace("Converting String array to comma-delimited String [" + convertedValue + "]");
		}
		convertedValue = StringUtils.arrayToCommaDelimitedString((String[]) convertedValue);
	}

	if (convertedValue instanceof String) {
		if (editor != null) {
			// Use PropertyEditor's setAsText in case of a String value.
			if (logger.isTraceEnabled()) {
				logger.trace("Converting String to [" + requiredType + "] using property editor [" + editor + "]");
			}
			String newTextValue = (String) convertedValue;
			return doConvertTextValue(oldValue, newTextValue, editor);
		}
		else if (String.class.equals(requiredType)) {
			returnValue = convertedValue;
		}
	}

	return returnValue;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:66,代码来源:TypeConverterDelegate.java


注:本文中的java.beans.PropertyEditor.setValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。