mardi 23 février 2010
JavaFX Composer, the blog!
JavaFX Composer, of course ;)
http://blogs.sun.com/javafxcomposer/
lundi 22 février 2010
Examples using JPA 2.0
- to create the database and one table
- to create the entity and the persistence.xml file
- to use a namedQuery
- to use criteria query API
- Create a derby database with :
- Database Name : javafxDB
- UserName : APP
- Password : paddy
- Create the music table and fill it.
- The Entity which is mapped to music table
| Music.java |
package paddy.domain; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.NamedQuery; /** * * @author Patrick */ @Entity @NamedQuery(name = "findAllAlbum", query= "select m from Music m") public class Music implements Serializable { @Id @GeneratedValue private Long id; @Column(name = "artist_name") private String artisteName; @Column(name = "album_title") private String albumTitle; public Music() { } ... Getter and setter ... @Override public String toString(){ StringBuffer sb = new StringBuffer(); sb.append("id : ");sb.append(id);sb.append(" ; "); sb.append("artisteName : ");sb.append(artisteName);sb.append(" ; "); sb.append("albumTitle : ");sb.append(albumTitle); sb.append(" \n"); return sb.toString(); } }
@Entity: designate my pojo as an entity so I can use it with JPA services.
- The persistence.xml file
| META-INF\persistence.xml |
<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="MusicAndLight" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <class>paddy.domain.Music</class> <properties> <property name="eclipselink.target-database" value="DERBY"/> <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/> <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/javafxDB"/> <property name="javax.persistence.jdbc.user" value="APP"/> <property name="javax.persistence.jdbc.password" value="paddy"/> </properties> </persistence-unit> </persistence>
- the persistence unit named MusicAndLight
- the entity (paddy.domain.Music) managed by the persistence unit
- and how the persistence unit connects to the database
| namedQuery |
EntityManagerFactory emf = Persistence.createEntityManagerFactory("MusicAndLight"); EntityManager em = emf.createEntityManager(); //get and create the namedQuery findAllBum Query query = em.createNamedQuery("findAllAlbum"); //execute the query List<Music> musics = query.getResultList(); for (Music music : musics){ System.out.println(music); } em.close(); emf.close();
| Criteria Api |
EntityManagerFactory emf = Persistence.createEntityManagerFactory("MusicAndLight"); EntityManager em = emf.createEntityManager(); String param = "Arc%"; CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Music> query2 = cb.createQuery(Music.class); //select * from Music Root<Music> music2 = query2.from(Music.class); //where artisteName like param //in my example where artisteName like Arc% (begining by Arc) query2.where(cb.like(music2.<String>get("artisteName"), param)); //execute the query List<Music> musics2 = em.createQuery(query2).getResultList(); for (Music music : musics2){ System.out.println(music); } em.close(); emf.close();
lundi 25 janvier 2010
Eclipse et Ubuntu 9.10 …
La chose parait assez simple de premier abord…
Mais impossible d’installer le plugin, les boutons ne produisent aucune action, les listes ne s’affichent pas, etc…
et comme le comportement interne de GTK+ a changé dans la version de GTK+ (2.18) utilisée dans Ubuntu 9.10 et que SWT utilise très mal et bidouille trop GTK+, ca ne marche plus.
https://bugs.launchpad.net/ubuntu/+source/gtk+2.0/+bug/442078/comments/28
Heureusement les créateurs on prévu le coup et il existe une variable pour redonner le comportement d’avant avec cette version de GTK+.
export GDK_NATIVE_WINDOWS=1
/home/patrick/patrick/program/eclipse.org/eclipse-javaEE-galileo/eclipse/eclipse
dimanche 10 janvier 2010
Scrolling with DisplacementMap effect
Bonne Année ! , Happy New Year !
For beginning this New Year, I added a sinusoidal effect to my scroll.
To do that, I added a DisplacementMap effect to the scroll line.
DisplacementMap Effect
effect: DisplacementMap { mapData: map
input:Reflection {
fraction: 0.75
topOffset: 0.0
topOpacity: 0.5
bottomOpacity: 0.0
}
}
And I created a FloatMap to make the sinusoidal effect
FloatMap
var widthScroll = letterWidth * 10; // 10 chars
var map = FloatMap { width: widthScroll height: letterHeight }
for (i:Integer in [0..<widthScroll]) {
var v = (Math.sin(i/35.0*Math.PI)-0.5)/30.0;
for (j:Integer in [0..<letterHeight]) {
map.setSamples(i, j, 0.0, v);
}
}
As you see in the code, the DisplacementMap effect take a FloatMap as parameter. And each individual entry in the FloatMap contains per-pixel offset information in the x and y direction.
For example if you have this image
My FloatMap contains offsets x and y to have
samedi 19 décembre 2009
Old School Scroll line
Normally this is a bitmap effect, but in JavaFx all is nodes…
So I use Nodes :) and this image (from http://forum.deltaforceteam.de/forum/viewtopic.php?f=3&t=127 )
The viewports variable is a sequence which contains for each character the portion of the image corresponding to it.
The line variable is a concatenation of the viewports of the letters to build the text shown in the screen.
And the timeline is used to scroll the text
I add a Reflection effect too :)
| Main.fx |
package scrolllinedemo; /* * Main.fx * * Created on 12 déc. 2009, 00:08:52 */ import javafx.stage.Stage; import javafx.scene.Scene; import javafx.geometry.Rectangle2D; import javafx.scene.image.ImageView; import javafx.scene.image.Image; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.scene.effect.Reflection; import javafx.scene.Group; import javafx.scene.shape.Rectangle; import javafx.scene.control.TextBox; import javafx.scene.control.Button; /** * @author Patrick */ def letterWidth = 32; def letterHeight = 32; var blankLine = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; var text = "Hello, this is my first old school scroll line demo. by Patrick ! "; var textFont = StringConverter.stringToFont(text); insert blankLine before textFont[0]; var textLength = sizeof(textFont)-1; insert blankLine into textFont; var textIncrement = 0; var font = Image { url: "{__DIR__}img/font.png" } def viewports = for (row in [0..5]) { for (col in [0..9]) { Rectangle2D{ minX: col * letterWidth, minY: row * letterHeight, height: letterWidth, width: letterHeight } } } var line = bind for (col in [0..10]) { //10 chars (320 = 32*10) ImageView { x: bind (col * letterWidth) -scrollX , y: 0, viewport: bind viewports[textFont[col+textIncrement]] image: font } } var scrollX =0; var t = Timeline { repeatCount: Timeline.INDEFINITE keyFrames : [ KeyFrame { time : 0s canSkip : true }, KeyFrame { time : 8ms canSkip : true action: function(): Void{ var tempX = scrollX+1; var tempTextIncrement = textIncrement; if (tempX>=32){ tempX = 0; if (textIncrement<textLength) then tempTextIncrement++ else tempTextIncrement = 0; } textIncrement = tempTextIncrement; scrollX = tempX; } } ] } t.play(); var tb:TextBox; Stage { title: "Application title" width: 335 height: 150 scene: Scene { content: [ Group { content:Group{ clip:Rectangle { width: 320 height: 64 } content: line } effect:Reflection { fraction: 0.75 topOffset: 0.0 topOpacity: 0.5 bottomOpacity: 0.0 } } tb = TextBox { text: "try to type your text here... and press on GO!" columns: 30 selectOnFocus: true translateY:70 } Button { text: "GO!" action: function() { var textFontTemp = StringConverter.stringToFont(tb.text); insert blankLine before textFontTemp[0]; textLength = sizeof(textFontTemp)-1; insert blankLine into textFontTemp; textFont = textFontTemp; textIncrement =0; } translateY:70 translateX:275 } ] } }download StringConverter.fx
dimanche 13 décembre 2009
Les jeux olympiques d’hiver de Vancouver choisissent JavaFX
J’entends dire ou des personnes me disent, ouais, JavaFx c’est bien mais il n’y a personne qui l’utilise, il n’y a pas de vraie référence, etc, etc …
C’est vrai que JavaFx est une technologie récente (la versions 1.0 n’est sortie que l’année dernière à cette même époque) et qu’il n’y a pas encore beaucoup de référence…
Mais cela commence à arriver, et cela commence avec les jeux olympiques d’hiver de Vancouver 2010 qui ont choisi JavaFX comme technologie de client riche !
On peut même déjà voir le résultat et essayer la première application disponible sur le site Vancouver2010 à l’adresse suivante : http://www.vancouver2010.com/olympic-medals/geo-view/
Cette application sert à montrer :
- les médailles qui ont été gagné par les différents pays durant les différentes éditions des jeux olympiques d’hiver
- quel athlète a gagné quelle médaille
- Et plein d'autres choses...
C’est plutôt pas mal et ca marche super bien sur mon Mac (Snow Leopard), mon Linux (Ubuntu 9.10) et Windows Vista et Seven.
jeudi 10 décembre 2009
Glassfish V3, NetBeans 6.8, JavaFX Composer Preview
GlassFish V3 et NetBeans 6.8 sont sorties aujourd’hui …