Java 类javax.swing.text.Position 实例源码

项目:incubator-netbeans    文件:RelationshipMappingRename.java   
@Override
 public PositionBounds getPosition() {
    try {
        DataObject dobj = DataObject.find(getParentFile());
        if (dobj != null) {
            EditorCookie.Observable obs = (EditorCookie.Observable)dobj.getLookup().lookup(EditorCookie.Observable.class);
            if (obs != null && obs instanceof CloneableEditorSupport) {
                CloneableEditorSupport supp = (CloneableEditorSupport)obs;

            PositionBounds bounds = new PositionBounds(
                    supp.createPositionRef(loc[0], Position.Bias.Forward),
                    supp.createPositionRef(Math.max(loc[0], loc[1]), Position.Bias.Forward)
                    );

            return bounds;
        }
        }
    } catch (DataObjectNotFoundException ex) {
        LOG.log(Level.INFO, "Can't resolve", ex);//NOI18N
    }
    return null;
}
项目:incubator-netbeans    文件:MergingPositionsBagTest.java   
public void testAddCompleteMatchOverlap() {
    PositionsBag hs = new PositionsBag(doc, true);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();

    attribsA.addAttribute("set-A", "attribsA");
    attribsB.addAttribute("set-B", "attribsB");

    hs.addHighlight(pos(10), pos(20), attribsA);
    hs.addHighlight(pos(10), pos(20), attribsB);
    GapList<Position> marks = hs.getMarks();
    GapList<AttributeSet> attributes = hs.getAttributes();

    assertEquals("Wrong number of highlights", 2, marks.size());
    assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 20, marks.get(1).getOffset());
    assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-A", "set-B");
    assertNull("1. highlight - wrong end", attributes.get(1));
}
项目:incubator-netbeans    文件:AnnotationHolder.java   
private Pair<FixData, String> buildUpFixDataForLine(Position line) {
    List<ErrorDescription> errorDescriptions = getErrorsForLine(line, true);
    if (errorDescriptions.isEmpty()) {
        return null;
    }

    List<ErrorDescription> trueErrors = filter(errorDescriptions, true);
    List<ErrorDescription> others = filter(errorDescriptions, false);

    //build up the description of the annotation:
    StringBuffer description = new StringBuffer();

    concatDescription(trueErrors, description);

    if (!trueErrors.isEmpty() && !others.isEmpty()) {
        description.append("\n\n"); //NOI18N
    }

    concatDescription(others, description);

    return Pair.of(new FixData(computeFixes(trueErrors), computeFixes(others)), description.toString());
}
项目:incubator-netbeans    文件:PositionsBagTest.java   
public void testAddRightOverlap() {
    PositionsBag hs = new PositionsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();

    attribsA.addAttribute("set-name", "attribsA");
    attribsB.addAttribute("set-name", "attribsB");

    hs.addHighlight(pos(10), pos(20), attribsA);
    hs.addHighlight(pos(15), pos(25), attribsB);
    GapList<Position> marks = hs.getMarks();
    GapList<AttributeSet> atttributes = hs.getAttributes();

    assertEquals("Wrong number of highlights", 3, marks.size());
    assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 15, marks.get(1).getOffset());
    assertEquals("1. highlight - wrong attribs", "attribsA", atttributes.get(0).getAttribute("set-name"));

    assertEquals("2. highlight - wrong start offset", 15, marks.get(1).getOffset());
    assertEquals("2. highlight - wrong end offset", 25, marks.get(2).getOffset());
    assertEquals("2. highlight - wrong attribs", "attribsB", atttributes.get(1).getAttribute("set-name"));
    assertNull(  "2. highlight - wrong end", atttributes.get(2));
}
项目:incubator-netbeans    文件:MasterMatcher.java   
private void fireMatchesHighlighted(Position[] origin, Position[] matches, BracesMatcher.ContextLocator locator) {
    MatchListener[] ll;
    synchronized (LOCK) {
        if (matchListeners.isEmpty()) {
            return;
        }
        ll = (MatchListener[]) matchListeners.toArray(new MatchListener[matchListeners.size()]);
    }
    if (ll.length == 0) {
        return;
    }
    MatchEvent evt = new MatchEvent(component, locator, this);
    evt.setHighlights(origin, matches);
    for (int i = 0; i < ll.length; i++) {
        MatchListener matchListener = ll[i];
        matchListener.matchHighlighted(evt);
    }
}
项目:incubator-netbeans    文件:EditorDocumentContentTest.java   
public void testMarkSwapMultiBB() throws Exception {
    RandomTestContainer container = createContainer();
    RandomTestContainer.Context context = container.context();

    DocumentContentTesting.insert(context, 0, "abcdefghijkl");
    Position pos2 = DocumentContentTesting.createPosition(context, 2, true);
    Position pos3 = DocumentContentTesting.createPosition(context, 3, true);
    Position pos5 = DocumentContentTesting.createPosition(context, 5, true);
    container.runChecks(context);
    DocumentContentTesting.remove(context, 2, 4);
    DocumentContentTesting.insert(context, 2, "xyzw");
    Position pos22 = DocumentContentTesting.createPosition(context, 2, true);
    Position pos23 = DocumentContentTesting.createPosition(context, 3, true);
    Position pos24 = DocumentContentTesting.createPosition(context, 4, true);
    Position pos25 = DocumentContentTesting.createPosition(context, 5, true);
    assertNotSame(pos3, pos2);
    container.runChecks(context);
    DocumentContentTesting.undo(context, 1); // Undo Ins(2, "x") tj. Rem(2,1) => becomes: pos3=2 2
    DocumentContentTesting.undo(context, 1); // Undo Rem(2, 1) tj. Ins(2,"c") => becomes: pos3=3 2
    container.runChecks(context);
}
项目:incubator-netbeans    文件:FormatSupport.java   
/** Get the next position of the position given by parameters.
 * It can be either just offset increasing but it can be movement
 * to the next token for the token boundary.
 * @return next token-position or null for the EOT position
 */
public FormatTokenPosition getNextPosition(TokenItem token, int offset,
Position.Bias bias) {
    if (token == null) { // end of chain
        return null;

    } else { // regular token
        offset++;

        if (offset >= token.getImage().length()) {
            token = token.getNext();
            offset = 0;
        }

        return getPosition(token, offset, bias);
    }
}
项目:incubator-netbeans    文件:CssTypedBreakInterceptor.java   
@Override
public void insert(MutableContext context) throws BadLocationException {
    int offset = context.getBreakInsertOffset();
    BaseDocument doc = (BaseDocument) context.getDocument();
    if (offset > 0 && offset < doc.getLength()) { //check corners
        String text = doc.getText(offset - 1, 2); //get char before and after
        if (TWO_CURLY_BRACES_IMAGE.equals(text)) { //NOI18N
            //context.setText("\n\n", 1, 1, 0, 2);
            //reformat workaround -- the preferred 
            //won't work as the reformatter will not reformat the line with the closing tag
            int from = Utilities.getRowStart(doc, offset);
            int to = Utilities.getRowEnd(doc, offset);
            reformat = new Position[]{doc.createPosition(from), doc.createPosition(to)};
            context.setText("\n\n", 1, 1);
        }
    }
}
项目:incubator-netbeans    文件:GrammarManager.java   
/**
     * Notification from invalidator thread, the grammar need to be reloaded.
     */
    public synchronized void invalidateGrammar() {

        // make current loader a zombie
        if (state == VALID) {
            String msg = NbBundle.getMessage(GrammarManager.class, "MSG_loading_cancel");
            StatusDisplayer.getDefault().setStatusText(msg);
        }

        doc.removeDocumentListener(this);

        //remove FileChangeListeners from the external DTD files
        for(FileObject fo : externalDTDs) {
//            System.out.println("[GrammarManager] removed FileObjectListener from " + fo.getPath());
            fo.removeFileChangeListener(this);
        }
        externalDTDs.clear();

        guarded = new Position[0];
        state = INVALID;
    }
项目:incubator-netbeans    文件:Utilities.java   
static Rectangle2D modelToView(JTextComponent tc, int pos, Position.Bias bias) throws BadLocationException {
Document doc = tc.getDocument();
if (doc instanceof AbstractDocument) {
    ((AbstractDocument)doc).readLock();
}
try {
    Rectangle alloc = getVisibleEditorRect(tc);
    if (alloc != null) {
               View rootView = tc.getUI().getRootView(tc);
    rootView.setSize(alloc.width, alloc.height);
    Shape s = rootView.modelToView(pos, alloc, bias);
    if (s != null) {
      return s.getBounds2D();
    }
    }
} finally {
    if (doc instanceof AbstractDocument) {
    ((AbstractDocument)doc).readUnlock();
    }
}
return null;
   }
项目:incubator-netbeans    文件:TabView.java   
@Override
public Shape modelToViewChecked(int offset, Shape alloc, Position.Bias bias) {
    int startOffset = getStartOffset();
    Rectangle2D.Double mutableBounds = ViewUtils.shape2Bounds(alloc);
    int charIndex = offset - startOffset;
    if (charIndex == 1) {
        mutableBounds.x += firstTabWidth;
    } else if (charIndex > 1) {
        int extraTabCount = getLength() - 1;
        if (extraTabCount > 0) {
            mutableBounds.x += firstTabWidth + (charIndex - 1) * ((width - firstTabWidth) / extraTabCount);
        }
    }
    mutableBounds.width = 1;
    return mutableBounds;
}
项目:incubator-netbeans    文件:PositionsBagTest.java   
public void testRemoveAligned2Clip() {
    PositionsBag hs = new PositionsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();

    attribsA.addAttribute("set-name", "attribsA");

    hs.addHighlight(pos(10), pos(40), attribsA);
    hs.removeHighlights(pos(10), pos(20), true);
    GapList<Position> marks = hs.getMarks();
    GapList<AttributeSet> atttributes = hs.getAttributes();

    assertEquals("Wrong number of highlights", 2, marks.size());
    assertEquals("1. highlight - wrong start offset", 20, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 40, marks.get(1).getOffset());
    assertEquals("1. highlight - wrong attribs", "attribsA", atttributes.get(0).getAttribute("set-name"));
    assertNull("  1. highlight - wrong end", atttributes.get(1));

    hs.removeHighlights(pos(30), pos(40), true);

    assertEquals("Wrong number of highlights", 2, marks.size());
    assertEquals("1. highlight - wrong start offset", 20, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 30, marks.get(1).getOffset());
    assertEquals("1. highlight - wrong attribs", "attribsA", atttributes.get(0).getAttribute("set-name"));
    assertNull("  1. highlight - wrong end", atttributes.get(1));
}
项目:incubator-netbeans    文件:CaretUndoEdit.java   
static List<Position.Bias> addBias(List<Position.Bias> biases, int offsetAndBias, int index) {
    if ((offsetAndBias & BACKWARD_BIAS_BIT) != 0) {
        if (biases == null) {
            biases = new ArrayList<>(index + 1);
            while (--index >= 0) {
                biases.add(Position.Bias.Forward);
            }
        }
        biases.add(Position.Bias.Backward);
    } else { // Forward bias
        if (biases != null) {
            biases.add(Position.Bias.Forward);
        }
    }
    return biases;
}
项目:incubator-netbeans    文件:Utilities.java   
/**
 * Reformat a block of code.
 * <br/>
 * The document should not be locked prior entering of this method.
 * <br/>
 * The method should be called from AWT thread so that the given offsets are more stable.
 * 
 * @param doc document to work with
 * @param startOffset offset at which the formatting starts
 * @param endOffset offset at which the formatting ends
 * @return length of the reformatted code
 */
public static int reformat (final BaseDocument doc, final int startOffset, final int endOffset) throws BadLocationException {
    final Reformat formatter = Reformat.get(doc);
    formatter.lock();
    try {
        final Object[] result = new Object[1];
        doc.runAtomicAsUser(new Runnable() {
            public @Override void run() {
                try {
                    Position endPos = doc.createPosition(endOffset);
                    formatter.reformat(startOffset, endOffset);
                    result[0] = Math.max(endPos.getOffset() - startOffset, 0);
                } catch (BadLocationException ex) {
                    result[0] = ex;
                }
            }
        });
        if (result[0] instanceof BadLocationException) {
            throw (BadLocationException) result[0];
        } else {
            return (Integer) result[0];
        }
    } finally {
        formatter.unlock();
    }
}
项目:incubator-netbeans    文件:PositionsBagTest.java   
public void testRemoveLeftOverlapClip() {
    PositionsBag hs = new PositionsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();

    attribsA.addAttribute("set-name", "attribsA");

    hs.addHighlight(pos(10), pos(20), attribsA);
    hs.removeHighlights(pos(5), pos(15), true);
    GapList<Position> marks = hs.getMarks();
    GapList<AttributeSet> atttributes = hs.getAttributes();

    assertEquals("Wrong number of highlights", 2, marks.size());
    assertEquals("1. highlight - wrong start offset", 15, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 20, marks.get(1).getOffset());
    assertEquals("1. highlight - wrong attribs", "attribsA", atttributes.get(0).getAttribute("set-name"));
    assertNull("  1. highlight - wrong end", atttributes.get(1));
}
项目:incubator-netbeans    文件:MergingPositionsBagTest.java   
public void testOrdering() {
    PositionsBag hs = new PositionsBag(doc, true);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();

    attribsA.addAttribute("attribute", "value-A");
    attribsB.addAttribute("attribute", "value-B");

    hs.addHighlight(pos(5), pos(15), attribsA);
    hs.addHighlight(pos(10), pos(20), attribsB);
    GapList<Position> marks = hs.getMarks();
    GapList<AttributeSet> attributes = hs.getAttributes();

    assertEquals("Wrong number of highlights", 4, marks.size());
    assertEquals("1. highlight - wrong attribs", "value-A", attributes.get(0).getAttribute("attribute"));
    assertEquals("2. highlight - wrong attribs", "value-B", attributes.get(1).getAttribute("attribute"));
    assertEquals("3. highlight - wrong attribs", "value-B", attributes.get(2).getAttribute("attribute"));
    assertNull("3. highlight - wrong end", attributes.get(3));
}
项目:incubator-netbeans    文件:ViewHierarchyTest.java   
public void testEmptyCustomBounds() throws Exception {
    loggingOn();    
    JEditorPane pane = ViewUpdatesTesting.createPane();
    Document doc = pane.getDocument();
    pane.modelToView(0);
    doc.insertString(0, "hello\nworld\ngood\nmorning", null);
    Position startPos = doc.createPosition(3);
    pane.putClientProperty(DocumentView.START_POSITION_PROPERTY, startPos);
    pane.putClientProperty(DocumentView.END_POSITION_PROPERTY, startPos);
    pane.modelToView(0); // Force rebuild of VH

    Position endPos = doc.createPosition(2);
    pane.putClientProperty(DocumentView.END_POSITION_PROPERTY, endPos);
    pane.modelToView(0); // Force rebuild of VH
}
项目:incubator-netbeans    文件:ErrorHintsProvider.java   
public Position[] getResult(int startOffset, int endOffset) {
    this.startOffset = startOffset;
    this.endOffset = endOffset;
    state = 1;
    sdoc.render(this);

    return result;
}
项目:code-sentinel    文件:JasonProjectSideKickParser.java   
private Position toPos(Buffer buffer, String p) {
    String text = buffer.getText(0, buffer.getLength());
    int pos = text.indexOf(p);
    if (pos >= 0) {
        return buffer.createPosition(pos);              
    } else {
        return buffer.createPosition(0);                
    }
}
项目:incubator-netbeans    文件:ChangeInfo.java   
/**
 * Adds one change.
 * @param fileObject
 * @param start
 * @param end
 */
public final void add (FileObject fileObject, Position start, Position end) {
    if (changes == null) {
        changes = new ArrayList<Change>(5);
    }
    changes.add (new ChangeImpl (fileObject, start, end));
}
项目:incubator-netbeans    文件:HighlightsView.java   
@Override
public int viewToModelChecked(double x, double y, Shape hViewAlloc, Position.Bias[] biasReturn) {
    checkTextLayoutValid();
    int offset = getStartOffset() +
            HighlightsViewUtils.viewToIndex(textLayout, x, hViewAlloc, biasReturn);

    return offset;
}
项目:incubator-netbeans    文件:JavaCompletionItem.java   
protected CharSequence substituteText(final JTextComponent c, final int offset, final int length, final CharSequence text, final CharSequence toAdd) {
    final StringBuilder sb = new StringBuilder();
    if (text != null) {
        sb.append(text);
    }
    if (toAdd != null) {
        sb.append(toAdd);
    }
    final BaseDocument doc = (BaseDocument) c.getDocument();
    doc.runAtomic (new Runnable() {
        @Override
        public void run() {
            try {
                String textToReplace = doc.getText(offset, length);
                if (textToReplace.contentEquals(sb)) {
                    c.setCaretPosition(offset + length);
                } else {
                    Position pos = doc.createPosition(offset);
                    doc.remove(offset, length);
                    doc.insertString(pos.getOffset(), sb.toString(), null);
                }
            } catch (BadLocationException e) {
            }
        }
    });
    return null;
}
项目:incubator-netbeans    文件:DocumentView.java   
@Override
protected StringBuilder appendViewInfo(StringBuilder sb, int indent, String xyInfo, int importantChildIndex) {
    DocumentView.super.appendViewInfo(sb, indent, xyInfo, importantChildIndex);
    if (getParent() == null) {
        sb.append("; NULL-PARENT");
    }
    if (!op.isChildrenValid()) {
        sb.append("; INVALID-CHILDREN");
    }
    Position startPos = getExtraStartPosition();
    Position endPos = getExtraEndPosition();
    if (startPos != null || endPos != null) {
        sb.append("; ExtraBounds:<");
        sb.append((startPos != null) ? startPos.getOffset() : "START");
        sb.append(","); // NOI18N
        sb.append((endPos != null) ? endPos.getOffset() : "END");
        sb.append(">, ");
    }
    op.appendInfo(sb);
    if (LOG_SOURCE_TEXT) {
        Document doc = getDocument();
        sb.append("\nDoc: ").append(ViewUtils.toString(doc)); // NOI18N
    }
    if (importantChildIndex != -1) {
        children.appendChildrenInfo(DocumentView.this, sb, indent, importantChildIndex);
    }
    return sb;
}
项目:incubator-netbeans    文件:EditorView.java   
/**
 * {@inheritDoc}
 */
@Override
public final Shape modelToView(int offset0, Position.Bias bias0, int offset1, Position.Bias bias1,
        Shape alloc) throws BadLocationException
{
    checkBounds(offset0);
    checkBias(bias0);
    checkBounds(offset1);
    checkBias(bias1);
    if (alloc != null) {
        return modelToViewChecked(offset0, bias0, offset1, bias1, alloc);
    } else {
        return null;
    }
}
项目:incubator-netbeans    文件:EditorView.java   
/**
 * {@inheritDoc}
 */
@Override
public final int viewToModel(float x, float y, Shape alloc, Position.Bias[] biasReturn) {
    if (alloc != null) {
        return viewToModelChecked((double)x, (double)y, alloc, biasReturn);
    } else {
        return getStartOffset();
    }
}
项目:NSS    文件:TextComponentPopupMenu.java   
public void actionPerformed(ActionEvent e) {
    JTextComponent tc = (JTextComponent) getInvoker();

    String sel = tc.getSelectedText();

    if (e.getSource() == cutItem) {
        tc.cut();
    } else if (e.getSource() == copyItem) {
        tc.copy();
    } else if (e.getSource() == pasteItem) {
        tc.paste();
    } else if (e.getSource() == selectAllItem) {
        tc.selectAll();
    } else if (e.getSource() == deleteItem) {
        Document doc = tc.getDocument();
        int start = tc.getSelectionStart();
        int end = tc.getSelectionEnd();

        try {
            Position p0 = doc.createPosition(start);
            Position p1 = doc.createPosition(end);

            if ((p0 != null) && (p1 != null)
                    && (p0.getOffset() != p1.getOffset())) {
                doc.remove(p0.getOffset(), p1.getOffset() - p0.getOffset());
            }
        } catch (BadLocationException be) {
        }
    }
}
项目:incubator-netbeans    文件:EditorDocumentContentTest.java   
public void testSimpleUndo() throws Exception {
    RandomTestContainer container = createContainer();
    RandomTestContainer.Context context = container.context();

    DocumentContentTesting.insert(context, 0, "ahoj cau");
    Position pos4 = DocumentContentTesting.createPosition(context, 4);
    DocumentContentTesting.remove(context, 3, 4);
    container.runChecks(context);
    DocumentContentTesting.undo(context, 1);
    container.runChecks(context);
    assertEquals(pos4.getOffset(), 4);
}
项目:OpenJSharp    文件:MultiTextUI.java   
/**
 * Invokes the <code>getNextVisualPositionFrom</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public int getNextVisualPositionFrom(JTextComponent a, int b, Position.Bias c, int d, Position.Bias[] e)
        throws BadLocationException {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).getNextVisualPositionFrom(a,b,c,d,e);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).getNextVisualPositionFrom(a,b,c,d,e);
    }
    return returnValue;
}
项目:incubator-netbeans    文件:AbstractPositionElement.java   
public static Position createPosition(Document doc, int offset) {
    try {
        return doc.createPosition(offset);
    } catch (BadLocationException ex) {
        throw new IndexOutOfBoundsException(ex.getMessage());
    }
}
项目:incubator-netbeans    文件:FoldView.java   
@Override
    public Shape modelToViewChecked(int offset, Shape alloc, Position.Bias bias) {
//        TextLayout textLayout = getTextLayout();
//        if (textLayout == null) {
//            return alloc; // Leave given bounds
//        }
//        Rectangle2D.Double bounds = ViewUtils.shape2Bounds(alloc);
//        return bounds;
        return alloc;
    }
项目:incubator-netbeans    文件:EditorCaret.java   
@Override
public void mouseMoved(MouseEvent evt) {
    if (mouseState == MouseState.DEFAULT) {
        boolean textCursor = true;
        int position = component.viewToModel(evt.getPoint());
        if (RectangularSelectionUtils.isRectangularSelection(component)) {
            List<Position> positions = RectangularSelectionUtils.regionsCopy(component);
            for (int i = 0; textCursor && i < positions.size(); i += 2) {
                int a = positions.get(i).getOffset();
                int b = positions.get(i + 1).getOffset();
                if (a == b) {
                    continue;
                }

                textCursor &= !(position >= a && position <= b || position >= b && position <= a);
            }
        } else // stream selection
        if (getDot() == getMark()) {
            // empty selection
            textCursor = true;
        } else {
            int dot = getDot();
            int mark = getMark();
            if (position >= dot && position <= mark || position >= mark && position <= dot) {
                textCursor = false;
            } else {
                textCursor = true;
            }
        }

        if (textCursor != showingTextCursor) {
            int cursorType = textCursor ? Cursor.TEXT_CURSOR : Cursor.DEFAULT_CURSOR;
            component.setCursor(Cursor.getPredefinedCursor(cursorType));
            showingTextCursor = textCursor;
        }
    }
}
项目:openjdk-jdk10    文件:MultiTextUI.java   
/**
 * Invokes the <code>viewToModel</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
@Deprecated(since = "9")
@Override
public int viewToModel(JTextComponent a, Point b, Position.Bias[] c) {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).viewToModel(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).viewToModel(a,b,c);
    }
    return returnValue;
}
项目:incubator-netbeans    文件:TooltipWindow.java   
@Override
public void computeBounds (JTextPane textPane) {
    Rectangle tpBounds = textPane.getBounds();
    TextUI tui = textPane.getUI();
    this.bounds = new Rectangle();
    try {
        Rectangle startr = tui.modelToView(textPane, docstart, Position.Bias.Forward).getBounds();
        Rectangle endr = tui.modelToView(textPane, docend, Position.Bias.Backward).getBounds();
        this.bounds = new Rectangle(tpBounds.x + startr.x, startr.y, endr.x - startr.x, startr.height);
    } catch (BadLocationException ex) {
        Exceptions.printStackTrace(ex);
    }
}
项目:jdk8u-jdk    文件:MultiTextUI.java   
/**
 * Invokes the <code>getNextVisualPositionFrom</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public int getNextVisualPositionFrom(JTextComponent a, int b, Position.Bias c, int d, Position.Bias[] e)
        throws BadLocationException {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).getNextVisualPositionFrom(a,b,c,d,e);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).getNextVisualPositionFrom(a,b,c,d,e);
    }
    return returnValue;
}
项目:incubator-netbeans    文件:DocumentContent.java   
public Position createBiasPosition(int offset, Position.Bias bias)
    throws BadLocationException {
        checkOffset(offset);
        BasePosition pos = new BasePosition();
//        registerStack(pos);
        markVector.insert(markVector.createBiasMark(pos, offset, bias));
        return pos;
    }
项目:incubator-netbeans    文件:PositionsBagTest.java   
public void testAddAll() {
    PositionsBag hsA = new PositionsBag(doc);
    PositionsBag hsB = new PositionsBag(doc);

    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();
    SimpleAttributeSet attribsC = new SimpleAttributeSet();

    attribsA.addAttribute("set-name", "attribsA");
    attribsB.addAttribute("set-name", "attribsB");
    attribsC.addAttribute("set-name", "attribsC");

    hsA.addHighlight(pos(0), pos(30), attribsA);
    hsA.addHighlight(pos(10), pos(20), attribsB);
    GapList<Position> marksA = hsA.getMarks();
    GapList<AttributeSet> atttributesA = hsA.getAttributes();

    hsB.addHighlight(pos(0), pos(40), attribsC);
    hsB.addAllHighlights(hsA);
    GapList<Position> marksB = hsB.getMarks();
    GapList<AttributeSet> atttributesB = hsB.getAttributes();

    assertEquals("Wrong number of highlights", marksA.size() + 1, marksB.size());
    for (int i = 0; i < marksA.size() - 1; i++) {
        assertEquals(i + ". highlight - wrong start offset", 
            marksA.get(i).getOffset(), marksB.get(i).getOffset());
        assertEquals(i + ". highlight - wrong end offset", 
            marksA.get(i + 1).getOffset(), marksB.get(i + 1).getOffset());
        assertEquals(i + ". highlight - wrong attribs",
            atttributesA.get(i).getAttribute("set-name"),
            atttributesB.get(i).getAttribute("set-name"));
    }

    assertEquals("4. highlight - wrong start offset", 30, marksB.get(3).getOffset());
    assertEquals("4. highlight - wrong end offset", 40, marksB.get(4).getOffset());
    assertEquals("4. highlight - wrong attribs", "attribsC", atttributesB.get(3).getAttribute("set-name"));
}
项目:incubator-netbeans    文件:BookmarkList.java   
/**
 * Create an unnamed bookmark if it did not exist before at the line containing
 * the given offset.
 * <br>
 * Drop an existing bookmark if it was already present for the line
 * containing the given offset.
 *
 * @param offset offset on a line in the document for which the presence of bookmark
 *  should be checked. The bookmarks are checked in a line-wise way.
 * @return bookmark that was either created or removed by the operation.
 *  Calling {@link Bookmark#isValid()} determines whether the returned
 *  bookmark was added or removed by the operation.
 *  <br>
 *  <code>null</code> is returned if the offset is above the end of document.
 */
public Bookmark toggleLineBookmark (int offset) {
    try {
        // Ensure that the bookmarks are loaded prior completing the task
        final Position pos = document.createPosition(offset);

        BookmarkUtils.postTask(new Runnable() {

            private boolean docLocked;

            @Override
            public void run() {
                if (docLocked) {
                    int lineIndex = BookmarkUtils.offset2LineIndex(document, pos.getOffset());
                    Bookmark bookmark = null;

                    Element lineElem = document.getDefaultRootElement().getElement(lineIndex);
                    int lineStartOffset = lineElem.getStartOffset();
                    bookmark = getNextBookmark(lineStartOffset);
                    if (bookmark != null
                            && bookmark.getOffset() < lineElem.getEndOffset() // inside line
                            ) { // remove the existing bookmark
                        removeBookmark(bookmark);
                    } else { // add bookmark
                        bookmark = addBookmark(lineStartOffset);
                    }
                } else {
                    docLocked = true;
                    document.render(this);
                }
            }

        });
    } catch (BadLocationException ex) {
        Exceptions.printStackTrace(ex);
    }
    // Return null since the task performs asynchronously
    return null;
}
项目:incubator-netbeans    文件:GuardedSectionsImpl.java   
private void checkNewSection(Position p, String name) {
    synchronized (sections) {
        checkOverlap(p);
        GuardedSectionImpl gs = sections.get(name);
        if (gs != null) {
            throw new IllegalArgumentException("name exists"); // NOI18N
        }
    }
}
项目:incubator-netbeans    文件:PositionBounds.java   
/** Creates new <code>PositionBounds</code>.
 * @param begin the start position of the range
 * @param end the end position of the range
*/
public PositionBounds(Position begin, Position end, GuardedSectionsImpl guards) {
    this.begin = begin;
    this.end = end;
    this.guards = guards;
    assertPositionBounds();
}
项目:incubator-netbeans    文件:EditorFindSupport.java   
private void addCaretSelectText(JTextComponent c, int start, int end, boolean back) {
    Caret eCaret = c.getCaret();
    ensureVisible(c, start, end);
    if (eCaret instanceof EditorCaret) {
        EditorCaret caret = (EditorCaret) eCaret;
        try {
            caret.addCaret(c.getDocument().createPosition(end), Position.Bias.Forward,
                c.getDocument().createPosition(start), Position.Bias.Forward);
        } catch (BadLocationException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}