default void moveToNextPage(JCas aJCas) { int nextSentenceAddress = WebAnnoCasUtil.getNextPageFirstSentenceAddress(aJCas, getFirstVisibleUnitAddress(), getPreferences().getWindowSize()); if (getFirstVisibleUnitAddress() == nextSentenceAddress) { throw new IllegalStateException("This is last page!"); } Sentence sentence = selectByAddr(aJCas, Sentence.class, nextSentenceAddress); setFirstVisibleUnit(sentence); setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin())); }
default void moveToSelection(JCas aJCas) { moveToOffset(aJCas, getSelection().getBegin()); }
default void moveToOffset(JCas aJCas, int aOffset) { // Fetch the first sentence on screen or first sentence Sentence sentence; if (getFirstVisibleUnitAddress() > -1) { sentence = selectByAddr(aJCas, Sentence.class, getFirstVisibleUnitAddress()); } else { sentence = getFirstSentence(aJCas); } // Calculate the first sentence in the window in such a way that the annotation // currently selected is in the center of the window sentence = findWindowStartCenteringOnSelection(aJCas, sentence, aOffset, getProject(), getDocument(), getPreferences().getWindowSize()); // Move to it setFirstVisibleUnit(sentence); // FIXME getSentenceNumber is not a good option... if we aim for the begin offset of the // very last unit, then we get (max-units - 1) instead of (max-units). However, this // method is used also in curation and I dimly remember that things broke when I tried // to fix it. Probably better to move away from it in the long run. -- REC setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, aOffset)); }
default void moveToFirstPage(JCas aJCas) { int firstSentenceAddress = WebAnnoCasUtil.getFirstSentenceAddress(aJCas); if (firstSentenceAddress == getFirstVisibleUnitAddress()) { throw new IllegalStateException("This is first page!"); } Sentence sentence = selectByAddr(aJCas, Sentence.class, firstSentenceAddress); setFirstVisibleUnit(sentence); setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin())); }
default void moveForward(JCas aJCas) { // Fetch the first sentence on screen Sentence sentence = selectByAddr(aJCas, Sentence.class, getFirstVisibleUnitAddress()); // Find the following one int address = getNextSentenceAddress(aJCas, sentence); // Move to it setFirstVisibleUnit(selectByAddr(aJCas, Sentence.class, address)); }
default void moveToUnit(JCas aJCas, int aIndex) { List<Sentence> units = new ArrayList<>(select(aJCas, Sentence.class)); // Index is 1-based! // The code below sets the focus unit index explicitly - see comment on getSentenceNumber // in moveToOffset for an explanation. We already know the index here, so no need to // calculate it (wrongly) using getSentenceNumber. if (aIndex <= 0) { moveToOffset(aJCas, units.get(0).getBegin()); setFocusUnitIndex(1); } else if (aIndex > units.size()) { moveToOffset(aJCas, units.get(units.size() - 1).getBegin()); setFocusUnitIndex(units.size()); } else { moveToOffset(aJCas, units.get(aIndex - 1).getBegin()); setFocusUnitIndex(aIndex); } }
default void moveToOffset(JCas aJCas, int aOffset) { // Fetch the first sentence on screen or first sentence Sentence sentence; if (getFirstVisibleUnitAddress() > -1) { sentence = selectByAddr(aJCas, Sentence.class, getFirstVisibleUnitAddress()); } else { sentence = getFirstSentence(aJCas); } // Calculate the first sentence in the window in such a way that the annotation // currently selected is in the center of the window sentence = findWindowStartCenteringOnSelection(aJCas, sentence, aOffset, getProject(), getDocument(), getPreferences().getWindowSize()); // Move to it setFirstVisibleUnit(sentence); // FIXME getSentenceNumber is not a good option... if we aim for the begin offset of the // very last unit, then we get (max-units - 1) instead of (max-units). However, this // method is used also in curation and I dimly remember that things broke when I tried // to fix it. Probably better to move away from it in the long run. -- REC setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, aOffset)); }
default void moveToFirstPage(JCas aJCas) { int firstSentenceAddress = WebAnnoCasUtil.getFirstSentenceAddress(aJCas); if (firstSentenceAddress == getFirstVisibleUnitAddress()) { throw new IllegalStateException("This is first page!"); } Sentence sentence = selectByAddr(aJCas, Sentence.class, firstSentenceAddress); setFirstVisibleUnit(sentence); setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin())); }
default void moveForward(JCas aJCas) { // Fetch the first sentence on screen Sentence sentence = selectByAddr(aJCas, Sentence.class, getFirstVisibleUnitAddress()); // Find the following one int address = getNextSentenceAddress(aJCas, sentence); // Move to it setFirstVisibleUnit(selectByAddr(aJCas, Sentence.class, address)); }
default void moveToUnit(JCas aJCas, int aIndex) { List<Sentence> units = new ArrayList<>(select(aJCas, Sentence.class)); // Index is 1-based! // The code below sets the focus unit index explicitly - see comment on getSentenceNumber // in moveToOffset for an explanation. We already know the index here, so no need to // calculate it (wrongly) using getSentenceNumber. if (aIndex <= 0) { moveToOffset(aJCas, units.get(0).getBegin()); setFocusUnitIndex(1); } else if (aIndex > units.size()) { moveToOffset(aJCas, units.get(units.size() - 1).getBegin()); setFocusUnitIndex(units.size()); } else { moveToOffset(aJCas, units.get(aIndex - 1).getBegin()); setFocusUnitIndex(aIndex); } }
default void moveToNextPage(JCas aJCas) { int nextSentenceAddress = WebAnnoCasUtil.getNextPageFirstSentenceAddress(aJCas, getFirstVisibleUnitAddress(), getPreferences().getWindowSize()); if (getFirstVisibleUnitAddress() == nextSentenceAddress) { throw new IllegalStateException("This is last page!"); } Sentence sentence = selectByAddr(aJCas, Sentence.class, nextSentenceAddress); setFirstVisibleUnit(sentence); setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin())); }
default void moveToSelection(JCas aJCas) { moveToOffset(aJCas, getSelection().getBegin()); }
default void moveToLastPage(JCas aJCas) { int lastDisplayWindowBeginingSentenceAddress = WebAnnoCasUtil .getLastDisplayWindowFirstSentenceAddress(aJCas, getPreferences().getWindowSize()); if (lastDisplayWindowBeginingSentenceAddress == getFirstVisibleUnitAddress()) { throw new IllegalStateException("This is last page!"); } Sentence sentence = selectByAddr(aJCas, Sentence.class, lastDisplayWindowBeginingSentenceAddress); setFirstVisibleUnit(sentence); setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin())); }
default void moveToLastPage(JCas aJCas) { int lastDisplayWindowBeginingSentenceAddress = WebAnnoCasUtil .getLastDisplayWindowFirstSentenceAddress(aJCas, getPreferences().getWindowSize()); if (lastDisplayWindowBeginingSentenceAddress == getFirstVisibleUnitAddress()) { throw new IllegalStateException("This is last page!"); } Sentence sentence = selectByAddr(aJCas, Sentence.class, lastDisplayWindowBeginingSentenceAddress); setFirstVisibleUnit(sentence); setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin())); }
default void moveToPreviousPage(JCas aJCas) { int firstSentenceAddress = WebAnnoCasUtil.getFirstSentenceAddress(aJCas); int previousSentenceAddress = WebAnnoCasUtil.getPreviousDisplayWindowSentenceBeginAddress( aJCas, getFirstVisibleUnitAddress(), getPreferences().getWindowSize()); // Since BratAjaxCasUtil.getPreviousDisplayWindowSentenceBeginAddress returns same // address // if there are not much sentences to go back to as defined in windowSize if (previousSentenceAddress == getFirstVisibleUnitAddress() && // Check whether it's not the beginning of document getFirstVisibleUnitAddress() != firstSentenceAddress) { previousSentenceAddress = firstSentenceAddress; } if (getFirstVisibleUnitAddress() == previousSentenceAddress) { throw new IllegalStateException("This is First Page!"); } Sentence sentence = selectByAddr(aJCas, Sentence.class, previousSentenceAddress); setFirstVisibleUnit(sentence); setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin())); }
default void moveToPreviousPage(JCas aJCas) { int firstSentenceAddress = WebAnnoCasUtil.getFirstSentenceAddress(aJCas); int previousSentenceAddress = WebAnnoCasUtil.getPreviousDisplayWindowSentenceBeginAddress( aJCas, getFirstVisibleUnitAddress(), getPreferences().getWindowSize()); // Since BratAjaxCasUtil.getPreviousDisplayWindowSentenceBeginAddress returns same // address // if there are not much sentences to go back to as defined in windowSize if (previousSentenceAddress == getFirstVisibleUnitAddress() && // Check whether it's not the beginning of document getFirstVisibleUnitAddress() != firstSentenceAddress) { previousSentenceAddress = firstSentenceAddress; } if (getFirstVisibleUnitAddress() == previousSentenceAddress) { throw new IllegalStateException("This is First Page!"); } Sentence sentence = selectByAddr(aJCas, Sentence.class, previousSentenceAddress); setFirstVisibleUnit(sentence); setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin())); }