本文整理汇总了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;
}
示例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);
}
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}