org.minueto.window
Class MinuetoFrame

java.lang.Object
  extended by org.minueto.window.MinuetoFrame
All Implemented Interfaces:
MinuetoDrawingSurface, MinuetoWindow

public class MinuetoFrame
extends java.lang.Object
implements MinuetoWindow

The MinuetoPanel class allows you to create a window (not fullscreen). This window is your main drawing surface (your canvas). This class is a subclass of MinuetoWindow. As such, all the drawing functionnality is found in the super class.

When a MinuetoWindow is created, it is invisible. The setVisible method must be used toshow the window (make it visible).

The size of the MinuetoWindow must be given to the construtor. Once a MinuetoWindow is created, it cannot be resized. To display a MinuetoWindow of different size, the current window must be closed using the close method and a new MinuetoWindow must be created.

Minueto draws to the screen using a double-buffering strategy. In other words, there are two drawing surfaces : your window itself and an off screen surface. All your drawing occurs on the off screen surface. The content of the off screen buffer is drawn to the screen when the render method is invoked.

Since:
Minueto 0.4
See Also:
MinuetoWindow, MinuetoBaseWindow, MinuetoImage

Constructor Summary
MinuetoFrame(int width, int height, boolean border)
          Creates a MinuetoWindow of the specified size.
 
Method Summary
 void clear()
          Clears the contents of the Drawing Surface.
 void clear(MinuetoColor color)
          Erases the contents from the Drawing Surface.
 void close()
          Close the window and free any ressource still in use by the window.
 void draw(MinuetoImage image, int x, int y)
          Draw another MinuetoImage on this MinuetoDrawingSurface (thus compositing them).
 void drawLine(MinuetoColor color, int xStart, int yStart, int xStop, int yStop)
          Draw a line of the specified color from the start point to the end point.
 void exitOnClose(boolean value)
          By default, when a MinuetoWindow is closed by the operating system (click on the X in the top right corner for example), the whole application is closed.
 double getFrameRate()
          Returns the number of frame renders per second.
 int getHeight()
          Return the height of the image.
 int getPositionX()
          Returns the top-left X screen location of the MinuetoWindow drawing surface
 int getPositionY()
          Returns the top-left Y screen location of the MinuetoWindow drawing surface
 int getWidth()
          Return the width of the image.
 int getWindowHeight()
          Returns the height of the current window.
 int getWindowPositionX()
          Returns the current X position of this window on the desktop.
 int getWindowPositionY()
          Returns the current Y position of this window.
 int getWindowWidth()
          Returns the width of the current window.
 boolean isClosed()
          Returns if the MinuetoWindow is was closed.
 boolean isVisible()
          Returns if the MinuetoWindow is visible or not.
 void registerFocusHandler(MinuetoFocusHandler handler, MinuetoEventQueue queue)
          Assign a focus handler to the MinuetoWindow to process focus events.
 void registerKeyboardHandler(MinuetoKeyboardHandler handler, MinuetoEventQueue queue)
          Assign a keyboard handler to the MinuetoWindow to process keyboard input.
 void registerMouseHandler(MinuetoMouseHandler handler, MinuetoEventQueue queue)
          Assign a mouse handler to the MinuetoWindow to process mouse input.
 void registerMouseWheelHandler(MinuetoMouseWheelHandler handler, MinuetoEventQueue queue)
          Assign a mousewheel handler to the MinuetoWindow to process mouse wheel input.
 void registerWindowHandler(MinuetoWindowHandler handler, MinuetoEventQueue queue)
          Assign a window handler to the MinuetoWindow to process window input.
 void render()
          Draws the content of the backbuffer onto the window.
 void save(java.lang.String filename)
          Saves the content of the MinuetoWindow to a PNG file.
 void setCursorVisible(boolean visible)
          Shows or hides the mouse cursor.
 void setMaxFrameRate(double value)
          Caps the number of frames which can be rendered (display) per second.
 void setPixel(int x, int y, MinuetoColor color)
          Change the color of pxel at location X,y.
 void setTitle(java.lang.String title)
          Change the title of the window.
 void setVisible(boolean value)
          Shows or hides the MinuetoWindow.
 void setWindowPosition(int x, int y)
          Moves the window to the desired location.
 void unregisterFocusHandler(MinuetoFocusHandler handler, MinuetoEventQueue queue)
          Removes a focus handler from the MinuetoWindow.
 void unregisterKeyboardHandler(MinuetoKeyboardHandler handler, MinuetoEventQueue queue)
          Removes a keyboard handler from the MinuetoWindow.
 void unregisterMouseHandler(MinuetoMouseHandler handler, MinuetoEventQueue queue)
          Removes a mouse handler from the MinuetoWindow.
 void unregisterMouseWheelHandler(MinuetoMouseWheelHandler handler, MinuetoEventQueue queue)
          Removes a mouse wheel handler from the MinuetoWindow.
 void unregisterWindowHandler(MinuetoWindowHandler handler, MinuetoEventQueue queue)
          Removes a window handler from the MinuetoWindow.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.minueto.window.MinuetoWindow
getFrameRate, isVisible, registerFocusHandler, registerKeyboardHandler, registerMouseHandler, registerMouseWheelHandler, registerWindowHandler, render, setMaxFrameRate, unregisterFocusHandler, unregisterKeyboardHandler, unregisterMouseHandler, unregisterMouseWheelHandler, unregisterWindowHandler
 
Methods inherited from interface org.minueto.image.MinuetoDrawingSurface
clear, clear, draw, drawLine, getHeight, getWidth, save, setPixel
 

Constructor Detail

MinuetoFrame

public MinuetoFrame(int width,
                    int height,
                    boolean border)
Creates a MinuetoWindow of the specified size. The second parameter determines if the window should be bordeless or not.

Parameters:
width - int denoting the desired width of the window.
height - int denoting the desired height of the window.
border - boolean indicating if the window should be have borders or not.
Throws:
MinuetoZeroNegativeException - if the window size is invalid.
Method Detail

setVisible

public void setVisible(boolean value)
Description copied from interface: MinuetoWindow
Shows or hides the MinuetoWindow.

Specified by:
setVisible in interface MinuetoWindow
Parameters:
value - boolean denoting if the window should be visible or not.

close

public void close()
Description copied from interface: MinuetoWindow
Close the window and free any ressource still in use by the window. Once executed, this window can no longuer be used. Any further invocation of a method from this object will result in a MinuetoWindowInvalidStateException.

Specified by:
close in interface MinuetoWindow

setTitle

public void setTitle(java.lang.String title)
Description copied from interface: MinuetoWindow
Change the title of the window.

Specified by:
setTitle in interface MinuetoWindow
Parameters:
title - String identifying the desired title of the screen.

getWindowWidth

public int getWindowWidth()
Returns the width of the current window. Please note that the width returned is the actual width of the window, not the requested width. This is important to take into acccount because operating systems such as Window add a thin border around every window. To properly center a window, the actual width of the window must be known.

Returns:
int denoting the real width of the window.
Throws:
MinuetoWindowInvalidStateException - if this window is hidden (invisible) or has been closed.

getWindowHeight

public int getWindowHeight()
Returns the height of the current window. Please note that the height returned is the actual height of the window, not the requested height. This is important to take into acccount because operating systems such as Window add a thin border around every window. To properly center a window, the actual width of the window must be known.

Returns:
int denoting the real height of the window.
Throws:
MinuetoWindowInvalidStateException - if this window is hidden (invisible) or has been closed.

getWindowPositionX

public int getWindowPositionX()
Returns the current X position of this window on the desktop. A value of 0 is returned if the window is in fullscreen mode.


getWindowPositionY

public int getWindowPositionY()
Returns the current Y position of this window. A value of 0 is returned if the window is in fullscreen mode.


setWindowPosition

public void setWindowPosition(int x,
                              int y)
Moves the window to the desired location. This method is ignored if Minueto is fullscreen mode.

Parameters:
x - int denoting the X position where the window should be moved.
y - int denoting the Y position where the window should be moved.
Throws:
MinuetoWindowInvalidStateException - if this window is hidden (invisible) or has been closed.

exitOnClose

public void exitOnClose(boolean value)
By default, when a MinuetoWindow is closed by the operating system (click on the X in the top right corner for example), the whole application is closed. This method allows you to change this behavior.

Parameters:
value - boolean denoting if the whole application should be closed.

setCursorVisible

public void setCursorVisible(boolean visible)
Description copied from interface: MinuetoWindow
Shows or hides the mouse cursor.

Specified by:
setCursorVisible in interface MinuetoWindow
Parameters:
visible - boolean denoting if the window should be visible or not.

getPositionX

public int getPositionX()
Description copied from interface: MinuetoWindow
Returns the top-left X screen location of the MinuetoWindow drawing surface

Specified by:
getPositionX in interface MinuetoWindow
Returns:
int denoting the x position of the drawing surface

getPositionY

public int getPositionY()
Description copied from interface: MinuetoWindow
Returns the top-left Y screen location of the MinuetoWindow drawing surface

Specified by:
getPositionY in interface MinuetoWindow
Returns:
int denoting the y position of the drawing surface

isClosed

public boolean isClosed()
Description copied from interface: MinuetoWindow
Returns if the MinuetoWindow is was closed.

Specified by:
isClosed in interface MinuetoWindow
Returns:
boolean if Window was closed or not

draw

public void draw(MinuetoImage image,
                 int x,
                 int y)
Description copied from interface: MinuetoDrawingSurface
Draw another MinuetoImage on this MinuetoDrawingSurface (thus compositing them).

Specified by:
draw in interface MinuetoDrawingSurface
Parameters:
image - MinuetoImage that we will draw on our image.
x - int denoting where we should start drawing on the x axis.
y - int denothing where we should start drawing on the y axis.

drawLine

public void drawLine(MinuetoColor color,
                     int xStart,
                     int yStart,
                     int xStop,
                     int yStop)
Description copied from interface: MinuetoDrawingSurface
Draw a line of the specified color from the start point to the end point.

Specified by:
drawLine in interface MinuetoDrawingSurface
Parameters:
color - MinuetoColor denoting the color of the line.
xStart - int denoting the X value of the start point.
yStart - int denoting the Y value of the start point.
xStop - int denoting the X value of the end point.
yStop - int denoting the Y value of the end point.

render

public void render()
Description copied from interface: MinuetoWindow
Draws the content of the backbuffer onto the window. The content of the backbuffer is lost after this call.

Specified by:
render in interface MinuetoWindow

getWidth

public int getWidth()
Description copied from interface: MinuetoDrawingSurface
Return the width of the image.

Specified by:
getWidth in interface MinuetoDrawingSurface
Returns:
int denoting the width of the image.

getHeight

public int getHeight()
Description copied from interface: MinuetoDrawingSurface
Return the height of the image.

Specified by:
getHeight in interface MinuetoDrawingSurface
Returns:
int denoting the height of the image.

clear

public void clear()
Description copied from interface: MinuetoDrawingSurface
Clears the contents of the Drawing Surface. The color that remains depends on the JVM.

Specified by:
clear in interface MinuetoDrawingSurface

clear

public void clear(MinuetoColor color)
Description copied from interface: MinuetoDrawingSurface
Erases the contents from the Drawing Surface. The color of the cleared surface is specified as a parameter.

Specified by:
clear in interface MinuetoDrawingSurface
Parameters:
color - MinuetoColor of the cleared buffer.

getFrameRate

public double getFrameRate()
Description copied from interface: MinuetoWindow
Returns the number of frame renders per second. This is value is updated every 50 frames.

Specified by:
getFrameRate in interface MinuetoWindow
Returns:
int denoting the number of frames drawn per second.

setMaxFrameRate

public void setMaxFrameRate(double value)
Description copied from interface: MinuetoWindow
Caps the number of frames which can be rendered (display) per second. The efficienty of the cap depends on the accuracy of the system timer. Calling this method with a value of 0 will disable the cap.

Specified by:
setMaxFrameRate in interface MinuetoWindow
Parameters:
value - double denoting the desired number of frames to be displayed per second.

registerKeyboardHandler

public void registerKeyboardHandler(MinuetoKeyboardHandler handler,
                                    MinuetoEventQueue queue)
Description copied from interface: MinuetoWindow
Assign a keyboard handler to the MinuetoWindow to process keyboard input. An unlimited number of keyboard handlers can be registered with a window, but too many handlers may slow the application (because of the large number of events produced).

Specified by:
registerKeyboardHandler in interface MinuetoWindow
Parameters:
handler - MinuetoKeyboardHandler to register with the MinuetoEventQueue.
queue - MinuetoEventQueue that will store events..

registerMouseHandler

public void registerMouseHandler(MinuetoMouseHandler handler,
                                 MinuetoEventQueue queue)
Description copied from interface: MinuetoWindow
Assign a mouse handler to the MinuetoWindow to process mouse input. An unlimited number of mouse handlers can be registered with a window, but too many handlers may slow the application (because of the large number of events produced).

Specified by:
registerMouseHandler in interface MinuetoWindow
Parameters:
handler - MinuetoMouseHandler to register with the MinuetoWindow.
queue - MinuetoEventQueue that will store events.

registerWindowHandler

public void registerWindowHandler(MinuetoWindowHandler handler,
                                  MinuetoEventQueue queue)
Description copied from interface: MinuetoWindow
Assign a window handler to the MinuetoWindow to process window input. An unlimited number of window handlers can be registered with a window, but too many handlers may slow the application (because of the large number of events produced).

Specified by:
registerWindowHandler in interface MinuetoWindow
Parameters:
handler - MinuetoWindowHandler to register with the MinuetoWindow.
queue - MinuetoEventQueue that will store events.

registerFocusHandler

public void registerFocusHandler(MinuetoFocusHandler handler,
                                 MinuetoEventQueue queue)
Description copied from interface: MinuetoWindow
Assign a focus handler to the MinuetoWindow to process focus events. An unlimited number of window handlers can be registered with a window, but too many handlers may slow the application (because of the large number of events produced).

Specified by:
registerFocusHandler in interface MinuetoWindow
Parameters:
handler - MinuetoFocusHandler to register with the MinuetoWindow.
queue - MinuetoEventQueue that will store events.

registerMouseWheelHandler

public void registerMouseWheelHandler(MinuetoMouseWheelHandler handler,
                                      MinuetoEventQueue queue)
Description copied from interface: MinuetoWindow
Assign a mousewheel handler to the MinuetoWindow to process mouse wheel input. An unlimited number of mouse wheel handlers can be registered with a window, but too many handlers may slow the application (because of the large number of events produced).

Specified by:
registerMouseWheelHandler in interface MinuetoWindow
Parameters:
handler - MinuetoMouseWheelHandler to register with the MinuetoWindow.
queue - MinuetoEventQueue that will store events.

unregisterKeyboardHandler

public void unregisterKeyboardHandler(MinuetoKeyboardHandler handler,
                                      MinuetoEventQueue queue)
Description copied from interface: MinuetoWindow
Removes a keyboard handler from the MinuetoWindow. Note that both the correct handler and queue must be given to unregister the handler.

Specified by:
unregisterKeyboardHandler in interface MinuetoWindow
Parameters:
handler - MinuetoKeyboardHandler to unregister with the MinuetoWindow.
queue - MinuetoEventQueue that stored the events.

unregisterMouseHandler

public void unregisterMouseHandler(MinuetoMouseHandler handler,
                                   MinuetoEventQueue queue)
Description copied from interface: MinuetoWindow
Removes a mouse handler from the MinuetoWindow. Note that both the correct handler and queue must be given to unregister the handler.

Specified by:
unregisterMouseHandler in interface MinuetoWindow
Parameters:
handler - MinuetoMouseHandler to unregister with the MinuetoWindow.
queue - MinuetoEventQueue that stored the events.

unregisterWindowHandler

public void unregisterWindowHandler(MinuetoWindowHandler handler,
                                    MinuetoEventQueue queue)
Description copied from interface: MinuetoWindow
Removes a window handler from the MinuetoWindow. Note that both the correct handler and queue must be given to unregister the handler.

Specified by:
unregisterWindowHandler in interface MinuetoWindow
Parameters:
handler - MinuetoWindowHandler to unregister with the MinuetoWindow.
queue - MinuetoEventQueue that stored the events.

unregisterFocusHandler

public void unregisterFocusHandler(MinuetoFocusHandler handler,
                                   MinuetoEventQueue queue)
Description copied from interface: MinuetoWindow
Removes a focus handler from the MinuetoWindow. Note that both the correct handler and queue must be given to unregister the handler.

Specified by:
unregisterFocusHandler in interface MinuetoWindow
Parameters:
handler - MinuetoFocusHandler to unregister with the MinuetoWindow.
queue - MinuetoEventQueue that stored the events.

unregisterMouseWheelHandler

public void unregisterMouseWheelHandler(MinuetoMouseWheelHandler handler,
                                        MinuetoEventQueue queue)
Description copied from interface: MinuetoWindow
Removes a mouse wheel handler from the MinuetoWindow. Note that both the correct handler and queue must be given to unregister the handler.

Specified by:
unregisterMouseWheelHandler in interface MinuetoWindow
Parameters:
handler - MinuetoMouseWheelHandler to unregister with the MinuetoWindow.
queue - MinuetoEventQueue that stored the events.

isVisible

public boolean isVisible()
Description copied from interface: MinuetoWindow
Returns if the MinuetoWindow is visible or not.

Specified by:
isVisible in interface MinuetoWindow
Returns:
boolean if Window is visible or not

save

public void save(java.lang.String filename)
          throws MinuetoFileException
Saves the content of the MinuetoWindow to a PNG file. This operation is very slow since the content of the screen must be retrieved from the video(card) memory.

Specified by:
save in interface MinuetoDrawingSurface
Parameters:
filename - String indicating the name of the target PNG file.
Throws:
MinuetoFileException - if it cannot write the file.
MinuetoWindowInvalidStateException - if this window is hidden (invisible) or has been closed.
MinuetoFileException
Since:
1.1
See Also:
MinuetoDrawingSurface.save(java.lang.String)

setPixel

public void setPixel(int x,
                     int y,
                     MinuetoColor color)
Description copied from interface: MinuetoDrawingSurface
Change the color of pxel at location X,y.

This uses the drawLine function to be faster than a direct raw data setPxel, though it should be used with caution as it is still slower than drawing a completed image to the drawing surface.

Specified by:
setPixel in interface MinuetoDrawingSurface
Parameters:
x - int denoting which pxel on the X axis should be colored.
y - int denoting which pxel on the y axis should be colored.
color - MinuetoColor denoting the new color for pxel x,y.