當前位置: 首頁>>代碼示例>>Java>>正文


Java Pair.getLeft方法代碼示例

本文整理匯總了Java中org.apache.commons.math3.util.Pair.getLeft方法的典型用法代碼示例。如果您正苦於以下問題:Java Pair.getLeft方法的具體用法?Java Pair.getLeft怎麽用?Java Pair.getLeft使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.math3.util.Pair的用法示例。


在下文中一共展示了Pair.getLeft方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLineStyleRanges

import org.apache.commons.math3.util.Pair; //導入方法依賴的package包/類
@Override
	protected List<StyleRange> getLineStyleRanges(int lineOffset) {		
		List<StyleRange> styleList = new ArrayList<>();
		
		int lineToHighlight = text.getLineAtOffset(lineOffset);
		TrpTextLineType line = getLineObject(lineToHighlight);
		int currentLineIndex = getCurrentLineIndex();
		TreeMap<TrpWordType, Pair<Integer, Integer>> wordRanges = getWordRanges(line);
		logger.trace("wordRanges.size = "+wordRanges.size());
		logger.trace("text: "+text.getText());
		
		for (TrpWordType word : wordRanges.keySet()) {
//			if (word!=null && word.getTextStyle()!=null) {
				Pair<Integer, Integer> r = wordRanges.get(word);
				TextStyle ts = GuiUtil.getSWTTextStyle(word.getTextStyle(), text.getFont().getFontData()[0], settings);
				StyleRange sr = new StyleRange(ts);
	
				sr.start = lineOffset + r.getLeft();
				sr.length = r.getRight() - r.getLeft();
				sr.foreground = Colors.getSystemColor(SWT.COLOR_BLACK);
								
				logger.trace("word = '"+word.getUnicodeText()+"'");
				logger.trace("stylerange = "+sr);
				
				// style for selected line:
				if (lineToHighlight == currentLineIndex) {
					sr.background = Colors.getSystemColor(SWT.COLOR_GRAY);
					// highlight word under cursor:
					if (currentWordObject == word) {									
						sr.foreground = Colors.getSystemColor(SWT.COLOR_BLUE);
					}
				}		
				
				styleList.add(sr);
//			}
		}		

//		TrpTextLineType tl = getLineObject(currentLineIndex);
//		logger.debug("highlightLines: lineToHighlight = " + lineToHighlight + " currentLineIndex = " + currentLineIndex);
			
		return styleList;
	}
 
開發者ID:Transkribus,項目名稱:TranskribusSwtGui,代碼行數:43,代碼來源:WordTranscriptionWidget.java

示例2: getWordStartIndex

import org.apache.commons.math3.util.Pair; //導入方法依賴的package包/類
private int getWordStartIndex(TrpWordType word) {
	TrpTextLineType tl = word.getLine();
	Pair<Integer, Integer> wi = getWordRanges(tl).get(word);
	if (wi == null) {
		return -1;
	} else {
		logger.trace("tl index: "+tl.getIndex());
		int lo = text.getOffsetAtLine(tl.getIndex());
		return lo+wi.getLeft();
	}		
}
 
開發者ID:Transkribus,項目名稱:TranskribusSwtGui,代碼行數:12,代碼來源:WordTranscriptionWidget.java

示例3: getTranscriptionUnitAndRelativePositionFromOffset

import org.apache.commons.math3.util.Pair; //導入方法依賴的package包/類
@Override public Pair<ITrpShapeType, Integer> getTranscriptionUnitAndRelativePositionFromOffset(int offset) {
	TrpTextLineType tl = getLineObject(text.getLineAtOffset(offset));
	if (tl==null)
		return null;
	
	Pair<Integer, Integer> wi = getWordIndexAndRelativePosition(offset);
	if (wi.getLeft()==-1)
		return null;
		
	return Pair.of((ITrpShapeType) tl.getWord(wi.getLeft()), wi.getRight());
}
 
開發者ID:Transkribus,項目名稱:TranskribusSwtGui,代碼行數:12,代碼來源:WordTranscriptionWidget.java

示例4: preventSomeStuff

import org.apache.commons.math3.util.Pair; //導入方法依賴的package包/類
private void preventSomeStuff(VerifyEvent e) {
//		Pair<Integer, Integer> wiC = getCurrentWordIndex();
		Pair<Integer, Integer> wiLeft = getWordIndexAndRelativePosition(e.start);
		Pair<Integer, Integer> wiRight = getWordIndexAndRelativePosition(e.end);
		logger.debug("wiLeft = "+wiLeft+", wiRight = "+wiRight+" e = "+e);
		
		if (wiLeft.getLeft() == -1) { // // word was not found; should not happen but you know - bad things happen!
			logger.warn("word index not found (index = -1) - should not happen here -> won't do it!");
			e.doit = false;
			return;
		}
		
		boolean isMultipleWord = (wiLeft.getLeft() != wiRight.getLeft());
		boolean isSingleSelect = e.start == e.end;
				
//		logger.debug("word length: "+currentWordObject.getUnicodeText().length());
		// backspace and on left border of word
		if ( (lastKeyCode == SWT.BS && wiRight.getRight()==0) && isMultipleWord ) { 
			logger.debug("backspace on left boundary of word -> reinterpret as arrow left");
			sendTextKeyDownEvent(SWT.ARROW_LEFT);
			e.doit = false;
			return;
		}
		// prevent del on right border of word
		if (lastKeyCode == SWT.DEL && wiLeft.getRight()==currentWordObject.getUnicodeText().length() && isMultipleWord ) { 
			logger.debug("del on right boundary of word -> won't do it!");
			e.doit = false;
			return;
		}
		// reinterpret space at end of word as jump to next word
		if (lastKeyCode == SWT.SPACE && wiLeft.getRight()==currentWordObject.getUnicodeText().length() && isSingleSelect ) { 
			logger.debug("space on right boundary of word -> reinterpret as arrow right!");
			sendTextKeyDownEvent(SWT.ARROW_RIGHT);
			e.doit = false;
			return;
		}		
		// prevent deleting of an empty word:
		if (currentWordObject.getUnicodeText().isEmpty() && (lastKeyCode == SWT.DEL || lastKeyCode == SWT.BS)) {
			logger.debug("trying to delete an empty word -> won't do it!");
			e.doit = false;
			return;
		}
		// prevent changes over multiple words (if not the cases above):
		if (isMultipleWord) {
			logger.debug("trying to edit over multiple words -> won't do it!");
			e.doit = false;
			return;
		}
	}
 
開發者ID:Transkribus,項目名稱:TranskribusSwtGui,代碼行數:50,代碼來源:WordTranscriptionWidget.java

示例5: onTextChangedFromUser

import org.apache.commons.math3.util.Pair; //導入方法依賴的package包/類
@Override
//	protected void onTextChangedFromUser(VerifyEvent e) {
	// FIXME: MACHE DAS A BISSL SCHÖNER!!!! (EXCEPTION SOLLTE AUCH KEINE GESCHMISSEN WERDEN!!) (oder doch?)
	// FIXME: derzeit wird der Text immer für das ganze Wort ersetzt und nicht indexbasiert so wie beim line-based editor!
	protected void onTextChangedFromUser(int start, int end, String replacementText) {
		int wi = currentLineObject.getWordIndex(currentWordObject);
		if (wi == -1)
			throw new RuntimeException("Fatal exception: could not find word in text change from user!");
		
		// construct new word from replacement:
		String newWordText = "";
		Pair<Integer, Integer> wRange = new ArrayList<>(getWordRanges(currentLineObject).values()).get(wi);
		int lineOffset = text.getOffsetAtLine(currentLineObject.getIndex());
		

		if (!currentWordObject.getUnicodeText().isEmpty()) {
			int bi = start - lineOffset - wRange.getLeft();
			int ei = end - lineOffset - wRange.getLeft();
			logger.trace("bi = "+bi+" ei = "+ei);			
			StringBuilder sb = new StringBuilder(currentWordObject.getUnicodeText());
			newWordText = sb.replace(bi, ei, replacementText).toString();
		} else { // empty word, but in the editor the word is displayed with EMPTY_WORD_FILL!
			logger.trace("the edited word was empty");
			newWordText = replacementText;
			// set range to range of EMPTY_WORD_FILL: (???, not needed anymore...)
			start = lineOffset+wRange.getLeft();
			end = start+TrpWordType.EMPTY_WORD_FILL.length();
		}
		
		logger.trace("wRange = "+wRange+" lineOffset = "+lineOffset+" newWordText='"+newWordText+"'");
			
//		if (newWordText.isEmpty()) {
//			e.text = TrpWordType.EMPTY_WORD_FILL;
//		}
		
		// compute and set the new selection index - for an empty word just put it to the start
//		modifiedSelection = newWordText.isEmpty() ? start : start+replacementText.length();

		// send a text modified signal, s.t. the text change is actually applied to current word:
//		sendTextModifiedSignal(currentWordObject, newWordText, modifiedSelection, start, end, text); // TODO: only replace text!
		sendTextModifiedSignal(currentWordObject, /*newWordText, modifiedSelection,*/ 0, currentWordObject.getUnicodeText().length(), newWordText);
		
//		e.doit = false; // text gets replaced from TranscriptObserver
//		text.redraw();
	}
 
開發者ID:Transkribus,項目名稱:TranskribusSwtGui,代碼行數:46,代碼來源:WordTranscriptionWidget.java

示例6: initVerifyKeyListener

import org.apache.commons.math3.util.Pair; //導入方法依賴的package包/類
@Override
	protected void initVerifyKeyListener() {
		VerifyKeyListener verifyKeyListener = new VerifyKeyListener() {
			@Override
			public void verifyKey(VerifyEvent e) {			
//				if (currentWordObject == null) {
//					updateWordObject();
//				}
				
				Pair<Integer, Integer> wi = getCurrentWordIndex();
				logger.debug("key/code = "+e.character+"/"+e.keyCode+", wi/wii = "+wi.getKey()+" / "+wi.getValue()+ ", currentLineIndex = "+getCurrentLineIndex());
				
				if (wi.getLeft() == -1) { // // word was not found; should not happen but you know - bad things happen!
					logger.warn("word index not found (index = -1) - should not happen here -> won't do it!");
					e.doit = false;
					return;
				}
				
				if (currentLineObject==null || currentWordObject==null) {
					logger.warn("line object or word object null - should not happen here -> won't do it!");
					e.doit = false;
					return;
				}
				
				// Jump to next word on tab or ctrl+arrow_right and to previous word on ctrl+arrow_left
				if ( (e.keyCode == SWT.TAB || (e.keyCode==SWT.ARROW_LEFT && CanvasKeys.isCtrlKeyDown(e)) || (e.keyCode==SWT.ARROW_RIGHT && CanvasKeys.isCtrlKeyDown(e)) ) 
						&& currentLineObject!=null && currentWordObject != null) {
					boolean prev = e.keyCode == SWT.ARROW_LEFT;
					TrpWordType nextWord = currentWordObject.getNeighborWord(prev, true, false);
					if (nextWord != currentWordObject) {
						updateData(nextWord.getLine().getRegion(), nextWord.getLine(), nextWord);
						sendSelectionChangedSignal();
						e.doit = false;
						return;
					}
				}

			}
		};
		addUserVerifyKeyListener(verifyKeyListener);
	}
 
開發者ID:Transkribus,項目名稱:TranskribusSwtGui,代碼行數:42,代碼來源:WordTranscriptionWidget.java


注:本文中的org.apache.commons.math3.util.Pair.getLeft方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。