/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * Copyright 2009 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * * Neither the name of Sun Microsystems nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import javafx.animation.Timeline; import javafx.scene.Group; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.paint.Color; import javafx.scene.Scene; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; def playNormal = Image { url: "{__DIR__}play_onMouseExited.png"}; def playHover = Image { url: "{__DIR__}play_onMouseEntered.png"}; def playPressed = Image { url: "{__DIR__}play_onMousePressed.png"}; def stopNormal = Image { url: "{__DIR__}stop_onMouseExited.png"}; def stopHover = Image { url: "{__DIR__}stop_onMouseEntered.png"}; def stopPressed = Image { url: "{__DIR__}stop_onMousePressed.png"}; var image = playNormal; var mode = true; var button = ImageView {image: bind image} var X: Number; var Y: Number; var tooltip = Text { content: bind if (mode) "Play Button" else "Stop Button" translateX: bind button.translateX translateY: bind button.translateY + 80 opacity: 0.0 font: Font { size: 12 name: "Tahoma" } fill: Color.BLACK }; def appear = Timeline { keyFrames: [ at(0s) {tooltip.opacity => 0.0}, at(0.5s) {tooltip.opacity => 1.0} ] } Stage { title: "Play Button" scene: Scene { fill: Color.WHITE width: 300 height: 240 content: Group { content: [ button, tooltip ] onMouseEntered: function(event) { image = if (mode){ playHover; } else { stopHover } appear.rate = 1; appear.play(); } onMouseExited: function(event) { image = if (mode){ playNormal; } else { stopNormal } appear.rate = -1; appear.play(); } onMousePressed: function(event) { X = event.sceneX - event.node.translateX; Y = event.sceneY - event.node.translateY; image = if (mode){ playPressed; } else { stopPressed; } } onMouseReleased: function(event) { if (mode){ image = stopHover; mode = false; } else { image = playHover; mode = true; } } onMouseDragged: function(event) { if (event.sceneX - X <0) { event.node.translateX = 0; } else { if (event.sceneX - X > 300 - image.width){ event.node.translateX = 300 - image.width; } else { event.node.translateX = event.sceneX - X; } } if (event.sceneY - Y <0) { event.node.translateY = 0; } else {if (event.sceneY - Y > 240 - image.height){ event.node.translateY = 240 - image.height; } else{ event.node.translateY = event.sceneY - Y; } } } } } }