当前位置: 首页>>代码示例>>Java>>正文


Java StyledDocument.createPosition方法代码示例

本文整理汇总了Java中javax.swing.text.StyledDocument.createPosition方法的典型用法代码示例。如果您正苦于以下问题:Java StyledDocument.createPosition方法的具体用法?Java StyledDocument.createPosition怎么用?Java StyledDocument.createPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.text.StyledDocument的用法示例。


在下文中一共展示了StyledDocument.createPosition方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPosition

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
private static Position getPosition(final StyledDocument doc, final int offset) {
    class Impl implements Runnable {
        private Position pos;
        public void run() {
            if (offset < 0 || offset >= doc.getLength())
                return ;

            try {
                pos = doc.createPosition(offset - NbDocument.findLineColumn(doc, offset));
            } catch (BadLocationException ex) {
                //should not happen?
                Logger.getLogger(ComputeAnnotations.class.getName()).log(Level.FINE, null, ex);
            }
        }
    }

    Impl i = new Impl();

    doc.render(i);

    return i.pos;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ComputeAnnotations.java

示例2: resolvePositions

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
public void resolvePositions() throws BadLocationException {
    StyledDocument doc = guards.getDocument();

    if (begin instanceof UnresolvedPosition) {
        begin = doc.createPosition(begin.getOffset());
    } else if (begin instanceof BiasedPosition) {
        ((BiasedPosition) begin).resolve(doc);
    }

    if (end instanceof UnresolvedPosition) {
        end = doc.createPosition(end.getOffset());
    } else if (end instanceof BiasedPosition) {
        ((BiasedPosition) end).resolve(doc);
    }
    assertPositionBounds();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:PositionBounds.java

示例3: createBodyBounds

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/**
 * creates bounds with backward begin position allowing to insert text to 
 * begin position while the begin position remains unchanged. The behavior
 * desired for body sections but not for header or footer sections.
 */
public static PositionBounds createBodyBounds(int begin, int end, GuardedSectionsImpl guards) throws BadLocationException {
    StyledDocument doc = guards.getDocument();
    return new PositionBounds(
            new BiasedPosition(doc.createPosition(begin - 1), Position.Bias.Backward),
            new BiasedPosition(doc.createPosition(end + 1), Position.Bias.Forward),
            guards);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:PositionBounds.java

示例4: doTestSetTextWithGuardMarks

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
private void doTestSetTextWithGuardMarks() throws BadLocationException {
    StyledDocument doc = editor.doc;
    doc.insertString(0, "abcdef", null);
    Position p = doc.createPosition(1);
    assertTrue(!GuardUtils.isGuarded(doc, 1));
    NbDocument.markGuarded(doc, 1, 3);
    // As of #174294 the GuardedDocument.isPosGuarded returns false
    // at the begining of an intra-line guarded section since an insert is allowed there.
    assertFalse(GuardUtils.isGuarded(doc, 1));
    assertTrue(GuardUtils.isGuarded(doc, 2));
    
    doc.insertString(1, "x", null);
    assertEquals(2, p.getOffset());
    assertTrue(GuardUtils.isGuarded(doc, 3));
    assertTrue(!GuardUtils.isGuarded(doc, 1));
    
    doc.insertString(4, "x", null);
    assertEquals(2, p.getOffset());
    assertTrue(GuardUtils.isGuarded(doc, 4));
    assertTrue(GuardUtils.isGuarded(doc, 3));
    assertTrue(GuardUtils.isGuarded(doc, 5));
    assertFalse(GuardUtils.isGuarded(doc, 2));
    assertTrue(!GuardUtils.isGuarded(doc, 1));
    GuardUtils.dumpGuardedAttr(doc);
    
    doc.remove(1, 1);
    assertEquals(1, p.getOffset());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:PositionBoundsTest.java

示例5: resolve

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
void resolve(StyledDocument doc) throws BadLocationException {
    if (delegate instanceof UnresolvedPosition) {
        delegate = doc.createPosition(delegate.getOffset());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:PositionBounds.java

示例6: create

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
public static PositionBounds create(int begin, int end, GuardedSectionsImpl guards) throws BadLocationException {
    StyledDocument doc = guards.getDocument();
    return new PositionBounds(doc.createPosition(begin), doc.createPosition(end), guards);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:PositionBounds.java

示例7: setText

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** Replaces the text contained in this range.
* This replacement is done atomically, and so is preferable to manual inserts & removes.
* <p>If you are running this from user-oriented code, you may want to wrap it in {@link NbDocument#runAtomicAsUser}.
* @param text new text to insert over existing text
* @exception BadLocationException if the positions are out of the bounds of the document
*/
public void setText(final String text) throws BadLocationException  {
    final StyledDocument doc = guards.getDocument();
    final BadLocationException[] hold = new BadLocationException[] { null };
    Runnable run = new Runnable() {
            public void run() {
                try {
                    int p1 = begin.getOffset();
                    int p2 = end.getOffset();
                    int len = text.length();

                    if (len == 0) { // 1) set empty string

                        if (p2 > p1) {
                            doc.remove(p1, p2 - p1);
                        }
                    } else { // 2) set non empty string

                        int docLen = doc.getLength();

                        if ((p2 - p1) >= 1) {
                            doc.insertString(p1 + 1, text, null);

                            // [MaM] compute length of inserted string
                            len = doc.getLength() - docLen;
                            doc.remove(p1 + 1 + len, p2 - p1 - 1);
                            doc.remove(p1, 1);
                        } else {
                            // zero or exactly one character:
                            // adjust the positions if they are
                            // biased to not absorb the text inserted at the start/end
                            // it would be ridiculous not to have text set by setText
                            // be part of the bounds.
                            doc.insertString(p1, text, null);

                            // [MaM] compute length of inserted string
                            len = doc.getLength() - docLen;

                            if (p2 > p1) {
                                doc.remove(p1 + len, p2 - p1);
                            }

                            if (begin.getOffset() != p1) {
                                begin = doc.createPosition(p1);
                            }

                            if ((end.getOffset() - p1) != len) {
                                end = doc.createPosition(p1 + len);
                            }
                            assertPositionBounds();
                        }
                    }
                } catch (BadLocationException e) {
                    hold[0] = e;
                }
            }
        };

    GuardedSectionsImpl.doRunAtomic(doc, run);

    if (hold[0] != null) {
        throw hold[0];
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:70,代码来源:PositionBounds.java


注:本文中的javax.swing.text.StyledDocument.createPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。