/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License.
*/
/** * Marks hold the relative position in the document. * * @author Miloslav Metelka * @version 1.00 * @deprecated Use {@link Position} instead.
*/
@Deprecated publicclass Mark {
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 * {@link javax.swing.text.Position.Bias#Forward} * or {@link javax.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. * @param backwardBias whether the inserts performed right at the position * of this mark will go after this mark i.e. this mark will not move * forward when inserting right at its position. This flag corresponds * 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. * Replaced by {@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 * {@link javax.swing.text.Position.Bias#Forward} * or {@link javax.swing.text.Position.Bias#Backward}.
*/ publicfinal Position.Bias getBias() { return bias;
}
/** Mark will no longer represent a valid place in the document. * Although it will not be removed from the structure that holds * the marks it will be done later automatically.
*/ 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 * be inserted again into some document.
*/ publicfinalvoid remove() throws InvalidMarkException {
dispose();
}
/** Compare this mark to some position. * @param pos tested position * @return zero - if the marks have the same position * less than zero - if this mark is before the position * greater than zero - if this mark is after the position
*/ publicfinalint compare(int pos) throws InvalidMarkException { return getOffset() - pos;
}
/** This function is called from removeUpdater when mark occupies * the removal area. The mark can decide what to do next. * If it doesn't redefine this method it will be simply moved to * the begining of removal area. It is valid to add or remove other mark * from this method. It is even possible (but not very useful) * to add the mark to the removal area. However that mark will not be * notified about current removal. * @deprecated It will not be supported in the future.
*/ protectedvoid removeUpdateAction(int pos, int len) {
}
/** @return true if this mark is currently inserted in the document * or false otherwise.
*/ 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()) : "") // 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 ist noch experimentell.