Java Swing Text Format getElementIndex(Element elem)

Here you can find the source of getElementIndex(Element elem)

Description

get the index of a given element in the list of its parents elements.

License

Open Source License

Parameter

Parameter Description
elem the element to get the index number for

Return

the index of the given element

Declaration

public static int getElementIndex(Element elem) 

Method Source Code

//package com.java2s;
/*//from  w w w .j av  a 2  s  .  c o  m
 * This file is part of the Scriba source distribution. This is free, open-source 
 * software. For full licensing information, please see the LicensingInformation file
 * at the root level of the distribution.
 *
 * Copyright (c) 2006-2007 Kobrix Software, Inc.
 */

import javax.swing.text.Element;

public class Main {
    /**
     * get the index of a given element in the list of its parents elements.
     * 
     * @param elem the element to get the index number for
     * @return the index of the given element
     */
    public static int getElementIndex(Element elem) {
        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);
                }
            }
        }
        return i;
    }
}

Related

  1. formatCpfCnpj(String cpfCnpj)
  2. formatCpfCNPJ(String str)
  3. formatNumericString(String string, String mask)
  4. getBidiVisualPosition(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)
  5. getElementByPosition(final Element rootElement, final int pos)
  6. getRegexFormatter(String regex)
  7. getRowIndex(Element cell)
  8. getTrivialVisualPosition(final boolean toWest, final int pos, final Position.Bias bias, final int docLength, final Position.Bias[] biasRet, final boolean isLTR)