Skip to content

Commit

Permalink
给编辑词库界面,增加编辑例句功能
Browse files Browse the repository at this point in the history
  • Loading branch information
tangshimin committed Sep 16, 2024
1 parent 4abd12f commit 228b3b4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/main/kotlin/ui/edit/CellVisibleState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data class CellVisible(
var usPhoneVisible: Boolean = true,
var exchangeVisible: Boolean = true,
var captionsVisible: Boolean = true,
var sentencesVisible: Boolean = true,
)

@OptIn(ExperimentalSerializationApi::class)
Expand All @@ -33,6 +34,7 @@ class CellVisibleState(cellVisible: CellVisible){
var usPhoneVisible by mutableStateOf(cellVisible.usPhoneVisible)
var exchangeVisible by mutableStateOf(cellVisible.exchangeVisible)
var captionsVisible by mutableStateOf(cellVisible.captionsVisible)
var sentencesVisible by mutableStateOf(cellVisible.sentencesVisible)


/** 保持列可见性的配置信息 */
Expand All @@ -46,6 +48,7 @@ class CellVisibleState(cellVisible: CellVisible){
usPhoneVisible,
exchangeVisible,
captionsVisible,
sentencesVisible
)
val encodeBuilder = Json {
prettyPrint = true
Expand All @@ -67,6 +70,7 @@ class CellVisibleSwingState(cellVisible: CellVisible){
var usPhoneVisible = cellVisible.usPhoneVisible
var exchangeVisible = cellVisible.exchangeVisible
var captionsVisible = cellVisible.captionsVisible
var sentencesVisible = cellVisible.sentencesVisible
}


Expand Down
27 changes: 18 additions & 9 deletions src/main/kotlin/ui/edit/EditVocabulary.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ fun Table(
"美国音标",
"英国音标",
"词形变化",
"例句",
"字幕",
)

Expand All @@ -150,6 +151,7 @@ fun Table(
word.usphone,
word.ukphone,
exchange,
word.pos,
captions,
)
)
Expand All @@ -173,6 +175,7 @@ fun Table(
sorter.setSortable(5, false)
sorter.setSortable(6, false)
sorter.setSortable(7, false)
sorter.setSortable(8, false)
table.rowSorter = sorter

// 搜索结果的高亮
Expand Down Expand Up @@ -228,7 +231,8 @@ fun Table(
model.setValueAt(it.usphone, editRow, 4)
model.setValueAt(it.ukphone, editRow, 5)
model.setValueAt(exchange, editRow, 6)
model.setValueAt(captions, editRow, 7)
model.setValueAt(it.pos, editRow, 7)
model.setValueAt(captions, editRow, 8)
// 保存词库
wordList[table.selectedRow] = it
saveVocabulary("保存成功")
Expand Down Expand Up @@ -260,7 +264,8 @@ fun Table(
val usPhoneColumn = table.columnModel.getColumn(4)
val ukPhoneColumn = table.columnModel.getColumn(5)
val exchangeColumn = table.columnModel.getColumn(6)
val captionsColumn = table.columnModel.getColumn(7)
val sentencesColumn = table.columnModel.getColumn(7)
val captionsColumn = table.columnModel.getColumn(8)


val textFieldCellEditor = DefaultCellEditor(textField)
Expand All @@ -286,6 +291,7 @@ fun Table(
translationColumn.cellRenderer = rowHeightCellRenderer
definitionColumn.cellRenderer = rowHeightCellRenderer
exchangeColumn.cellRenderer = rowHeightCellRenderer
sentencesColumn.cellRenderer = rowHeightCellRenderer
captionsColumn.cellRenderer = rowHeightCellRenderer

indexColumn.minWidth = 33
Expand All @@ -297,6 +303,7 @@ fun Table(
usPhoneColumn.preferredWidth = 95
ukPhoneColumn.preferredWidth = 95
exchangeColumn.preferredWidth = 420
sentencesColumn.preferredWidth = 350
captionsColumn.preferredWidth = 350
table.autoResizeMode = JTable.AUTO_RESIZE_OFF

Expand Down Expand Up @@ -324,9 +331,7 @@ fun Table(
close = { isSettingOpen = false },
displayColumn = {
for (pair in removedColumnSet) {
println(" ${pair.first}")
if(pair.first ==it){
println(" ${pair.first} == $it")
val column = pair.second
table.addColumn(column)
break
Expand Down Expand Up @@ -785,6 +790,7 @@ fun Table(
it.usphone,
it.ukphone,
captions,
it.pos,
exchange
)
model.addRow(row)
Expand Down Expand Up @@ -986,17 +992,20 @@ fun displayOrHideColumn(cellVisibleState: CellVisibleSwingState, table: JTable):
if (!cellVisibleState.definitionVisible) {
hideColumnList.add("英文释义" to 3)
}
if (!cellVisibleState.usPhoneVisible) {
hideColumnList.add("英国英标" to 4)
}
if (!cellVisibleState.uKPhoneVisible) {
hideColumnList.add("美国音标" to 5)
hideColumnList.add("美国音标" to 4)
}
if (!cellVisibleState.usPhoneVisible) {
hideColumnList.add("英国英标" to 5)
}
if (!cellVisibleState.exchangeVisible) {
hideColumnList.add("词形变化" to 6)
}
if (!cellVisibleState.sentencesVisible) {
hideColumnList.add("例句" to 7)
}
if (!cellVisibleState.captionsVisible) {
hideColumnList.add("字幕" to 7)
hideColumnList.add("字幕" to 8)
}
hideColumnList.reverse()
hideColumnList.forEach { (columnName,columnIndex) ->
Expand Down
30 changes: 25 additions & 5 deletions src/main/kotlin/ui/edit/ExportVocabulary.kt
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,17 @@ fun ExportVocabulary(
)
}
)
ListItem(
text = { Text("例句", color = MaterialTheme.colors.onBackground) },
modifier = Modifier.clickable { cellVisible.sentencesVisible = !cellVisible.sentencesVisible },
trailing = {
Switch(
colors = SwitchDefaults.colors(checkedThumbColor = MaterialTheme.colors.primary),
checked = cellVisible.sentencesVisible,
onCheckedChange = {cellVisible.sentencesVisible = !cellVisible.sentencesVisible},
)
}
)
ListItem(
text = { Text("字幕", color = MaterialTheme.colors.onBackground) },
modifier = Modifier.clickable { cellVisible.captionsVisible = !cellVisible.captionsVisible },
Expand Down Expand Up @@ -734,15 +745,13 @@ fun createWorkbook(
val cell = headerRow.createCell(cellIndex++)
cell.cellStyle = headerStyle
cell.setCellValue("中文释义")

}
if(cellVisible.definitionVisible){
// 50 个字符宽度
sheet.setColumnWidth(cellIndex, 256 * 50)
val cell = headerRow.createCell(cellIndex++)
cell.cellStyle = headerStyle
cell.setCellValue("英文释义")

}
if(cellVisible.uKPhoneVisible){

Expand All @@ -761,7 +770,13 @@ fun createWorkbook(
val cell = headerRow.createCell(cellIndex++)
cell.cellStyle = headerStyle
cell.setCellValue("词形变化")

}
if(cellVisible.sentencesVisible){
// 50 个字符宽度
sheet.setColumnWidth(cellIndex, 256 * 50)
val cell = headerRow.createCell(cellIndex++)
cell.cellStyle = headerStyle
cell.setCellValue("例句")
}
if(cellVisible.captionsVisible){
captionsIndex = cellIndex
Expand Down Expand Up @@ -808,6 +823,11 @@ fun createWorkbook(
cell.setCellValue(exchange)
cell.cellStyle = bodyStyle
}
if(cellVisible.sentencesVisible){
val cell = row.createCell(cellIndex++)
cell.setCellValue(word.pos)
cell.cellStyle = bodyStyle
}
if(cellVisible.captionsVisible){
val captions = displayCaptions(word, vocabularyType)
val cell = row.createCell(cellIndex++)
Expand All @@ -818,8 +838,8 @@ fun createWorkbook(

// 自动调整列宽
for (columnIndex in 0 until cellIndex) {
// 中文释义、英文释义和词形变化的列宽度不自动调整
if (columnIndex != 1 && columnIndex != 2 && columnIndex != 5) {
// 中文释义、英文释义和词形变化和例句的列宽度不自动调整
if (columnIndex != 1 && columnIndex != 2 && columnIndex != 5 && columnIndex != 6) {
sheet.autoSizeColumn(columnIndex)
}
// 字幕列宽度最小为 10 个字符宽度
Expand Down
18 changes: 18 additions & 0 deletions src/main/kotlin/ui/edit/Setting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,24 @@ fun Setting(
)
}
)
ListItem(
text = { Text("例句", color = MaterialTheme.colors.onBackground) },
trailing = {
Switch(
colors = SwitchDefaults.colors(checkedThumbColor = MaterialTheme.colors.primary),
checked = cellVisible.sentencesVisible,
onCheckedChange = {
cellVisible.sentencesVisible = it
if (it) {
displayColumn("例句")
} else {
hideColumn("例句")
}
cellVisible.saveCellVisibleState()
},
)
}
)
ListItem(
text = { Text("字幕", color = MaterialTheme.colors.onBackground) },
trailing = {
Expand Down

0 comments on commit 228b3b4

Please sign in to comment.