Merge branch 'master' of https://gitee.com/jcnc-org/JNotepad
This commit is contained in:
commit
3daba03cbb
2
.gitignore
vendored
2
.gitignore
vendored
@ -42,3 +42,5 @@ build/
|
||||
logs/
|
||||
/ch_language_pack.txt
|
||||
/en_language_pack.txt
|
||||
/jnotepadConfig.json
|
||||
/qodana.yaml
|
||||
|
||||
@ -18,10 +18,6 @@ public class AppConstants {
|
||||
* 初始高度
|
||||
*/
|
||||
public static final double SCREEN_LENGTH = 600;
|
||||
/**
|
||||
* 应用名
|
||||
*/
|
||||
public static final String APP_NAME = "JNotepad";
|
||||
/**
|
||||
* logo地址
|
||||
*/
|
||||
|
||||
@ -6,6 +6,10 @@ import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 文本常量
|
||||
* <p>
|
||||
* 任何string请都在此处readPropertiesFromFile,然后在
|
||||
* src/main/java/org/jcnc/jnotepad/init/Config.java的getXXXXXLanguagePack
|
||||
* 注册配置文件,设置多语言语言包
|
||||
*
|
||||
* @author gewuyou
|
||||
*/
|
||||
@ -56,7 +60,7 @@ public class TextConstants {
|
||||
public static final String JNOTEPAD_EN_LANGUAGE_PACK_NAME = PROPERTIES.getProperty("JNotepad en_language_pack");
|
||||
|
||||
/// EncodingDetector 文本常量
|
||||
public static final String UNKNOWN = "UNKNOWN";
|
||||
public static final String UNKNOWN = PROPERTIES.getProperty("UNKNOWN");
|
||||
|
||||
/// JNotepadStatusBox
|
||||
public static final String ROW = PROPERTIES.getProperty("ROW");
|
||||
|
||||
@ -3,6 +3,7 @@ package org.jcnc.jnotepad.tool;
|
||||
|
||||
import com.ibm.icu.text.CharsetDetector;
|
||||
import com.ibm.icu.text.CharsetMatch;
|
||||
import org.jcnc.jnotepad.constants.TextConstants;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
@ -13,6 +14,7 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.jcnc.jnotepad.constants.TextConstants.UNKNOWN;
|
||||
|
||||
|
||||
/**
|
||||
* 编码检测工具类
|
||||
*
|
||||
@ -21,6 +23,10 @@ import static org.jcnc.jnotepad.constants.TextConstants.UNKNOWN;
|
||||
public class EncodingDetector {
|
||||
|
||||
private static final Logger LOG = LogUtil.getLogger(EncodingDetector.class);
|
||||
/**
|
||||
* 编码侦测概率,阈值:50%
|
||||
*/
|
||||
public static final int THRESHOLD_CONFIDENCE = 50;
|
||||
|
||||
|
||||
private EncodingDetector() {
|
||||
@ -36,10 +42,22 @@ public class EncodingDetector {
|
||||
CharsetDetector charsetDetector = new CharsetDetector();
|
||||
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file.getPath()))) {
|
||||
charsetDetector.setText(inputStream);
|
||||
CharsetMatch match = charsetDetector.detect();
|
||||
CharsetMatch[] matchList = charsetDetector.detectAll();
|
||||
if (matchList == null || matchList.length == 0) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
CharsetMatch maxConfidence = matchList[0];
|
||||
if (maxConfidence.getConfidence() < THRESHOLD_CONFIDENCE) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
for (int i = 1; i < matchList.length; i++) {
|
||||
CharsetMatch match = matchList[i];
|
||||
LOG.debug("{} : {}", match.getName(), match.getConfidence());
|
||||
if (match.getConfidence() > 50) {
|
||||
return match.getName();
|
||||
if (match.getConfidence() >= THRESHOLD_CONFIDENCE && match.getConfidence() >= maxConfidence.getConfidence()) {
|
||||
maxConfidence = match;
|
||||
} else {
|
||||
return maxConfidence.getName();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("", e);
|
||||
@ -56,7 +74,7 @@ public class EncodingDetector {
|
||||
public static Charset detectEncodingCharset(File file) {
|
||||
String charset = detectEncoding(file);
|
||||
if (charset.equals(UNKNOWN)) {
|
||||
return StandardCharsets.UTF_8;
|
||||
return Charset.defaultCharset();
|
||||
}
|
||||
return Charset.forName(charset);
|
||||
}
|
||||
|
||||
@ -41,18 +41,26 @@ public class LineNumberTextArea extends BorderPane {
|
||||
"-fx-border-color:white;" +
|
||||
"-fx-background-color:white"
|
||||
);
|
||||
|
||||
initListeners();
|
||||
|
||||
setCenter(mainTextArea);
|
||||
setLeft(lineNumberArea);
|
||||
|
||||
initListeners();
|
||||
|
||||
}
|
||||
|
||||
private void initListeners() {
|
||||
// 当主要文本区域的垂直滚动位置发生变化时,使行号文本区域的滚动位置保持一致
|
||||
mainTextArea.scrollTopProperty().addListener((observable, oldValue, newValue) -> lineNumberArea.setScrollTop(mainTextArea.getScrollTop()));
|
||||
mainTextArea.scrollTopProperty().addListener((observable, oldValue, newValue) -> {
|
||||
lineNumberArea.setScrollTop(mainTextArea.getScrollTop());
|
||||
});
|
||||
|
||||
// 当行号文本区域的垂直滚动位置发生变化时,使主要文本区域的滚动位置保持一致
|
||||
lineNumberArea.scrollTopProperty().addListener((observable, oldValue, newValue) -> mainTextArea.setScrollTop(lineNumberArea.getScrollTop()));
|
||||
lineNumberArea.scrollTopProperty().addListener((observable, oldValue, newValue) -> {
|
||||
mainTextArea.setScrollTop(lineNumberArea.getScrollTop());
|
||||
});
|
||||
|
||||
lineNumberArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberWidth());
|
||||
|
||||
this.mainTextArea.caretPositionProperty().addListener((caretObservable, oldPosition, newPosition) -> JNotepadStatusBox.getInstance().updateWordCountStatusLabel());
|
||||
@ -126,9 +134,10 @@ public class LineNumberTextArea extends BorderPane {
|
||||
lineNumberText.append(i).append("\n");
|
||||
}
|
||||
lineNumberArea.setText(lineNumberText.toString());
|
||||
|
||||
// 恢复之前的滚动位置
|
||||
mainTextArea.setScrollTop(mainTextAreaScrollTop);
|
||||
lineNumberArea.setScrollTop(lineNumberAreaScrollTop - 8);
|
||||
lineNumberArea.setScrollTop(lineNumberAreaScrollTop-8);
|
||||
}
|
||||
|
||||
public TextArea getMainTextArea() {
|
||||
|
||||
@ -4,7 +4,7 @@ jpackage `
|
||||
-m org.jcnc.jnotepad/org.jcnc.jnotepad.LunchApp `
|
||||
--runtime-image .\target\JNotepad\ `
|
||||
--icon src/main/resources/img/icon.ico `
|
||||
--app-version 1.1.10 `
|
||||
--app-version 1.1.11 `
|
||||
--vendor "JCNC"
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user