This page is no longer maintained — Please continue to the home page at www.scala-lang.org

GUI questions

14 replies
Russ P.
Joined: 2009-01-31,
User offline. Last seen 1 year 26 weeks ago.

I decided to try some basic GUI programming, so I typed in Listing
34.1 from Programming in Scala, 2nd Edition. It's called
"FirstSwingApp". I tried to compile it with Scala 2.9.1 (on Linux),
and here's what I got:

[error] /home/russ/GUItest.scala:2: object swing is not a member of
package scala
[error] import scala.swing._

I looked in the docs for 2.9.1, and I see "swing" listed. Any idea
what the problem could be here?

Also, I have a few general questions. I am thinking about developing a
simplified GUI display for an air traffic controller. It would show a
top-down view of the positions of all the flights in a zoomable area
of airspace. Each flight would be represented as a
"target" (represented by some symbol), and left-clicking on it will
toggle a data block with three or four lines of data, showing
callsign, aircraft type, altitude, assigned altitude and a couple
other items. As each surveillance track comes in, the position of the
associated flight will be updated. Right-clicking on a target will
show the assigned route.

Should I use Swing for something like this? If so, which classes in
particular should I look at?

Can anyone with Scala/Java GUI experience give me a rough estimate of
the time if should take an experienced GUI developer to get something
like this working? Thanks.

--Russ P.

ichoran
Joined: 2009-08-14,
User offline. Last seen 2 years 3 weeks ago.
Re: GUI questions
Swing is entirely up to the job, and it would only take me an afternoon to do what you've described, but that's because I've already done zoomable clickable stuff with objects and trajectories in Swing, so I know just what is required.  Every step requires a while to learn: how do you handle a click?  A mouse move?  Drawing something custom?  Finding a clickable target?  Etc..

I'm not sure why you're having trouble importing scala.swing.  What happens if you type scala.swing<tab> in the REPL?  The Swing stuff _does_ live in a different jar (scala-swing.jar) than the main library, so if you're using a build system that needs to know where the jars are, you'll have to add that jar to make Swing visible.

It's entirely possible to play with Swing in the REPL, though.  That's generally what I do while prototyping (to get layouts and stuff right), restarting every now and again when I've let too many window handles go untidied.

  --Rex

On Sat, Feb 11, 2012 at 3:13 PM, Russ P. <russ.paielli@gmail.com> wrote:
I decided to try some basic GUI programming, so I typed in Listing
34.1 from Programming in Scala, 2nd Edition. It's called
"FirstSwingApp". I tried to compile it with Scala 2.9.1 (on Linux),
and here's what I got:

[error] /home/russ/GUItest.scala:2: object swing is not a member of
package scala
[error] import scala.swing._

I looked in the docs for 2.9.1, and I see "swing" listed. Any idea
what the problem could be here?

Also, I have a few general questions. I am thinking about developing a
simplified GUI display for an air traffic controller. It would show a
top-down view of the positions of all the flights in a zoomable area
of airspace. Each flight would be represented as a
"target" (represented by some symbol), and left-clicking on it will
toggle a data block with three or four lines of data, showing
callsign, aircraft type, altitude, assigned altitude and a couple
other items. As each surveillance track comes in, the position of the
associated flight will be updated. Right-clicking on a target will
show the assigned route.

Should I use Swing for something like this? If so, which classes in
particular should I look at?

Can anyone with Scala/Java GUI experience give me a rough estimate of
the time if should take an experienced GUI developer to get something
like this working? Thanks.

--Russ P.

Naoki Takezoe
Joined: 2011-08-12,
User offline. Last seen 42 years 45 weeks ago.
Re: GUI questions

As Rex said, scala.swing is separated from core library.
So if you are using sbt, you have to add the following dependency
into your build.sbt to use scala.swing:

libraryDependencies += "org.scala-lang" % "scala-swing" % "2.9.1"

2012/2/12 Russ P. :
> I decided to try some basic GUI programming, so I typed in Listing
> 34.1 from Programming in Scala, 2nd Edition. It's called
> "FirstSwingApp". I tried to compile it with Scala 2.9.1 (on Linux),
> and here's what I got:
>
> [error] /home/russ/GUItest.scala:2: object swing is not a member of
> package scala
> [error] import scala.swing._
>
> I looked in the docs for 2.9.1, and I see "swing" listed. Any idea
> what the problem could be here?
>
> Also, I have a few general questions. I am thinking about developing a
> simplified GUI display for an air traffic controller. It would show a
> top-down view of the positions of all the flights in a zoomable area
> of airspace. Each flight would be represented as a
> "target" (represented by some symbol), and left-clicking on it will
> toggle a data block with three or four lines of data, showing
> callsign, aircraft type, altitude, assigned altitude and a couple
> other items. As each surveillance track comes in, the position of the
> associated flight will be updated. Right-clicking on a target will
> show the assigned route.
>
> Should I use Swing for something like this? If so, which classes in
> particular should I look at?
>
> Can anyone with Scala/Java GUI experience give me a rough estimate of
> the time if should take an experienced GUI developer to get something
> like this working? Thanks.
>
> --Russ P.

Russ P.
Joined: 2009-01-31,
User offline. Last seen 1 year 26 weeks ago.
Re: GUI questions

Thanks for that tip.

Also, can anyone point me to a good tutorial (online, book, or
whatever) that would help me to accomplish my original objective? Here
it is again:

I would like to develop a simplified GUI display for an air traffic
controller. It would show a top-down view of the positions of all the
flights in a zoomable area of airspace. Each flight would be
represented as a "target" (represented by some symbol), and left-
clicking on it will toggle a data block with three or four lines of
data, showing callsign, aircraft type, altitude, assigned altitude and
a couple other items. As each surveillance track comes in, the
position of the associated flight will be updated. Right-clicking on a
target will show the assigned route.

Thanks.

--Russ P.

On Feb 11, 8:14 pm, Naoki Takezoe wrote:
> As Rex said, scala.swing is separated from core library.
> So if you are using sbt, you have to add the following dependency
> into your build.sbt to use scala.swing:
>
> libraryDependencies += "org.scala-lang" % "scala-swing" % "2.9.1"

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: GUI questions
Some options:


On Sun, Feb 12, 2012 at 3:05 PM, Russ P. <russ.paielli@gmail.com> wrote:
Thanks for that tip.

Also, can anyone point me to a good tutorial (online, book, or
whatever) that would help me to accomplish my original objective? Here
it is again:

I would like to develop a simplified GUI display for an air traffic
controller. It would show a top-down view of the positions of all the
flights in a zoomable area of airspace. Each flight would be
represented as a "target" (represented by some symbol), and left-
clicking on it will toggle a data block with three or four lines of
data, showing callsign, aircraft type, altitude, assigned altitude and
a couple other items. As each surveillance track comes in, the
position of the associated flight will be updated. Right-clicking on a
target will show the assigned route.

Thanks.

--Russ P.

On Feb 11, 8:14 pm, Naoki Takezoe <take...@gmail.com> wrote:
> As Rex said, scala.swing is separated from core library.
> So if you are using sbt, you have to add the following dependency
> into your build.sbt to use scala.swing:
>
> libraryDependencies += "org.scala-lang" % "scala-swing" % "2.9.1"

Russ P.
Joined: 2009-01-31,
User offline. Last seen 1 year 26 weeks ago.
Re: GUI questions

Thanks for the suggestions, but I'd rather stick with Scala/Swing
unless there's is some compelling advantage of another library or
language. I'd just like to know which main classes or "widgets" I
should use. I'm not trying to break any new ground here.

Again, I mainly just need to display the positions of aircraft in the
horizontal plane, and I need to update those positions as new tracking
data comes in. Clicking on an aircraft should toggle a data block. I
would also like to be able to zoom and translate the display
(something like what you can do with google maps). I don't really need
a map, although in the future I may want to draw sector boundaries
(polygons).

In the examples in chapter 34 of Programming in Scala, they use
"SimpleGUIApplication" and "MainFrame". In chapter 35 they use
"ScrollPane." Are these the classes I should start with? Clues
welcome. Thanks.

--Russ P.

On Feb 12, 6:43 pm, Naftoli Gugenheim wrote:
> Some options:
>
>    -http://www.piccolo2d.org/zoomable interface (no map though)
>    -
>    http://today.java.net/pub/a/today/2007/10/30/building-maps-into-swing...
> (not
>    sure if it still exists)
>    - Write it in javascript with OpenLayers --
>    that way you can overlay it over a map with zoomability for free. One
>    possibility is to serve it from a Lift app and send javascript commands to
>    the browser on the fly, either with CometActors or with
> reactive-web(with the latter you can write
> one-liners like
>    Reactions.queue("javascript.command();") with less bolerplate to set it up).
>    - GWT's map widget (you can use scala+GWT).
>
>
>
>
>
>
>
> On Sun, Feb 12, 2012 at 3:05 PM, Russ P. wrote:
> > Thanks for that tip.
>
> > Also, can anyone point me to a good tutorial (online, book, or
> > whatever) that would help me to accomplish my original objective? Here
> > it is again:
>
> > I would like to develop a simplified GUI display for an air traffic
> > controller. It would show a top-down view of the positions of all the
> > flights in a zoomable area of airspace. Each flight would be
> > represented as a "target" (represented by some symbol), and left-
> > clicking on it will toggle a data block with three or four lines of
> > data, showing callsign, aircraft type, altitude, assigned altitude and
> > a couple other items. As each surveillance track comes in, the
> > position of the associated flight will be updated. Right-clicking on a
> > target will show the assigned route.
>
> > Thanks.
>
> > --Russ P.
>
> > On Feb 11, 8:14 pm, Naoki Takezoe wrote:
> > > As Rex said, scala.swing is separated from core library.
> > > So if you are using sbt, you have to add the following dependency
> > > into your build.sbt to use scala.swing:
>
> > > libraryDependencies += "org.scala-lang" % "scala-swing" % "2.9.1"

Michael Schmitz
Joined: 2011-11-01,
User offline. Last seen 42 years 45 weeks ago.
Re: GUI questions

This might be a bad suggestion, but I recently learned that it's easy
to display SVG within scala Swing. You can handle click events in the
SVG, although I couldn't find an easy way to work with the SVG xml.
SVG can handle the scaling.

Peace. Michael

On Sat, Feb 11, 2012 at 12:13 PM, Russ P. wrote:
> I decided to try some basic GUI programming, so I typed in Listing
> 34.1 from Programming in Scala, 2nd Edition. It's called
> "FirstSwingApp". I tried to compile it with Scala 2.9.1 (on Linux),
> and here's what I got:
>
> [error] /home/russ/GUItest.scala:2: object swing is not a member of
> package scala
> [error] import scala.swing._
>
> I looked in the docs for 2.9.1, and I see "swing" listed. Any idea
> what the problem could be here?
>
> Also, I have a few general questions. I am thinking about developing a
> simplified GUI display for an air traffic controller. It would show a
> top-down view of the positions of all the flights in a zoomable area
> of airspace. Each flight would be represented as a
> "target" (represented by some symbol), and left-clicking on it will
> toggle a data block with three or four lines of data, showing
> callsign, aircraft type, altitude, assigned altitude and a couple
> other items. As each surveillance track comes in, the position of the
> associated flight will be updated. Right-clicking on a target will
> show the assigned route.
>
> Should I use Swing for something like this? If so, which classes in
> particular should I look at?
>
> Can anyone with Scala/Java GUI experience give me a rough estimate of
> the time if should take an experienced GUI developer to get something
> like this working? Thanks.
>
> --Russ P.

ichoran
Joined: 2009-08-14,
User offline. Last seen 2 years 3 weeks ago.
Re: GUI questions
If it's easy, can you share how (at least a hint or a link)?

  --Rex

On Mon, Feb 13, 2012 at 5:58 PM, Michael Schmitz <michael@schmitztech.com> wrote:
This might be a bad suggestion, but I recently learned that it's easy
to display SVG within scala Swing.  You can handle click events in the
SVG, although I couldn't find an easy way to work with the SVG xml.
SVG can handle the scaling.

Peace.  Michael


On Sat, Feb 11, 2012 at 12:13 PM, Russ P. <russ.paielli@gmail.com> wrote:
> I decided to try some basic GUI programming, so I typed in Listing
> 34.1 from Programming in Scala, 2nd Edition. It's called
> "FirstSwingApp". I tried to compile it with Scala 2.9.1 (on Linux),
> and here's what I got:
>
> [error] /home/russ/GUItest.scala:2: object swing is not a member of
> package scala
> [error] import scala.swing._
>
> I looked in the docs for 2.9.1, and I see "swing" listed. Any idea
> what the problem could be here?
>
> Also, I have a few general questions. I am thinking about developing a
> simplified GUI display for an air traffic controller. It would show a
> top-down view of the positions of all the flights in a zoomable area
> of airspace. Each flight would be represented as a
> "target" (represented by some symbol), and left-clicking on it will
> toggle a data block with three or four lines of data, showing
> callsign, aircraft type, altitude, assigned altitude and a couple
> other items. As each surveillance track comes in, the position of the
> associated flight will be updated. Right-clicking on a target will
> show the assigned route.
>
> Should I use Swing for something like this? If so, which classes in
> particular should I look at?
>
> Can anyone with Scala/Java GUI experience give me a rough estimate of
> the time if should take an experienced GUI developer to get something
> like this working? Thanks.
>
> --Russ P.

Jonathan Merritt 2
Joined: 2011-08-12,
User offline. Last seen 42 years 45 weeks ago.
Re: GUI questions
Hi Russ, Rex et al.,
> Also, I have a few general questions. I am thinking about developing a
> simplified GUI display for an air traffic controller. It would show a
> top-down view of the positions of all the flights in a zoomable area
> of airspace. Each flight would be represented as a
> "target" (represented by some symbol), and left-clicking on it will
> toggle a data block with three or four lines of data, showing
> callsign, aircraft type, altitude, assigned altitude and a couple
> other items. As each surveillance track comes in, the position of the
> associated flight will be updated. Right-clicking on a target will
> show the assigned route.

I'm interested to hear what other replies you get, but here's my take...
Firstly, you're not displaying data which fits into the model of an existing control.  You're not displaying a table, text field or button for example.  So, you will probably end up building a "custom control".  Here's an example of an image viewer with zooming and scaling:   http://www.javareference.com/jrexamples/viewexample.jsp?id=84The ImagePanel class is the custom control.  (That's not necessarily a great example, but it shows zooming and scaling.  Just Google for "Swing custom control".)  In many contexts, custom controls will be intended for a more general audience, so they will cope with things like different Look-and-Feel, etc., that you probably don't need.  However, custom controls often also do lots of their own painting, so they may be a good place to start looking.
You will probably have to build your display from the ground up.  Typically, you extend an existing Swing class such as JPanel, which provides you with basic component-like behaviour.  You then have your GUI class listen to your event-firing data model, and request re-paints as necessary.  The Swing framework will call the paintComponent method on your control to do the actual Java2D drawing.  Take a look at the source for a typical Swing model / view pair to see how this is done (eg: DefaultBoundedRangeModel and JScrollBar).
I would also note that IMHO this isn't an "easy" use of Swing (or really any GUI toolkit).  You will have to understand somewhat more about the internals of Swing than somebody building a business-oriented form application, for example.  It will probably be more involved than the examples from the Scala textbook.
Although it hasn't been mentioned yet, another option you have is JavaFX (or the nacent ScalaFX):  http://code.google.com/p/scalafx/ IMO, the JavaFX scene-graph approach has a distinct advantage over Swing when it comes to more "free-form" displays / components like the one you're proposing.  It is better able to cope with arbitrary layout, and will allow you to do things like your right-click data box more easily.  On the down side, it is an Oracle technology, and they've already abandoned one version of it.
--Jonathan Merritt, BE(Mech)/BSc PhDResearch Fellow, Veterinary ScienceThe University of Melbourne
Michael Schmitz
Joined: 2011-11-01,
User offline. Last seen 42 years 45 weeks ago.
Re: GUI questions

Sure--so long as you tell what I'm doing wrong if you go this route.

Here's a gist that has code to convert SVG representation of a DOT
graph (see graphviz) and made the nodes clickable (a println is
executed). The nice thing about SVG is it's flexible technology. The
bad thing about SVG is that it uses a lot of XML. org.w3c.dom is
hell, but I'm not sure there's another way I can play with the XML
since the nodes are subclassed by Batik (I think).

https://gist.github.com/1822050

I have a question regarding whether there's an easier way to
navigate/add event handlers to the XML nodes. It's not a great
question so I don't expect a great answer.

http://stackoverflow.com/questions/9233179/manipulate-svg-xml-for-batik

Hope this helps! Michael

P.S. This is from playing around for a couple hours last week, and I
totally welcome any criticism about what I'm doing wrong!

On Mon, Feb 13, 2012 at 3:31 PM, Rex Kerr wrote:
> If it's easy, can you share how (at least a hint or a link)?
>
>   --Rex
>
>
> On Mon, Feb 13, 2012 at 5:58 PM, Michael Schmitz
> wrote:
>>
>> This might be a bad suggestion, but I recently learned that it's easy
>> to display SVG within scala Swing.  You can handle click events in the
>> SVG, although I couldn't find an easy way to work with the SVG xml.
>> SVG can handle the scaling.
>>
>> Peace.  Michael
>>
>>
>> On Sat, Feb 11, 2012 at 12:13 PM, Russ P. wrote:
>> > I decided to try some basic GUI programming, so I typed in Listing
>> > 34.1 from Programming in Scala, 2nd Edition. It's called
>> > "FirstSwingApp". I tried to compile it with Scala 2.9.1 (on Linux),
>> > and here's what I got:
>> >
>> > [error] /home/russ/GUItest.scala:2: object swing is not a member of
>> > package scala
>> > [error] import scala.swing._
>> >
>> > I looked in the docs for 2.9.1, and I see "swing" listed. Any idea
>> > what the problem could be here?
>> >
>> > Also, I have a few general questions. I am thinking about developing a
>> > simplified GUI display for an air traffic controller. It would show a
>> > top-down view of the positions of all the flights in a zoomable area
>> > of airspace. Each flight would be represented as a
>> > "target" (represented by some symbol), and left-clicking on it will
>> > toggle a data block with three or four lines of data, showing
>> > callsign, aircraft type, altitude, assigned altitude and a couple
>> > other items. As each surveillance track comes in, the position of the
>> > associated flight will be updated. Right-clicking on a target will
>> > show the assigned route.
>> >
>> > Should I use Swing for something like this? If so, which classes in
>> > particular should I look at?
>> >
>> > Can anyone with Scala/Java GUI experience give me a rough estimate of
>> > the time if should take an experienced GUI developer to get something
>> > like this working? Thanks.
>> >
>> > --Russ P.
>
>

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: GUI questions
How are you displaying it?

On Monday, February 13, 2012, Michael Schmitz wrote:
Sure--so long as you tell what I'm doing wrong if you go this route.

Here's a gist that has code to convert SVG representation of a DOT
graph (see graphviz) and made the nodes clickable (a println is
executed).  The nice thing about SVG is it's flexible technology.  The
bad thing about SVG is that it uses a lot of XML.  org.w3c.dom is
hell, but I'm not sure there's another way I can play with the XML
since the nodes are subclassed by Batik (I think).

https://gist.github.com/1822050

I have a question regarding whether there's an easier way to
navigate/add event handlers to the XML nodes.  It's not a great
question so I don't expect a great answer.

http://stackoverflow.com/questions/9233179/manipulate-svg-xml-for-batik

Hope this helps!  Michael

P.S. This is from playing around for a couple hours last week, and I
totally welcome any criticism about what I'm doing wrong!


On Mon, Feb 13, 2012 at 3:31 PM, Rex Kerr <ichoran@gmail.com> wrote:
> If it's easy, can you share how (at least a hint or a link)?
>
>   --Rex
>
>
> On Mon, Feb 13, 2012 at 5:58 PM, Michael Schmitz <michael@schmitztech.com>
> wrote:
>>
>> This might be a bad suggestion, but I recently learned that it's easy
>> to display SVG within scala Swing.  You can handle click events in the
>> SVG, although I couldn't find an easy way to work with the SVG xml.
>> SVG can handle the scaling.
>>
>> Peace.  Michael
>>
>>
>> On Sat, Feb 11, 2012 at 12:13 PM, Russ P. <russ.paielli@gmail.com> wrote:
>> > I decided to try some basic GUI programming, so I typed in Listing
>> > 34.1 from Programming in Scala, 2nd Edition. It's called
>> > "FirstSwingApp". I tried to compile it with Scala 2.9.1 (on Linux),
>> > and here's what I got:
>> >
>> > [error] /home/russ/GUItest.scala:2: object swing is not a member of
>> > package scala
>> > [error] import scala.swing._
>> >
>> > I looked in the docs for 2.9.1, and I see "swing" listed. Any idea
>> > what the problem could be here?
>> >
>> > Also, I have a few general questions. I am thinking about developing a
>> > simplified GUI display for an air traffic controller. It would show a
>> > top-down view of the positions of all the flights in a zoomable area
>> > of airspace. Each flight would be represented as a
>> > "target" (represented by some symbol), and left-clicking on it will
>> > toggle a data block with three or four lines of data, showing
>> > callsign, aircraft type, altitude, assigned altitude and a couple
>> > other items. As each surveillance track comes in, the position of the
>> > associated flight will be updated. Right-clicking on a target will
>> > show the assigned route.
>> >
>> > Should I use Swing for something like this? If so, which classes in
>> > particular should I look at?
>> >
>> > Can anyone with Scala/Java GUI experience give me a rough estimate of
>> > the time if should take an experienced GUI developer to get something
>> > like this working? Thanks.
>> >
>> > --Russ P.
>
>
Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: GUI questions


On Monday, February 13, 2012, Russ P. wrote:
Thanks for the suggestions, but I'd rather stick with Scala/Swing
unless there's is some compelling advantage of another library or
language.

It's much easier to code something like this (zoomable ui) with these. With swing there's a lot you'll have to do yourself, depending on how intuitive you want the ui to be. For instance, mouse-wheel to zoom, click and drag to scroll, and painting everything, are manual work with plain swing. Also I never did something like this with *scala* swing, so I'll describe doing with swing directly, from vague memories so there may be more to it. Basically, IIRC you have to:
  1. Maintain a data structure
  2. Subclass JPanel
  3. Handle all events to update all aspects of the display (zoom, pan, select) then call repaint, and take action (display a JPopupMenu). (This step can be made a lot more scalable with reactive-core, and with implicits that convert functions to listener interface instances. It's more than you may think.)
  4. Paint as appropriate
  5. Wrap the JPanel in a JScrollPane in a JFrame etc.
  6. When notified of new data, update the data structure and call repaint
 With something that is based on a zoomable scene graph, which is basically everything I linked to, all you have to do is:
  1. Add UI elements to the scene graph
  2. Handle *custom* events (right click, etc.)
  3. When notified of new data update the scene graph as appropriate
  4. Add the panel to the container

I'd just like to know which main classes or "widgets" I
should use. I'm not trying to break any new ground here.

Again, I mainly just need to display the positions of aircraft in the
horizontal plane, and I need to update those positions as new tracking
data comes in. Clicking on an aircraft should toggle a data block. I
would also like to be able to zoom and translate the display
(something like what you can do with google maps). I don't really need
a map, although in the future I may want to draw sector boundaries
(polygons).

In the examples in chapter 34 of Programming in Scala, they use
"SimpleGUIApplication" and "MainFrame". In chapter 35 they use
"ScrollPane." Are these the classes I should start with? Clues
welcome. Thanks.

--Russ P.


On Feb 12, 6:43 pm, Naftoli Gugenheim <naftoli...@gmail.com> wrote:
> Some options:
>
>    -http://www.piccolo2d.org/zoomable interface (no map though)
>    -
>    http://today.java.net/pub/a/today/2007/10/30/building-maps-into-swing...
> (not
>    sure if it still exists)
>    - Write it in javascript with OpenLayers <http://openlayers.org/> --
>    that way you can overlay it over a map with zoomability for free. One
>    possibility is to serve it from a Lift app and send javascript commands to
>    the browser on the fly, either with CometActors or with
> reactive-web<http://reactive-web.tk>(with the latter you can write
> one-liners like
>    Reactions.queue("javascript.command();") with less bolerplate to set it up).
>    - GWT's map widget (you can use scala+GWT).
>
>
>
>
>
>
>
> On Sun, Feb 12, 2012 at 3:05 PM, Russ P. <russ.paie...@gmail.com> wrote:
> > Thanks for that tip.
>
> > Also, can anyone point me to a good tutorial (online, book, or
> > whatever) that would help me to accomplish my original objective? Here
> > it is again:
>
> > I would like to develop a simplified GUI display for an air traffic
> > controller. It would show a top-down view of the positions of all the
> > flights in a zoomable area of airspace. Each flight would be
> > represented as a "target" (represented by some symbol), and left-
> > clicking on it will toggle a data block with three or four lines of
> > data, showing callsign, aircraft type, altitude, assigned altitude and
> > a couple other items. As each surveillance track comes in, the
> > position of the associated flight will be updated. Right-clicking on a
> > target will show the assigned route.
>
> > Thanks.
>
> > --Russ P.
>
> > On Feb 11, 8:14 pm, Naoki Takezoe <take...@gmail.com> wrote:
> > > As Rex said, scala.swing is separated from core library.
> > > So if you are using sbt, you have to add the following dependency
> > > into your build.sbt to use scala.swing:
>
> > > libraryDependencies += "org.scala-lang" % "scala-swing" % "2.9.1"
Michael Schmitz
Joined: 2011-11-01,
User offline. Last seen 42 years 45 weeks ago.
Re: GUI questions

I realized just before reading this email I completely skipped that code...

import org.apache.batik.swing.JSVGCanvas
import org.apache.batik.swing.svg.JSVGComponent

val canvas = new JSVGCanvas
canvas.setDocumentState(JSVGComponent.ALWAYS_DYNAMIC)

contents += new Component {
override lazy val peer = canvas
}

canvas.setDocument(xmlDoc)

Easy!
Michael

On Mon, Feb 13, 2012 at 8:16 PM, Naftoli Gugenheim wrote:
> How are you displaying it?
>
>
> On Monday, February 13, 2012, Michael Schmitz wrote:
>>
>> Sure--so long as you tell what I'm doing wrong if you go this route.
>>
>> Here's a gist that has code to convert SVG representation of a DOT
>> graph (see graphviz) and made the nodes clickable (a println is
>> executed).  The nice thing about SVG is it's flexible technology.  The
>> bad thing about SVG is that it uses a lot of XML.  org.w3c.dom is
>> hell, but I'm not sure there's another way I can play with the XML
>> since the nodes are subclassed by Batik (I think).
>>
>> https://gist.github.com/1822050
>>
>> I have a question regarding whether there's an easier way to
>> navigate/add event handlers to the XML nodes.  It's not a great
>> question so I don't expect a great answer.
>>
>> http://stackoverflow.com/questions/9233179/manipulate-svg-xml-for-batik
>>
>> Hope this helps!  Michael
>>
>> P.S. This is from playing around for a couple hours last week, and I
>> totally welcome any criticism about what I'm doing wrong!
>>
>>
>> On Mon, Feb 13, 2012 at 3:31 PM, Rex Kerr wrote:
>> > If it's easy, can you share how (at least a hint or a link)?
>> >
>> >   --Rex
>> >
>> >
>> > On Mon, Feb 13, 2012 at 5:58 PM, Michael Schmitz
>> >
>> > wrote:
>> >>
>> >> This might be a bad suggestion, but I recently learned that it's easy
>> >> to display SVG within scala Swing.  You can handle click events in the
>> >> SVG, although I couldn't find an easy way to work with the SVG xml.
>> >> SVG can handle the scaling.
>> >>
>> >> Peace.  Michael
>> >>
>> >>
>> >> On Sat, Feb 11, 2012 at 12:13 PM, Russ P.
>> >> wrote:
>> >> > I decided to try some basic GUI programming, so I typed in Listing
>> >> > 34.1 from Programming in Scala, 2nd Edition. It's called
>> >> > "FirstSwingApp". I tried to compile it with Scala 2.9.1 (on Linux),
>> >> > and here's what I got:
>> >> >
>> >> > [error] /home/russ/GUItest.scala:2: object swing is not a member of
>> >> > package scala
>> >> > [error] import scala.swing._
>> >> >
>> >> > I looked in the docs for 2.9.1, and I see "swing" listed. Any idea
>> >> > what the problem could be here?
>> >> >
>> >> > Also, I have a few general questions. I am thinking about developing
>> >> > a
>> >> > simplified GUI display for an air traffic controller. It would show a
>> >> > top-down view of the positions of all the flights in a zoomable area
>> >> > of airspace. Each flight would be represented as a
>> >> > "target" (represented by some symbol), and left-clicking on it will
>> >> > toggle a data block with three or four lines of data, showing
>> >> > callsign, aircraft type, altitude, assigned altitude and a couple
>> >> > other items. As each surveillance track comes in, the position of the
>> >> > associated flight will be updated. Right-clicking on a target will
>> >> > show the assigned route.
>> >> >
>> >> > Should I use Swing for something like this? If so, which classes in
>> >> > particular should I look at?
>> >> >
>> >> > Can anyone with Scala/Java GUI experience give me a rough estimate of
>> >> > the time if should take an experienced GUI developer to get something
>> >> > like this working? Thanks.
>> >> >
>> >> > --Russ P.
>> >
>> >

hohonuuli
Joined: 2009-08-30,
User offline. Last seen 3 years 9 weeks ago.
Re: GUI questions

> > > > Also, I have a few general questions. I am thinking about developing a
> > > > simplified GUI display for an air traffic controller. It would show a
> > > > top-down view of the positions of all the flights in a zoomable area
> > > > of airspace. Each flight would be represented as a
> > > > "target" (represented by some symbol), and left-clicking on it will
> > > > toggle a data block with three or four lines of data, showing
> > > > callsign, aircraft type, altitude, assigned altitude and a couple
> > > > other items. As each surveillance track comes in, the position of the
> > > > associated flight will be updated. Right-clicking on a target will
> > > > show the assigned route.
> > >
> >
>

If you're going to use Swing for this, you'll definitely need a decent understanding of Java2D for drawing your symbols and paths. I've used the book 'Java 2D Graphics' by Jonathan Knudsen (pub: O'Reilly) and it's been a handy reference to have. What you're proposing to do should be pretty straight-forward; sounds pretty fun actually.
> Although it hasn't been mentioned yet, another option you have is JavaFX (or the nacent ScalaFX):
> http://code.google.com/p/scalafx/
> IMO, the JavaFX scene-graph approach has a distinct advantage over Swing when it comes to more "free-form" displays / components like the one you're proposing. […] On the down side, it is an Oracle technology, and they've already abandoned one version of it.
>
JavaFX would be a good choice for this too. The API is definitely more 'modern' than Java2D; the performance will likely be better to. BTW, you can mix JavaFX and ScalaFX code together pretty easily (ScalaFX classes are just wrappers around the JavaFX equivalents. You can access the underlying JavaFX class like so: val javafxShape = scalafxShape.delegate)

Have fun.

Philippe Lhoste
Joined: 2010-09-02,
User offline. Last seen 42 years 45 weeks ago.
Re: GUI questions

On 13/02/2012 03:43, Naftoli Gugenheim wrote:
> Some options:
>
> * http://www.piccolo2d.org/ zoomable interface (no map though)
> * http://today.java.net/pub/a/today/2007/10/30/building-maps-into-swing-ap... (not
> sure if it still exists)
> * Write it in javascript with OpenLayers -- that way you can
> overlay it over a map with zoomability for free. One possibility is to serve it from a
> Lift app and send javascript commands to the browser on the fly, either with
> CometActors or with reactive-web (with the latter you can
> write one-liners like Reactions.queue("javascript.command();") with less bolerplate to
> set it up).
> * GWT's map widget (you can use scala+GWT).

JavaFX is still an option... It might be suitable for such job (since it is vector-based,
so easily zoomable) and it has a Scala wrapper.

As said, if this is done in Swing, all drawing, zooming must be made by hand, with scale
and translate.

Hey, there is also an option with Processing! ;-) (low level, but easier to code than
Swing) http://Processing.org

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland