Skip to content

Commit

Permalink
Tweak OptionBox
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddenton committed Aug 30, 2024
1 parent 9786d96 commit 190a6f9
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions src/main/kotlin/org/http4k/intellij/step/OptionBox.kt
Original file line number Diff line number Diff line change
@@ -1,50 +1,43 @@
package org.http4k.intellij.step

import com.intellij.ui.JBColor
import com.intellij.ui.JBColor.GRAY
import org.http4k.intellij.wizard.Option
import java.awt.Component
import java.awt.Dimension
import java.awt.Font
import javax.swing.BorderFactory
import java.awt.Component.LEFT_ALIGNMENT
import java.awt.Font.BOLD
import javax.swing.BorderFactory.createCompoundBorder
import javax.swing.BorderFactory.createEmptyBorder
import javax.swing.BorderFactory.createLineBorder
import javax.swing.Box
import javax.swing.BoxLayout
import javax.swing.BoxLayout.X_AXIS
import javax.swing.BoxLayout.Y_AXIS
import javax.swing.JComponent
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JTextArea

fun OptionBox(button: JComponent, option: Option) = JPanel().apply {
layout = BoxLayout(this, BoxLayout.Y_AXIS)
maximumSize = Dimension(150, 150)
preferredSize = Dimension(150, 150)
layout = BoxLayout(this, Y_AXIS)

border = BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(JBColor.GRAY),
BorderFactory.createEmptyBorder(10, 10, 10, 10) // 10px padding on all sides
)
border = createCompoundBorder(createLineBorder(GRAY), createEmptyBorder(5, 5, 5, 5))

// Create a panel to hold the button and label in a horizontal row
val buttonWithLabel = JPanel().apply {
layout = BoxLayout(this, BoxLayout.X_AXIS) // Horizontal layout
isOpaque = false // Make it blend with the background
add(JPanel().apply {
layout = BoxLayout(this, X_AXIS)
isOpaque = false

add(button)
add(Box.createHorizontalStrut(5)) // Small space between button and label
add(Box.createHorizontalStrut(5))
add(JLabel(option.label).apply {
font = font.deriveFont(Font.BOLD)
font = font.deriveFont(BOLD)
})
}

add(buttonWithLabel) // Add the button and label panel
add(Box.createVerticalStrut(5)) // Vertical space between rows
})
add(Box.createVerticalStrut(5))

add(JTextArea(option.description).apply {
lineWrap = true
wrapStyleWord = true
isEditable = false
isOpaque = false
border = null
alignmentX = Component.LEFT_ALIGNMENT
background = this@apply.background
alignmentX = LEFT_ALIGNMENT
})
}

0 comments on commit 190a6f9

Please sign in to comment.