Created
June 29, 2011 23:01
-
-
Save hideaki-t/1055227 to your computer and use it in GitHub Desktop.
JavaFX 2.0 and Groovy
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
import javafx.animation.Interpolator | |
import javafx.animation.TranslateTransition | |
import javafx.application.Application | |
import javafx.event.Event | |
import javafx.event.EventHandler | |
import javafx.geometry.Pos | |
import javafx.scene.Group | |
import javafx.scene.Scene | |
import javafx.scene.control.Button | |
import javafx.scene.control.TextBox | |
import javafx.scene.layout.HBox | |
import javafx.scene.layout.VBox | |
import javafx.scene.web.WebEngine | |
import javafx.scene.web.WebView | |
import javafx.stage.Stage | |
import javafx.util.Duration | |
import javafx.scene.effect.Reflection | |
class CustomBrowser extends Application { | |
void start(Stage stage) { | |
def view = new WebView(new WebEngine("http://www.yahoo.co.jp/")) | |
view.with { | |
effect = new Reflection() | |
setPrefSize(800, 400) | |
translateX = 800 | |
} | |
view.engine.loadTask.onDone = new EventHandler() { | |
void handle(Event e) { | |
new TranslateTransition(new Duration(500)).with { | |
node = view | |
fromX = 800 | |
toX = 0 | |
interpolator = Interpolator.EASE_BOTH | |
play() | |
} | |
stage.title = view.engine.title | |
view.parent.lookup("#urlbox").text = view.engine.location | |
} | |
} | |
view.engine.loadTask.onStarted = new EventHandler() { | |
void handle(Event e) { | |
new TranslateTransition(new Duration(500)).with { | |
node = view | |
fromX = 0 | |
toX = -800 | |
play() | |
} | |
} | |
} | |
def hbox = new HBox(spacing: 10, alignment: Pos.CENTER) | |
hbox.children.addAll( | |
new TextBox(columns: 40, id: "urlbox"), | |
new Button( | |
text: "Load", | |
onAction: new EventHandler() { | |
void handle(Event t) { | |
view.engine.load(new URI(hbox.scene.lookup("#urlbox").getText()).toString()) | |
} | |
} | |
) | |
) | |
def vbox = new VBox(spacing: 10, layoutY: 10) | |
vbox.children.addAll(hbox, view) | |
stage.with { | |
title = "JavaFX + Groovyのテスト" | |
scene = new Scene( | |
new Group(vbox), 800, 600 | |
) | |
visible = true | |
} | |
} | |
static void main(args) { | |
Application.launch(CustomBrowser, args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment