Created
November 13, 2011 16:15
-
-
Save ksky/1362274 to your computer and use it in GitHub Desktop.
Twitter and HTML5 content integration by GroovyFX
This file contains hidden or 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
@Grab('org.twitter4j:twitter4j:2.2.5') | |
@Grab('org.twitter4j:twitter4j-stream:2.2.5') | |
import twitter4j.* | |
import groovyx.javafx.* | |
import javafx.scene.control.* | |
import javafx.scene.media.* | |
import javafx.application.Platform | |
final HOTWORD = /(?i)groovy/ | |
def ball1 = new AudioClip("<URL to coin sound file(.mp3)>") | |
def ball10 = new AudioClip("<URL to 1up sound file(.mp3)>") | |
GroovyFX.start({ | |
def sg = new SceneGraphBuilder() | |
def stage = sg.stage(title: "Twitter Ball") { | |
scene(width: 1024, height: 768) { | |
vbox { | |
browser = webView(prefWidth: 1024, prefHeight: 568) | |
engine = browser.engine | |
scrollPane(prefViewportWidth:1024, prefViewportHeight:200, | |
hbarPolicy:"never") { | |
vpane = vbox() | |
} | |
} | |
} | |
} | |
engine.load("http://mrdoob.com/projects/chromeexperiments/ball_pool/") | |
stage.show() | |
def stream = new TwitterStreamFactory().instance | |
def listener = [ | |
onStatus: { st -> | |
def tweet = "$st.user.screenName: $st.text" | |
println tweet | |
boolean hottweet = (st.text =~ HOTWORD) | |
Platform.runLater({ | |
vpane.children.add(0, sg.hbox { | |
imageView { image(st.user.profileImageUrl) } | |
text(text: tweet, fill: (hottweet) ? red : black) | |
}) | |
((hottweet) ? ball10 : ball1).play() | |
engine.executeScript((hottweet) ? | |
"for(i=0;i<10;i++){createBall();}" : "createBall()") | |
} as Runnable) | |
}, | |
onException: { ex -> ex.printStackTrace() }, | |
// ] as UserStreamAdapter | |
] as StatusAdapter | |
stream.addListener(listener) | |
// stream.user() | |
def query = new FilterQuery() | |
query.track(["#jjfxug"] as String[]) | |
stream.filter(query) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment