/** Class for window used during tests
* Takes care of initiating tests, drawing tests, and
* cleaning up after test ends
**/
package yerkes;
import javax.swing.*;
import java.awt.Color;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
import java.awt.Graphics;
import java.io.*;
import javax.sound.sampled.*;
/**
*
* @author Pearce Peck-Walden
*
**/
class Base extends JWindow {
public String Tester, imageDirectory, monkeyid, dbHost;
public boolean isDB, isSettingUp, written;
public KeyEvent buttonPress;
public int card, isBetween, correction, readytobypass;
public int[][] customGrid;
public Object[][] customImages;
public String[] imageNames;
private int skipInitial;
private program1aHandler p1a;
private program1bHandler p1b;
private program2aHandler p2a;
private program2bHandler p2b;
private program3aHandler p3a;
private program3bHandler p3b;
private program4Handler p4;
private program5Handler p5;
private program6Handler p6;
private program7Handler p7;
private program8Handler p8;
private startHandler sh;
private Vector theImages;
private JFrame tWindow;
private int number, trials, customSize, baseline;
private ImageIcon test;
private int count, theC, countValid, pr, csst, reward, comPort, time, delay, customShift, customNumberStimuli;
private int theX, theY, theX2, theY2, w, h, swap, numberOfImages, width, height, attention;
protected int started;
private java.util.Timer t;
private String Date, Id, prog, size;
private float[] delays;
private FileOutputStream outputFile = null;
private PrintWriter outputStream = null;
private Color[] colors = { Color.black, Color.blue, Color.gray, Color.green, Color.orange, Color.pink,
Color.yellow, Color.red, Color.white, new Color( 128, 64, 0 ), Color.cyan, Color.magenta, new Color( 153, 0, 153 ),
Color.red, Color.green };
private int[] theXs;
private int[] theYs;
private int[] csstData;
private float iti;
private Clip correctSound, incorrectSound;
private ImageIcon asterix;
private ImageIcon ii1, ii2;
private BufferedImage buf;
protected Graphics g2;
private String[] customTargets;
private boolean isProgressiveDelays;
/** Creates new Base */
public Base(Vector images, JFrame window, int program, String p, int theDelay,
int tallow, String date, String id, String tester, int tr, float[] d, String outFile,
String imageDir, String screenSize, int c, int v, int fr, String ititemp, String VD, String VT,
int at, int v2, int rgb, int port, int cursor, int crd, Clip CS, Clip IS, String db, String custom1,
String custom2, String custom3, String custom4, int stim, int shfts, int progDel, int corProc ) {
if ( progDel == 0 ) isProgressiveDelays = true;
else isProgressiveDelays = false;
isBetween = 0;
customTargets = new String[4];
skipInitial = 0;
customTargets[0] = custom1;
customTargets[1] = custom2;
customTargets[2] = custom3;
customTargets[3] = custom4;
customShift = shfts;
customNumberStimuli = stim + 2;
card = crd;
theImages = images;
tWindow = window;
number = program;
readytobypass = 0;
prog = p;
setBackground(Color.black);
Date = date;
Id = id;
monkeyid = id;
dbHost = db;
Tester = tester;
trials = tr;
time = tallow;
delays = d;
delay = theDelay;
size = screenSize;
imageDirectory = imageDir;
count = 0;
swap = 0;
numberOfImages = 1;
theC = c;
countValid = v;
pr = fr;
csst = v2;
try{ iti = Float.parseFloat(ititemp); } catch (Exception e) {}
attention = at;
t = new java.util.Timer();
correctSound = CS;
incorrectSound = IS;
comPort = port;
reward = rgb;
correction = corProc;
isSettingUp = written = false;
if ( dbHost.equals("")) {
isDB = false;
}
else {
isDB = true;
}
if(reward != 0)
{
com.setTime(Float.parseFloat(VD), Float.parseFloat(VT));
usbHandler.setTime(Float.parseFloat(VD), Float.parseFloat(VT));
}
started = -1;
asterix = new ImageIcon ( getClass().getResource("asterix.jpg") );
if(cursor == 0)
{
this.setCursor( Toolkit.getDefaultToolkit().createCustomCursor(
new ImageIcon ( getClass().getResource("cursor.gif")).getImage(),
new Point(0,0),""));
}
//If there is an output file, open it and write the general info
if( ! ( outFile.equals("") ) )
{
try {
outputFile = new FileOutputStream( outFile, true );
outputStream = new PrintWriter( outputFile, true );
writeHeader();
} catch ( FileNotFoundException err ) {}
}
//Data to for determining the position of items in the test
if( size.equals( "1024x768" ) )
{
setBounds(0,0,1024,768);
theX = ( 1024 / 2 ) - 200 / 2;
theY = ( 768 / 2 ) - 200 / 2;
w = 1024;
h = 768;
width = 200;
height = 200;
customSize = 200;
}
else
{
setBounds(0,0,800,600);
theX = ( 800 / 2 ) - 150 / 2;
theY = ( 600 / 2 ) - 150 / 2;
w = 800;
h = 600;
width = 150;
height = 150;
customSize = 150;
}
//Handler for quitting the program when q/Q is pressed
BypassHandler BP = new BypassHandler( this, t );
this.addKeyListener( BP );
//Handler for displaying the start image
sh = new startHandler( this, theX, theY, width, height);
this.addMouseListener( sh );
//Make the visible visible and get mouse/keyboard focus
this.setVisible(true);
System.out.println("Focusable = " + this.isFocusable());
this.setFocusable(true);
buf = new BufferedImage(w , h, BufferedImage.TYPE_INT_RGB);
g2 = buf.createGraphics();
this.requestFocus();
this.paintBuf( g2 );
}
//Function called by start handler when image is pressed
protected void setup()
{
//Remove the start handler (no longer needed)
removeMouseListener(sh);
isSettingUp = true;
//Program hasn't started, but init screen is not running
started = 0;
//Depending on which number program was selected, setup the appropriate variables
// and call the constructor for the program
// add the newly constructed program as a handlder to the window
// schedule the timeAllowance timer (if program doesnt start w/ flashing)
switch ( number )
{
//Shaping - Centered
case 1:
ii1 = ( ImageIcon ) theImages.elementAt( 0 );
p1a = new program1aHandler( this, theImages, theX, theY, delay,
time, t , trials, delays, outputStream, w, h, width, height, theC,
countValid, correctSound, incorrectSound, reward, comPort, iti );
addMouseListener( p1a );
t.schedule( new Time ( p1a ), time * 1000 );
break;
// Shaping - Random location
case 2:
ii1 = ( ImageIcon ) theImages.elementAt( 0 );
p1b = new program1bHandler( this, theImages, theX, theY, delay,
time, t , trials, delays, outputStream, w, h, width, height, theC,
countValid, correctSound, incorrectSound, reward, comPort, iti );
addMouseListener( p1b );
t.schedule( new Time ( p1b ), time * 1000 );
break;
// Matching to sample - DMS
case 3:
theX2 = 0;
theY2 = 0;
p2a = new program2aHandler( this, theImages, theX, theY, theX2, theY2, delay,
time, t , trials, delays, outputStream, w, h, width, height, theC,
countValid, correctSound, incorrectSound, reward, comPort, iti, isProgressiveDelays, correction );
addMouseListener( p2a );
t.schedule( new Time ( p2a ), time * 1000 );
break;
//Matching to sample - DNMS
case 4:
theX2 = 0;
theY2 = 0;
p2b = new program2bHandler( this, theImages, theX, theY, theX2, theY2, delay,
time, t , trials, delays, outputStream, w, h, width, height, theC,
countValid, correctSound, incorrectSound, reward, comPort, iti, isProgressiveDelays, correction );
addMouseListener( p2b );
t.schedule( new Time ( p2b ), time * 1000 );
break;
// 5-> Spacial DRST 6-> Object DRST
// These two programs are so similar and require a large amount of data
// so they are put togeather
case 5:
case 6:
{
Random r = new Random();
Vector positionX = new Vector(15);
Vector positionY = new Vector(15);
int xHelp, yHelp, theSize, whichOne, value, value2, ii;
theXs = new int[15];
theYs = new int[15];
count = 1;
baseline = 0;
imageNames = new String[15];
//Reset window data (images need to be smaller than standard to fit them all)
if( size.equals("1024x768") )
{
width = 180;
height = 180;
}
else
{
width = 125;
height = 125;
}
// Position of the first image
xHelp = 10;
yHelp = ( h - (height * 3 ) ) / 4;
// Create two vectors, one for the x coordinate valuse
// one for the y values
for( ii = 1; ii < 16; ii++ )
{
positionX.addElement( new Integer ( xHelp ) );
positionY.addElement( new Integer ( yHelp ) );
xHelp = xHelp + width + 10;
// If this was the last image in the row, reset
if ( ( ii % 5 ) == 0 )
{
xHelp = 10;
yHelp = yHelp + height + ( h - (height * 3) ) / 4;
}
}
//Pull the positions out of the vectors (in random order) and put them
// into arrays (creates a set of positons in random order)
for( ii = 0; ii < 15 ; ii++)
{
theSize = positionX.size() - 1;
if( theSize > 1 )
{
whichOne = r.nextInt( theSize );
value = ( ( Integer ) positionX.elementAt( whichOne ) ).intValue() ;
value2 = ( ( Integer ) positionY.elementAt( whichOne ) ).intValue() ;
}
else
{
whichOne = 0;
value = ( ( Integer ) positionX.elementAt( whichOne ) ).intValue() ;
value2 = ( ( Integer ) positionY.elementAt( whichOne ) ).intValue() ;
}
positionX.removeElementAt( whichOne );
positionY.removeElementAt( whichOne );
theXs[ii] = value;
theYs[ii] = value2;
}
// If the data point is in the middle row (of three) offset the X value
// So the images arent in straight columns
for( ii = 0; ii < 15; ii++)
{
if( theYs[ii] == ( ( h - (height * 3) ) / 4 ) + height + ( h - (height * 3) ) / 4 )
theXs[ii] = theXs[ii] + ( ( h - (height * 3) ) / 4 );
}
if( number == 5 )
{
p3a = new program3aHandler( this, theImages, theXs, theYs, delay,
time, t , trials, delays, outputStream, w, h, width, height, theC,
countValid, correctSound, incorrectSound, reward, comPort, iti );
addMouseListener( p3a );
t.schedule( new Time ( p3a ), time * 1000 );
}
else
{
count = 0;
p3b = new program3bHandler( this, theImages, theXs, theYs, delay,
time, t , trials, delays, outputStream, w, h, width, height, theC,
countValid, baseline, correctSound, incorrectSound, reward, comPort, iti );
addMouseListener( p3b );
t.schedule( new Time ( p3b ), time * 1000 );
}
}
break;
// Progressive Ratio
case 7:
p4 = new program4Handler( this, theX, theY, delay,
time, t , trials, delays, outputStream, w, h, width, height,
theC, countValid, pr, correctSound, incorrectSound, reward, comPort, iti );
addMouseListener( p4 );
t.schedule( new Time ( p4 ), time * 1000 );
break;
// Delayed response
case 8:
//Positions are not standard so reset
if( size.equals("1024x768") )
{
theX = 50;
theY = h /2 - height / 2 + height / 4;
theX2 = w - width - 50;
theY2 = h /2 - height / 2 + height / 4;
}
else
{
theX = 50;
theY = h /2 - height / 2 + height / 4;
theX2 = w - width - 50;
theY2 = h /2 - height / 2 + height / 4;
}
p5 = new program5Handler( this, theX, theY, theX2, theY2, delay,
time, t , trials, delays, outputStream, w, h, width, height, theC,
countValid, correctSound, incorrectSound, reward, comPort, iti, isProgressiveDelays, correction );
addMouseListener( p5 );
// Don't schedule timer. Timer shouldn't start until flashing has finished
break;
// Attention tasks
case 9:
{
int xHelp, yHelp, theSize, whichOne, value, value2, ii;
theXs = new int[12];
theYs = new int[12];
Random r = new Random();
count = r.nextInt( 12 );
//Positions are non standard so reset
if( size.equals("1024x768") )
{
width = 130;
height = 130;
}
else
{
width = 85;
height = 85;
}
xHelp = width - width / 4;
yHelp = (height / 4 );
//Setup an array of positions
for( ii = 1; ii < 13; ii++ )
{
theXs[ ii - 1 ] = xHelp;
theYs[ ii - 1 ] = yHelp;
xHelp = xHelp + w / 3 ;
if ( ( ii % 3 ) == 0 )
{
xHelp = width - width / 4;
yHelp = yHelp + h / 4;
}
}
p6 = new program6Handler( this, theXs, theYs, delay,
time, t , trials, delays, outputStream, w, h, width, height, theC,
countValid, attention, r, count, correctSound, incorrectSound, reward, comPort, iti );
addMouseListener( p6 );
//Schedule time unless this is cued seach b/c cued search flashes
if( attention != 3 ) t.schedule( new Time ( p6 ), time * 1000 );
}
break;
// Conceptual set shifting
case 10:
{
int isline;
Random r = new Random();
int xHelp, yHelp, theSize, whichOne, value, value2, ii, yStart;
theXs = new int[9];
theYs = new int[9];
csstData = new int[9];
xHelp = (w - width * 3 ) / 4;
yHelp = (height / 6);
yStart = yHelp;
//Create array of positions
for( ii = 1; ii < 10; ii++ )
{
theXs[ ii - 1 ] = xHelp;
theYs[ ii - 1 ] = yHelp;
xHelp = xHelp + (w - width * 3) / 4 + width;
if ( ( ii % 3 ) == 0 )
{
xHelp = (w - width * 3) / 4;
yHelp = yHelp + h / 3;
}
}
//this covers one row option
if ( (card == 2) || (card == 3) )
{
isline = 3;
yStart = yStart;
for ( ii = 0; ii < 9; ii++ ) {
theYs[ii] = yStart + h / 3;
}
}
else {
isline = 9;
}
p7 = new program7Handler( this, theXs, theYs, delay,
time, t , trials, delays, outputStream, w, h, width, height, theC,
countValid, csst, r, csstData, correctSound, incorrectSound, reward, comPort, isline, iti );
addMouseListener( p7 );
t.schedule( new Time ( p7 ), time * 1000 );
}
break;
//Custom CSST
case 11:
{
int xHelp, yHelp, ii, buffer, Xedging, Yedging;
customGrid = new int[9][3];
Yedging = ( h - ( customSize * 3 ) ) / 8;
buffer = ( h - ( customSize * 3 ) - ( Yedging * 2 ) ) / 2 ; //distance between cells
Xedging = ( w - ( customSize * 3 ) - ( buffer * 2 ) ) / 2; //on sides
xHelp = Xedging;
yHelp = Yedging;
//Create array of positions
for( ii = 1; ii < 10; ii++ )
{
customGrid[ ii - 1 ][0] = -1;
customGrid[ ii - 1 ][1] = xHelp;
customGrid[ ii - 1 ][2] = yHelp;
yHelp = yHelp + customSize + buffer;
if ( ( ii % 3 ) == 0 )
{
xHelp = xHelp + customSize + buffer;
yHelp = Yedging;
}
}
p8 = new program8Handler( this, delay, time, t, trials, delays, outputStream, theC,
countValid, correctSound, incorrectSound, reward, comPort,
iti, customTargets, customNumberStimuli, customSize, customShift );
addMouseListener( p8 );
t.schedule( new Time ( p8 ), time * 1000 );
}
break;
// This should never happen, buf if it does just end (go back)
default:
end( 0 );
}
//Mark programs as having started
started = 1;
//If the program flashes, start the flashing
if( number == 8 ) p5.flash();
if(( number == 9 ) && (attention == 3)) p6.flash();
//Create a new paint thread to make sure the screen has refreshed from the init screen
paintThread pt = new paintThread( this );
pt.start();
}
//When window is repainted draw the offscreen buffer to the window
public void paint( Graphics screen ) {
if(buf != null)
{
screen.drawImage( buf, 0, 0, null );
}
}
//This is for when an image updates (such as a moving GIF)
public void update(Graphics g) {
// DO NOTHING. This is because animated GIFS update too fast and generate all sorts of crazy stuff. This freezes them.
}
//This takes care of doing the actual drawing
public synchronized void paintBuf ( Graphics g ) {
//If the program hasn't started, draw the initial image
if( started == -1)
{
g.drawImage( asterix.getImage() , theX, theY, width, height, this );
return;
}
//If the program is out of the initial handler, but new programs hasnt finished
// Initializing, just draw a black screen
else if( started == 0 )
{
g.setColor( colors[ 0 ] );
g.fillRect(0, 0, w, h);
return;
}
// If the program has started, draw the appropriate images depending on data
// Manipulated by program handler
switch( number )
{
// For Shaping programs, if count is positive draw the image at specified position
// Otherwise fill screen with selected color
case 1:
case 2:
if ( count >= 0 )
{
g.setColor( colors[ 0 ] );
g.fillRect(0, 0, w, h);
ii1 = (ImageIcon) theImages.elementAt(count);
g.drawImage( ii1.getImage() , theX, theY, width, height, this );
}
else
{
g.setColor( colors[ (count * -1) - 1 ] );
g.fillRect(0, 0, w, h);
}
break;
// For DMS and DMNS if count >= 0 draw images
// Otherwise colored screen
case 3:
case 4:
if( ( count >= 0 ) )
{
g.setColor( colors[ 0 ] );
g.fillRect(0, 0, w, h);
if ( ( swap == 1) || ( numberOfImages == 1 ) )
{
ii1 = ( ImageIcon ) theImages.elementAt( count );
ii2 = ( ImageIcon ) theImages.elementAt( count + 1 );
}
else
{
ii1 = ( ImageIcon ) theImages.elementAt( count + 1 );
ii2 = ( ImageIcon ) theImages.elementAt( count );
}
g.drawImage( ii1.getImage() , theX, theY, width, height, this );
}
else
{
ii2 = null;
g.setColor( colors[ (count * -1) - 1 ] );
g.fillRect(0, 0, w, h);
}
// If this is a screen w/ 2 images, draw second image
if( ( ii2 != null ) && ( numberOfImages == 2 ) )
{
g.drawImage( ii2.getImage() , theX2, theY2, width, height, this );
}
break;
// if count > 0 draw all images needed, otherwise colored screen
case 5:
if( count > 0 )
{
g.setColor( colors[ 0 ] );
g.fillRect(0, 0, w, h);
ii1 = ( ImageIcon ) theImages.elementAt( 0 );
for (int ii = count - 1; ii >= 0 ; ii--)
{
g.drawImage( ii1.getImage() , theXs[ii] , theYs[ii], width, height, this );
}
}
else
{
g.setColor( colors[ (count * -1) - 1 ] );
g.fillRect(0, 0, w, h);
}
break;
// if count > 0 draw all images needed, otherwise colored screen
case 6:
if( count >= 0 )
{
int temp;
int temp2;
g.setColor( colors[ 0 ] );
g.fillRect(0, 0, w, h);
for (int ii = count; ii >= 0 + baseline ; ii--)
{
if ( ii >= theImages.size() )
temp = ii % theImages.size();
else
temp = ii;
ii1 = ( ImageIcon ) theImages.elementAt( temp );
g.drawImage( ii1.getImage() , theXs[ii % theXs.length ] , theYs[ii % theYs.length ], width, height, this );
String tempStr = new String(ii1.toString());
int temp3 = tempStr.lastIndexOf("\\"); //this section gets the filename
tempStr = tempStr.substring( temp3+1 , tempStr.length() );
imageNames[ii % theXs.length] = tempStr;
}
}
else
{
g.setColor( colors[ (count * -1) - 1 ] );
g.fillRect(0, 0, w, h);
}
break;
// if count >= 0 draw centered square, otherwise colored screen
case 7:
if ( count >= 0 )
{
g.setColor( colors[ 0 ] );
g.fillRect(0, 0, w, h);
g.setColor( colors[ 6 ] );
g.fillRect(theX, theY, width, height );
}
else
{
g.setColor( colors[ (count * -1) - 1 ] );
g.fillRect(0, 0, w, h);
}
break;
//If count is 100 draw the two squares
// If < 0 draw colored screen
// If equal to 0 draw the circle (cue during flash) by left sqauare
// If equal to 1 draw the circle (cue during flash) by right sqaure
case 8:
if(count >= 0 )
{
g.setColor( colors[ 0 ] );
g.fillRect(0, 0, w, h);
}
if( ( count == 100 ) )
{
g.setColor(colors[ 6 ]);
g.fillRect(50, h /2 - height / 2, width, height);
g.fillRect(w - width - 50, h /2 - height / 2, width, height);
}
else if ( count < 0 )
{
g.setColor( colors[ (count * -1) - 1 ] );
g.fillRect(0, 0, w, h);
}
else if ( count == 0 )
{
g.setColor(colors[ 7 ]);
g.fillArc(width / 2 + width / 4, h /2 - height / 2 + height / 4, width / 4, height / 4, 0 , 360);
}
else if ( count == 1 )
{
g.setColor(colors[ 7 ]);
g.fillArc(w - width / 2 - 50 - width / 4, h /2 - height / 2 + height / 4, width / 4, height / 4, 0 , 360);
}
break;
//If count is between 0 and 100 draw all the circles
// If < 0 draw colored screen
// If > 100 draw circle in specified position only (used for flashing)
case 9:
if (( count >= 0 ) && (count < 100))
{
g.setColor( colors[ 0 ] );
g.fillRect(0, 0, w, h);
//this controls the color of the circles before the star
if ( attention == 1 ) g.setColor(colors[ 6 ]);
else g.setColor(colors[ 7 ]);
for( int ii = 0; ii < 12; ii++ )
if(( ii != count) && (attention != 0))
g.fillArc(theXs[ii], theYs[ii], width, height, 0 , 360);
else if ( ii == count)
{
//The Star
int[] xPoints = { theXs[ii], theXs[ii] + width / 3,
theXs[ii] + width / 2,
theXs[ii] + 2 * (width / 3),
theXs[ii] + width,
theXs[ii] + 3 * (width / 4),
theXs[ii] + 7 * (width / 8),
theXs[ii] + width / 2,
theXs[ii] + (width / 8),
theXs[ii] + ( width / 4) };
int[] yPoints = { theYs[ii] + height / 3, theYs[ii] + height / 3, theYs[ii], theYs[ii] + height / 3,
theYs[ii] + height / 3, theYs[ii] + 3 * ( height / 5), theYs[ii] + height, theYs[ii] + 3 * (height / 4), theYs[ii] + height,
theYs[ii] + 3 * (height / 5) };
g.setColor(colors[ 7 ]); //the star
g.fillPolygon( xPoints, yPoints, xPoints.length);
//this controls the color of the circles after the star
if ( attention == 1 ) g.setColor(colors[ 6 ]);
else g.setColor(colors[ 7 ]);
}
}
else if ( count >= 100 )
{
g.setColor( colors[ 0 ] );
g.fillRect(0, 0, w, h);
g.setColor(colors[ 6 ]); //cue is yellow
g.fillArc(theXs[count - 100], theYs[count - 100], width , height, 0 , 360);
}
else
{
g.setColor( colors[ (count * -1) - 1 ] );
g.fillRect(0, 0, w, h);
}
break;
// If csstData[0] is greater than 0
// And csst equals 0 (discrimination) draw the three shapes
// Otherwise draw level X shapes
// If csstData[0] is less than 0 draw colored screen
case 10:
if ( (card == 0) || (card == 2) ) //no cards
{
if ( csstData[0] >= 0 )
{
g.setColor( colors[ 0 ] );
g.fillRect(0, 0, w, h);
if( csst == 0)
{
for( int ii = 0; ii < 3; ii++ )
{
g.setColor(colors[ 0 ]);
g.fillRect(theXs[csstData[ii]], theYs[csstData[ii]], width, height);
if( csstData[ ii + 3 ] == 0 )
{
g.setColor(colors[10] );
g.fillRect( theXs[csstData[ii]], theYs[csstData[ii]], width, height);
}
else if( csstData[ ii + 3 ] == 1 )
{
g.setColor(colors[11] );
g.fillRect( theXs[csstData[ii]], theYs[csstData[ii]] + height / 2 - height / 16, width, height / 8);
g.fillRect( theXs[csstData[ii]] + width / 2 - width / 16, theYs[csstData[ii]], width / 8, height);
}
else
{
g.setColor( colors[6] );
int[] xPoints = { theXs[csstData[ii]],
theXs[csstData[ii]] + width / 2,
theXs[csstData[ii]] + width,
theXs[csstData[ii]] + width,
theXs[csstData[ii]] + width / 2,
theXs[csstData[ii]]};
int[] yPoints = { theYs[csstData[ii]],
theYs[csstData[ii]] + height / 2,
theYs[csstData[ii]],
theYs[csstData[ii]] + height,
theYs[csstData[ii]] + height / 2,
theYs[csstData[ii]] + height};
g.fillPolygon( xPoints, yPoints, xPoints.length);
}
}
}
else
{
for( int ii = 0; ii < 3; ii++ )
{
g.setColor(colors[ 0 ]);
g.fillRect(theXs[csstData[ii]], theYs[csstData[ii]], width, height);
if ( csstData[ii+6] == 0) g.setColor(colors[7]);
else if ( csstData[ii+6] == 1) g.setColor(colors[3]);
else if ( csstData[ii+6] == 2) g.setColor(colors[1]);
if( csstData[ ii + 3 ] == 0 )
g.fillArc( theXs[csstData[ii]], theYs[csstData[ii]], width, height, 0, 360);
else if( csstData[ii + 3 ] == 1 )
{
int[] xPoints = { theXs[csstData[ii]], theXs[csstData[ii]] + width / 2 ,
theXs[csstData[ii]] + width};
int[] yPoints = { theYs[csstData[ii]] + height, theYs[csstData[ii]],
theYs[csstData[ii]] + height};
g.fillPolygon( xPoints, yPoints, xPoints.length);
}
else
{
int[] xPoints = { theXs[csstData[ii]],
theXs[csstData[ii]] + 2 * (width / 6 ),
theXs[csstData[ii]] + 3 * (width / 6 ),
theXs[csstData[ii]] + 4 * (width / 6 ),
theXs[csstData[ii]] + width,
theXs[csstData[ii]] + 4 * (width / 6 ),
theXs[csstData[ii]] + 5 * (width / 6 ),
theXs[csstData[ii]] + 3 * (width / 6 ),
theXs[csstData[ii]] + 1 * (width / 6 ),
theXs[csstData[ii]] + 2 * (width / 6 ) };
int[] yPoints = { theYs[csstData[ii]] + 4 * (height / 12),
theYs[csstData[ii]] + 4 * (height / 12),
theYs[csstData[ii]],
theYs[csstData[ii]] + 4 * (height / 12),
theYs[csstData[ii]] + 4 * (height / 12),
theYs[csstData[ii]] + 7 * (height / 12),
theYs[csstData[ii]] + height,
theYs[csstData[ii]] + 9 * (height / 12),
theYs[csstData[ii]] + height,
theYs[csstData[ii]] + 7 * (height / 12) };
g.fillPolygon( xPoints, yPoints, xPoints.length);
}
}
}
}
else
{
g.setColor( colors[ (csstData[0] * -1) - 1 ] );
g.fillRect(0, 0, w, h);
}
}//end if card == 0 or 2
else if ( (card == 1) || (card == 3) || (card == 4 ) ) //they want the cards
{
if ( card == 4) //we're using the alternate colors
{
colors[13] = colors[11];
colors[14] = colors[6];
}
if ( csstData[0] >= 0 )
{
g.setColor( colors[ 0 ] );
g.fillRect(0, 0, w, h);
if( csst == 0)
{
for( int ii = 0; ii < 3; ii++ )
{
g.setColor(colors[ 8 ]);
g.fillRect(theXs[csstData[ii]], theYs[csstData[ii]], width, height);
if( csstData[ ii + 3 ] == 0 )
{
g.setColor(colors[5] );
g.fillRect( theXs[csstData[ii]] + width / 4, theYs[csstData[ii]] + height / 4, width / 2, height / 2);
}
else if( csstData[ ii + 3 ] == 1 )
{
g.setColor(colors[4] );
g.fillRect( theXs[csstData[ii]] + width / 4, theYs[csstData[ii]] + height / 2 - height / 16, width / 2, height / 8);
g.fillRect( theXs[csstData[ii]] + width / 2 - width / 16, theYs[csstData[ii]] + height / 4, width / 8, height / 2);
}
else
{
g.setColor( colors[9] );
int[] xPoints = { theXs[csstData[ii]] + width / 4,
theXs[csstData[ii]] + width / 2,
theXs[csstData[ii]] + 3 * (width / 4),
theXs[csstData[ii]] + 3 * (width / 4),
theXs[csstData[ii]] + width / 2,
theXs[csstData[ii]] + width / 4 };
int[] yPoints = { theYs[csstData[ii]] + height / 4,
theYs[csstData[ii]] + height / 2,
theYs[csstData[ii]] + height / 4,
theYs[csstData[ii]] + 3 * ( height / 4),
theYs[csstData[ii]] + height / 2,
theYs[csstData[ii]] + 3 * ( height / 4)};
g.fillPolygon( xPoints, yPoints, xPoints.length);
}
}
}
else
{
for( int ii = 0; ii < 3; ii++ )
{
g.setColor(colors[ 8 ]);
g.fillRect(theXs[csstData[ii]], theYs[csstData[ii]], width, height);
if ( csstData[ii+6] == 0) g.setColor(colors[13]);
else if ( csstData[ii+6] == 1) g.setColor(colors[14]);
else if ( csstData[ii+6] == 2) g.setColor(colors[1]);
if( csstData[ ii + 3 ] == 0 )
g.fillArc( theXs[csstData[ii]] + width / 4, theYs[csstData[ii]] + height / 4, width / 2, height / 2, 0, 360);
else if( csstData[ii + 3 ] == 1 )
{
int[] xPoints = { theXs[csstData[ii]] + width / 4, theXs[csstData[ii]] + width / 2 ,
theXs[csstData[ii]] + width / 4 + width / 2};
int[] yPoints = { theYs[csstData[ii]] + height / 4 + height / 2, theYs[csstData[ii]] + height / 4,
theYs[csstData[ii]] + height / 4 + height / 2};
g.fillPolygon( xPoints, yPoints, xPoints.length);
}
else
{
int[] xPoints = { theXs[csstData[ii]] + width / 4,
theXs[csstData[ii]] + width / 3 + width / 4,
theXs[csstData[ii]] + width / 2 ,
theXs[csstData[ii]] + 2 * (width / 3) - width / 4,
theXs[csstData[ii]] + width - width / 4,
theXs[csstData[ii]] + 3 * (width / 4) - width / 8,
theXs[csstData[ii]] + 7 * (width / 8) - width / 6,
theXs[csstData[ii]] + width / 2,
theXs[csstData[ii]] + (width / 8) + width / 6,
theXs[csstData[ii]] + ( width / 4) + width / 8 };
int[] yPoints = { theYs[csstData[ii]] + height / 4 + height / 6,
theYs[csstData[ii]] + height / 4 + height / 6,
theYs[csstData[ii]] + height / 4,
theYs[csstData[ii]] + height / 4 + height / 6,
theYs[csstData[ii]] + height / 4 + height / 6,
theYs[csstData[ii]] + ( height / 2) + height / 20,
theYs[csstData[ii]] + height - height / 8 - height / 8,
theYs[csstData[ii]] + 3 * (height / 4) - height / 8,
theYs[csstData[ii]] + height - height / 8 - height / 8,
theYs[csstData[ii]] + (height / 2) + height / 20};
g.fillPolygon( xPoints, yPoints, xPoints.length);
}
}
}
}
else
{
g.setColor( colors[ (csstData[0] * -1) - 1 ] );
g.fillRect(0, 0, w, h);
}
}//end else for cards
break;
//custom CSST
case 11:
if (skipInitial == 0) {
skipInitial = 1;
return;
} //we do this because our handler draws the first screen
if ( isBetween == 3 ) {
g.setColor( colors[ 7 ] );
g.fillRect(0, 0, w, h);
}
else if ( isBetween == 2 ) {
g.setColor( colors[ theC ] );
g.fillRect(0, 0, w, h);
}
else {
g.setColor( colors[ 0 ] );
g.fillRect(0, 0, w, h); //paints the black background
if ( isBetween == 0 ) {
//now draw the images
for ( int i = 0 ; i < 9 ; i++ ) {
if ( customGrid[i][0] != -1 ) {
g.drawImage( (Image)customImages[customGrid[i][0]][1] , customGrid[i][1], customGrid[i][2], customSize, customSize, this );
}//end if
} //end for
} //end if
} //end else
break;
}
readytobypass = 1;
} //end paintBuf
//Used for program Handlers to change "count"
protected int changeCount( int c ) {
int old;
old = count;
count = c;
return old;
}
// Used for program Handlers to change "baseline" (used for DRST tasks)
protected void changeBaseline( int c ) { baseline = c; }
// Used for program Handlers to change x and y positions
protected void loc(int x, int y, int x2, int y2, int s, int nI )
{
theX = x;
theY = y;
theX2 = x2;
theY2 = y2;
swap = s;
numberOfImages = nI;
}
// When the program is supposed to stop
// Call the quit function of the running program (if one has started)
protected void end( int kill )
{
System.out.println("ending");
if( started > 0 )
{
switch( number )
{
case 1:
p1a.quit();
break;
case 2:
p1b.quit();
break;
case 3:
p2a.quit();
break;
case 4:
p2b.quit();
break;
case 5:
p3a.quit();
break;
case 6:
p3b.quit();
break;
case 7:
p4.quit();
break;
case 8:
p5.quit();
break;
case 9:
p6.quit();
break;
case 10:
p7.quit();
break;
case 11:
p8.quit();
break;
}
}
// Close the sounds
if( correctSound != null) correctSound.close();
if( incorrectSound != null) incorrectSound.close();
// If this was a Q then quit entire program
if ( kill == 1 )
System.exit(1);
// Otherwise hide this base and show program selector
else
{
tWindow.setVisible( true );
this.setVisible(false);
}
}
protected void updateGraphics()
{
paintThread pt = new paintThread( this );
pt.start();
}
// When the programs is supposed to stop
// Call the quit function of the running program (if one has started)
protected void bypass(KeyEvent k)
{
buttonPress = k;
if( (started > 0) && (readytobypass == 1 ) )
{
switch( number )
{
case 1:
p1a.bypass();
break;
case 2:
p1b.bypass();
break;
case 3:
p2a.bypass();
break;
case 4:
p2b.bypass();
break;
case 5:
p3a.bypass();
break;
case 6:
p3b.bypass();
break;
case 7:
p4.bypass();
break;
case 8:
p5.bypass();
break;
case 9:
p6.bypass();
break;
case 10:
p7.bypass();
break;
case 11:
p8.bypass();
break;
}
}
}
// This function writes the header in formation for a program
private void writeHeader( )
{
outputStream.println( "Date: " + Date );
outputStream.println( "Monkey ID: " + Id );
outputStream.println( "Task: " + prog );
if( (number == 3) || (number == 4) || (number == 8) ){
if (correction == 0)
outputStream.println("Forced correction procedure");
else if (correction == 1)
outputStream.println("No correction procedure");
else if (correction == 2)
outputStream.println("Correction procedure on");
}
else if (number == 10 )
{
if( csst == 0 ) outputStream.println(" (Discrimination)");
if( csst == 1 ) outputStream.println(" (Level 1)");
if( csst == 2 ) outputStream.println(" (Level 2)");
if( csst == 3 ) outputStream.println(" (Level 3)");
if( csst == 4 ) outputStream.println(" (Level 4)");
}
else if (number == 9)
{
if( attention == 0 ) outputStream.println(" (Training)");
else if( attention == 1 ) outputStream.println(" (Simple Search Easy)");
else if( attention == 2 ) outputStream.println(" (Simple Search Hard)");
else if( attention == 3 ) outputStream.println(" (Cued Search)");
}
else if (number == 7 )
{
if( pr == 0 ) outputStream.println(" (Fixed Ratio 1)");
else if( pr == 1 ) outputStream.println(" (Fixed Ratio 2)");
else if( pr == 2 ) outputStream.println(" (Fixed Ratio 3)");
else if( pr == 3 ) outputStream.println(" (Fixed Ratio 4)");
else if( pr == 4 ) outputStream.println(" (Fixed Ratio 5)");
else if( pr == 5 ) outputStream.println(" (Fixed Ratio 6)");
else if( pr == 6 ) outputStream.println(" (Progressive Ratio)");
}
outputStream.println( "Tested By: " + Tester );
outputStream.println( "Image Directory: " + imageDirectory );
outputStream.println( "ITI: " + iti );
outputStream.print( "Database Host: ");
if (dbHost.equals("")) {
outputStream.println("NONE");
}
else {
outputStream.println(dbHost);
}
outputStream.println( " " );
outputStream.println( "Trial" );
}
}