Advertisement
Guest User

NewJXAClass (commented) LWJGL test splitpane AWTGLCanvas

a guest
Feb 5th, 2013
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package jxa;
  6.  
  7. import java.awt.datatransfer.DataFlavor;
  8. import java.awt.datatransfer.UnsupportedFlavorException;
  9. import java.io.IOException;
  10. import net.sf.jiga.xtended.ui.AntFrame;
  11. import java.awt.BorderLayout;
  12. import java.awt.Dimension;
  13. import java.awt.FlowLayout;
  14. import java.lang.reflect.InvocationTargetException;
  15. import java.util.Timer;
  16. import java.util.TimerTask;
  17. import java.util.Vector;
  18.  
  19. import javax.swing.*;
  20. import net.sf.jiga.xtended.ui.DisplayInterface;
  21.  
  22. import org.lwjgl.LWJGLException;
  23. import org.lwjgl.opengl.AWTGLCanvas;
  24. import org.lwjgl.opengl.PixelFormat;
  25.  
  26. import static org.lwjgl.opengl.GL11.*;
  27.  
  28. /**
  29.  *
  30.  * @author www.b23prodtm.info
  31.  */
  32. public class NewClass implements AntFrame {
  33.  
  34.     /**
  35.      * @param args args from java command-line
  36.      */
  37.     public NewClass(String[] args) {
  38.     }
  39.  
  40.     public boolean open(Object o) {
  41.         /**
  42.          * ! implement with your code !
  43.          */
  44.         return false;
  45.     }
  46.  
  47.     public boolean save(String string) {
  48.         /**
  49.          * ! implement with your code !
  50.          */
  51.         return false;
  52.     }
  53.  
  54.     /**
  55.      * ### APPLET SUPPORT ###
  56.      */
  57.     public void start() {
  58.         /**
  59.          * ! implement with your code !
  60.          */
  61.         TimerTask tt = new TimerTask() {
  62.  
  63.             public void run() {
  64.                 try {
  65.                     // this invokes update(g) on the EDT
  66.                     SwingUtilities.invokeAndWait(new Runnable() { // Wait for the task to complete, since we don't want to use this Timer for any other tasks
  67. // AWT/Swing will render Canvas on our Thread.
  68.                         public void run() {
  69.                             canvas.update(canvas.getGraphics());
  70.                         }
  71.                     });
  72.                 } catch (InterruptedException ex) {
  73.                 } catch (InvocationTargetException ex) {
  74.                     ex.printStackTrace();
  75.                 }
  76.             }
  77.         };
  78. // by using the Timer for our canvas OpenGL rendering, it ensures that AWT/Swing is able to handle all AWTEvent requests (Mouse, Components validation, Layout repaint, etc.) ASAP, seemlessly.
  79.         Timer t = new Timer();
  80.         t.scheduleAtFixedRate(tt, 0, 30);
  81.  
  82.     }
  83.  
  84.     /**
  85.      * ### APPLET SUPPORT ###
  86.      */
  87.     public void stop() {
  88.         /**
  89.          * ! implement with your code !
  90.          */
  91.     }
  92.     boolean initialized = false;
  93.  
  94.     public boolean isInitialized() {
  95.         return initialized;
  96.     }
  97.  
  98.     public Runnable shutdownHook() {
  99.         /**
  100.          * ! implement with your code !
  101.          */
  102.         return new Runnable() {
  103.  
  104.             public void run() {
  105.             }
  106.         };
  107.     }
  108.  
  109.     public DataFlavor[] getTransferDataFlavors() {
  110.         /**
  111.          * ! implement with your code !
  112.          */
  113.         return new DataFlavor[]{};
  114.     }
  115.  
  116.     public boolean isDataFlavorSupported(DataFlavor flavor) {
  117.         /**
  118.          * ! implement with your code !
  119.          */
  120.         return false;
  121.     }
  122.  
  123.     public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
  124.         /**
  125.          * ! implement with your code !
  126.          */
  127.         return null;
  128.     }
  129.     JApplet applet = null;
  130.  
  131.     /**
  132.      * ### APPLET SUPPORT ###
  133.      */
  134.     public void setApplet(JApplet ja) {
  135.         applet = ja;
  136.     }
  137.  
  138.     /**
  139.      * ### APPLET SUPPORT ###
  140.      */
  141.     public JApplet getApplet() {
  142.         return applet;
  143.     }
  144.  
  145.     /**
  146.      * ### APPLET SUPPORT ###
  147.      */
  148.     public void destroy() {
  149.         /**
  150.          * ! implement with your code !
  151.          */
  152.         /**
  153.          *
  154.          */
  155.         initialized = false;
  156.     }
  157.  
  158.     /**
  159.      * ### APPLET SUPPORT ###
  160.      */
  161.     public void init() {
  162.         /**
  163.          * ! implement with your code !
  164.          */
  165.         /**
  166.          *
  167.          */
  168.         initialized = true;
  169.     }
  170.     JFrame frame = null;
  171.  
  172.     /**
  173.      * ### JFRAME APP SUPPORT ###
  174.      */
  175.     public void setFrame(JFrame jframe) {
  176.         frame = jframe;
  177.     }
  178.  
  179.     /**
  180.      * ### JFRAME APP SUPPORT ###
  181.      */
  182.     public JFrame getFrame() {
  183.         return frame;
  184.     }
  185.  
  186.     /**
  187.      * ### JFRAME APP SUPPORT ###
  188.      */
  189.     public void destroyComponents() {
  190.         /**
  191.          * ! implement with your code !
  192.          */
  193.         /**
  194.          *
  195.          */
  196.         initialized = false;
  197.     }
  198.     AWTGLCanvas canvas;
  199.  
  200.     /**
  201.      * ### JFRAME APP SUPPORT ###
  202.      */
  203.     public void initComponents() {
  204.         /**
  205.          * ! implement with your code !
  206.          */
  207.         /**
  208.          *
  209.          */
  210.         final JPanel panel_canvas = new JPanel();
  211.  
  212.         try {
  213.             panel_canvas.add(canvas = new AWTGLCanvas(new PixelFormat(8, 8, 0, 4)) {
  214.  
  215.                 final Dimension size = new Dimension(100, 100);
  216.  
  217.                 @Override
  218.                 public void initGL() {
  219.  
  220.                     setPreferredSize(size);
  221.                     setSize(size);
  222.  
  223.                     glDisable(GL_DEPTH_TEST);
  224.                     glDisable(GL_CULL_FACE);
  225.                 }
  226.  
  227.                 @Override
  228.                 public void paintGL() {
  229.  
  230.                     try {
  231.  
  232.                         glViewport(0, 0, getWidth(), getHeight());
  233.  
  234.                         glColor3f(1, 0, 0);
  235.  
  236.                         glBegin(GL_QUADS);
  237.                         glVertex2f(-1, -1);
  238.                         glVertex2f(1, -1);
  239.                         glVertex2f(1, 1);
  240.                         glVertex2f(-1, 1);
  241.                         glEnd();
  242.  
  243.                         glFinish();
  244.  
  245.                         swapBuffers();
  246.  
  247.                     } catch (LWJGLException ex) {
  248.                     }
  249.                 }
  250.             }, BorderLayout.CENTER);
  251.  
  252.         } catch (Exception e) {
  253.         };
  254.  
  255.         JPanel panel_top = new JPanel(new FlowLayout());
  256.         JPanel panel_bottom = new JPanel(new BorderLayout());/*
  257.          * {
  258.          *
  259.          * @Override public void paint(Graphics g) {
  260.          *
  261.          * canvas.update(g); }
  262.         };
  263.          */
  264.  
  265.         panel_top.setPreferredSize(new Dimension(200, 300));
  266.         panel_bottom.setPreferredSize(new Dimension(200, 300));
  267.  
  268.         panel_bottom.add(panel_canvas);
  269.  
  270.         JScrollPane scrollpane_top = new JScrollPane(panel_top);
  271.         JScrollPane scrollpane_bottom = new JScrollPane(panel_bottom);
  272.  
  273.         JSplitPane splitpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
  274.  
  275.         splitpane.setPreferredSize(new Dimension(200, 300));
  276.  
  277.         splitpane.setTopComponent(scrollpane_top);
  278.         splitpane.setBottomComponent(scrollpane_bottom);
  279.  
  280.         splitpane.setContinuousLayout(true);
  281.         splitpane.setResizeWeight(0.5f);
  282.         frame.add(splitpane);
  283.         frame.pack();
  284.  
  285.         frame.setVisible(true);
  286.         initialized = true;
  287.     }
  288.  
  289.     public DisplayInterface getSplash() {
  290.         return null;
  291.     }
  292.  
  293.     public Vector<Action> getLoadLayers() {
  294.         return new Vector();
  295.     }
  296. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement