<commit_before>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package pomodoro.toolkitwindow

import com.intellij.openapi.application.ApplicationManager
import pomodoro.UIBundle
import pomodoro.model.PomodoroModel
import pomodoro.model.PomodoroState
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.time.Duration
import java.time.Instant
import javax.swing.ImageIcon
import javax.swing.JComponent

class PomodoroPresenter(private val model: PomodoroModel) {
    private val playIcon = ImageIcon(javaClass.getResource("/resources/play-icon.png"))
    private val stopIcon = ImageIcon(javaClass.getResource("/resources/stop-icon.png"))

    private val form = PomodoroForm()
    private var progressBarPrefix = ""

    val contentPane: JComponent
        get() = form.rootPanel

    init {
        form.controlButton.addActionListener {
            model.onUserSwitchToNextState(Instant.now())
            updateUI(model.state)
        }
        form.pomodorosLabel.addMouseListener(object : MouseAdapter() {
            override fun mouseClicked(event: MouseEvent) {
                if (event.clickCount >= 2) {
                    model.resetPomodoros()
                    updateUI(model.state)
                }
            }
        })
        updateUI(model.state)

        model.addUpdateListener(this, object : PomodoroModel.Listener {
            override fun onStateChange(state: PomodoroState, wasManuallyStopped: Boolean) {
                updateUI(state)
            }
        })
    }

    private fun updateUI(state: PomodoroState) {
        ApplicationManager.getApplication().invokeLater {
            when (state.type) {
                PomodoroState.Type.RUN -> {
                    form.controlButton.text = UIBundle.message("toolwindow.button_stop")
                    form.controlButton.icon = stopIcon
                    progressBarPrefix = UIBundle.message("toolwindow.prefix_working")
                }
                PomodoroState.Type.STOP -> {
                    form.controlButton.text = UIBundle.message("toolwindow.button_start")
                    form.controlButton.icon = playIcon
                }
                PomodoroState.Type.BREAK -> {
                    form.controlButton.text = UIBundle.message("toolwindow.button_stop")
                    progressBarPrefix = UIBundle.message("toolwindow.button_break")
                }
                else -> throw IllegalStateException()
            }
            form.pomodorosLabel.text = state.pomodorosAmount.toString()

            form.progressBar.maximum = model.progressMax.toProgress()
            form.progressBar.value = hack_for_jdk1_6_u06__IDEA_9_0_2__winXP(state.progress.toProgress().toLong()).toInt()

            form.progressBar.string = progressBarPrefix + " " + formatDuration(model.timeLeft)
        }
    }

    companion object {
        private fun hack_for_jdk1_6_u06__IDEA_9_0_2__winXP(progress: Long): Long {
            // for some reason JProgressBar doesn't display text when progress is too small to be displayed
            return if (progress < 10) 10 else progress
        }

        fun formatDuration(timeLeft: Duration): String {
            val minutes = timeLeft.toMinutes()
            val seconds = timeLeft.minusMinutes(timeLeft.toMinutes()).seconds
            return String.format("%02d", minutes) + ":" + String.format("%02d", seconds)
        }

        fun Duration.toProgress(): Int {
            return (toMillis() / 1000).toInt()
        }
    }
}
<commit_msg>removed win xp jdk6 workaround<commit_after>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package pomodoro.toolkitwindow

import com.intellij.openapi.application.ApplicationManager
import pomodoro.UIBundle
import pomodoro.model.PomodoroModel
import pomodoro.model.PomodoroState
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.time.Duration
import java.time.Instant
import javax.swing.ImageIcon
import javax.swing.JComponent

class PomodoroPresenter(private val model: PomodoroModel) {
    private val playIcon = ImageIcon(javaClass.getResource("/resources/play-icon.png"))
    private val stopIcon = ImageIcon(javaClass.getResource("/resources/stop-icon.png"))

    private val form = PomodoroForm()
    private var progressBarPrefix = ""

    val contentPane: JComponent
        get() = form.rootPanel

    init {
        form.controlButton.addActionListener {
            model.onUserSwitchToNextState(Instant.now())
            updateUI(model.state)
        }
        form.pomodorosLabel.addMouseListener(object : MouseAdapter() {
            override fun mouseClicked(event: MouseEvent) {
                if (event.clickCount >= 2) {
                    model.resetPomodoros()
                    updateUI(model.state)
                }
            }
        })
        updateUI(model.state)

        model.addUpdateListener(this, object : PomodoroModel.Listener {
            override fun onStateChange(state: PomodoroState, wasManuallyStopped: Boolean) {
                updateUI(state)
            }
        })
    }

    private fun updateUI(state: PomodoroState) {
        ApplicationManager.getApplication().invokeLater {
            when (state.type) {
                PomodoroState.Type.RUN -> {
                    form.controlButton.text = UIBundle.message("toolwindow.button_stop")
                    form.controlButton.icon = stopIcon
                    progressBarPrefix = UIBundle.message("toolwindow.prefix_working")
                }
                PomodoroState.Type.STOP -> {
                    form.controlButton.text = UIBundle.message("toolwindow.button_start")
                    form.controlButton.icon = playIcon
                }
                PomodoroState.Type.BREAK -> {
                    form.controlButton.text = UIBundle.message("toolwindow.button_stop")
                    progressBarPrefix = UIBundle.message("toolwindow.button_break")
                }
                else -> throw IllegalStateException()
            }
            form.pomodorosLabel.text = state.pomodorosAmount.toString()

            form.progressBar.maximum = model.progressMax.toProgress()
            form.progressBar.value = state.progress.toProgress()

            form.progressBar.string = progressBarPrefix + " " + formatDuration(model.timeLeft)
        }
    }

    companion object {
        fun formatDuration(timeLeft: Duration): String {
            val minutes = timeLeft.toMinutes()
            val seconds = timeLeft.minusMinutes(timeLeft.toMinutes()).seconds
            return String.format("%02d", minutes) + ":" + String.format("%02d", seconds)
        }

        private fun Duration.toProgress(): Int {
            return (toMillis() / 1000).toInt()
        }
    }
}

{'fraction_non_alphanumeric': 0.0890314304041052, 'fraction_numerical': 0.005772931366260423, 'mean_word_length': 2.3545611015490535, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2394745', 'n_tokens_mistral': 2116, 'n_tokens_neox': 2017, 'n_words': 454}