Created
December 6, 2008 09:39
-
-
Save segphault/32851 to your computer and use it in GitHub Desktop.
A Twitter search tool written in JavaFX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Main.fx | |
* | |
* Created on Dec 5, 2008, 11:27:35 AM | |
*/ | |
package testapplication; | |
import javafx.scene.*; | |
import javafx.scene.image.*; | |
import javafx.scene.layout.*; | |
import javafx.scene.effect.*; | |
import javafx.stage.*; | |
import javafx.ext.swing.SwingButton; | |
import javafx.scene.text.*; | |
import javafx.scene.shape.*; | |
import javafx.scene.paint.*; | |
import javafx.async.RemoteTextDocument; | |
import org.json.JSONObject; | |
import testapplication.Message; | |
/** | |
* @author Ryan Paul | |
*/ | |
var vb:VBox; | |
Stage { | |
title: "Application title" | |
width: 430 height: 500 | |
onClose: function() { | |
java.lang.System.exit(0); | |
} | |
scene: Scene {content: [ | |
ImageView { image: Image { url: "{__DIR__}fyre.png" } }, | |
vb = VBox { | |
spacing: 5 | |
content: [ | |
Group {content: [ | |
Rectangle { width: 430 height: 40 fill: Color.rgb(114, 159, 207) } | |
Rectangle { | |
width: 430 height: 40 | |
fill: LinearGradient { | |
startX: 0 startY: 0 endX: 0 endY: 1 | |
stops: [ | |
Stop { offset: 0.0 color: Color { opacity: 0.10 }}, | |
Stop { offset: 0.05 color: Color { red:1 green:1 blue:1 opacity: 0.45 }} | |
Stop { offset: 0.2 color: Color { red:1 green:1 blue:1 opacity: 0.50 }} | |
Stop { offset: 0.4 color: Color { red:1 green:1 blue:1 opacity: 0.25 }} | |
Stop { offset: 0.6 color: Color { red:1 green:1 blue:1 opacity: 0.0 }} | |
Stop { offset: 0.9 color: Color { red:1 green:1 blue:1 opacity: 0.10 }} | |
Stop { offset: 1.0 color: Color { red:1 green:1 blue:1 opacity: 0.50 }} | |
]} | |
} | |
Text { | |
content: "Twitter Watch" | |
x: 10 y: 25 font: Font.font("Calibri", FontWeight.BOLD, 24) fill: Color.WHITE; | |
effect: DropShadow { offsetX: 1 offsetY: 1 radius: 4 color: Color.BLACK } | |
} | |
]} | |
] | |
} | |
]} | |
} | |
function addMessages(query, box:VBox, count) { | |
var twitterData:RemoteTextDocument = RemoteTextDocument { | |
url: "http://search.twitter.com/search.json?q={query}&rpp={count}" | |
onDone: function (finished) { | |
var data = new JSONObject(twitterData.document).getJSONArray("results"); | |
for (i in [0..data.length()]) { | |
var j = data.getJSONObject(i); | |
insert Message { | |
username: j.getString("from_user") | |
text: j.getString("text"); | |
picture: j.getString("profile_image_url") | |
} into box.content; | |
} | |
} | |
} | |
} | |
addMessages("query string", vb, 5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Test.fx | |
* | |
* Created on Dec 5, 2008, 11:44:39 AM | |
*/ | |
package testapplication; | |
import javafx.scene.*; | |
import javafx.scene.effect.*; | |
import javafx.scene.text.*; | |
import javafx.scene.image.*; | |
import javafx.scene.paint.*; | |
import javafx.scene.layout.*; | |
import javafx.scene.shape.*; | |
import javafx.scene.control.*; | |
import javafx.stage.*; | |
/** | |
* @author Ryan Paul | |
*/ | |
public class Message extends CustomNode { | |
public var username:String; | |
public var text:String; | |
public var picture:String; | |
public override function create(): Node { | |
return Group { | |
content: [ | |
Rectangle { | |
opacity: 0.85 | |
arcHeight: 20 arcWidth: 20 | |
width: 400 height: 90 x: 10 | |
fill: LinearGradient { | |
startX: 0 startY: 0 endX: 0 endY: 1 | |
stops: [ | |
Stop { offset: 0.1 color: Color.rgb(114, 159, 207) }, | |
Stop { offset: 1.0 color: Color.rgb(65, 92, 120) } | |
] | |
} | |
}, | |
ImageView { | |
image: Image { url: picture } | |
x: 20 y: 10 effect: Reflection { topOffset: 0 fraction: 0.5 } | |
}, | |
VBox { | |
spacing: 5 | |
content: [ | |
Text { | |
content: username | |
x: 80 y: 20 font: Font.font("Calibri", FontWeight.BOLD, 18) fill: Color.WHITE; | |
effect: DropShadow { offsetX: 1 offsetY: 1 radius: 4 color: Color.BLACK } | |
}, | |
Text { | |
content: text | |
x: 80 y: 10 font: Font.font("Calibri", 14) fill: Color.WHITE; | |
effect: DropShadow { offsetX: 1 offsetY: 1 radius: 1 color: Color.BLACK } | |
wrappingWidth: 320 | |
} | |
] | |
} | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment