Skip to main content

ActionManager and Actions with state

2 replies [Last post]
jtr
Offline
Joined: 2003-06-10
Points: 0

I have a question about how to use ActionManager. I have a JXPanel with a JXEditor and a toolbar created via code like this:

<br />
        ActionManager manager = ActionManager.getInstance();<br />
        manager.addAction(ActionFactory.createTargetableAction("font-bold", "font-bold"));<br />
        List l = Arrays.asList("font-bold");<br />
        _editorToolbarPanel.add(manager.getFactory().createToolBar(l));<br />

which did result in a somewhat functional "font-bold" button on a toolbar. When I select text and click on it, the text gets the bold attribute. Great. But the button state doesn't track of the attributes of the text under my cursor.

The toolbar's bold button state is never shown depressed. I do see code in JXEditorPane.CaretHandler which looks like it should be setting it, but I don't see the results.

Obviously, I'm missing something important. Is there something else I'm supposed to do?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jtr
Offline
Joined: 2003-06-10
Points: 0

I spent some time with the debugger and found that if an Action has state, it needs to be created with the 'toggle" parameter set to true. Apparently this means that the button can be toggled.

[code]
manager.addAction(ActionFactory.createTargetableAction("font-bold", "font-bold", null, true));
[/code]

This ends up calling AbstractActionExt.setStateAction(), which makes this a stateful action. Cool that it works and interesting how it works. But a little hard to find docs for.

Kleopatra

looks like I missed a couple of posts again (broken traffic between
forum and mailinglist) ... arrghhh, will go to the forum and look at the
preceding to this soon.

Here just a quick note: currently the action package is under review
(thread: "[FYI]: Action overhaul under way") so there probably will be
changes. Just started, though with a cleanup of the AbstractActionExt.

That said, I'm be most happy to have somebody really trying to use it :-)

Cheers
Jeanette

> I spent some time with the debugger and found that if an Action has state, it needs to be created with the 'toggle" parameter set to true. Apparently this means that the button can be toggled.
>
> [code]
> manager.addAction(ActionFactory.createTargetableAction("font-bold", "font-bold", null, true));
> [/code]
>
>
> This ends up calling AbstractActionExt.setStateAction(), which makes this a stateful action. Cool that it works and interesting how it works. But a little hard to find docs for.

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net