Wednesday, October 31, 2012

An IDE for ScalaFX development? Yes - PLEEEEEASE!

This entry should tell you how to get an IDE (Integrated Development Environment) up and running for Scala development - and especially for ScalaFX (graphics application) development.

It shouldn't be even this difficult (and most likely will become easier over the years).

The *current* (Oct 2012) situation is that I fought over a week with Eclipse Juno without still getting it to fully work. With IntelliJ the fight was roughly half a day (not bad). 

With this text, you'll be up and running within an hour.

You shall need:
- OS X
- Scala 2.9.2 installed via HomeBrew.
- ScalaFX jar precompiled

You probably should read this earlier blog post first.



- Download "IntelliJ IDEA". Use the "Early Adapter Program" (recommended for Scala plugin to work) and take IDEA 12 (it has a great duck splash screen):

http://confluence.jetbrains.net/display/IDEADEV/IDEA+12+EAP   ( I took version 'idealC-122.639.dmg'. )

- Drag 'Leda-IC-122.639' app to somewhere (i.e. /Applications).

- Launch it and pick 'Open plugin manager' (top right corner of the welcome page):

- "Browser repositories…" > choose "Scala" plugin (v.0.6.287) (double click to download & install)
- You may also wish to install "SBT" plugin but it seems to only provide compilation help, not sure how it can be used for debugging.
- restart IntelliJ

THIS IS IMPORTANT!!!

In order to use the Scala plugin, it needs to be given a "language facet", essentially libraries that tell where Scala compiler & libraries can be found.

We'll do it here using the command-line-installed ("brew install scala") version 2.9.2 files.

- Create a project (i.e. from scratch)

Select type: "Java module"

Click "Scala" on the "desired technologies" page (below) and fill the "Create compiler library" and "Create standard library" names to your liking (and probably you want them to be 'global').

We'll make these point to the right HomeBrew-loaded jar's in a minute.





You should get to the main IDE soon.


There's a ton of things you should go through in File > Project Structure… Do it now.

Within there, you see 'Modules > Scala' that should be like this:


Notice that "scala-compiler" is selected as the way to compile Scala. This points to the scala-compiler.jar and scala-library.jar that we'll now define under "Global Libraries" (last entry of the "Project Structure…" dialog):

Make the entries look like this (in case you do have Scala 2.9.2 via 'brew'):




This should allow IDEA to compile Scala. 

NOTE: It is absolutely essential that you only play with one version of Scala. Don't download "another" 2.9.2 and make IDEA point to it (did not work - at least not for me).

- Within "Project Structure… > Libraries" add 'scalafx-1.0-SNAPSHOT.jar' (that you've snitched earlier, compiled with the same Scala version):


- To compile, "Build > Rebuild project" (I'm not a fan of automatic build)

- To start code, right click i.e. on 'Main.scala' and take 'run MainFX.main()' (no breakpoints etc.) or 'Debug 'MainFX.main()' (will stop at breakpoints).

Did it work?

Note that i.e. renaming the "Scala compiler library" seems to be enough to throw the "Scala facet" setting off the wall, and requires it to be reset ("Project Structure… > Facets)

References:

http://confluence.jetbrains.net/display/SCA/Getting+Started+with+IntelliJ+IDEA+Scala+Plugin


Saturday, October 20, 2012

Replicator service for spare parts, anyone? (mail order, reasonable price, scanning included)

I broke a small part of a classic table lamp recently, and am now considering the options of how to fix the damage.

Glue will probably not be strong enough. Wood will take time and not be 1:1 with the original.

Are there any 3d-printing shops available (within Finland, EU or globally) which would also offer the necessary scanning for actual replication of existing parts?

Ideally, they would extend the missing part, and give me perfect holder piece that lasts the next 40 years.



We thought this was science fiction. Star Trek has it. But the technology is there, and the business model is simple. I'm sure there's someone already out doing this - please find me. I'm your customer! :)

Contact either by comment here, email to akauppi(at)welho.com or twitter @bmdesignhki.

Addendum.

Got the parts done, in bright Xmas Red. Lamp says Thank you, Robin B!





Wednesday, October 17, 2012

Getting ScalaFX 2.2 demo up and running on OS X (with Oracle Java 7u7)

News 20-Oct-2012 - JDK 7u9 and a JavaFX 2.2.3 samples are out:


Use those files instead of the 7u7 mentioned below. The performance of some JavaFX Ensemble demos is now way better on the NVidia 9400 GPU (but not all). Also, there are new demos included in the bundle.



JavaFX is a 2d/3d GPU-accelerated graphics library that is going to be replacing the Swing as the main Java application UI library.

ScalaFX is a Scala language binding to JavaFX.

JavaFX development kit is distributed as an integral part of the general Java 7.x development kit (JDK), by Oracle.

Below are the steps to get a basic ScalaFX project started, developing on OS X.

You will need:
- OS X 10.7.3 or later ("Lion" or later) (a JDK 7u7 requirement)
- Basic experience on command line usage on OS X
- HomeBrew (or similar) command line tool installation system ('brew' is great and easy to install)
- Willingness to accept the Oracle 7.x JDK license agreement



Getting ScalaFX and JavaFX 2.1 running on OS X

Java SE 7 Update 7 (or later)

Download and install "Java SE 7u7" (or later) from Oracle:

Take these files:
jdk-7u7-macosx-x64.tar.gz
javafx_samples-2_2_0-macosx-universal.zip

The JDK (development kit) contains the JRE (runtime engine) so just a single install is sufficient.

Installation FAQ:

Note for users with Apple Java 6:

JDK 7 Installation for Mac OS X:

In short, just install the .pkg file by double-clicking. It will not replace the Apple Java 6 (in case you have Java enabled). You will need Java 7 for JavaFX 2.2 to function on OS X.

<<
You can determine which version of the JDK is the default by typing java -version in a Terminal window. If the installed version is 7u6, you will see a string that includes the text 1.7.0_06. For example:
    % java -version
    java version "1.7.0_06-ea"
    Java(TM) SE Runtime Environment (build 1.7.0_06-ea-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 23.2-b04, mixed mode)
To run a different version of Java, either specify the full path, or use the java_home tool:
    /usr/libexec/java_home -v 1.7.0_06 --exec javac -version
<<

JavaFX samples

Likely you already downloaded these (see URL and filename above).

Extract the files to some suitable directory.

To launch the .jar files, right-click and select 'Open in Jar Launcher > Run (or Open or something)'. This seems the way to bypass safety system preventing to launch .jar by a simple double click.

On OS X, they don't (yet) support launching from the HTML files. Ignore them. )

The UI responsiveness may be sluggish at times. This may be because of lack of optimization for hardware (GPU) rendering. Oracle site says any GPU supported by Lion should do, but in practice my MacBook Air (integrated Core i7 Intel GPU) performs way better than 2009 Mac Mini with NVidia. Likely the situation will improve once Oracle gets more OS X tuning done. Hope so.


BrickBraker.jar

Nice retro game.



Ensamble.jar

Try making this into full screen mode (the '+' icon at upper right). Unfortunately it seems the 'real' full screen mode (Apple-F) is not supported by JavaFX (or this demo)?

The 3D-xylophone was probably hot in (…no, it never was). Now it mainly displays the lack of antialiasing in its rendering.


"Advanced media" demo looks like animated gifs when played in full-screen on my Mini (but good on MacBook Air).

"Audio spectrum data" demos are great - check the lyrics! :)

The song is available also in Youtube.


ScalaFX compilation


First, get 'hg' (Mercurial) and 'sbt' to the Mac (i.e. using HomeBrew):

    $ brew install hg sbt

This makes a copy of 'scalafx' repository (to local folder 'scalafx'):

    $ hg clone https://code.google.com/p/scalafx/

The instructions in  'README.txt' are outdated. Do this instead:

    $ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home/
    $ sbt clean compile package

(without the 'package' sbt does not create the target/*.jar file)

To launch a demo of fading circles (makes other things on your computer crawl so don't leave it on :) ):

    $ sbt run





Making your own project

Create these files:

    build.sbt
    lib/
        scalafx-1.0-SNAPSHOT.jar
    src/
        mydemo.scala

'build.sbt' you can adopt from the one used in ScalaFX samples.

'lib/scalafx-1.0-SNAPSHOT.jar' is a copy from the 'target' directory of scalafx compilation.

'mydemo.scala' is whatever file you wish to use (again, something from the scalafx 'demo' directory would be fine).

    $ sbt run

Please make a comment if you got things working, with this walkthrough.


Monday, October 1, 2012

iPhone Lite - Yes, They Should!

"Analysts" are telling this:

http://appleinsider.com/articles/12/10/01/apple-seen-as-unlikely-to-introduce-new-inexpensive-iphone-model

I'm telling Apple should introduce an iPhone Lite and here's how I would have it done. Heh, writing's Cheap! :)

In the new iPod Nano, Apple has introduced a form factor that also suits a phone. 7.6 x 4 x 0.5cm. You can fit three of those on a Samsung Galaxy III (almost; that's 13.7 x 7 x 0.9cm).


Ingredients to add:
- GSM/EDGE telephony (no 3G necessary)
- iMessage
- Twitter (with pictures)

That's it.

Since the device is so small, one can think of using it with earphones only (the same as currently).

Having such a wide gap to the existing entry-level iPhone 4 makes a clear differentiation between the models. At the same time, this makes iPhone Lite perfect as a child's phone. Or as an entry level developing world phone (Brazil et.al.) without tarnishing the Apple brand.

Apple already has this division between iPhone and iPod touch. They only lack a phone in the Nano size category. It should look *exactly* the same.