Skip to content

Commit

Permalink
Functional translation tool incl import and export
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-griffith committed Jan 10, 2025
1 parent 75f2b55 commit 6ba73f0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class ToolPanel(
layoutConstraints: String = "ins 6, fill, hidemode 3",
) : JPanel(MigLayout(layoutConstraints)), FloatableComponent, PopupMenuCustomizer {
abstract override val icon: Icon?
override val tabName: String get() = name
override val tabName: String get() = name ?: this.paramString()
override val tabTooltip: String get() = toolTipText

override fun customizePopupMenu(menu: JPopupMenu) = Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class FileFilterSidebar<T> private constructor(
}
}

val fileDropButton = JButton("Drop files here.").apply {
val fileDropButton = JButton("Drop files here").apply {
isVisible = false
putClientProperty("FlatLaf.styleClass", "h2.regular")
}
Expand Down Expand Up @@ -538,7 +538,7 @@ internal class FileFilterColumns<T> : ColumnList<FileFilterConfigItem<T>>() {
value as Color?
JLabel().apply {
isOpaque = value != null
text = value?.toRgbHex().orEmpty()
text = value?.toHexString().orEmpty()
background = value
this@apply.toolTipText = "Click to change color"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ open class FilterSidebar<T>(
}

companion object {
val FilterPanel<*>.formattedTabName
@JvmStatic
protected val FilterPanel<*>.formattedTabName
get() = buildString {
tag("html") {
tag("p", "style" to "margin: 3px;") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ package io.github.inductiveautomation.kindling.utils
import com.formdev.flatlaf.extras.FlatSVGIcon
import com.github.weisj.jsvg.SVGDocument
import com.github.weisj.jsvg.attributes.ViewBox
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.swing.Swing
import org.jdesktop.swingx.decorator.ColorHighlighter
import org.jdesktop.swingx.decorator.ComponentAdapter
import org.jdesktop.swingx.decorator.HighlightPredicate
import org.jdesktop.swingx.prompt.BuddySupport
import java.awt.Color
import java.awt.Component
import java.awt.Container
Expand All @@ -23,13 +30,6 @@ import javax.swing.event.DocumentEvent
import javax.swing.event.DocumentListener
import javax.swing.event.EventListenerList
import javax.swing.text.Document
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.swing.Swing
import org.jdesktop.swingx.decorator.ColorHighlighter
import org.jdesktop.swingx.decorator.ComponentAdapter
import org.jdesktop.swingx.decorator.HighlightPredicate
import org.jdesktop.swingx.prompt.BuddySupport

/**
* A common CoroutineScope bound to the event dispatch thread (see [Dispatchers.Swing]).
Expand Down Expand Up @@ -155,7 +155,8 @@ fun ColorHighlighter(
predicate: (component: Component, componentAdapter: ComponentAdapter) -> Boolean = { _, _ -> true },
) = ColorHighlighter(HighlightPredicate(predicate), background, foreground)

fun Color.toRgbHex(): String {
val hexString = Integer.toHexString(rgb).substring(2)
return "#$hexString"
@OptIn(ExperimentalStdlibApi::class)
fun Color.toHexString(alpha: Boolean = false): String {
val hexString = rgb.toHexString()
return "#${if (alpha) hexString else { hexString.substring(2) }}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TableColorCellEditor(
label.apply {
isOpaque = true
background = colorChooser.selectionModel.selectedColor
if (showHex) text = colorChooser.selectionModel.selectedColor.toRgbHex() + " (editing...)"
if (showHex) text = colorChooser.selectionModel.selectedColor.toHexString() + " (editing...)"
}
}

Expand Down Expand Up @@ -67,7 +67,7 @@ class TableColorCellEditor(
background = component.background

if (component is JComponent) border = component.border
if (showHex) text = component.background?.toRgbHex().orEmpty() + " (editing...)"
if (showHex) text = component.background?.toHexString().orEmpty() + " (editing...)"
}

if (!::dialog.isInitialized) {
Expand Down Expand Up @@ -99,7 +99,7 @@ class RandomColorPanel : AbstractColorChooserPanel() {

override fun updateChooser() {
previewLabel.apply {
text = colorFromModel.toRgbHex()
text = colorFromModel.toHexString()
background = colorFromModel
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,31 @@ class TableHeaderCheckbox(

private val isAllDataSelected: Boolean
get() {
if (!this::table.isInitialized || targetColumn == null) return false
val column = targetColumn
if (!this::table.isInitialized || column == null) return false

val columnModelIndex = table.convertColumnIndexToModel(targetColumn!!)
val columnClass = table.getColumnClass(targetColumn!!)

println("Column class: $columnClass")
val columnModelIndex = table.convertColumnIndexToModel(column)
val columnClass = table.getColumnClass(column)

if (columnClass != java.lang.Boolean::class.java) return false

val data = (0..<table.rowCount).map {
return table.model.rowIndices.all {
table.model.getValueAt(it, columnModelIndex) as? Boolean ?: return false
}

return data.all { it }
}

private fun handleClick() {
valueIsAdjusting = true

if (!this::table.isInitialized || targetColumn == null) return
val column = targetColumn
if (!this::table.isInitialized || column == null) return

val columnModelIndex = table.convertColumnIndexToModel(targetColumn!!)
val columnClass = table.getColumnClass(targetColumn!!)
val columnModelIndex = table.convertColumnIndexToModel(column)
val columnClass = table.getColumnClass(column)

if (columnClass != java.lang.Boolean::class.java) return

for (row in 0..<table.rowCount) {
for (row in table.model.rowIndices) {
table.model.setValueAt(isSelected, row, columnModelIndex)
}

Expand Down

0 comments on commit 6ba73f0

Please sign in to comment.