11package com.huayi.intellijplatform.gitstats.toolWindow
22
33import com.huayi.intellijplatform.gitstats.MyBundle
4+ import com.huayi.intellijplatform.gitstats.components.SettingDialogWrapper
45import com.huayi.intellijplatform.gitstats.services.GitStatsService
56import com.huayi.intellijplatform.gitstats.utils.Utils
7+ import com.intellij.icons.AllIcons
68import com.intellij.openapi.components.service
79import com.intellij.openapi.diagnostic.thisLogger
810import com.intellij.openapi.project.Project
11+ import com.intellij.openapi.ui.popup.IconButton
912import com.intellij.openapi.wm.ToolWindow
1013import 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.*
1615import com.intellij.ui.content.ContentFactory
1716import com.intellij.ui.table.JBTable
1817import com.michaelbaranov.microba.calendar.DatePicker
1918import java.awt.BorderLayout
2019import java.awt.CardLayout
2120import java.awt.Dimension
2221import java.awt.Font
23- import java.text.SimpleDateFormat
24- import java.time.LocalDate
25- import java.time.ZoneId
2622import 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
3125
3226
3327class GitStatsWindowFactory : ToolWindowFactory {
@@ -50,27 +44,7 @@ class GitStatsWindowFactory : ToolWindowFactory {
5044
5145 private val service = toolWindow.project.service<GitStatsService >()
5246
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 {
7448 var (startTime, endTime) = Utils .getThisWeekDateTimeRange()
7549 val table = JBTable ().apply {
7650 font = Font (" Arial" , Font .PLAIN , 14 )
@@ -81,7 +55,6 @@ class GitStatsWindowFactory : ToolWindowFactory {
8155 rowHeight = 30
8256 setSelectionMode(ListSelectionModel .SINGLE_SELECTION )
8357 }
84- layout = BorderLayout ()
8558 border = BorderFactory .createEmptyBorder(0 , 0 , 0 , 0 )
8659
8760 val contentPanel = JBPanel <JBPanel <* >>().apply {
@@ -105,8 +78,11 @@ class GitStatsWindowFactory : ToolWindowFactory {
10578 layout = BoxLayout (this , BoxLayout .X_AXIS )
10679 add(JBBox .createHorizontalStrut(10 ))
10780 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()
11086// add(DatePicker(Date.from(startTime.atStartOfDay(ZoneId.systemDefault()).toInstant())).apply {
11187 add(DatePicker (startTime).apply {
11288 isDropdownFocusable = false
@@ -115,26 +91,28 @@ class GitStatsWindowFactory : ToolWindowFactory {
11591 preferredSize = size
11692 maximumSize = size
11793 minimumSize = size
94+ isShowNoneButton = false
95+ isShowNumberOfWeek = true
96+ isStripTime = true
97+ components.last().preferredSize = Dimension (30 , 30 )
11898 addPropertyChangeListener {
11999 if (it.propertyName == " date" && it.newValue != null ) {
120100 startTime = it.newValue as Date
121101 }
122102 }
123103 })
124104 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()
129105 add(JBLabel (MyBundle .message(" filterEndTimeLabel" , " " )))
130- // add(DatePicker(Date.from(endTime.atStartOfDay(ZoneId.systemDefault()).toInstant())).apply {
131106 add(DatePicker (endTime).apply {
132107 isDropdownFocusable = false
133- // isFieldEditable = false
134108 val size = Dimension (200 , preferredSize.height)
135109 preferredSize = size
136110 maximumSize = size
137111 minimumSize = size
112+ isShowNoneButton = false
113+ isShowNumberOfWeek = true
114+ isStripTime = true
115+ components.last().preferredSize = Dimension (30 , 30 )
138116 addPropertyChangeListener {
139117 if (it.propertyName == " date" && it.newValue != null ) {
140118 val calendar = Calendar .getInstance()
@@ -150,17 +128,24 @@ class GitStatsWindowFactory : ToolWindowFactory {
150128 add(JButton (MyBundle .message(" refreshButtonLabel" )).apply {
151129 addActionListener {
152130 (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+ }
156138 }
139+ doClick()
157140 })
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 ))
164149 }
165150 add(headerPanel, BorderLayout .NORTH )
166151
0 commit comments