📄 ideutil.java
字号:
/*
* Created on 2004-5-30
*/
package yuchifang.javaIDE.util;
import java.awt.Dimension;
/**
* @author yuchifang
*/
public final class IDEUtil
{
/**
* 计算一个字符串中某个<b>光标位置</b>的行列值(如果不是用getCaretPosition获得的位置会出问题)
* @param s 字符串
* @param pos 位置,有效范围是 [ 0, s.length()]
* @return Dimension.width是行的值,Dimension.height是列的值
*/
public static Dimension getCaretRowCol(String s, int pos)
{
if (pos < 0 || pos > s.length()) return null;
int col = 1;
int row = 1;
// "\r\n"在text中是两个字符,但在caretPos来说只是一个,故做此替换
s = s.replaceAll("\r\n", "\n");
int lastIndex=0;
int index = s.indexOf("\n");
while (index >= 0 && index < pos)
{
row++;
lastIndex = index;
index = s.indexOf("\n", index+1);
}
col = pos - lastIndex + 1;
return new Dimension(col, row);
}
/**
* 获取行数,以"\n"做为行辨认符
* @param s 字符串
* @return 行数
*/
public static int getLineCount(String s)
{
int count = 1;
s = s.replaceAll("\r\n", "\n");
for (int i=0; i<s.length(); i++)
{
if (s.charAt(i) == '\n') count++;
}
return count;
}
//
// /**
// * 根据行列号返回其在字符串中的位置
// * @param string 字符串
// * @param row 行号
// * @param col 列号
// * @return 行列号对应的字符串位置
// */
// public static int RowCol2Pos(String string, int row, int col)
// {
// if (row < 0 || row > (getLineCount(string) + 1)) return -1;
//
// int pos = 0;
//
// String s = string.replaceAll("\r\n", "\n");
//
// int lastIndex = 0;
// int index = s.indexOf("\n");
// while (index >= 0 && row > 0)
// {
// row--;
// lastIndex = index;
// index = s.indexOf("\n", index+1);
// }
// pos = col + lastIndex - 1;
//
// return pos;
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -