Search in sources :

Example 1 with XFootnote

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

the class OOBibBase method getSortedReferenceMarks.

private List<String> getSortedReferenceMarks(final XNameAccess nameAccess) throws WrappedTargetException, NoSuchElementException {
    XTextViewCursorSupplier cursorSupplier = UnoRuntime.queryInterface(XTextViewCursorSupplier.class, mxDoc.getCurrentController());
    XTextViewCursor viewCursor = cursorSupplier.getViewCursor();
    XTextRange initialPos = viewCursor.getStart();
    List<String> names = Arrays.asList(nameAccess.getElementNames());
    List<Point> positions = new ArrayList<>(names.size());
    for (String name : names) {
        XTextContent textContent = UnoRuntime.queryInterface(XTextContent.class, nameAccess.getByName(name));
        XTextRange range = textContent.getAnchor();
        // Check if we are inside a footnote:
        if (UnoRuntime.queryInterface(XFootnote.class, range.getText()) != null) {
            // Find the linking footnote marker:
            XFootnote footer = UnoRuntime.queryInterface(XFootnote.class, range.getText());
            // The footnote's anchor gives the correct position in the text:
            range = footer.getAnchor();
        }
        positions.add(findPosition(viewCursor, range));
    }
    Set<ComparableMark> set = new TreeSet<>();
    for (int i = 0; i < positions.size(); i++) {
        set.add(new ComparableMark(names.get(i), positions.get(i)));
    }
    List<String> result = new ArrayList<>(set.size());
    for (ComparableMark mark : set) {
        result.add(mark.getName());
    }
    viewCursor.gotoRange(initialPos, false);
    return result;
}
Also used : XTextRange(com.sun.star.text.XTextRange) ArrayList(java.util.ArrayList) Point(com.sun.star.awt.Point) Point(com.sun.star.awt.Point) XTextViewCursorSupplier(com.sun.star.text.XTextViewCursorSupplier) XFootnote(com.sun.star.text.XFootnote) XTextContent(com.sun.star.text.XTextContent) TreeSet(java.util.TreeSet) XTextViewCursor(com.sun.star.text.XTextViewCursor)

Aggregations

Point (com.sun.star.awt.Point)1 XFootnote (com.sun.star.text.XFootnote)1 XTextContent (com.sun.star.text.XTextContent)1 XTextRange (com.sun.star.text.XTextRange)1 XTextViewCursor (com.sun.star.text.XTextViewCursor)1 XTextViewCursorSupplier (com.sun.star.text.XTextViewCursorSupplier)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1