CMenu/CDopDownButton question

Hi all, hi beni.
My question is if you can embed swing components as children of a CMenu or CDopDownButton?
For example, i want to have a zoom slider that pops out if i trigger the CDropDownButton/CMenu.
Is this possible?

Thanks very much in advance!
Greetings, -chris-

Not directly. But you can write a new CAction with the desired behavior. Have a look at the Notes demo-application, this demo adds such a special action. The action is called “IconAction”, you need to install a special handler for each DockTheme (in the demo application look out for NoteBasicTheme for an example).

In Common you have to extend the Common-version of themes (i.e. extend CFlatTheme instead of FlatTheme). You would need to instruct the ThemeMap (CControl.getThemes) to use your new themes. Call the method “put” to override a theme.

… and I add a mental note to add a “custom-action” sometimes in the future…

[edit: if necessary I can write some code for you, just not while I’m at work…]

Hi Beni,
thanks very much for the fast reply. At the moment i’m trying to understand how the IconAction works, which you suggested.

Greetings, -chris-

Hi Beni,
i played around with the notes application a little bit, but i didn’t get the point where to put the things to get a custom panel with a DropDown action.
I didn’t even understand why i have to modify the theme for that.
Maybe you could give me a more simplistic example. Of course only when you have some spare time for that.

Many thanks in advance for your help!
Greetings, -chris-

During the weekend I worked on this problem and added a „CPanelPopup“-action to Common. My proposal: download the current version directly from the repository (You need to register at JavaForge and at the DockingFrames-project to gain access. The repository itself has the url: http://svn.javaforge.com/svn/DockingFrames ). There will be a file which does not compile, but it is not yet used anywhere so you can delete or ignore it. The project itself is an Eclipse project.

I can also upload a „preview2b“, but that will require some time.

[edit: or I give you the example. Your choice :stuck_out_tongue_winking_eye: ]

Hi Beni,
well if the choice is up to me i would prefer a simple example :slight_smile:
I also will use your updated sources.

Thanks very much again for your support!!
Greetings, -chris-

Ok, I’ll write something. But not today.

This is a demo programm adding a new CAction to Common. The action does not do anything useful other than call “println” but the programm is a good start for further customizing. Hope that helps a little.

Hi Beni,
thanks again for all your help!
I guess it will take several days for me to understand how this is done.
If i have any questions on that i will get back to you.

Greetings, -chris-

Hi Beni,
in the meantime i managed to get a custom popup. But there’s one thing i do not understand.
I’ve wrote my own theme class deriving from EclipseTheme which looks like this:

...
	@Override
	public void install(DockController controller)
	{
		ActionViewConverter converter = controller.getActionViewConverter();
		converter.putTheme(ZoomAction.ZOOM, ViewTarget.TITLE, new ViewGenerator<ZoomAction, BasicTitleViewItem<JComponent>>()
		{

			public BasicTitleViewItem<JComponent> create(ActionViewConverter converter, ZoomAction action, Dockable dockable)
			{
				ZoomButtonHandler handler = new ZoomButtonHandler(action, dockable);
				/**
				 * Connect action to handler, since there's no other way, to get
				 * the ZoomButtonHandler later on
				 */
				action.setHandler(handler);
				RoundRectButton button = new RoundRectButton(handler);
				handler.setModel(button.getModel());
				return handler;
			}
		});

...

The thing i do not understand is that the method

public BasicTitleViewItem<JComponent> create(ActionViewConverter converter, ZoomAction action, Dockable dockable)

gets called 10 times when my application starts. But I only added the action to 1 view.
I do not understand why this method is called so many times.
Maybe you can tell me why this behavior is like that.

Edit: I wrote a workaround for my problem, which looks like that:

			public BasicTitleViewItem<JComponent> create(ActionViewConverter converter, ZoomAction action, Dockable dockable)
			{
				if(action.getHandler() == null)
				{
					ZoomButtonHandler handler = new ZoomButtonHandler(action, dockable);
					/**
					 * Connect action to handler, since there's no other way, to get
					 * the ZoomButtonHandler later on
					 */
					action.setHandler(handler);
					RoundRectButton button = new RoundRectButton(handler);
					handler.setModel(button.getModel());
					return handler;
				}
				else
					return action.getHandler();
			}

It avoids my problem, but i still dunno why this method gets called so often.

Many thanks in advance for any help!!
Greetings, -chris-

When buttons are reorded, Dockables moved around, titles added and removed, titles made so small they can’t show all actions … every-time the actions get “rebuild”. It’s not nice, but it keeps the system correct all the time.
Btw.: you get a problem with your cached handler as soon as the action is displayed at two places simultaneously (which can happen).

Thanks for the clarification. But recreating the panel with the slider every time seems like a resource hog and also the settings of my slider get lost every time unless i cache them.

Btw.: you get a problem with your cached handler as soon as the action is displayed at two places simultaneously (which can happen).

I hope that’s not gonna happen ;). At least i’m not planning to reuse the action more than once.
Can you tell me in which case the action can be displayed twice?

Greetings, -chris-

For example when the user grabs the title and starts a drag&drop operation. The framework does not take a screenshot of the old title, but creates a new one (this allows to have an animation). So now there are two titles, with the same action displayed twice.

And yes, all the standard-actions use some kind of cache to circumvent the problems you just described.