Skip to content

Instantly share code, notes, and snippets.

@rubenquadros
Last active July 21, 2022 19:49
Show Gist options
  • Save rubenquadros/468af1041a2d5fd294e6f874b918bdee to your computer and use it in GitHub Desktop.
Save rubenquadros/468af1041a2d5fd294e6f874b918bdee to your computer and use it in GitHub Desktop.
Settings UI
class InspectionComponent(
private val inspectionSettingState: InspectionSettingState
) {
// used to maintain the current state
private var parser: Parser = Parser.GSON
init {
// set the current state to the persisted state
parser = inspectionSettingState.state.parser
}
/** Used to provide the UI component */
fun getPanel(): JPanel = panel {
titledRow("Configure Plugin Settings For Your Project") {
row("Select JSON parser:") {
buttonGroup {
row {
radioButton(text = "Gson").component.apply {
isSelected = parser == Parser.GSON
addActionListener {
setNewState(parser = Parser.GSON)
}
}
}
row {
radioButton(text = "Moshi").component.apply {
isSelected = parser == Parser.MOSHI
addActionListener {
setNewState(parser = Parser.MOSHI)
}
}
}
row {
radioButton(text = "Kotlinx-serialization").component.apply {
isSelected = parser == Parser.KOTLINX_SERIALIZATION
addActionListener {
setNewState(parser = Parser.KOTLINX_SERIALIZATION)
}
}
}
}
}
}
}
/** Used to reset the state. This is triggered if user clicks on reset */
fun resetState() {
// reset the state to presisted state
}
/** Used to propagate the UI state to other components */
fun getCurrentState(): Parser {
return this.parser
}
/** Whenever a radio button is selected the current state is updated */
private fun setNewState(parser: Parser) {
this.parser = parser
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment