@@ -5,9 +5,13 @@ import cc.unitmesh.devti.gui.chat.message.ChatActionType
5
5
import cc.unitmesh.devti.sketch.AutoSketchMode
6
6
import com.intellij.openapi.project.Project
7
7
import com.intellij.ui.Gray
8
+ import com.intellij.ui.JBColor
8
9
import com.intellij.ui.components.JBScrollPane
9
10
import com.intellij.util.ui.JBUI
11
+ import com.intellij.util.ui.UIUtil
10
12
import java.awt.*
13
+ import java.awt.event.FocusEvent
14
+ import java.awt.event.FocusListener
11
15
import javax.swing.*
12
16
import javax.swing.border.LineBorder
13
17
@@ -18,75 +22,80 @@ class IssueInputPanel(
18
22
private val onCancel : () -> Unit
19
23
) : JPanel(BorderLayout ()) {
20
24
private val textArea: JTextArea
25
+ private var isPlaceholderVisible = true
21
26
22
27
init {
23
28
background = JBUI .CurrentTheme .ToolWindow .background()
29
+ border = JBUI .Borders .customLine(UIUtil .getBoundsColor(), 1 , 0 , 1 , 0 )
24
30
25
31
val mainPanel = JPanel (BorderLayout (8 , 8 )).apply {
26
- border = BorderFactory .createCompoundBorder(
27
- JBUI .Borders .empty(8 ),
28
- BorderFactory .createCompoundBorder(LineBorder (Gray ._230 , 1 , true ),
29
- JBUI .Borders .empty(8 )
30
- )
31
- )
32
32
background = JBUI .CurrentTheme .ToolWindow .background()
33
33
}
34
34
35
- val headerLabel = JLabel (title).apply {
36
- font = font.deriveFont(font.size + 2f )
37
- border = JBUI .Borders .emptyBottom(10 )
38
- }
39
-
40
35
textArea = JTextArea ().apply {
41
36
lineWrap = true
42
37
wrapStyleWord = true
43
- border = null
44
38
font = Font (" Arial" , Font .PLAIN , 16 )
45
39
rows = 10
40
+ text = title
41
+ foreground = JBColor .GRAY
42
+
43
+ addFocusListener(object : FocusListener {
44
+ override fun focusGained (e : FocusEvent ? ) {
45
+ if (isPlaceholderVisible) {
46
+ text = " "
47
+ foreground = UIManager .getColor(" TextArea.foreground" )
48
+ isPlaceholderVisible = false
49
+ }
50
+ }
51
+
52
+ override fun focusLost (e : FocusEvent ? ) {
53
+ if (text.isEmpty()) {
54
+ text = title
55
+ foreground = JBColor .GRAY
56
+ isPlaceholderVisible = true
57
+ }
58
+ }
59
+ })
46
60
}
47
61
48
62
val scrollPane = JBScrollPane (textArea).apply {
49
63
border = null
50
- preferredSize = Dimension (400 , 300 )
64
+ preferredSize = Dimension (preferredSize.width , 300 )
51
65
}
52
66
53
67
val controlsPanel = JPanel (BorderLayout (10 , 0 )).apply {
54
- border = JBUI .Borders .emptyTop(10 )
55
68
background = JBUI .CurrentTheme .ToolWindow .background()
56
69
}
57
70
58
71
val buttonsPanel = JPanel ().apply {
59
72
layout = FlowLayout (FlowLayout .RIGHT , 8 , 0 )
73
+ background = JBUI .CurrentTheme .ToolWindow .background()
60
74
isOpaque = false
61
75
}
62
76
63
77
val submitButton = JButton (" Submit" ).apply {
64
78
addActionListener {
65
- val text = textArea.text
79
+ val text = if (isPlaceholderVisible) " " else textArea.text
66
80
if (text.isNotBlank()) {
67
81
handlingExecute(text)
68
82
onSubmit(text)
69
83
}
70
84
}
71
-
72
- preferredSize = Dimension (90 , 32 )
73
85
}
74
86
75
87
val cancelButton = JButton (" Cancel" ).apply {
76
88
addActionListener {
77
89
onCancel()
78
90
}
79
-
80
- preferredSize = Dimension (90 , 32 )
81
91
}
82
92
83
93
buttonsPanel.add(submitButton)
84
- buttonsPanel.add(Box .createHorizontalStrut(5 ))
94
+ buttonsPanel.add(Box .createHorizontalStrut(4 ))
85
95
buttonsPanel.add(cancelButton)
86
96
87
97
controlsPanel.add(buttonsPanel, BorderLayout .EAST )
88
98
89
- mainPanel.add(headerLabel, BorderLayout .NORTH )
90
99
mainPanel.add(scrollPane, BorderLayout .CENTER )
91
100
mainPanel.add(controlsPanel, BorderLayout .SOUTH )
92
101
@@ -100,10 +109,18 @@ class IssueInputPanel(
100
109
}
101
110
}
102
111
103
- fun getText (): String = textArea.text
112
+ fun getText (): String = if (isPlaceholderVisible) " " else textArea.text
104
113
105
114
fun setText (text : String ) {
106
- textArea.text = text
115
+ if (text.isNotBlank()) {
116
+ textArea.text = text
117
+ textArea.foreground = UIManager .getColor(" TextArea.foreground" )
118
+ isPlaceholderVisible = false
119
+ } else {
120
+ textArea.text = title
121
+ textArea.foreground = JBColor .GRAY
122
+ isPlaceholderVisible = true
123
+ }
107
124
}
108
125
109
126
fun requestTextAreaFocus () {
0 commit comments