All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.ifarchive.glk.Window

java.lang.Object
   |
   +----org.ifarchive.glk.OpaqueObject
           |
           +----org.ifarchive.glk.Window

public class Window
extends OpaqueObject
A wrapper for all types of Glk window. It might be an idea in the future to have separate subclasses for the separate window types. However, the way that window capabilities overlap (eg: both text buffer and text grid can request line events; text grid and graphics windows can request mouse events) makes it rather nasty to do without full multiple inheritance.


Variable Index

 o imagealign_InlineCenter
The image appears at the current point, and it is centered between the top and baseline of the line of text.
 o imagealign_InlineDown
The image appears at the current point, and the top edge is aligned with the top of the line of text.
 o imagealign_InlineUp
The image appears at the current point in the text, sticking up.
 o imagealign_MarginLeft
The image appears in the left margin.
 o imagealign_MarginRight
The image appears in the right margin, and subsequent text will flow around it on the left.
 o winmethod_Above
When splitting a window, the new window will be above the old one.
 o winmethod_Below
When splitting a window, the new window will be below the old one.
 o winmethod_DirMask
Mask for the left/right/above/below constants.
 o winmethod_DivisionMask
Mask for the fixed/proportional constants.
 o winmethod_Fixed
When splitting a window, the new window will be a fixed size.
 o winmethod_Left
When splitting a window, the new window will be to the left of the old one.
 o winmethod_Proportional
When splitting a window, the new window will be a proportion of the old window's size.
 o winmethod_Right
When splitting a window, the new window will be to the right of the old one.
 o wintype_AllTypes
Used to set / clear a style hint for all window types.
 o wintype_Blank
Blank windows support neither input nor output.
 o wintype_Graphics
A grid of colored pixels.
 o wintype_Pair
Pair windows contain exactly two child windows.
 o wintype_TextBuffer
Text buffer windows: A stream of text.
 o wintype_TextGrid
Text grid windows: A grid of characters in a fixed-width font.

Method Index

 o cancelCharEvent()
This cancels a pending request for character input.
 o cancelHyperlinkEvent()
 o cancelLineEvent()
Cancel a pending line event and ignore anything composed so far.
 o cancelLineEvent(Event)
Cancel a pending line event.
 o cancelMouseEvent()
This cancels a pending event for mouse input.
 o clear()
Erase the window.
 o close()
Close a window, ignoring the count of characters written.
 o close(StreamResult)
This closes a window.
 o eraseRect(int, int, long, long)
Fill a rectangle with the window's background colour.
 o fillRect(int, int, int, long, long)
Fill a rectangle with given colour.
 o finalize()
If the Glk object is still in existence when this object is garbage-collected, destroy it.
 o flowBreak()
Break the stream of text around an image.
 o getArrangementKey()
Returns the key window of a pair window.
 o getArrangementMethod()
Returns the arrangement method of a pair window.
 o getArrangementSize()
Returns the arrangement size of a pair window.
 o getEchoStream()
Return this window's echo stream.
 o getHeight()
Get the height of this window.
 o getParent()
This returns the window which is the parent of this window.
 o getRoot()
Get the root window.
 o getSibling()
This returns the other child of this window's parent.
 o getStream()
Return this window's output stream.
 o getType()
This returns the window's type.
 o getWidth()
Get the width of this window.
 o imageDraw(int, int, int)
This draws the given image resource.
 o imageDrawScaled(int, int, int, long, long)
This draws the given image resource, scaling it to a different size.
 o imageGetInfo(int, int[])
Check if image exists and get its dimensions.
 o iterate(Window, Object[])
Iterate over windows.
 o moveCursor(long, long)
Set the text cursor position.
 o open(Window, int, long, int)
Open a new window.
 o open(Window, int, long, int, Object)
Open a new window.
 o requestCharEvent()
Request character input from this window.
 o requestHyperlinkEvent()
 o requestLineEvent(String[], int)
Request line input from this window.
 o requestMouseEvent()
Request mouse input from this window.
 o setArrangement(int, long, Window)
Change the constraints of an existing pair window.
 o setBackgroundColor(int)
Set the background colour for this window.
 o setEchoStream(Stream)
Set the echo stream for this window.

Variables

 o wintype_AllTypes
 public static final int wintype_AllTypes
Used to set / clear a style hint for all window types.

 o wintype_Pair
 public static final int wintype_Pair
Pair windows contain exactly two child windows.

 o wintype_Blank
 public static final int wintype_Blank
Blank windows support neither input nor output.

 o wintype_TextBuffer
 public static final int wintype_TextBuffer
Text buffer windows: A stream of text. You can only print at the end of the stream, and input a line of text at the end of the stream.

 o wintype_TextGrid
 public static final int wintype_TextGrid
Text grid windows: A grid of characters in a fixed-width font. You can print anywhere in the grid.

 o wintype_Graphics
 public static final int wintype_Graphics
A grid of colored pixels. Graphics windows do not support text input or output, but there are image commands to draw in them.

 o winmethod_Left
 public static final int winmethod_Left
When splitting a window, the new window will be to the left of the old one.

 o winmethod_Right
 public static final int winmethod_Right
When splitting a window, the new window will be to the right of the old one.

 o winmethod_Above
 public static final int winmethod_Above
When splitting a window, the new window will be above the old one.

 o winmethod_Below
 public static final int winmethod_Below
When splitting a window, the new window will be below the old one.

 o winmethod_DirMask
 public static final int winmethod_DirMask
Mask for the left/right/above/below constants.

 o winmethod_Fixed
 public static final int winmethod_Fixed
When splitting a window, the new window will be a fixed size.

 o winmethod_Proportional
 public static final int winmethod_Proportional
When splitting a window, the new window will be a proportion of the old window's size.

 o winmethod_DivisionMask
 public static final int winmethod_DivisionMask
Mask for the fixed/proportional constants.

 o imagealign_InlineUp
 public static final int imagealign_InlineUp
The image appears at the current point in the text, sticking up. That is, the bottom edge of the image is aligned with the baseline of the line of text.

 o imagealign_InlineDown
 public static final int imagealign_InlineDown
The image appears at the current point, and the top edge is aligned with the top of the line of text.

 o imagealign_InlineCenter
 public static final int imagealign_InlineCenter
The image appears at the current point, and it is centered between the top and baseline of the line of text. If the image is taller than the line of text, it will stick up and down equally.

 o imagealign_MarginLeft
 public static final int imagealign_MarginLeft
The image appears in the left margin. Subsequent text will be displayed to the right of the image, and will flow around it -- that is, it will be left-indented for as many lines as it takes to pass the image.

 o imagealign_MarginRight
 public static final int imagealign_MarginRight
The image appears in the right margin, and subsequent text will flow around it on the left.

Methods

 o getRoot
 public static Window getRoot()
Get the root window. The root window is the one which covers the entire screen area, with all the other windows inside it.

Returns:
The root window.
 o open
 public static Window open(Window split,
                           int method,
                           long size,
                           int wintype)
Open a new window.

Parameters:
split - The window to split, null if you are creating the root window.
method - The method used to split the existing window.
size - The size of the split.
wintype - The type of window to create.
Returns:
The newly-created Window, or null if one could not be created.
See Also:
open
 o open
 public static Window open(Window split,
                           int method,
                           long size,
                           int wintype,
                           Object jrock)
Open a new window.

If there are no windows, the first three arguments are meaningless. split must be null, and method and size are ignored.

If any windows exist, new windows must be created by splitting existing ones. split is the window you want to split; this must not be null. method is a mask of constants to specify the direction and the split method. size is the size of the split.

The method constants are:

Parameters:
split - The window to split, null if you are creating the root window.
method - The method used to split the existing window.
size - The size of the split.
wintype - The type of window to create.
rock - The rock for this window.
Returns:
The newly-created Window, or null if one could not be created.
 o finalize
 protected void finalize()
If the Glk object is still in existence when this object is garbage-collected, destroy it.

Overrides:
finalize in class OpaqueObject
 o close
 public void close()
Close a window, ignoring the count of characters written.

See Also:
close
 o close
 public void close(StreamResult r)
This closes a window.

It is legal to close all your windows, or to close the root window (which does the same thing.)

The result argument is filled with the output character count of the window stream.

Parameters:
r - will be populated with the number of characters output to the window stream.
See Also:
StreamResult
 o getWidth
 public long getWidth()
Get the width of this window.

Returns:
The width of this window, using its measurement system.
 o getHeight
 public long getHeight()
Get the height of this window.

Returns:
The height of this window, using its measurement system.
 o setArrangement
 public void setArrangement(int method,
                            long size,
                            Window key)
Change the constraints of an existing pair window. If you do change the key window of a pair window, the new key window must be a descendant of that pair window.

Parameters:
key - The key window for the pair, or null not to change it.
method - The split method to be used
size - The size for the key window.
See Also:
open
 o getArrangementMethod
 public int getArrangementMethod()
Returns the arrangement method of a pair window.

 o getArrangementSize
 public long getArrangementSize()
Returns the arrangement size of a pair window.

 o getArrangementKey
 public Window getArrangementKey()
Returns the key window of a pair window.

 o iterate
 public static Window iterate(Window w,
                              Object r[])
Iterate over windows.

See Also:
iterate
 o getType
 public int getType()
This returns the window's type.

See Also:
wintype_Pair, wintype_Blank, wintype_TextBuffer, wintype_TextGrid, wintype_Graphics
 o getParent
 public Window getParent()
This returns the window which is the parent of this window. If this is the root window, this returns null, since the root window has no parent. The parent of every window is a pair window; other window types are always childless.

Returns:
This window's parent
 o getSibling
 public Window getSibling()
This returns the other child of this window's parent. If this is the root window, getSibling() returns NULL.

Returns:
This window's sibling
 o clear
 public void clear()
Erase the window. The meaning of this depends on the window type.

It is illegal to erase a window which has line input pending.

 o moveCursor
 public void moveCursor(long x,
                        long y)
Set the text cursor position. This is only effective in text grid windows.

If you move the cursor right past the end of a line, it wraps; the next character which is printed will appear at the beginning of the next line.

If you move the cursor below the last line, or when the cursor reaches the end of the last line, it goes "off the screen" and further output has no effect. You must call moveCursor() or clear() to move the cursor back into the visible region.

Parameters:
x - The column to move to
y - The row to move to
See Also:
clear
 o getStream
 public Stream getStream()
Return this window's output stream.

Every window has an output stream associated with it. This is created automatically, with FileRef.filemode_Write, when you open the window.

A window stream cannot be closed with Stream.close(). It is closed automatically when you close its window with Window.close().

Only printable characters (including newline) may be printed to a window stream.

Returns:
This window's output stream.
 o getEchoStream
 public Stream getEchoStream()
Return this window's echo stream.

Returns:
This window's echo stream, or null if there is none set.
See Also:
setEchoStream
 o setEchoStream
 public void setEchoStream(Stream s)
Set the echo stream for this window.

Every window has an associated window stream; you print to the window by printing to this stream. However, it is possible to attach a second stream to a window. Any text printed to the window is also echoed to this second stream, which is called the window's "echo stream."

Effectively, any call to putChar() (or the other output commands) which is directed to the window's window stream, is replicated to the window's echo stream. This also goes for the style commands such as setStyle().

Note that the echoing is one-way. You can still print text directly to the echo stream, and it will go wherever the stream is bound, but it does not back up and appear in the window.

It is illegal to set a window's echo stream to be its own window stream. That would create an infinite loop, and is nearly certain to crash the Glk library. It is similarly illegal to create a longer loop (two or more windows echoing to each other.)

Parameters:
s - The echo stream. Pass null to stop this window echoing.
 o requestLineEvent
 public void requestLineEvent(String input[],
                              int maxLen)
Request line input from this window.

A window cannot have requests for both character and line input at the same time. It is illegal to call requestLineEvent() if the window already has a pending request for either character or line input.

If a window has a pending request for line input, and the player hits enter in that window (or whatever action is appropriate to enter his input), Glk.select() will return an event whose type is Event.evtype_LineInput. Once this happens, the request is complete; it is no longer pending. You must call requestLineEvent() if you want another line of text from that window.

In the event structure, win tells what window the event came from. val1 tells how many characters were entered. val2 will be 0. The characters themselves are stored in the string passed to the original requestLineEvent() call.

On entry, any text in input[0] will be displayed as if the player had typed it. When the input is completed (either by a line buffer input event, or by cancelLineEvent(), input[0] will contain the text typed.

It is illegal to print anything to a window which has line input pending.

Parameters:
input - Initial text to display / result string.
maxLen - The maximum length of input that will be accepted.
 o cancelLineEvent
 public void cancelLineEvent()
Cancel a pending line event and ignore anything composed so far.

See Also:
cancelLineEvent
 o cancelLineEvent
 public void cancelLineEvent(Event e)
Cancel a pending line event.

This cancels a pending request for line input. The event pointed to by the event argument will be filled in as if the player had hit enter, and the input composed so far will be stored in the string passed to requestLineEvent().

For convenience, it is legal to call cancelLineEvent() even if there is no line input request on that window. The event type will be set to Event.evtype_None in this case.

 o requestCharEvent
 public void requestCharEvent()
Request character input from this window.

A window cannot have requests for both character and line input at the same time. It is illegal to call requestCharEvent() if the window already has a pending request for either character or line input.

If a window has a pending request for character input, and the player hits a key in that window, Glk.select() will return an event whose type is Event.evtype_CharInput. Once this happens, the request is complete; it is no longer pending. You must call requestCharEvent() if you want another character from that window.

In the event structure, win tells what window the event came from. val1 tells what character was entered; this will be a code from 0 to 255, or a special keycode. val2 will be 0.

 o requestMouseEvent
 public void requestMouseEvent()
Request mouse input from this window.

If the player clicks in a window which has a mouse input event pending, Glk.select() will return an event whose type is Event.evtype_MouseInput. Again, once this happens, the request is complete, and you must request another if you want further mouse input.

In the event structure, win tells what window the event came from.

In a text grid window, the val1 and val2 fields are the x and y coordinates of the character that was clicked on. The top leftmost character is considered to be (0,0).

In a graphics window, they are the x and y coordinates of the pixel that was clicked on. Again, the top left corner of the window is (0,0).

You can test whether mouse input is supported with the gestalt_MouseInput selector.

res = Glk.gestalt(Glk.gestalt_MouseInput, windowtype);

This will return TRUE (1) if windows of the given type support mouse input. If this returns FALSE (0), it is still legal to call requestMouseEvent(), but it will have no effect, and you will never get mouse events.

 o cancelCharEvent
 public void cancelCharEvent()
This cancels a pending request for character input. For convenience, it is legal to call cancelCharEvent() even if there is no character input request on that window. Glk will ignore the call in this case.

 o cancelMouseEvent
 public void cancelMouseEvent()
This cancels a pending event for mouse input.

 o imageDraw
 public boolean imageDraw(int image,
                          int val1,
                          int val2)
This draws the given image resource.

In a text buffer window, val1 should be the alignment (imagealign_*) and val2 should be 0.

In a graphics window, val1 and val2 are the coordinates at which to draw the image.

Parameters:
image - The number of the image resource to draw.
val1 - The X-coordinate or alignment of the image.
val2 - The Y-coordinate of the image, or 0.
Returns:
true if the image was drawn, otherwise false.
 o imageDrawScaled
 public boolean imageDrawScaled(int image,
                                int val1,
                                int val2,
                                long w,
                                long h)
This draws the given image resource, scaling it to a different size.

In a text buffer window, val1 should be the alignment (imagealign_*) and val2 should be 0.

In a graphics window, val1 and val2 are the coordinates at which to draw the image.

Parameters:
image - The number of the image resource to draw.
val1 - The X-coordinate or alignment of the image.
val2 - The Y-coordinate of the image, or 0.
w - The width that the image should appear.
h - The width that the image should appear.
Returns:
true if the image was drawn, otherwise false.
 o imageGetInfo
 public static boolean imageGetInfo(int image,
                                    int res[])
Check if image exists and get its dimensions.

Parameters:
image - The number of the image resource to check.
res - If not null, an array of two integers. On return these will hold the width and height of the image in pixels.
Returns:
true if the image exists, else false.
 o flowBreak
 public void flowBreak()
Break the stream of text around an image. If the current point in the text is indented around a margin-aligned image, this acts like the correct number of newlines to start a new line below the image. (If there are several margin-aligned images, it goes below all of them.) If the current point is not beside a margin-aligned image, this call has no effect.

 o eraseRect
 public void eraseRect(int left,
                       int top,
                       long w,
                       long h)
Fill a rectangle with the window's background colour. It is legitimate for part of the rectangle to fall outside the window. If width or height is zero, nothing is drawn.

This function can only be used in graphics windows.

Parameters:
left - The left-hand edge of the rectangle.
top - The top row of the rectangle.
w - The width of the rectangle.
h - The height of the rectangle.
 o fillRect
 public void fillRect(int col,
                      int left,
                      int top,
                      long w,
                      long h)
Fill a rectangle with given colour. It is legitimate for part of the rectangle to fall outside the window. If width or height is zero, nothing is drawn.

This function can only be used in graphics windows.

The colour is defined as described in setBackgroundColor().

Parameters:
col - The colour to use.
left - The left-hand edge of the rectangle.
top - The top row of the rectangle.
w - The width of the rectangle.
h - The height of the rectangle.
See Also:
setBackgroundColor
 o setBackgroundColor
 public void setBackgroundColor(int col)
Set the background colour for this window.

This function may only be used with graphics windows.

Colors are encoded in a 32-bit value: the top 8 bits must be zero, the next 8 bits are the red value, the next 8 bits are the green value, and the bottom 8 bits are the blue value. Color values range from 0 to 255.

Parameters:
col - The colour to use as background.
 o requestHyperlinkEvent
 public void requestHyperlinkEvent()
 o cancelHyperlinkEvent
 public void cancelHyperlinkEvent()

All Packages  Class Hierarchy  This Package  Previous  Next  Index