Example: Selection

This example copies the first paragraph, and then replaces the content of the second paragraph with the first paragraph's content.

import com.ibm.symphony.javaapi.Application;
import com.ibm.symphony.javaapi.document.Document;
import com.ibm.symphony.javaapi.document.Documents;
import com.ibm.symphony.javaapi.document.Selection;
import com.ibm.symphony.javaapi.document.TextRange;

public class SelectionExample {

	public void example() {
		try {
			Application application = Application.getInstance();
			Documents documents = application.getDocuments();
			Document document = documents
					.openDocument("D:\\document.ott", true);
			Selection selection = document.getSelection();
			TextRange range = document.getParagraphs().item(1).getRange();
			selection.setRange(range.getStart(), range.getEnd());
			selection.copy();
			range = document.getParagraphs().item(2).getRange();
			selection.setRange(range.getStart(), range.getEnd());
			selection.paste();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

Related information

Selection

Selection property in Document