import javax.swing.JTextArea; /** * * Class Output. Receives and despatches comments to the user. Will pass * messages and excitement levelsto OutputVocal if the user has demanded * vocal commentating. Will also handle the scheduling of the messages to * OutputVocal. This class also deals with any stats messages. * * @author Adrien Martel * */ public class Output { private OutputVocal vo; private int type; private JTextArea ta; /** * Create a new output class. * @type - 0 for cmd * @type - 1 for vocal * @type - 2 for vocal and cmd * */ public Output(int type, GUI gui) { this.type = type; if(type == 1 || type == 2){ vo = new OutputVocal(); vo.start(); } ta = gui.getTA(); } /** * Method out. Produces the relevant output to the user. * If type is 1 then the output is strictly vocal, 0 is * cmd output and 2 is the combined vocal and cmd line * output. * * @param output - the string to be outputted * */ public void out(String output) { if (type == 1 || type == 2){ //first we need to service //the parameter in outputVocal vo.serviceCommentator(output,-1); //then we let it know that there is a //new sentence in the variable if vo is //waiting. synchronized(vo){ vo.notify(); } } if (type == 0 || type == 2){ ta.append(">" + output + "\n"); ta.setCaretPosition(ta.getText().length()); } //System.out.println("[Commentator]: " + output); } /** * Overloaded method out. Same as out but the speech can * have varied excitement levels. * * @param output - the string to be output * @param param - the excitement level of the voice, see outputvocal * */ public void out(String output, int param) { if (type == 1 || type == 2){ //first we need to service //the parameter in outputVocal vo.serviceCommentator(output, param); synchronized(vo){ vo.notify(); } } if (type == 0 || type == 2){ ta.append(">" + output + "\n"); ta.setCaretPosition(ta.getText().length()); } //System.out.println("[Commentator %" + param + "]: " + output); } /** * Overloaded method out. Same as out but specifically for statistics. Any call * to this method should be for stats outputs only. * * @param output - the string to be output * @param stats - set to true or false will consider to be stats. * */ public void out(String output, boolean stats){ vo.serviceCommentator(output,stats); synchronized(vo){ vo.notify(); } if (type == 0 || type == 2){ ta.append("STATS >" + output + "\n"); ta.setCaretPosition(ta.getText().length()); } //System.out.print("[STATISTICS]: " + output); } //Returns the OutputVocal object (here for testing purposes) public OutputVocal getVo() { return vo; } }