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


Java Utilities類代碼示例

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


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

示例1: prepareTest

import javax.swing.text.Utilities; //導入依賴的package包/類
public static void prepareTest (String[] stringLayers, Lookup lkp) 
            throws IOException, SAXException, PropertyVetoException {
    URL[] layers = new URL[stringLayers.length];
    
    for (int cntr = 0; cntr < layers.length; cntr++) {
        layers[cntr] = Utilities.class.getResource(stringLayers[cntr]);
    }
    
    XMLFileSystem system = new XMLFileSystem();
    system.setXmlUrls(layers);
    
    Repository repository = new Repository(system);
    
    if (lkp == null) {
        DEFAULT_LOOKUP.setLookup(new Object[] { repository }, UnitTestUtils.class.getClassLoader());
    } else {
        DEFAULT_LOOKUP.setLookup(new Object[] { repository }, lkp, UnitTestUtils.class.getClassLoader());
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:UnitTestUtils.java

示例2: prepareTest

import javax.swing.text.Utilities; //導入依賴的package包/類
public static void prepareTest (String[] stringLayers, Lookup lkp) 
            throws IOException, SAXException, PropertyVetoException {
    URL[] layers = new URL[stringLayers.length];
    
    for (int cntr = 0; cntr < layers.length; cntr++) {
        layers[cntr] = Utilities.class.getResource(stringLayers[cntr]);
    }
    
    XMLFileSystem system = new XMLFileSystem();
    system.setXmlUrls(layers);
    
    Repository repository = new Repository(system);
    
    if (lkp == null) {
        UnitTestUtils.setLookup(new Object[] { repository }, UnitTestUtils.class.getClassLoader());
    } else {
        UnitTestUtils.setLookup(new Object[] { repository }, lkp, UnitTestUtils.class.getClassLoader());
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:UnitTestUtils.java

示例3: getRow

import javax.swing.text.Utilities; //導入依賴的package包/類
public int getRow(int pos,JTextArea textPane1)
{
    int rn=(pos==0) ? 1:0;
    try
    {
        int offs=pos;
        while(offs>0)
        {
            offs=Utilities.getRowStart(textPane1, offs)-1;
            rn++;
        }
    }
    catch(BadLocationException evt){ evt.printStackTrace();}

    return rn;
}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:17,代碼來源:Caretlistener.java

示例4: testNPE

import javax.swing.text.Utilities; //導入依賴的package包/類
private static void testNPE() {

        Graphics g = null;
        try {
            String test = "\ttest\ttest2";
            BufferedImage buffImage = new BufferedImage(
                    100, 100, BufferedImage.TYPE_INT_RGB);
            g = buffImage.createGraphics();
            Segment segment = new Segment(test.toCharArray(), 0, test.length());
            Utilities.drawTabbedText(segment, 0, 0, g, null, 0);
        } finally {
            if (g != null) {
                g.dispose();
            }
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:bug8134721.java

示例5: getCursorPosition

import javax.swing.text.Utilities; //導入依賴的package包/類
/**
 * Get the cursor position for the popup menu
 * 
 * @param jText
 *            current JTextComponent
 * @return the current position
 * @throws BadLocationException
 *             should never occur
 */
protected int getCursorPosition( JTextComponent jText ) throws BadLocationException {
    Caret caret = jText.getCaret();
    int offs;
    Point p = jText.getMousePosition();
    if( p != null ) {
        // use position from mouse click and not from editor cursor position 
        offs = jText.viewToModel( p );
        // calculate rectangle of line
        int startPos = Utilities.getRowStart( jText, offs );
        int endPos = Utilities.getRowEnd( jText, offs );
        Rectangle bounds = jText.modelToView( startPos ).union( jText.modelToView( endPos ) );
        if( !bounds.contains( p ) ){
            return -1; // mouse is outside of text
        }
    } else {
        offs = Math.min( caret.getDot(), caret.getMark() );
    }
    Document doc = jText.getDocument();
    if( offs > 0 && (offs >= doc.getLength() || Character.isWhitespace( doc.getText( offs, 1 ).charAt( 0 ) )) ) {
        // if the next character is a white space then use the word on the left site
        offs--;
    }
    return offs;
}
 
開發者ID:kolchagov,項目名稱:jlokalize,代碼行數:34,代碼來源:CheckerListener.java

示例6: action

import javax.swing.text.Utilities; //導入依賴的package包/類
public void action()
{
	JTextComponent c = getTextComponent();
	if(c != null)
	{
		try
		{
			int offs = c.getCaretPosition();
			int begOffs = Utilities.getRowStart(c, offs);
			if(select)
			{
				c.moveCaretPosition(begOffs);
			}
			else
			{
				c.setCaretPosition(begOffs);
			}
		}
		catch(Exception e)
		{
			UIManager.getLookAndFeel().provideErrorFeedback(c);
		}
	}
}
 
開發者ID:andy-goryachev,項目名稱:PasswordSafe,代碼行數:25,代碼來源:CEditorBeginLineAction.java

示例7: action

import javax.swing.text.Utilities; //導入依賴的package包/類
public void action()
{
	JTextComponent c = getTextComponent();
	if(c != null)
	{
		try
		{
			int offs = c.getCaretPosition();
			int endOffs = Utilities.getRowEnd(c, offs);
			if(select)
			{
				c.moveCaretPosition(endOffs);
			}
			else
			{
				c.setCaretPosition(endOffs);
			}
		}
		catch(Exception e)
		{
			UIManager.getLookAndFeel().provideErrorFeedback(c);
		}
	}
}
 
開發者ID:andy-goryachev,項目名稱:PasswordSafe,代碼行數:25,代碼來源:CEditorEndLineAction.java

示例8: actionPerformed

import javax.swing.text.Utilities; //導入依賴的package包/類
public void actionPerformed(ActionEvent ae) {
    try {
        if (multiLineTab && TextEditor.this.getSelectedText() != null) {
            int end = Utilities.getRowEnd(TextEditor.this, getSelectionEnd());
            TextEditor.this.setSelectionEnd(end);

            Element el = Utilities.getParagraphElement(TextEditor.this, getSelectionStart());
            int start = el.getStartOffset();
            TextEditor.this.setSelectionStart(start);

            // remove text and reselect the text
            String text = tabsAsSpaces ?
                    TAB_BACK_PATTERN.matcher(getSelectedText()).replaceAll("") :
                    getSelectedText().replaceAll("^\t", "");

            TextEditor.this.replaceSelection(text);

            TextEditor.this.select(start, start + text.length());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:apache,項目名稱:groovy,代碼行數:24,代碼來源:TextEditor.java

示例9: paintPlainLine

import javax.swing.text.Utilities; //導入依賴的package包/類
protected void paintPlainLine(Graphics gfx, int line, Font defaultFont,
	Color defaultColor, int x, int y)
{
	paintHighlight(gfx,line,y);
	textArea.getLineText(line,currentLine);

	gfx.setFont(defaultFont);
	gfx.setColor(defaultColor);

	y += fm.getHeight();
	x = Utilities.drawTabbedText(currentLine,x,y,gfx,this,0);

	if(eolMarkers)
	{
		gfx.setColor(eolMarkerColor);
		gfx.drawString(".",x,y);
	}
}
 
開發者ID:nativelibs4java,項目名稱:JNAerator,代碼行數:19,代碼來源:TextAreaPainter.java

示例10: caretUpdate

import javax.swing.text.Utilities; //導入依賴的package包/類
public void caretUpdate(CaretEvent evt)
{
	JTextComponent comp = (JTextComponent)evt.getSource();
	if (comp != null && highlight != null)
	{
		comp.getHighlighter().removeHighlight(highlight);
		highlight = null;
	}
	
	int pos = comp.getCaretPosition();
	Element elem = Utilities.getParagraphElement(comp, pos);
	int start = elem.getStartOffset();
	int end = elem.getEndOffset();
	
	try
	{
		highlight = comp.getHighlighter().addHighlight(start, end,
		painter);
	}
	catch (BadLocationException ex)
	{
		ex.printStackTrace();
	}
}
 
開發者ID:ltrr-arizona-edu,項目名稱:tellervo,代碼行數:25,代碼來源:LineHighlighter.java

示例11: getTabbedTextOffset

import javax.swing.text.Utilities; //導入依賴的package包/類
public static int getTabbedTextOffset(Segment segment, FontMetrics metrics, int tabBase,int x,TabExpander e, int startOffset){
    List<Segment> segments=new ArrayList<Segment>();
    List<Boolean> unis=new ArrayList<Boolean>();
    
    Font origFont=metrics.getFont();
    getSegments(origFont, segment, segments, unis);
    Graphics g=new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).getGraphics();
    Font uniFont = defaultUniFont.deriveFont(origFont.getStyle(),origFont.getSize2D());       
    int ofs=0;
    int totalto = 0;
    for(int i=0;i<segments.size();i++){
        Segment seg=segments.get(i);
        FontMetrics fm=unis.get(i)?g.getFontMetrics(uniFont):metrics;
        int to = Utilities.getTabbedTextOffset(seg, fm, tabBase+ofs,x, e, startOffset);
        totalto += to;
        ofs+=fm.stringWidth(seg.toString());
        if(to<seg.length()){
            break;
        }            
    }        
    return totalto;
}
 
開發者ID:jindrapetrik,項目名稱:jpexs-decompiler,代碼行數:23,代碼來源:UniTools.java

示例12: drawTabbedText

import javax.swing.text.Utilities; //導入依賴的package包/類
public static int drawTabbedText(Segment segment, int x, int y, Graphics g, TabExpander e, int startOffset){
    
    List<Segment> segments=new ArrayList<Segment>();
    List<Boolean> unis=new ArrayList<Boolean>();
    getSegments(g.getFont(), segment, segments, unis);
    Font origFont=g.getFont();
    Font uniFont = defaultUniFont.deriveFont(origFont.getStyle(),origFont.getSize2D());
    int ret=x;
    int pos=0;
    for(int i=0;i<segments.size();i++){
        Segment seg=segments.get(i);
        if(unis.get(i)){
            g.setFont(uniFont);
        }else{
            g.setFont(origFont);
        }
        ret = Utilities.drawTabbedText(seg, ret, y, g, e, startOffset+pos);   
        pos += seg.length();
    }
    g.setFont(origFont);
    return ret;         
}
 
開發者ID:jindrapetrik,項目名稱:jpexs-decompiler,代碼行數:23,代碼來源:UniTools.java

示例13: mouseClicked

import javax.swing.text.Utilities; //導入依賴的package包/類
@Override
public void mouseClicked(MouseEvent me) {
    if (me.getClickCount() < 2) return;

    int pos = output.viewToModel(me.getPoint());

    try {
        int rowStart = Utilities.getRowStart(output, pos);
        int rowEnd = Utilities.getRowEnd(output, pos);
        String line = output.getDocument().getText(rowStart, rowEnd - rowStart);
        if (opListener.getCmdHistory().contains(line)) {
            output.select(rowStart, rowEnd);
            cliGuiCtx.getCommandLine().getCmdText().setText(line);
            systemClipboard.setContents(new StringSelection(line), this);
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }

}
 
開發者ID:wildfly,項目名稱:wildfly-core,代碼行數:21,代碼來源:SelectPreviousOpMouseAdapter.java

示例14: actionPerformed

import javax.swing.text.Utilities; //導入依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
    JTextComponent jtc = getTextComponent(e);
    if (jtc != null) {
        try {
            int offs = jtc.getCaretPosition();
            jtc.setSelectionEnd(offs);
            offs = Utilities.getPreviousWord(jtc, offs);
            jtc.setSelectionStart(offs);
            String selectedText = jtc.getSelectedText();
            if (selectedText != null) {
                KillRing.getInstance().add(selectedText);
            }
            jtc.cut();
        } catch (BadLocationException ble) {
            jtc.getToolkit().beep();
        }
    }
}
 
開發者ID:JabRef,項目名稱:jabref,代碼行數:20,代碼來源:EmacsKeyBindings.java

示例15: drawText

import javax.swing.text.Utilities; //導入依賴的package包/類
/**
 * Draw text. This can directly call the Utilities.drawTabbedText.
 * Sub-classes can override this method to provide any other decorations.
 * 
 * @param  segment - the source of the text
 * @param  x - the X origin >= 0
 * @param  y - the Y origin >= 0
 * @param  graphics - the graphics context
 * @param e - how to expand the tabs. If this value is null, tabs will be 
 * expanded as a space character.
 * @param startOffset - starting offset of the text in the document >= 0 
 * @return
 */
public int drawText(Segment segment, int x, int y,
        Graphics graphics, TabExpander e, int startOffset) {
    graphics.setFont(graphics.getFont().deriveFont(getFontStyle()));
    FontMetrics fontMetrics = graphics.getFontMetrics();
    int a = fontMetrics.getAscent();
    int h = a + fontMetrics.getDescent();
    int w = Utilities.getTabbedTextWidth(segment, fontMetrics, 0, e, startOffset);
    int rX = x - 1;
    int rY = y - a;
    int rW = w + 2;
    int rH = h;
    if ((getFontStyle() & 0x10) != 0) {
        graphics.setColor(Color.decode("#EEEEEE"));
        graphics.fillRect(rX, rY, rW, rH);
    }
    graphics.setColor(getColor());
    x = Utilities.drawTabbedText(segment, x, y, graphics, e, startOffset);
    if ((getFontStyle() & 0x8) != 0) {
        graphics.setColor(Color.RED);
        graphics.drawRect(rX, rY, rW, rH);
    }
    
    return x;
}
 
開發者ID:nextreports,項目名稱:nextreports-designer,代碼行數:38,代碼來源:SyntaxStyle.java


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