• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Interactive shell scripts (console style) in application

 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Another usage example could be -

load image1 "original.png"
img = blur(image1, 15)
img = crop(img, 50, 150)
save img "newimage.png"

So you can see from both usage examples, the ability to do dynamic inputs is the key part. The syntax isn't so important.

Can someone provide some input on how I might approach this? What might be a pro or con for one method over another?

I don't want to write my own parser for doing this. From what I understand I don't have to with some of the options out there.

I came across this great article on some scripting options out there -

Choosing A Java Scripting Language

Suggestions?

Thanks,
Aaron R>
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are spoiled for choice.

Jacl was originally created by Sun in 1994 so it's quite mature. It's also lightweight and easy to learn.


https://coderanch.com/t/280/ol/New-JACL-release
 
Aaron Roberts
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
reply
    Bookmark Topic Watch Topic
  • New Topic