Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
rock3r committed Oct 5, 2023
1 parent c1ba714 commit 496d6ed
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 41 deletions.
7 changes: 7 additions & 0 deletions samples/ide-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ dependencies {
exclude(group = "org.jetbrains.kotlinx")
}
}

tasks {
// We don't have any settings in the demo plugin
buildSearchableOptions {
enabled = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,58 @@ enum class ReleaseChannel(

Stable(
background = JBColor(
/* regular = */ JBColor.namedColor("ColorPalette.Green10", 0xE6F7E9),
/* dark = */ JBColor.namedColor("ColorPalette.Green3", 0x436946),
/* regular = */
JBColor.namedColor("ColorPalette.Green10", 0xE6F7E9),
/* dark = */
JBColor.namedColor("ColorPalette.Green3", 0x436946),
),
foreground = JBColor(
/* regular = */ JBColor.namedColor("ColorPalette.Green5", 0x369650),
/* dark = */ JBColor.namedColor("ColorPalette.Green6", 0x5FAD65),
/* regular = */
JBColor.namedColor("ColorPalette.Green5", 0x369650),
/* dark = */
JBColor.namedColor("ColorPalette.Green6", 0x5FAD65),
),
),
Beta(
background = JBColor(
/* regular = */ JBColor.namedColor("ColorPalette.Yellow10", 0xFCEBA4),
/* dark = */ JBColor.namedColor("ColorPalette.Yellow3", 0x826A41),
/* regular = */
JBColor.namedColor("ColorPalette.Yellow10", 0xFCEBA4),
/* dark = */
JBColor.namedColor("ColorPalette.Yellow3", 0x826A41),
),
foreground = JBColor(
/* regular = */ JBColor.namedColor("ColorPalette.Yellow4", 0xFFAF0F),
/* dark = */ JBColor.namedColor("ColorPalette.Yellow6", 0xD6AE58),
/* regular = */
JBColor.namedColor("ColorPalette.Yellow4", 0xFFAF0F),
/* dark = */
JBColor.namedColor("ColorPalette.Yellow6", 0xD6AE58),
),
),
Canary(
background = JBColor(
/* regular = */ JBColor.namedColor("ColorPalette.Orange8", 0xEC8F4C),
/* dark = */ JBColor.namedColor("ColorPalette.Orange3", 0x825845),
/* regular = */
JBColor.namedColor("ColorPalette.Orange8", 0xEC8F4C),
/* dark = */
JBColor.namedColor("ColorPalette.Orange3", 0x825845),
),
foreground = JBColor(
/* regular = */ JBColor.namedColor("ColorPalette.Orange5", 0xEC8F4C),
/* dark = */ JBColor.namedColor("ColorPalette.Orange6", 0xE08855),
/* regular = */
JBColor.namedColor("ColorPalette.Orange5", 0xEC8F4C),
/* dark = */
JBColor.namedColor("ColorPalette.Orange6", 0xE08855),
),
),
Other(
background = JBColor(
/* regular = */ JBColor.namedColor("ColorPalette.Grey12", 0xEBECF0),
/* dark = */ JBColor.namedColor("ColorPalette.Grey5", 0x4E5157),
/* regular = */
JBColor.namedColor("ColorPalette.Grey12", 0xEBECF0),
/* dark = */
JBColor.namedColor("ColorPalette.Grey5", 0x4E5157),
),
foreground = JBColor(
/* regular = */ JBColor.namedColor("ColorPalette.Grey6", 0x6C707E),
/* dark = */ JBColor.namedColor("ColorPalette.Grey10", 0xB4B8BF),
/* regular = */
JBColor.namedColor("ColorPalette.Grey6", 0x6C707E),
/* dark = */
JBColor.namedColor("ColorPalette.Grey10", 0xB4B8BF),
),
)
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ internal class JewelDemoToolWindowFactory : ToolWindowFactory, DumbAware {
addSwingTab(toolWindow)

toolWindow.addComposeTab("Compose Sample") {

}
}

private fun addSwingTab(toolWindow: ToolWindow) {
val manager = toolWindow.contentManager
val tabContent =
manager.factory.createContent(
/* component = */ SwingDemoPanel(toolWindow.disposable.createCoroutineScope()),
/* displayName = */ "Swing Sample",
/* isLockable = */ true
SwingDemoPanel(toolWindow.disposable.createCoroutineScope()),
"Swing Sample",
true,
)
tabContent.isCloseable = false
manager.addContent(tabContent)
}
}

@Suppress("InjectDispatcher") // This is likely wrong anyway, it's only for the demo
private fun Disposable.createCoroutineScope(): CoroutineScope {
val job = SupervisorJob()
val scopeDisposable = Disposable { job.cancel("Disposing") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal class ApiLevelIndication(apiLevel: Int) : JLabel("API level $apiLevel")
height - y,
JBUIScale.scale(8),
ReleaseChannel.Other.background,
null
null,
)

graphicsConfig.restore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private class ItemDetailsPanel(
JBScrollPane(
mainContentPanel,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER,
)

addToCenter(scrollingContainer)
Expand All @@ -84,7 +84,9 @@ private class ItemDetailsPanel(
val releaseDate = contentItem.releaseDate
if (releaseDate != null) {
it.comment("Released on ${formatter.format(releaseDate.toJavaLocalDate())}")
} else it
} else {
it
}
}
.component.font = JBFont.h1()
}.bottomGap(BottomGap.MEDIUM)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ internal class ImageComponent(
registerUiInspectorInfoProvider {
mapOf(
"image" to image,
"imageSize" to image?.let { Dimension(ImageUtil.getUserWidth(it), ImageUtil.getUserHeight(it)) }
"imageSize" to image?.let { Dimension(ImageUtil.getUserWidth(it), ImageUtil.getUserHeight(it)) },
)
}
}

@Suppress("InjectDispatcher") // It's ok in a silly sample
private fun updateScaledImage() {
resizeJob?.cancel("New image")

Expand Down Expand Up @@ -113,10 +114,14 @@ internal class ImageComponent(
val componentHeight = height

drawImage(
/* img = */ currentImage,
/* x = */ componentWidth / 2 - (imageWidth) / 2,
/* y = */ componentHeight / 2 - (imageHeight) / 2,
/* observer = */ null
/* img = */
currentImage,
/* x = */
componentWidth / 2 - (imageWidth) / 2,
/* y = */
componentHeight / 2 - (imageHeight) / 2,
/* observer = */
null,
)

graphicsConfig.restore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SwingDemoPanel(scope: CoroutineScope) : BorderLayoutPanel() {
}

override fun getActionUpdateThread() = ActionUpdateThread.BGT
}
},
)

private val overflowAction = MoreActionGroup()
Expand All @@ -82,7 +82,7 @@ class SwingDemoPanel(scope: CoroutineScope) : BorderLayoutPanel() {
overflowAction,
overflowAction.templatePresentation.clone(),
"JewelSwingDemoTopBar",
ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE
ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE,
)

private val topBar = BorderLayoutPanel().apply {
Expand Down Expand Up @@ -124,17 +124,21 @@ class SwingDemoPanel(scope: CoroutineScope) : BorderLayoutPanel() {
addToCenter(JBLabel(it.displayText))

if (it is ContentItem.AndroidStudio) {
addToRight(JPanel().apply {
layout = BoxLayout(this, BoxLayout.LINE_AXIS)
isOpaque = false
add(ChannelIndication(it.channel))
})
addToRight(
JPanel().apply {
layout = BoxLayout(this, BoxLayout.LINE_AXIS)
isOpaque = false
add(ChannelIndication(it.channel))
},
)
} else if (it is ContentItem.AndroidRelease) {
addToRight(JPanel().apply {
layout = BoxLayout(this, BoxLayout.LINE_AXIS)
isOpaque = false
add(ApiLevelIndication(it.apiLevel))
})
addToRight(
JPanel().apply {
layout = BoxLayout(this, BoxLayout.LINE_AXIS)
isOpaque = false
add(ApiLevelIndication(it.apiLevel))
},
)
}
}
}
Expand Down

0 comments on commit 496d6ed

Please sign in to comment.