<commit_before>/**
 * Copyright 2011-2014 eBusiness Information, Groupe Excilys (www.ebusinessinformation.fr)
 *
 * 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 io.gatling.recorder.ui.swing.frame

import java.awt.Font
import javax.swing.filechooser.FileNameExtensionFilter

import scala.collection.JavaConversions.seqAsJavaList
import scala.swing._
import scala.swing.BorderPanel.Position._
import scala.swing.FileChooser.SelectionMode
import scala.swing.event.{ ButtonClicked, KeyReleased, SelectionChanged }
import scala.util.Try

import io.gatling.core.util.PathHelper._
import io.gatling.core.util.StringHelper.RichString
import io.gatling.recorder.RecorderMode
import io.gatling.recorder.config._
import io.gatling.recorder.config.FilterStrategy.BlacklistFirst
import io.gatling.recorder.http.ssl.{ SSLServerContext, SSLCertUtil, HttpsMode, KeyStoreType }
import io.gatling.recorder.http.ssl.HttpsMode._
import io.gatling.recorder.ui.RecorderFrontend
import io.gatling.recorder.ui.swing.Commons._
import io.gatling.recorder.ui.swing.component.FilterTable
import io.gatling.recorder.ui.swing.frame.ValidationHelper._
import io.gatling.recorder.ui.swing.util._
import io.gatling.recorder.ui.swing.util.UIHelper._

class ConfigurationFrame(frontend: RecorderFrontend)(implicit configuration: RecorderConfiguration) extends MainFrame {

  /************************************/
  /**           COMPONENTS           **/
  /************************************/

  /* Top panel components */
  private val modeSelector = new LabelledComboBox[RecorderMode](RecorderMode.AllModes)

  /* Network panel components */
  private val localProxyHttpPort = new TextField(4)
  private val outgoingProxyHost = new TextField(10)
  private val outgoingProxyHttpPort = new TextField(4) { enabled = false }
  private val outgoingProxyHttpsPort = new TextField(4) { enabled = false }
  private val outgoingProxyUsername = new TextField(10) { enabled = false }
  private val outgoingProxyPassword = new TextField(10) { enabled = false }

  /* HTTPS mode components */
  private val httpsModes = new LabelledComboBox[HttpsMode](HttpsMode.AllHttpsModes)

  private val keyStorePath = new TextField(20)
  private val keyStoreChooser = new FileChooser { fileSelectionMode = SelectionMode.FilesOnly }
  private val keyStoreBrowserButton = Button("Browse")(keyStoreChooser.openSelection().foreach(keyStorePath.text = _))
  private val keyStorePassword = new TextField(10)
  private val keyStoreTypes = new LabelledComboBox[KeyStoreType](KeyStoreType.AllKeyStoreTypes)
  private val certificatePath = new TextField(20)
  private val certificatePathChooser = new FileChooser { fileSelectionMode = SelectionMode.FilesOnly }
  private val certificatePathBrowserButton = Button("Browse")(certificatePathChooser.openSelection().foreach(certificatePath.text = _))
  private val privateKeyPath = new TextField(20)
  private val privateKeyPathChooser = new FileChooser { fileSelectionMode = SelectionMode.FilesOnly }
  private val privateKeyPathBrowserButton = Button("Browse")(privateKeyPathChooser.openSelection().foreach(privateKeyPath.text = _))

  private val caFilesSavePathChooser = new FileChooser { fileSelectionMode = SelectionMode.DirectoriesOnly }
  private val generateCAFilesButton = new Button(Action("Generate CA")(caFilesSavePathChooser.openSelection().foreach { dir =>
    generateCAFiles(dir)
    certificatePath.text = s"$dir/${SSLServerContext.GatlingCACrtFile}"
    privateKeyPath.text = s"$dir/${SSLServerContext.GatlingCAKeyFile}"
  }))

  /* Har Panel components */
  private val harPath = new TextField(66)
  private val harFileFilter = new FileNameExtensionFilter("HTTP Archive (.har)", "har")
  private val harFileChooser = new FileChooser { fileSelectionMode = SelectionMode.FilesOnly; fileFilter = harFileFilter }
  private val harFileBrowserButton = Button("Browse")(harFileChooser.openSelection().foreach(harPath.text = _))

  /* Simulation panel components */
  private val simulationPackage = new TextField(30)
  private val simulationClassName = new TextField(30)
  private val followRedirects = new CheckBox("Follow Redirects?")
  private val inferHtmlResources = new CheckBox("Infer html resources?")
  private val removeConditionalCache = new CheckBox("Remove conditional cache headers?")
  private val checkResponseBodies = new CheckBox("Save & check response bodies?")
  private val automaticReferers = new CheckBox("Automatic Referers?")

  /* Output panel components */
  private val outputEncoding = new ComboBox[String](CharsetHelper.orderedLabelList)
  private val outputFolderPath = new TextField(60)
  private val outputFolderChooser = new FileChooser { fileSelectionMode = SelectionMode.DirectoriesOnly }
  private val outputFolderBrowserButton = Button("Browse")(outputFolderChooser.saveSelection().foreach(outputFolderPath.text = _))

  /* Filters panel components */<commit_msg>Resize HAR file path TextField<commit_after>/**
 * Copyright 2011-2014 eBusiness Information, Groupe Excilys (www.ebusinessinformation.fr)
 *
 * 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 io.gatling.recorder.ui.swing.frame

import java.awt.Font
import javax.swing.filechooser.FileNameExtensionFilter

import scala.collection.JavaConversions.seqAsJavaList
import scala.swing._
import scala.swing.BorderPanel.Position._
import scala.swing.FileChooser.SelectionMode
import scala.swing.event.{ ButtonClicked, KeyReleased, SelectionChanged }
import scala.util.Try

import io.gatling.core.util.PathHelper._
import io.gatling.core.util.StringHelper.RichString
import io.gatling.recorder.RecorderMode
import io.gatling.recorder.config._
import io.gatling.recorder.config.FilterStrategy.BlacklistFirst
import io.gatling.recorder.http.ssl.{ SSLServerContext, SSLCertUtil, HttpsMode, KeyStoreType }
import io.gatling.recorder.http.ssl.HttpsMode._
import io.gatling.recorder.ui.RecorderFrontend
import io.gatling.recorder.ui.swing.Commons._
import io.gatling.recorder.ui.swing.component.FilterTable
import io.gatling.recorder.ui.swing.frame.ValidationHelper._
import io.gatling.recorder.ui.swing.util._
import io.gatling.recorder.ui.swing.util.UIHelper._

class ConfigurationFrame(frontend: RecorderFrontend)(implicit configuration: RecorderConfiguration) extends MainFrame {

  /************************************/
  /**           COMPONENTS           **/
  /************************************/

  /* Top panel components */
  private val modeSelector = new LabelledComboBox[RecorderMode](RecorderMode.AllModes)

  /* Network panel components */
  private val localProxyHttpPort = new TextField(4)
  private val outgoingProxyHost = new TextField(10)
  private val outgoingProxyHttpPort = new TextField(4) { enabled = false }
  private val outgoingProxyHttpsPort = new TextField(4) { enabled = false }
  private val outgoingProxyUsername = new TextField(10) { enabled = false }
  private val outgoingProxyPassword = new TextField(10) { enabled = false }

  /* HTTPS mode components */
  private val httpsModes = new LabelledComboBox[HttpsMode](HttpsMode.AllHttpsModes)

  private val keyStorePath = new TextField(20)
  private val keyStoreChooser = new FileChooser { fileSelectionMode = SelectionMode.FilesOnly }
  private val keyStoreBrowserButton = Button("Browse")(keyStoreChooser.openSelection().foreach(keyStorePath.text = _))
  private val keyStorePassword = new TextField(10)
  private val keyStoreTypes = new LabelledComboBox[KeyStoreType](KeyStoreType.AllKeyStoreTypes)
  private val certificatePath = new TextField(20)
  private val certificatePathChooser = new FileChooser { fileSelectionMode = SelectionMode.FilesOnly }
  private val certificatePathBrowserButton = Button("Browse")(certificatePathChooser.openSelection().foreach(certificatePath.text = _))
  private val privateKeyPath = new TextField(20)
  private val privateKeyPathChooser = new FileChooser { fileSelectionMode = SelectionMode.FilesOnly }
  private val privateKeyPathBrowserButton = Button("Browse")(privateKeyPathChooser.openSelection().foreach(privateKeyPath.text = _))

  private val caFilesSavePathChooser = new FileChooser { fileSelectionMode = SelectionMode.DirectoriesOnly }
  private val generateCAFilesButton = new Button(Action("Generate CA")(caFilesSavePathChooser.openSelection().foreach { dir =>
    generateCAFiles(dir)
    certificatePath.text = s"$dir/${SSLServerContext.GatlingCACrtFile}"
    privateKeyPath.text = s"$dir/${SSLServerContext.GatlingCAKeyFile}"
  }))

  /* Har Panel components */
  private val harPath = new TextField(60)
  private val harFileFilter = new FileNameExtensionFilter("HTTP Archive (.har)", "har")
  private val harFileChooser = new FileChooser { fileSelectionMode = SelectionMode.FilesOnly; fileFilter = harFileFilter }
  private val harFileBrowserButton = Button("Browse")(harFileChooser.openSelection().foreach(harPath.text = _))

  /* Simulation panel components */
  private val simulationPackage = new TextField(30)
  private val simulationClassName = new TextField(30)
  private val followRedirects = new CheckBox("Follow Redirects?")
  private val inferHtmlResources = new CheckBox("Infer html resources?")
  private val removeConditionalCache = new CheckBox("Remove conditional cache headers?")
  private val checkResponseBodies = new CheckBox("Save & check response bodies?")
  private val automaticReferers = new CheckBox("Automatic Referers?")

  /* Output panel components */
  private val outputEncoding = new ComboBox[String](CharsetHelper.orderedLabelList)
  private val outputFolderPath = new TextField(60)
  private val outputFolderChooser = new FileChooser { fileSelectionMode = SelectionMode.DirectoriesOnly }
  private val outputFolderBrowserButton = Button("Browse")(outputFolderChooser.saveSelection().foreach(outputFolderPath.text = _))

  /* Filters panel components */
{'fraction_non_alphanumeric': 0.09916291049581455, 'fraction_numerical': 0.006807101462606936, 'mean_word_length': 5.47528290649196, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '144870', 'n_tokens_mistral': 3093, 'n_tokens_neox': 2970, 'n_words': 770}