<%@ jet package="cruise.ui.jfx.templates.impl" imports="java.util.* cruise.model.abstractObjects.BackingObject cruise.umple.compiler.* cruise.ui.jfx.* " class="Application" skeleton="../jfx.skeleton" %> <% String preffix=JFXProvider.properties.getProperty(cruise.model.Constants.PACKAGE_PREFIX);%> package main; /* * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ import javafx.scene.Cursor; import javafx.scene.CustomNode; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.control.Label; import javafx.scene.input.MouseEvent; import javafx.scene.layout.Resizable; import javafx.scene.paint.Color; import javafx.scene.paint.Paint; import javafx.scene.shape.Circle; import javafx.scene.shape.Rectangle; import javafx.scene.text.Font; import javafx.stage.AppletStageExtension; import javafx.stage.Stage; import javafx.stage.StageStyle.TRANSPARENT; import javafx.util.Math.max; import javafx.scene.Group; import javafx.scene.text.FontWeight; import javafx.scene.shape.Rectangle; import javafx.scene.paint.Color; import javafx.scene.paint.LinearGradient; import javafx.scene.paint.Stop; import javafx.scene.layout.VBox; import <%=preffix%>.components.Button; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.text.Text; import javafx.scene.text.Font; import <%=preffix%>.components.Menu; import javafx.ext.swing.SwingComponent; import javafx.scene.image.Image; public def imageGlass= Image {url: "{__DIR__}images/glass.png"}; public def imageKey= Image {url: "{__DIR__}images/key.png"}; public def imageReload= Image {url: "{__DIR__}images/reload.png"}; public class Application { public var foreground: Paint = Color.WHITE; public var background: Paint = Color.ORANGE; public var size = 16.0; public var minWidth = 160.0; public var minHeight = 120.0; public var title: String; public var header: Node; public var content: Node; var applet = __PROFILE__ == "browser"; def mobile = __PROFILE__ == "mobile"; var hover: Boolean; def show: Boolean = bind not mobile and not stage.fullScreen; def resizable = bind show and not applet; def draggable = applet and AppletStageExtension.appletDragSupported; def round: Number = bind if (resizable) size else 0; def border: Number = bind if (show) size / 4 else 0; def width: Number = bind stage.scene.width - border - border on replace { def panel = content as Resizable; panel.width = width } def label = Label { textFill: bind foreground graphic: bind header width: bind width - size * 4 text: bind if (header != null) null else title font: bind Font { name: "Arial Bold" size: if (mobile) size else size * 2 } } def offset = bind max(size, label.height) + size / 2; def height: Number = bind stage.scene.height - border - border - offset on replace { def panel = content as Resizable; panel.height = height } def stage: Stage = Stage { title: bind title style: TRANSPARENT opacity: bind if (stage.containsFocus) 1.0 else 0.5 extensions: if (mobile) null else AppletStageExtension { useDefaultClose: false shouldDragStart: function(event) { return hover and event.primaryButtonDown } onDragStarted: function() { applet = false } onAppletRestored: function() { applet = true } } scene: Scene { fill: null width: 650 height: 600 content: [ Rectangle { var sX: Number; var sY: Number; var wX: Number; var wY: Number; var wW: Number; var wH: Number; var top: Boolean; var left: Boolean; var right: Boolean; var bottom: Boolean; var cursor: Cursor; cursor: bind cursor blocksMouse: true width: bind stage.scene.width height: bind stage.scene.height + size arcWidth: bind round * 1.5 arcHeight: bind round * 1.5 fill: bind background def update = function(event: MouseEvent): Void { if (not event.primaryButtonDown) { if (resizable) { top = event.y < size; left = event.x < size; right = event.x > stage.scene.width - size; bottom = event.y > stage.scene.height - size; if (top and left) { cursor = Cursor.NW_RESIZE } else if (top and right) { cursor = Cursor.NE_RESIZE } else if (bottom and left) { cursor = Cursor.SW_RESIZE } else if (bottom and right) { cursor = Cursor.SE_RESIZE } else if (top) { cursor = Cursor.N_RESIZE } else if (left) { cursor = Cursor.W_RESIZE } else if (right) { cursor = Cursor.E_RESIZE } else if (bottom) { cursor = Cursor.S_RESIZE } else { cursor = null } } else { cursor = null } } } onMouseDragged: function(event) { if (top) { def dY = event.screenY - sY; stage.y = wY + dY; stage.height = max(minHeight, wH - dY); } else if (bottom) { stage.height = max(minHeight, wH + event.screenY - sY); } if (left) { def dX = event.screenX - sX; stage.x = wX + dX; stage.width = max(minWidth, wW - dX); } else if (right) { stage.width = max(minWidth, wW + event.screenX - sX); } } onMousePressed: function(event) { sX = event.screenX; sY = event.screenY; wX = stage.x; wY = stage.y; wW = stage.width; wH = stage.height; } onMouseReleased: update onMouseEntered: update onMouseExited: update onMouseMoved: update } Rectangle { cursor: Cursor.MOVE blocksMouse: true visible: bind show and (not applet or draggable) x: bind border y: bind border width: bind width height: bind offset arcWidth: bind round arcHeight: bind round fill: bind foreground opacity: 0.1 onMouseEntered: function(event) { hover = true } onMouseExited: function(event) { hover = false } onMouseDragged: function(event) { stage.x += event.dragX; stage.y += event.dragY; } } Group { translateX: bind border + size / 4 translateY: bind border + size / 4 content: bind label } Group { cursor: Cursor.HAND blocksMouse: true visible: bind not applet translateX: bind stage.scene.width - border translateY: bind border + size * 0.75 content: [ Button { foreground: foreground background: background rotate: 45 translateX: bind - size * 0.75 onMouseClicked: function(event) { stage.close() } } Button { foreground: foreground background: background rotate: 90 visible: not mobile translateX: bind - size * 2 onMouseClicked: function(event) { stage.fullScreen = not stage.fullScreen; } } Button { foreground: foreground background: background visible: not mobile translateX: bind - size * 3.25 onMouseClicked: function(event) { if (stage.fullScreen) { stage.fullScreen = false } stage.iconified = true } } ] } Group { blocksMouse: true translateX: bind border translateY: bind border + offset content: bind content } ] } } }