<commit_before>package com.hea3ven.idolscraper.ui

import com.hea3ven.idolscraper.Config
import com.hea3ven.idolscraper.PreserveOriginalSaveStrategy
import com.hea3ven.idolscraper.getSaveStrategy
import com.hea3ven.idolscraper.page.ScrapingTask
import com.hea3ven.idolscraper.page.getPageHandler
import java.awt.*
import java.awt.event.ActionEvent
import java.io.*
import java.net.MalformedURLException
import java.net.URL
import java.nio.file.Files
import java.nio.file.Paths
import javax.imageio.ImageIO
import javax.swing.*
import javax.swing.border.EmptyBorder

class MainWindow : JFrame("Idol Scraper") {

	private val dirChooser = JFileChooser().apply {
		dialogTitle = "Target destination"
		fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
		isAcceptAllFileFilterUsed = false
		selectedFile = Config.getDestinationDir()
	}

	init {
		defaultCloseOperation = EXIT_ON_CLOSE
		size = Dimension(600, 900)

		layout = GridBagLayout()

		val urlLbl = JLabel("URL:")
		urlLbl.border = EmptyBorder(0, 5, 0, 0)
		val urlTxt = JTextField()

		val destLbl = JLabel("Destination:")
		destLbl.border = EmptyBorder(0, 5, 0, 0)
		val destTxt = JTextField(Config.getDestinationDir()?.absolutePath ?: "")
		val destBtn = JButton()
		destBtn.action = object : AbstractAction() {
			override fun actionPerformed(e: ActionEvent?) {
				if (dirChooser.showOpenDialog(this@MainWindow) == JFileChooser.APPROVE_OPTION) {
					destTxt.text = dirChooser.selectedFile.absolutePath
					Config.setDestinationDir(dirChooser.selectedFile)
				}
			}
		}
		destBtn.text = "..."

		val formatLbl = JLabel("Format:")
		formatLbl.border = EmptyBorder(0, 5, 0, 0)
		val formatCb = JComboBox(arrayOf("original", "png", "jpg"))
		formatCb.preferredSize = Dimension(100, 22)
		formatCb.border = EmptyBorder(2, 2, 2, 5)
		formatCb.selectedItem = Config.getFormat()
		formatCb.action = object : AbstractAction() {
			override fun actionPerformed(e: ActionEvent?) {
				Config.setFormat(formatCb.selectedItem as String?)
			}
		}

		val scanBtn = JButton()
		scanBtn.preferredSize = Dimension(72, 22)

		val logTxtArea = JTextArea()
		logTxtArea.isEditable = false
		val logTxtAreaScrlPn = JScrollPane(logTxtArea)

		scanBtn.action = object : AbstractAction() {<commit_msg>Make it so that the whole url and target text entries get selected when getting focused with a click<commit_after>package com.hea3ven.idolscraper.ui

import com.hea3ven.idolscraper.Config
import com.hea3ven.idolscraper.PreserveOriginalSaveStrategy
import com.hea3ven.idolscraper.getSaveStrategy
import com.hea3ven.idolscraper.page.ScrapingTask
import com.hea3ven.idolscraper.page.getPageHandler
import java.awt.*
import java.awt.event.ActionEvent
import java.awt.event.FocusEvent
import java.awt.event.FocusListener
import java.io.*
import java.net.MalformedURLException
import java.net.URL
import java.nio.file.Files
import java.nio.file.Paths
import javax.imageio.ImageIO
import javax.swing.*
import javax.swing.border.EmptyBorder

class MainWindow : JFrame("Idol Scraper") {

	private val dirChooser = JFileChooser().apply {
		dialogTitle = "Target destination"
		fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
		isAcceptAllFileFilterUsed = false
		selectedFile = Config.getDestinationDir()
	}

	init {
		defaultCloseOperation = EXIT_ON_CLOSE
		size = Dimension(600, 900)

		layout = GridBagLayout()

		val urlLbl = JLabel("URL:")
		urlLbl.border = EmptyBorder(0, 5, 0, 0)
		val urlTxt = JTextField()
		urlTxt.addFocusListener(object : FocusListener {
			override fun focusLost(e: FocusEvent?) {
			}

			override fun focusGained(e: FocusEvent?) {
				urlTxt.select(0, urlTxt.text.length)
			}
		})

		val destLbl = JLabel("Destination:")
		destLbl.border = EmptyBorder(0, 5, 0, 0)
		val destTxt = JTextField(Config.getDestinationDir()?.absolutePath ?: "")
		destTxt.addFocusListener(object : FocusListener {
			override fun focusLost(e: FocusEvent?) {
			}

			override fun focusGained(e: FocusEvent?) {
				destTxt.select(0, destTxt.text.length)
			}
		})
		val destBtn = JButton()
		destBtn.action = object : AbstractAction() {
			override fun actionPerformed(e: ActionEvent?) {
				if (dirChooser.showOpenDialog(this@MainWindow) == JFileChooser.APPROVE_OPTION) {
					destTxt.text = dirChooser.selectedFile.absolutePath
					Config.setDestinationDir(dirChooser.selectedFile)
				}
			}
		}
		destBtn.text = "..."

		val formatLbl = JLabel("Format:")
		formatLbl.border = EmptyBorder(0, 5, 0, 0)
		val formatCb = JComboBox(arrayOf("original", "png", "jpg"))
		formatCb.preferredSize = Dimension(100, 22)
		formatCb.border = EmptyBorder(2, 2, 2, 5)
		formatCb.selectedItem = Config.getFormat()
		formatCb.action = object : AbstractAction() {
			override fun actionPerformed(e: ActionEvent?) {
				Config.setFormat(formatCb.selectedItem as String?)
			}
		}

		val scanBtn = JButton()
		scanBtn.preferredSize = Dimension(72, 22)

		val logTxtArea = JTextArea()
		logTxtArea.isEditable = false
		val logTxtAreaScrlPn = JScrollPane(logTxtArea)

		scanBtn.action = object : AbstractAction() {
{'fraction_non_alphanumeric': 0.1087949176096883, 'fraction_numerical': 0.015088346237839985, 'mean_word_length': 4.705549263873159, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3868644', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1700, 'n_words': 338}