Attached is some ugly sample code (just a hacked HelloUniverse.java) to
show that JPopup works with JDK1.2.2 and Java3D1.1.2OpenGL.
Note that
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
must occur before the new JPopupMenu as it only affects JPopupMenus
created after the call, any created before are still rendered as
lightweight popups.
The problem Tachio describes with it only displaying when the JPopupMenu
intersects the edge of the Canvas3D is exactly the behaviour you see
with a lightweight popup.
Hopefully the sample code will stop a few of these questions for a
while.
Tim.
Tachio Terauchi wrote:
>
> Thank you, but I do have that disabled. In fact, JMenu works fine. It's
> JPopupMenu not working correctly. If you do have JPopupMenu working,
> could you send me a small code of that? Thanks in advance.
>
> -Tachio
>
> On Thu, 22 Jul 1999, Justin Couch wrote:
>
> > Tachio Terauchi wrote:
> > >
> > > Hi,
> > >
> > > Is it possible at all to display JPopupMenu over Canvas3D? I got it to be
> > > displayed if the JPopupMenu intersects an edge of the Canvas3D but not
> > > when the JPopupMenu is entirely within the Canvas3D.
> >
> > http://tintoy.ncsa.uiuc.edu/~srp/java3d/howto.html#menus
> >
> > --
> > Justin Couch Author, Java Hacker
> > Snr Software Engineer [EMAIL PROTECTED]
> > ADI Ltd, Systems Group http://www.vlc.com.au/~justin/
> > Java3D FAQ: http://tintoy.ncsa.uiuc.edu/~srp/java3d/faq.html
> > -------------------------------------------------------------------
> > "Look through the lens, and the light breaks down into many lights.
> > Turn it or move it, and a new set of arrangements appears... is it
> > a single light or many lights, lights that one must know how to
> > distinguish, recognise and appreciate? Is it one light with many
> > frames or one frame for many lights?" -Subcomandante Marcos
> > -------------------------------------------------------------------
> >
> > ===========================================================================
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> > of the message "signoff JAVA3D-INTEREST". For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
> >
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
--
Tim Stevenson
Surpac Software International
162A Roslyn Avenue, Blackmans Bay, Tasmania, Australia 7052
Phone/Fax: +61 3 62294610
Home Phone: +61 3 62298866
Email: [EMAIL PROTECTED]
/*
* @(#)HelloUniverse.java 1.48 99/05/20 14:07:00
*
* Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
*/
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import java.awt.Dimension;
import java.awt.AWTEvent;
import java.awt.Event;
import java.util.Enumeration;
class PickCanvas extends Behavior {
protected WakeupCriterion wakeupCondition;
public void initialize() {
wakeupCondition = new WakeupOnAWTEvent(Event.MOUSE_DOWN);
wakeupOn(wakeupCondition);
}
public void processStimulus (Enumeration criteria) {
WakeupCriterion wakeup;
AWTEvent[] evt = null;
while (criteria.hasMoreElements()) {
wakeup = (WakeupCriterion)criteria.nextElement();
if (wakeup instanceof WakeupOnAWTEvent)
evt = ((WakeupOnAWTEvent)wakeup).getAWTEvent();
}
if (evt[0] instanceof MouseEvent){
MouseEvent e = (MouseEvent) evt[0];
System.out.println("got mouse event (" + e.getPoint().x + ", " +
e.getPoint().y + ")");
JPopupMenu menu = new JPopupMenu();
if (SwingUtilities.isLeftMouseButton(e)) {
menu.add("left");
System.out.println("left");
} else if (SwingUtilities.isRightMouseButton(e)) {
menu.add("right");
System.out.println("right");
} else {
menu.add("other");
System.out.println("other");
}
menu.show(e.getComponent(), e.getX(), e.getY());
}
wakeupOn (wakeupCondition);
}
}
public class HelloUniversePopup extends JPanel {
public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
// Create the transform group node and initialize it to the
// identity. Enable the TRANSFORM_WRITE capability so that
// our behavior code can modify it at runtime. Add it to the
// root of the subgraph.
TransformGroup objTrans = new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objTrans);
// Create a simple shape leaf node, add it to the scene graph.
objTrans.addChild(new ColorCube(0.4));
// Create a new Behavior object that will perform the desired
// operation on the specified transform object and add it into
// the scene graph.
AxisAngle4f axisAngle = new AxisAngle4f(0.0f, 0.0f, 1.0f,
-(float)Math.PI / 2.0f);
Transform3D yAxis = new Transform3D();
Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE,
0, 0,
4000, 0, 0,
0, 0, 0);
RotationInterpolator rotator =
new RotationInterpolator(rotationAlpha, objTrans, yAxis,
0.0f, (float) Math.PI*2.0f);
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
rotator.setSchedulingBounds(bounds);
objTrans.addChild(rotator);
// Have Java 3D perform optimizations on this scene graph.
//objRoot.compile();
return objRoot;
}
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
public HelloUniversePopup() {
setLayout(new BorderLayout());
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
add("Center", c);
// Create a simple scene and attach it to the virtual universe
BranchGroup scene = createSceneGraph();
SimpleUniverse u = new SimpleUniverse(c);
Behavior b = new PickCanvas();
scene.addChild(b);
b.setSchedulingBounds(bounds);
// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
//
// The following allows HelloUniverse to be run as an application
// as well as an applet
//
public static void main(String[] args) {
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
JFrame frame = new JFrame("Hello Universe Popup");
frame.setSize(new Dimension(256, 256));
final JPanel panel = new HelloUniversePopup();
frame.getContentPane().add(panel);
frame.show();
}
}