jueves, 12 de febrero de 2009

JavaFX: Stage "controller" demo - Demo "controlador" de Stage


This small code demostrates how easy is to handle the onResize and onMove events implemented by the Stage controller (Stage Controller).

Este pequeño código demuestra lo fácil que es manejar los eventos onResize y onMove implementados por el controlador de Stage (Controlador de Stage)



Here's the code / Aquí está el código:

var img = Image { url: "{__DIR__}myimage.jpg" };
var rect:Rectangle;
var sw:Integer;
var sh:Integer;

var cs = controlStage {
timeToCallFunctions:0.001s
timeToCheckPosSize:0.001s
initialPosition:controlStage.CENTER, persist:true
checkMinWidth:true, minWidth:270,
checkMinHeight:true, minHeight:270,
stickyBorders:true
onResize: function(e) { clip(e) }
onMove: function(e) { clip(e) }
};

// screen resolution
sw = cs.maxScrWidth;
sh = cs.maxScrHeight;

function clip(r:Rectangle2D) {
rect = Rectangle {
x: r.minX - (sw - img.width) / 2
y: r.minY - (sh - img.height) /2
width: r.width, height: r.height
}
};

Stage {
width: bind cs.width with inverse
height: bind cs.height with inverse
x: bind cs.x with inverse
y: bind cs.y with inverse
onClose: function() { cs.persistStage() };

scene: Scene { content:
ImageView {
translateX: bind -rect.x
translateY: bind -rect.y
image: img
clip: rect
}
}
};



Download the Netbeans 6.5 project, here. Descarga el proyecto Netbeans 6.5, aquí.

No hay comentarios: