Skip to main content

How to set the location of a SGComponent?

6 replies [Last post]
keeskuip
Offline
Joined: 2003-06-17
Points: 0

How to set the location and size of a SGComponent?

The solution I found was:

JSGPanel panel = new JSGPanel();
JButton button = new JButton("Press me");
SGComponent sgButton = new SGComponent();
sgButton.setComponent(button);
SGTransform.Translate translate = SGTransform.createTranslation(10, 20, sgButton);
panel.add(translate);

Am I right? if so, I find this a very strange interface! I would expect:
JSGPanel panel = new JSGPanel();
JButton button = new JButton("Press me");
SGComponent sgButton = new SGComponent();
sgButton.setComponent(button);
sgButton.setLocation(10, 2);
panel.add(sgButton);

Why do I need to add a SGTransform.Translate to the panel? I want to add a button not a translation! (Please look at the scenegraph of netbeans (graph.netbeans.org)) It has a
very nice API.

Kees.

Reply viewing options

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

> Our first priority was to provide a compact scene
> graph API for use in the JavaFX Script runtime. The
> design of the scene graph favored
> cleanliness-of-implementation over ease-of-use, and
> from that aspect I think we did pretty well.

JavaFX is no small undertaking! So first things first.

> As for the lack of setLocation() method on
> SGComponent... I think we purposely did not provide
> an SGComponent.setLocation() method, because the
> original intention was that it should be possible to
> call setLocation() on the underlying JComponent and
> everything would work as you expected (in your first
> posting).

But it's not only the setLocation(). It's just an example. If I have to
scale/rotate/shear/etc. a widget I also have the same construction.

keeskuip
Offline
Joined: 2003-06-17
Points: 0

By looking at the API it doesn't seem that this library is intended to be used by plain java programs. I think it is designed specifically for JavaFX. Then I can understand this strange API.

campbell
Offline
Joined: 2003-06-24
Points: 0

> By looking at the API it doesn't seem that this
> library is intended to be used by plain java
> programs. I think it is designed specifically for
> JavaFX. Then I can understand this strange API.

Our first priority was to provide a compact scene graph API for use in the JavaFX Script runtime. The design of the scene graph favored cleanliness-of-implementation over ease-of-use, and from that aspect I think we did pretty well. It's only been in the last few weeks that we've started exploring how we can make the API more user friendly for Java developers, so this feedback is useful.

As for the lack of setLocation() method on SGComponent... I think we purposely did not provide an SGComponent.setLocation() method, because the original intention was that it should be possible to call setLocation() on the underlying JComponent and everything would work as you expected (in your first posting). But looking at the code in SGComponent, it seems that the code does not currently work that way (the "shell" is anchored to (0,0) always), so I'm not sure if something got lost over time. Someone else from the team (Igor?) may have a better idea.

Thanks,
Chris

rah003
Offline
Joined: 2004-05-26
Points: 0

> As for the lack of setLocation() method on SGComponent... I think we purposely did not provide
> an SGComponent.setLocation() method, because the original intention was that it should be possible to
> call setLocation() on the underlying JComponent and everything would work as you expected (in your first
> posting). But looking at the code in SGComponent, it seems that the code does not currently work that way
> (the "shell" is anchored to (0,0) always), so I'm not sure if something got lost over time. Someone else
> from the team (Igor?) may have a better idea.

Yeah I thought originally the same thing - use setLocation() from the component itself and it didn't work. Then again since all other SG*** have their setLocation() I would prefer to get one for for SGComponent as well. Why? perhaps I'm just plain lazy and perhaps it is a usability thing. It seems easier to use something more static like text or image during testing the scene and replace it only later by the real components. I definitively don't want to have to change too much code to do this. In my opinion all the graph leafs should be easily interchangeable.

rah003
Offline
Joined: 2004-05-26
Points: 0

I've run into exactly same issue. Currently there is no way to set location on SGComponent apart from using Transform.Translate. If one of the intentions behind releasing SceneGraph early was to get API right, this is one of the things that I would think as of really important (specially since other leafs (SGText and SGImage) have their own setLocation() already implemented).

mpymm
Offline
Joined: 2007-12-12
Points: 0

setLocation on SGText just changes where the text is rendered relative to the node's origin - it doesn't change the geometry of the scene. I think the intent is to let you support text alignments relative to the node's origin rather than specify layout.