This repository has been archived by the owner on Jun 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 增加熟悉词库 2. 增加过滤 BNC 和 COCA 词频前 1000 的单词 修复: 1. 生成词库时,先用鼠标单击单词的右上角的删除按钮,再点击左边的过滤区过滤单词,手动选择删除的单词会再次出现(#76)。
- Loading branch information
1 parent
45ba023
commit 2ad4c15
Showing
6 changed files
with
641 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
package dialog | ||
|
||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.material.* | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.RectangleShape | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.unit.DpSize | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.window.Dialog | ||
import androidx.compose.ui.window.WindowPosition | ||
import androidx.compose.ui.window.rememberDialogState | ||
import components.createTransferHandler | ||
import data.* | ||
import java.io.File | ||
import java.util.concurrent.FutureTask | ||
import javax.swing.JFileChooser | ||
import javax.swing.JOptionPane | ||
import javax.swing.filechooser.FileNameExtensionFilter | ||
import javax.swing.filechooser.FileSystemView | ||
|
||
/** | ||
* 导入词库到熟悉词库 | ||
*/ | ||
@Composable | ||
fun FamiliarDialog( | ||
futureFileChooser: FutureTask<JFileChooser>, | ||
close: () -> Unit | ||
){ | ||
Dialog( | ||
title = "导入词库到熟悉词库", | ||
icon = painterResource("logo/logo.png"), | ||
onCloseRequest = { close() }, | ||
resizable = false, | ||
state = rememberDialogState( | ||
position = WindowPosition(Alignment.Center), | ||
size = DpSize(600.dp, 600.dp) | ||
), | ||
) { | ||
var importing by remember { mutableStateOf(false) } | ||
var processingFile by remember { mutableStateOf("") } | ||
|
||
/** 熟悉词库 */ | ||
val familiarVocabulary = loadMutableVocabularyByName("FamiliarVocabulary") | ||
|
||
/** 导入词库 */ | ||
val import:(List<File>) -> Unit = {files -> | ||
if(files.size>100){ | ||
JOptionPane.showMessageDialog(null,"一次最多导入 100 个词库") | ||
}else{ | ||
files.forEach { file -> | ||
processingFile = file.nameWithoutExtension | ||
val vocabulary = loadVocabulary(file.absolutePath) | ||
vocabulary.wordList.forEach { word -> | ||
val index = familiarVocabulary.wordList.indexOf(word) | ||
// wordList 没有这个单词 | ||
if (index == -1) { | ||
// 如果是视频词库或字幕词库,需要把字幕变成外部字幕 | ||
if (word.captions.isNotEmpty()) { | ||
word.captions.forEach { caption -> | ||
// 创建一条外部字幕 | ||
val externalCaption = ExternalCaption( | ||
relateVideoPath = vocabulary.relateVideoPath, | ||
subtitlesTrackId = vocabulary.subtitlesTrackId, | ||
subtitlesName = vocabulary.name, | ||
start = caption.start, | ||
end = caption.end, | ||
content = caption.content | ||
) | ||
word.externalCaptions.add(externalCaption) | ||
} | ||
word.captions.clear() | ||
} | ||
familiarVocabulary.wordList.add(word) | ||
// wordList 有这个单词 | ||
} else { | ||
val oldWord = familiarVocabulary.wordList[index] | ||
// 如果单词有外部字幕,同时已经加入到列表的单词的外部字幕没有超过3个就导入 | ||
if (word.externalCaptions.isNotEmpty()) { | ||
word.externalCaptions.forEach { externalCaption -> | ||
if (oldWord.externalCaptions.size < 3) { | ||
oldWord.externalCaptions.add(externalCaption) | ||
} | ||
} | ||
// 如果单词是视频或字幕词库中的单词 | ||
} else if (word.captions.isNotEmpty()) { | ||
word.captions.forEach { caption -> | ||
// 创建一条外部字幕 | ||
val externalCaption = ExternalCaption( | ||
relateVideoPath = vocabulary.relateVideoPath, | ||
subtitlesTrackId = vocabulary.subtitlesTrackId, | ||
subtitlesName = vocabulary.name, | ||
start = caption.start, | ||
end = caption.end, | ||
content = caption.content | ||
) | ||
if (oldWord.externalCaptions.size < 3) { | ||
oldWord.externalCaptions.add(externalCaption) | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
familiarVocabulary.size = familiarVocabulary.wordList.size | ||
val familiarFile = getFamiliarVocabularyFile() | ||
saveVocabulary(familiarVocabulary.serializeVocabulary, familiarFile.absolutePath) | ||
importing = false | ||
} | ||
} | ||
|
||
/** 打开文件对话框 */ | ||
val openFileChooser:()-> Unit = { | ||
Thread(Runnable { | ||
val fileChooser = futureFileChooser.get() | ||
fileChooser.dialogTitle = "选择词库" | ||
fileChooser.fileSystemView = FileSystemView.getFileSystemView() | ||
fileChooser.fileSelectionMode = JFileChooser.FILES_ONLY | ||
fileChooser.isAcceptAllFileFilterUsed = false | ||
fileChooser.isMultiSelectionEnabled = true | ||
val fileFilter = FileNameExtensionFilter("词库", "json") | ||
fileChooser.addChoosableFileFilter(fileFilter) | ||
fileChooser.selectedFile = null | ||
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { | ||
val files = fileChooser.selectedFiles.toList() | ||
importing = true | ||
import(files) | ||
} | ||
fileChooser.selectedFile = null | ||
fileChooser.isMultiSelectionEnabled = false | ||
fileChooser.removeChoosableFileFilter(fileFilter) | ||
}).start() | ||
} | ||
|
||
/** 处理拖放文件的函数 */ | ||
val transferHandler = createTransferHandler( | ||
singleFile = false, | ||
showWrongMessage = { message -> | ||
JOptionPane.showMessageDialog(window, message) | ||
}, | ||
parseImportFile = { files -> | ||
Thread(Runnable { | ||
importing = true | ||
import(files) | ||
}).start() | ||
} | ||
) | ||
window.transferHandler = transferHandler | ||
|
||
Surface( | ||
elevation = 5.dp, | ||
shape = RectangleShape, | ||
) { | ||
Box{ | ||
Divider(Modifier.align(Alignment.TopCenter)) | ||
|
||
Column( | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
modifier = Modifier.fillMaxSize() | ||
){ | ||
Text("熟悉词库现在有 ${familiarVocabulary.wordList.size} 个单词", | ||
modifier = Modifier.padding(bottom = if(importing) 90.dp else 20.dp)) | ||
if (importing) { | ||
Row( | ||
horizontalArrangement = Arrangement.Center, | ||
modifier = Modifier.fillMaxWidth().padding(bottom = 20.dp) | ||
) { | ||
Text(text = "正在读取 $processingFile") | ||
} | ||
} | ||
Row{ | ||
OutlinedButton( | ||
onClick = { openFileChooser() }, | ||
){ | ||
Text("导入") | ||
} | ||
Spacer(Modifier.width(20.dp)) | ||
OutlinedButton( | ||
onClick = { close() }, | ||
){ | ||
Text("关闭") | ||
} | ||
} | ||
} | ||
if (importing) { | ||
CircularProgressIndicator(Modifier.align(Alignment.Center).padding(bottom = 70.dp)) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.