<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.util.*;
import java.io.*;

import Iota.util.*;

/**
 * Testing Iota.util.CodeWriter 
 */
public class CWTest
{
	public static void main (String[] args) throws Exception 
	{
		CodeWriter cw;
		
		//create a new CodeWriter object, set the right
		//margin(line width) as 60. 
		cw = new CodeWriter(System.out, 60);
		
		//Begin a new block.
		cw.begin(4);
		cw.write("(This is block 1:");
		cw.allowBreak(0, " ");
		cw.write("item1,");
		cw.allowBreak(0, " ");
		cw.write("item2,");
		cw.allowBreak(0, " ");
		cw.write("item3)");
		cw.end();
		
		//start a new line
		cw.newline(0);
		
		//Begin another block
		cw.begin(4);
		//The first line will start at the current position without
		//indentation. 
		cw.write("(This is block 2:");
		cw.allowBreak(0, " ");
		cw.write("long item 1**********,");
		cw.allowBreak(0, " ");
		cw.write("long item 2**********,");
		cw.allowBreak(0, " ");
		cw.write("long item 3**********,");
		cw.allowBreak(0, " ");
		
		cw.begin(4);
		cw.write("(This is an embeded block.");
		cw.allowBreak(0, " ");
		cw.write("subitem1)");
		cw.allowBreak(0, " ");
		cw.end();
		cw.allowBreak(0, " ");
		
		cw.begin(4);
		cw.write("(This is another embeded block.");
		cw.allowBreak(0, " ");
		cw.write("subitem1,"); 
		cw.allowBreak(0, " ");
		cw.write("subitem2,");
		cw.allowBreak(0, " ");
		cw.write("subitem3)");
		cw.end();
		cw.end();
		
		cw.allowBreak(0, " ");
		
		//Begin another block, virtually similar to the first block
		//except replacing a "allowBreak" with a "newLine". Because
		//there exists one "newLine" item, every other "allowBreak"
		//items will cause a line change. 
		cw.begin(4);
		cw.write("(This is block 3:");
		cw.allowBreak(0, " ");
		cw.write("item1,");
		cw.newline();
		cw.write("item2,");
		cw.allowBreak(0, " ");
		cw.write("item3)");
		cw.end();

		cw.flush();
	}
}
</pre></body></html>