//Chloe Chao //Highlight consonantal occurrences with different //colors according to family //Color key //stops = p, b, t, d, k, g, q = red //fricatives = f, v, th, s, z, sh, h = light blue //affricate = ch, j = dark blue //nasals = m, n, ng = light green //liquids = l, r = bluish green //glides = y, w, wh = dark green import java.applet.*; import java.awt.*; import java.awt.image.*; import java.net.*; import java.util.*; import java.io.*; public class Linguist extends Applet implements Runnable { public void init() { UNIT = 4; LEFT_MARGIN = 6; TOP_MARGIN = 30; alphabet = new Vector(); toBeCoded = new String(); noiseFactor = 0; Panel p = new Panel(); p.setLayout(new GridLayout(0,2)); //Create the URL textfield and place in view. makeUrlField(); p.add("West", urlField); //Create the button and place in view. makeButton(); p.add("East", button); // Use BorderLayout. BorderLayout b = new BorderLayout(); setLayout(b); add( "North", p ); //Create the display Image and place in view. makeImageCanvas(); add( "South", imageCanvas ); displayImage = createImage(size().width,size().height); offg = displayImage.getGraphics(); offg.setColor( Color.black ); imageCanvas.setImage(displayImage); imageCanvas.repaint(); //Read in the homemade font file. fetch("http://acg.media.mit.edu/mas962/users/cchao/ps7/colorfontcode.txt"); //fetch("file://C|/fontcode.txt"); // Start the applet thread. thread = new Thread( this ); thread.start(); } public void start() { if (thread != null) { thread.resume(); } } public void stop() { if (thread != null) { thread.suspend(); } } public void destroy() { if(thread != null) { thread.stop(); } } public void run() { try { while( true ) { repaint(); thread.sleep(sleepRate); } } catch (InterruptedException e) {} } public void update(Graphics g) { paint(g); } public void paint (Graphics g) { paintComponents(g); imageCanvas.setImage(displayImage); imageCanvas.repaint(); g.drawImage(displayImage, 0, 0, this); } public boolean action(Event e, Object arg) { if (e.target == button) { toBeCoded = urlField.getText(); offg = displayImage.getGraphics(); coded( 0, toBeCoded.toUpperCase() ); //This guarantees uppercase. return true; } return false; } public Image noiseImage(double bf, CodeString cs1, int gx, int gy) { int dim = UNIT*12; Image i2 = cs1.getImage(); Graphics g2 = i2.getGraphics(); g2.setColor( DKBLUE ); g2.fillRect( 0, 0, 2*dim, dim ); g2.setColor( cs1.getColor() ); for( int i=0; i 1.0) noise = 1.0; //Reset drawing coordinates to upper-left and clear screen int currx, curry; currx = LEFT_MARGIN; curry = TOP_MARGIN; offg.setColor(DKBLUE); offg.fillRect( 0, 0, this.size().width, this.size().height); //StringBuffer sb = new StringBuffer(); for( int i=0; i(size().width-(12*UNIT)) ) { currx = LEFT_MARGIN; curry+=(12*UNIT); } }//end for each letter }// end coded() public void fetch (String address) { byte buf[] = null; Image img; Graphics gg; if (!alphabet.isEmpty()) alphabet.removeAllElements(); try { URL url = new URL(address); StreamTokenizer tokens = new StreamTokenizer(url.openStream()); int token; tokens.ordinaryChar(';'); // signifies end of commands tokens.ordinaryChar('|'); // signifies eol tokens.whitespaceChars( '(', ')' ); tokens.eolIsSignificant(true); tokens.commentChar('%'); tokens.wordChars('<', '@' ); // Get first token. token = tokens.nextToken(); // if (FILE_READABLE) { // While not eof while (token != tokens.TT_EOF) { // While not eol while ( token != tokens.TT_EOL ) { // Take the first character of the line as the letter. if( tokens.sval != null ) { String codestr = tokens.sval; char code = codestr.charAt(0); //System.out.println("code: "+code); Image ii=createImage(UNIT*24, UNIT*12 ); CodeString cs = new CodeString( code, UNIT, ii );//**** alphabet.addElement( cs ); img = cs.getImage(); gg = img.getGraphics(); gg.setColor( Color.black ); // Get the next token and start parsing for operators. // I don't have any error-checking. Sorry. //token = tokens.nextToken(); while( (token=tokens.nextToken())!='|' ) { if( token == tokens.TT_WORD ) { if (tokens.sval.equals( "stop" )) { cs.setColor(STOP); } if (tokens.sval.equals( "fricative" )) { cs.setColor(FRICATIVE); } if (tokens.sval.equals( "affricate" )) { cs.setColor(Color.red); } if (tokens.sval.equals( "nasal" )) { cs.setColor(NASAL); } if (tokens.sval.equals( "liquid" )) { cs.setColor(LIQUID); } if (tokens.sval.equals( "glide" )) { cs.setColor(GLIDE); } if (tokens.sval.equals( "serifs" )) { // Get the number of serifs to draw. //tokens.nextToken(); //int numOfSerifs = (int)tokens.nval; //for(int i=0; i