Skip to content

Commit efcb80b

Browse files
authored
Smaller insight icons (#135)
* Most of the icons * Merge * Snail + cleanups * cleaner svg code * Fixed trace button alignment
1 parent aaf891e commit efcb80b

28 files changed

+267
-166
lines changed

buildSrc/src/main/kotlin/common-java-library.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
2-
import org.gradle.api.tasks.testing.logging.TestLogEvent
3-
41
//this plugin is for projects that are pure java, meaning they don't have the
52
//org.jetbrains.intellij plugin.
63
//for example analytics-provider, model

buildSrc/src/main/kotlin/digma-base.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import common.properties
2-
import gradle.kotlin.dsl.accessors._32850698d653820f6f0bff6e9d585ccb.build
3-
import gradle.kotlin.dsl.accessors._744ce3376bf13942cde73334c3c9bc84.kotlin
42
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
53
import org.gradle.api.tasks.testing.logging.TestLogEvent
6-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
74

85
plugins{
96
`java`

src/main/kotlin/org/digma/intellij/plugin/ui/common/Laf.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,17 @@ object Laf {
8484
@JvmStatic val INTERFACE: Icon = SvgIcon.withColor("/icons/interface.svg", Colors.DEFAULT_LABEL_FOREGROUND)
8585
@JvmStatic val MESSAGE: Icon = SvgIcon.withColor("/icons/message.svg", Colors.DEFAULT_LABEL_FOREGROUND)
8686
// Insight item icons
87+
@JvmStatic val BOTTLENECK = SvgIcon.asIs("/icons/bottleneck.svg")
88+
@JvmStatic val DURATION = SvgIcon.asIs("/icons/duration.svg")
89+
@JvmStatic val ERRORS = SvgIcon.asIs("/icons/errors.svg")
90+
@JvmStatic val HOTSPOT = SvgIcon.asIs("/icons/hotspot.svg")
91+
@JvmStatic val LOW_USAGE = SvgIcon.asIs("/icons/traffic-low.svg")
92+
@JvmStatic val NORMAL_USAGE = SvgIcon.asIs("/icons/traffic-normal.svg")
93+
@JvmStatic val HIGH_USAGE = SvgIcon.asIs("/icons/traffic-high.svg")
94+
@JvmStatic val WAITING_DATA = SvgIcon.asIs("/icons/sand-watch.svg")
95+
@JvmStatic val SLOW = SvgIcon.asIs("/icons/snail.svg")
96+
8797
@JvmStatic val QUESTION_MARK = AllIcons.General.QuestionDialog
88-
@JvmStatic val BOTTLENECK = loadAndScaleInsightIcon("/icons/bottleneck.png")
89-
@JvmStatic val LOW_USAGE = loadAndScaleInsightIcon("/icons/gauge_low.png")
90-
@JvmStatic val NORMAL_USAGE = loadAndScaleInsightIcon("/icons/gauge_normal.png")
91-
@JvmStatic val HIGH_USAGE = loadAndScaleInsightIcon("/icons/gauge_high.png")
92-
@JvmStatic val SLOW = loadAndScaleInsightIcon("/icons/slow.png")
93-
@JvmStatic val WAITING_DATA = loadAndScaleInsightIcon("/icons/waiting-data.png")
94-
@JvmStatic val HOTSPOT = loadAndScaleInsightIcon("/icons/target.png")
95-
@JvmStatic val HISTOGRAM = loadAndScaleInsightIcon("/icons/histogram.png")
9698
@JvmStatic val SPAN_DURATION_DROPPED = loadAndScaleIconByWidth("/icons/dropped.png", 8)
9799
@JvmStatic val SPAN_DURATION_ROSE = loadAndScaleIconByWidth("/icons/rose.png", 8)
98100
}

src/main/kotlin/org/digma/intellij/plugin/ui/common/SvgIcon.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import java.awt.Component
88
import java.awt.Graphics
99
import java.io.File
1010
import java.nio.charset.StandardCharsets
11-
import java.util.*
11+
import java.util.Objects
1212
import javax.swing.Icon
1313

1414
typealias ColorGetter = () -> Color
1515

16-
class SvgIcon constructor(val path: String, val getColor : ColorGetter) : Icon {
16+
class SvgIcon constructor(val path: String, val getColor : ColorGetter? = null) : Icon {
1717

1818
companion object {
1919
private val cache: MutableMap<String, Icon> = HashMap()
@@ -22,6 +22,10 @@ class SvgIcon constructor(val path: String, val getColor : ColorGetter) : Icon {
2222
fun withColor(path: String, color: Color): SvgIcon{
2323
return SvgIcon(path) { color }
2424
}
25+
26+
fun asIs(path: String): SvgIcon{
27+
return SvgIcon(path)
28+
}
2529
}
2630

2731
override fun paintIcon(c: Component?, g: Graphics?, x: Int, y: Int) {
@@ -37,7 +41,10 @@ class SvgIcon constructor(val path: String, val getColor : ColorGetter) : Icon {
3741
}
3842

3943
private fun getIcon(): Icon {
40-
val color = getColor()
44+
if(getColor == null)
45+
return IconLoader.getIcon(path, javaClass.classLoader);
46+
47+
val color = getColor.invoke()
4148
val key = "$path:${color.getHex()}"
4249
var icon = cache[key]
4350
if(icon == null){

src/main/kotlin/org/digma/intellij/plugin/ui/list/ListItemActionButton.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ internal class ListItemActionButton constructor(text: String): JButton(text) {
5454
}
5555

5656
override fun getPreferredSize(): Dimension {
57-
// use the original: super.getPreferredSize
58-
return Dimension(Laf.scalePanels(50),Laf.scalePanels(15))
57+
val original = super.getPreferredSize()
58+
return Dimension(original.width-Laf.scalePanels(15), original.height - Laf.scalePanels(5))
5959
}
6060

6161
override fun paintComponent(g: Graphics) {

src/main/kotlin/org/digma/intellij/plugin/ui/list/insights/ErrorsPanel.kt

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,23 @@ package org.digma.intellij.plugin.ui.list.insights
22

33
import com.intellij.openapi.project.Project
44
import com.intellij.ui.components.ActionLink
5-
import com.intellij.ui.components.JBPanel
65
import com.intellij.util.ui.JBUI.Borders
76
import org.digma.intellij.plugin.model.rest.insights.ErrorInsight
87
import org.digma.intellij.plugin.model.rest.insights.ErrorInsightNamedError
98
import org.digma.intellij.plugin.service.ErrorsActionsService
109
import org.digma.intellij.plugin.service.InsightsActionsService
11-
import org.digma.intellij.plugin.ui.common.buildBoldTitleGrayedComment
10+
import org.digma.intellij.plugin.ui.common.Laf
1211
import org.digma.intellij.plugin.ui.common.buildLinkTextWithGrayedAndDefaultLabelColorPart
1312
import org.digma.intellij.plugin.ui.list.ListItemActionButton
1413
import org.digma.intellij.plugin.ui.list.PanelsLayoutHelper
15-
import java.awt.BorderLayout
1614
import java.awt.GridLayout
17-
import javax.swing.BorderFactory
18-
import javax.swing.JLabel
1915
import javax.swing.JPanel
20-
import javax.swing.SwingConstants
2116

2217
fun errorsPanel(project: Project, modelObject: ErrorInsight, panelsLayoutHelper: PanelsLayoutHelper): JPanel {
2318

2419
val errorCount = modelObject.errorCount
2520
val unhandled = modelObject.unhandledCount
2621
val unexpected = modelObject.unexpectedCount
27-
val title = JLabel(buildBoldTitleGrayedComment("Errors","$errorCount errors($unhandled unhandled, $unexpected unexpected)"),
28-
SwingConstants.LEFT)
29-
3022

3123
val errorsListPanel = JPanel()
3224
errorsListPanel.layout = GridLayout(modelObject.topErrors.size, 1,0,3)
@@ -46,28 +38,16 @@ fun errorsPanel(project: Project, modelObject: ErrorInsight, panelsLayoutHelper:
4638
errorsListPanel.add(link)
4739
}
4840

49-
val errorsWrapper = JBPanel<JBPanel<*>>()
50-
errorsWrapper.layout = BorderLayout(0,10)
51-
errorsWrapper.border = BorderFactory.createEmptyBorder()
52-
errorsWrapper.isOpaque = false
53-
errorsWrapper.add(title, BorderLayout.NORTH)
54-
errorsWrapper.add(errorsListPanel, BorderLayout.CENTER)
55-
56-
5741
val expandButton = ListItemActionButton("Expand")
5842
expandButton.addActionListener { project.getService(InsightsActionsService::class.java).showErrorsTab(modelObject) }
5943

60-
val expandPanel = InsightAlignedPanel(panelsLayoutHelper)
61-
expandPanel.layout = BorderLayout()
62-
expandPanel.isOpaque = false
63-
expandPanel.add(expandButton, BorderLayout.EAST)
64-
addCurrentLargestWidthIconPanel(panelsLayoutHelper,expandPanel.preferredSize.width)
65-
66-
val result = JBPanel<JBPanel<*>>()
67-
result.layout = BorderLayout()
68-
result.isOpaque = false
69-
result.add(errorsWrapper,BorderLayout.CENTER)
70-
result.add(expandPanel,BorderLayout.SOUTH)
44+
return createInsightPanel(
45+
"Errors",
46+
"$errorCount errors($unhandled unhandled, $unexpected unexpected)",
47+
Laf.Icons.Insight.ERRORS,
48+
errorsListPanel,
49+
listOf(expandButton),
50+
panelsLayoutHelper)
7151

72-
return insightItemPanel(result)
52+
//return insightItemPanel(result)
7353
}

src/main/kotlin/org/digma/intellij/plugin/ui/list/insights/HotspotPanel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ import javax.swing.JPanel
1010
fun hotspotPanel(modelObject: HotspotInsight, panelsLayoutHelper: PanelsLayoutHelper): JPanel {
1111
return createInsightPanel(
1212
"This is an error hotspot", "Many major errors occur or propagate through this function",
13-
Laf.Icons.Insight.HOTSPOT, "HotSpot",panelsLayoutHelper
13+
Laf.Icons.Insight.HOTSPOT,null, null, panelsLayoutHelper
1414
)
1515
}

src/main/kotlin/org/digma/intellij/plugin/ui/list/insights/InsightsCommon.kt

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ import org.digma.intellij.plugin.ui.list.PanelsLayoutHelper
99
import org.digma.intellij.plugin.ui.list.commonListItemPanel
1010
import java.awt.BorderLayout
1111
import java.awt.Dimension
12-
import javax.swing.Icon
13-
import javax.swing.JLabel
14-
import javax.swing.JPanel
15-
import javax.swing.SwingConstants
12+
import java.awt.FlowLayout
13+
import javax.swing.*
1614
import kotlin.math.max
1715

16+
1817
fun insightTitlePanel(panel: JPanel): JPanel {
1918
panel.isOpaque = false
2019
panel.border = empty(10, 5,0,5)
@@ -26,34 +25,56 @@ fun insightItemPanel(panel: JPanel): JPanel {
2625
}
2726

2827

29-
fun createInsightPanel(title: String, body: String, icon: Icon, iconText: String, panelsLayoutHelper: PanelsLayoutHelper): JPanel {
30-
return createInsightPanel(title, body, icon, iconText, true,panelsLayoutHelper)
31-
}
28+
fun createInsightPanel(title: String, description: String, icon: Icon, body: JComponent?, buttons: List<JButton?>?, panelsLayoutHelper: PanelsLayoutHelper): JPanel {
3229

33-
@Deprecated("remove,wrap is always true")
34-
private fun createInsightPanel(title: String, body: String, icon: Icon, iconText: String, wrap: Boolean, panelsLayoutHelper: PanelsLayoutHelper): JPanel {
30+
// .-----------------------------------.
31+
// | title | icon |
32+
// | description | |
33+
// |-----------------------------------|
34+
// | body |
35+
// |-----------------------------------|
36+
// | buttons |
37+
// '-----------------------------------'
3538

36-
val iconPanel = insightsIconPanelBorder(icon, iconText, panelsLayoutHelper)
37-
iconPanel.isOpaque = false
39+
val iconLabel = JLabel(icon, SwingConstants.RIGHT)
40+
iconLabel.horizontalAlignment = SwingConstants.RIGHT
41+
iconLabel.verticalAlignment = SwingConstants.TOP
42+
iconLabel.isOpaque = false
43+
iconLabel.border = empty(2)
3844

39-
val message = JLabel(buildBoldTitleGrayedComment(title,body),SwingConstants.LEFT)
40-
val messagePanel = JBPanel<JBPanel<*>>()
41-
messagePanel.layout = BorderLayout()
42-
messagePanel.add(message,BorderLayout.NORTH)
43-
messagePanel.border = empty()
44-
messagePanel.isOpaque = false
45+
val messageLabel = JLabel(buildBoldTitleGrayedComment(title,description), SwingConstants.LEFT)
46+
messageLabel.isOpaque = false
47+
messageLabel.verticalAlignment = SwingConstants.TOP
4548

4649
val result = JBPanel<JBPanel<*>>()
4750

4851
result.layout = BorderLayout()
49-
result.add(messagePanel,BorderLayout.CENTER)
50-
result.add(iconPanel,BorderLayout.EAST)
52+
result.add(messageLabel,BorderLayout.CENTER)
53+
result.add(iconLabel,BorderLayout.EAST)
54+
55+
if(body != null || buttons != null){
56+
val bodyWrapper = JPanel(BorderLayout())
57+
bodyWrapper.isOpaque = false
58+
59+
if(body != null)
60+
bodyWrapper.add(body, BorderLayout.CENTER)
61+
62+
if(buttons != null){
63+
val buttonsList = JPanel(FlowLayout(FlowLayout.RIGHT, 0 ,0))
64+
buttonsList.isOpaque = false
65+
buttonsList.border = empty()
66+
buttons.filterNotNull().forEach {
67+
buttonsList.add(Box.createHorizontalStrut(5))
68+
buttonsList.add(it)
69+
}
70+
bodyWrapper.add(buttonsList, BorderLayout.SOUTH)
71+
}
5172

52-
return if (wrap) {
53-
insightItemPanel(result)
54-
} else {
55-
result
73+
result.add(bodyWrapper,BorderLayout.SOUTH)
5674
}
75+
76+
77+
return insightItemPanel(result)
5778
}
5879

5980

@@ -62,15 +83,15 @@ fun unmappedInsightPanel(modelObject: UnmappedInsight, panelsLayoutHelper: Panel
6283
val methodName = modelObject.codeObjectId.substringAfterLast("\$_\$")
6384
return createInsightPanel("Unmapped insight: '${modelObject.theType}'",
6485
"unmapped insight type for '$methodName'",
65-
Laf.Icons.Insight.QUESTION_MARK, "",panelsLayoutHelper)
86+
Laf.Icons.Insight.QUESTION_MARK, null, null, panelsLayoutHelper)
6687
}
6788

6889

6990
fun genericPanelForSingleInsight(modelObject: Any?, panelsLayoutHelper: PanelsLayoutHelper): JPanel {
7091

7192
return createInsightPanel("Generic insight panel",
7293
"Insight named ${modelObject?.javaClass?.simpleName}",
73-
Laf.Icons.Insight.QUESTION_MARK, "",panelsLayoutHelper)
94+
Laf.Icons.Insight.QUESTION_MARK,null, null, panelsLayoutHelper)
7495
}
7596

7697

src/main/kotlin/org/digma/intellij/plugin/ui/list/insights/SlowEndpointPanel.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@ package org.digma.intellij.plugin.ui.list.insights
22

33
import org.digma.intellij.plugin.model.rest.insights.Duration
44
import org.digma.intellij.plugin.model.rest.insights.SlowEndpointInsight
5-
import org.digma.intellij.plugin.ui.common.*
5+
import org.digma.intellij.plugin.ui.common.Laf
6+
import org.digma.intellij.plugin.ui.common.asHtml
7+
import org.digma.intellij.plugin.ui.common.span
68
import org.digma.intellij.plugin.ui.list.PanelsLayoutHelper
79
import java.math.BigDecimal
810
import java.math.RoundingMode
11+
import javax.swing.JLabel
912
import javax.swing.JPanel
1013

1114

1215
fun slowEndpointPanel(insight: SlowEndpointInsight, panelsLayoutHelper: PanelsLayoutHelper): JPanel {
1316
val bodyContents = genContent(insight)
14-
val iconText = evalDuration(insight.median)
15-
val result = createInsightPanel("Slow Endpoint", bodyContents, Laf.Icons.Insight.SLOW, iconText,panelsLayoutHelper)
17+
val durationLabel = JLabel(evalDuration(insight.median))
18+
val result = createInsightPanel("Slow Endpoint", bodyContents, Laf.Icons.Insight.SLOW, durationLabel, null, panelsLayoutHelper)
1619
result.toolTipText = asHtml(genToolTip(insight))
1720
return result
1821
}

src/main/kotlin/org/digma/intellij/plugin/ui/list/insights/SlowestSpansPanel.kt

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import javax.swing.SwingConstants
2626

2727
fun slowestSpansPanel(project: Project, insight: SlowestSpansInsight, moreData: HashMap<String, Any>, panelsLayoutHelper: PanelsLayoutHelper): JPanel {
2828

29-
val title = JLabel(buildBoldTitleGrayedComment("Span Bottleneck","The following spans are slowing request handling"), SwingConstants.LEFT)
30-
3129
val spansListPanel = JPanel()
3230
spansListPanel.layout = GridLayout(insight.spans.size, 1, 0, 3)
3331
spansListPanel.border = JBUI.Borders.empty()
@@ -56,34 +54,13 @@ fun slowestSpansPanel(project: Project, insight: SlowestSpansInsight, moreData:
5654
}
5755
}
5856

59-
60-
val iconPanel = panel {
61-
row {
62-
cell(insightsIconPanelBorder(Laf.Icons.Insight.BOTTLENECK, wrapCentered("Slow<br>Spans"),panelsLayoutHelper))
63-
.horizontalAlign(HorizontalAlign.RIGHT)
64-
}.layout(RowLayout.INDEPENDENT)
65-
}
66-
iconPanel.isOpaque = false
67-
68-
val spansWrapper = JBPanel<JBPanel<*>>()
69-
spansWrapper.layout = BorderLayout(0,10)
70-
spansWrapper.add(title, BorderLayout.NORTH)
71-
spansWrapper.add(spansListPanel, BorderLayout.CENTER)
72-
spansWrapper.border = BorderFactory.createEmptyBorder()
73-
spansWrapper.isOpaque = false
74-
75-
val iconPanelWrapper = JBPanel<JBPanel<*>>()
76-
iconPanelWrapper.layout = BorderLayout()
77-
iconPanelWrapper.add(iconPanel, BorderLayout.EAST)
78-
iconPanelWrapper.isOpaque = false
79-
80-
81-
val result = JBPanel<JBPanel<*>>()
82-
result.layout = BorderLayout()
83-
result.add(spansWrapper,BorderLayout.CENTER)
84-
result.add(iconPanelWrapper,BorderLayout.EAST)
85-
86-
return insightItemPanel(result)
57+
return createInsightPanel(
58+
"Span Bottleneck",
59+
"The following spans are slowing request handling",
60+
Laf.Icons.Insight.BOTTLENECK,
61+
spansListPanel,
62+
null,
63+
panelsLayoutHelper)
8764
}
8865

8966

0 commit comments

Comments
 (0)