privatestaticfinal MarkComparator MARK_COMPARATOR = new MarkComparator();
/** Document to which this mark belongs. */ private BaseDocument doc;
/** Position to which this mark delegates. */ private Position pos;
/** Bias of the mark. It is either *{@linkjavax.swing.text.Position.Bias#Forward} *or{@linkjavax.swing.text.Position.Bias#Backward}
*/ private Position.Bias bias;
/** Construct new mark with forward bias. */ public Mark() { this(Position.Bias.Forward);
}
public Mark(Position.Bias bias) { this.bias = bias;
}
/** Construct new mark. *@parambackwardBiaswhethertheinsertsperformedrightattheposition *ofthismarkwillgoafterthismarki.e.thismarkwillnotmove *forwardwheninsertingrightatitsposition.Thisflagcorresponds *to<code>Position.Bias.Backward</code>.
*/ public Mark(boolean backwardBias) { this(backwardBias ? Position.Bias.Backward : Position.Bias.Forward);
}
// If there is still a low surrogate after recalculating, // treat it as an invalid document, just ignore and pass through. // Since there should be a surrogate pair in Java and Unicode to // represent a supplementary character.
}
/** Get the position of this mark */ publicfinalint getOffset() throws InvalidMarkException {
BaseDocument ldoc = doc; if (ldoc != null) { synchronized (ldoc) { if (pos != null) { return pos.getOffset();
} else { thrownew InvalidMarkException();
}
}
} else { thrownew InvalidMarkException();
}
}
/** Get the line number of this mark */ publicfinalint getLine() throws InvalidMarkException {
BaseDocument ldoc = doc; if (ldoc != null) { synchronized (ldoc) { if (pos != null) { int offset = pos.getOffset();
Element lineRoot = ldoc.getParagraphElement(0).getParentElement(); return lineRoot.getElementIndex(offset);
/** Get the insertAfter flag. *Replacedby{@link#getBackwardBias()} *@deprecated
*/ publicfinalboolean getInsertAfter() { return (bias == Position.Bias.Backward);
}
/** @return true if the mark has backward bias or false if it has forward bias.
*/ publicfinalboolean getBackwardBias() { return getInsertAfter();
}
/** @return the bias of this mark. It will be either *{@linkjavax.swing.text.Position.Bias#Forward} *or{@linkjavax.swing.text.Position.Bias#Backward}.
*/ publicfinal Position.Bias getBias() { return bias;
}
/** Mark will no longer represent a valid place in the document. *Althoughitwillnotberemovedfromthestructurethatholds *themarksitwillbedonelaterautomatically.
*/ publicfinalvoid dispose() {
BaseDocument ldoc = doc; if (ldoc != null) { synchronized (ldoc) { if (pos != null) {
pos = null; this.doc = null; return;
}
}
}
/** Remove mark from the structure holding the marks. The mark can *beinsertedagainintosomedocument.
*/ publicfinalvoid remove() throws InvalidMarkException {
dispose();
}
/** Compare this mark to some position. *@parampostestedposition *@returnzero-ifthemarkshavethesameposition *lessthanzero-ifthismarkisbeforetheposition *greaterthanzero-ifthismarkisaftertheposition
*/ publicfinalint compare(int pos) throws InvalidMarkException { return getOffset() - pos;
}
/** This function is called from removeUpdater when mark occupies *theremovalarea.Themarkcandecidewhattodonext. *Ifitdoesn'tredefinethismethoditwillbesimplymovedto *thebeginingofremovalarea.Itisvalidtoaddorremoveothermark *fromthismethod.Itisevenpossible(butnotveryuseful) *toaddthemarktotheremovalarea.Howeverthatmarkwillnotbe *notifiedaboutcurrentremoval. *@deprecatedItwillnotbesupportedinthefuture.
*/ protectedvoid removeUpdateAction(int pos, int len) {
}
/** @return true if this mark is currently inserted in the document *orfalseotherwise.
*/ publicfinalboolean isValid() {
BaseDocument ldoc = doc; if (ldoc != null) { synchronized (ldoc) { return (pos != null);
}
}
returnfalse;
}
/** Get info about <CODE>Mark</CODE>. */ public @Override String toString() { return"offset=" + (isValid() ? Integer.toString(pos.getOffset()) : "<invalid>") // NOI18N
+ ", bias=" + bias; // NOI18N
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.