@Override public Shape modelToView(int pos, Shape a, Bias b) throws BadLocationException { // line coordinates Element map = getElement(); int lineIndex = map.getElementIndex(pos); Rectangle lineArea = lineToRect(a, lineIndex); // determine span from the start of the line tabBase = lineArea.x; Element line = map.getElement(lineIndex); int lineStart = line.getStartOffset(); Segment s = getSegment(); getText(lineStart, pos - lineStart, s); int xOffs = Utilities.getTabbedTextWidth(s, metrics, tabBase, this, lineStart); // fill in the results and return lineArea.x += xOffs; lineArea.width = 1; lineArea.height = metrics.getHeight(); return lineArea; }
@Override public int getNextMatch(String prefix, int startIndex, Bias bias) { ListModel model = getModel(); if (!(model instanceof TableModel)) { return super.getNextMatch(prefix, startIndex, bias); } TableModel tablesModel = (TableModel)model; int max = tablesModel.getSize(); int increment = (bias == Bias.Forward) ? 1 : -1; int index = startIndex; prefix = prefix.toUpperCase(); do { Table table = tablesModel.getElementAt(index); String tableName = table.getName().toUpperCase(); if (tableName.startsWith(prefix)) { return index; } index = (index + increment + max) % max; } while (index != startIndex); return -1; }
public float getPreferredSpan(int axis) { switch (axis) { case Y_AXIS: return getEditorUI().getLineHeight(); case X_AXIS: // try { int offset = Math.max(0, getEndOffset() - 1); Shape retShape = modelToView(offset, new Rectangle(), Position.Bias.Forward, false); int ret = retShape.getBounds().x + retShape.getBounds().width; return Math.max(ret, 1f); // } catch (BadLocationException ble) { // LOG.log(Level.INFO, "Can't determine x-axis span", ble); //NOI18N // } } return 1f; }
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; }
@Override public void damageRange(JTextComponent t, int p0, int p1, Bias p0Bias, Bias p1Bias) { View rootView = getRootView(getComponent()); boolean doDamageRange = true; if (rootView.getViewCount() > 0) { View view = rootView.getView(0); if (view instanceof LockView) { LockView lockView = (LockView) view; lockView.lock(); try { GapDocumentView docView = (GapDocumentView)view.getView(0); doDamageRange = docView.checkDamageRange(p0, p1, p0Bias, p1Bias); } finally { lockView.unlock(); } } } if (doDamageRange) { // Patch since this used to be a fallback and the original views' impl cleared char area at p1 too Document doc = t.getDocument(); if (doc != null && p1 < doc.getLength()) { p1++; } super.damageRange(t, p0, p1, p0Bias, p1Bias); } }
public void testCRLF197538() throws Exception { prepareTest("test\r\ntest\r\ntest\r\n"); PositionRef start1 = ces.createPositionRef(5, Bias.Forward); PositionRef end1 = ces.createPositionRef(9, Bias.Forward); ModificationResult.Difference diff1 = new ModificationResult.Difference(ModificationResult.Difference.Kind.CHANGE, start1, end1, "test", "abcde", Source.create(testFile)); PositionRef start2 = ces.createPositionRef(10, Bias.Forward); PositionRef end2 = ces.createPositionRef(13, Bias.Forward); ModificationResult.Difference diff2 = new ModificationResult.Difference(ModificationResult.Difference.Kind.CHANGE, start2, end2, "tes", "a", Source.create(testFile)); ModificationResult result = new ModificationResult(); result.diffs = new HashMap<FileObject, List<ModificationResult.Difference>>(); result.diffs.put(testFile, Arrays.asList(diff1, diff2)); result.commit(); assertEquals("test\r\nabcde\r\nat\r\n", testFile.asText()); }
/** * {@inheritDoc} */ @Override public int yForLineContaining(Rectangle alloc, int offs) throws BadLocationException { if (isAllocationValid()) { // TODO: make cached Y_AXIS offsets valid even with folding enabled // to speed this back up! Rectangle r = (Rectangle)modelToView(offs, alloc, Bias.Forward); if (r!=null) { if (host.isCodeFoldingEnabled()) { int line = host.getLineOfOffset(offs); FoldManager fm = host.getFoldManager(); if (fm.isLineHidden(line)) { return -1; } } return r.y; } } return -1; }
@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; }
/** * Find next visual position in Y direction. * In case of no line-wrap the method should return -1 for a given valid offset. * and a valid offset when -1 is given as parameter. * @param offset offset inside line or -1 to "enter" a line at the given x. */ int getNextVisualPositionX(ParagraphView pView, int offset, Bias bias, Shape pAlloc, boolean eastDirection, Bias[] biasRet) { // Children already ensured to be measured by parent int viewCount = size(); int index = (offset == -1) ? (eastDirection ? 0 : viewCount - 1) : getViewIndex(pView, offset); int increment = eastDirection ? 1 : -1; int retOffset = -1; // Cycle through individual views in left or right direction for (; retOffset == -1 && index >= 0 && index < viewCount; index += increment) { EditorView view = get(index); // Ensure valid children Shape viewAlloc = getChildAllocation(index, pAlloc); retOffset = view.getNextVisualPositionFromChecked(offset, bias, viewAlloc, eastDirection ? SwingConstants.EAST : SwingConstants.WEST, biasRet); if (retOffset == -1) { offset = -1; // Continue by entering the paragraph from outside } } return retOffset; }
static Shape indexToView(TextLayout textLayout, Rectangle2D textLayoutBounds, int index, Position.Bias bias, int maxIndex, Shape alloc) { if (textLayout == null) { return alloc; // Leave given bounds } assert (maxIndex <= textLayout.getCharacterCount()) : "textLayout.getCharacterCount()=" + // NOI18N textLayout.getCharacterCount() + " < maxIndex=" + maxIndex; // NOI18N // If offset is >getEndOffset() use view-end-offset - otherwise it would throw exception from textLayout.getCaretInfo() int charIndex = Math.min(index, maxIndex); // When e.g. creating fold-preview the offset can be < startOffset charIndex = Math.max(charIndex, 0); TextHitInfo startHit; TextHitInfo endHit; if (bias == Position.Bias.Forward) { startHit = TextHitInfo.leading(charIndex); } else { // backward bias startHit = TextHitInfo.trailing(charIndex - 1); } endHit = (charIndex < maxIndex) ? TextHitInfo.trailing(charIndex) : startHit; if (textLayoutBounds == null) { textLayoutBounds = ViewUtils.shapeAsRect(alloc); } return TextLayoutUtils.getRealAlloc(textLayout, textLayoutBounds, startHit, endHit); }
int getNextVisualPositionY(DocumentView docView, int offset, Bias bias, Shape docViewAlloc, boolean southDirection, Bias[] biasRet) { double x = HighlightsViewUtils.getMagicX(docView, docView, offset, bias, docViewAlloc); int pIndex = docView.getViewIndex(offset, bias); int viewCount = size(); int increment = southDirection ? 1 : -1; int retOffset = -1; for (; retOffset == -1 && pIndex >= 0 && pIndex < viewCount; pIndex += increment) { // Get paragraph view with valid children ParagraphView pView = get(pIndex); Shape pAlloc = getChildAllocation(docView, pIndex, docViewAlloc); if (ensureParagraphViewChildrenValid(docView, pIndex, pView)) { pView = get(pIndex); pAlloc = getChildAllocation(docView, pIndex, docViewAlloc); } if (pView.checkLayoutUpdate(pIndex, pAlloc)) { pAlloc = getChildAllocation(docView, pIndex, docViewAlloc); } docView.op.getTextLayoutCache().activate(pView); retOffset = pView.children.getNextVisualPositionY(pView, offset, bias, pAlloc, southDirection, biasRet, x); if (retOffset == -1) { offset = -1; // Continue by entering the paragraph from outside } } return retOffset; }
int getNextVisualPositionX(DocumentView docView, int offset, Bias bias, Shape docViewAlloc, boolean eastDirection, Bias[] biasRet) { int pIndex = docView.getViewIndex(offset, bias); int viewCount = size(); int increment = eastDirection ? 1 : -1; int retOffset = -1; for (; retOffset == -1 && pIndex >= 0 && pIndex < viewCount; pIndex += increment) { // Get paragraph view with valid children ParagraphView pView = get(pIndex); Shape pAlloc = getChildAllocation(docView, pIndex, docViewAlloc); if (ensureParagraphViewChildrenValid(docView, pIndex, pView)) { pView = get(pIndex); pAlloc = getChildAllocation(docView, pIndex, docViewAlloc); } if (pView.checkLayoutUpdate(pIndex, pAlloc)) { pAlloc = getChildAllocation(docView, pIndex, docViewAlloc); } retOffset = pView.children.getNextVisualPositionX(pView, offset, bias, pAlloc, eastDirection, biasRet); if (retOffset == -1) { offset = -1; // Continue by entering the paragraph from outside } } return retOffset; }
private Occurrence createClassOccurrence(String matched, SpringBean bean) throws BadLocationException { Location loc = bean.getLocation(); if (loc == null) { return null; } int startOffset = loc.getOffset(); if (startOffset == -1) { return null; } AttributeValueFinder finder = new AttributeValueFinder(syntaxSupport, startOffset); // NOI18N if (!finder.find("class")) { return null; } int foundOffset = finder.getFoundOffset(); String foundValue = finder.getValue(); int index = foundValue.indexOf(matched); if (index == -1) { return null; } String displayText = createClassDisplayText(finder, foundValue, index, matched.length()); PositionRef startRef = docAccess.createPositionRef(foundOffset + index, Bias.Forward); PositionRef endRef = docAccess.createPositionRef(foundOffset + index + matched.length(), Bias.Backward); return new JavaElementRefOccurrence(displayText, docAccess.getFileObject(), new PositionBounds(startRef, endRef)); }
private void findResult() { if (isCanceled()) return; int len = sdoc.getLength(); if (startOffset >= len || endOffset > len) { if (!isCanceled() && ERR.isLoggable(ErrorManager.WARNING)) { ERR.log(ErrorManager.WARNING, "document changed, but not canceled?" ); ERR.log(ErrorManager.WARNING, "len = " + len ); ERR.log(ErrorManager.WARNING, "startOffset = " + startOffset ); ERR.log(ErrorManager.WARNING, "endOffset = " + endOffset ); } cancel(); return; } try { result[0] = NbDocument.createPosition(sdoc, startOffset, Bias.Forward); result[1] = NbDocument.createPosition(sdoc, endOffset, Bias.Backward); } catch (BadLocationException e) { ERR.notify(ErrorManager.ERROR, e); } }
public static List<PositionBounds> prepareSpansFor(FileObject file, Iterable<? extends int[]> spans) { List<PositionBounds> result = new ArrayList<PositionBounds>(); try { DataObject d = DataObject.find(file); EditorCookie ec = d.getLookup().lookup(EditorCookie.class); CloneableEditorSupport ces = (CloneableEditorSupport) ec; result = new LinkedList<PositionBounds>(); for (int[] span : spans) { PositionRef start = ces.createPositionRef(span[0], Bias.Forward); PositionRef end = ces.createPositionRef(span[1], Bias.Forward); result.add(new PositionBounds(start, end)); } } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } return result; }
private void refactorElements(ModificationResult modificationResult, RefactoringElementContext context, Collection<RefactoringElement> elementsToRename, String renameMsg) throws IOException, ParseException { Map<FileObject, List<Difference>> file2diffs = new HashMap<>(); for (RefactoringElement re : elementsToRename) { CloneableEditorSupport editor = GsfUtilities.findCloneableEditorSupport(re.getFile()); Difference diff = new Difference(Difference.Kind.CHANGE, editor.createPositionRef(re.getRange().getStart(), Bias.Forward), editor.createPositionRef(re.getRange().getEnd(), Bias.Backward), re.getName(), refactoring.getNewName(), renameMsg); List<Difference> diffs = file2diffs.get(re.getFile()); if (diffs == null) { diffs = new ArrayList<>(); file2diffs.put(re.getFile(), diffs); } diffs.add(diff); } for (Entry<FileObject, List<Difference>> entry : file2diffs.entrySet()) { modificationResult.addDifferences(entry.getKey(), entry.getValue()); } }
@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; }
@Override public int getNextVisualPositionFromChecked(int offset, Bias bias, Shape alloc, int direction, Bias[] biasRet) { int startOffset = getStartOffset(); int retOffset = -1; switch (direction) { case WEST: if (offset == -1) { retOffset = startOffset; } else { retOffset = -1; } break; case EAST: if (offset == -1) { retOffset = startOffset; } else { retOffset = -1; } break; case NORTH: case SOUTH: break; default: throw new IllegalArgumentException("Bad direction: " + direction); // NOI18N } return retOffset; }
@Override public synchronized void insertUpdate(DocumentEvent e) { try { modifiedSpans.add(new Position[] { doc.createPosition(e.getOffset(), Bias.Backward), doc.createPosition(e.getOffset() + e.getLength(), Bias.Forward), }); } catch (BadLocationException ex) { LOG.log(Level.FINE, null, ex); } schedule(); }
@Override public int getNextVisualPositionFrom(int pos, Bias b, Shape a, int direction, Bias[] biasRet) throws BadLocationException { switch (direction) { case WEST: { pos = super.getNextVisualPositionFrom(pos, b, a, direction, biasRet); if (Character.isLowSurrogate(org.netbeans.lib.editor.util.swing.DocumentUtilities.getText(getDocument()).charAt(pos))) { // Supplementary character return super.getNextVisualPositionFrom(pos, b, a, direction, biasRet); } } break; case EAST: { pos = super.getNextVisualPositionFrom(pos, b, a, direction, biasRet); if (Character.isLowSurrogate(org.netbeans.lib.editor.util.swing.DocumentUtilities.getText(getDocument()).charAt(pos))) { // Supplementary character return super.getNextVisualPositionFrom(pos, b, a, direction, biasRet); } } break; default: pos = super.getNextVisualPositionFrom(pos, b, a, direction, biasRet); break; } return pos; }
static void ensureAttached(final BaseDocument doc) { if (doc.getProperty(REGISTERED_KEY) != null) { return; } final HighlightURLs h = new HighlightURLs(doc); doc.putProperty(REGISTERED_KEY, true); if (h.coloring == null) { LOG.log(Level.WARNING, "'url' coloring cannot be found"); return; } doc.addDocumentListener(h); doc.render(new Runnable() { @Override public void run() { try { h.modifiedSpans.add(new Position[] { doc.createPosition(0, Bias.Backward), doc.createPosition(doc.getLength(), Bias.Forward) }); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } }); h.schedule(); }
void insert(BaseDocument doc, int offset) throws InvalidMarkException, BadLocationException { BaseDocument ldoc = this.doc; if (ldoc != null) { throw new InvalidMarkException("Mark already inserted: mark=" + this // NOI18N + ", class=" + this.getClass()); // NOI18N } this.doc = doc; ldoc = this.doc; synchronized (ldoc) { if (pos != null) { throw new IllegalStateException("Mark already inserted: mark=" + this // NOI18N + ", class=" + this.getClass()); // NOI18N } if (offset < 0 || offset > ldoc.getLength() + 1) { // doc.getEndPosition() is valid throw new BadLocationException("Invalid offset", offset); // NOI18N } // Deal with supplementary characters #164820 if (offset <= ldoc.getLength() && Character.isLowSurrogate(org.netbeans.lib.editor.util.swing.DocumentUtilities.getText(ldoc).charAt(offset))) { if (bias == Bias.Forward && offset < ldoc.getLength()) { offset++; } else if (bias == Bias.Backward && offset > 0) { offset--; } // If there is still a low surrogate after recalculating, // treat it as an invalid document, just ignore and pass through. // Since there should be a surrogate pair in Java and Unicode to // represent a supplementary character. } pos = doc.createPosition(offset, bias); } }
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException { Rectangle result = new Rectangle(); result.setBounds (0, 0, charWidth, charHeight); OutputDocument od = odoc(); if (od != null) { int line, start; synchronized (od.getLines().readLock()) { line = Math.max(0, od.getLines().getLineAt(pos)); start = od.getLineStart(line); } int column = pos - start; column = od.getLines().getNumLogicalChars(start, column); int row = od.getLines().getLogicalLineCountAbove(line, charsPerLine); int end = getLineEnd(line, od.getLines()); int len = od.getLines().getNumLogicalChars(start, end - start); //#104307 if ((column >= charsPerLine) && charsPerLine != 0) { row += (column % charsPerLine == 0 && column == len) ? column / charsPerLine - 1 : column / charsPerLine; column = (column % charsPerLine == 0 && column == len) ? charsPerLine : column % charsPerLine; } result.y = (row * charHeight) + fontDescent; result.x = margin() + (column * charWidth); // System.err.println(pos + "@" + result.x + "," + result.y + " line " + line + " start " + start + " row " + row + " col " + column); } return result; }
@Deprecated public static int getNextWord(JTextComponent c, int offset) throws BadLocationException { int nextWordOffset = getNextWord((BaseDocument)c.getDocument(), offset); int nextVisualPosition = -1; if (nextWordOffset > 0){ nextVisualPosition = c.getUI().getNextVisualPositionFrom(c, nextWordOffset - 1, Position.Bias.Forward, javax.swing.SwingConstants.EAST, null); } return (nextVisualPosition == -1) ? nextWordOffset : nextVisualPosition; }
@Deprecated public static int getPreviousWord(JTextComponent c, int offset) throws BadLocationException { int prevWordOffset = getPreviousWord((BaseDocument)c.getDocument(), offset); int nextVisualPosition = c.getUI().getNextVisualPositionFrom(c, prevWordOffset, Position.Bias.Forward, javax.swing.SwingConstants.WEST, null); if (nextVisualPosition == 0 && prevWordOffset == 0){ return 0; } return (nextVisualPosition + 1 == prevWordOffset) ? prevWordOffset : nextVisualPosition + 1; }
/** Next visually represented model location where caret can be placed. * This version works without placing read lock on the document. */ public @Override int getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet) throws BadLocationException{ if (biasRet == null) { biasRet = new Position.Bias[1]; biasRet[0] = Position.Bias.Forward; } return super.getNextVisualPositionFrom(t, pos, b, direction, biasRet); }
public void writeTo(String s) throws IOException, BadLocationException { ModificationResult.Difference diff = diffs.size() > 0 ? diffs.get(diffs.size() - 1) : null; if (diff != null && diff.getKind() == ModificationResult.Difference.Kind.REMOVE && diff.getEndPosition().getOffset() == offset) { diffs.remove(diffs.size() - 1); diffs.add(JavaSourceAccessor.getINSTANCE().createDifference(ModificationResult.Difference.Kind.CHANGE, diff.getStartPosition(), diff.getEndPosition(), diff.getOldText(), s, diff.getDescription(), src)); } else { int off = converter != null ? converter.getOriginalPosition(offset) : offset; if (off >= 0) { diffs.add(JavaSourceAccessor.getINSTANCE().createDifference(ModificationResult.Difference.Kind.INSERT, prp.createPosition(off, Bias.Forward), prp.createPosition(off, Bias.Backward), null, s, userInfo.get(offset), src)); } } }
public void skipThrough(char[] in, int pos) throws IOException, BadLocationException { String origText = new String(in, offset, pos - offset); org.netbeans.api.java.source.ModificationResult.Difference diff = diffs.size() > 0 ? diffs.get(diffs.size() - 1) : null; if (diff != null && diff.getKind() == org.netbeans.api.java.source.ModificationResult.Difference.Kind.INSERT && diff.getStartPosition().getOffset() == offset) { diffs.remove(diffs.size() - 1); diffs.add(JavaSourceAccessor.getINSTANCE().createDifference(ModificationResult.Difference.Kind.CHANGE, diff.getStartPosition(), diff.getEndPosition(), origText, diff.getNewText(), diff.getDescription(), src)); } else { int off = converter != null ? converter.getOriginalPosition(offset) : offset; if (off >= 0) { diffs.add(JavaSourceAccessor.getINSTANCE().createDifference(ModificationResult.Difference.Kind.REMOVE, prp.createPosition(off, Bias.Forward), prp.createPosition(off + origText.length(), Bias.Backward), origText, null, userInfo.get(offset), src)); } } offset = pos; }
private static Position createPositionRef(FileObject file, int position, Position.Bias bias) { try { PositionRefProvider prp = PositionRefProvider.get(file); Position positionRef = prp != null ? prp.createPosition(position, bias) : null; if (positionRef != null) { return positionRef; } } catch (IOException ex) { Exceptions.printStackTrace(ex); } throw new IllegalStateException("Cannot create PositionRef for file " + file.getPath() + ". CloneableEditorSupport not found"); }
private ModificationResult prepareInsertResult() throws Exception { PositionRef start1 = ces.createPositionRef(5, Bias.Forward); ModificationResult.Difference diff1 = new ModificationResult.Difference(ModificationResult.Difference.Kind.INSERT, start1, start1, "", "new-test1\n", Source.create(testFile)); PositionRef start2 = ces.createPositionRef(10, Bias.Forward); ModificationResult.Difference diff2 = new ModificationResult.Difference(ModificationResult.Difference.Kind.INSERT, start2, start2, "", "new-test2\n", Source.create(testFile)); ModificationResult result = new ModificationResult(); result.diffs = new HashMap<FileObject, List<ModificationResult.Difference>>(); result.diffs.put(testFile, Arrays.asList(diff1, diff2)); return result; }
private ModificationResult prepareInsertResultFiltered() throws Exception { PositionRef start1 = ces.createPositionRef(4, Bias.Forward); ModificationResult.Difference diff1 = new ModificationResult.Difference(ModificationResult.Difference.Kind.INSERT, start1, start1, "", "new-test1\n", Source.create(testFile)); PositionRef start2 = ces.createPositionRef(8, Bias.Forward); ModificationResult.Difference diff2 = new ModificationResult.Difference(ModificationResult.Difference.Kind.INSERT, start2, start2, "", "new-test2\n", Source.create(testFile)); ModificationResult result = new ModificationResult(); result.diffs = new HashMap<FileObject, List<ModificationResult.Difference>>(); result.diffs.put(testFile, Arrays.asList(diff1, diff2)); return result; }
private ModificationResult prepareRemoveResult() throws Exception { PositionRef start1 = ces.createPositionRef(5, Bias.Forward); PositionRef end1 = ces.createPositionRef(9, Bias.Forward); ModificationResult.Difference diff1 = new ModificationResult.Difference(ModificationResult.Difference.Kind.REMOVE, start1, end1, "test", "", Source.create(testFile)); PositionRef start2 = ces.createPositionRef(11, Bias.Forward); PositionRef end2 = ces.createPositionRef(12, Bias.Forward); ModificationResult.Difference diff2 = new ModificationResult.Difference(ModificationResult.Difference.Kind.REMOVE, start2, end2, "e", "", Source.create(testFile)); ModificationResult result = new ModificationResult(); result.diffs = new HashMap<FileObject, List<ModificationResult.Difference>>(); result.diffs.put(testFile, Arrays.asList(diff1, diff2)); return result; }
private ModificationResult prepareModificationResult1() throws Exception { PositionRef start1 = ces.createPositionRef(5, Bias.Forward); PositionRef end1 = ces.createPositionRef(9, Bias.Forward); ModificationResult.Difference diff1 = new ModificationResult.Difference(ModificationResult.Difference.Kind.CHANGE, start1, end1, "test", "ab", Source.create(testFile)); PositionRef start2 = ces.createPositionRef(11, Bias.Forward); PositionRef end2 = ces.createPositionRef(13, Bias.Forward); ModificationResult.Difference diff2 = new ModificationResult.Difference(ModificationResult.Difference.Kind.CHANGE, start2, end2, "es", "a", Source.create(testFile)); ModificationResult result = new ModificationResult(); result.diffs = new HashMap<FileObject, List<ModificationResult.Difference>>(); result.diffs.put(testFile, Arrays.asList(diff1, diff2)); return result; }
private ModificationResult prepareModificationResult2() throws Exception { PositionRef start1 = ces.createPositionRef(5, Bias.Forward); PositionRef end1 = ces.createPositionRef(9, Bias.Forward); ModificationResult.Difference diff1 = new ModificationResult.Difference(ModificationResult.Difference.Kind.CHANGE, start1, end1, "test", "abcde", Source.create(testFile)); PositionRef start2 = ces.createPositionRef(11, Bias.Forward); PositionRef end2 = ces.createPositionRef(13, Bias.Forward); ModificationResult.Difference diff2 = new ModificationResult.Difference(ModificationResult.Difference.Kind.CHANGE, start2, end2, "es", "a", Source.create(testFile)); ModificationResult result = new ModificationResult(); result.diffs = new HashMap<FileObject, List<ModificationResult.Difference>>(); result.diffs.put(testFile, Arrays.asList(diff1, diff2)); return result; }
@Override public int getNextVisualPositionFromChecked(int offset, Bias bias, Shape alloc, int direction, Bias[] biasRet) { int startOffset = getStartOffset(); int endOffset = startOffset + getLength(); int retOffset = -1; switch (direction) { case EAST: biasRet[0] = Bias.Forward; if (offset == -1) { retOffset = getStartOffset(); } else { retOffset = offset + 1; if (retOffset >= endOffset) { retOffset = endOffset; biasRet[0] = Bias.Backward; } } break; case WEST: biasRet[0] = Bias.Forward; if (offset == -1) { retOffset = endOffset - 1; } else { retOffset = offset - 1; if (retOffset < startOffset) { retOffset = -1; } } break; case View.NORTH: case View.SOUTH: break; // Return -1 default: throw new IllegalArgumentException("Bad direction: " + direction); } return retOffset; }
@Override public int getNextVisualPositionFromChecked(int offset, Bias bias, Shape alloc, int direction, Bias[] biasRet) { int retOffset; biasRet[0] = Bias.Forward; // BaseCaret ignores bias int viewStartOffset = getStartOffset(); switch (direction) { case View.EAST: if (offset == -1) { retOffset = viewStartOffset; } else { retOffset = -1; } break; case View.WEST: if (offset == -1) { retOffset = viewStartOffset; } else if (offset == viewStartOffset) { // Regular offset retOffset = -1; } else { retOffset = viewStartOffset; } break; case View.NORTH: case View.SOUTH: retOffset = -1; break; default: throw new IllegalArgumentException("Bad direction: " + direction); } return retOffset; }
@Override public int getViewIndex(int offset, Position.Bias b) { if (b == Position.Bias.Backward) { offset--; } return getViewIndex(offset); }
@Override public Shape modelToViewChecked(int offset, Shape alloc, Bias bias) { if (lock()) { try { return modelToViewNeedsLock(offset, alloc, bias); } finally { unlock(); } } return null; }