private int getNextIndex(LinkedPosition current) { if (current != null && fList.get(fIndex) != current) return findNext(current); else if (fIsCycling && fIndex == fSize - 1) return 0; else // default: increase return fIndex + 1; }
private int getPreviousIndex(LinkedPosition current) { if (current != null && fList.get(fIndex) != current) return findPrevious(current); else if (fIsCycling && fIndex == 0) return fSize - 1; else return fIndex - 1; }
LinkedPosition next(LinkedPosition current) { if (!hasNext(current)) throw new NoSuchElementException(); return fList.get(fIndex= getNextIndex(current)); }
LinkedPosition previous(LinkedPosition current) { if (!hasPrevious(current)) throw new NoSuchElementException(); return fList.get(fIndex= getPreviousIndex(current)); }
void previous() { if (fIterator.hasPrevious(fFramePosition)) { switchPosition(fIterator.previous(fFramePosition), true, true); } else // dont't update caret, but rather select the current frame leave(ILinkedModeListener.SELECT); }
/** * This does the actual constructor work. * * @param model the linked mode model * @param targets the non-empty array of targets upon which the linked mode UI * should act */ private void constructor(LinkedModeModel model, LinkedModeUITarget[] targets) { Assert.isNotNull(model); Assert.isNotNull(targets); Assert.isTrue(targets.length > 0); Assert.isTrue(model.getTabStopSequence().size() > 0); fModel= model; fTargets= targets; fCurrentTarget= targets[0]; fIterator= new TabStopIterator(fModel.getTabStopSequence()); fIterator.setCycling(!fModel.isNested()); fModel.addLinkingListener(fLinkedListener); fAssistant= new ContentAssistant2(); fAssistant.addProposalListener(fProposalListener); // TODO find a way to set up content assistant. // fAssistant.setDocumentPartitioning(IJavaPartitions.JAVA_PARTITIONING); fCaretPosition.delete(); }
/** * Sets the exit position to move the caret to when linked mode mode is * exited. * * @param target the target where the exit position is located * @param offset the offset of the exit position * @param length the length of the exit position (in case there should be a * selection) * @param sequence set to the tab stop position of the exit position, or * <code>LinkedPositionGroup.NO_STOP</code> if there should be no * tab stop. * @throws BadLocationException if the position is not valid in the viewer's * document */ public void setExitPosition(LinkedModeUITarget target, int offset, int length, int sequence) throws BadLocationException { // remove any existing exit position if (fExitPosition != null) { fExitPosition.getDocument().removePosition(fExitPosition); fIterator.removePosition(fExitPosition); fExitPosition= null; } IDocument doc= target.getViewer().getDocument(); if (doc == null) return; fExitPosition= new LinkedPosition(doc, offset, length, sequence); doc.addPosition(fExitPosition); // gets removed in leave() if (sequence != LinkedPositionGroup.NO_STOP) fIterator.addPosition(fExitPosition); }
boolean hasPrevious(LinkedPosition current) { return getPreviousIndex(current) != -1; }
private void createAnnotationModel() { if (fCurrentTarget.fAnnotationModel == null) { LinkedPositionAnnotations lpa= new LinkedPositionAnnotations(); if (fSimple) { lpa.markExitTarget(true); lpa.markFocus(false); lpa.markSlaves(false); lpa.markTargets(false); } lpa.setTargets(fIterator.getPositions()); lpa.setExitTarget(fExitPosition); lpa.connect(fCurrentTarget.getViewer().getDocument()); fCurrentTarget.fAnnotationModel= lpa; } }
boolean hasNext(LinkedPosition current) { return getNextIndex(current) != fSize; }
private void switchPosition(LinkedPosition pos, boolean select, boolean showProposals) { Assert.isNotNull(pos); if (pos.equals(fFramePosition)) return; if (fFramePosition != null && fCurrentTarget != null) fPositionListener.linkingFocusLost(fFramePosition, fCurrentTarget); // undo endCompoundChangeIfNeeded(); redraw(); // redraw current position being left - usually not needed IDocument oldDoc= fFramePosition == null ? null : fFramePosition.getDocument(); IDocument newDoc= pos.getDocument(); switchViewer(oldDoc, newDoc, pos); fFramePosition= pos; if (select) select(); if (fFramePosition == fExitPosition && !fIterator.isCycling()) leave(ILinkedModeListener.NONE); else { redraw(); // redraw new position ensureAnnotationModelInstalled(); } if (showProposals) triggerContentAssist(); if (fFramePosition != fExitPosition && fDoContextInfo) triggerContextInfo(); if (fFramePosition != null && fCurrentTarget != null) fPositionListener.linkingFocusGained(fFramePosition, fCurrentTarget); }
LinkedPosition previous(LinkedPosition current) { if (!hasPrevious(current)) throw new NoSuchElementException(); return fList.get(fIndex= getPreviousIndex(current)); }
void previous() { if (fIterator.hasPrevious(fFramePosition)) { switchPosition(fIterator.previous(fFramePosition), true, true); } else // dont't update caret, but rather select the current frame leave(ILinkedModeListener.SELECT); }
/** * This does the actual constructor work. * * @param model the linked mode model * @param targets the non-empty array of targets upon which the linked mode UI * should act */ private void constructor(LinkedModeModel model, LinkedModeUITarget[] targets) { Assert.isNotNull(model); Assert.isNotNull(targets); Assert.isTrue(targets.length > 0); Assert.isTrue(model.getTabStopSequence().size() > 0); fModel= model; fTargets= targets; fCurrentTarget= targets[0]; fIterator= new TabStopIterator(fModel.getTabStopSequence()); fIterator.setCycling(!fModel.isNested()); fModel.addLinkingListener(fLinkedListener); fAssistant= new ContentAssistant2(); fAssistant.addProposalListener(fProposalListener); // TODO find a way to set up content assistant. // fAssistant.setDocumentPartitioning(IJavaPartitions.JAVA_PARTITIONING); fCaretPosition.delete(); }
/** * Sets the exit position to move the caret to when linked mode mode is * exited. * * @param target the target where the exit position is located * @param offset the offset of the exit position * @param length the length of the exit position (in case there should be a * selection) * @param sequence set to the tab stop position of the exit position, or * <code>LinkedPositionGroup.NO_STOP</code> if there should be no * tab stop. * @throws BadLocationException if the position is not valid in the viewer's * document */ public void setExitPosition(LinkedModeUITarget target, int offset, int length, int sequence) throws BadLocationException { // remove any existing exit position if (fExitPosition != null) { fExitPosition.getDocument().removePosition(fExitPosition); fIterator.removePosition(fExitPosition); fExitPosition= null; } IDocument doc= target.getViewer().getDocument(); if (doc == null) return; fExitPosition= new LinkedPosition(doc, offset, length, sequence); doc.addPosition(fExitPosition); // gets removed in leave() if (sequence != LinkedPositionGroup.NO_STOP) fIterator.addPosition(fExitPosition); }
boolean hasPrevious(LinkedPosition current) { return getPreviousIndex(current) != -1; }
private void createAnnotationModel() { if (fCurrentTarget.fAnnotationModel == null) { LinkedPositionAnnotations lpa= new LinkedPositionAnnotations(); if (fSimple) { lpa.markExitTarget(true); lpa.markFocus(false); lpa.markSlaves(false); lpa.markTargets(false); } lpa.setTargets(fIterator.getPositions()); lpa.setExitTarget(fExitPosition); lpa.connect(fCurrentTarget.getViewer().getDocument()); fCurrentTarget.fAnnotationModel= lpa; } }
boolean hasNext(LinkedPosition current) { return getNextIndex(current) != fSize; }