📄 jmtextarea.java
字号:
// 暥帤楍挿傪UNICODE僉儍儔僋僞悢偱敾抐
if (piLengthMethod == LENGTH_BY_UNICODE) {
/*
巜掕偝傟偨峴偺奐巒僆僼僙僢僩傪庢摼偡傞
巜掕偝傟偨峴偺廔椆僆僼僙僢僩傪庢摼偡傞丅
廔椆僆僼僙僢僩偐傜奐巒僆僼僙僢僩偺嵎傪偲傝丄1僾儔僗偡傞
寁嶼偟偨抣傪栠傝抣偲偟偰曉傞丅
*/
String psVal = getDocument().getText(
getLineStartOffset(aiLineNum),
getLineEndOffset(aiLineNum) -
getLineStartOffset(aiLineNum) + 1);
return psVal.length();
}
// 暥帤楍挿傪OS昗弨暥帤僙僢僩偵傛傞僶僀僩悢偱敾抐
else {
/*
巜掕偝傟偨峴偺暥帤楍傪庢摼偡傞丅
暥帤楍偺僶僀僩攝楍傪庢摼偡傞丅
僶僀僩攝楍偺挿偝傪栠傝抣偲偟偰曉傞丅
*/
String psVal = getDocument().getText(
getLineStartOffset(aiLineNum),
getLineEndOffset(aiLineNum) -
getLineStartOffset(aiLineNum));
return psVal.getBytes().length;
} // END IF
} catch (Exception ex) {
//椺奜偑敪惗偟偨応崌丄傑偨偼僄儔乕偑敪惗偟偨応崌偼-1傪曉傞丅
return -1;
} // END TRY
} // END getLength(int)
/**
* getLengthMethod
* 暥帤楍挿偺敾抐曽朄傪庢摼偡傞丅
* @return int : 暥帤楍挿偺敾掕曽朄偑曉傞丅栠傝抣偵偼師偺堄枴偑偁偡
* 栠傝抣 愢柧
* LENGTH_BY_UNICODE UNICODE 僉儍儔僋僞悢偵傛傝敾掕偡傞丅
* LENGTH_BY_NATIVE OS偺昗弨暥帤僙僢僩偵傛傞僶僀僩悢偵傛傝敾掕偡傞丅
*/
public int getLengthMethod () {
return piLengthMethod;
} // END getLengthMethod()
/**
* getMaxLength
* 扨峴偵擖椡偱偒傞嵟戝暥帤楍挿傪庢摼偡傞丅
* @return int : 扨峴偵擖椡偱偒傞嵟戝暥帤楍挿偑曉傞丅
*/
public int getMaxLineLength () {
return piMaxLength;
} // END getMaxLength()
/**
* getMaxLineCount
* 僥僉僗僩僄儕傾偵擖椡壜擻側嵟戝峴悢傪庢摼偡傞丅
* @return int : 僥僉僗僩僄儕傾偵擖椡壜擻側嵟戝峴悢偑曉傞丅
*/
public int getMaxLineCount () {
return piMaxLineCount;
} // END getMaxLineCount()
/**
* getRefusalCharacterMode
* 擖椡嫅斲偡傞暥帤僙僢僩儌乕僪傪庢摼偡傞丅
* @return int : 愝掕偝傟偰偄傞擖椡嫅斲儌乕僪偑曉傞丅
* 栠傝抣偼師偺抣偺慻傒崌傢偣偺堄枴傪帩偮丅
* 栠傝抣 愢柧
* REFUSAL_NONE 慡偰偺暥帤庬傪嫋壜偟偰偄傞丅
* REFUSAL_WIDE 慡妏暥帤偺擖椡傪嫅斲偟偰偄傞丅
* REFUSAL_NUMBER 敿妏悢帤偺擖椡傪嫅斲偟偰偄傞丅
* REFUSAL_ALPHABET 敿妏塸帤偺擖椡傪嫅斲偟偰偄傞丅
* REFUSAL_SYMBOL 敿妏婰崋偺擖椡傪嫅斲偟偰偄傞丅
*/
public int getRefusalCharacterMode () {
return piRefusalMode;
} // END getRefusalCharacterMode()
/**
* getReplaceMode
* 尰嵼偺抲姺儌乕僪傪庢摼偡傞丅
* @return boolean : 尰嵼偺抲姺儌乕僪偑曉傞丅
* 栠傝抣 愢柧
* true 僼僅乕僇僗庢摼帪偵慡僥僉僗僩偑慖戰忬懺偵側傞丅
* false 摿偵惂屼偼峴傢側偄丅
*/
public boolean getReplaceMode () {
return pbReplaceMode;
} // END getReplaceMode()
/**
* getMaxStringNum
* 嵟戝暥帤悢偺庢摼
* @return int
*/
public int getMaxStringNum () {
return this.piMaxStringNum;
}
/**
* processFocusEvent
* 僼僅乕僇僗庢摼傑偨偼憆幐帪偺僀儀儞僩張棟傪峴偆丅
* @param aoEvent : 僼僅乕僇僗僀儀儞僩
*/
public void processFocusEvent (FocusEvent aoEvent) {
// 僼僅乕僇僗庢摼偡傞帪
if (aoEvent.getID() == FocusEvent.FOCUS_GAINED) {
if (pbReplaceMode) {
this.selectAll();
} // END IF
// IME偑IME_ON
if (piImeMethod == IME_ON) {
this.getInputContext().setCharacterSubsets(new Character.Subset[] {
InputSubset.HANJA});
super.enableInputMethods(true);
}
// IME偑IME_OFF丄IME_NONE
else if (piImeMethod == IME_OFF) {
this.getInputContext().setCharacterSubsets(new Character.Subset[] {
InputSubset.LATIN_DIGITS});
super.enableInputMethods(false);
} else {
this.getInputContext().setCharacterSubsets(new Character.Subset[] {
InputSubset.LATIN_DIGITS});
} // END IF
}
// 僼僅乕僇僗幐偆帪
else if (aoEvent.getID() == FocusEvent.FOCUS_LOST) {
//this.getInputContext().setCharacterSubsets(new Character.Subset[] {
// InputSubset.FULLWIDTH_LATIN});
super.enableInputMethods(true);
} // END IF
super.processFocusEvent(aoEvent);
} // END processFocusEvent(FocusEvent)
/**
* replaceSelection
* 僥僉僗僩僄儕傾偵擖椡偝傟偨暥帤楍偺僠僃僢僋偲憓擖張棟傪峴偆丅
* @param asDestination : 僥僉僗僩僄儕傾偵擖椡偝傟偨暥帤楍
*/
public void replaceSelection (String asDestination) {
replaceRange(asDestination,
this.getSelectionStart(), this.getSelectionEnd());
} // END replaceSelection(String)
/**
* replaceRange
* 僥僉僗僩僄儕傾傊偺擖椡張棟傪峴偆丅
* 擖椡帪偵偼丄棙梡偡傞僥僉僗僩僄儕傾偵愝掕偝傟偨擖椡挿丄
* 暥帤楍惂尷偵傛傞僠僃僢僋偑峴傢傟傞丅
* @param asDestination : 僥僉僗僩僄儕傾偵擖椡偝傟偨暥帤楍
* @param aiStart : 慖戰偝傟偰偄傞僥僉僗僩偺奐巒埵抲傪巜掕偡傞
* @param aiEnd : 慖戰偝傟偰偄傞僥僉僗僩偺廔椆埵抲傪巜掕偡傞
*/
public void replaceRange (String asDestination, int aiStart, int aiEnd) {
//擖椡嫅斲暥帤楍偺僠僃僢僋
if (piRefusalMode != REFUSAL_NONE) {
//堷悢asDestination偵piRefusalMode偵堦抳偡傞暥帤楍偑懚嵼偡傞偐僠僃僢僋偡傞丅
String psReVal = SNULL + phRefusal.get(SNULL + piRefusalMode);
if (mChkStr(psReVal).equals(SNULL)) {
return;
} // END IF
if (piImeMethod == IME_OFF) {
if (JMCheck.isZen(asDestination)) {
return;
} // END IF
}
if (asDestination == null) {
if (this.getSelectionEnd() != this.getSelectionStart()) {
super.replaceSelection(asDestination);
} // END IF
return;
} // END IF
for (int m = 0; m < psReVal.length(); m++) {
char psStr = psReVal.charAt(m);
//慡妏暥帤偺擖椡傪嫅斲
if (psStr == '1') {
for (int n = 0; n < asDestination.length(); n++) {
if ((SNULL + asDestination.charAt(n)).getBytes().
length == 2) {
return;
} // END IF
} // END FOR
} // END IF
//敿妏悢帤偺擖椡傪嫅斲
if (psStr == '2') {
if (!JMCheck.isNumAlpha(asDestination)) {
return;
} // END IF
} // END IF
//敿妏塸帤偺擖椡傪嫅斲
if (psStr == '4') {
if (!JMCheck.isEngAlpha(asDestination)) {
return;
} // END IF
} // END IF
//敿妏婰崋偺擖椡傪嫅斲
if (psStr == '8') {
if (mChkSignAlpha(asDestination)) {
return;
} // END IF
} // END IF
} // END FOR
} // END IF
if (piMaxLineCount != 0) {
int curLines = this.calculateLines(this.getText() + asDestination);
if (curLines > piMaxLineCount) {
return;
}
}
if (piMaxStringNum > 0) {
int max = piMaxLineCount * piMaxLength;
max = max > 0 ? Math.min(max, piMaxStringNum) : piMaxStringNum;
int leftLen = max - getText().length();
if (leftLen < asDestination.length()) {
asDestination = asDestination.substring(0, leftLen);
}
}
super.replaceRange(asDestination, aiStart, aiEnd);
} // END replaceRange(String, int, int)
/**
* setIMEMethod
* IME偺惂屼曽朄傪愝掕偡傞丅
* @param aiImeMethod : IME偺惂屼曽朄傪巜掕偡傞丅惂屼曽朄偼師偺抣傪巜掕偡傞丅
* 抣 愢柧
* IME_NONE IME 惂屼傪摿偵峴傢側偄丅
* IME_ON 僼僅乕僇僗庢摼帪偵IME傪ON偵偡傞丅
* IME_OFF 僼僅乕僇僗庢摼帪偵IME 傪OFF偵偡傞丅
* @return boolean : 惉岟帪偼true傪曉偟傑偡丅堷悢偑晄惓側応崌偼false傪曉傞丅
*/
public boolean setIMEMethod (int aiImeMethod) {
if (aiImeMethod != IME_NONE &&
aiImeMethod != IME_ON &&
aiImeMethod != IME_OFF) {
return false;
} // END IF
piImeMethod = aiImeMethod;
return true;
} // END setIMEMethod(int)
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -