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