Java Utililty Methods Swing Text Format

List of utility methods to do Swing Text Format

Description

The list of methods to do Swing Text Format are organized into topic(s).

Method

intgetBidiVisualPosition(final int start, final int end, final Element neighbouringElement, final int pos, final Position.Bias b0, final Position.Bias[] biasRet, final int length, final boolean toWest, final boolean isLTR)
get Bidi Visual Position
boolean direction = toWest ^ isLTR;
if (pos == end && direction && b0 == forward) {
    biasRet[0] = backward;
    return pos + 1;
} else if (pos == start + 1 && pos <= end && !direction) {
    return pos - 1;
} else if (pos == start) {
    if (direction) {
...
ElementgetElementByPosition(final Element rootElement, final int pos)
get Element By Position
int index = rootElement.getElementIndex(pos);
return rootElement.getElement(index);
intgetElementIndex(Element elem)
get the index of a given element in the list of its parents elements.
int i = 0;
Element parent = elem.getParentElement();
if (parent != null) {
    int last = parent.getElementCount() - 1;
    Element anElem = parent.getElement(i);
    if (anElem != elem) {
        while ((i < last) && (anElem != elem)) {
            anElem = parent.getElement(++i);
...
DefaultFormattergetRegexFormatter(String regex)
get Regex Formatter
final Pattern pattern = Pattern.compile(regex);
DefaultFormatter formatter = new DefaultFormatter() {
    @Override
    public Object stringToValue(String text) throws ParseException {
        Matcher matcher = pattern.matcher(text);
        if (matcher.matches())
            return text;
        throw new ParseException("Pattern did not match", 0);
...
intgetRowIndex(Element cell)
get the row index for a given table cell
Element thisRow = cell.getParentElement();
Element table = thisRow.getParentElement();
int index = 0;
int count = table.getElementCount();
Element elem = table.getElement(index);
while (!elem.equals(thisRow) && index < count) {
    elem = table.getElement(++index);
return index;
intgetTrivialVisualPosition(final boolean toWest, final int pos, final Position.Bias bias, final int docLength, final Position.Bias[] biasRet, final boolean isLTR)
get Trivial Visual Position
boolean condition = (toWest && isLTR) || (!toWest && !isLTR);
return condition ? Math.max(pos - 1, 0) : Math.min(pos + 1, docLength);