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


Java Utilities.getRowEnd方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: actionPerformed

import javax.swing.text.Utilities; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
    JTextComponent jtc = getTextComponent(e);
    if (jtc != null) {
        try {
            int start = jtc.getCaretPosition();
            int end = Utilities.getRowEnd(jtc, start);
            if ((start == end) && jtc.isEditable()) {
                Document doc = jtc.getDocument();
                doc.remove(end, 1);
            } else {
                jtc.setSelectionStart(start);
                jtc.setSelectionEnd(end);
                String selectedText = jtc.getSelectedText();
                if (selectedText != null) {
                    KillRing.getInstance().add(selectedText);
                }

                jtc.cut();
                // jtc.replaceSelection("");
            }
        } catch (BadLocationException ble) {
            jtc.getToolkit().beep();
        }
    }
}
 
开发者ID:JabRef,项目名称:jabref,代码行数:27,代码来源:EmacsKeyBindings.java

示例6: actionPerformed

import javax.swing.text.Utilities; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
	JTextComponent jtc = getTextComponent(e);
	if (jtc != null) {
		try {
			int start = jtc.getCaretPosition();
			int end = Utilities.getRowEnd(jtc, start);
			if (start == end && jtc.isEditable()) {
				Document doc = jtc.getDocument();
				doc.remove(end, 1);
			} else {
				jtc.setSelectionStart(start);
				jtc.setSelectionEnd(end);
				KillRing.getInstance().add(jtc.getSelectedText());
				jtc.cut();
				// jtc.replaceSelection("");
			}
		} catch (BadLocationException ble) {
			jtc.getToolkit().beep();
		}
	}
}
 
开发者ID:jpverkamp,项目名称:wombat-ide,代码行数:22,代码来源:EmacsKeyBindings.java

示例7: actionPerformedImpl

import javax.swing.text.Utilities; //导入方法依赖的package包/类
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
	int offs = textArea.getCaretPosition();
	int endOffs = 0;
	try {
		if (textArea.getLineWrap()) {
			// Must check per character, since one logical line may be
			// many physical lines.
			// FIXME:  Replace Utilities call with custom version to
			// cut down on all of the modelToViews, as each call causes
			// a getTokenList => expensive!
			endOffs = Utilities.getRowEnd(textArea, offs);
		}
		else {
			Element root = textArea.getDocument().getDefaultRootElement();
			int line = root.getElementIndex(offs);
			endOffs = root.getElement(line).getEndOffset() - 1;
		}
		if (select) {
			textArea.moveCaretPosition(endOffs);
		}
		else {
			textArea.setCaretPosition(endOffs);
		}
	} catch (Exception ex) {
		UIManager.getLookAndFeel().provideErrorFeedback(textArea);
	}
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:29,代码来源:RTextAreaEditorKit.java

示例8: getPos

import javax.swing.text.Utilities; //导入方法依赖的package包/类
public static int getPos(int line, int column, JTextPane editor) {
//       return editor.getDocument().getDefaultRootElement().getElement(line).getStartOffset() + column;
        try {
            int off=0;
            int rn = 0;
            while( rn<line-1) {
                off=Utilities.getRowEnd(editor, off)+1;
                rn++;
            }
            return off + column-1;
        } catch (BadLocationException e) {
        }
        return 0;
    }
 
开发者ID:iapafoto,项目名称:DicomViewer,代码行数:15,代码来源:RightEditorPane.java

示例9: shouldComment

import javax.swing.text.Utilities; //导入方法依赖的package包/类
private boolean shouldComment(int start, int end) throws BadLocationException {
    int offset = start;
    int length = editor.getDocument().getLength();
    
    do {
        int rowStart = Utilities.getRowStart(editor, offset);
        int rowEnd = Utilities.getRowEnd(editor, offset);
        if(!isCommented(rowStart, rowEnd))
            return true;
        offset = rowEnd + 1;
    } while(offset <= end && offset < length);
    
    return false;
}
 
开发者ID:Depter,项目名称:JRLib,代码行数:15,代码来源:TogleCommentAction.java

示例10: commentRows

import javax.swing.text.Utilities; //导入方法依赖的package包/类
private void commentRows(int start, int end) throws BadLocationException {
    int offset = start;
    int length = editor.getDocument().getLength();
    
    do {
        int rowStart = Utilities.getRowStart(editor, offset);
        commentRow(rowStart);
        end +=2;
        offset = Utilities.getRowEnd(editor, rowStart) + 1;
    } while(offset <= end && offset < length);
}
 
开发者ID:Depter,项目名称:JRLib,代码行数:12,代码来源:TogleCommentAction.java

示例11: uncommentRows

import javax.swing.text.Utilities; //导入方法依赖的package包/类
private void uncommentRows(int start, int end) throws BadLocationException {
    int offset = start;
    int length = editor.getDocument().getLength();
    
    do {
        int rowStart = Utilities.getRowStart(editor, offset);
        int rowEnd = Utilities.getRowEnd(editor, offset);
        int cOffset = getCommentPosition(rowStart, rowEnd);
        if(cOffset >= 0) {
            removeComment(cOffset);
            end -= 2;
        }
        offset = Utilities.getRowEnd(editor, rowStart) + 1;
    } while(offset <= end && offset < length);
}
 
开发者ID:Depter,项目名称:JRLib,代码行数:16,代码来源:TogleCommentAction.java

示例12: mouseEvent

import javax.swing.text.Utilities; //导入方法依赖的package包/类
private void mouseEvent(MouseEvent e)
{
	if (e.getButton() != MouseEvent.BUTTON1) {
           return;
        }
        if (e.getClickCount() != 2) {
           return;
        }

        int offset = txtAreaWaypoints.viewToModel(e.getPoint());

        try {
           rowStart = Utilities.getRowStart(txtAreaWaypoints, offset);
           int rowEnd = Utilities.getRowEnd(txtAreaWaypoints, offset);
           String selectedLine = txtAreaWaypoints.getText().substring(rowStart, rowEnd);
          
           btnAddPoint.setText("Update");
           
       	String[] splitStr = selectedLine.trim().split("\\s+");
       	String xValueS = splitStr[0];
   		String yValueS = splitStr[1];
      	String aValueS = splitStr[2];
       		
       	txtXValue.setText(xValueS);
       	txtYValue.setText(yValueS);
       	txtAngle.setText(aValueS);
       		
       	int off = txtAreaWaypoints.getCaretPosition();
        lineNum = txtAreaWaypoints.getLineOfOffset(off);

        Document document = txtAreaWaypoints.getDocument();

        int len = rowEnd - rowStart + 1;
        if (rowStart + len > document.getLength()) 
        {
        	len--;
        }
            document.remove(rowStart, len);
		}
	catch (Exception e1) {
			JOptionPane.showMessageDialog(null, "The Row is empty!", "Row Empty", JOptionPane.INFORMATION_MESSAGE);
		}
	points.remove(lineNum);
}
 
开发者ID:vannaka,项目名称:Motion_Profile_Generator,代码行数:45,代码来源:Gui2.java


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