Search in sources :

Example 1 with Property

use of org.openide.nodes.Node.Property in project gephi by gephi.

the class LayoutProperty method createProperty.

/**
     * Create a property.
     * The parameter <code>propertyName</code> will be used as the canonical name of the <code>LayoutProperty</code>.
     * @param layout The layout instance
     * @param valueType The type of the property value, ex: <code>Double.class</code>
     * @param propertyName The display name of the property
     * @param propertyCategory A category string or <code>null</code> for using
     * default category
     * @param propertyDescription A description string for the property
     * @param getMethod The name of the get method for this property, must exist
     * to make Java reflexion working.
     * @param setMethod The name of the set method for this property, must exist
     * to make Java reflexion working.
     * @return the created property
     * @throws NoSuchMethodException if the getter or setter methods cannot be found
     */
public static LayoutProperty createProperty(Layout layout, Class valueType, String propertyName, String propertyCategory, String propertyDescription, String getMethod, String setMethod) throws NoSuchMethodException {
    Property property = new PropertySupport.Reflection(layout, valueType, getMethod, setMethod);
    property.setName(propertyName);
    property.setShortDescription(propertyDescription);
    return new LayoutProperty(property, propertyCategory, propertyName);
}
Also used : Property(org.openide.nodes.Node.Property)

Example 2 with Property

use of org.openide.nodes.Node.Property in project ACS by ACS-Community.

the class CheckBoxEditor method getInPlaceCustomEditor.

/*
   *  (non-Javadoc)
   * @see org.openide.explorer.propertysheet.editors.EnhancedPropertyEditor#getInPlaceCustomEditor()
   */
public Component getInPlaceCustomEditor() {
    if (editor == null) {
        editor = new JCheckBox();
        editor.setOpaque(false);
        editor.addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent e) {
                setBoolValue(editor.isSelected());
            }
        });
    }
    if (!editableMode) {
        editor.setSelected(getBoolValue());
    } else {
        // immediately invert the selection. This is what the user expects, because he does not want to click twice on the
        // checkbox. We want to avoid the normal behavior of the program, that requires you to click once to activate 
        // editing mode and once to change the value.
        boolean invBoolValue = !getBoolValue();
        editor.setSelected(invBoolValue);
        Boolean invBooleanObject = invBoolValue ? Boolean.TRUE : Boolean.FALSE;
        // we have to go directly to the Node.Property because this object (the PropertyEditor) 
        // does not propagate a setValue(invBoolValue). It gets blocked in the propertyChange() method of 
        // the private class PropertyPanel.EditorListener.
        // this is less of a Hack than it looks like, c.f. Javadoc of 
        // {@link org.openide.explorer.propertysheet.PropertyEnv.getFeatureDescriptor()}
        FeatureDescriptor fd = propertyEnv.getFeatureDescriptor();
        if (fd instanceof Node.Property) {
            try {
                setNodeProperty(invBoolValue, (Property) fd);
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            System.out.println("fd not Node.Property, but " + fd.getClass());
        }
        // nevertheless call this.setValue() to be coherent
        setBoolValue(invBoolValue);
    }
    return editor;
}
Also used : JCheckBox(javax.swing.JCheckBox) ChangeEvent(javax.swing.event.ChangeEvent) FeatureDescriptor(java.beans.FeatureDescriptor) ChangeListener(javax.swing.event.ChangeListener) Property(org.openide.nodes.Node.Property) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

Property (org.openide.nodes.Node.Property)2 FeatureDescriptor (java.beans.FeatureDescriptor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 JCheckBox (javax.swing.JCheckBox)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1