@@ -16,14 +16,17 @@ import com.intellij.openapi.ui.ValidationInfo
16
16
import com.intellij.ui.TextFieldWithAutoCompletion
17
17
import com.intellij.ui.TextFieldWithAutoCompletionListProvider
18
18
import com.intellij.ui.components.JBLabel
19
- import com.intellij.util.ui.JBUI
19
+ import com.redhat.devtools.intellij.kubernetes.registerEscapeShortcut
20
+ import com.redhat.devtools.intellij.kubernetes.setBold
21
+ import com.redhat.devtools.intellij.kubernetes.setRootPaneBorders
22
+ import com.redhat.devtools.intellij.kubernetes.setGlassPaneResizable
23
+ import com.redhat.devtools.intellij.kubernetes.setMovable
20
24
import io.fabric8.kubernetes.api.model.HasMetadata
21
- import java.awt.BorderLayout
25
+ import net.miginfocom.swing.MigLayout
22
26
import java.awt.Point
23
- import javax.swing.Box
24
- import javax.swing.BoxLayout
25
27
import javax.swing.JComponent
26
28
import javax.swing.JPanel
29
+ import javax.swing.RootPaneContainer
27
30
import javax.swing.SwingConstants
28
31
29
32
class ResourceNameDialog <NAMESPACE : HasMetadata >(
@@ -34,9 +37,8 @@ class ResourceNameDialog<NAMESPACE: HasMetadata>(
34
37
private val location : Point ?
35
38
) : DialogWrapper(project, false ) {
36
39
37
- companion object {
38
- private const val HEIGHT = 40
39
- private const val WIDTH = 300
40
+ private val title = JBLabel (" Set current $kind " ).apply {
41
+ setBold(this )
40
42
}
41
43
42
44
private val nameTextField = TextFieldWithAutoCompletion (
@@ -55,24 +57,31 @@ class ResourceNameDialog<NAMESPACE: HasMetadata>(
55
57
}
56
58
57
59
override fun createCenterPanel (): JComponent {
58
- return JPanel (BorderLayout ()).apply {
60
+ return JPanel (
61
+ MigLayout (" ins 4, gap 4, fillx, filly, hidemode 3" )
62
+ ).apply {
63
+ add(title, " gapbottom 10, span 2, wrap" )
59
64
val label = JBLabel (" Current $kind :" , SwingConstants .LEFT )
60
- label.border = JBUI .Borders .empty(0 , 2 , 2 , 0 )
61
- add(label, BorderLayout .PAGE_START )
62
- add(nameTextField, BorderLayout .CENTER )
65
+ add(label)
66
+ add(nameTextField, " growx, pushx, w min:200, wrap" )
63
67
}
64
68
}
65
69
66
70
override fun init () {
67
- title = " Set Current $kind "
68
- setResizable(false )
69
- setOKButtonText(" Set" )
71
+ super .init ()
72
+ setUndecorated(true )
73
+ val dialogWindow = peer.window
74
+ val rootPane = (dialogWindow as RootPaneContainer ).rootPane
75
+ registerEscapeShortcut(rootPane, ::closeImmediately, myDisposable)
76
+ setRootPaneBorders(rootPane)
77
+ setGlassPaneResizable(peer.rootPane, disposable)
78
+ setMovable(getRootPane(), title)
79
+ isResizable = false
70
80
isModal = false
71
- setSize(WIDTH , HEIGHT )
72
81
if (location != null ) {
73
82
setLocation(location.x, location.y)
74
83
}
75
- super . init ( )
84
+ setOKButtonText( " Set " )
76
85
}
77
86
78
87
override fun getPreferredFocusedComponent (): JComponent {
@@ -86,7 +95,7 @@ class ResourceNameDialog<NAMESPACE: HasMetadata>(
86
95
87
96
override fun doValidate (): ValidationInfo ? {
88
97
return if (nameTextField.text.isEmpty()) {
89
- ValidationInfo (" Name musn 't be empty" , nameTextField)
98
+ ValidationInfo (" Name mustn 't be empty" , nameTextField)
90
99
} else {
91
100
null
92
101
}
@@ -96,4 +105,10 @@ class ResourceNameDialog<NAMESPACE: HasMetadata>(
96
105
super .doOKAction()
97
106
onOk.invoke(nameTextField.text)
98
107
}
99
- }
108
+
109
+ private fun closeImmediately () {
110
+ if (isVisible) {
111
+ doCancelAction()
112
+ }
113
+ }
114
+ }
0 commit comments