@@ -13,7 +13,6 @@ import com.intellij.util.ui.JBUI
13
13
import com.intellij.util.ui.UIUtil
14
14
import com.intellij.util.ui.components.BorderLayoutPanel
15
15
import java.awt.BorderLayout
16
- import java.awt.Color
17
16
import java.awt.Font
18
17
import java.awt.GridBagConstraints
19
18
import java.awt.GridBagLayout
@@ -25,10 +24,6 @@ import javax.swing.SwingConstants
25
24
* Panel that displays token usage statistics for the current session
26
25
*/
27
26
class TokenUsagePanel (private val project : Project ) : BorderLayoutPanel() {
28
-
29
- private val promptTokensLabel = JBLabel (" 0" , SwingConstants .RIGHT )
30
- private val completionTokensLabel = JBLabel (" 0" , SwingConstants .RIGHT )
31
- private val totalTokensLabel = JBLabel (" 0" , SwingConstants .RIGHT )
32
27
private val modelLabel = JBLabel (" " , SwingConstants .LEFT )
33
28
private val progressBar = JProgressBar (0 , 100 )
34
29
private val usageRatioLabel = JBLabel (" " , SwingConstants .CENTER )
@@ -46,7 +41,6 @@ class TokenUsagePanel(private val project: Project) : BorderLayoutPanel() {
46
41
isOpaque = false
47
42
border = JBUI .Borders .empty(4 , 8 )
48
43
49
- // Setup progress bar
50
44
progressBar.apply {
51
45
isStringPainted = false
52
46
preferredSize = java.awt.Dimension (150 , 8 )
@@ -55,19 +49,16 @@ class TokenUsagePanel(private val project: Project) : BorderLayoutPanel() {
55
49
isOpaque = false
56
50
}
57
51
58
- // Setup usage ratio label
59
52
usageRatioLabel.apply {
60
53
font = font.deriveFont(Font .PLAIN , 10f )
61
54
foreground = UIUtil .getContextHelpForeground()
62
55
}
63
56
64
- // Create main layout
65
57
val mainPanel = JPanel (GridBagLayout ())
66
58
mainPanel.isOpaque = false
67
59
68
60
val gbc = GridBagConstraints ()
69
61
70
- // Top row: Model info and progress bar
71
62
gbc.gridx = 0
72
63
gbc.gridy = 0
73
64
gbc.anchor = GridBagConstraints .WEST
@@ -129,18 +120,13 @@ class TokenUsagePanel(private val project: Project) : BorderLayoutPanel() {
129
120
currentUsage = event.usage
130
121
currentModel = event.model
131
122
132
- // Get max tokens for current model
133
123
updateMaxTokens()
134
-
135
-
136
- // Update progress bar
137
124
updateProgressBar(event.usage.totalTokens ? : 0 )
138
-
125
+
139
126
if (! event.model.isNullOrBlank()) {
140
127
modelLabel.text = " Model: ${event.model} "
141
128
}
142
129
143
- // Show the panel when we have data
144
130
isVisible = true
145
131
revalidate()
146
132
repaint()
@@ -154,7 +140,6 @@ class TokenUsagePanel(private val project: Project) : BorderLayoutPanel() {
154
140
val limits = modelManager.getUsedMaxToken()
155
141
maxContextWindowTokens = limits.maxContextWindowTokens?.toLong() ? : 0
156
142
} catch (e: Exception ) {
157
- // Fallback to default if unable to get limits
158
143
maxContextWindowTokens = 4096
159
144
}
160
145
}
@@ -169,7 +154,6 @@ class TokenUsagePanel(private val project: Project) : BorderLayoutPanel() {
169
154
val usageRatio = (totalTokens.toDouble() / maxContextWindowTokens * 100 ).toInt()
170
155
progressBar.value = usageRatio.coerceIn(0 , 100 )
171
156
172
- // Update color based on usage ratio
173
157
progressBar.foreground = when {
174
158
usageRatio >= 90 -> JBColor .RED
175
159
usageRatio >= 75 -> JBColor .ORANGE
@@ -178,12 +162,9 @@ class TokenUsagePanel(private val project: Project) : BorderLayoutPanel() {
178
162
else -> UIUtil .getPanelBackground().brighter()
179
163
}
180
164
181
- // Update ratio label
182
165
usageRatioLabel.text = " ${formatTokenCount(totalTokens)} /${formatTokenCount(maxContextWindowTokens)} (${usageRatio} %)"
183
-
184
166
progressBar.isVisible = true
185
167
usageRatioLabel.isVisible = true
186
-
187
168
progressBar.toolTipText = " Token usage: $usageRatio % of context window"
188
169
}
189
170
@@ -194,10 +175,7 @@ class TokenUsagePanel(private val project: Project) : BorderLayoutPanel() {
194
175
else -> count.toString()
195
176
}
196
177
}
197
-
198
- /* *
199
- * Reset the token usage display
200
- */
178
+
201
179
fun reset () {
202
180
ApplicationManager .getApplication().invokeLater {
203
181
currentUsage = Usage ()
@@ -213,14 +191,8 @@ class TokenUsagePanel(private val project: Project) : BorderLayoutPanel() {
213
191
repaint()
214
192
}
215
193
}
216
-
217
- /* *
218
- * Get current usage for external access
219
- */
194
+
220
195
fun getCurrentUsage (): Usage = currentUsage
221
-
222
- /* *
223
- * Get current model for external access
224
- */
196
+
225
197
fun getCurrentModel (): String? = currentModel
226
198
}
0 commit comments