當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。