Home | History | Annotate | Download | only in awt
      1 package jme3test.awt;
      2 
      3 import com.jme3.app.SimpleApplication;
      4 import com.jme3.material.Material;
      5 import com.jme3.math.Vector3f;
      6 import com.jme3.scene.Geometry;
      7 import com.jme3.scene.shape.Box;
      8 import com.jme3.system.AppSettings;
      9 import com.jme3.system.awt.AwtPanel;
     10 import com.jme3.system.awt.AwtPanelsContext;
     11 import com.jme3.system.awt.PaintMode;
     12 import java.awt.BorderLayout;
     13 import java.awt.Dimension;
     14 import java.awt.Toolkit;
     15 import java.awt.event.WindowAdapter;
     16 import java.awt.event.WindowEvent;
     17 import java.util.logging.Level;
     18 import java.util.logging.Logger;
     19 import javax.swing.JFrame;
     20 import javax.swing.SwingUtilities;
     21 
     22 public class TestAwtPanels extends SimpleApplication {
     23 
     24     private static TestAwtPanels app;
     25     private static AwtPanel panel, panel2;
     26     private static int panelsClosed = 0;
     27 
     28     private static void createWindowForPanel(AwtPanel panel, int location){
     29         JFrame frame = new JFrame("Render Display " + location);
     30         frame.getContentPane().setLayout(new BorderLayout());
     31         frame.getContentPane().add(panel, BorderLayout.CENTER);
     32         frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
     33         frame.addWindowListener(new WindowAdapter() {
     34             @Override
     35             public void windowClosed(WindowEvent e) {
     36                 if (++panelsClosed == 2){
     37                     app.stop();
     38                 }
     39             }
     40         });
     41         frame.pack();
     42         frame.setLocation(location, Toolkit.getDefaultToolkit().getScreenSize().height - 400);
     43         frame.setVisible(true);
     44     }
     45 
     46     public static void main(String[] args){
     47         Logger.getLogger("com.jme3").setLevel(Level.WARNING);
     48 
     49         app = new TestAwtPanels();
     50         app.setShowSettings(false);
     51         AppSettings settings = new AppSettings(true);
     52         settings.setCustomRenderer(AwtPanelsContext.class);
     53         settings.setFrameRate(60);
     54         app.setSettings(settings);
     55         app.start();
     56 
     57         SwingUtilities.invokeLater(new Runnable(){
     58             public void run(){
     59                 final AwtPanelsContext ctx = (AwtPanelsContext) app.getContext();
     60                 panel = ctx.createPanel(PaintMode.Accelerated);
     61                 panel.setPreferredSize(new Dimension(400, 300));
     62                 ctx.setInputSource(panel);
     63 
     64                 panel2 = ctx.createPanel(PaintMode.Accelerated);
     65                 panel2.setPreferredSize(new Dimension(400, 300));
     66 
     67                 createWindowForPanel(panel, 300);
     68                 createWindowForPanel(panel2, 700);
     69             }
     70         });
     71     }
     72 
     73     @Override
     74     public void simpleInitApp() {
     75         flyCam.setDragToRotate(true);
     76 
     77         Box b = new Box(Vector3f.ZERO, 1, 1, 1);
     78         Geometry geom = new Geometry("Box", b);
     79         Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
     80         mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
     81         geom.setMaterial(mat);
     82         rootNode.attachChild(geom);
     83 
     84         panel.attachTo(true, viewPort);
     85         guiViewPort.setClearFlags(true, true, true);
     86         panel2.attachTo(false, guiViewPort);
     87     }
     88 }
     89