Skip to content

Commit

Permalink
feat: Improve Layout and Responsiveness of Several UI Forms (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangcent authored Nov 12, 2023
1 parent aa54e70 commit b0b688c
Show file tree
Hide file tree
Showing 8 changed files with 1,225 additions and 1,167 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -189,35 +189,8 @@ class ApiCallDialog : ContextDialog(), ApiCallUI {
initApisModule()
LOG.info("init RequestModule")
initRequestModule()
resize()
this.onResized {
resize()
}
this.requestPanel.onResized {
resize()
}
this.responsePanel.onResized {
resize()
}
}

private val resize = {
actionContext.runInSwingUI {
val rightWidth = this.contentPane.width - this.apisListPanel.width

val rightPanel = this.rightPanel
rightPanel.setSizeIfNecessary(rightWidth, this.contentPane.height - 6)

val requestPanel = this.requestPanel
requestPanel.setSizeIfNecessary(rightWidth - 30, requestPanel.height)

this.responsePanel.let {
it.setSizeIfNecessary(rightWidth - 30, it.height)
it.bottomAlignTo(this.apisJList)
}
}
}.throttle(50, TimeUnit.MILLISECONDS)

//region api module
private fun initApisModule() {

Expand Down Expand Up @@ -268,7 +241,6 @@ class ApiCallDialog : ContextDialog(), ApiCallUI {
?.response?.firstOrNull()?.body?.let { RequestUtils.parseRawBody(it) }
?: ""
formatForm(currRequest)
resize()
}

override fun updateRequestList(requestList: List<Request>?) {
Expand All @@ -293,7 +265,6 @@ class ApiCallDialog : ContextDialog(), ApiCallUI {
if (requestRawViewList.isNotEmpty()) {
this.apisJList.selectedIndex = 0
}
resize()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package com.itangcent.idea.plugin.dialog

import com.google.inject.Inject
import com.intellij.ide.util.PropertiesComponent
import com.itangcent.common.logger.Log
import com.itangcent.common.logger.traceError
import com.itangcent.common.utils.safe
import com.itangcent.idea.utils.initAfterShown
import com.itangcent.intellij.constant.EventKey
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.extend.guice.PostConstruct
import com.itangcent.intellij.logger.Logger
import java.awt.Dimension
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
import javax.swing.JDialog
import javax.swing.WindowConstants

abstract class ContextDialog : JDialog() {
companion object : Log() {
private const val LAST_SIZE = "com.itangcent.easyapi.suv.last.size"
}

private val lastSizePropertiesName
get() = "$LAST_SIZE.${this::class.qualifiedName}"

@Inject
protected lateinit var actionContext: ActionContext
Expand All @@ -36,6 +45,8 @@ abstract class ContextDialog : JDialog() {
}
})

restoreSize()

this.initAfterShown {
try {
init()
Expand All @@ -45,6 +56,22 @@ abstract class ContextDialog : JDialog() {
} finally {
init = true
}

//restore size
restoreSize()
}
}

private fun restoreSize() {
PropertiesComponent.getInstance().getValue(lastSizePropertiesName)?.let {
val split = it.split(",")
if (split.size == 2) {
val width = split[0].toIntOrNull()
val height = split[1].toIntOrNull()
if (width != null && height != null) {
this.size = Dimension(width, height)
}
}
}
}

Expand Down Expand Up @@ -87,12 +114,22 @@ abstract class ContextDialog : JDialog() {
if (!disposed) {
disposed = true
dispose()
safe { onDispose() }
actionContext.runAsync {
safe {
PropertiesComponent.getInstance().setValue(
lastSizePropertiesName,
"${this.size.width},${this.size.height}"
)
}
safe { onDispose() }
safe {
actionContext.unHold()
actionContext.stop()
}
}
}
}

open fun onDispose() {
actionContext.unHold()
actionContext.stop()
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="300"/>
<preferred-size width="-1" height="300"/>
</grid>
</constraints>
<properties/>
Expand All @@ -37,7 +37,7 @@
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="300"/>
<preferred-size width="-1" height="300"/>
</grid>
</constraints>
<properties/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,31 @@
<properties/>
<border type="none"/>
<children>
<grid id="70de0" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="70de0" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="0" vgap="0">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="3b4e4" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<component id="spacer" class="javax.swing.JPanel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<grid id="3b4e4" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="0" vgap="0">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="4" fill="2" indent="0" use-parent-layout="false"/>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="51bd3" class="javax.swing.JButton" binding="addConfigButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="20" height="20"/>
<preferred-size width="20" height="20"/>
<maximum-size width="20" height="20"/>
Expand All @@ -38,7 +44,7 @@
</component>
<component id="20195" class="javax.swing.JButton" binding="removeConfigButton">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="20" height="20"/>
<preferred-size width="20" height="20"/>
<maximum-size width="20" height="20"/>
Expand All @@ -50,7 +56,7 @@
</component>
<component id="ab2e" class="javax.swing.JButton" binding="refreshConfigButton">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="20" height="20"/>
<preferred-size width="20" height="20"/>
<maximum-size width="20" height="20"/>
Expand All @@ -64,7 +70,7 @@
</grid>
</children>
</grid>
<grid id="ef7c3" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="ef7c3" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="true" same-size-vertically="true" hgap="0" vgap="0">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand All @@ -74,7 +80,7 @@
<children>
<scrollpane id="7d3e">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
Expand All @@ -87,23 +93,35 @@
</scrollpane>
</children>
</grid>
<scrollpane id="caa07">
<grid id="525f1" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="300"/>
</grid>
</constraints>
<properties>
<horizontalScrollBarPolicy value="30"/>
</properties>
<properties/>
<border type="none"/>
<children>
<component id="31bc5" class="javax.swing.JTextArea" binding="previewRemoteConfigTextArea">
<constraints/>
<scrollpane id="caa07">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<lineWrap value="true"/>
<horizontalScrollBarPolicy value="30"/>
</properties>
</component>
<border type="none"/>
<children>
<component id="31bc5" class="javax.swing.JTextArea" binding="previewRemoteConfigTextArea">
<constraints/>
<properties>
<lineWrap value="true"/>
</properties>
</component>
</children>
</scrollpane>
</children>
</scrollpane>
</grid>
</children>
</grid>
</form>
Loading

0 comments on commit b0b688c

Please sign in to comment.