<commit_before>package hu;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.*;
import java.io.File;
import java.util.*;

import javax.swing.*;

import jsui.JSJDialog;
import ca.uhn.hl7v2.model.Message;

/** main class and top level frame */
public class EditorJFrame extends JFrame {
	
	public static void main (String[] args) {
		System.out.println("user dir " + System.getProperty("user.dir"));
		EditorJFrame frame = new EditorJFrame();
		frame.setVisible(true);
		if (args.length == 0) {
			frame.addEditor();
		} else {
			for (String a : args) {
				frame.addFileEditor(new File(a));
			}
		}
	}
	
	private final JTabbedPane tabs = new JTabbedPane();
	
	private File dir = new File(System.getProperty("user.dir"));
	private Font editorFont = new Font("Monospaced", 0, 14);
	private String messageVersion = MsgUtil.HIGHEST_VERSION;
	private String js = "util.replace('A', 'B');";
	private String host = "localhost";
	private int port = 1000;
	
	public EditorJFrame () {
		super("HAPI HL7|^~\\&!");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setJMenuBar(createMenu());
		setTransferHandler(new FileTransferHandler(this));
		
		tabs.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked (MouseEvent e) {
				if (!e.isPopupTrigger() && e.getClickCount() >= 2) {
					System.out.println("mouse click " + e.getClickCount());
					addEditor();
				}
			}
			@Override
			public void mousePressed (MouseEvent e) {
				if (e.isPopupTrigger()) {
					popup(e.getPoint());
				}
			}
			@Override
			public void mouseReleased (MouseEvent e) {
				if (e.isPopupTrigger()) {
					popup(e.getPoint());
				}
			}
		});
		tabs.setTransferHandler(new FileTransferHandler(this));
		
		setContentPane(tabs);
		setPreferredSize(new Dimension(800, 600));
		pack();
	}
	
	private JMenuBar createMenu () {
		JMenu fontMenu = new JMenu("Font");
		{
			JMenuItem item = new JMenuItem("Font...");
			item.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed (ActionEvent e) {
					System.out.println("font");
					FontJDialog dialog = new FontJDialog(EditorJFrame.this, editorFont);
					dialog.setVisible(true);
					Font f = dialog.getSelectedFont();
					if (f != null) {
						setEditorFonts(f);
					}
				}
			});
			fontMenu.add(item);
		}
		
		JMenu fileMenu = new JMenu("File");
		{
			JMenuItem newItem = new JMenuItem("New");
			newItem.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed (ActionEvent e) {
					System.out.println("new");
					addEditor();
				}
			});
			
			JMenuItem openItem = new JMenuItem("Open...");
			openItem.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed (ActionEvent e) {
					openFile();
				}
			});
			
			JMenuItem reopenItem = new JMenuItem("Re-open");
			reopenItem.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed (ActionEvent e) {
					reopenFile();<commit_msg>font preference<commit_after>package hu;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.*;
import java.io.File;
import java.util.*;
import java.util.prefs.Preferences;

import javax.swing.*;

import jsui.JSJDialog;
import ca.uhn.hl7v2.model.Message;

/** main class and top level frame */
public class EditorJFrame extends JFrame {
	
	public static void main (String[] args) {
		System.out.println("user dir " + System.getProperty("user.dir"));
		EditorJFrame frame = new EditorJFrame();
		frame.setVisible(true);
		if (args.length == 0) {
			frame.addEditor();
		} else {
			for (String a : args) {
				frame.addFileEditor(new File(a));
			}
		}
	}
	
	private final JTabbedPane tabs = new JTabbedPane();
	
	private File dir = new File(System.getProperty("user.dir"));
	private Font editorFont;
	private String messageVersion = MsgUtil.HIGHEST_VERSION;
	private String js = "util.replace('A', 'B');";
	private String host = "localhost";
	private int port = 1000;
	
	public EditorJFrame () {
		super("HAPI HL7|^~\\&!");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setJMenuBar(createMenu());
		setTransferHandler(new FileTransferHandler(this));
		initComps();
		loadPrefs();
		setContentPane(tabs);
		setPreferredSize(new Dimension(800, 600));
		pack();
	}
	
	private void loadPrefs() {
		Preferences prefs = Preferences.userNodeForPackage(getClass());
		String fontName = prefs.get("font", "Monospaced");
		int fontSize = prefs.getInt("fontsize", 14);
		int fontStyle = prefs.getInt("fontstyle", 0);
		editorFont = new Font(fontName, fontStyle, fontSize);
	}
	
	private void savePrefs() {
		Preferences prefs = Preferences.userNodeForPackage(getClass());
		prefs.put("font", editorFont.getFontName());
		prefs.putInt("fontsize", editorFont.getSize());
		prefs.putInt("fontstyle", editorFont.getStyle());
		try {
			prefs.flush();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void initComps () {
		tabs.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked (MouseEvent e) {
				if (!e.isPopupTrigger() && e.getClickCount() >= 2) {
					System.out.println("mouse click " + e.getClickCount());
					addEditor();
				}
			}
			@Override
			public void mousePressed (MouseEvent e) {
				if (e.isPopupTrigger()) {
					popup(e.getPoint());
				}
			}
			@Override
			public void mouseReleased (MouseEvent e) {
				if (e.isPopupTrigger()) {
					popup(e.getPoint());
				}
			}
		});
		tabs.setTransferHandler(new FileTransferHandler(this));
	}
	
	private JMenuBar createMenu () {
		JMenu fontMenu = new JMenu("Font");
		{
			JMenuItem item = new JMenuItem("Font...");
			item.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed (ActionEvent e) {
					System.out.println("font");
					FontJDialog dialog = new FontJDialog(EditorJFrame.this, editorFont);
					dialog.setVisible(true);
					Font f = dialog.getSelectedFont();
					if (f != null) {
						setEditorFonts(f);
						savePrefs();
					}
				}
			});
			fontMenu.add(item);
		}
		
		JMenu fileMenu = new JMenu("File");
		{
			JMenuItem newItem = new JMenuItem("New");
			newItem.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed (ActionEvent e) {
					System.out.println("new");
					addEditor();
				}
			});
			
			JMenuItem openItem = new JMenuItem("Open...");
			openItem.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed (ActionEvent e) {
					openFile();
				}
			});
			
			JMenuItem reopenItem = new JMenuItem("Re-open");
			reopenItem.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed (ActionEvent e) {
					reopenFile();
{'fraction_non_alphanumeric': 0.13791071165463387, 'fraction_numerical': 0.005304258140562841, 'mean_word_length': 3.662087912087912, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5076399', 'n_tokens_mistral': 2616, 'n_tokens_neox': 2159, 'n_words': 485}