Skip to main content

how to handle rotate component from KeyPressedEventAdapter

10 replies [Last post]
deepthi_ventrap...
Offline
Joined: 2006-08-29
Points: 0

could anyone tell me how to implement rotation of component from KeyPressedEventAdapter as when I had compiled the code (a piece of code is shown below) , it says component must be declared final as its used in an inner class. My component has JPanel - JTextArea. So, i cannot handle rotation in MouseClickedEvent as per my knowledge. So I tried the KeyPressedEvent.

(new KeyPressedEventAdapter( new ActionBooleanInt() {
public void performAction(LgEventSource source,
boolean pressed, int key) {
if (pressed && key == KeyEvent.VK_Z) {
new RotateActionBoolean(comp1, (float)Math.PI, 100);
}
}
}));

regards
deepthi

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
deepthi_ventrap...
Offline
Joined: 2006-08-29
Points: 0

Could anyone please suggest me a solution for this asap.. plzzz...

paulby
Offline
Joined: 2003-06-13
Points: 0

I guess comp1 needs to be declared final.

deepthi_ventrap...
Offline
Joined: 2006-08-29
Points: 0

I tried declaring component as final but it didn't help me. The code gets compiled and when I click on the icon in lg3d, the component doesn't appear :(
please find the code below:
public class SwingApplication2
{
public static void main(String[] args)
{
new SwingApplication2();
}
public SwingApplication2(){
Frame3D frame3d = new Frame3D();
final Component3D comp;
comp = new Component3D();
JPanel jp = new JPanel(new BorderLayout());
SwingNode sn = new SwingNode();
JTextArea jt = new JTextArea();

jp.setPreferredSize(new Dimension(400, 400));

jt.setText("plugin");
jt.setEditable(true);
jt.setLineWrap(true);
jt.setWrapStyleWord(true);
jp.add(jt,BorderLayout.CENTER);
sn.setPanel(jp);

comp.setRotationAxis(0.3f, 0.5f, 1.0f);
comp.changeTranslation(0.05f,0.0f,0.0f);

comp.addListener(
(new KeyPressedEventAdapter(ModifierId.CTRL,new ActionBooleanInt() {
public void performAction(LgEventSource source,
boolean pressed, int key)
{
if (pressed && key == KeyEvent.VK_Z) {
new RotateActionBoolean(comp, (float)(Math.PI/2), 100);
}
}
})));

comp.addChild(sn);

frame3d.addChild(comp);
frame3d.setPreferredSize(new Vector3f(0.06f, 0.08f, 0.04f));
frame3d.changeEnabled(true);
frame3d.changeVisible(true);
}
}

Krishna Gadepalli

Hi Deepthi

Here are few of the issues.
1. You really cannot process any key or mouse events (currently)
generated over a SwingNode in the LG domain since all the events are
passed down to Swing and consumed there.
This is something we could/should change so that events are first
processed in the LG domain before passsing them down to Swing. I will
make a note of this - since we are rewriting the AWT implementation anyway.

2. To overcome the above problem, a temporary fix might be to add a
non-swing node to your Component3D and use the events generated over
that to do what you need. (i am including sample code).

3. In the code you sent the "performAction" of RotateActionBoolean was
never getting called - you need to call it explicitly in the
"performAction" method of the ActionBooleanInt

Try running the attached code and pressing Control-Z on the red-sphere

Hope this helps
-krishna

http://forums.java.net/jive/thread.jspa?messageID=157964
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@lg3d.dev.java.net
> For additional commands, e-mail: interest-help@lg3d.dev.java.net
>
>
[SwingApplication2.java]
---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@lg3d.dev.java.net
For additional commands, e-mail: interest-help@lg3d.dev.java.net

krishna_gadepalli
Offline
Joined: 2005-12-14
Points: 0

I just realized that attachments are not visible from the web-interface. So here is the code snippet inline...
-krishna

[code]
public class SwingApplication2 {
public static void main(String[] args) {
new SwingApplication2();
}
public SwingApplication2(){
Frame3D frame3d = new Frame3D();
final Component3D comp;
comp = new Component3D();
JPanel jp = new JPanel(new BorderLayout());
final SwingNode sn = new SwingNode();
JTextArea jt = new JTextArea();

jp.setPreferredSize(new Dimension(400, 400));

jt.setText("plugin");
jt.setEditable(true);
jt.setLineWrap(true);
jt.setWrapStyleWord(true);
jp.add(jt,BorderLayout.CENTER);
sn.setPanel(jp);

comp.setRotationAxis(0.3f, 0.5f, 1.0f);
comp.changeTranslation(0.05f,0.0f,0.0f);

final ActionBoolean ab = new RotateActionBoolean(comp, (float)(Math.PI/2), 100);
comp.addListener(
(new KeyPressedEventAdapter(ModifierId.CTRL,new ActionBooleanInt() {
public void performAction(LgEventSource source,
boolean pressed, int key) {
if (key == KeyEvent.VK_Z) {
ab.performAction(source, pressed);
}
}
})));

SimpleAppearance app = new SimpleAppearance(0.6f, 0f, 0f);
Sphere sphere = new Sphere(0.007f, app);
Transform3D t3d = new Transform3D();
t3d.set(new Vector3f(-0.08f, 0.02f, 0f));
TransformGroup tg = new TransformGroup(t3d);
tg.addChild(sphere);

comp.addChild(tg);
comp.addChild(sn);

frame3d.addChild(comp);
frame3d.setPreferredSize(new Vector3f(0.06f, 0.08f, 0.04f));
frame3d.changeEnabled(true);
frame3d.changeVisible(true);
}
}
[/code]

deepthi_ventrap...
Offline
Joined: 2006-08-29
Points: 0

I tried implementing the code Krishna had posted. The code gets compiled but the component still doesn't appear in lg3D on clicking the icon created for it. I couldn't trace the reason for the same. plz suggest me what changes can be made/how else we can implement rotation of swing component.
regards
deepthi

Krishna Gadepalli

You could take a look at /var/tmp/lgserver.log (on linux) or just
lgserver.log (on windows) to see if there are any error messages that
show up
-krishna

lg3d@javadesktop.org said the following on 10/03/2006 06:21 AM:
> I tried implementing the code Krishna had posted. The code gets compiled but the component still doesn't appear in lg3D on clicking the icon created for it. I couldn't trace the reason for the same. plz suggest me what changes can be made/how else we can implement rotation of swing component.
> regards
> deepthi
> [Message sent by forum member 'deepthi_ventrapragada' (deepthi_ventrapragada)]
>
> http://forums.java.net/jive/thread.jspa?messageID=159192
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@lg3d.dev.java.net
> For additional commands, e-mail: interest-help@lg3d.dev.java.net
>
>

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

deepthi_ventrap...
Offline
Joined: 2006-08-29
Points: 0

Hi Krishna
Please find the part of lgserver.log file which shows the warnings/errors below:

INFO: Waiting for client connection...
Oct 3, 2006 9:07:41 AM org.jdesktop.lg3d.utils.action.AppLaunchAction performAction
WARNING: Executing java app in the same JVM: java SwingApplication2
Using ClassLoader org.jdesktop.lg3d.displayserver.LgClassLoader@1b00766 ID = 58
Classpath = file:/C:/lg3D/bin/../ext/app/SwingApplication2.jar :
Oct 3, 2006 9:07:41 AM java.awt.Lg3dWindowPeer updateFocusableWindowState
WARNING: updateFocusableWindowState not implemented
Oct 3, 2006 9:07:41 AM org.jdesktop.lg3d.utils.action.AppLaunchAction$1 run
WARNING: Failed to start: SwingApplication2
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:589)
at org.jdesktop.lg3d.utils.action.AppLaunchAction$1.run(AppLaunchAction.java:83)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NoClassDefFoundError: SwingApplication2$1
at SwingApplication2.(SwingApplication2.java:66)
at SwingApplication2.main(SwingApplication2.java:25)
... 6 more

Krishna Gadepalli

Hi Deepthi

> Caused by: java.lang.NoClassDefFoundError: SwingApplication2$1
>

When you built your SwingApplication2.jar you must have forgotten to
bundle SwingApplication2$1.class with it
-krishna

> at SwingApplication2.(SwingApplication2.java:66)
> at SwingApplication2.main(SwingApplication2.java:25)
> ... 6 more
> [Message sent by forum member 'deepthi_ventrapragada' (deepthi_ventrapragada)]
>
> http://forums.java.net/jive/thread.jspa?messageID=159492
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@lg3d.dev.java.net
> For additional commands, e-mail: interest-help@lg3d.dev.java.net
>
>

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

deepthi_ventrap...
Offline
Joined: 2006-08-29
Points: 0

Hi Krishna
U were right,I forgot to bundle it. Its working fine now. Thank you once again.
regards
deepthi