import java.awt.*;import java.awt.event.*;import java.awt.datatransfer.*;import java.applet.*;public class PhonemePicker extends Applet {	// this will probably only work on a mac	// the proper unicode codes are noted (where the	// wrong char is in use	public final String[] phonemes = { 						"I",   // u026A						"i",  // i  + :						"j",						"w",						"tS",  // u02A7						"dZ",  // u02A4						"e",						"A",  // u0251 + :						"p",						"t",						"k",						"l",						"Q",   // u00E6						"U",   // u028A						"b",						"d",						"g",						"r",						"",   // u028C						"u",  // u + :						"m", 						"n",						"N",   // u014B						"h",						"",   // u0252						"",  // u0254 + :						"f",						"P",   // u03B8						"s",						"S",   // u0283						"",   // u0259						"",  // u025C + :						"v",						"D",   // u00F0						"z",						"Z",   //0292						null, null, null, null, null, null,						null, null, null, null, null, null						};										   	{		phonemes[ 36 ] = phonemes[ 6 ]  + phonemes[ 0 ];		phonemes[ 37 ] = phonemes[ 30 ] + phonemes[ 13 ];		phonemes[ 38 ] = "a"            + phonemes[ 0 ];		phonemes[ 39 ] = "a"  			+ phonemes[ 13 ];										   		phonemes[ 42 ] = ""            + phonemes[ 0 ];		phonemes[ 43 ] = phonemes[ 0 ]  + phonemes[ 30 ];		phonemes[ 44 ] = phonemes[ 6 ]  + phonemes[ 30 ];		phonemes[ 45 ] = phonemes[ 13 ] + phonemes[ 30 ];	}		public final String[] words = { 						"shIp",   // u026A						"shEEp",  // i  + :						"Yoghurt",						"Watch",						"CHurCH",  // u02A7						"Jug",  // u02A4						"bEd",						"cAr",  // u0251 + :						"Pen",						"TenT",						"King",						"Light",						"cAt",   // u00E6						"fOOt",   // u028A						"Bill",						"Desk",						"Girl",						"Road",						"cUp",   // u028C						"mOOn",  // u + :						"Milk", 						"Nose",						"riNG",   // u014B						"Hat",						"dOg",   // u0252						"hORse",  // u0254 + :						"Fish",						"THrow",   // u03B8						"Sun",						"SHower",   // u0283						"doctOR",   // u0259						"pURse",  // u025C + :						"Vase",						"moTHer",   // u00F0						"Zebra",						"treaSURE",   //0292						"tAble", "cOAt", "pIpe", "hOUse", null, null,						"bOY", "EAR", "bEAR", "jEWEl", null, null						};										   	private final Color darkGreen = new Color( 0, 128, 0 );	private final Color brown     = new Color( 128, 64, 64 );	private final Color purple    = new Color( 128, 0, 128 );										   	public final Color[] phonemeColors = { 										   Color.yellow,										   Color.yellow,										   darkGreen,										   darkGreen,										   Color.cyan,										   Color.cyan,										   Color.yellow,										   Color.yellow,										   Color.pink,										   Color.pink,										   Color.pink,										   Color.black,										   Color.yellow,										   Color.yellow,										   Color.pink,										   Color.pink,										   Color.pink,										   brown,										   Color.yellow,										   Color.yellow,										   Color.green,										   Color.green,										   Color.green,										   purple,										   Color.yellow,										   Color.yellow,										   purple,										   purple,										   purple,										   purple,										   Color.yellow,										   Color.yellow,										   purple,										   purple,										   purple,										   purple,										   Color.red,										   Color.red,										   Color.red,										   Color.red,										   null,										   null,										   Color.red,										   Color.red,										   Color.red,										   Color.red,										   null,										   null										   }; 		private TextArea textfield = null;	private Label wordLabel = null;	private Window tipWindow = null;											private void tip( String str, int x, int y ) {		wordLabel.setText( str );		Dimension size = wordLabel.getPreferredSize();		tipWindow.setSize( size );		tipWindow.setLocation( x, y - size.height -1 );		//tipWindow.pack();		tipWindow.setVisible( true );		//tipWindow.pack();	}		private void untip() {		tipWindow.setVisible( false );	}										   	public void init() {				setBackground( Color.lightGray );				Panel panel = new Panel();		panel.setBackground( Color.black );										   		int gridWidth = 6;		int gridHeight = 8;				GridLayout gridLayout = new GridLayout( gridHeight, gridWidth, 1, 1 );		panel.setLayout( gridLayout );												   		MouseAdapter mouseAdapter = new MouseAdapter() {			public void mouseClicked( MouseEvent me ) {				Object source = me.getSource();				Label label = (Label)source;				textfield.append( label.getText() );			}																	   			public void mouseEntered( MouseEvent me ) {				Object source = me.getSource();				Label label = (Label)source;				String phoneme = label.getText();				for ( int i = 0; i < phonemes.length; i++ ) {					if ( phoneme.equals( phonemes[ i ] ) ) {						//wordLabel.setText( words[ i ]);						Point pt = label.getLocationOnScreen();						tip( words[ i ], pt.x + me.getX() + label.getSize().width + 5,							 pt.y + me.getY() );										   						break;					}				}			}										   			public void mouseExited( MouseEvent me ) {				untip();			}					};										   		MouseMotionAdapter mouseMotionAdapter = new MouseMotionAdapter() {			public void mouseMoved( MouseEvent me ) {				Object source = me.getSource();				Label label = (Label)source;				String phoneme = label.getText();				for ( int i = 0; i < phonemes.length; i++ ) {					if ( phoneme.equals( phonemes[ i ] ) ) {						//wordLabel.setText( words[ i ]);						Point pt = label.getLocationOnScreen();						tip( words[ i ], pt.x + me.getX() + label.getSize().width + 5,							 pt.y + me.getY() );						break;					}				}			}		};						for ( int i = 0; i < phonemes.length; i++ ) {			String phoneme = phonemes[ i ];			Color color    = phonemeColors[ i ];						if ( phoneme != null ) {				Label label = new Label( phoneme, Label.CENTER );				label.setFont( new Font( "SILDoulosIPA-Regular", Font.PLAIN, 24 ) );				label.addMouseListener( mouseAdapter );				label.addMouseMotionListener( mouseMotionAdapter );				label.setForeground( color );				label.setBackground( Color.gray );				panel.add( label );			} 			else {				Label label = new Label("");				label.setBackground( Color.gray );				panel.add( label ); // empty label				}		}												   		BorderLayout layout = new BorderLayout();		setLayout( layout );				String fontName = "SILDoulosIPA-Regular";		Label fontLabel = new Label( "use: " + fontName, Label.CENTER );								   										   		textfield = new TextArea( 2, 20 );		textfield.setFont( new Font( fontName, Font.PLAIN, 24 ) );				   		textfield.setBackground( Color.white );		textfield.setForeground( Color.black );				textfield.setSize( 200, 40 );				Panel sidePanel = new Panel();				Panel controls = new Panel( new GridLayout( 4, 1, 20, 5 ) );				Button copy = new Button( "copy" );		copy.setActionCommand( "copy" );				Button back = new Button( "back" );		back.setActionCommand( "back" );										   		Button clearall = new Button( "clear all" );		clearall.setActionCommand( "clear all" );										   		ActionListener actionlistener = new ActionListener() {			public void actionPerformed( ActionEvent ae ) {				Object source = ae.getSource();				Button button = (Button)source;				String action =  button.getActionCommand();								if ( action.equals( "copy" ) ) {										Toolkit tk = getToolkit();					Clipboard clipboard = tk.getSystemClipboard();					StringSelection text = new StringSelection( textfield.getText() );					clipboard.setContents( text, text );				}				else if ( action.equals( "back" ) ) {					String text = textfield.getText();					textfield.replaceRange( "", text.length()-1, text.length() );				}				else if ( action.equals( "clear all" ) ) {					textfield.setText( "" );				}							}		};					copy.addActionListener( actionlistener );		back.addActionListener( actionlistener );		clearall.addActionListener( actionlistener );										   		controls.add( copy );		controls.add( back );		controls.add( clearall );		//controls.add( wordLabel );										   		sidePanel.add( controls );				Panel textPanel = new Panel( new BorderLayout() );		textPanel.add( BorderLayout.NORTH, textfield );		textPanel.add( BorderLayout.SOUTH, fontLabel );								   					add( BorderLayout.NORTH, textPanel );		add( BorderLayout.EAST, sidePanel );				add( BorderLayout.CENTER, panel );										   		tipWindow = new Window( (Frame)getParent() );		tipWindow.setLayout( new FlowLayout() );		tipWindow.setBackground( new Color( 250, 230, 245 ) );		wordLabel = new Label( "phoneme picker" );		tipWindow.add( wordLabel );		//tipWindow.show();		tipWindow.setVisible( true );		try {			Thread.sleep( 100 );		}		catch( Exception e) {		}		tipWindow.setVisible( false );	}											   	public static void main( String[] args ) {		Frame frame = new Frame( "Phonemes" );		WindowAdapter close = new WindowAdapter() {			public void windowClosing( WindowEvent we ) {				Window win = we.getWindow();				win.dispose();			}			public void windowClosed( WindowEvent we ) {				System.exit( 0 );			}		};				frame.addWindowListener( close );										   			PhonemePicker picker = new PhonemePicker();				frame.add( picker );		picker.init();		frame.pack();		frame.show();						/*Toolkit tk = frame.getToolkit();		String[] fontList = tk.getFontList();		for ( int i = 0; i < fontList.length; i++ ) {			System.out.println( fontList[ i ] );		}*/			}	}