@@ -9,51 +9,27 @@ import com.intellij.openapi.fileEditor.FileEditorLocation
9
9
import com.intellij.openapi.fileEditor.FileEditorState
10
10
import com.intellij.openapi.fileEditor.FileEditorStateLevel
11
11
import com.intellij.openapi.project.Project
12
- import com.intellij.openapi.ui.OnePixelDivider
13
12
import com.intellij.openapi.util.UserDataHolderBase
14
13
import com.intellij.openapi.vfs.VirtualFile
15
- import com.intellij.ui.JBColor
16
- import com.intellij.ui.SeparatorComponent
17
14
import com.intellij.ui.dsl.builder.Align
18
- import com.intellij.ui.dsl.builder.AlignX
19
15
import com.intellij.ui.dsl.builder.AlignY
20
16
import com.intellij.ui.dsl.builder.BottomGap
21
- import com.intellij.ui.dsl.builder.Cell
22
17
import com.intellij.ui.dsl.builder.Panel
23
- import com.intellij.ui.dsl.builder.Row
24
18
import com.intellij.ui.dsl.builder.TopGap
25
19
import com.intellij.ui.dsl.builder.panel
26
20
import com.intellij.ui.dsl.gridLayout.Gaps
27
21
import icons.AwsIcons
28
- import software.aws.toolkits.jetbrains.services.codewhisperer.language.CodeWhispererProgrammingLanguage
29
- import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererCsharp
30
- import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererJava
31
- import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererJavaScript
32
- import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererPython
33
- import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererTypeScript
34
- import software.aws.toolkits.jetbrains.services.codewhisperer.learn.LearnCodeWhispererEditorProvider.Companion.NEW_ONBOARDING_UX_KEY
35
- import software.aws.toolkits.jetbrains.services.codewhisperer.learn.LearnCodeWhispererUIComponents.bannerPanel
36
- import software.aws.toolkits.jetbrains.services.codewhisperer.learn.LearnCodeWhispererUIComponents.codeScanDescriptionPanel
37
- import software.aws.toolkits.jetbrains.services.codewhisperer.learn.LearnCodeWhispererUIComponents.commandsPanel
38
22
import software.aws.toolkits.jetbrains.services.codewhisperer.learn.LearnCodeWhispererUIComponents.examplesDescriptionPanel
39
- import software.aws.toolkits.jetbrains.services.codewhisperer.learn.LearnCodeWhispererUIComponents.resourcesPanel
40
23
import software.aws.toolkits.jetbrains.services.codewhisperer.learn.LearnCodeWhispererUIComponents.tryExamplePanel
41
- import software.aws.toolkits.jetbrains.services.codewhisperer.learn.LearnCodeWhispererUIComponents.workshopPanel
42
24
import software.aws.toolkits.resources.message
43
- import java.awt.Font
44
25
import java.beans.PropertyChangeListener
45
- import javax.swing.BorderFactory
46
- import javax.swing.ImageIcon
47
- import javax.swing.JButton
48
26
import javax.swing.JComponent
49
- import javax.swing.JPanel
50
27
51
28
class LearnCodeWhispererEditor (val project : Project , val virtualFile : VirtualFile ) : UserDataHolderBase(), FileEditor {
52
- private val languageButtons = mutableListOf<Cell <JButton >>()
53
29
private val contentPanel = panel {
54
30
row {
55
31
panel {
56
- customize(Gaps (0 , 50 , 0 , 0 ))
32
+ customize(Gaps (20 , 50 , 0 , 0 ))
57
33
row {
58
34
icon(AwsIcons .Logos .CODEWHISPERER_LARGE )
59
35
@@ -68,77 +44,22 @@ class LearnCodeWhispererEditor(val project: Project, val virtualFile: VirtualFil
68
44
}.topGap(TopGap .MEDIUM ).bottomGap(BottomGap .MEDIUM )
69
45
70
46
row {
71
- // Left panel
47
+ // Single panel
72
48
panel {
73
49
customize(Gaps (0 , 50 , 0 , 0 ))
74
50
align(AlignY .TOP )
75
- addToLeftPanel(commandsPanel(project))
76
- addToLeftPanel(workshopPanel())
77
- addToLeftPanel(resourcesPanel(project))
78
- }
79
51
80
- // Right panel
81
- panel {
82
- customize(Gaps (0 , 40 , 50 , 60 ))
83
- align(AlignY .TOP )
84
-
85
- title(message(" codewhisperer.learn_page.examples.title" ))
52
+ title(message(" codewhisperer.learn_page.examples.title" )).bottomGap(BottomGap .MEDIUM )
86
53
row {
87
- cell(examplesDescriptionPanel )
54
+ cell(tryExamplePanel(project)).widthGroup( FIRST_COLUMN_WIDTH_GROUP )
88
55
}.bottomGap(BottomGap .MEDIUM )
89
- buttonsGroup {
90
- row {
91
- val javaButton = learnCodeWhispererLanguageButton(CodeWhispererJava .INSTANCE )
92
- val pythonButton = learnCodeWhispererLanguageButton(CodeWhispererPython .INSTANCE )
93
- val javascriptButton = learnCodeWhispererLanguageButton(CodeWhispererJavaScript .INSTANCE )
94
- val typescriptButton = learnCodeWhispererLanguageButton(CodeWhispererTypeScript .INSTANCE )
95
- val csharpButton = learnCodeWhispererLanguageButton(CodeWhispererCsharp .INSTANCE )
96
- languageButtons.add(javaButton)
97
- languageButtons.add(pythonButton)
98
- languageButtons.add(javascriptButton)
99
- languageButtons.add(typescriptButton)
100
- languageButtons.add(csharpButton)
101
- javaButton.component.doClick()
102
- }.bottomGap(BottomGap .MEDIUM )
103
- }
104
56
row {
105
- cell(tryExamplePanel(project)) .widthGroup(RIGHT_PANEL_WIDTH_GROUP )
57
+ cell(examplesDescriptionPanel) .widthGroup(FIRST_COLUMN_WIDTH_GROUP )
106
58
}.bottomGap(BottomGap .MEDIUM )
107
-
108
- // A separator with width adjusted to its sibling components
109
- row {
110
- cell(SeparatorComponent (0 , OnePixelDivider .BACKGROUND , null ))
111
- .widthGroup(RIGHT_PANEL_WIDTH_GROUP )
112
- }.bottomGap(BottomGap .MEDIUM )
113
-
114
- title(message(" codewhisperer.learn_page.codescan.title" ))
115
- row {
116
- cell(codeScanDescriptionPanel)
117
- }.bottomGap(BottomGap .SMALL )
118
- row {
119
- icon(ImageIcon (LearnCodeWhispererUIComponents .javaClass.classLoader.getResource(" codewhisperer/codescan.png" )))
120
- .widthGroup(RIGHT_PANEL_WIDTH_GROUP ).align(AlignX .LEFT )
121
- }
122
59
}
123
60
}
124
61
}
125
- private val banner = panel {
126
- panel {
127
- customize(Gaps (10 , 20 , 10 , 10 ))
128
- row {
129
- cell(bannerPanel()).resizableColumn().align(Align .FILL )
130
- }
131
- }
132
- }.apply {
133
- background = JBColor .BLUE .darker().darker()
134
- }
135
62
private val rootPanel = panel {
136
- val hasUserSeenNewUX = virtualFile.getUserData(NEW_ONBOARDING_UX_KEY ) ? : false
137
- if (! hasUserSeenNewUX) {
138
- row {
139
- cell(banner).resizableColumn().align(Align .FILL )
140
- }
141
- }
142
63
row {
143
64
scrollCell(contentPanel).align(Align .FILL )
144
65
}.resizableRow()
@@ -174,52 +95,11 @@ class LearnCodeWhispererEditor(val project: Project, val virtualFile: VirtualFil
174
95
175
96
override fun getFile (): VirtualFile = virtualFile
176
97
177
- private fun Row.learnCodeWhispererLanguageButton (buttonLanguage : CodeWhispererProgrammingLanguage ): Cell <JButton > {
178
- val buttonContext = when (buttonLanguage) {
179
- CodeWhispererJava .INSTANCE -> " Java " to AwsIcons .Misc .JAVA
180
- CodeWhispererPython .INSTANCE -> " Python " to AwsIcons .Misc .PYTHON
181
- CodeWhispererJavaScript .INSTANCE -> " JavaScript " to AwsIcons .Misc .JAVASCRIPT
182
- CodeWhispererTypeScript .INSTANCE -> " TypeScript " to AwsIcons .Misc .TYPESCRIPT
183
- CodeWhispererCsharp .INSTANCE -> " C# " to AwsIcons .Misc .CSHARP
184
- else -> " Java " to AwsIcons .Misc .JAVA
185
- }
186
- val text = buttonContext.first
187
- val buttonIcon = buttonContext.second
188
-
189
- return button(text) {
190
- LearnCodeWhispererManager .getInstance(project).language = buttonLanguage
191
- languageButtons.forEach { button ->
192
- button.applyToComponent {
193
- border = BorderFactory .createEmptyBorder(3 , 3 , 3 , 3 )
194
- font = font.deriveFont(Font .PLAIN )
195
- }
196
- }
197
- languageButtons.filter { button -> button.component.text == text }[0 ].applyToComponent {
198
- border = BorderFactory .createCompoundBorder(
199
- CustomRadiusRoundedBorder (1 , 30 , JBColor .BLUE ),
200
- BorderFactory .createEmptyBorder(2 , 2 , 2 , 2 )
201
- )
202
- font = font.deriveFont(Font .BOLD )
203
- }
204
- }.applyToComponent {
205
- icon = buttonIcon
206
- isOpaque = false
207
- isContentAreaFilled = false
208
- border = BorderFactory .createEmptyBorder(3 , 3 , 3 , 3 )
209
- isSelected = LearnCodeWhispererManager .getInstance(project).language == buttonLanguage
210
- }.customize(Gaps (0 , 10 , 2 , 10 ))
211
- }
212
-
213
98
private fun Panel.title (text : String ) = row {
214
99
label(text).bold().applyToComponent { font = font.deriveFont(24f ) }
215
100
}
216
101
217
- private fun Panel.addToLeftPanel (panel : JPanel ) = row {
218
- cell(panel).widthGroup(LEFT_PANEL_WIDTH_GROUP ).customize(Gaps (22 , 18 , 11 , 18 ))
219
- }.bottomGap(BottomGap .MEDIUM )
220
-
221
102
companion object {
222
- private const val LEFT_PANEL_WIDTH_GROUP = " leftPanel"
223
- private const val RIGHT_PANEL_WIDTH_GROUP = " rightPanel"
103
+ private const val FIRST_COLUMN_WIDTH_GROUP = " firstColumn"
224
104
}
225
105
}
0 commit comments