Hi Sandro,
Thank you for the warm welcome to Pivot. I've ran through the examples
you mentioned, and have been able to create a Hello World example in
Groovy with Pivot. I am confused about some things however:
First, I don't like the fact that it seems to be necessary to write your
logic in a class that extends/implements Application. My programs are
more than just a GUI and using this kind of naming/method suggest that
everything is centered around the application. I suspect that this is
partly because you're trying to hide the logic of initializing the
graphics subsystem/awt as well as trying to hide the event loop. There's
other ways that that could be done however.
I'm also still confused about pivot Windows. These seem to be a strange
mix between a 'virtual desktop' and an actual window, eg if I extend a
Hello World example with "window.setPreferredSize(200,500)" I'm getting
strange results. The *window* isn't resized, but the way the Label is
displayed inside the window is affected by this. Manually resizing the
window by dragging the bottom right corner on the other hand seems to be
have just as you would expect.
Finally, and I don't know if this is a bug or not, but if I create 2
windows and call window.close() on one of them, pivot closes both
windows instead and my application exits.
Let me give you an example of what I'd ideally would expect from using a
windowing toolkit from Groovy. First of all, it wouldn't use XML to
define the GUI layout. I know that in the Java world such an approach
makes sense because Java code would get very verbose and it's not very
good in showing the hierarchical relationships of the various GUI
components. However in Groovy there's another way of addressing that,
and that's by creating a Domain Specific Language by writing a so-called
"Builder". Assuming we'd have a "PivotBuilder" in groovy, the equivalent
of
http://svn.apache.org/repos/asf/pivot/trunk/examples/src/org/apache/pivot/examples/scripting/
for the java_window.bxml/JavaWindow.java example could look like:
import groovy.pivot.PivotBuilder
def pivot = new PivotBuilder()
def prompt = pivot.prompt(text: 'Hello from Java')
def window = pivot.window(size: [200,500], maximized: true, title: 'Java
Window') {
boxPane(orientation: 'vertical', styles: [horizontalAlignment:
'center', verticalAlignment: 'center']) {
label(text: 'This is a Java Window')
button(text: 'Say Hello') {
buttonPressListener << { button ->
prompt.open(window)
// this is actually invalid code because 'window' is not
// defined here yet, (we're still working on it) but this
// is good enough to give an idea of how this would work
}
}
}
}
window.open()/show()/whatever()
That's a first approximation of what a PivotBuilder in groovy could look
like, heavily inspired by how the exist SwingBuilder (and to a lesser
extend the SwtBuilder) work.
On the implementation side of such a PivotBuilder, I don't have any
specific ideas yet. I know I don't particularly like using
DesktopApplicationContext, it doesn't seem to fit the model very well to
me (but again I need to look deeper into this). So any suggestions would
be appreciated.
Just to let you know upfront as well, I'm interested in this (provided I
can get over the first technical hurdle of how to just simply open a
darn window), but I can't spend much time on this. Work doesn't allow
it, and at home I can probably only get a few hours per weekend on this,
maybe an hour here or there during the week.
Maarten
On 01/03/2013 08:52 PM, Sandro Martini wrote:
Hi Maarten, welcome to Pivot,
under our example subproject (for example here:
http://svn.apache.org/repos/asf/pivot/trunk/examples/src/org/apache/pivot/examples/scripting/
), there is a package org.apache.pivot.examples.scripting where we
have some minimal scripting samples from Javascript (that embedded in
the JVM, Groovy, and Scala).
Note that it's an eclipse project with Scala support but not Groovy
(don't remember why, I have to look ...), so to make it work you have
to add the Groovy nature to it, then run the groovy_window.bxml for
example with our Pivot eclipse plugin.
In the meantime, you can do the same with javascript_window.bxml,
java_window.bxml, and scala_window.bxml . Note that the Java and Scala
version have a related class to simplify things. Probably a Groovy
class could be done in the same way, really don't remember why it's
missing here ...
In this case, scripting was focused on using scripting languages
inside Pivot bxml files.
As you know, in Pivot the preferred way to build user interfaces is
with bxml files, but of course all could be done even with code
(scripting code or normal). And probably this could be a good way even
in your case, to decouple the UI from the code.
But I have never tried to make it work from a Groovy script, could be
interesting.
To further improve our interoperability with other JVM languages, we
have some secondary projects at Apache-Extras, like this:
http://code.google.com/a/apache-extras.org/p/pivot-multilang/
but due to the lack of time, it's near-empty ...
If you have some to share, please tell us.
For questions, etc we are here ... thanks for now.
Bye,
Sandro