本文整理汇总了Java中javax.swing.text.Utilities.getRowStart方法的典型用法代码示例。如果您正苦于以下问题:Java Utilities.getRowStart方法的具体用法?Java Utilities.getRowStart怎么用?Java Utilities.getRowStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.Utilities
的用法示例。
在下文中一共展示了Utilities.getRowStart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
}
}
示例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: getColumn
import javax.swing.text.Utilities; //导入方法依赖的package包/类
public int getColumn(int pos,JTextArea textPane1)
{
try
{
return pos-Utilities.getRowStart(textPane1, pos)+1;
}
catch (BadLocationException evt) {evt.printStackTrace(); }
return -1;
}
示例6: getRow
import javax.swing.text.Utilities; //导入方法依赖的package包/类
public static int getRow(int pos, JTextPane editor) {
int rn = (pos == 0) ? 1 : 0;
try {
int offs = pos;
while (offs > 0) {
offs = Utilities.getRowStart(editor, offs) - 1;
rn++;
}
} catch (BadLocationException e) {
}
return rn;
}
示例7: getColumn
import javax.swing.text.Utilities; //导入方法依赖的package包/类
public static int getColumn(int pos, JTextPane editor) {
try {
return pos - Utilities.getRowStart(editor, pos) + 1;
} catch (BadLocationException e) {
}
return -1;
}
示例8: getCurrentCaretPosition
import javax.swing.text.Utilities; //导入方法依赖的package包/类
private int getCurrentCaretPosition() {
int rowNum=0;
try {
int caretPos = PrincipalWindow.interpreter.getCaretPosition();
rowNum = (caretPos == 0) ? 1 : 0;
for (int offset = caretPos; offset > 0;) {
offset = Utilities.getRowStart(PrincipalWindow.interpreter, offset) - 1;
rowNum++;
}
} catch (BadLocationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return rowNum;
}
示例9: getRow
import javax.swing.text.Utilities; //导入方法依赖的package包/类
private static int getRow(final int pos, final JTextComponent editor) {
int rn = (pos == 0) ? 1 : 0;
try {
int offs = pos;
while (offs > 0) {
offs = Utilities.getRowStart(editor, offs) - 1;
rn++;
}
} catch (BadLocationException e) {
LOGGER.error("Bad location", e); //NOI18N
}
return rn;
}
示例10: getColumn
import javax.swing.text.Utilities; //导入方法依赖的package包/类
private static int getColumn(final int pos, final JTextComponent editor) {
try {
return pos - Utilities.getRowStart(editor, pos) + 1;
} catch (BadLocationException e) {
LOGGER.error("Bad location", e); //NOI18N
}
return -1;
}
示例11: currentLine
import javax.swing.text.Utilities; //导入方法依赖的package包/类
private int currentLine() {
int caretPos = scriptField.getCaretPosition();
int rowNum = (caretPos == 0) ? 1 : 0;
for (int offset = caretPos; offset > 0; ) {
try {
offset = Utilities.getRowStart(scriptField, offset) - 1;
} catch (BadLocationException e) {
e.printStackTrace();
}
rowNum++;
}
return rowNum;
}
示例12: getRow
import javax.swing.text.Utilities; //导入方法依赖的package包/类
/**
* 指定キャレット位置の行番号を取得する
*
* @param editor
* テキストコンポーネント
* @param pos
* キャレット位置
* @return 行番号(1〜)
*/
public static int getRow(JTextComponent editor, int pos) {
int rn = (pos == 0) ? 1 : 0;
try {
int offs = pos;
while (offs > 0) {
offs = Utilities.getRowStart(editor, offs) - 1;
rn++;
}
} catch (BadLocationException e) {
e.printStackTrace();
}
return rn;
}
示例13: getRow
import javax.swing.text.Utilities; //导入方法依赖的package包/类
public static int getRow(int pos, JTextComponent editor) {
int rn = (pos==0) ? 1 : 0;
try {
int offs=pos;
while( offs>0) {
offs=Utilities.getRowStart(editor, offs)-1;
rn++;
}
} catch (BadLocationException e) {
e.printStackTrace();
}
return rn;
}
示例14: getColumn
import javax.swing.text.Utilities; //导入方法依赖的package包/类
public static int getColumn(int pos, JTextComponent editor) {
try {
return pos-Utilities.getRowStart(editor, pos)+1;
} catch (BadLocationException e) {
e.printStackTrace();
}
return -1;
}
示例15: 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;
}