Search in sources :

Example 11 with XTextCursor

use of com.sun.star.text.XTextCursor in project jabref by JabRef.

the class OOBibBase method italicizeOrBold.

private void italicizeOrBold(XTextCursor position, boolean italicize, int start, int end) throws UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException {
    XTextRange range = position.getStart();
    XTextCursor cursor = position.getText().createTextCursorByRange(range);
    cursor.goRight((short) start, false);
    cursor.goRight((short) (end - start), true);
    XPropertySet xcp = UnoRuntime.queryInterface(XPropertySet.class, cursor);
    if (italicize) {
        xcp.setPropertyValue("CharPosture", com.sun.star.awt.FontSlant.ITALIC);
    } else {
        xcp.setPropertyValue("CharWeight", com.sun.star.awt.FontWeight.BOLD);
    }
}
Also used : XPropertySet(com.sun.star.beans.XPropertySet) XTextRange(com.sun.star.text.XTextRange) XTextCursor(com.sun.star.text.XTextCursor)

Example 12 with XTextCursor

use of com.sun.star.text.XTextCursor in project zotero-libreoffice-integration by zotero.

the class ReferenceMark method delete.

public void delete() throws Exception {
    if (isWholeRange()) {
        ((XComponent) UnoRuntime.queryInterface(XComponent.class, text)).dispose();
    } else {
        XTextCursor dupRange = text.createTextCursorByRange(range);
        text.removeTextContent(textContent);
        range = dupRange;
        // dispose of a Bookmark or TextSection
        if (isDisposable) {
            ((XComponent) UnoRuntime.queryInterface(XComponent.class, textContent)).dispose();
        }
    }
}
Also used : XComponent(com.sun.star.lang.XComponent) XTextCursor(com.sun.star.text.XTextCursor)

Example 13 with XTextCursor

use of com.sun.star.text.XTextCursor in project zotero-libreoffice-integration by zotero.

the class ReferenceMark method prepareMultiline.

protected void prepareMultiline() throws Exception {
    if (!isTextSection) {
        // need to convert to TextSection
        delete();
        // if this is not done, it's hard to add text after the TextSection
        if (doc.textRangeCompare.compareRegionEnds(doc.text.getEnd(), range.getEnd()) == 0) {
            doc.text.insertControlCharacter(doc.text.getEnd(), ControlCharacter.PARAGRAPH_BREAK, false);
            doc.text.insertControlCharacter(doc.text.getEnd(), ControlCharacter.PARAGRAPH_BREAK, false);
            XTextCursor cursor = doc.text.createTextCursorByRange(doc.text.getEnd());
            cursor.goLeft((short) 1, false);
            cursor.goLeft((short) 1, true);
            range = cursor;
        }
        named = (XNamed) UnoRuntime.queryInterface(XNamed.class, doc.docFactory.createInstance("com.sun.star.text.TextSection"));
        named.setName(rawCode);
        textContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, named);
        textContent.attach(range);
        isTextSection = true;
        isDisposable = true;
    }
}
Also used : XTextCursor(com.sun.star.text.XTextCursor)

Example 14 with XTextCursor

use of com.sun.star.text.XTextCursor in project zotero-libreoffice-integration by zotero.

the class ReferenceMark method select.

public void select() throws Exception {
    XTextCursor cursor = doc.getSelection();
    cursor.gotoRange(range, false);
    if (isTextSection) {
        cursor.goLeft((short) 1, true);
    }
}
Also used : XTextCursor(com.sun.star.text.XTextCursor)

Example 15 with XTextCursor

use of com.sun.star.text.XTextCursor in project zotero-libreoffice-integration by zotero.

the class Document method insertField.

public ReferenceMark insertField(String fieldType, int noteType) throws Exception {
    // duplicate selection cursor
    XTextViewCursor selectionCursor = getSelection();
    XTextCursor rangeToInsert = (XParagraphCursor) UnoRuntime.queryInterface(XParagraphCursor.class, selectionCursor.getText().createTextCursorByRange(selectionCursor));
    return insertMarkAtRange(fieldType, noteType, rangeToInsert, null, null);
}
Also used : XParagraphCursor(com.sun.star.text.XParagraphCursor) XTextCursor(com.sun.star.text.XTextCursor) XTextViewCursor(com.sun.star.text.XTextViewCursor)

Aggregations

XTextCursor (com.sun.star.text.XTextCursor)15 UnknownPropertyException (com.sun.star.beans.UnknownPropertyException)4 XPropertySet (com.sun.star.beans.XPropertySet)4 WrappedTargetException (com.sun.star.lang.WrappedTargetException)4 Point (com.sun.star.awt.Point)3 PropertyVetoException (com.sun.star.beans.PropertyVetoException)3 IllegalArgumentException (com.sun.star.lang.IllegalArgumentException)3 XTextContent (com.sun.star.text.XTextContent)3 XNameAccess (com.sun.star.container.XNameAccess)2 XComponent (com.sun.star.lang.XComponent)2 XTextRange (com.sun.star.text.XTextRange)2 XTextSection (com.sun.star.text.XTextSection)2 XTextSectionsSupplier (com.sun.star.text.XTextSectionsSupplier)2 ArrayList (java.util.ArrayList)2 BibDatabase (org.jabref.model.database.BibDatabase)2 BibEntry (org.jabref.model.entry.BibEntry)2 IllegalTypeException (com.sun.star.beans.IllegalTypeException)1 NotRemoveableException (com.sun.star.beans.NotRemoveableException)1 PropertyExistException (com.sun.star.beans.PropertyExistException)1 XMultiPropertyStates (com.sun.star.beans.XMultiPropertyStates)1