Joined: Jul 4, 2011
Post Count: 22
Status:
Offline
Is this a mistake in the ActionAdapter Class?
Hi Emmanuel,
For the plugin I'm writing I'd like the plugin's icon in the Toolbar to stay "toggled" when the user clicks it (like the standard drawing modes, selection and panning). But the PluginAction is wrapped in an ActionAdapter instance and has no knowledge of the button it's assigned to so it can't access it's ButtonModel.
So I tried another approach: have the icon change it's image when it's clicked to make it look like setSelected(true) was called in the ButtonModel.
Now the ActionAdapter Class registers itself as a listener for the PluginAction Class and propagates it's changes. Before this happens, you're translating the PluginAction properties so that they match the keys for the Action class, like so :
if (PluginAction.Property.NAME.name().equals(propertyName)) propertyChangeSupport.firePropertyChange(new PropertyChangeEvent(ev.getSource(), Action.NAME, oldValue, newValue));
you're also putting this code in a if statement that makes sure the event is fired only when the new value for the property is not null. However, this is how this new value is obtained:
Here, the getValue() method is expecting a Key for a property from Action, but it's recieving one from PluginAction, wich means the output is always null because none of the if statements is going to eval to true. eg:
if("NAME".equals("Name")) // false
So I think either the keys in PluginAction should be made to match those of the Action Class, or they should be translated before being passed to getValue().
Please correct me if I'm wrong. Thanks in advance.
France
Joined: Nov 7, 2005
Post Count: 9426
Status:
Offline
Re: Is this a mistake in the ActionAdapter Class?
Thanks for finding out this bug. I fixed it by simply retrieving property value with ev.getNewValue(). As I just released version 3.3, this correction won't be released in a close future but I committed it in CVS. If you need it, you'll have to work on the current version of the source code.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
Joined: Jul 4, 2011
Post Count: 22
Status:
Offline
Re: Is this a mistake in the ActionAdapter Class?
Emmanuel, I was able to do what I wanted but the result wasn't extremely satisfaying because all what i can do is surround the icon with a rectangle, however the other buttons in the Toolbar have the bounds of their button surrounded with a rectangle not the icon. So there's a small difference in the size If you have a workround for this I'd love to hear from you! Thanks!
France
Joined: Nov 7, 2005
Post Count: 9426
Status:
Offline
Re: Is this a mistake in the ActionAdapter Class?
Instead of trying to show the same icon as selected, I would show a different icon, like for example the locked / unlocked icon used at the top left corner of the plan.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator