1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
/* * @(#)DocumentEvent.java 1.24 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.swing.event; import javax.swing.undo.*; import javax.swing.text.*; /** * Interface for document change notifications. This provides * detailed information to Document observers about how the * Document changed. It provides high level information such * as type of change and where it occurred, as well as the more * detailed structural changes (What Elements were inserted and * removed). * * @author Timothy Prinzing * @version 1.24 11/17/05 * @see javax.swing.text.Document * @see DocumentListener */ public interface DocumentEvent { /** * Returns the offset within the document of the start * of the change. * * @return the offset >= 0 */ public int getOffset(); /** * Returns the length of the change. * * @return the length >= 0 */ public int getLength(); /** * Gets the document that sourced the change event. * * @return the document */ public Document getDocument(); /** * Gets the type of event. * * @return the type */ public EventType getType(); /** * Gets the change information for the given element. * The change information describes what elements were * added and removed and the location. If there were * no changes, null is returned. * <p> * This method is for observers to discover the structural * changes that were made. This means that only elements * that existed prior to the mutation (and still exist after * the mutatino) need to have ElementChange records. * The changes made available need not be recursive. * <p> * For example, if the an element is removed from it's * parent, this method should report that the parent * changed and provide an ElementChange implementation * that describes the change to the parent. If the * child element removed had children, these elements * do not need to be reported as removed. * <p> * If an child element is insert into a parent element, * the parent element should report a change. If the * child element also had elements inserted into it * (grandchildren to the parent) these elements need * not report change. * * @param elem the element * @return the change information, or null if the * element was not modified */ public ElementChange getChange(Element elem); /** * Enumeration for document event types */ public static final class EventType { private EventType(String s) { typeString = s; } /** * Insert type. */ public static final EventType INSERT = new EventType("INSERT"); /** * Remove type. */ public static final EventType REMOVE = new EventType("REMOVE"); /** * Change type. */ public static final EventType CHANGE = new EventType("CHANGE"); /** * Converts the type to a string. * * @return the string */ public String toString() { return typeString; } private String typeString; } /** * Describes changes made to a specific element. */ public interface ElementChange { /** * Returns the element represented. This is the element * that was changed. * * @return the element */ public Element getElement(); /** * Fetches the index within the element represented. * This is the location that children were added * and/or removed. * * @return the index >= 0 */ public int getIndex(); /** * Gets the child elements that were removed from the * given parent element. The element array returned is * sorted in the order that the elements used to lie in * the document, and must be contiguous. * * @return the child elements */ public Element[] getChildrenRemoved(); /** * Gets the child elements that were added to the given * parent element. The element array returned is in the * order that the elements lie in the document, and must * be contiguous. * * @return the child elements */ public Element[] getChildrenAdded(); } }