001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021package org.biojava.bio.program.tagvalue; 022 023/** 024 * <p> 025 * A simple listener that just echoes events back to the console. 026 * </p> 027 * 028 * @author Matthew Pocock 029 * @since 1.3 030 */ 031public class Echo implements TagValueListener { 032 private int depth = 0; 033 private String indent = ""; 034 035 public void startRecord() { 036 System.out.println(depth + indent + "["); 037 indent(); 038 } 039 040 public void endRecord() { 041 outdent(); 042 System.out.println(depth + indent + "]"); 043 } 044 045 public void startTag(Object tag) { 046 System.out.println(depth + indent + tag + " {"); 047 indent(); 048 } 049 050 public void endTag() { 051 outdent(); 052 System.out.println(depth + indent + "}"); 053 } 054 055 private void indent() { 056 depth += 1; 057 indent += " "; 058 } 059 060 private void outdent() { 061 indent = ""; 062 depth--; 063 for(int i = 0; i < depth; i++) { 064 indent += " "; 065 } 066 } 067 068 public void value(TagValueContext tvc, Object value) { 069 System.out.println(depth + indent + value); 070 } 071} 072