|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Window
java.awt.Frame
javax.swing.JFrame
psychWithJava.FullScreen
public class FullScreen
FullScreen
class provides methods to display visual stimuli
and interact with the observer in full screen exclusive mode (FSEM).
FullScreen
is capable of chosing the best available mode and
strategy on a particular software (OS) and hardware. By default user does not
have to change any of these strategies. However it provides
methods for expert users who wish to modify those strategies. Needs Java
SE version 5.0 or higher.
Methods provided include: displayImage()
to display images,
displayText()
to display text messages, and
getKeyPressed()
to get observer's keyboard responses. Because it
is inherited from the Java core class JFrame
, all its methods
are also available, such as setForeground()
.
Some demos using the FullScreen class can be found here.
This implementation of this class is explained in great detail in The Guide to psychophysics programming with Java.
FullScreen
class utilizes the
Full screen exclusive mode (FSEM), a feature of Java (after J2SE 1.4)
that allows
programmers to suspend the windowing system of the underlying OS, and
directly access the video card and draw on the screen. If exclusive full
screen is not supported a regular window is positioned at (0,0) and resized
to fit the whole screen to mimic full screen exclusive mode. Whether in full
screen exclusive mode or not, FullScreen
usues active
rendering as opposed to passive rendering - in passive rendering the
underlying OS may intervene and send directives to the rendering program,
whereas in active rendering the program itself is responsible of drawing and
re-drawing the contents on the screen without the OS's directives.
For more details, developers can see JSE API definitions at http://java.sun.com. See also Full-Screen Exclusive Mode API tutorial, Programmer's Guide to the Java 2D API, and Painting in AWT and Swing, and http://java.sun.com/j2se/1.5.0/docs/guide/2d/new_features.html.
Note: Java 2D API (and rest of the entire platform) is improved with JSE 5.0, and FullScreen needs at least version 5.0. This version is available on all platforms (Linux, Mac OS X (only Tiger), MS Windows).
Note: Real full screen exclusive mode is not supported on Linux in Java
5.0, but it simulates the exclusive mode. However this situation is fixed and
the new version of Java (1.6 Mustang) has the exclusive mode for Linux. FSEM
on Linux works fine now especially with opengl pipeline enabled.
To enable opengl pipeline user must specify the following
system property on the command line:
-Dsun.java2d.opengl=True
.
See The
Guide, "Chapter XXX: Fine tune your strategies to eliminate artifacts"
(coming soon!).
Matlab and Mathematica development:
It is possible to create Java objects from within Matlab and Mathematica. You
can, therefore, create a FullScreen object in Matlab or Mathematica and
invoke its methods. In other words, if you choose, you could use this class
as a tool for psychophysics programming much like the well known Psychtoolbox
package.
Instructions on Matlab and Mathematica development can be found here.
NormalWindow
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.BaselineResizeBehavior |
Field Summary |
---|
Fields inherited from class javax.swing.JFrame |
---|
EXIT_ON_CLOSE |
Fields inherited from class java.awt.Frame |
---|
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface javax.swing.WindowConstants |
---|
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
FullScreen()
Constructs a FullScreen object on the default screen. |
|
FullScreen(int displayID)
Constructs a FullScreen object on the screen designated with displayID. |
Method Summary | |
---|---|
void |
blankScreen()
Blanks the whole screen using the current background color. |
void |
closeScreen()
Closes the full screen exclusive mode screen. |
void |
displayImage(java.awt.image.BufferedImage bi)
Displays a BufferedImage at the center of the screen. |
void |
displayImage(int x,
int y,
java.awt.image.BufferedImage bi)
Displays a BufferedImage at the specified position. |
void |
displayText(int x,
int y,
java.lang.String text)
Displays text at the specified position. |
void |
displayText(java.lang.String text)
Displays text at the center of the screen. |
void |
flushKeyPressed()
Clears both key pressed and when key pressed queues. |
void |
flushKeyReleased()
Clears both key released and when key released queues. |
void |
flushKeyTyped()
Clears both keyTyped and whenKeyTyped queues. |
java.awt.Color |
getBackground()
Returns the current background color. |
java.awt.DisplayMode |
getDisplayMode()
Returns the current DisplayMode. |
java.awt.DisplayMode[] |
getDisplayModes()
Returns all available DisplayModes on client's system. |
java.lang.Integer |
getKeyPressed()
Returns the key pressed by the observer. |
java.lang.Integer |
getKeyPressed(long ms)
Returns the key pressed by the observer. |
java.lang.Integer |
getKeyReleased()
Returns the key released by the observer. |
java.lang.Integer |
getKeyReleased(long ms)
Returns the key released by the observer. |
java.lang.String |
getKeyTyped()
Returns the key typed by the observer. |
java.lang.String |
getKeyTyped(long ms)
Returns the key typed by the observer. |
int |
getNBuffers()
Returns number of video buffers (including the front (visible) one) used by this FullScreen object. |
java.lang.Long |
getWhenKeyPressed()
Returns the time of the key pressed event. |
java.lang.Long |
getWhenKeyReleased()
Returns the time of the key released event. |
java.lang.Long |
getWhenKeyTyped()
Returns the time of the key typed event. |
void |
hideCursor()
Renders the cursor invisible. |
boolean |
isDisplayChangeSupported()
Returns whether or not DisplayMode change is available on client's system. |
boolean |
isDisplayModeAvailable(java.awt.DisplayMode dm)
Returns whether or not given DisplayMode is applicable to client's screen. |
boolean |
isFullScreenSupported()
Returns whether or not Full Screen Exclusive Mode (FSEM) is supported on client's system. |
void |
keyPressed(java.awt.event.KeyEvent ke)
|
void |
keyReleased(java.awt.event.KeyEvent ke)
|
void |
keyTyped(java.awt.event.KeyEvent ke)
|
java.lang.String |
reportDisplayMode()
Returns the current screen resolution, vertical synchronization rate and color depth in a readable form. |
java.lang.String[] |
reportDisplayModes()
Reports all available DisplayMode parameters in a readable format. |
void |
setBackground(java.awt.Color bg)
Sets the background color. |
void |
setDisplayMode(java.awt.DisplayMode dm)
Sets a new DisplayMode: secreen resolution, vertical synchronization rate, and color depth. |
void |
setNBuffers(int n)
Sets number of video buffers (including the front (visible) one). |
void |
showCursor()
Renders the cursor visible using default cursor |
void |
updateScreen()
Updates the entire screen by bringing the back video buffer front (if there exists a back buffer, if not it has no effect). |
Methods inherited from class javax.swing.JFrame |
---|
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, update |
Methods inherited from class java.awt.Frame |
---|
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated |
Methods inherited from class java.awt.Window |
---|
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, toBack, toFront |
Methods inherited from class java.awt.Container |
---|
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.awt.MenuContainer |
---|
getFont, postEvent |
Constructor Detail |
---|
public FullScreen(int displayID)
closeScreen()
.
displayID
- a numerical id indicating the screen devicesetDisplayMode(DisplayMode)
,
setNBuffers(int)
,
closeScreen()
public FullScreen()
closeScreen()
.
setDisplayMode(DisplayMode)
,
setNBuffers(int)
,
closeScreen()
Method Detail |
---|
public void keyTyped(java.awt.event.KeyEvent ke)
keyTyped
in interface java.awt.event.KeyListener
public void keyReleased(java.awt.event.KeyEvent ke)
keyReleased
in interface java.awt.event.KeyListener
public void keyPressed(java.awt.event.KeyEvent ke)
keyPressed
in interface java.awt.event.KeyListener
public void setNBuffers(int n)
n
- number of buffers requested; must not be less than 1getNBuffers()
public int getNBuffers()
setNBuffers(int)
public void updateScreen()
displayImage(int, int, BufferedImage)
,
displayText(int, int, String)
,
blankScreen()
public void displayImage(java.awt.image.BufferedImage bi)
bi
- BufferedImage to displaydisplayImage(int, int, BufferedImage)
,
updateScreen()
public void displayImage(int x, int y, java.awt.image.BufferedImage bi)
x
- horizontal offset of the upper left corner of the image from the
upper left corner of the screeny
- vertical offset of the upper left corner of the image from the
upper left corner of the screenbi
- BufferedImage to displaydisplayImage(BufferedImage)
,
updateScreen()
public void displayText(java.lang.String text)
text
- a text message to displaydisplayText(int, int, String)
,
updateScreen()
public void displayText(int x, int y, java.lang.String text)
x
- horizontal offset of the upper left corner of the text from the
upper left corner of the screeny
- vertical offset of the upper left corner of the text from the
upper left corner of the screentext
- a text message to displaydisplayText(String)
,
updateScreen()
public void blankScreen()
updateScreen()
public java.awt.Color getBackground()
getBackground
in class java.awt.Component
setBackground(Color)
public void setBackground(java.awt.Color bg)
setBackground
in class java.awt.Component
bg
- new background colorgetBackground()
public void hideCursor()
showCursor()
public void showCursor()
hideCursor()
public void closeScreen()
FullScreen(int)
,
FullScreen()
public java.lang.String getKeyTyped(long ms)
If the specified wait time is positive: This method either (i) returns the top element in the keyTyped queue immediately if there is at least one element in the keyTyped event queue or (ii) waits up to the specified amount of time for an element to become available. If no key is typed within the specified amount of time it returns null.
If the specified time is zero: Returns the top element in the keyTyped event queue or null if queue is empty.
If the specified wait time is negative: This method either returns the top element in the queue or if the queue is empty it waits indefinetely untill the observer types a character.
In all cases, the element returned is removed from the event queue.
General principles of event handling in FullScreen: FullScreen captures the key events in a seperate Thread and stores them in Thread safe BlockingQueue objects. Anytime observer types, presses or releases a key, that key and the time of the event are inserted to the end (tail) of the respective queues. When one of the getKeyTyped(), getKeyPressed() or getKeyReleased() methods is invoked, the top (head) of the respective queue is retrived and removed. Similarly, getWhenKeyTyped(), getWhenKeyPressed() and getWhenKeyReleased() methods retrive and remove the head in event time queues. flushKeyTyped(), flushKeyPressed() and flushKeyReleased() methods clear all queues, including the event time queues.
For more information see Chapter 6: Getting observer response of the Guide to Psychophysics programming with Java.
ms
- time in milliseconds to wait for a response
getKeyTyped()
,
flushKeyTyped()
,
getWhenKeyTyped()
public java.lang.String getKeyTyped()
The element returned is removed from the event queue. See also general principles of event handling in FullScreen above.
For more information see Chapter 6: Getting observer response of the Guide to Psychophysics programming with Java.
getKeyTyped(long)
,
flushKeyTyped()
,
getWhenKeyTyped()
public java.lang.Long getWhenKeyTyped()
The element returned is removed from the event queue. See also general principles of event handling in FullScreen above.
For more information see Chapter 6: Getting observer response of the Guide to Psychophysics programming with Java.
getKeyTyped(long)
,
flushKeyTyped()
public void flushKeyTyped()
For more information see Chapter 6: Getting observer response of the Guide to Psychophysics programming with Java.
getKeyTyped(long)
,
getWhenKeyTyped()
public java.lang.Integer getKeyPressed(long ms)
If the specified wait time is positive: This method either (i) returns the top element in the keyPressed queue immediately if there is at least one element in the keyPressed event queue or (ii) waits up to the specified amount of time for an element to become available. If no key is pressed within the specified amount of time it returns null.
If the specified time is zero: Returns the top element in the keyPressed event queue or null if queue is empty.
If the specified wait time is negative: This method either returns the top element in the queue or if the queue is empty it waits indefinetely untill the observer presses a key.
In all cases, the element returned is removed from the event queue. See also general principles of event handling in FullScreen above.
For more information see Chapter 6: Getting observer response of the Guide to Psychophysics programming with Java.
ms
- time in milliseconds to wait for a response
getKeyPressed()
,
flushKeyPressed()
,
getWhenKeyPressed()
public java.lang.Integer getKeyPressed()
The element returned is removed from the event queue. See also general principles of event handling in FullScreen above.
For more information see Chapter 6: Getting observer response of the Guide to Psychophysics programming with Java.
getKeyPressed(long)
,
flushKeyPressed()
,
getWhenKeyPressed()
public java.lang.Long getWhenKeyPressed()
The element returned is removed from the event queue. See also general principles of event handling in FullScreen above.
For more information see Chapter 6: Getting observer response of the Guide to Psychophysics programming with Java.
getKeyPressed(long)
,
flushKeyPressed()
public void flushKeyPressed()
For more information see Chapter 6: Getting observer response of the Guide to Psychophysics programming with Java.
getKeyPressed(long)
,
getWhenKeyPressed()
public java.lang.Integer getKeyReleased(long ms)
If the specified wait time is positive: This method either (i) returns the top element in the keyReleased queue immediately if there is at least one element in the keyReleased event queue or (ii) waits up to the specified amount of time for an element to become available. If no key is released within the specified amount of time it returns null.
If the specified time is zero: Returns the top element in the keyReleased event queue or null if queue is empty.
If the specified wait time is negative: This method either returns the top element in the queue or if the queue is empty it waits indefinetely untill the observer releases a key.
In all cases, the element returned is removed from the event queue. See also general principles of event handling in FullScreen above.
For more information see Chapter 6: Getting observer response of the Guide to Psychophysics programming with Java.
ms
- time in milliseconds to wait for a response
getKeyReleased()
,
flushKeyReleased()
,
getWhenKeyReleased()
public java.lang.Integer getKeyReleased()
The element returned is removed from the event queue. See also general principles of event handling in FullScreen above.
For more information see Chapter 6: Getting observer response of the Guide to Psychophysics programming with Java.
getKeyReleased(long)
,
flushKeyReleased()
,
getWhenKeyReleased()
public java.lang.Long getWhenKeyReleased()
The element returned is removed from the event queue. See also general principles of event handling in FullScreen above.
For more information see Chapter 6: Getting observer response of the Guide to Psychophysics programming with Java.
getKeyReleased(long)
,
flushKeyReleased()
public void flushKeyReleased()
For more information see Chapter 6: Getting observer response of the Guide to Psychophysics programming with Java.
getKeyReleased(long)
,
getWhenKeyReleased()
public boolean isFullScreenSupported()
public void setDisplayMode(java.awt.DisplayMode dm)
dm
- new display mode to applyisDisplayChangeSupported()
,
isDisplayModeAvailable(DisplayMode)
public boolean isDisplayModeAvailable(java.awt.DisplayMode dm)
dm
- DisplayMode to check
public java.lang.String reportDisplayMode()
public java.awt.DisplayMode getDisplayMode()
public boolean isDisplayChangeSupported()
public java.lang.String[] reportDisplayModes()
public java.awt.DisplayMode[] getDisplayModes()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |