Sorry,

Better with attachments !

Arnaud

-----Message d'origine-----
De�: Discussion list for Java 3D API
[mailto:[EMAIL PROTECTED] De la part de Kevin Glass
Envoy�: jeudi 3 avril 2003 09:39
��: [EMAIL PROTECTED]
Objet�: Re: [JAVA3D] RE : [JAVA3D] JDialog and Java3D

Most likely this is to do with how you're creating the canvas that is
being used in the dialog. When you set the dialog to modal the
setVisible(true) call blocks on the current thread until
setVisible(false)
is called. This "blocking" is probably stopping the rendering thread
from
running.

Have to see the code structure to guess at the problem really,

Kev

> Thank you Isaac for this help, but I tried and it doesn�t work !
> Moreover, I read that JDialog are not LightWeight components although
> they are swing Components.
> Could it be a problem of frame focus ? (actually I have a JFrame with
a
> 3d scene and another one which is the JDialog, with another 3d scene.
> And I would like to have this one on top of the first in modal mode!)
>
> -----Message d'origine-----
> De : Discussion list for Java 3D API
> [mailto:[EMAIL PROTECTED] De la part de Isaac Brobbey
> Envoy� : mercredi 2 avril 2003 04:05
> � : [EMAIL PROTECTED]
> Objet : Re: [JAVA3D] JDialog and Java3D
>
> Problems with swing and java3D , try
> JPopupMenu.setDefaultLightWeightPopupEnabled(false);
>
> ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
>
> Hope that helps.
>
> Isaac Brobbey
> Java2 & Java3D
> MS/CIT Project
> -----Original Message-----
> From: Discussion list for Java 3D API
> [mailto:[EMAIL PROTECTED] On Behalf Of Arnaud Forgues
> Sent: Wednesday, April 02, 2003 2:09 PM
> To: [EMAIL PROTECTED]
> Subject: [JAVA3D] JDialog and Java3D
>
> Hello Guys,
>
> I am trying to insert a 3d scene into a swing component JDialog. This
> works well while I set the �modal� parameter to false.
> However if I set it to true, the dialog frame is frozen and my 3d
scene
> doesn�t render!!
> I am sorry if it is a well-known problem between swing and java3d but
> could anyone enlighten me on the problem ?
>
> Regards
>
> Arnaud Forgues


--
Jose UML - http://www.newdawnsoftware.com/jose
Pondering RPG - http://pondering.newdawnsoftware.com

========================================================================
===
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".
package jchess3d;

import java.awt.*;
import javax.swing.*;
import jchess3dInterface.JChessActionListener;
import jchess3dInterface.JChessFrame;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * <p>Title: JChess3D</p>
 * <p>Description: a 3D chess game in java</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: ISEP</p>
 * @author Arnaud Forgues
 * @version 1.0
 */

public class JChessPromoteDialog extends JDialog implements ActionListener {

  JChessFrame owner;
  int color;
  ButtonGroup radioGroup;
  JRadioButton qbutton, bbutton, kbutton, rbutton;
  JButton okButton;
  JLabel label;
  JChessPromote3D pieceView;
  Box globalBox = new Box(BoxLayout.Y_AXIS);
  Box middleBox = new Box(BoxLayout.X_AXIS);
  Box buttonsBox = new Box(BoxLayout.Y_AXIS);

  public JChessPromoteDialog(JChessFrame frame, String title, boolean modal) {
    super(frame, title, modal);

    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);

    this.owner = frame;

    try {
      jbInit();
      pack();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }

  public JChessPromoteDialog() {
    this(null, "", false);
  }

  public void setColor(int type)
  {
    this.color = type;
    pieceView.setPiece(JChessPromote3D.QUEEN, this.color);
    this.qbutton.setSelected(true);
  }

  private void jbInit() throws Exception {
    //Center the window
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = this.getSize();
    if (frameSize.height > screenSize.height) {
      frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width) {
      frameSize.width = screenSize.width;
    }
    this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);

    this.getContentPane().setLayout(new BorderLayout());

    // ajout d'un texte demandant � l'utilisateur de choisir une piece
    label = new JLabel("Choose a piece to exchange with your pawn");
    globalBox.add(label);

    // ajout d'une boite horizontale contenant deux autres boites
    globalBox.add(middleBox);

      // ajout des radioboutons � la boite verticale constituant la premiere boite
    radioGroup = new ButtonGroup();
    qbutton = new JRadioButton("Queen", true);
    qbutton.addActionListener(this);
    buttonsBox.add(qbutton);
    radioGroup.add(qbutton);
    bbutton = new JRadioButton("Bishop", false);
    bbutton.addActionListener(this);
    buttonsBox.add(bbutton);
    radioGroup.add(bbutton);
    kbutton = new JRadioButton("Knight", false);
    kbutton.addActionListener(this);
    buttonsBox.add(kbutton);
    radioGroup.add(kbutton);
    rbutton = new JRadioButton("Rook", false);
    rbutton.addActionListener(this);
    buttonsBox.add(rbutton);
    radioGroup.add(rbutton);

    middleBox.add(buttonsBox);

      // ajout de la fenetre contenant la vue en 3d de la piece selectionn�e dans la seconde boite
    pieceView = new JChessPromote3D();
    pieceView.setSize(250, 300);
    middleBox.add(pieceView);

    // Ajout du bouton de validation du choix de la piece � la boite principale
    okButton = new JButton("OK");
    okButton.setName("PromoteOkButton");
    okButton.addActionListener(new JChessActionListener(owner));
    globalBox.add(okButton);

    // ajout de la boite principale au panel de la boite de dialogue
    getContentPane().add(globalBox);
  }

  public ButtonGroup getButtonGroup() {
    return this.radioGroup;
  }

  public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("Queen"))
    {
      this.pieceView.setPiece(JChessPromote3D.QUEEN, this.color);
    }
    else if (e.getActionCommand().equals("Bishop"))
    {
      this.pieceView.setPiece(JChessPromote3D.BISHOP, this.color);
    }
    else if (e.getActionCommand().equals("Knight"))
    {
      this.pieceView.setPiece(JChessPromote3D.KNIGHT, this.color);
    }
    else if (e.getActionCommand().equals("Rook"))
    {
      this.pieceView.setPiece(JChessPromote3D.ROOK, this.color);
    }
    else
      System.out.println("Unknown actionPerformed code");
  }
}
package jchess3d;

import javax.media.j3d.*;
import javax.vecmath.*;

import java.awt.*;
import javax.swing.*;

import com.sun.j3d.loaders.*;
import com.sun.j3d.utils.behaviors.vp.*;
import com.sun.j3d.utils.universe.*;

/**
 * <p>Title: JChessPromote3D</p>
 * <p>Description: a 3D component in which a piece is shown for pawn promotion</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: ISEP</p>
 * @author Arnaud Forgues
 * @version 1.0
 */

public class JChessPromote3D extends JComponent {

  public static final int QUEEN = 0;
  public static final int BISHOP = 1;
  public static final int KNIGHT = 2;
  public static final int ROOK = 4;

  private Canvas3D canvas;
  private SimpleUniverse universe;
  private BranchGroup rootVolume;
  private TransformGroup tgVolume;
  private TransformGroup objScale;
  private BoundingSphere bounds;

  /**
   * Constructeur : initialise l'univers3D de l'objet et ins�re une reine
   */
  public JChessPromote3D() {
    /*----- Contenu de la fen�tre -----*/
    this.setLayout(new BorderLayout());

    /*----- Cr�ation du Canvas -----*/
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    canvas = new Canvas3D(config);
    this.add("Center", canvas);

    /*----- Cr�ation de l'univers virtuel -----*/
    this.universe = new SimpleUniverse(canvas);

    /*----- Position de l'observateur -----*/
    this.universe.getViewingPlatform().setNominalViewingTransform();

    /*----- Cr�ation du noeud racine et de la matrice de transformation de la branche volume -----*/
    this.tgVolume = new TransformGroup();

    /*----- Ajout d'un comportement clavier -----*/
/*    this.tgVolume.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    this.tgVolume.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);*/

    this.rootVolume = new BranchGroup();
    this.rootVolume.addChild(this.tgVolume);
    this.tgVolume.addChild(createBranchVolume());

    // add mouse behaviors to the ViewingPlatform
    ViewingPlatform viewingPlatform = universe.getViewingPlatform();

    PlatformGeometry pg = new PlatformGeometry();

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.2f, 0.2f, 0.2f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    pg.addChild(ambientLightNode);

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f light2Direction = new Vector3f( -1.0f, -1.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    pg.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    pg.addChild(light2);

    viewingPlatform.setPlatformGeometry(pg);

    OrbitBehavior orbit = new OrbitBehavior(canvas, OrbitBehavior.REVERSE_ALL);
    orbit.setSchedulingBounds(bounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    /*----- Ajout de la branche de volume -----*/
    this.universe.addBranchGraph(rootVolume);

  }

  /**
   * Construit la branche de Volume de la scene 3D (ensemble des objets)
   * @return le noeud de l'arbre g�rant la branche du volume
   */
  private BranchGroup createBranchVolume() {

    bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    BranchGroup root = new BranchGroup();

    objScale = new TransformGroup();
    objScale.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    objScale.setCapability(Group.ALLOW_CHILDREN_READ);
    objScale.setCapability(Group.ALLOW_CHILDREN_WRITE);

    /*** Mise � l'echelle des objets 3d ***/
    Transform3D t3ds = new Transform3D();
    t3ds.setScale(0.03);
    Transform3D t3dt = new Transform3D();
    t3dt.setTranslation(new Vector3d(0.0, -20.0, 0.0));
    t3ds.mul(t3dt);
    objScale.setTransform(t3ds);
    root.addChild(objScale);

    /*** Initialisation du background ***/
    Color3f bgColor = new Color3f(0.0f, 0.0f, 0.2f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    root.addChild(bgNode);

    /*** Optimisation java3D du graphe ***/
    root.compile();

    return root;
  }

  /**
   * Remplace (si n�cessaire) la pi�ce actuelle affich�e par celle indiqu� par le flag
   * @param piece identifie la pi�ce � ins�rer
   * @param color identifie la couleur de cette pi�ce
   */
  public void setPiece(int piece, int color) {

    // On retire le model s'il y en a deja un (ainsi on remplace la piece par la nouvelle)
    if (objScale.numChildren() != 0)
      objScale.removeChild(0);

    Scene model=null;

    // on charge le nouveau model 3d � partir du fichier correspondant
    switch  (piece)
    {
      case QUEEN:
        if (color == JChessPiece.WHITE_PIECE)
        {
          model = JChessObject.loadFile("images/whitequeen.3ds");
        }
        else
        {
          model = JChessObject.loadFile("images/blackqueen.3ds");
        }
        break;

      case BISHOP:
        if (color == JChessPiece.WHITE_PIECE)
        {
          model = JChessObject.loadFile("images/whitemad.3ds");
        }
        else
        {
          model = JChessObject.loadFile("images/blackmad.3ds");
        }
        break;

      case KNIGHT:
        if (color == JChessPiece.WHITE_PIECE)
        {
          model = JChessObject.loadFile("images/whitehorse.3ds");
        }
        else
        {
          model = JChessObject.loadFile("images/blackhorse.3ds");
        }
        break;

      case ROOK:
        if (color == JChessPiece.WHITE_PIECE)
        {
          model = JChessObject.loadFile("images/whitetower.3ds");
        }
        else
        {
          model = JChessObject.loadFile("images/blacktower.3ds");
        }
        break;

      default:
        System.out.println("Unexpected piece");
        return;
    }

    BranchGroup root = model.getSceneGroup();
    root.setCapability(BranchGroup.ALLOW_DETACH);

    // on ajoute l'objet a la scene
    objScale.addChild(root);
  }

}

Reply via email to