package edu.mines.jtk.ogl; import java.io.*; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Makes OpenGL wrapper class Gl.java for JOGL's javax.media.opengl.GL. *GL. * To make a new Gl.java, save the javadoc file GL.html from JOGL as a * text file Gl.txt (note the change in case from GL to Gl), and run this * program. *

* This program may require modification if the format of JOGL's javadoc * files changes. Check the output file Gl.java before using. *

* An alternative to this program would be to use reflection on the JOGL * class file javax.media.opengl.GL.class, but this alternative would not * preserve the names of method parameters. A better alternative would be * for JOGL to provide these bindings. * @author Dave Hale, Colorado School of Mines * @version 2006.07.10 */ class MakeGl { public static void main(String[] args) { String inputFileName = "Gl.txt"; String outputFileName = "Gl.java"; try { BufferedReader br = null; BufferedWriter bw = null; br = new BufferedReader(new FileReader(inputFileName)); bw = new BufferedWriter(new FileWriter(outputFileName)); for (int i=0; i parList = new ArrayList(); Pattern parPattern = Pattern.compile(".*\\s(\\w*)[,\\)]"); for (; input!=null; input=br.readLine()) { if (input.startsWith("public")) { int i = input.indexOf("gl"); int j = input.indexOf("("); if (i<0 || j<=i) break; boolean isVoid = input.indexOf("void ")>=0; name = input.substring(i,j); parList.clear(); output = ""; for (boolean first=true; input!=null; input=br.readLine(),first=false) { if (first) { int k = input.indexOf(" "); output = " public static"+input.substring(k); } else { output = " "+input; } Matcher parMatcher = parPattern.matcher(input); if (parMatcher.matches()) parList.add(parMatcher.group(1)); if (input.endsWith(")")) { output = output+" {"; break; } bw.write(output+NEWLINE); } bw.write(output+NEWLINE); if (isVoid) { output = " gl()."+name+"("; } else { output = " return gl()."+name+"("; } int n = parList.size(); if (n==0) { bw.write(output+");"+NEWLINE); } else { bw.write(output+NEWLINE); for (int k=0; k