Java JTextComponent adjustForLineComment(JTextComponent editor, int iStart)

Here you can find the source of adjustForLineComment(JTextComponent editor, int iStart)

Description

adjust For Line Comment

License

Apache License

Declaration

public static int adjustForLineComment(JTextComponent editor, int iStart) throws BadLocationException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import javax.swing.text.BadLocationException;

import javax.swing.text.Document;
import javax.swing.text.Element;
import javax.swing.text.JTextComponent;

public class Main {
    public static int adjustForLineComment(JTextComponent editor, int iStart) throws BadLocationException {
        Document doc = editor.getDocument();
        Element root = doc.getDefaultRootElement();
        Element line = root.getElement(root.getElementIndex(iStart));
        int iLineOffset = line.getStartOffset();
        int iLength = iStart - iLineOffset;
        if (iLength <= 0) {
            return iStart;
        }/* ww w. j  a va 2  s. co m*/
        String strLine = doc.getText(iLineOffset, iLength);
        if (strLine.contains("//")) {
            return iLineOffset;
        }
        return iStart;
    }
}

Related

  1. addChangeListener(JTextComponent text, ChangeListener changeListener)
  2. addJTextComponentListeners(JTextComponent c, Object... objs)
  3. addTextListener( JTextComponent c, Runnable listener )
  4. addTextUpdateListener(JTextComponent textComponent, Consumer listener)
  5. addUndoRedo(JTextComponent comp)
  6. appendToText(JTextComponent textComp, String s)
  7. applyDefaultProperties(final JTextComponent comp)
  8. biggestFont(final javax.swing.text.JTextComponent c)
  9. clear(JTextComponent... fields)