Mostrando entradas con la etiqueta posicion. Mostrar todas las entradas
Mostrando entradas con la etiqueta posicion. Mostrar todas las entradas

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í.

viernes, 6 de febrero de 2009

JavaFX: A Stage "controller" / Un "controlador" de Stage


Update: Stage Controller hosted on Google Code, includes documentation for using the class. Click Here for a Java Web Start example.



This class allows you to "attach" some automatic behaviors to your app window (Stage). For example, you can make the window to stick to the edges of the screen with a simple... stickyBorders:true ... or select the borders you want to make sticky... ie. stickyLeft:true

You can persist the position and/or size of the window (with a simple persist:true, persistPosition:true or persistSize:true). You can anchor the window to the borders too (ie. anchorBottom:true). Enforce minimum and maximum sizes or enforce a specific size for the window or keep it in the middle of the screen, etc.

It can trigger two events: onResize and onMove... so, your app can obtain it screen position and size at any moment (demo, handling events).

There are many options and combinations.

Enjoy it ;)

Actualización: Ahora el Controlador de Stage es capaz de mantener la posición y/o tamaño de la ventana de la aplicación entre sesiones.

Esta clase permite definir comportamientos automáticos para la ventana de tu aplicación. Por ejemplo, puedes hacer que la ventana se "pegue" a los bordes de la pantalla con un simple... stickyBorders:true ... o seleccionar los bordes que quieres que sean "pegajosos"... ej. stickyLeft:true

Puedes hacer que la aplicación recuerde su posición y/o tamaño entre sesiones de uso (con un simple persist:true, persistPosition:true o persistSize:true). Puedes "anclar" la ventana a los bordes también (ej. anchorBottom:true). Forzar tamaños mínimos y máximos o un tamaño específico para la ventana... o mantener la ventana en el centro de la pantalla.

También puede gatillar dos eventos: onResize (si cambia el tamaño de la ventana) y onMove (si cambia de posición la ventana en la pantalla)... de esa manera la aplicación puede saber -en todo momento- en que área de la pantalla está localizada o que tamaño tiene (demo, manejando los eventos).

Hay muchas opciones y combinaciones.

Ojalá sea útil ;)

How to use it / Cómo se usa...
/** Stage controller */
var cs = controlStage { //persistFile: "testStage.persist"
initialPosition:controlStage.RIGHT + controlStage.TOP, persist:true
checkMinWidth:true, minWidth:440, checkMinHeight:true, minHeight:270,
stickyBorders:true


onResize: function(e):Void {
println("resize to {e.width},{e.height} at {e.minX},{e.minY}");
}
onMove: function(e):Void {
println("moved to {e.minX},{e.minY} with {e.width},{e.height}")
};


};

Stage {
// bind Stage (window) to the controller
width: bind cs.width with inverse
height: bind cs.height with inverse
x: bind cs.x with inverse
y: bind cs.y with inverse


// on stage close, stores last position and size
onClose: function() { cs.persistStage() };

scene: Scene { ....





Descargar el proyecto Netbeans 6.5.... DOWNLOAD the Netbeans 6.5 project.... CLICK HERE