本文整理匯總了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;
}