Add a new home property to a change listener

This topic has been viewed 5580 times and has 2 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
Post Reply New Topic
enkonyito
Posts: 607
Joined: Thu May 28, 2015 4:52 pm

Add a new home property to a change listener

Post by enkonyito »

The setProperty method allow to set a new property associated with a home.
But can this property be taken into account by the addPropertyChangeListener method without returning an IllegalArgumentException if you use valueOf (String name)?

With this code:

Code: Select all

this.home.addPropertyChangeListener(Home.Property.valueOf(ENHANCED_EXTERNAL_BRIGHTNESS),
	    new PropertyChangeListener() {
	    	public void propertyChange(PropertyChangeEvent ev) {
	    		isEnhancedExternalBrightness = Boolean.parseBoolean(home.getProperty(ENHANCED_EXTERNAL_BRIGHTNESS));
	    		externalBrightnessEnabledCheckBox.setSelected(isEnhancedExternalBrightness);
	    	}
    	});
I have this error:

Code: Select all

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: No enum constant com.eteks.sweethome3d.model.Home.Property.enhancedExternalBrightness
EnkoNyito
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Add a new home property to a change listener

Post by Puybaret »

The method [font=courier new]valueOf[/font] of an enum takes into account only values of the enum that exist.
The main problem comes from the fact that enums are [font=courier new]final[/font], and using enums for these properties is actually a wrong idea I had [:(]
Emmanuel Puybaret, Sweet Home 3D creator
enkonyito
Posts: 607
Joined: Thu May 28, 2015 4:52 pm

Re: Add a new home property to a change listener

Post by enkonyito »

I wanted to bind the enhance external brightness option of the photo panel to the video panel.
The alternative would be an implicit selection from the photo panel only.
The main problem comes from the fact that enums are [font=courier new]final[/font], and using enums for these properties is actually a wrong idea I had [:(]
I do not know if other developers needed to add a new home property to existing ones but if there is a solution for it to be possible without too much changing the source code, why not?
EnkoNyito
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 1 guest