|
Sweet Home 3D Forum » List all forums » » Forum: Developers » » » Thread: Is this a mistake in the ActionAdapter Class? |
|
| Print at Dec 21, 2025, 12:02:24 AM | View all posts in this thread on one page |
| Posted by Cardinal at Jul 28, 2011, 9:33:01 AM |
|
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: String propertyName = ev.getPropertyName(); Object newValue = getValue(propertyName); 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. |
| Posted by Puybaret at Jul 28, 2011, 11:08:57 AM |
|
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 |
| Posted by Cardinal at Jul 28, 2011, 1:02:42 PM |
|
Re: Is this a mistake in the ActionAdapter Class? No problem I'll make this modification for the current version and building against it, assuming it'll be there in future versions ![]() |
| Posted by Cardinal at Jul 28, 2011, 2:04:47 PM |
|
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! |
| Posted by Puybaret at Jul 29, 2011, 1:25:01 PM |
|
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 |
| Posted by Cardinal at Jul 31, 2011, 7:18:56 PM |
|
Re: Is this a mistake in the ActionAdapter Class? This could be a nice alternative indeed. Thanks! |
|
|
Current timezone is GMT Dec 21, 2025, 12:02:24 AM |