当前位置: 首页>>代码示例>>Java>>正文


Java Highlight类代码示例

本文整理汇总了Java中javax.swing.text.Highlighter.Highlight的典型用法代码示例。如果您正苦于以下问题:Java Highlight类的具体用法?Java Highlight怎么用?Java Highlight使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Highlight类属于javax.swing.text.Highlighter包,在下文中一共展示了Highlight类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getArgumentText

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
/**
 * Returns the text inserted for the parameter containing the specified
 * offset.
 *
 * @param offs The offset into the document.
 * @return The text of the parameter containing the offset, or
 *         <code>null</code> if the offset is not in a parameter.
 */
public String getArgumentText(int offs) {
	List<Highlight> paramHighlights = getParameterHighlights();
	if (paramHighlights==null || paramHighlights.size()==0) {
		return null;
	}
	for (Highlight h : paramHighlights) {
		if (offs>=h.getStartOffset() && offs<=h.getEndOffset()) {
			int start = h.getStartOffset() + 1;
			int len = h.getEndOffset() - start;
			JTextComponent tc = ac.getTextComponent();
			Document doc = tc.getDocument();
			try {
				return doc.getText(start, len);
			} catch (BadLocationException ble) {
				UIManager.getLookAndFeel().provideErrorFeedback(tc);
				ble.printStackTrace();
				return null;
			}
		}
	}
	return null;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:31,代码来源:ParameterizedCompletionContext.java

示例2: getCurrentParameterHighlight

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
/**
 * Returns the highlight of the current parameter.
 *
 * @return The current parameter's highlight, or <code>null</code> if
 *         the caret is not in a parameter's bounds.
 * @see #getCurrentParameterStartOffset()
 */
private Highlight getCurrentParameterHighlight() {

	JTextComponent tc = ac.getTextComponent();
	int dot = tc.getCaretPosition();
	if (dot>0) {
		dot--; // Workaround for Java Highlight issues
	}

	List<Highlight> paramHighlights = getParameterHighlights();
	for (Highlight h : paramHighlights) {
		if (dot>=h.getStartOffset() && dot<h.getEndOffset()) {
			return h;
		}
	}

	return null;

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:26,代码来源:ParameterizedCompletionContext.java

示例3: getCurrentParameterIndex

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
private int getCurrentParameterIndex() {

		JTextComponent tc = ac.getTextComponent();
		int dot = tc.getCaretPosition();
		if (dot>0) {
			dot--; // Workaround for Java Highlight issues
		}

		List<Highlight> paramHighlights = getParameterHighlights();
		for (int i=0; i<paramHighlights.size(); i++) {
			Highlight h = paramHighlights.get(i);
			if (dot>=h.getStartOffset() && dot<h.getEndOffset()) {
				return i;
			}
		}

		return -1;

	}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:20,代码来源:ParameterizedCompletionContext.java

示例4: insertSelectedChoice

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
/**
 * Inserts the choice selected in the parameter choices window.
 *
 * @return Whether the choice was inserted.  This will be <code>false</code>
 *         if the window is not visible, or no choice is selected.
 */
boolean insertSelectedChoice() {
	if (paramChoicesWindow!=null && paramChoicesWindow.isVisible()) {
		String choice = paramChoicesWindow.getSelectedChoice();
		if (choice!=null) {
			JTextComponent tc = ac.getTextComponent();
			Highlight h = getCurrentParameterHighlight();
			if (h!=null) {
				 // "+1" is a workaround for Java Highlight issues.
				tc.setSelectionStart(h.getStartOffset()+1);
				tc.setSelectionEnd(h.getEndOffset());
				tc.replaceSelection(choice);
				moveToNextParam();
			}
			else {
				UIManager.getLookAndFeel().provideErrorFeedback(tc);
			}
			return true;
		}
	}
	return false;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:28,代码来源:ParameterizedCompletionContext.java

示例5: getArgumentText

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
/**
 * Returns the text inserted for the parameter containing the specified
 * offset.
 *
 * @param offs
 *            The offset into the document.
 * @return The text of the parameter containing the offset, or
 *         <code>null</code> if the offset is not in a parameter.
 */
public String getArgumentText(int offs) {
	List<Highlight> paramHighlights = getParameterHighlights();
	if (paramHighlights == null || paramHighlights.size() == 0) {
		return null;
	}
	for (Highlight h : paramHighlights) {
		if (offs >= h.getStartOffset() && offs <= h.getEndOffset()) {
			int start = h.getStartOffset() + 1;
			int len = h.getEndOffset() - start;
			JTextComponent tc = ac.getTextComponent();
			Document doc = tc.getDocument();
			try {
				return doc.getText(start, len);
			} catch (BadLocationException ble) {
				UIManager.getLookAndFeel().provideErrorFeedback(tc);
				ble.printStackTrace();
				return null;
			}
		}
	}
	return null;
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:32,代码来源:ParameterizedCompletionContext.java

示例6: getPreferredInitialHighlight

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
/**
 * We prefer parameter standing for table names better than column names
 * since the choice of the table determines the choice of the column
 * 
 * there are completions containing only columns but no tables
 * 
 * @return highlight chosen. not null.
 */
private Highlight getPreferredInitialHighlight() {
	Highlight result = null;
	int idxTableParam = -1;
	int idxColumnParam = -1;
	List<Highlight> highlights = getParameterHighlights();

	for (int i = 0; i < pc.getParamCount(); i++) {
		if (pc.getParam(i).getName().equals(Const.paramNameTable))
			idxTableParam = i;
		if (pc.getParam(i).getName().equals(Const.paramNameColumn))
			idxColumnParam = i;
	}

	if (idxTableParam >= 0)
		result = highlights.get(idxTableParam);
	else if (idxColumnParam >= 0)
		result = highlights.get(idxColumnParam);

	if (result == null && pc.getParamCount() > 0)
		result = highlights.get(0);

	return result;
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:32,代码来源:ParameterizedCompletionContext.java

示例7: insertChoice

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
/**
 * gft adaption: quote
 * @param choice
 */
private void insertChoice(String choice) {
	JTextComponent tc = ac.getTextComponent();
	Highlight h = getCurrentParameterHighlight();

	if (h != null) {
		String text = tc.getText();
		// "+1" is a workaround for Java Highlight issues.
		tc.setSelectionStart(h.getStartOffset() + 1);
		tc.setSelectionEnd(h.getEndOffset());
		tc.replaceSelection(AutoCompletion.quoteChoice(choice));

		moveToNextParam();
	} else {
		UIManager.getLookAndFeel().provideErrorFeedback(tc);
	}
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:21,代码来源:ParameterizedCompletionContext.java

示例8: disable

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
/**
 * Remove the AutoSpellChecker from the given JTextComponent.
 * 
 * @param text
 *            the JTextComponent
 */
static void disable( JTextComponent text ){
    AbstractDocument doc = (AbstractDocument)text.getDocument();
    for(DocumentListener listener : doc.getDocumentListeners()){
        if(listener instanceof AutoSpellChecker){
            AutoSpellChecker autoSpell = (AutoSpellChecker)listener;
            doc.removeDocumentListener( autoSpell );
            Highlighter highlighter = text.getHighlighter();
            for( Highlight highlight : highlighter.getHighlights() ) {
                if( highlight.getPainter() == painter ){
                    highlighter.removeHighlight( highlight );
                }
            }
        }
    }
}
 
开发者ID:dasatti,项目名称:urduhtmlmaster,代码行数:22,代码来源:AutoSpellChecker.java

示例9: getFirstHighlight

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
/**
 * Returns the highlight from a list that comes "first" in a list.  Even
 * though most parameter highlights are ordered, sometimes they aren't
 * (e.g. the "cursor" parameter in a template completion is always last,
 * even though it can be anywhere in the template).
 *
 * @param highlights The list of highlights.  Assumed to be non-empty.
 * @return The highlight that comes first in the document.
 * @see #getLastHighlight(List)
 */
private static final int getFirstHighlight(List<Highlight> highlights) {
	int first = -1;
	Highlight firstH = null;
	for (int i=0; i<highlights.size(); i++) {
		Highlight h = highlights.get(i);
		if (firstH==null || h.getStartOffset()<firstH.getStartOffset()) {
			firstH = h;
			first = i;
		}
	}
	return first;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:23,代码来源:ParameterizedCompletionContext.java

示例10: getLastHighlight

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
/**
 * Returns the highlight from a list that comes "last" in that list.  Even
 * though most parameter highlights are ordered, sometimes they aren't
 * (e.g. the "cursor" parameter in a template completion is always last,
 * even though it can be anywhere in the template.
 *
 * @param highlights The list of highlights.  Assumed to be non-empty.
 * @return The highlight that comes last in the document.
 * @see #getFirstHighlight(List)
 */
private static final int getLastHighlight(List<Highlight> highlights) {
	int last = -1;
	Highlight lastH = null;
	for (int i=highlights.size()-1; i>=0; i--) {
		Highlight h = highlights.get(i);
		if (lastH==null || h.getStartOffset()>lastH.getStartOffset()) {
			lastH = h;
			last = i;
		}
	}
	return last;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:23,代码来源:ParameterizedCompletionContext.java

示例11: getParameterHighlights

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
public List<Highlight> getParameterHighlights() {
	List<Highlight> paramHighlights = new ArrayList<Highlight>(2);
	JTextComponent tc = ac.getTextComponent();
	Highlight[] highlights = tc.getHighlighter().getHighlights();
	for (int i=0; i<highlights.length; i++) {
		HighlightPainter painter = highlights[i].getPainter();
		if (painter==p || painter==endingP) {
			paramHighlights.add(highlights[i]);
		}
	}
	return paramHighlights;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:13,代码来源:ParameterizedCompletionContext.java

示例12: moveToNextParam

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
/**
 * Moves to and selects the next parameter.
 *
 * @see #moveToPreviousParam()
 */
private void moveToNextParam() {

	JTextComponent tc = ac.getTextComponent();
	int dot = tc.getCaretPosition();
	int tagCount = tags.size();
	if (tagCount==0) {
		tc.setCaretPosition(maxPos.getOffset());
		deactivate();
	}

	Highlight currentNext = null;
	int pos = -1;
	List<Highlight> highlights = getParameterHighlights();
	for (int i=0; i<highlights.size(); i++) {
		Highlight hl = highlights.get(i);
		// Check "< dot", not "<= dot" as OutlineHighlightPainter paints
		// starting at one char AFTER the highlight starts, to work around
		// Java issue.  Thanks to Matthew Adereth!
		if (currentNext==null || currentNext.getStartOffset()</*=*/dot ||
				(hl.getStartOffset()>dot &&
				hl.getStartOffset()<=currentNext.getStartOffset())) {
			currentNext = hl;
			pos = i;
		}
	}

	// No params after caret - go to first one
	if (currentNext.getStartOffset()+1<=dot) {
		int nextIndex = getFirstHighlight(highlights);
		currentNext = highlights.get(nextIndex);
		pos = 0;
	}

	// "+1" is a workaround for Java Highlight issues.
	tc.setSelectionStart(currentNext.getStartOffset()+1);
	tc.setSelectionEnd(currentNext.getEndOffset());
	updateToolTipText(pos);

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:45,代码来源:ParameterizedCompletionContext.java

示例13: possiblyUpdateParamCopies

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
private void possiblyUpdateParamCopies(Document doc) {
	
	int index = getCurrentParameterIndex();
	// FunctionCompletions add an extra param at end of inserted text
	if (index>-1 && index<pc.getParamCount()) {

		// Typing in an "end parameter" => stop parameter assistance.
		Parameter param = pc.getParam(index);
		if (param.isEndParam()) {
			deactivate();
			return;
		}

		// Get the current value of the current parameter.
		List<Highlight> paramHighlights = getParameterHighlights();
		Highlight h = paramHighlights.get(index);
		int start = h.getStartOffset() + 1; // param offsets are offset (!) by 1
		int len = h.getEndOffset() - start;
		String replacement = null;
		try {
			replacement = doc.getText(start, len);
		} catch (BadLocationException ble) {
			ble.printStackTrace(); // Never happens
		}

		// Replace any param copies tracking this parameter with the
		// value of this parameter.
		for (ParamCopyInfo pci : paramCopyInfos) {
			if (pci.paramName.equals(param.getName())) {
				pci.h = replaceHighlightedText(doc, pci.h, replacement);
			}
		}

	}

	else { // Probably the "end parameter" for FunctionCompletions.
		deactivate();
	}

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:41,代码来源:ParameterizedCompletionContext.java

示例14: updateToolTipText

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
/**
 * Updates the text in the tool tip to have the current parameter
 * displayed in bold.  The "current parameter" is determined from the
 * current caret position.
 *
 * @return The "prefix" of text in the caret's parameter before the caret.
 */
private String updateToolTipText() {

	JTextComponent tc = ac.getTextComponent();
	int dot = tc.getSelectionStart();
	int mark = tc.getSelectionEnd();
	int index = -1;
	String paramPrefix = null;

	List<Highlight> paramHighlights = getParameterHighlights();
	for (int i=0; i<paramHighlights.size(); i++) {
		Highlight h = paramHighlights.get(i);
		// "+1" because of param hack - see OutlineHighlightPainter
		int start = h.getStartOffset()+1;
		if (dot>=start && dot<=h.getEndOffset()) {
			try {
				// All text selected => offer all suggestions, otherwise
				// use prefix before selection
				if (dot!=start || mark!=h.getEndOffset()) {
					paramPrefix = tc.getText(start, dot-start);
				}
			} catch (BadLocationException ble) {
				ble.printStackTrace();
			}
			index = i;
			break;
		}
	}

	updateToolTipText(index);
	return paramPrefix;

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:40,代码来源:ParameterizedCompletionContext.java

示例15: setMarkupColor

import javax.swing.text.Highlighter.Highlight; //导入依赖的package包/类
public void setMarkupColor(Bounds bounds, Color color) {
    // Save the currently selected offsets
    int start = textCode.getSelectionStart();
    int end = textCode.getSelectionEnd();

    // Remove selection
    SwingUtilities.invokeLater(() -> {
        textCode.setSelectionStart(start);
        textCode.setSelectionEnd(start);
    });
    

    Stream.of(highlighter.getHighlights())
            // Obtain highlights which are within the requested bounds
            .filter(h -> Bounds.of(h.getStartOffset(), h.getEndOffset()).collidesWith(bounds))
            // For each highlight, we need to remove it and add it again as another color. There is no
            // way to directly change the color of a highlight once set.
            .forEach(h -> {
                Bounds b = Bounds.of(h.getStartOffset(), h.getEndOffset());
                
                // TODO: Race Condition!!! highlightMap is added to from UI Thread
                SwingUtilities.invokeLater(() -> {
                    highlighter.removeHighlight(h);
                    HighlightPainter hp = new DefaultHighlightPainter(ColorUtils.makeTransparent(color));
                    try {
                        Highlight h1 = (Highlight) highlighter.addHighlight(b.getStart(), b.getEnd(), hp);
                        highlightMap.put(b, h1);
                    } catch (BadLocationException ex) {
                        ex.printStackTrace();
                    }
                });
            });

    // Restore saved offsets
    if (start != 0 || end != 0) {
        SwingUtilities.invokeLater(() -> setSelection(Bounds.of(start, end)));
    }
}
 
开发者ID:LouisJenkinsCS,项目名称:Code-Glosser,代码行数:39,代码来源:MarkupView.java


注:本文中的javax.swing.text.Highlighter.Highlight类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。