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.
-
imagealign_InlineCenter
- The image appears at the current point,
and it is centered between the top and baseline of the line of
text.
-
imagealign_InlineDown
- The image appears at the current point, and the top edge is
aligned with the top of the line of text.
-
imagealign_InlineUp
- The image appears at the current point in the text, sticking up.
-
imagealign_MarginLeft
- The image appears in the left margin.
-
imagealign_MarginRight
- The image appears in the right margin,
and subsequent text will flow around it on the left.
-
winmethod_Above
- When splitting a window, the new window will be above the old one.
-
winmethod_Below
- When splitting a window, the new window will be below the old one.
-
winmethod_DirMask
- Mask for the left/right/above/below constants.
-
winmethod_DivisionMask
- Mask for the fixed/proportional constants.
-
winmethod_Fixed
- When splitting a window, the new window will be a fixed size.
-
winmethod_Left
- When splitting a window, the new window will be to the left of the old one.
-
winmethod_Proportional
- When splitting a window, the new window will be a proportion of the old window's size.
-
winmethod_Right
- When splitting a window, the new window will be to the right of the old one.
-
wintype_AllTypes
- Used to set / clear a style hint for all window types.
-
wintype_Blank
- Blank windows support neither input nor output.
-
wintype_Graphics
- A grid of colored pixels.
-
wintype_Pair
- Pair windows contain exactly two child windows.
-
wintype_TextBuffer
- Text buffer windows: A stream of text.
-
wintype_TextGrid
- Text grid windows: A grid of characters in a fixed-width font.
-
cancelCharEvent()
- This cancels a pending request for character input.
-
cancelHyperlinkEvent()
-
-
cancelLineEvent()
- Cancel a pending line event and ignore anything composed
so far.
-
cancelLineEvent(Event)
- Cancel a pending line event.
-
cancelMouseEvent()
- This cancels a pending event for mouse input.
-
clear()
- Erase the window.
-
close()
- Close a window, ignoring the count of characters written.
-
close(StreamResult)
- This closes a window.
-
eraseRect(int, int, long, long)
- Fill a rectangle with the window's background colour.
-
fillRect(int, int, int, long, long)
- Fill a rectangle with given colour.
-
finalize()
- If the Glk object is still in existence when this object is
garbage-collected, destroy it.
-
flowBreak()
- Break the stream of text around an image.
-
getArrangementKey()
- Returns the key window of a pair window.
-
getArrangementMethod()
- Returns the arrangement method of a pair window.
-
getArrangementSize()
- Returns the arrangement size of a pair window.
-
getEchoStream()
- Return this window's echo stream.
-
getHeight()
- Get the height of this window.
-
getParent()
- This returns the window which is the parent of this window.
-
getRoot()
- Get the root window.
-
getSibling()
- This returns the other child of this window's parent.
-
getStream()
- Return this window's output stream.
-
getType()
- This returns the window's type.
-
getWidth()
- Get the width of this window.
-
imageDraw(int, int, int)
- This draws the given image resource.
-
imageDrawScaled(int, int, int, long, long)
- This draws the given image resource, scaling it to a different size.
-
imageGetInfo(int, int[])
- Check if image exists and get its dimensions.
-
iterate(Window, Object[])
- Iterate over windows.
-
moveCursor(long, long)
- Set the text cursor position.
-
open(Window, int, long, int)
- Open a new window.
-
open(Window, int, long, int, Object)
- Open a new window.
-
requestCharEvent()
- Request character input from this window.
-
requestHyperlinkEvent()
-
-
requestLineEvent(String[], int)
- Request line input from this window.
-
requestMouseEvent()
- Request mouse input from this window.
-
setArrangement(int, long, Window)
- Change the constraints of an existing pair window.
-
setBackgroundColor(int)
- Set the background colour for this window.
-
setEchoStream(Stream)
- Set the echo stream for this window.
wintype_AllTypes
public static final int wintype_AllTypes
- Used to set / clear a style hint for all window types.
wintype_Pair
public static final int wintype_Pair
- Pair windows contain exactly two child windows.
wintype_Blank
public static final int wintype_Blank
- Blank windows support neither input nor output.
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.
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.
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.
winmethod_Left
public static final int winmethod_Left
- When splitting a window, the new window will be to the left of the old one.
winmethod_Right
public static final int winmethod_Right
- When splitting a window, the new window will be to the right of the old one.
winmethod_Above
public static final int winmethod_Above
- When splitting a window, the new window will be above the old one.
winmethod_Below
public static final int winmethod_Below
- When splitting a window, the new window will be below the old one.
winmethod_DirMask
public static final int winmethod_DirMask
- Mask for the left/right/above/below constants.
winmethod_Fixed
public static final int winmethod_Fixed
- When splitting a window, the new window will be a fixed size.
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.
winmethod_DivisionMask
public static final int winmethod_DivisionMask
- Mask for the fixed/proportional constants.
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.
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.
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.
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.
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.
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.
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
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:
- winmethod_Above, winmethod_Below, winmethod_Left, winmethod_Right:
The new window will be above, below, to the left, or to the right
of the old one which was split.
- winmethod_Fixed, winmethod_Proportional: The new window is a
fixed size, or a given proportion of the old window's size.
- 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.
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
close
public void close()
- Close a window, ignoring the count of characters written.
- See Also:
- close
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
getWidth
public long getWidth()
- Get the width of this window.
- Returns:
- The width of this window, using its measurement system.
getHeight
public long getHeight()
- Get the height of this window.
- Returns:
- The height of this window, using its measurement system.
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
getArrangementMethod
public int getArrangementMethod()
- Returns the arrangement method of a pair window.
getArrangementSize
public long getArrangementSize()
- Returns the arrangement size of a pair window.
getArrangementKey
public Window getArrangementKey()
- Returns the key window of a pair window.
iterate
public static Window iterate(Window w,
Object r[])
- Iterate over windows.
- See Also:
- iterate
getType
public int getType()
- This returns the window's type.
- See Also:
- wintype_Pair, wintype_Blank, wintype_TextBuffer, wintype_TextGrid, wintype_Graphics
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
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
clear
public void clear()
- Erase the window. The meaning of this depends on the window type.
- Text buffer: This may do any number of things, such as
delete all text in the window, or print enough blank lines to
scroll all text beyond visibility, or insert a page-break marker
which is treated specially by the display part of the library.
- Text grid: This will clear the window, filling all positions
with blanks. The window cursor is moved to the top left corner
(position 0,0).
- Graphics: Clears the entire window to its current background
color.
- Other window types: No effect.
It is illegal to erase a window which has line input pending.
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
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.
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
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.
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.
cancelLineEvent
public void cancelLineEvent()
- Cancel a pending line event and ignore anything composed
so far.
- See Also:
- cancelLineEvent
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.
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.
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.
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.
cancelMouseEvent
public void cancelMouseEvent()
- This cancels a pending event for mouse input.
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.
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.
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.
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.
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.
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
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.
requestHyperlinkEvent
public void requestHyperlinkEvent()
cancelHyperlinkEvent
public void cancelHyperlinkEvent()
All Packages Class Hierarchy This Package Previous Next Index