A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.
I need to provide ability to dynamically change the behaviour of charts using Beanshell. I have been looking at Beanshell site but couldn't get any examples.
Here is what I am trying to achieve.
In my dashboard application, I set the basic properities of the chart but need to do the following
BarRenderer3D r = (BarRenderer3D) plot.getRenderer();
GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.BLUE,
0.0f, 300.0f, new Color(0,0,100,100));
GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, new Color(0,0,230,200),
0.0f, 300.0f, new Color(204,204,255,200));
I don't want to compile the above code in the application but leave it outside as a customizable source by the end-user. The only thing the application should pass is the "plot" variable and then rest of the renderer modifications should be done inside the Beanshell script.
I just started looking into Beanshell and got excited about the extensibility but don't know how to do it.
Sunday, June 10, 2007
Take a look at the Interpreter class and examples.
Here's a basic kind of example:
- create an Interpreter
- set variables in the context the could be accessed by the script.
- evaluate the script text
- get results back out and dereference them.
Interpreter interpreter = new Interpreter();
// Beanshell script references for context, session
// Evaluate the script
// Could also set common imports before eval'ing script
interpreter.eval("import mypackage.*; javax.sql.*;");
// If the script is expected to create certain types
// of result objects, retrieve them and cast.
XXXType resultX = (XXXType)interpreter.get("someVar");
YYYType resultY = (YYYType)interpreter.get("otherVar");
This topic is archived. No further replies will be accepted.Other recent topics
Powered by FogBugz