JavaFX 1.0 is out and is absolutely amazing. You guys did really a great work on it.
As I really need a working SDK on Linux to continue to study and I don’t have any Windows/Mac near me, I’m using the Weiqi Gao’s workaround. I tried to simplify a little bit more the process for those who need JavaFX SDK working on Linux right now.
Now you can call javafx, javafxc, javafxdoc and javafxpackager from your terminal. Don’t forget that you need Java 1.6 or greater installed.
Here’s a video showing the SDK working, I’m compiling and running two sample applications. Remeber that as a temporary unofficial port for Linux, there’s not native video support nor hardware acceleration.
// returning 0 means collision
int collision(int ax, int ay, int bx, int by, int cx, int cy, int dx, int dy){
return ((ax > dx)||(bx < cx)||(ay > dy)||(by < cy));
}
I’ll show here a little demo about how implement simple rectangular collisions on JavaFX.
First I created a movable rectangle using the same idea of draggable nodes I already had posted before.
You can use rectangular collisions to create bounding boxes to handle collisions in more complex shapes or sprites. Is a common approach in 2d games to avoid more expensive calculations.
There are space for optimizations.
In this case I’m using only two objects. Some problems raises when I have N objects to handle.
This way we can pass just two bounding boxes to hitnode and easily check collision of a node against a list of bounding boxes nodes.
Using the same approach I also wrote this function to test if a Node is inside another Node:
function inside (ax, ay, bx, by, cx, cy, dx, dy):Boolean{return((ax > cx) and (bx < dx) and (ay > cy) and (by < dy));}
function insidenode(a:Node,b:Node):Boolean{return(inside(
a.getBoundsX(), a.getBoundsY(),
a.getBoundsX()+ a.getWidth(), a.getBoundsY()+ a.getHeight(),
b.getBoundsX(), b.getBoundsY(),
b.getBoundsX()+ b.getWidth(), b.getBoundsY()+ b.getHeight()));}
function inside (ax, ay, bx, by, cx, cy, dx, dy):Boolean{
return ((ax > cx) and (bx < dx) and (ay > cy) and (by < dy));
}
function insidenode(a:Node,b:Node):Boolean{
return (inside(
a.getBoundsX(), a.getBoundsY(),
a.getBoundsX() + a.getWidth(), a.getBoundsY() + a.getHeight(),
b.getBoundsX(), b.getBoundsY(),
b.getBoundsX() + b.getWidth(), b.getBoundsY() + b.getHeight()
));
}
Soon I’ll post game examples showing how to use this method and others collission detection methods.
Long urls are difficult to remember or print, usually full of redundancy and low semantic. With short and meaningful urls you can avoid thes problems and even achieve profitable goals with SEO
SEO (search engine optimization) technics.
There are services like Tiny URL, Fancy URL, Moo URL and others. Although they solve part of the problems, they bring several others. Another problem is if you have a web site like example.com and use a third-party service for short urls you are losing part of your mind-share with your users and clients.
As an example, if a example.com company wants to promote a open work position would be preferable spread a example.com/jobs instead of a tinyurl.com/examplejobs, or even worst, a tinyurl.com/3i4i592 (meaningless hash).
2. Solution Approach
I created a little program called xort that can be placed on your own server and provide you own short maintening your base url.
I use a pipe abstraction. Each pipe redirects from a key url to an output url.
The idea is that you have xort installed and associated into your domain (preferably on /x). A pipe inside example.com would be like example.com/x/jobs.
3. Tools
All those tools are multi platform, open source and free.
3.1 Glassfish Application Server
Glassfish is an open source application server project led by Sun Microsystems for the Java Enterprise Edition (Java EE) platform. It’s very easy to install and run and have a very nice administration web interface where you can do from simple tasks like deploy a application to more complexes like clustering.
Glassfish Admin Console
To develop the application I’m using NetBeans 6.5 Beta that comes with Glassfish V3 prelude b15b. Netbeans also provides a integration of project, database and web server.
Nevertheless, Glassfish has no dependencies with any IDE and perfectly works by alone. If you need I wrote this post explaining how to install and deploy a application on Glassfish from scratch.
3.2 MySQL Relational Database
MySQL is a relational database management system and probably the most used database on internet (has more than 11 million installations). It’s also very easy to install and administer, through command line or many gui interfaces.
To install MySQL and JDBC driver on Ubuntu just run as root:
# apt-get install mysql-server libmysql-java
After installing and configuring it you can test the jdbc driver throught this servlet code. You can optionally register the MySQL on NetBeans to have a easier access to it thought the service tab.
At the command line you can invoke mysql command line interface and use MySql commands or SQL queries. I’ll login and create a database called xort:
$ mysql -u username -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.0.51a-3ubuntu5.3 (Ubuntu)
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
You could also create this database by an SQL statement:
CREATEDATABASE xort;
CREATE DATABASE xort;
To select the database xort:
mysql> use xort;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>
Now we create a database called pipes with fields pin (pipe in) and pout (pipe out). They represent the input url and the output url of our pipe abstraction.
CREATETABLE pipes (
pin VARCHAR(255)NOTNULL,
pout VARCHAR(255));
CREATE TABLE pipes (
pin varchar(255) NOT NULL,
pout varchar(255)
);
As we expect a lot of searches queries on this table, we can optionally create a index for it on pin field. This can reduce ours searches from O(n) to O(logn) (because pin’s will be ordered so don’t need to look all pipes, we can use logn algorithms like binary search).
CREATEINDEX pinindex ON pipes (pin);
CREATE INDEX pinindex ON pipes (pin);
Another trick to improve our speed is recycling connections through connection pools.
Creating a pool of MySQL connections on Glassfish is very easy. There’re two good tutorials on this subject:
Set if users can add new pipes using the web interface.
allowNewPipes
true
JDBC driver to use
driver
com.mysql.jdbc.Driver
Username to login on the database.
username
root
Password for the given username.
password
yourpassword
JDBC path to database.
database
jdbc:mysql://localhost:3306/xort
Set if users can add new pipes using the web interface.
allowNewPipes
true
JDBC driver to use
driver
com.mysql.jdbc.Driver
Username to login on the database.
username
root
Password for the given username.
password
yourpassword
JDBC path to database.
database
jdbc:mysql://localhost:3306/xort
Inkscape is a Open Source vector graphics editor that works with SVG (Scalable Vector Graphics) format, Inkscape works with transparency, gradients, node editing, pattern fills, PNG export, and more. It also runs on Linux, Windows and OSX, those three are officially supported, but also runs in a broad list of Operational Systems. Is a software that I work daily and frequently is featured here in my blog.
You can download Inkscape or directly install it via some package system like Apt:
sudo apt-get install inskcape
But sometimes we need some special feature that is not available yet in the repositories or we want gain speed by having special binaries for our platforms or we want to help developing a new feature. In those cases we need to compile the software by ourself.
Those tips are valid for Ubuntu 8.04 but some part of them can be applied in others distributions. The Inkscape compiled here is the version 0.46+devel so newest versions can have compiling procedures slightly different.
Getting sources via APT.The easiest way to compile Inkscape on Ubuntu is
sudo su
apt-get build-dep inkscape
apt-get source inkscape
cd inkscape
./autogen.sh
./configure
make
make install
This will get a version of inkscape, compile it and install. If the first step doesn’t work well, you can try install all necessary packages by yourself using:
Getting sources via SVN. The recipe I showed above will compile a stable version of Inkscape but not the last version of Inkscape. For that we need to grab the source directly from the Subversion repositories and so compile it.
A alternative way to subversion is getting sources from here. Those are tarballs built every hour after someone change something in the development repositories. Download a tarball, and decompress it on your home folder.
Install all tools we need to compile Inkscape, this should fits:
Enter in the directory with the Inkscape source and do:
./autogen.sh
mkdir build
cd build
../configure
make
sudo make install
In both cases, grabbing sources via svn or via apt, or can set the place where the software will be installed so it not cause conflicts with you already installed version of Inkscape. You can do that replacing the ./configure step with something like:
./configure –prefix=/home/yourname/inkscape
If you had some trouble in one of those steps, consider reading some of those other tutorials:
This is a short tutorial about some JavaFX elements like ellipses, circles, effects and gradients.
In the first code we are creating a frame with a ellipse with center in (120,140), 60 pixels of horizontal radius, 20 pixels of vertical radius and color black. We have also a circle with center in (100,100), 50 pixels of radius and color red. The idea is make this circle appears like a sphere and make the ellipse look like a shadow.
First lets look at the gradient. It starts with a white color, going to red during the first 30% of the way. The remaining of the way is the color red going to a dark red. It creates a gradient like this one:
But it is a radial gradient, with center in (75,75) and radius 50. So this radial gradient looks like this:
As we place this radial gradient in our circle, it was like this:
And now is like this:
Now the complete code. I guess it’s simple and also concise.
I did this little script to download the last version of JavaFX continuos build and install it for you.
#!/bin/sh
envfile=$HOME/.bash_profile
#download and unpatch the last build of JavaFx
mkdir jfx
cd jfx
wget http://openjfx.java.sun.com/hudson/job/openjfx-compiler/lastBuild/artifact/openjfx-compiler/dist//*zip*/dist.zip
unzip dist.zip
rm dist.zip
#set files at bin folder as executable
chmod +x dist/bin/*
#add those executables to the path
echo "PATH=\$PATH:`pwd`/dist/bin" >> $envfile
#!/bin/sh
envfile=$HOME/.bash_profile
#download and unpatch the last build of JavaFx
mkdir jfx
cd jfx
wget http://openjfx.java.sun.com/hudson/job/openjfx-compiler/lastBuild/artifact/openjfx-compiler/dist//*zip*/dist.zip
unzip dist.zip
rm dist.zip
#set files at bin folder as executable
chmod +x dist/bin/*
#add those executables to the path
echo "PATH=\$PATH:`pwd`/dist/bin" >> $envfile
Save this script as install_jfx.sh and execute it. Probably you want to execute it at you home directory. If you want to install JavaFX to root change envfile for /root/.bash_profile, if you want to install to all users change for /etc/profile. I tested this script successfully on my Ubuntu 8.04.
After that open a new terminal and try to see if javafx, javafxc and javafxdoc are available. You can test your enviroment with this simple program.
importjavafx.ui.*;importjava.lang.*;Frame{
visible:true
content: FlowPanel {
content:Button{
var n =0
text: bind Integer.toString(n)
action: function(){
n++;}}}}