當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。