package OT; import java.awt.*; import java.applet.*; import java.net.*; import java.util.*; /** * Representation drawing. * @version 1999-04-02 * @author Andrea Heiberg, University of Arizona */ public class RepPanel extends Panel { private boolean drawInert = false; private boolean drawColor = true; private boolean drawTokens = true; private boolean drawHeads = true; private Image rootImage; private Image moraImage; private Image syllImage; private Representation rep; private int vSpace = 24; //vertical space between rows private int vFeatureSpace = 10; //vertical space between feature rows private int rootHeight = 15; //root graphic height private int rootWidth = 9; //root graphic width private int moraHeight = 20; //mora graphic height private int moraWidth = 11; //mora graphic width private int syllHeight = 15; //syllable graphic height private int syllWidth = 10; //syllable graphic width public RepPanel(Representation rep, Image rootImage, Image moraImage, Image syllImage, boolean drawInert, boolean drawColor, boolean drawTokens, boolean drawHeads) { this.rootImage = rootImage; this.moraImage = moraImage; this.syllImage = syllImage; this.drawInert = drawInert; this.drawColor = drawColor; this.drawTokens = drawTokens; this.drawHeads = drawHeads; this.rep = rep; rep.assignCoordinates(275, vSpace, 0, vFeatureSpace); //assign coordinates to rep } //end constructor public void paint(Graphics g) { int x = 0; int y = 0; FontMetrics fm = g.getFontMetrics(); int height = fm.getHeight(); g.drawString(rep.toOrthography() + " '" + rep.gloss + "'", 5, 20); //draw PrWds for (Enumeration e = rep.prwdNodes.elements(); e.hasMoreElements();) { PrWd node = (PrWd)e.nextElement(); String s = "PrWd"; int width = fm.stringWidth(s); g.drawString( s, node.x - width/2, node.y + height ); writeDiacritics(g, node, height, width, false); } //end for //draw feet for (Enumeration e = rep.footNodes.elements(); e.hasMoreElements();) { Foot node = (Foot)e.nextElement(); String nodeString = node.toString(); boolean head = false; Enumeration z = rep.prwdNodes.elements(); while (!head && z.hasMoreElements()) { ProsodicNode a = (ProsodicNode)z.nextElement(); if (a.head != null) { if (nodeString.equals(a.head.toString())) { head = true; } //end if } //end if } //end while String s = "Foot"; if (head && drawHeads) s = "[" + s + "]"; int width = fm.stringWidth(s); g.drawString( s, node.x - width/2, node.y + height ); writeDiacritics(g, node, height, width, false); } //end for //draw syllables for (Enumeration e = rep.syllableNodes.elements(); e.hasMoreElements();) { Syllable node = (Syllable)e.nextElement(); String nodeString = node.toString(); boolean head = false; Enumeration z = rep.footNodes.elements(); while (!head && z.hasMoreElements()) { ProsodicNode a = (ProsodicNode)z.nextElement(); if (a.head != null) { if (nodeString.equals(a.head.toString())) { head = true; } //end if } //end if } //end while g.drawImage( syllImage, node.x - (syllWidth/2), node.y, this); writeDiacritics(g, node, syllHeight, syllWidth, head); } //end for //draw moras for (Enumeration e = rep.moraNodes.elements(); e.hasMoreElements();) { Mora node = (Mora)e.nextElement(); String nodeString = node.toString(); boolean head = false; Enumeration z = rep.syllableNodes.elements(); while (!head && z.hasMoreElements()) { ProsodicNode a = (ProsodicNode)z.nextElement(); if (a.head != null) { if (nodeString.equals(a.head.toString())) { head = true; } //end if } //end if } //end while g.drawImage( moraImage, node.x - (moraWidth/2), node.y, this); writeDiacritics(g, node, moraHeight, moraWidth, head); } //end for //draw roots for (Enumeration e = rep.rootNodes.elements(); e.hasMoreElements();) { Root node = (Root)e.nextElement(); String nodeString = node.toString(); boolean head = false; Enumeration z = rep.moraNodes.elements(); while (!head && z.hasMoreElements()) { ProsodicNode a = (ProsodicNode)z.nextElement(); if (a.head != null) { if (nodeString.equals(a.head.toString())) { head = true; } //end if } //end if } //end while g.drawImage( rootImage, node.x - (rootWidth/2), node.y, this); writeDiacritics(g, node, rootHeight, rootWidth, head); } //end for //draw associations between roots and features for (Enumeration e = rep.rootAssociations.elements(); e.hasMoreElements();) { Association association = (Association)e.nextElement(); Feature f = (Feature)association.child; if (drawInert || !f.featureType.inert) { if (drawColor) g.setColor(f.featureType.color); g.drawLine( association.parent.x, association.parent.y + rootHeight, association.child.x, association.child.y); } //end if } //end for g.setColor(Color.black); //draw features for (Enumeration e = rep.featureTypeSet.elements(); e.hasMoreElements();) { FeatureTokenSet featureTokens = (FeatureTokenSet)e.nextElement(); for (Enumeration f = featureTokens.elements(); f.hasMoreElements();) { Feature feature = (Feature)f.nextElement(); if (drawInert || !feature.featureType.inert) { x = feature.x; String fname = feature.featureType.name; if (drawTokens) fname = fname + ":" + feature.token; if (feature.ordered) fname = fname + " >"; if (x == 0) { //floating x = 10; y = feature.y + height; } else { x = x - (fm.stringWidth(fname) / 2); y = feature.y + height; } //end if if (drawColor) g.setColor(feature.featureType.color); g.drawString( fname, x, y); } //end if } //end for } //end for g.setColor(Color.black); //draw associations between moras and roots for (Enumeration e = rep.moraAssociations.elements(); e.hasMoreElements();) { Association association = (Association)e.nextElement(); g.drawLine( association.parent.x, association.parent.y + moraHeight, association.child.x, association.child.y); } //end for //draw associations between syllables and moras, syllables and roots for (Enumeration e = rep.syllableAssociations.elements(); e.hasMoreElements();) { Association association = (Association)e.nextElement(); g.drawLine( association.parent.x, association.parent.y + syllHeight, association.child.x, association.child.y); } //end for //draw associations between feet and syllables for (Enumeration e = rep.footAssociations.elements(); e.hasMoreElements();) { Association association = (Association)e.nextElement(); g.drawLine( association.parent.x, association.parent.y + g.getFontMetrics().getHeight() + 2, association.child.x, association.child.y); } //end for //draw associations between PrWds and feet for (Enumeration e = rep.prwdAssociations.elements(); e.hasMoreElements();) { Association association = (Association)e.nextElement(); g.drawLine( association.parent.x, association.parent.y + g.getFontMetrics().getHeight() + 2, association.child.x, association.child.y); } //end for } //end paint private void writeDiacritics(Graphics g, Node node, int nodeHeight, int nodeWidth, boolean head) { String leftBracket = "["; String rightBracket = "]"; int subscriptSize = 4; FontMetrics fm = g.getFontMetrics(); int height = fm.getHeight(); int offset = 0; int rightOffset = nodeWidth - nodeWidth/2; if (drawHeads && head) { g.drawString( leftBracket, node.x - nodeWidth, node.y + height ); g.drawString( rightBracket, node.x + rightOffset, node.y + height ); offset = fm.stringWidth(rightBracket); } //end if if (drawTokens) { Font f = g.getFont(); g.setFont(new Font(f.getName(), f.getStyle(), subscriptSize)); g.drawString( node.token, node.x + rightOffset + offset, node.y + height + (nodeHeight / 2) ); g.setFont(f); } //end if } //end writeDiacritics }