@@ -2,14 +2,18 @@ package com.vk.admstorm.ssh
2
2
3
3
import com.intellij.openapi.project.Project
4
4
import com.intellij.openapi.ui.DialogWrapper
5
+ import com.intellij.ui.JBColor
5
6
import com.intellij.ui.components.JBCheckBox
6
7
import com.intellij.ui.components.JBPasswordField
7
8
import com.intellij.ui.dsl.builder.AlignX
8
9
import com.intellij.ui.dsl.builder.BottomGap
9
10
import com.intellij.ui.dsl.builder.TopGap
10
11
import com.intellij.ui.dsl.builder.panel
11
12
import com.intellij.util.ui.JBDimension
13
+ import java.awt.event.KeyAdapter
14
+ import java.awt.event.KeyEvent
12
15
import javax.swing.JComponent
16
+ import javax.swing.JLabel
13
17
import javax.swing.JPanel
14
18
15
19
class EnterPasswordDialog (project : Project ) : DialogWrapper(project, true , IdeModalityType .PROJECT ) {
@@ -25,38 +29,54 @@ class EnterPasswordDialog(project: Project) : DialogWrapper(project, true, IdeMo
25
29
}
26
30
}
27
31
28
- private var myPasswordInput = JBPasswordField ()
29
- private val myRememberCheckBox = JBCheckBox (" Remember" , true )
32
+ private var passwordInput = JBPasswordField ()
33
+ private val rememberCheckBox = JBCheckBox (" Remember" , true )
34
+ private val warningLabel = JLabel ().apply { foreground = JBColor .RED }
30
35
31
- fun getPassword () = String (myPasswordInput .password)
32
- fun isRemember () = myRememberCheckBox .isSelected
36
+ fun getPassword () = String (passwordInput .password)
37
+ fun isRemember () = rememberCheckBox .isSelected
33
38
34
39
init {
35
- title = " Enter Password "
40
+ title = " Enter PIN "
36
41
37
42
init ()
43
+
44
+ passwordInput.addKeyListener(object : KeyAdapter () {
45
+ override fun keyReleased (e : KeyEvent ) {
46
+ if (getPassword().any { it in ' А' .. ' я' || it == ' ё' || it == ' Ё' }) {
47
+ warningLabel.text = " PIN should contain only English characters and numbers!"
48
+ } else {
49
+ warningLabel.text = " "
50
+ }
51
+ }
52
+ })
38
53
}
39
54
40
- override fun getPreferredFocusedComponent () = myPasswordInput
55
+ override fun getPreferredFocusedComponent () = passwordInput
41
56
42
57
override fun createSouthAdditionalPanel (): JPanel {
43
58
return panel {
44
59
row {
45
- cell(myRememberCheckBox )
60
+ cell(rememberCheckBox )
46
61
}
47
62
}
48
63
}
49
64
50
65
override fun createCenterPanel (): JComponent {
51
66
return panel {
52
67
row {
53
- label(" Enter password for Yubikey:" )
68
+ label(" Enter PIN for Yubikey:" )
54
69
}.topGap(TopGap .NONE )
55
70
56
71
row {
57
- cell(myPasswordInput )
72
+ cell(passwordInput )
58
73
.align(AlignX .FILL )
59
74
}.bottomGap(BottomGap .NONE )
75
+
76
+ row{
77
+ cell(warningLabel)
78
+ }.bottomGap(BottomGap .NONE )
79
+
60
80
}.apply {
61
81
preferredSize = JBDimension (300 , - 1 )
62
82
}
0 commit comments