Skip to content

Commit 01881af

Browse files
committed
Update JSON Input Dialog, Add Icon
1 parent bb4f561 commit 01881af

File tree

6 files changed

+112
-50
lines changed

6 files changed

+112
-50
lines changed

src/main/kotlin/wu/seal/jsontokotlin/ui/JsonInputDialog.kt

Lines changed: 80 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.intellij.openapi.progress.util.DispatchThreadProgressWindow
1111
import com.intellij.openapi.project.Project
1212
import com.intellij.openapi.ui.InputValidator
1313
import com.intellij.openapi.ui.Messages
14+
import com.intellij.openapi.util.IconLoader
1415
import com.intellij.ui.components.JBLabel
1516
import com.intellij.util.ui.JBDimension
1617
import com.intellij.util.ui.JBEmptyBorder
@@ -19,7 +20,9 @@ import wu.seal.jsontokotlin.feedback.sendActionInfo
1920
import wu.seal.jsontokotlin.utils.addComponentIntoVerticalBoxAlignmentLeft
2021
import java.awt.*
2122
import java.awt.datatransfer.DataFlavor
22-
import java.awt.event.*
23+
import java.awt.event.ActionEvent
24+
import java.awt.event.MouseAdapter
25+
import java.awt.event.MouseEvent
2326
import java.net.URI
2427
import java.net.URL
2528
import javax.swing.*
@@ -72,16 +75,17 @@ class JsonInputDialog(classsName: String, private val project: Project) : Messag
7275
myField.text = classsName
7376
}
7477

75-
override fun createCenterPanel(): JComponent? {
76-
jsonContentEditor = createJsonContentEditor()
77-
myInputValidator.jsonInputEditor = jsonContentEditor
78-
79-
val jsonTitle = JBLabel("JSON Text:")
80-
jsonTitle.border = JBEmptyBorder(0, 0, 5, 0)
78+
override fun createNorthPanel(): JComponent? {
79+
val jsonTitle = JBLabel("JSON Text: ").apply {
80+
font = font.deriveFont(14f)
81+
}
82+
val jsonTip =
83+
JBLabel("Tips: you can use JSON string、http urls or local file just right click on text area").apply {
84+
font = font.deriveFont(12f)
85+
}
8186

82-
val formatButton = JButton("Format")
87+
val formatButton = JButton("JSON Format")
8388
.apply {
84-
horizontalAlignment = SwingConstants.CENTER
8589
addActionListener(object : AbstractAction() {
8690
override fun actionPerformed(p0: ActionEvent?) {
8791
handleFormatJSONString()
@@ -93,28 +97,58 @@ class JsonInputDialog(classsName: String, private val project: Project) : Messag
9397
border = JBEmptyBorder(0, 0, 5, 0)
9498
layout = BoxLayout(this, BoxLayout.LINE_AXIS)
9599
add(jsonTitle)
100+
add(jsonTip)
96101
add(Box.createHorizontalGlue())
97102
add(formatButton)
98103
}
104+
val rightContainer = JPanel(BorderLayout()).apply {
105+
106+
add(JLabel(myMessage).apply {
107+
font = font.deriveFont(12f)
108+
}, BorderLayout.NORTH)
109+
add(jsonInputTitleContainer, BorderLayout.CENTER)
110+
111+
}
112+
113+
val icon = IconLoader.getIcon("/icons/icon_json_input_dialog.png")
114+
115+
val iconLabel = JBLabel(icon).apply {
116+
minimumSize = JBDimension(42, 42)
117+
verticalAlignment = SwingConstants.TOP
118+
border = JBEmptyBorder(0, 0, 0, 5)
119+
}
120+
return JPanel(BorderLayout())
121+
.apply {
122+
border = JBEmptyBorder(0, 0, 5, 0)
123+
add(iconLabel, BorderLayout.WEST)
124+
add(rightContainer, BorderLayout.CENTER)
125+
}
126+
127+
}
128+
129+
override fun createCenterPanel(): JComponent? {
130+
jsonContentEditor = createJsonContentEditor()
131+
myInputValidator.jsonInputEditor = jsonContentEditor
132+
99133

100134
val jsonInputContainer = JPanel(BorderLayout())
101135
.apply {
102136
preferredSize = JBDimension(700, 400)
103137
border = JBEmptyBorder(5, 0, 5, 5)
104-
add(jsonInputTitleContainer, BorderLayout.NORTH)
105138
add(jsonContentEditor.component, BorderLayout.CENTER)
106139
}
107140

108141
myField = createTextFieldComponent()
109142

110143
val classNameInputContainer = createLinearLayoutVertical()
111-
.apply {
112-
val classNameTitle = JBLabel("Class Name:")
113-
classNameTitle.border = JBEmptyBorder(5, 0, 5, 0)
114-
addComponentIntoVerticalBoxAlignmentLeft(classNameTitle)
115-
addComponentIntoVerticalBoxAlignmentLeft(myField)
116-
preferredSize = JBDimension(500, 56)
117-
}
144+
.apply {
145+
val classNameTitle = JBLabel("Class Name:")
146+
classNameTitle.border = JBEmptyBorder(5, 0, 5, 0)
147+
addComponentIntoVerticalBoxAlignmentLeft(classNameTitle)
148+
addComponentIntoVerticalBoxAlignmentLeft(myField)
149+
preferredSize = JBDimension(500, 56)
150+
font = font.deriveFont(14f)
151+
}
118152

119153
val centerInputContainer = JPanel(BorderLayout())
120154
.apply {
@@ -124,24 +158,23 @@ class JsonInputDialog(classsName: String, private val project: Project) : Messag
124158

125159
val settingContainer = createAdvancedPanel()
126160

127-
val centerContainer = JPanel(BorderLayout())
161+
return JPanel(BorderLayout())
128162
.apply {
129163
add(centerInputContainer, BorderLayout.CENTER)
130164
add(settingContainer, BorderLayout.SOUTH)
131165
}
132-
return centerContainer
133166
}
134167

135168
private fun createAdvancedPanel(): JPanel {
136169
val advancedButton = JButton("Advanced")
137-
.apply {
138-
horizontalAlignment = SwingConstants.CENTER
139-
addActionListener(object : AbstractAction() {
140-
override fun actionPerformed(e: ActionEvent) {
141-
AdvancedDialog(false).show()
142-
}
143-
})
144-
}
170+
.apply {
171+
horizontalAlignment = SwingConstants.CENTER
172+
addActionListener(object : AbstractAction() {
173+
override fun actionPerformed(e: ActionEvent) {
174+
AdvancedDialog(false).show()
175+
}
176+
})
177+
}
145178

146179
val tip = JLabel("Like this version? Please star here: ")
147180
val projectLink =
@@ -163,7 +196,7 @@ class JsonInputDialog(classsName: String, private val project: Project) : Messag
163196
projectLink.cursor = Cursor.getDefaultCursor()
164197
}
165198
})
166-
val settingContainer = JPanel()
199+
return JPanel()
167200
.apply {
168201
border = JBEmptyBorder(0, 0, 10, 7)
169202
layout = BoxLayout(this, BoxLayout.LINE_AXIS)
@@ -172,13 +205,6 @@ class JsonInputDialog(classsName: String, private val project: Project) : Messag
172205
add(tip)
173206
add(projectLink)
174207
}
175-
return settingContainer
176-
}
177-
178-
override fun createMessagePanel(): JPanel {
179-
return createLinearLayoutVertical().apply {
180-
addComponentIntoVerticalBoxAlignmentLeft(JLabel(myMessage))
181-
}
182208
}
183209

184210
private fun createJsonContentEditor(): Editor {
@@ -195,11 +221,11 @@ class JsonInputDialog(classsName: String, private val project: Project) : Messag
195221
val editor = editorFactory.createEditor(document, null, JsonFileType.INSTANCE, false)
196222

197223
editor.component
198-
.apply {
199-
isEnabled = true
200-
preferredSize = Dimension(640, 480)
201-
autoscrolls = true
202-
}
224+
.apply {
225+
isEnabled = true
226+
preferredSize = Dimension(640, 480)
227+
autoscrolls = true
228+
}
203229

204230

205231
val contentComponent = editor.contentComponent
@@ -216,15 +242,19 @@ class JsonInputDialog(classsName: String, private val project: Project) : Messag
216242
override fun createTextFieldComponent(): JTextComponent {
217243

218244
return JTextField()
219-
.apply {
220-
preferredSize = JBDimension(400, 40)
221-
document = object : PlainDocument() {
222-
override fun insertString(offs: Int, str: String?, a: AttributeSet?) {
223-
str ?: return
224-
super.insertString(offs, str.filter { it.isLetterOrDigit() || it in listOf('_', '$') }.take(252), a)
225-
}
245+
.apply {
246+
preferredSize = JBDimension(400, 40)
247+
document = object : PlainDocument() {
248+
override fun insertString(offs: Int, str: String?, a: AttributeSet?) {
249+
str ?: return
250+
super.insertString(
251+
offs,
252+
str.filter { it.isLetterOrDigit() || it in listOf('_', '$') }.take(252),
253+
a
254+
)
226255
}
227256
}
257+
}
228258
}
229259

230260
private fun createPasteFromClipboardMenuItem() = JMenuItem("Paste from clipboard").apply {
@@ -307,7 +337,7 @@ class JsonInputDialog(classsName: String, private val project: Project) : Messag
307337
fun createLinearLayoutVertical(): JPanel {
308338

309339
return JPanel()
310-
.apply {
311-
layout = BoxLayout(this, BoxLayout.PAGE_AXIS)
312-
}
340+
.apply {
341+
layout = BoxLayout(this, BoxLayout.PAGE_AXIS)
342+
}
313343
}
Lines changed: 32 additions & 0 deletions
Loading
-935 Bytes
Loading
1.53 KB
Loading
1.79 KB
Loading
4.45 KB
Loading

0 commit comments

Comments
 (0)