10
10
******************************************************************************/
11
11
package com.redhat.devtools.intellij.kubernetes.dialogs
12
12
13
+ import com.intellij.openapi.actionSystem.ActionManager
14
+ import com.intellij.openapi.actionSystem.AnActionEvent
15
+ import com.intellij.openapi.actionSystem.CommonShortcuts
16
+ import com.intellij.openapi.project.DumbAwareAction
13
17
import com.intellij.openapi.project.Project
14
18
import com.intellij.openapi.ui.DialogWrapper
15
19
import com.intellij.openapi.ui.ValidationInfo
20
+ import com.intellij.ui.PopupBorder
16
21
import com.intellij.ui.TextFieldWithAutoCompletion
17
22
import com.intellij.ui.TextFieldWithAutoCompletionListProvider
18
23
import com.intellij.ui.components.JBLabel
19
- import com.intellij.util.ui.JBUI
24
+ import com.redhat.devtools.intellij.kubernetes.setBold
25
+ import com.redhat.devtools.intellij.kubernetes.setGlassPaneResizable
26
+ import com.redhat.devtools.intellij.kubernetes.setMovable
20
27
import io.fabric8.kubernetes.api.model.HasMetadata
21
- import java.awt.BorderLayout
28
+ import net.miginfocom.swing.MigLayout
22
29
import java.awt.Point
23
- import javax.swing.Box
24
- import javax.swing.BoxLayout
25
30
import javax.swing.JComponent
26
31
import javax.swing.JPanel
32
+ import javax.swing.JRootPane
33
+ import javax.swing.RootPaneContainer
27
34
import javax.swing.SwingConstants
28
35
29
36
class ResourceNameDialog <NAMESPACE : HasMetadata >(
@@ -34,9 +41,8 @@ class ResourceNameDialog<NAMESPACE: HasMetadata>(
34
41
private val location : Point ?
35
42
) : DialogWrapper(project, false ) {
36
43
37
- companion object {
38
- private const val HEIGHT = 40
39
- private const val WIDTH = 300
44
+ private val title = JBLabel (" Set current $kind " ).apply {
45
+ setBold(this )
40
46
}
41
47
42
48
private val nameTextField = TextFieldWithAutoCompletion (
@@ -55,24 +61,31 @@ class ResourceNameDialog<NAMESPACE: HasMetadata>(
55
61
}
56
62
57
63
override fun createCenterPanel (): JComponent {
58
- return JPanel (BorderLayout ()).apply {
64
+ return JPanel (
65
+ MigLayout (" ins 4, gap 4, fillx, filly, hidemode 3" )
66
+ ).apply {
67
+ add(title, " gapbottom 10, span 2, wrap" )
59
68
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 )
69
+ add(label)
70
+ add(nameTextField, " growx, pushx, w min:200, wrap" )
63
71
}
64
72
}
65
73
66
74
override fun init () {
67
- title = " Set Current $kind "
68
- setResizable(false )
69
- setOKButtonText(" Set" )
75
+ super .init ()
76
+ setUndecorated(true )
77
+ val dialogWindow = peer.window
78
+ val rootPane = (dialogWindow as RootPaneContainer ).rootPane
79
+ registerShortcuts(rootPane)
80
+ setBorders(rootPane)
81
+ setGlassPaneResizable(peer.rootPane, disposable)
82
+ setMovable(getRootPane(), title)
83
+ isResizable = false
70
84
isModal = false
71
- setSize(WIDTH , HEIGHT )
72
85
if (location != null ) {
73
86
setLocation(location.x, location.y)
74
87
}
75
- super . init ( )
88
+ setOKButtonText( " Set " )
76
89
}
77
90
78
91
override fun getPreferredFocusedComponent (): JComponent {
@@ -96,4 +109,27 @@ class ResourceNameDialog<NAMESPACE: HasMetadata>(
96
109
super .doOKAction()
97
110
onOk.invoke(nameTextField.text)
98
111
}
99
- }
112
+
113
+ private fun registerShortcuts (rootPane : JRootPane ) {
114
+ val escape = ActionManager .getInstance().getAction(" EditorEscape" )
115
+ DumbAwareAction .create { e: AnActionEvent ? -> closeImmediately() }
116
+ .registerCustomShortcutSet(
117
+ escape?.shortcutSet ? : CommonShortcuts .ESCAPE ,
118
+ rootPane,
119
+ myDisposable
120
+ )
121
+ }
122
+
123
+
124
+ private fun setBorders (rootPane : JRootPane ) {
125
+ rootPane.border = PopupBorder .Factory .create(true , true )
126
+ rootPane.windowDecorationStyle = JRootPane .NONE
127
+ }
128
+
129
+ private fun closeImmediately () {
130
+ if (isVisible) {
131
+ doCancelAction()
132
+ }
133
+ }
134
+
135
+ }
0 commit comments