From: Kyle R. B. <kyl...@gm...> - 2005-07-13 18:27:44
|
When using dclass it emits some diagnostic information using display.=20 Is there a standard method for suppressing this? I see that it uses display, but don't see a way of turning off the output. Also, does anyone know of any other library code for declaring classes in JScheme? Thanks, Kyle R. Burton --=20 ---------------------------------------------------------------------------= --- Wisdom and Compassion are inseparable. -- Christmas Humphreys kyl...@gm... =20 http://www.neverlight.com/~mortis ---------------------------------------------------------------------------= --- |
From: Timothy J H. <tjh...@br...> - 2005-07-15 18:57:42
|
Hi Kyle, On Jul 13, 2005, at 2:27 PM, Kyle R. Burton wrote: > When using dclass it emits some diagnostic information using display. > Is there a standard method for suppressing this? I see that it uses > display, but don't see a way of turning off the output. You'd have to comment out the lines in dclass.scm .... If you put in a switch for turning on/off the output we can add it to the next release... > > Also, does anyone know of any other library code for declaring classes > in JScheme? I don't know of any other automatic code, but I have developed some general approaches that work well using the jscheme.JScheme class to add a Scheme environment to a Java class. For example, this week I was working on a Java component for plotting various data coming from a Neuron simulattion program and I wanted to do the GUI layout and mouse handling (zoom/unzoom, etc.) in Java, but wrap it in Java so we could include it in other Java libraries easily. The approach I used was to add a static JScheme object (js) to the class and then load the relevant Scheme code in a static declaration. Finally, one can use js.call(....) to call JScheme code from the java methods... This executes the code in an interpreter belonging only to this class. In this particular case, the Java constructor calls a Scheme procedure that creates a GUI for the Neuron trace plotter and returns a Scheme procedure that can be used in Java to control the GUI and to access GUI field values, as well as to call any Scheme code that operates on the GUI. Here are some snippets of the Java and Scheme code for this Neuron Visualization tool > /** > PlotPanel represents a panel that provides a view of the data stored > in a Neuron object. > The GUI is created by a JScheme program plotpanelGUI.scm > > **/ > > > import javax.swing.JPanel; > import java.awt.Graphics; > import java.awt.Color; > > > public class PlotPanel { > public static jscheme.JScheme js = new jscheme.JScheme(); // here is a jscheme interpreter for interpreting Scheme code associated to this class > > public CompressedNeuron cNeuron; > public Neuron aNeuron; > > private jsint.Procedure handler; // this is a scheme procedure to > access the GUI > > > static { > js.call("load","plotpanelGUI.scm"); > } // here we load the scheme code into the interpreter (it can reside in the Jar file and will be loaded correctly) // this happens when the Java class is initially loaded > > > public void setNeuron(Neuron n) { this.aNeuron = n;} > public void setCompressedNeuron(CompressedNeuron n) {this.cNeuron=n;} > > public PlotPanel() { > handler = (jsint.Procedure) js.call("make-plot-panel", this); // here we make a scheme call in the Java constructor to create a GUI component for plotting // and we get back a procedure (handler) that can be called to control the GUI // and to read/write GUI component values > } > > private Object guiLookup(String s) { return js.call(handler,s); } > private double doubleLookup(String s){ return ((Number) > js.call(handler,s)).doubleValue(); } > private int intLookup(String s){ return ((Number) > js.call(handler,s)).intValue(); } // here are some help procedures for returning doubles, integers, or general objects from Scheme into Java // next is an example of getting the graphics component from Scheme, doing some painting, and the repainting the GUI // the guiLookup calls are calls to Scheme > public void clearScreen() { > Graphics g = (Graphics) guiLookup("g"); > g.setColor(Color.BLUE); > g.fillRect(0,0,10000,10000); > guiLookup("repaint"); > } The Scheme code looks like this ... > > ;; plotpanelGUI.scm > ;; This code creates a GUI for a PlotPanel > ;; It is meant to be called from PlotPanel.java > ;; all of the state variables and actions are stored in the java object > ;; This class just sets up the GUI > > (use-module "jlib/Swing.scm") // load the jlib library > > ;; return a plot panel for putting into the table ... this is the Java > object that creates this GUI > (define (make-plot-panel this) > > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > ;; Create the GUI > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > (define plots > (choice "MembranePotential" "intracellularCa" "NaActivation" > "NaInactivation" > "CaTActivation" "CaTInactivation" "CaSActivation" > "CaSInactivation" > "AActivation" "AInactivation" "KCaActivation" > "KdActivation" "HActivation")) > > (define c (canvas 400 600)) ----snip--- .... we continue creating the GUI > > (define the-panel (border (center c) (south (col 'none 'north > preference_selector)))) > ;; finally we end with a Scheme procedure that is passed back to Java that lets us control ;; the Scheme-built GUI from Java > (define (H msg) > (case msg > (("panel") the-panel) > (("canvas") the-canvas) > (("plotChoice") plots) > (("xmin") (readexpr xminTF)) > (("xmax") (readexpr xmaxTF)) > (("ymin") (readexpr yminTF)) > (("ymax") (readexpr ymaxTF)) > (("xminTF") xminTF) > (("xmaxTF") xmaxTF) > (("yminTF") yminTF) > (("ymaxTF") ymaxTF) > (("width") (.getWidth c)) > (("height") (.getHeight c)) > (("colorTF") (list->array int.class (readexpr colorTF))) > (("g") (.bufferg$ c)) > (("c") c) > (("repaint") (.repaint c)) > (("cNeuron") cNeuron) > (("aNeuron") aNeuron) > (("plotMethod") (readstring plotMethodChoice)) > (else "error?"))) > > > H > > > ) ; end of make-plot-panel > > This is not an automatic generation approach like the dclass method, but it does provide a nice pattern for writing programs that mix Java and Scheme. I often like to use Scheme to do the GUI (including adding mouse listeners, layout managers, etc.) and then use Java to do some of the tight numeric loops (analyzing plots, etc.) I hope this is helpful Best, ---Tim--- > > > Thanks, > > Kyle R. Burton > > -- > ----------------------------------------------------------------------- > ------- > Wisdom and Compassion are inseparable. > -- Christmas Humphreys > kyl...@gm... > http://www.neverlight.com/~mortis > ----------------------------------------------------------------------- > ------- > > > ------------------------------------------------------- > This SF.Net email is sponsored by the 'Do More With Dual!' webinar > happening > July 14 at 8am PDT/11am EDT. We invite you to explore the latest in > dual > core and dual graphics technology at this free one hour event hosted > by HP, > AMD, and NVIDIA. To register visit http://www.hp.com/go/dualwebinar > _______________________________________________ > Jscheme-user mailing list > Jsc...@li... > https://lists.sourceforge.net/lists/listinfo/jscheme-user |