1
1
package com.huayi.intellijplatform.gitstats.toolWindow
2
2
3
3
import com.huayi.intellijplatform.gitstats.MyBundle
4
+ import com.huayi.intellijplatform.gitstats.components.SettingDialogWrapper
4
5
import com.huayi.intellijplatform.gitstats.services.GitStatsService
5
6
import com.huayi.intellijplatform.gitstats.utils.Utils
7
+ import com.intellij.icons.AllIcons
6
8
import com.intellij.openapi.components.service
7
9
import com.intellij.openapi.diagnostic.thisLogger
8
10
import com.intellij.openapi.project.Project
11
+ import com.intellij.openapi.ui.popup.IconButton
9
12
import com.intellij.openapi.wm.ToolWindow
10
13
import com.intellij.openapi.wm.ToolWindowFactory
11
- import com.intellij.ui.components.JBBox
12
- import com.intellij.ui.components.JBLabel
13
- import com.intellij.ui.components.JBPanel
14
- import com.intellij.ui.components.JBScrollPane
15
- import com.intellij.ui.components.JBLoadingPanel
14
+ import com.intellij.ui.components.*
16
15
import com.intellij.ui.content.ContentFactory
17
16
import com.intellij.ui.table.JBTable
18
17
import com.michaelbaranov.microba.calendar.DatePicker
19
18
import java.awt.BorderLayout
20
19
import java.awt.CardLayout
21
20
import java.awt.Dimension
22
21
import java.awt.Font
23
- import java.text.SimpleDateFormat
24
- import java.time.LocalDate
25
- import java.time.ZoneId
26
22
import java.util.*
27
- import javax.swing.BorderFactory
28
- import javax.swing.BoxLayout
29
- import javax.swing.JButton
30
- import javax.swing.ListSelectionModel
23
+ import javax.swing.*
24
+ import kotlin.concurrent.thread
31
25
32
26
33
27
class GitStatsWindowFactory : ToolWindowFactory {
@@ -50,27 +44,7 @@ class GitStatsWindowFactory : ToolWindowFactory {
50
44
51
45
private val service = toolWindow.project.service<GitStatsService >()
52
46
53
- private fun getUserStatsTableModel (startTime : Date , endTime : Date ): StatsTableModel {
54
- val userStats = service.getUserStats(
55
- SimpleDateFormat (" yyyy-MM-dd HH:mm:ss" ).format(startTime),
56
- SimpleDateFormat (" yyyy-MM-dd HH:mm:ss" ).format(endTime)
57
- )
58
- val data = userStats.map { item ->
59
- arrayOf(
60
- item.author,
61
- item.commitCount.toString(),
62
- item.addedLines.toString(),
63
- item.deletedLines.toString(),
64
- item.modifiedFileCount.toString()
65
- )
66
- }.toTypedArray()
67
- return StatsTableModel (
68
- data,
69
- arrayOf(" Author" , " CommitCount" , " AddedLines" , " DeletedLines" , " ModifiedFileCount" )
70
- )
71
- }
72
-
73
- fun getContent (toolWindow : ToolWindow ) = JBPanel <JBPanel <* >>().apply {
47
+ fun getContent (toolWindow : ToolWindow ) = JBPanel <JBPanel <* >>(BorderLayout ()).apply {
74
48
var (startTime, endTime) = Utils .getThisWeekDateTimeRange()
75
49
val table = JBTable ().apply {
76
50
font = Font (" Arial" , Font .PLAIN , 14 )
@@ -81,7 +55,6 @@ class GitStatsWindowFactory : ToolWindowFactory {
81
55
rowHeight = 30
82
56
setSelectionMode(ListSelectionModel .SINGLE_SELECTION )
83
57
}
84
- layout = BorderLayout ()
85
58
border = BorderFactory .createEmptyBorder(0 , 0 , 0 , 0 )
86
59
87
60
val contentPanel = JBPanel <JBPanel <* >>().apply {
@@ -105,8 +78,11 @@ class GitStatsWindowFactory : ToolWindowFactory {
105
78
layout = BoxLayout (this , BoxLayout .X_AXIS )
106
79
add(JBBox .createHorizontalStrut(10 ))
107
80
add(JBLabel (MyBundle .message(" filterStartTimeLabel" , " " )))
108
- // val dateTimePicker = LocalDateTimePicker(LocalDateTime.now())
109
- // add(dateTimePicker)
81
+ // add(LocalDateTimePicker(LocalDateTime.now()))
82
+ // datePicker.dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
83
+ // add(CalendarView())
84
+ // val datePicker = JXDatePicker()
85
+ // datePicker.date = Date()
110
86
// add(DatePicker(Date.from(startTime.atStartOfDay(ZoneId.systemDefault()).toInstant())).apply {
111
87
add(DatePicker (startTime).apply {
112
88
isDropdownFocusable = false
@@ -115,26 +91,28 @@ class GitStatsWindowFactory : ToolWindowFactory {
115
91
preferredSize = size
116
92
maximumSize = size
117
93
minimumSize = size
94
+ isShowNoneButton = false
95
+ isShowNumberOfWeek = true
96
+ isStripTime = true
97
+ components.last().preferredSize = Dimension (30 , 30 )
118
98
addPropertyChangeListener {
119
99
if (it.propertyName == " date" && it.newValue != null ) {
120
100
startTime = it.newValue as Date
121
101
}
122
102
}
123
103
})
124
104
add(JBBox .createHorizontalStrut(10 ))
125
- // datePicker.dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
126
- // add(CalendarView())
127
- // val datePicker = JXDatePicker()
128
- // datePicker.date = Date()
129
105
add(JBLabel (MyBundle .message(" filterEndTimeLabel" , " " )))
130
- // add(DatePicker(Date.from(endTime.atStartOfDay(ZoneId.systemDefault()).toInstant())).apply {
131
106
add(DatePicker (endTime).apply {
132
107
isDropdownFocusable = false
133
- // isFieldEditable = false
134
108
val size = Dimension (200 , preferredSize.height)
135
109
preferredSize = size
136
110
maximumSize = size
137
111
minimumSize = size
112
+ isShowNoneButton = false
113
+ isShowNumberOfWeek = true
114
+ isStripTime = true
115
+ components.last().preferredSize = Dimension (30 , 30 )
138
116
addPropertyChangeListener {
139
117
if (it.propertyName == " date" && it.newValue != null ) {
140
118
val calendar = Calendar .getInstance()
@@ -150,17 +128,24 @@ class GitStatsWindowFactory : ToolWindowFactory {
150
128
add(JButton (MyBundle .message(" refreshButtonLabel" )).apply {
151
129
addActionListener {
152
130
(contentPanel.layout as CardLayout ).show(contentPanel, " content_loading" )
153
- table.model = getUserStatsTableModel(startTime, endTime)
154
- (contentPanel.layout as CardLayout ).show(contentPanel, " content_table" )
155
- // label.text = MyBundle.message("randomLabel", service.getRandomNumber())
131
+ thread {
132
+ // service.getTopSpeedUserStats(startTime, endTime)
133
+ table.model = service.getUserStats(startTime, endTime)
134
+ SwingUtilities .invokeLater {
135
+ (contentPanel.layout as CardLayout ).show(contentPanel, " content_table" )
136
+ }
137
+ }
156
138
}
139
+ doClick()
157
140
})
158
- // val datePicker = JXDatePicker()
159
- // datePicker.setFormats(SimpleDateFormat("yyyy-MM-dd HH:mm:ss"))
160
- // datePicker.timeZone = TimeZone.getDefault()
161
- // datePicker.editor.isEditable = true
162
- // add(datePicker)
163
- // datePicker.editor = DateEditor(datePicker, "yyyy-MM-dd HH:mm:ss")
141
+ add(Box .createHorizontalGlue())
142
+ // add(IconButton(MyBundle.message("settingButtonTooltipText"), AllIcons.General.Settings))
143
+ add(IconLabelButton (AllIcons .General .Settings ) {
144
+ SettingDialogWrapper ().showAndGet()
145
+ }.apply {
146
+ toolTipText = MyBundle .message(" settingButtonTooltipText" )
147
+ })
148
+ add(JBBox .createHorizontalStrut(10 ))
164
149
}
165
150
add(headerPanel, BorderLayout .NORTH )
166
151
0 commit comments