Java Code Examples for javax.swing.text.Position.Bias#Forward

The following examples show how to use javax.swing.text.Position.Bias#Forward . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableUISupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public int getNextMatch(String prefix, int startIndex, Bias bias) {
    ListModel model = getModel();
    if (!(model instanceof TableModel)) {
        return super.getNextMatch(prefix, startIndex, bias);
    }
    TableModel tablesModel = (TableModel)model;
    int max = tablesModel.getSize();
    int increment = (bias == Bias.Forward) ? 1 : -1;
    int index = startIndex;
    prefix = prefix.toUpperCase();
    do {
        Table table = tablesModel.getElementAt(index);
        String tableName = table.getName().toUpperCase();
        if (tableName.startsWith(prefix)) {
            return index;
        }
        index = (index + increment + max) % max;
    } while (index != startIndex);
    return -1;
}
 
Example 2
Source File: TableUISupport.java    From jeddict with Apache License 2.0 6 votes vote down vote up
@Override
public int getNextMatch(String prefix, int startIndex, Bias bias) {
    ListModel model = getModel();
    if (!(model instanceof TableModel)) {
        return super.getNextMatch(prefix, startIndex, bias);
    }
    TableModel tablesModel = (TableModel) model;
    int max = tablesModel.getSize();
    int increment = (bias == Bias.Forward) ? 1 : -1;
    int index = startIndex;
    prefix = prefix.toUpperCase();
    do {
        Table table = tablesModel.getElementAt(index);
        String tableName = table.getName().toUpperCase();
        if (tableName.startsWith(prefix)) {
            return index;
        }
        index = (index + increment + max) % max;
    } while (index != startIndex);
    return -1;
}
 
Example 3
Source File: Mark.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void insert(BaseDocument doc, int offset) throws InvalidMarkException, BadLocationException {
     BaseDocument ldoc = this.doc;
     if (ldoc != null) {
         throw new InvalidMarkException("Mark already inserted: mark=" + this // NOI18N
             + ", class=" + this.getClass()); // NOI18N
     }

     this.doc = doc;
     ldoc = this.doc;
     synchronized (ldoc) {
         if (pos != null) {
             throw new IllegalStateException("Mark already inserted: mark=" + this // NOI18N
             + ", class=" + this.getClass()); // NOI18N
         }

if (offset < 0 || offset > ldoc.getLength() + 1) { // doc.getEndPosition() is valid
	throw new BadLocationException("Invalid offset", offset); // NOI18N
}

// Deal with supplementary characters #164820

if (offset <= ldoc.getLength() && Character.isLowSurrogate(org.netbeans.lib.editor.util.swing.DocumentUtilities.getText(ldoc).charAt(offset))) {
	if (bias == Bias.Forward && offset < ldoc.getLength()) {
		offset++;

	} else if (bias == Bias.Backward && offset > 0) {
		offset--;
	}
	
	// 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.
}

         pos = doc.createPosition(offset, bias);
     }
 }
 
Example 4
Source File: TabView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public int getNextVisualPositionFromChecked(int offset, Bias bias, Shape alloc, int direction, Bias[] biasRet) {
    int startOffset = getStartOffset();
    int endOffset = startOffset + getLength();
    int retOffset = -1;
    switch (direction) {
        case EAST:
            biasRet[0] = Bias.Forward;
            if (offset == -1) {
                retOffset = getStartOffset();
            } else {
                retOffset = offset + 1;
                if (retOffset >= endOffset) {
                    retOffset = endOffset;
                    biasRet[0] = Bias.Backward;
                }
            }
            break;

        case WEST:
            biasRet[0] = Bias.Forward;
            if (offset == -1) {
                retOffset = endOffset - 1;
            } else {
                retOffset = offset - 1;
                if (retOffset < startOffset) {
                    retOffset = -1;
                }
            }
            break;

        case View.NORTH:
        case View.SOUTH:
            break; // Return -1
        default:
            throw new IllegalArgumentException("Bad direction: " + direction);
    }
    return retOffset;
}
 
Example 5
Source File: NewlineView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public int getNextVisualPositionFromChecked(int offset, Bias bias, Shape alloc, int direction, Bias[] biasRet) {
    int retOffset;
    biasRet[0] = Bias.Forward; // BaseCaret ignores bias
    int viewStartOffset = getStartOffset();
    switch (direction) {
        case View.EAST:
            if (offset == -1) {
                retOffset = viewStartOffset;
            } else {
                retOffset = -1;
            }
            break;

        case View.WEST:
            if (offset == -1) {
                retOffset = viewStartOffset;
            } else if (offset == viewStartOffset) { // Regular offset
                retOffset = -1;
            } else {
                retOffset = viewStartOffset;
            }
            break;

        case View.NORTH:
        case View.SOUTH:
            retOffset = -1;
            break;
        default:
            throw new IllegalArgumentException("Bad direction: " + direction);
    }
    return retOffset;
}