
org.fernice.reflare.element.Text.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fernice-reflare Show documentation
Show all versions of fernice-reflare Show documentation
CSS integration through fernice-flare in Java Swing as a LookAndFeel
package org.fernice.reflare.element
import org.fernice.flare.selector.NonTSPseudoClass
import org.fernice.flare.selector.PseudoElement
import org.fernice.flare.style.ComputedValues
import org.fernice.reflare.awt.toAWTColor
import java.awt.Component
import javax.swing.JEditorPane
import javax.swing.JFormattedTextField
import javax.swing.JLabel
import javax.swing.JPasswordField
import javax.swing.JTextArea
import javax.swing.JTextField
import javax.swing.JTextPane
import javax.swing.text.JTextComponent
class LabelElement(label: JLabel) : ComponentElement(label) {
override val localName get() = "label"
override fun hasPseudoElement(pseudoElement: PseudoElement): Boolean {
return when (pseudoElement) {
PseudoElement.Flare_Icon -> true
else -> super.matchPseudoElement(pseudoElement)
}
}
override fun matchPseudoElement(pseudoElement: PseudoElement): Boolean {
return when (pseudoElement) {
PseudoElement.Flare_Icon -> true
else -> super.matchPseudoElement(pseudoElement)
}
}
}
abstract class TextElement(textComponent: JTextComponent) : ComponentElement(textComponent) {
override fun matchNonTSPseudoClass(pseudoClass: NonTSPseudoClass, component: Component): Boolean {
return when (pseudoClass) {
NonTSPseudoClass.ReadWrite -> (component as JTextComponent).isEditable
NonTSPseudoClass.ReadOnly -> !(component as JTextComponent).isEditable
else -> super.matchNonTSPseudoClass(pseudoClass, component)
}
}
override fun updateStyle(style: ComputedValues) {
val component = component as JTextComponent
component.caretColor = style.color.color.toAWTColor()
}
override fun hasPseudoElement(pseudoElement: PseudoElement): Boolean {
return when (pseudoElement) {
PseudoElement.Selection -> true
else -> super.matchPseudoElement(pseudoElement)
}
}
override fun matchPseudoElement(pseudoElement: PseudoElement): Boolean {
return when (pseudoElement) {
PseudoElement.Selection -> true
else -> super.matchPseudoElement(pseudoElement)
}
}
override fun updatePseudoElement(pseudoElement: PseudoElement, style: ComputedValues) {
when (pseudoElement) {
PseudoElement.Selection -> {
val component = component as JTextComponent
component.selectedTextColor = style.color.color.toAWTColor()
component.selectionColor = style.background.color.toAWTColor()
}
else -> super.updatePseudoElement(pseudoElement, style)
}
}
}
open class TextFieldElement(textField: JTextField) : TextElement(textField) {
override val localName get() = "text"
}
class FormattedTextFieldElement(textField: JFormattedTextField) : TextFieldElement(textField)
class PasswordFieldElement(textField: JPasswordField) : TextFieldElement(textField)
class TextAreaElement(textArea: JTextArea) : TextElement(textArea) {
override val localName get() = "textarea"
}
open class EditorPaneElement(editorPane: JEditorPane) : TextElement(editorPane) {
override val localName get() = "text"
}
open class TextPaneElement(textPane: JTextPane) : EditorPaneElement(textPane) {
override val localName get() = "textpane"
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy