aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2001-12-12 07:19:25 +0000
committerKenneth Russel <[email protected]>2001-12-12 07:19:25 +0000
commit48c2a0f69ee4f85e2abc0044dca76516fbf834bd (patch)
tree15bed40d59850abd5753e0adcce9fb75e8eb18d7
parent10f15a12d51ef116c46140a45875c011d9c1dbd8 (diff)
Fixed gearsFullScreen demo
-rw-r--r--demos/MiscDemos/ScreenResSelector.java201
-rw-r--r--demos/MiscDemos/gearRenderer.java2
-rw-r--r--demos/MiscDemos/gearsFullScreen.java424
-rw-r--r--demos/MiscDemos/makefile5
-rw-r--r--gl4java/applet/SimpleGLAnimApplet1.java734
5 files changed, 785 insertions, 581 deletions
diff --git a/demos/MiscDemos/ScreenResSelector.java b/demos/MiscDemos/ScreenResSelector.java
new file mode 100644
index 0000000..508fa53
--- /dev/null
+++ b/demos/MiscDemos/ScreenResSelector.java
@@ -0,0 +1,201 @@
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import javax.swing.*;
+
+/** Simple class for selecting a display mode for the purpose of
+ switching to full-screen mode.
+
+ @author Kenneth Russell ([email protected])
+*/
+
+public class ScreenResSelector {
+ static interface DisplayModeFilter {
+ public boolean filter(DisplayMode mode);
+ }
+
+ public static java.util.List getAvailableDisplayModes() {
+ java.util.List modes = getDisplayModes();
+ final DisplayMode curMode = getCurrentDisplayMode();
+ // Filter everything which is higher frequency than the current
+ // display mode
+ modes = filterDisplayModes(modes, new DisplayModeFilter() {
+ public boolean filter(DisplayMode mode) {
+ return (mode.getRefreshRate() <= curMode.getRefreshRate());
+ }
+ });
+ // Filter everything that is not at least 24-bit
+ modes = filterDisplayModes(modes, new DisplayModeFilter() {
+ public boolean filter(DisplayMode mode) {
+ return (mode.getBitDepth() >= 24);
+ }
+ });
+ // Filter everything less than 640x480
+ modes = filterDisplayModes(modes, new DisplayModeFilter() {
+ public boolean filter(DisplayMode mode) {
+ return (mode.getWidth() >= 640 && mode.getHeight() >= 480);
+ }
+ });
+ if (modes.size() == 0) {
+ throw new RuntimeException("Couldn't find any valid display modes");
+ }
+ return modes;
+ }
+
+ /** Shows a modal dialog containing the available screen resolutions
+ and requests selection of one of them. Returns the selected one. */
+ public static DisplayMode showSelectionDialog() {
+ SelectionDialog dialog = new SelectionDialog();
+ dialog.show();
+ dialog.waitFor();
+ return dialog.selected();
+ }
+
+ public static void main(String[] args) {
+ DisplayMode mode = showSelectionDialog();
+ if (mode != null) {
+ System.err.println("Selected display mode:");
+ System.err.println(modeToString(mode));
+ } else {
+ System.err.println("No display mode selected.");
+ }
+ System.exit(0);
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only below this point
+ //
+
+ private static DisplayMode getCurrentDisplayMode() {
+ GraphicsDevice dev = getDefaultScreenDevice();
+ return dev.getDisplayMode();
+ }
+
+ private static java.util.List/*<DisplayMode>*/ getDisplayModes() {
+ GraphicsDevice dev = getDefaultScreenDevice();
+ DisplayMode[] modes = dev.getDisplayModes();
+ return toList(modes);
+ }
+
+ private static GraphicsDevice getDefaultScreenDevice() {
+ return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ }
+
+ private static java.util.List/*<DisplayMode>*/ toList(DisplayMode[] modes) {
+ java.util.List res = new ArrayList();
+ for (int i = 0; i < modes.length; i++) {
+ res.add(modes[i]);
+ }
+ return res;
+ }
+
+ private static String modeToString(DisplayMode mode) {
+ return (mode.getBitDepth() + " bits, " +
+ mode.getWidth() + "x" + mode.getHeight() + ", " +
+ mode.getRefreshRate() + " Hz");
+ }
+
+ private static String[] modesToString(java.util.List/*<DisplayMode>*/ modes) {
+ String[] res = new String[modes.size()];
+ int i = 0;
+ for (Iterator iter = modes.iterator(); iter.hasNext(); ) {
+ res[i++] = modeToString((DisplayMode) iter.next());
+ }
+ return res;
+ }
+
+ private static java.util.List/*<DisplayMode>*/ filterDisplayModes(java.util.List/*<DisplayMode>*/ modes,
+ DisplayModeFilter filter) {
+ java.util.List res = new ArrayList();
+ for (Iterator iter = modes.iterator(); iter.hasNext(); ) {
+ DisplayMode mode = (DisplayMode) iter.next();
+ if (filter.filter(mode)) {
+ res.add(mode);
+ }
+ }
+ return res;
+ }
+
+ static class SelectionDialog extends JFrame {
+ private Object monitor = new Object();
+ private java.util.List modes;
+ private volatile boolean done = false;
+ private volatile int selectedIndex;
+
+ public SelectionDialog() {
+ super();
+
+ setTitle("Display Modes");
+ modes = getAvailableDisplayModes();
+ String[] strings = modesToString(modes);
+ final JList modeList = new JList(strings);
+ modeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ modeList.setSelectedIndex(0);
+ JScrollPane scroller = new JScrollPane(modeList);
+ getContentPane().setLayout(new BorderLayout());
+ getContentPane().add(BorderLayout.NORTH, new JLabel("Select display mode:"));
+ getContentPane().add(BorderLayout.CENTER, scroller);
+ JPanel buttonPanel = new JPanel();
+ buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
+ buttonPanel.add(Box.createGlue());
+ JButton button = new JButton("OK");
+ button.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ selectedIndex = modeList.getSelectedIndex();
+ done = true;
+ synchronized(monitor) {
+ monitor.notify();
+ }
+ hide();
+ dispose();
+ }
+ });
+ buttonPanel.add(button);
+ buttonPanel.add(Box.createHorizontalStrut(10));
+ button = new JButton("Cancel");
+ button.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ selectedIndex = -1;
+ done = true;
+ synchronized(monitor) {
+ monitor.notify();
+ }
+ hide();
+ dispose();
+ }
+ });
+ buttonPanel.add(button);
+ buttonPanel.add(Box.createGlue());
+ getContentPane().add(BorderLayout.SOUTH, buttonPanel);
+ pack();
+ center(this, Toolkit.getDefaultToolkit().getScreenSize());
+ }
+
+ public void waitFor() {
+ synchronized(monitor) {
+ while (!done) {
+ try {
+ monitor.wait();
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ }
+
+ public DisplayMode selected() {
+ if (selectedIndex < 0) {
+ return null;
+ } else {
+ return (DisplayMode) modes.get(selectedIndex);
+ }
+ }
+ }
+
+ private static void center(Component component,
+ Dimension containerDimension) {
+ Dimension sz = component.getSize();
+ int x = ((containerDimension.width - sz.width) / 2);
+ int y = ((containerDimension.height - sz.height) / 2);
+ component.setLocation(x, y);
+ }
+}
diff --git a/demos/MiscDemos/gearRenderer.java b/demos/MiscDemos/gearRenderer.java
index 345790a..aa5a803 100644
--- a/demos/MiscDemos/gearRenderer.java
+++ b/demos/MiscDemos/gearRenderer.java
@@ -328,7 +328,7 @@ public class gearRenderer
//System.out.println("mouse dragged: ");
int x = evt.getX();
int y = evt.getY();
- Dimension size = gldrawable.getSize();
+ Dimension size = evt.getComponent().getSize();
float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)size.width);
float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)size.height);
diff --git a/demos/MiscDemos/gearsFullScreen.java b/demos/MiscDemos/gearsFullScreen.java
index 8cabd83..e51ba84 100644
--- a/demos/MiscDemos/gearsFullScreen.java
+++ b/demos/MiscDemos/gearsFullScreen.java
@@ -1,215 +1,209 @@
-/**
- * @(#) gearsFullScreen.java
- * @(#) author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel)
- *
- * This version is equal to Brian Paul's version 1.2 1999/10/21
- */
-
-import java.applet.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.lang.*;
-import java.util.*;
-import java.io.*;
-import gl4java.*;
-import gl4java.drawable.*;
-import gl4java.awt.GLAnimCanvas;
-import gl4java.applet.SimpleGLAnimApplet1;
-
-public class gearsFullScreen extends SimpleGLAnimApplet1
- implements MouseListener
-{
-
- /* Initialize the applet */
- public void init()
- {
- init(false);
- }
-
- public void init(boolean showGL)
- {
- super.init();
-
- Dimension d = getSize();
-
- GLCapabilities caps = new GLCapabilities();
-
- canvas =
- GLDrawableFactory.getFactory().createGLAnimCanvas(caps, d.width, d.height);
-
- gearRenderer gear = new gearRenderer(showGL);
- canvas.addGLEventListener(gear);
-
- add("Center", canvas);
- addMouseListener(this);
- }
-
- public void destroy()
- {
- removeMouseListener(this);
- super.destroy();
- }
-
-
- public static void main( String args[] )
- {
- int i = 0;
- String gljLib = null;
- String glLib = null;
- String gluLib = null;
- boolean perftest=false;
-
- GLContext.gljNativeDebug = false;
- GLContext.gljClassDebug = false;
- GLContext.gljThreadDebug = false;
-
- while(args.length>i)
- {
- if(args[i].equals("-perftest"))
- {
- perftest=true;
- } else if(args[i].equals("-gljLib"))
- {
- i++;
- if(args.length>i)
- gljLib=args[i];
- } else if(args[i].equals("-glLib"))
- {
- i++;
- if(args.length>i)
- glLib=args[i];
- } else if(args[i].equals("-gluLib"))
- {
- i++;
- if(args.length>i)
- gluLib=args[i];
- } else {
- System.out.println("illegal arg "+i+": "+args[i]);
- }
- i++;
- }
-
- if(perftest)
- {
- GLContext.gljNativeDebug = false;
- GLContext.gljThreadDebug = false;
- GLContext.gljClassDebug = false;
- }
-
- if(perftest)
- GLContext.gljClassDebug=true;
- GLContext.doLoadNativeLibraries(gljLib, glLib, gluLib);
- if(perftest)
- GLContext.gljClassDebug=false;
-
- GraphicsEnvironment env =
- GraphicsEnvironment.getLocalGraphicsEnvironment();
- GraphicsDevice device = env.getDefaultScreenDevice();
- Frame mainFrame = null;
-
- System.out.println("isFullScreenSupported: "+
- device.isFullScreenSupported() );
-
- try {
- GraphicsConfiguration gc ;
- gl4java.drawable.GLDrawableFactory df =
- gl4java.drawable.GLDrawableFactory.getFactory();
-
- if(df instanceof gl4java.drawable.SunJDK13GLDrawableFactory)
- {
- GLCapabilities glCaps = new GLCapabilities();
- gl4java.drawable.SunJDK13GLDrawableFactory sdf =
- (gl4java.drawable.SunJDK13GLDrawableFactory)df;
-
- gc = sdf.getGraphicsConfiguration(glCaps, device);
- } else {
- gc = device.getDefaultConfiguration();
- }
-
- mainFrame = new Frame(gc);
-
- gearsFullScreen applet = new gearsFullScreen();
- mainFrame.add(applet);
- applet.setSize(400,500);
- applet.init();
-
- if(perftest)
- {
- applet.canvas.setUseFpsSleep(false);
- applet.canvas.setUseRepaint(false);
- applet.canvas.setUseYield(false);
-
- System.out.println("useFpsSleep: "+
- applet.canvas.getUseFpsSleep());
- System.out.println("useRepaint: "+
- applet.canvas.getUseRepaint());
-
- System.out.println("useFpsSleep: "+
- applet.canvas.getUseFpsSleep());
- }
-
- applet.start();
-
- Dimension ps = applet.getPreferredSize();
- mainFrame.setBounds(-100,-100,99,99);
- mainFrame.setVisible(true);
- mainFrame.setVisible(false);
- mainFrame.setVisible(true);
- Insets is = mainFrame.getInsets();
- mainFrame.setBounds(0,0,
- ps.width+is.left+is.right,
- ps.height+is.top+is.bottom);
- mainFrame.setVisible(true);
- Thread.currentThread().sleep(10000, 0 );
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- device.setFullScreenWindow(null);
- }
-
- }
-
- // Methods required for the implementation of MouseListener
- public void mouseEntered( MouseEvent evt )
- {
- //System.out.println("mouse entered: ");
- super.mouseEntered(evt);
- }
-
- public void mouseExited( MouseEvent evt )
- {
- //System.out.println("mouse exit: ");
- super.mouseExited(evt);
- }
-
- public void mousePressed( MouseEvent evt )
- {
- //System.out.println("mouse pressed: ");
- super.mousePressed(evt);
- }
-
- public void mouseReleased( MouseEvent evt )
- {
- //System.out.println("mouse released: ");
- super.mouseReleased(evt);
- }
-
- public void mouseClicked( MouseEvent evt )
- {
- //System.out.println("mouse clicked: ");
- super.mouseClicked(evt);
-
- if ((evt.getModifiers() & evt.BUTTON2_MASK) != 0)
- {
- System.out.println("stopping applet now .. (after 1s, restart)");
- stop();
- try {
- Thread.sleep(1000);
- } catch (Exception e)
- { System.out.println("oops, somebody woke us up .."); }
- System.out.println("restarting applet now .. ");
- canvas.setVisible(true);
- start();
- }
- }
-}
+/**
+ * @(#) gearsFullScreen.java
+ * @(#) author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel)
+ *
+ * This version is equal to Brian Paul's version 1.2 1999/10/21
+ */
+
+import java.applet.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.lang.*;
+import java.util.*;
+import java.io.*;
+import gl4java.*;
+import gl4java.drawable.*;
+import gl4java.awt.GLAnimCanvas;
+import gl4java.applet.SimpleGLAnimApplet1;
+
+public class gearsFullScreen extends SimpleGLAnimApplet1
+ implements MouseListener
+{
+
+ /* Initialize the applet */
+ public void init() {
+ init(false);
+ }
+
+ public void init(boolean showGL) {
+ super.init();
+
+ Dimension d = getSize();
+
+ GLCapabilities caps = new GLCapabilities();
+
+ canvas =
+ GLDrawableFactory.getFactory().createGLAnimCanvas(caps, d.width, d.height);
+
+ gearRenderer gear = new gearRenderer(showGL);
+ canvas.addGLEventListener(gear);
+
+ add("Center", canvas);
+ addMouseListener(this);
+ }
+
+ public void destroy() {
+ removeMouseListener(this);
+ super.destroy();
+ }
+
+
+ public static void main(String args[]) {
+ int i = 0;
+ String gljLib = null;
+ String glLib = null;
+ String gluLib = null;
+ boolean perftest=false;
+
+ GLContext.gljNativeDebug = false;
+ GLContext.gljClassDebug = false;
+ GLContext.gljThreadDebug = false;
+
+ while(args.length > i) {
+ if(args[i].equals("-perftest")) {
+ perftest=true;
+ } else if(args[i].equals("-gljLib")) {
+ i++;
+ if(args.length>i)
+ gljLib=args[i];
+ } else if(args[i].equals("-glLib")) {
+ i++;
+ if(args.length>i)
+ glLib=args[i];
+ } else if(args[i].equals("-gluLib")) {
+ i++;
+ if(args.length>i)
+ gluLib=args[i];
+ } else {
+ System.out.println("illegal arg "+i+": "+args[i]);
+ }
+ i++;
+ }
+
+ if(perftest) {
+ GLContext.gljNativeDebug = false;
+ GLContext.gljThreadDebug = false;
+ GLContext.gljClassDebug = false;
+ }
+
+ if(perftest)
+ GLContext.gljClassDebug=true;
+ GLContext.doLoadNativeLibraries(gljLib, glLib, gluLib);
+ if(perftest)
+ GLContext.gljClassDebug=false;
+
+ GraphicsEnvironment env =
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
+ final GraphicsDevice device = env.getDefaultScreenDevice();
+ Frame mainFrame = null;
+ final DisplayMode origMode = device.getDisplayMode();
+ DisplayMode newMode = null;
+ int initWidth = 400;
+ int initHeight = 300;
+
+ System.out.println("isFullScreenSupported: " +
+ device.isFullScreenSupported());
+
+ if (device.isFullScreenSupported()) {
+ newMode = ScreenResSelector.showSelectionDialog();
+ if (newMode != null) {
+ initWidth = newMode.getWidth();
+ initHeight = newMode.getHeight();
+ }
+ }
+
+ try {
+ mainFrame = new Frame();
+ gearsFullScreen applet = new gearsFullScreen();
+ mainFrame.add(applet);
+
+ if (device.isFullScreenSupported()) {
+ mainFrame.setUndecorated(true);
+ }
+
+ applet.init();
+ if(perftest) {
+ applet.canvas.setUseFpsSleep(false);
+ applet.canvas.setUseRepaint(false);
+ applet.canvas.setUseYield(false);
+
+ System.out.println("useFpsSleep: "+
+ applet.canvas.getUseFpsSleep());
+ System.out.println("useRepaint: "+
+ applet.canvas.getUseRepaint());
+
+ System.out.println("useFpsSleep: "+
+ applet.canvas.getUseFpsSleep());
+ }
+
+ mainFrame.setSize(initWidth, initHeight);
+ mainFrame.show();
+ mainFrame.setLocation(0, 0);
+
+ if (device.isFullScreenSupported()) {
+ device.setFullScreenWindow(mainFrame);
+ if (device.isDisplayChangeSupported()) {
+ device.setDisplayMode(newMode);
+ } else {
+ newMode = null;
+ }
+ final DisplayMode tmpMode = newMode;
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ if (tmpMode != null) {
+ try {
+ device.setDisplayMode(origMode);
+ } catch (Exception e) {
+ }
+ }
+ device.setFullScreenWindow(null);
+ }
+ });
+ }
+
+ applet.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ device.setFullScreenWindow(null);
+ }
+ }
+
+ // Methods required for the implementation of MouseListener
+ public void mouseEntered( MouseEvent evt ) {
+ //System.out.println("mouse entered: ");
+ super.mouseEntered(evt);
+ }
+
+ public void mouseExited( MouseEvent evt ) {
+ //System.out.println("mouse exit: ");
+ super.mouseExited(evt);
+ }
+
+ public void mousePressed( MouseEvent evt ) {
+ //System.out.println("mouse pressed: ");
+ super.mousePressed(evt);
+ }
+
+ public void mouseReleased( MouseEvent evt ) {
+ //System.out.println("mouse released: ");
+ super.mouseReleased(evt);
+ }
+
+ public void mouseClicked( MouseEvent evt ) {
+ //System.out.println("mouse clicked: ");
+ super.mouseClicked(evt);
+
+ if ((evt.getModifiers() & evt.BUTTON2_MASK) != 0) {
+ System.out.println("stopping applet now .. (after 1s, restart)");
+ stop();
+ try {
+ Thread.sleep(1000);
+ } catch (Exception e) {
+ System.out.println("oops, somebody woke us up .."); }
+ System.out.println("restarting applet now .. ");
+ canvas.setVisible(true);
+ start();
+ }
+ }
+}
diff --git a/demos/MiscDemos/makefile b/demos/MiscDemos/makefile
index e7a1ae4..89d83c3 100644
--- a/demos/MiscDemos/makefile
+++ b/demos/MiscDemos/makefile
@@ -44,7 +44,8 @@ JAVA13_CLASSES = ${JAVA13_SOURCES:.java=.class})
ifdef JAVAC_14
JAVA14_SOURCES = \
- gearsFullScreen.java
+ gearsFullScreen.java \
+ ScreenResSelector.java
JAVA14_CLASSES = ${JAVA14_SOURCES:.java=.class})
HAVE_JAVAC_14 = 1
else
@@ -53,7 +54,7 @@ else
endif
all: cleanup $(JAVA13_CLASSES) $(JAVA14_CLASSES)
-
+
$(JAVA13_CLASSES) : $(JAVA13_SOURCES)
$(JAVAC_13) -O -deprecation $^ | tee -a errors
diff --git a/gl4java/applet/SimpleGLAnimApplet1.java b/gl4java/applet/SimpleGLAnimApplet1.java
index c989834..31f96e7 100644
--- a/gl4java/applet/SimpleGLAnimApplet1.java
+++ b/gl4java/applet/SimpleGLAnimApplet1.java
@@ -1,363 +1,371 @@
-/**
- * @(#) SimpleGLAnimApplet.java
- * @(#) author: Sven Goethel
- */
-
-package gl4java.applet;
-
-/* This program is licensed under the LGPL */
-
-import java.applet.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.lang.*;
-import gl4java.GLContext;
-import gl4java.GLFunc;
-import gl4java.GLUFunc;
-import gl4java.awt.GLAnimCanvas;
-
-public class SimpleGLAnimApplet1 extends Applet
- implements MouseListener, WindowListener, ActionListener, ItemListener
-{
- public GLAnimCanvas canvas = null;
-
- public Button buttonInfo = null;
- public Button buttonFps = null;
- public TextField textFps = null;
- public Checkbox checkUseRepaint = null;
- public Checkbox checkUseFpsSleep = null;
- public Checkbox checkUseYield = null;
- public Button buttonReStart = null;
-
-
- Frame fInfo = null;
-
- /* Initialize the applet */
-
- public void init()
- {
- setLayout(new BorderLayout());
-
- Panel pan = new Panel();
- pan.setLayout(new GridLayout(2,4));
-
- buttonInfo = new Button("GL4Java");
- pan.add(buttonInfo);
-
- buttonReStart = new Button("start/stop");
- pan.add(buttonReStart);
-
- buttonFps = new Button("fps: ");
- pan.add(buttonFps);
-
- textFps=new TextField("0000000000");
- pan.add(textFps);
-
- checkUseRepaint = new Checkbox("repaint", true);
- pan.add(checkUseRepaint);
-
- checkUseFpsSleep = new Checkbox("fps-sleep", true);
- pan.add(checkUseFpsSleep);
-
- checkUseYield = new Checkbox("yield", true);
- pan.add(checkUseYield);
-
- add("South",pan);
- }
-
-
- public void setCheckButtons()
- {
- checkUseFpsSleep.setState(canvas.getUseFpsSleep());
- checkUseRepaint.setState(canvas.getUseRepaint());
- checkUseYield.setState(canvas.getUseYield());
- }
-
- public void start()
- {
- if(GLContext.gljClassDebug)
- System.out.println("SGLApplet start ..");
-
- setCheckButtons();
-
- buttonInfo.addActionListener(this);
- checkUseRepaint.addItemListener(this);
- checkUseFpsSleep.addItemListener(this);
- checkUseYield.addItemListener(this);
- buttonReStart.addActionListener(this);
- buttonFps.addActionListener(this);
- canvas.addMouseListener(this);
- textFps.addActionListener(this);
-
- canvas.setVisible(true);
- canvas.repaint();
- canvas.start();
- }
-
-
- public void stop()
- {
- if(GLContext.gljClassDebug)
- System.out.println("SGLApplet stop ..");
- buttonInfo.removeActionListener(this);
- checkUseRepaint.removeItemListener(this);
- checkUseFpsSleep.removeItemListener(this);
- checkUseYield.removeItemListener(this);
- buttonReStart.removeActionListener(this);
- buttonFps.removeActionListener(this);
- canvas.removeMouseListener(this);
-
- canvas.cvsDispose();
- }
-
-
- public void destroy()
- {
- if(GLContext.gljClassDebug)
- System.out.println("SGLApplet destroy ..");
- if(fInfo!=null)
- {
- fInfo.dispose();
- fInfo=null;
- }
- canvas.cvsDispose();
- }
-
-
- protected void finalize()
- throws Throwable
- {
- if(GLContext.gljClassDebug)
- System.out.println("SGLApplet finalize ..");
-
- super.finalize();
- }
-
- // Methods required for the implementation of MouseListener
- public void mouseEntered( MouseEvent evt )
- {
- }
-
- public void mouseExited( MouseEvent evt )
- {
- }
-
- public void mousePressed( MouseEvent evt )
- {
- }
-
- public void mouseReleased( MouseEvent evt )
- {
- }
-
- Container _origCont = null;
- Frame _saveFrame = null;
-
- public void mouseClicked( MouseEvent evt )
- {
- Component comp = evt.getComponent();
-
- if ( ( (evt.getModifiers() & evt.BUTTON1_MASK) != 0 ) &&
- evt.getClickCount()==2 )
- {
- if(comp instanceof GLAnimCanvas)
- {
- GLAnimCanvas glcvs = (GLAnimCanvas)comp;
- System.out.println("\n\nswitch requested: "+glcvs);
- glcvs.cvsDispose();
- System.out.println("\n\ndisposed: "+glcvs);
-
- Container c = glcvs.getParent();
- c.remove(glcvs);
-
- System.out.println("\n\nremoved: "+glcvs);
- System.out.println("Global GLAnimCanvas Render-Thread Number: "+ GLAnimCanvas.getGlobalThreadNumber());
- System.out.println("GLContextNumber: "+
- GLContext.getNativeGLContextNumber());
-
- if(_origCont !=null && c == _saveFrame)
- {
- _saveFrame.dispose();
- _saveFrame=null;
-
- _origCont.add(canvas);
- _origCont.doLayout();
- _origCont = null;
- } else if( _saveFrame ==null && _origCont == null )
- {
- _origCont = c;
- _saveFrame = new Frame("EXTRA");
- _saveFrame.add(glcvs);
- _saveFrame.pack();
- _saveFrame.setVisible(true);
- }
- glcvs.setVisible(true);
- glcvs.repaint();
- glcvs.start();
-
- System.out.println("\nadded+started: "+glcvs);
- System.out.println("Global GLAnimCanvas Render-Thread Number: "+ GLAnimCanvas.getGlobalThreadNumber());
- System.out.println("GLContextNumber: "+
- GLContext.getNativeGLContextNumber());
- }
- return;
- }
- }
-
- public void itemStateChanged( ItemEvent evt )
- {
- ItemSelectable comp = evt.getItemSelectable();
-
- if( comp.equals(checkUseRepaint ) )
- {
- if(canvas!=null)
- {
- canvas.setUseRepaint(checkUseRepaint.getState());
- System.out.println("canvas uses repaint: "+
- checkUseRepaint.getState());
- }
- }
- if( comp.equals(checkUseFpsSleep ) )
- {
- if(canvas!=null)
- {
- canvas.setUseFpsSleep(checkUseFpsSleep.getState());
- System.out.println("canvas uses fps-sleep: "+
- checkUseFpsSleep.getState());
- }
- }
- if( comp.equals(checkUseYield ) )
- {
- if(canvas!=null)
- {
- canvas.setUseYield(checkUseYield.getState());
- System.out.println("canvas uses Yield "+
- checkUseYield.getState());
- }
- }
- setCheckButtons();
- }
-
- public void actionPerformed(ActionEvent event)
- {
- Object source = event.getSource();
-
- if ( source == textFps)
- {
- try {
- double FramesPerSec=
- Double.valueOf(textFps.getText()).doubleValue();
- if(canvas!=null)
- {
- canvas.setAnimateFps(FramesPerSec);
- canvas.setSuspended(false, true);
- }
- } catch (NumberFormatException s) {
- System.out.println("wrong fps format, use float ..");
- }
- } else if( canvas!=null && source.equals(buttonFps) )
- {
- double fps = 0;
- int a1;
-
- canvas.stopFpsCounter();
- fps=canvas.getFps();
- a1=(int)(fps*100.0);
- fps=(double)a1/100.0;
- textFps.setText(String.valueOf(fps));
- canvas.resetFpsCounter();
- } else if( source.equals(buttonInfo) )
- {
- if(fInfo==null && canvas!=null && canvas.getGLContext()!=null)
- fInfo = showGLInfo();
- }
- else if( canvas!=null && source.equals(buttonReStart) )
- {
- canvas.setSuspended(!canvas.isSuspended(), false);
- }
- }
-
- public void windowOpened(WindowEvent e)
- {
- }
-
- public void windowClosing(WindowEvent e)
- {
- Window w = e.getWindow();
- if(w == fInfo && fInfo!=null)
- {
- fInfo.dispose();
- fInfo=null;
- }
- }
-
- public void windowClosed(WindowEvent e)
- {
- Window w = e.getWindow();
- if(w == fInfo && fInfo!=null)
- {
- fInfo.dispose();
- fInfo=null;
- }
- }
-
- public void windowIconified(WindowEvent e)
- {
- }
-
- public void windowDeiconified(WindowEvent e)
- {
- }
-
- public void windowActivated(WindowEvent e)
- {
- }
-
- public void windowDeactivated(WindowEvent e)
- {
- }
-
- public Frame showGLInfo()
- {
- if(canvas==null) return null;
-
- GLContext glc = canvas.getGLContext();
- if(glc==null) return null;
-
- GLFunc gl = glc.getGLFunc();
- if(gl==null) return null;
-
- GLUFunc glu = glc.getGLUFunc();
- if(gl==null) return null;
-
- canvas.setSuspended(true, false);
-
- Frame f = new Frame("GL4Java Version");
- TextArea info= new TextArea(25, 80);
- info.setEditable(false);
- f.add(info);
- f.setSize(600, 400);
-
- String str = "null string";
- if( glc.gljMakeCurrent() == false )
- {
- str="problem in use() method\n";
- } else {
- str=canvas.getGLContext().gljGetVersions();
- if(str==null)
- str="could not get versions";
- System.out.println(str);
- glc.gljFree();
- }
- info.append(str);
-
- f.addWindowListener(this);
-
- canvas.setSuspended(false, false);
-
- f.pack();
- f.setVisible(true);
-
- return f;
- }
-}
+/**
+ * @(#) SimpleGLAnimApplet.java
+ * @(#) author: Sven Goethel
+ */
+
+package gl4java.applet;
+
+/* This program is licensed under the LGPL */
+
+import java.applet.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.lang.*;
+import gl4java.GLContext;
+import gl4java.GLFunc;
+import gl4java.GLUFunc;
+import gl4java.awt.GLAnimCanvas;
+
+public class SimpleGLAnimApplet1 extends Applet
+ implements MouseListener, WindowListener, ActionListener, ItemListener
+{
+ public GLAnimCanvas canvas = null;
+
+ public Button buttonInfo = null;
+ public Button buttonFps = null;
+ public TextField textFps = null;
+ public Checkbox checkUseRepaint = null;
+ public Checkbox checkUseFpsSleep = null;
+ public Checkbox checkUseYield = null;
+ public Button buttonReStart = null;
+ public Button buttonQuit = null;
+
+
+ Frame fInfo = null;
+
+ /* Initialize the applet */
+
+ public void init()
+ {
+ setLayout(new BorderLayout());
+
+ Panel pan = new Panel();
+ pan.setLayout(new GridLayout(2,4));
+
+ buttonInfo = new Button("GL4Java");
+ pan.add(buttonInfo);
+
+ buttonReStart = new Button("start/stop");
+ pan.add(buttonReStart);
+
+ buttonFps = new Button("fps: ");
+ pan.add(buttonFps);
+
+ textFps=new TextField("0000000000");
+ pan.add(textFps);
+
+ checkUseRepaint = new Checkbox("repaint", true);
+ pan.add(checkUseRepaint);
+
+ checkUseFpsSleep = new Checkbox("fps-sleep", true);
+ pan.add(checkUseFpsSleep);
+
+ checkUseYield = new Checkbox("yield", true);
+ pan.add(checkUseYield);
+
+ buttonQuit = new Button("Quit");
+ pan.add(buttonQuit);
+
+ add("South",pan);
+ }
+
+
+ public void setCheckButtons()
+ {
+ checkUseFpsSleep.setState(canvas.getUseFpsSleep());
+ checkUseRepaint.setState(canvas.getUseRepaint());
+ checkUseYield.setState(canvas.getUseYield());
+ }
+
+ public void start()
+ {
+ if(GLContext.gljClassDebug)
+ System.out.println("SGLApplet start ..");
+
+ setCheckButtons();
+
+ buttonInfo.addActionListener(this);
+ checkUseRepaint.addItemListener(this);
+ checkUseFpsSleep.addItemListener(this);
+ checkUseYield.addItemListener(this);
+ buttonReStart.addActionListener(this);
+ buttonFps.addActionListener(this);
+ buttonQuit.addActionListener(this);
+ canvas.addMouseListener(this);
+ textFps.addActionListener(this);
+
+ canvas.setVisible(true);
+ canvas.repaint();
+ canvas.start();
+ }
+
+
+ public void stop()
+ {
+ if(GLContext.gljClassDebug)
+ System.out.println("SGLApplet stop ..");
+ buttonInfo.removeActionListener(this);
+ checkUseRepaint.removeItemListener(this);
+ checkUseFpsSleep.removeItemListener(this);
+ checkUseYield.removeItemListener(this);
+ buttonReStart.removeActionListener(this);
+ buttonFps.removeActionListener(this);
+ buttonQuit.removeActionListener(this);
+ canvas.removeMouseListener(this);
+
+ canvas.cvsDispose();
+ }
+
+
+ public void destroy()
+ {
+ if(GLContext.gljClassDebug)
+ System.out.println("SGLApplet destroy ..");
+ if(fInfo!=null)
+ {
+ fInfo.dispose();
+ fInfo=null;
+ }
+ canvas.cvsDispose();
+ }
+
+
+ protected void finalize()
+ throws Throwable
+ {
+ if(GLContext.gljClassDebug)
+ System.out.println("SGLApplet finalize ..");
+
+ super.finalize();
+ }
+
+ // Methods required for the implementation of MouseListener
+ public void mouseEntered( MouseEvent evt )
+ {
+ }
+
+ public void mouseExited( MouseEvent evt )
+ {
+ }
+
+ public void mousePressed( MouseEvent evt )
+ {
+ }
+
+ public void mouseReleased( MouseEvent evt )
+ {
+ }
+
+ Container _origCont = null;
+ Frame _saveFrame = null;
+
+ public void mouseClicked( MouseEvent evt )
+ {
+ Component comp = evt.getComponent();
+
+ if ( ( (evt.getModifiers() & evt.BUTTON1_MASK) != 0 ) &&
+ evt.getClickCount()==2 )
+ {
+ if(comp instanceof GLAnimCanvas)
+ {
+ GLAnimCanvas glcvs = (GLAnimCanvas)comp;
+ System.out.println("\n\nswitch requested: "+glcvs);
+ glcvs.cvsDispose();
+ System.out.println("\n\ndisposed: "+glcvs);
+
+ Container c = glcvs.getParent();
+ c.remove(glcvs);
+
+ System.out.println("\n\nremoved: "+glcvs);
+ System.out.println("Global GLAnimCanvas Render-Thread Number: "+ GLAnimCanvas.getGlobalThreadNumber());
+ System.out.println("GLContextNumber: "+
+ GLContext.getNativeGLContextNumber());
+
+ if(_origCont !=null && c == _saveFrame)
+ {
+ _saveFrame.dispose();
+ _saveFrame=null;
+
+ _origCont.add(canvas);
+ _origCont.doLayout();
+ _origCont = null;
+ } else if( _saveFrame ==null && _origCont == null )
+ {
+ _origCont = c;
+ _saveFrame = new Frame("EXTRA");
+ _saveFrame.add(glcvs);
+ _saveFrame.pack();
+ _saveFrame.setVisible(true);
+ }
+ glcvs.setVisible(true);
+ glcvs.repaint();
+ glcvs.start();
+
+ System.out.println("\nadded+started: "+glcvs);
+ System.out.println("Global GLAnimCanvas Render-Thread Number: "+ GLAnimCanvas.getGlobalThreadNumber());
+ System.out.println("GLContextNumber: "+
+ GLContext.getNativeGLContextNumber());
+ }
+ return;
+ }
+ }
+
+ public void itemStateChanged( ItemEvent evt )
+ {
+ ItemSelectable comp = evt.getItemSelectable();
+
+ if( comp.equals(checkUseRepaint ) )
+ {
+ if(canvas!=null)
+ {
+ canvas.setUseRepaint(checkUseRepaint.getState());
+ System.out.println("canvas uses repaint: "+
+ checkUseRepaint.getState());
+ }
+ }
+ if( comp.equals(checkUseFpsSleep ) )
+ {
+ if(canvas!=null)
+ {
+ canvas.setUseFpsSleep(checkUseFpsSleep.getState());
+ System.out.println("canvas uses fps-sleep: "+
+ checkUseFpsSleep.getState());
+ }
+ }
+ if( comp.equals(checkUseYield ) )
+ {
+ if(canvas!=null)
+ {
+ canvas.setUseYield(checkUseYield.getState());
+ System.out.println("canvas uses Yield "+
+ checkUseYield.getState());
+ }
+ }
+ setCheckButtons();
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ Object source = event.getSource();
+
+ if ( source == textFps)
+ {
+ try {
+ double FramesPerSec=
+ Double.valueOf(textFps.getText()).doubleValue();
+ if(canvas!=null)
+ {
+ canvas.setAnimateFps(FramesPerSec);
+ canvas.setSuspended(false, true);
+ }
+ } catch (NumberFormatException s) {
+ System.out.println("wrong fps format, use float ..");
+ }
+ } else if( canvas!=null && source.equals(buttonFps) )
+ {
+ double fps = 0;
+ int a1;
+
+ canvas.stopFpsCounter();
+ fps=canvas.getFps();
+ a1=(int)(fps*100.0);
+ fps=(double)a1/100.0;
+ textFps.setText(String.valueOf(fps));
+ canvas.resetFpsCounter();
+ } else if( source.equals(buttonInfo) )
+ {
+ if(fInfo==null && canvas!=null && canvas.getGLContext()!=null)
+ fInfo = showGLInfo();
+ }
+ else if( canvas!=null && source.equals(buttonReStart) )
+ {
+ canvas.setSuspended(!canvas.isSuspended(), false);
+ } else if (source.equals(buttonQuit)) {
+ System.exit(0);
+ }
+ }
+
+ public void windowOpened(WindowEvent e)
+ {
+ }
+
+ public void windowClosing(WindowEvent e)
+ {
+ Window w = e.getWindow();
+ if(w == fInfo && fInfo!=null)
+ {
+ fInfo.dispose();
+ fInfo=null;
+ }
+ }
+
+ public void windowClosed(WindowEvent e)
+ {
+ Window w = e.getWindow();
+ if(w == fInfo && fInfo!=null)
+ {
+ fInfo.dispose();
+ fInfo=null;
+ }
+ }
+
+ public void windowIconified(WindowEvent e)
+ {
+ }
+
+ public void windowDeiconified(WindowEvent e)
+ {
+ }
+
+ public void windowActivated(WindowEvent e)
+ {
+ }
+
+ public void windowDeactivated(WindowEvent e)
+ {
+ }
+
+ public Frame showGLInfo()
+ {
+ if(canvas==null) return null;
+
+ GLContext glc = canvas.getGLContext();
+ if(glc==null) return null;
+
+ GLFunc gl = glc.getGLFunc();
+ if(gl==null) return null;
+
+ GLUFunc glu = glc.getGLUFunc();
+ if(gl==null) return null;
+
+ canvas.setSuspended(true, false);
+
+ Frame f = new Frame("GL4Java Version");
+ TextArea info= new TextArea(25, 80);
+ info.setEditable(false);
+ f.add(info);
+ f.setSize(600, 400);
+
+ String str = "null string";
+ if( glc.gljMakeCurrent() == false )
+ {
+ str="problem in use() method\n";
+ } else {
+ str=canvas.getGLContext().gljGetVersions();
+ if(str==null)
+ str="could not get versions";
+ System.out.println(str);
+ glc.gljFree();
+ }
+ info.append(str);
+
+ f.addWindowListener(this);
+
+ canvas.setSuspended(false, false);
+
+ f.pack();
+ f.setVisible(true);
+
+ return f;
+ }
+}