本文整理汇总了Java中com.sun.star.text.XTextRangeCompare类的典型用法代码示例。如果您正苦于以下问题:Java XTextRangeCompare类的具体用法?Java XTextRangeCompare怎么用?Java XTextRangeCompare使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XTextRangeCompare类属于com.sun.star.text包,在下文中一共展示了XTextRangeCompare类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTextFields
import com.sun.star.text.XTextRangeCompare; //导入依赖的package包/类
/**
* Returns all available text fields.
*
* @return all available text fields
*
* @author Andreas Bröker
*/
public ITextField[] getTextFields() {
ArrayList arrayList = new ArrayList();
XTextCursor textCursor = xTextRange.getText().createTextCursorByRange(xTextRange.getStart());
XTextRangeCompare xTextRangeCompare = (XTextRangeCompare)UnoRuntime.queryInterface(XTextRangeCompare.class, xTextRange.getText());
try {
while(xTextRangeCompare.compareRegionEnds(textCursor.getStart(), xTextRange.getEnd()) != -1) {
XPropertySet propertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, textCursor);
Any any = (Any)propertySet.getPropertyValue("TextField");
XTextField xTextField = (XTextField)any.getObject();
if(xTextField != null)
arrayList.add(new TextField(textDocument, xTextField));
if(!textCursor.goRight((short)1, false))
break;
}
}
catch(Exception exception) {
//do nothing
}
ITextField[] textFields = new ITextField[arrayList.size()];
return (ITextField[])arrayList.toArray(textFields);
}
示例2: startsWithSection
import com.sun.star.text.XTextRangeCompare; //导入依赖的package包/类
/**
* Liefert true gdw der Start von doc mit dem Starter einer Section von doc
* zusammenfällt.
*
* @author Matthias Benkmann (D-III-ITD 5.1) TESTED
*/
private static boolean startsWithSection(XTextDocument doc)
{
XTextRange docText = doc.getText();
XTextRangeCompare compare = UNO.XTextRangeCompare(docText);
XNameAccess sections = UNO.XTextSectionsSupplier(doc).getTextSections();
String[] names = sections.getElementNames();
for (int i = 0; i < names.length; ++i)
{
try
{
XTextRange range =
UNO.XTextContent(sections.getByName(names[i])).getAnchor();
if (compare.compareRegionStarts(docText, range) == 0) return true;
}
catch (Exception x)
{
Logger.error(x);
}
}
return false;
}
示例3: selectionChanged
import com.sun.star.text.XTextRangeCompare; //导入依赖的package包/类
/**
* Nimmt eine Menge von XTextRange Objekten, sucht alle umschlossenen Bookmarks und
* broadcastet eine entsprechende Nachricht, damit sich die entsprechenden Objekte
* selektieren.
*
* @author Matthias Benkmann (D-III-ITD 5.1) TESTED
*/
public void selectionChanged(XIndexAccess access)
{
Set<String> names = new HashSet<String>();
int count = access.getCount();
for (int i = 0; i < count; ++i)
{
XEnumerationAccess enuAccess = null;
try
{
XTextRange range = UNO.XTextRange(access.getByIndex(i));
enuAccess = UNO.XEnumerationAccess(range);
handleParagraphEnumeration(names, enuAccess,
UNO.XTextRangeCompare(range.getText()), range, false);
}
catch (Exception x)
{
Logger.error(x);
}
}
if (!names.isEmpty()) broadcast(new BroadcastObjectSelectionByBookmarks(names));
}
示例4: handleParagraphEnumeration
import com.sun.star.text.XTextRangeCompare; //导入依赖的package包/类
/**
* Falls enuAccess != null, wird die entsprechende XEnumeration genommen und ihre
* Elemente als Paragraphen bzw TextTables interpretiert, deren Inhalt enumeriert
* wird, um daraus alle enthaltenen Bookmarks UND InputUser Felder zu bestimmen und
* ihre Namen zu names hinzuzufügen.
*
* @param doCompare
* if true, then text portions will be ignored if they lie outside of
* range (as tested with compare). Text portions inside of tables are
* always checked, regardless of doCompare.
*
* @throws NoSuchElementException
* @throws WrappedTargetException
* @author Matthias Benkmann (D-III-ITD-D101)
*
* TESTED
*/
private void handleParagraphEnumeration(Set<String> names,
XEnumerationAccess enuAccess, XTextRangeCompare compare, XTextRange range,
boolean doCompare) throws NoSuchElementException, WrappedTargetException
{
if (enuAccess != null)
{
XEnumeration paraEnu = enuAccess.createEnumeration();
while (paraEnu.hasMoreElements())
{
Object nextEle = paraEnu.nextElement();
if (nextEle == null)
throw new NullPointerException(
L.m("nextElement() == null obwohl hasMoreElements()==true"));
XEnumerationAccess xs = UNO.XEnumerationAccess(nextEle);
if (xs != null)
handleParagraph(names, xs, compare, range, doCompare);
else
{// unterstützt nicht XEnumerationAccess, ist wohl SwXTextTable
XTextTable table = UNO.XTextTable(nextEle);
if (table != null) handleTextTable(names, table, compare, range);
}
}
}
}
示例5: isInvalidRange
import com.sun.star.text.XTextRangeCompare; //导入依赖的package包/类
/**
* Returns true iff (doCompare == false OR range2 is null or not an XTextRange OR
* range2 lies inside of range (tested with compare)).
*
* @author Matthias Benkmann (D-III-ITD-D101)
*
*/
private boolean isInvalidRange(XTextRangeCompare compare, XTextRange range,
Object range2, boolean doCompare)
{
XTextRange compareRange = UNO.XTextRange(range2);
if (doCompare && compareRange != null)
{
try
{
if (compare.compareRegionStarts(range, compareRange) < 0) return true;
if (compare.compareRegionEnds(range, compareRange) > 0) return true;
}
catch (Exception x)
{
return true;
/*
* Do not Logger.error(x); because the most likely cause for an exception is
* that range2 does not belong to the text object compare, which happens in
* tables, because when enumerating over a range inside of a table the
* enumeration hits a lot of unrelated cells (OOo bug).
*/
}
}
return false;
}
示例6: getNewParagraphTextContent
import com.sun.star.text.XTextRangeCompare; //导入依赖的package包/类
/**
* Returns the XTextContent interface of the paragraph just added,
* or null if not found.
*
* @param oldParagraphsBeforeInsert the old paragraphs array before the new paragraph is added
*
* @return the XTextContent interface of the paragraph just added,
* or null if not found
*
* @throws TextException if something fails
*
* @author Markus Krüger
* @date 21.06.2010
*/
private XTextContent getNewParagraphTextContent(IParagraph[] oldParagraphsBeforeInsert)
throws TextException {
try {
IParagraph[] newParagraphs = getRealParagraphs();
for (int i = 0; i < newParagraphs.length; i++) {
IParagraph newParagraph = newParagraphs[i];
IParagraph oldParagraph = null;
if (i < oldParagraphsBeforeInsert.length) {
oldParagraph = oldParagraphsBeforeInsert[i];
}
else {
return newParagraphs[newParagraphs.length - 1].getXTextContent();
}
XText text = newParagraph.getXTextContent().getAnchor().getText();
text = textDocument.getTextService().getText().getXText();
XTextRangeCompare comparator = (XTextRangeCompare) UnoRuntime.queryInterface(XTextRangeCompare.class,
text);
if (comparator.compareRegionStarts(newParagraph.getXTextContent().getAnchor().getStart(),
oldParagraph.getXTextContent().getAnchor().getStart()) != 0) {
return newParagraph.getXTextContent();
}
}
return null;
}
catch (Exception exception) {
TextException textException = new TextException(exception.getMessage());
textException.initCause(exception);
throw textException;
}
}
示例7: rangeStartTouchesNewSection
import com.sun.star.text.XTextRangeCompare; //导入依赖的package包/类
/**
* Liefert true gdw der Anfang von range mit dem Anfang einer Section aus doc
* zusammenfällt, deren Name nicht in oldSections ist.
*
* @author Matthias Benkmann (D-III-ITD 5.1) TESTED
*/
private static boolean rangeStartTouchesNewSection(XTextRange range,
Set<String> oldSectionNames, XTextDocument doc)
{
XTextRange docText = doc.getText();
XTextRangeCompare compare = UNO.XTextRangeCompare(docText);
XNameAccess sections = UNO.XTextSectionsSupplier(doc).getTextSections();
String[] names = sections.getElementNames();
for (int i = 0; i < names.length; ++i)
{
if (!oldSectionNames.contains(names[i]))
{
try
{
XTextRange sectionRange =
UNO.XTextContent(sections.getByName(names[i])).getAnchor();
if (compare.compareRegionStarts(range, sectionRange) == 0) return true;
}
catch (Exception x)
{
// keine Logger-Meldung. Dies tritt regulär auf bei Bereichen, die in
// anderen
// Rahmen liegen und daher nicht mit einem Cursor im Dokumenthaupttext
// vergleichbar sind.
}
}
}
return false;
}
示例8: handleTextTable
import com.sun.star.text.XTextRangeCompare; //导入依赖的package包/类
/**
* Enumeriert über die Zellen von table und ruft für jede
* {@link #handleParagraph(Set, XEnumerationAccess, XTextRangeCompare, XTextRange, boolean)}
* auf, wobei für doCompare immer true übergeben wird.
*
* @throws NoSuchElementException
* @throws WrappedTargetException
*
* @author Matthias Benkmann (D-III-ITD-D101)
*
* TESTED
*/
private void handleTextTable(Set<String> names, XTextTable table,
XTextRangeCompare compare, XTextRange range) throws NoSuchElementException,
WrappedTargetException
{
String[] cellNames = table.getCellNames();
for (int i = 0; i < cellNames.length; ++i)
{
XCell cell = table.getCellByName(cellNames[i]);
handleParagraphEnumeration(names, UNO.XEnumerationAccess(cell), compare,
range, true);
}
}
示例9: combineCiteMarkers
import com.sun.star.text.XTextRangeCompare; //导入依赖的package包/类
public void combineCiteMarkers(List<BibDatabase> databases, OOBibStyle style)
throws IOException, WrappedTargetException, NoSuchElementException, IllegalArgumentException,
UndefinedCharacterFormatException, UnknownPropertyException, PropertyVetoException, CreationException,
BibEntryNotFoundException {
XNameAccess nameAccess = getReferenceMarks();
// TODO: doesn't work for citations in footnotes/tables
List<String> names = getSortedReferenceMarks(nameAccess);
final XTextRangeCompare compare = UnoRuntime.queryInterface(XTextRangeCompare.class, text);
int piv = 0;
boolean madeModifications = false;
while (piv < (names.size() - 1)) {
XTextRange range1 = UnoRuntime.queryInterface(XTextContent.class, nameAccess.getByName(names.get(piv)))
.getAnchor().getEnd();
XTextRange range2 = UnoRuntime.queryInterface(XTextContent.class, nameAccess.getByName(names.get(piv + 1)))
.getAnchor().getStart();
if (range1.getText() != range2.getText()) {
piv++;
continue;
}
XTextCursor mxDocCursor = range1.getText().createTextCursorByRange(range1);
mxDocCursor.goRight((short) 1, true);
boolean couldExpand = true;
while (couldExpand && (compare.compareRegionEnds(mxDocCursor, range2) > 0)) {
couldExpand = mxDocCursor.goRight((short) 1, true);
}
String cursorText = mxDocCursor.getString();
// Check if the string contains no line breaks and only whitespace:
if ((cursorText.indexOf('\n') == -1) && cursorText.trim().isEmpty()) {
// If we are supposed to set character format for citations, test this before
// making any changes. This way we can throw an exception before any reference
// marks are removed, preventing damage to the user's document:
if (style.isFormatCitations()) {
XPropertySet xCursorProps = UnoRuntime.queryInterface(XPropertySet.class, mxDocCursor);
String charStyle = style.getCitationCharacterFormat();
try {
xCursorProps.setPropertyValue(CHAR_STYLE_NAME, charStyle);
} catch (UnknownPropertyException | PropertyVetoException | IllegalArgumentException |
WrappedTargetException ex) {
// Setting the character format failed, so we throw an exception that
// will result in an error message for the user:
throw new UndefinedCharacterFormatException(charStyle);
}
}
List<String> keys = parseRefMarkName(names.get(piv));
keys.addAll(parseRefMarkName(names.get(piv + 1)));
removeReferenceMark(names.get(piv));
removeReferenceMark(names.get(piv + 1));
List<BibEntry> entries = new ArrayList<>();
for (String key : keys) {
for (BibDatabase database : databases) {
Optional<BibEntry> entry = database.getEntryByKey(key);
if (entry.isPresent()) {
entries.add(entry.get());
break;
}
}
}
Collections.sort(entries, new FieldComparator(FieldName.YEAR));
String keyString = String.join(",", entries.stream().map(entry -> entry.getCiteKeyOptional().orElse(""))
.collect(Collectors.toList()));
// Insert bookmark:
String bName = getUniqueReferenceMarkName(keyString, OOBibBase.AUTHORYEAR_PAR);
insertReferenceMark(bName, "tmp", mxDocCursor, true, style);
names.set(piv + 1, bName);
madeModifications = true;
}
piv++;
}
if (madeModifications) {
updateSortedReferenceMarks();
refreshCiteMarkers(databases, style);
}
}