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


Java Highlighter.HighlightPainter方法代碼示例

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


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

示例1: useSelectedTextColor

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
 * Determines whether the SelectedTextColor should be used for painting text
 * foreground for the specified highlight.
 *
 * Returns true only if the highlight painter for the specified highlight
 * is the swing painter (whether inner class of javax.swing.text.DefaultHighlighter
 * or com.sun.java.swing.plaf.windows.WindowsTextUI) and its background color
 * is null or equals to the selection color of the text component.
 *
 * This is a hack for fixing both bugs 4761990 and 5003294
 */
public static boolean useSelectedTextColor(Highlighter.Highlight h, JTextComponent c) {
    Highlighter.HighlightPainter painter = h.getPainter();
    String painterClass = painter.getClass().getName();
    if (painterClass.indexOf("javax.swing.text.DefaultHighlighter") != 0 &&
            painterClass.indexOf("com.sun.java.swing.plaf.windows.WindowsTextUI") != 0) {
        return false;
    }
    try {
        DefaultHighlighter.DefaultHighlightPainter defPainter =
                (DefaultHighlighter.DefaultHighlightPainter) painter;
        if (defPainter.getColor() != null &&
                !defPainter.getColor().equals(c.getSelectionColor())) {
            return false;
        }
    } catch (ClassCastException e) {
        return false;
    }
    return true;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:31,代碼來源:SwingUtilities2.java

示例2: updateSelection

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
private void updateSelection() {
    Highlighter h = component.getHighlighter();
    if (h != null) {
        int p0 = Math.min(dot, mark);
        int p1 = Math.max(dot, mark);

        if (p0 == p1 || !selectionVisible) {
            if (selectionTag != null) {
                h.removeHighlight(selectionTag);
                selectionTag = null;
            }
        } else {
            try {
                if (selectionTag != null) {
                    h.changeHighlight(selectionTag, p0, p1);
                } else {
                    Highlighter.HighlightPainter p = getSelectionPainter();
                    selectionTag = h.addHighlight(p0, p1, p);
                }
            } catch (BadLocationException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:CaretFloatingPointAPITest.java

示例3: paint

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
    * Renders the highlights.
    *
    * @param g the graphics context
    */
   public void paint(Graphics g) {
       // PENDING(prinz) - should cull ranges not visible
       int len = highlights.size();
       for (int i = 0; i < len; i++) {
    HighlightInfo info = highlights.elementAt(i);
    if (!(info instanceof LayeredHighlightInfo)) {
	// Avoid allocing unless we need it.
	Rectangle a = component.getBounds();
	Insets insets = component.getInsets();
	a.x = insets.left;
	a.y = insets.top;
	a.width -= insets.left + insets.right;
	a.height -= insets.top + insets.bottom;
	for (; i < len; i++) {
	    info = highlights.elementAt(i);
	    if (!(info instanceof LayeredHighlightInfo)) {
		Highlighter.HighlightPainter p = info.getPainter();
		p.paint(g, info.getStartOffset(), info.getEndOffset(),
			a, component);
	    }
	}
    }
}
   }
 
開發者ID:freeseawind,項目名稱:littleluck,代碼行數:30,代碼來源:SnippetHighlighter.java

示例4: addHighlight

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
    * Adds a highlight to the view.  Returns a tag that can be used 
    * to refer to the highlight.
    *
    * @param p0   the start offset of the range to highlight >= 0
    * @param p1   the end offset of the range to highlight >= p0
    * @param p    the painter to use to actually render the highlight
    * @return     an object that can be used as a tag
    *   to refer to the highlight
    * @exception BadLocationException if the specified location is invalid
    */
   public Object addHighlight(int p0, int p1, Highlighter.HighlightPainter p) throws BadLocationException {
Document doc = component.getDocument();
HighlightInfo i = (getDrawsLayeredHighlights() &&
		   (p instanceof LayeredHighlighter.LayerPainter)) ?
                  new LayeredHighlightInfo() : new HighlightInfo();
i.painter = p;
i.p0 = doc.createPosition(p0);
i.p1 = doc.createPosition(p1);
       // For snippets, we want to make sure selection is layered ON TOP
       // since we add transparency to the selection color;  so rather
       // than append the highlight, we insert it in the front.
highlights.insertElementAt(i, 0);
       safeDamageRange(p0, p1);
       return i;
   }
 
開發者ID:freeseawind,項目名稱:littleluck,代碼行數:27,代碼來源:SnippetHighlighter.java

示例5: highlightErrorLines

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
 * Highlights the lines of the original file that contain detected errors.
 */
private void highlightErrorLines() {

	String text = originalFileDisplayTextArea.getText();
	String[] lines = text.split("\n");
	for (int i = 0; i < lines.length; i++)
	{
		if (lines[i].contains(" <ERROR #"))
		{
			try
			{
				int startIndex = originalFileDisplayTextArea.getLineStartOffset(i);
				int endIndex = originalFileDisplayTextArea.getLineEndOffset(i);
				Highlighter.HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(new Color(250, 170, 170));
				originalFileDisplayTextArea.getHighlighter().addHighlight(startIndex, endIndex, painter);
			}
			catch (BadLocationException ex)
			{
				ex.printStackTrace();
			}
		}
	}
}
 
開發者ID:petebrew,項目名稱:fhaes,代碼行數:26,代碼來源:ErrorDisplayPanel.java

示例6: highlightLocation

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
public void highlightLocation(JTextComponent textComp, String location) {
	//Highlights a single location throughout the text
	Highlighter.HighlightPainter locationHighlighter= new MyHighlighPainter(Color.cyan);
	
	try{
		Highlighter highlighter= textComp.getHighlighter();
		highlighter.removeAllHighlights();
		Document doc = textComp.getDocument();
		String text = doc.getText(0, doc.getLength()).toUpperCase();
		int size= location.length();
		LinkedList<Integer> indeces= allIndeces(text, location.toUpperCase());
		for(int i=0; i<indeces.size(); i++){
			int index=indeces.get(i);
			highlighter.addHighlight(index, index+size, locationHighlighter);
		}
	}
	catch(Exception e){
		e.printStackTrace();
	}
}
 
開發者ID:rkhatib,項目名稱:topotext,代碼行數:21,代碼來源:HighlighterImplementation.java

示例7: extraHighlight

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
 * Highlightet den Textbereich zwischen pos1 und pos2
 * 
 * @param pos1
 * @param pos2
 * 
 * @author Christoph Lutz (D-III-ITD-5.1)
 */
private void extraHighlight(int pos1, int pos2)
{
  Highlighter hl = compo.getHighlighter();
  try
  {
    if (extraHighlightTag == null)
    {
      Highlighter.HighlightPainter hp =
        new DefaultHighlighter.DefaultHighlightPainter(new Color(0xddddff));
      extraHighlightTag = hl.addHighlight(pos1, pos2, hp);
    }
    else
      hl.changeHighlight(extraHighlightTag, pos1, pos2);
  }
  catch (BadLocationException e1)
  {}
}
 
開發者ID:WollMux,項目名稱:WollMux,代碼行數:26,代碼來源:TextComponentTags.java

示例8: markText

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
 * add highlights for the given region on the given pane
 *
 * @param pane Editor
 * @param start Start index
 * @param end End index
 * @param marker Marker
 */
public static void markText(JTextComponent pane, int start, int end, Highlighter.HighlightPainter marker) {
    try {
        Highlighter hiliter = pane.getHighlighter();
        int selStart = pane.getSelectionStart();
        int selEnd = pane.getSelectionEnd();
        // if there is no selection or selection does not overlap
        if (selStart == selEnd || end < selStart || start > selStart) {
            hiliter.addHighlight(start, end, marker);
            return;
        }
        // selection starts within the highlight, highlight before slection
        if (selStart > start && selStart < end) {
            hiliter.addHighlight(start, selStart, marker);
        }
        // selection ends within the highlight, highlight remaining
        if (selEnd > start && selEnd < end) {
            hiliter.addHighlight(selEnd, end, marker);
        }

    } catch (BadLocationException ex) {

    }
}
 
開發者ID:jindrapetrik,項目名稱:jpexs-decompiler,代碼行數:32,代碼來源:MyMarkers.java

示例9: colorLine

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
public void colorLine(int l)
{
    Highlighter.HighlightPainter redPainter =
            new DefaultHighlighter.DefaultHighlightPainter(Color.red);
    try
    {
        System.out.println(l);
        int startIndex = jta.getLineStartOffset(l);
        int endIndex = jta.getLineEndOffset(l);
        jta.getHighlighter().addHighlight(startIndex, endIndex, redPainter);
    }
    catch (BadLocationException ble)
    {
        System.err.println("Failed coloring editor line");
    }

}
 
開發者ID:smetzlaff,項目名稱:openDLX,代碼行數:18,代碼來源:EditorFrame.java

示例10: moveCursorDown

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/*** Highlight index functions ***/

private void moveCursorDown() {
    if (currentHighlight != null) {
        textareaMessage.getHighlighter().removeHighlight(currentHighlight);
        currentHighlight = null;
    }
    
    try {
        selectIndex++;
        if (selectIndex >= myHighlights.size()) {
            selectIndex = 0;
        }
        SentinelHighlight nextHighlight = myHighlights.get(selectIndex);

        Highlighter.HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.GRAY);
        currentHighlight = textareaMessage.getHighlighter().addHighlight(nextHighlight.getStart()-1, nextHighlight.getEnd()+1, painter);
        
        int o = nextHighlight.getStart();
        viewMessagePart(o, false);
        labelPosition.setText(Integer.toString(selectIndex + 1) + "/" + Integer.toString(myHighlights.size()));
    } catch (BadLocationException ex) {
        BurpCallbacks.getInstance().print("CANT HIGHLIGHT1");
    }
}
 
開發者ID:dobin,項目名稱:BurpSentinel,代碼行數:26,代碼來源:PanelViewMessageUi.java

示例11: moveCursorUp

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
private void moveCursorUp() {
    if (currentHighlight != null) {
        textareaMessage.getHighlighter().removeHighlight(currentHighlight);
        currentHighlight = null;
    }
    
    try {
        selectIndex--;
        if (selectIndex < 0) {
            selectIndex = myHighlights.size() - 1;
        }
        SentinelHighlight nextHighlight = myHighlights.get(selectIndex);
        
        Highlighter.HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.GRAY);
        currentHighlight = textareaMessage.getHighlighter().addHighlight(nextHighlight.getStart()-1, nextHighlight.getEnd()+1, painter);
        
        int o = nextHighlight.getStart();
        
        viewMessagePart(o, false);
        labelPosition.setText(Integer.toString(selectIndex + 1) + "/" + Integer.toString(myHighlights.size()));
    } catch (BadLocationException ex) {
        BurpCallbacks.getInstance().print("CANT HIGHLIGHT2");
    }
}
 
開發者ID:dobin,項目名稱:BurpSentinel,代碼行數:25,代碼來源:PanelViewMessageUi.java

示例12: setHighlightedTokens

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
private void setHighlightedTokens(Iterable<Token> tokens, Highlighter.HighlightPainter painter) {
	for (Token token : tokens) {
		try {
			m_editor.getHighlighter().addHighlight(token.start, token.end, painter);
		} catch (BadLocationException ex) {
			throw new IllegalArgumentException(ex);
		}
	}
}
 
開發者ID:cccssw,項目名稱:enigma-vk,代碼行數:10,代碼來源:Gui.java

示例13: paint

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
@Override
public void paint(Graphics g) {
    Highlighter.Highlight[] highlights = getHighlights();

    for (int i = 0; i < highlights.length; i++) {
        Highlighter.Highlight hl = highlights[i];
        Rectangle bg = component.getBounds();
        Insets insets = component.getInsets();
        bg.x = insets.left;
        bg.y = insets.top;
        bg.height = insets.top + insets.bottom;
        Highlighter.HighlightPainter painter = hl.getPainter();
        painter.paint(g, hl.getStartOffset(), hl.getEndOffset(), bg, component);
    }
}
 
開發者ID:arodchen,項目名稱:MaxSim,代碼行數:16,代碼來源:BookmarkableLogViewer.java

示例14: highlightWords

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
private void highlightWords(Element element, String[] highlightedWords,
		Highlighter.HighlightPainter highlightPainter)
{
	if (element.isLeaf())
	{
		int startOffset = element.getStartOffset();
		try
		{
			String text = element.getDocument()
					.getText(element.getStartOffset(), element.getEndOffset() - startOffset).toLowerCase();
			for (String highlightedWord : highlightedWords)
			{
				for (int index = 0; index < text.length() - 1
						&& (index = text.indexOf(highlightedWord, index)) >= 0; index += highlightedWord.length()
								+ 1)
				{
					this.helpEditorPane.getHighlighter().addHighlight(startOffset + index,
							startOffset + index + highlightedWord.length(), highlightPainter);
				}
			}
		}
		catch (BadLocationException ex)
		{
			// Ignore unexpected exception
		}
	}
	else
	{
		for (int i = 0, n = element.getElementCount(); i < n; i++)
		{
			highlightWords(element.getElement(i), highlightedWords, highlightPainter);
		}
	}
}
 
開發者ID:valsr,項目名稱:SweetHome3D,代碼行數:35,代碼來源:HelpPane.java

示例15: setHighlightedTokens

import javax.swing.text.Highlighter; //導入方法依賴的package包/類
private void setHighlightedTokens(Iterable<Token> tokens, Highlighter.HighlightPainter painter) {
    for (Token token : tokens) {
        try {
            this.editor.getHighlighter().addHighlight(token.start, token.end, painter);
        } catch (BadLocationException ex) {
            throw new IllegalArgumentException(ex);
        }
    }
}
 
開發者ID:OpenModLoader,項目名稱:Enigma,代碼行數:10,代碼來源:Gui.java


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