<commit_before>package ui.issuepanel;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.WeakChangeListener;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.control.ToggleButton;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.event.Event;
import model.Model;
import model.TurboIssue;
import model.TurboLabel;
import model.TurboMilestone;
import model.TurboUser;
import ui.CheckboxListDialog;
import ui.EditableMarkupPopup;
import ui.LabelCheckboxListDialog;
import ui.LabelDisplayBox;
import ui.ListableDisplayBox;
import ui.ParentIssuesDisplayBox;
import ui.TraversableTextArea;
import util.Browse;

public class IssueEditDisplay extends VBox{
	private static final int ELEMENT_SPACING = 5;
	protected static final String DEFAULT_WEB_CSS = 
			"<style type=\"text/css\">"
			+ "img{"
			+ "max-width: 100%;"
			+ "}"
			+ "p {"
			+ "font-family: System;"
			+ "font-size: 13px"
			+ "}"
			+ "</style>";
	protected static String EDIT_BTN_TXT = "\uf058";
	protected static String BACK_BTN_TXT = " \uf0a4 ";
	protected static String POPUP_BTN_TXT = "\uf07f";
	protected static final String ISSUE_DETAILS_BTN_TXT = "Details >>";
	protected static final int LINE_HEIGHT = 18;
	protected static final int TITLE_ROW_NUM = 3;
	protected static final int DESC_ROW_NUM = 8;
	protected static final KeyCombination SAVE_ISSUE_SHORTCUT = new KeyCodeCombination(KeyCode.ENTER, KeyCombination.CONTROL_DOWN);
	
	private Text issueIdText;
	private TraversableTextArea editableIssueDesc;
	private WebView issueDesc;
	private ToggleButton descEditMode;
	private Button descPopup;
	private VBox descArea;
	
	private LabelDisplayBox statusBox;
	private Parent parents;
	private Parent milestone;
	private Parent labels;
	private Parent assignee;
	
	private Button cancel;
	private Button save;
	
	private final TurboIssue issue;
	private final Model model;
	private final Stage parentStage;
	private final WeakReference<IssueDisplayPane> parentContainer;
	private boolean focusRequested;
	
	private ArrayList<ChangeListener<?>> changeListeners = new ArrayList<ChangeListener<?>>();
	
	public IssueEditDisplay(TurboIssue displayedIssue, Stage parentStage, Model model, IssueDisplayPane parent, boolean focusRequested){
		this.issue = displayedIssue;
		this.model = model;
		this.parentStage = parentStage;
		this.parentContainer = new WeakReference<IssueDisplayPane>(parent);
		this.focusRequested = focusRequested;
		setup();
		setupKeyboardShortcuts();
	}

	
	private void setup(){
		setPadding(new Insets(15));
		setSpacing(ELEMENT_SPACING);
		setupDescription();
		setVgrow(descArea, Priority.ALWAYS);
		getChildren().addAll(top(), descArea, bottom());
	}
	
	private void triggerClick(Node node){
		Event.fireEvent(node, 
				new MouseEvent(MouseEvent.MOUSE_CLICKED, 
						0, 0, 0, 0, MouseButton.PRIMARY, 1, 
						true, true, true, true, true, true, true, true, true, true, null));
	}
	
	private void setupKeyboardShortcuts(){
		WeakReference<IssueEditDisplay> selfRef = new WeakReference<>(this);
		this.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
			if(SAVE_ISSUE_SHORTCUT.match(e)){
				parentContainer.get().handleSaveClicked();
			}else{
				KeyCode code = e.getCode();
				switch(code){
				case D:
					descEditMode.fire();
					break;
				case P:
					selfRef.get().triggerClick(parents);
					break;
				case S:
					selfRef.get().triggerClick(statusBox);
					break;
				case L:
					selfRef.get().triggerClick(labels);
					break;
				case A:
					selfRef.get().triggerClick(assignee);
					break;
				case M:
					selfRef.get().triggerClick(milestone);
					break;
				default:
					break;
				}
			}
		});<commit_msg>implemented escape to set focus on issue form itself<commit_after>package ui.issuepanel;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.WeakChangeListener;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.control.ToggleButton;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.event.Event;
import model.Model;
import model.TurboIssue;
import model.TurboLabel;
import model.TurboMilestone;
import model.TurboUser;
import ui.CheckboxListDialog;
import ui.EditableMarkupPopup;
import ui.LabelCheckboxListDialog;
import ui.LabelDisplayBox;
import ui.ListableDisplayBox;
import ui.ParentIssuesDisplayBox;
import ui.TraversableTextArea;
import util.Browse;

public class IssueEditDisplay extends VBox{
	private static final int ELEMENT_SPACING = 5;
	protected static final String DEFAULT_WEB_CSS = 
			"<style type=\"text/css\">"
			+ "img{"
			+ "max-width: 100%;"
			+ "}"
			+ "p {"
			+ "font-family: System;"
			+ "font-size: 13px"
			+ "}"
			+ "</style>";
	protected static String EDIT_BTN_TXT = "\uf058";
	protected static String BACK_BTN_TXT = " \uf0a4 ";
	protected static String POPUP_BTN_TXT = "\uf07f";
	protected static final String ISSUE_DETAILS_BTN_TXT = "Details >>";
	protected static final int LINE_HEIGHT = 18;
	protected static final int TITLE_ROW_NUM = 3;
	protected static final int DESC_ROW_NUM = 8;
	protected static final KeyCombination SAVE_ISSUE_SHORTCUT = new KeyCodeCombination(KeyCode.ENTER, KeyCombination.CONTROL_DOWN);
	
	private Text issueIdText;
	private TraversableTextArea editableIssueDesc;
	private WebView issueDesc;
	private ToggleButton descEditMode;
	private Button descPopup;
	private VBox descArea;
	
	private LabelDisplayBox statusBox;
	private Parent parents;
	private Parent milestone;
	private Parent labels;
	private Parent assignee;
	
	private Button cancel;
	private Button save;
	
	private final TurboIssue issue;
	private final Model model;
	private final Stage parentStage;
	private final WeakReference<IssueDisplayPane> parentContainer;
	private boolean focusRequested;
	
	private ArrayList<ChangeListener<?>> changeListeners = new ArrayList<ChangeListener<?>>();
	
	public IssueEditDisplay(TurboIssue displayedIssue, Stage parentStage, Model model, IssueDisplayPane parent, boolean focusRequested){
		this.issue = displayedIssue;
		this.model = model;
		this.parentStage = parentStage;
		this.parentContainer = new WeakReference<IssueDisplayPane>(parent);
		this.focusRequested = focusRequested;
		setup();
		setupKeyboardShortcuts();
	}

	
	private void setup(){
		setPadding(new Insets(15));
		setSpacing(ELEMENT_SPACING);
		setupDescription();
		setVgrow(descArea, Priority.ALWAYS);
		getChildren().addAll(top(), descArea, bottom());
	}
	
	private void triggerClick(Node node){
		Event.fireEvent(node, 
				new MouseEvent(MouseEvent.MOUSE_CLICKED, 
						0, 0, 0, 0, MouseButton.PRIMARY, 1, 
						true, true, true, true, true, true, true, true, true, true, null));
	}
	
	private void setupKeyboardShortcuts(){
		WeakReference<IssueEditDisplay> selfRef = new WeakReference<>(this);
		this.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
			if(SAVE_ISSUE_SHORTCUT.match(e)){
				parentContainer.get().handleSaveClicked();
			}else{
				KeyCode code = e.getCode();
				switch(code){
				case ESCAPE:
					selfRef.get().requestFocus();
					break;
				case D:
					descEditMode.fire();
					break;
				case P:
					selfRef.get().triggerClick(parents);
					break;
				case S:
					selfRef.get().triggerClick(statusBox);
					break;
				case L:
					selfRef.get().triggerClick(labels);
					break;
				case A:
					selfRef.get().triggerClick(assignee);
					break;
				case M:
					selfRef.get().triggerClick(milestone);
					break;
				default:
					break;
				}
			}
		});
{'fraction_non_alphanumeric': 0.10186926224975114, 'fraction_numerical': 0.005309147218228072, 'mean_word_length': 4.890553745928338, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, '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': '512560', 'n_tokens_mistral': 3225, 'n_tokens_neox': 2819, 'n_words': 666}