当前位置: 首页>>代码示例>>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;未经允许,请勿转载。