Interactive shell scripts (console style) in application
Aaron Roberts
Ranch Hand
Joined: Sep 10, 2002
Posts: 174
posted
0
I want to have a shell/console in an application. The idea is to make a very simple image application that just applies a few filters to an image. So I would have an image viewing area and an entry area for the shell commands.
In the shell/console area I'd enter commands which would execute methods on java classes. A psuedo syntax might be -
image = new Image("original.png"); Blur.blur(image, 10) Crop.crop(image, 50, 150) save(image)
The idea in the above is that Blur.blur is a static method on a class. Thats a bit of design ignorance, since I don't know enough about scripting with java at all.
My first thought is to simply embed some interpreter into a small java application. Something like this. I'm not sure if Groovy supports something similar or not. I've got a question into the mailing list and I'll let you know as soon as I hear something back.
I'm interested to see what others have to say about this as well.
Like Gregg I thought that this sounds like embedding a scripting engine. JavaScript has a Java-like syntax, so the Rhino engine might fit the bill, or BeanShell if you want to get even closer at Java. Both can be integrated via BSF (which has been the de-facto standard for integrating scripting languages in Java for a while), so you wouldn't even have to change the integration code if you switched script engines.
If I understood the purpose of BSF, its to provide connectivity between a language and java. This means to create a working language of my own, I'd need -
BSF Java code I wanted to interact with via my script language The Java 'glue' code that connected BSF and the above
I wasn't sure if that would actually give me the shell type console I desired.
I think I've settled on BeanShell (bsh), since it retains so much of the java syntax. Can anyone comment on how difficult it would be to make the image app I described? Using beanshell, I'd need -
beanshell My application code (this would open a JFrame with an image at the top and the text entry area at the bottom.)
Would the app code be able to use beanshell and instantiate a console?
Regards, Aaron R>
subject: Interactive shell scripts (console style) in application