<commit_before>package org.reldb.dbrowser.ui.html;

import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;

import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultCaret;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;

import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

public class BrowserSwing implements HtmlBrowser {

	private BrowserSwingWidget browserPanel;
	private JTextPane browser;
	private Style style;
	private StringBuffer text;

	private void setEnhancedOutputStyle(JTextPane pane) {
		pane.setContentType("text/html");
		pane.setEditable(false);
		pane.setEnabled(true);
		HTMLEditorKit editorKit = new HTMLEditorKit();
		HTMLDocument defaultDocument = (HTMLDocument) editorKit.createDefaultDocument();
		pane.setEditorKit(editorKit);
		pane.setDocument(defaultDocument);
		StyleSheet css = editorKit.getStyleSheet();
		for (String entry : style.getFormattedStyle())
			css.addRule(entry);
	}

	@Override
	public boolean createWidget(Composite parent) {
		browserPanel = new BrowserSwingWidget(parent);
		Frame frame = SWT_AWT.new_Frame(browserPanel);

		style = new Style(0);

		Panel root = new Panel();
		root.setLayout(new GridLayout());
		
		browser = new JTextPane();
		KeyListener[] listeners = browser.getKeyListeners();
		for (KeyListener listener: listeners)
			browser.removeKeyListener(listener);
		browser.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
				if (!(e.getKeyCode() == KeyEvent.VK_C))
					return;
				if (!(e.getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()))
					return;
				e.consume();
				browserPanel.getDisplay().asyncExec(new Runnable() {
					@Override
					public void run() {<commit_msg>Experimental scaling for Swing-based browser.<commit_after>package org.reldb.dbrowser.ui.html;

import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;

import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultCaret;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;

import org.eclipse.jface.util.Util;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;

public class BrowserSwing implements HtmlBrowser {

	private BrowserSwingWidget browserPanel;
	private JTextPane browser;
	private Style style;
	private StringBuffer text;

	private void setEnhancedOutputStyle(JTextPane pane) {
		pane.setContentType("text/html");
		pane.setEditable(false);
		pane.setEnabled(true);
		HTMLEditorKit editorKit = new HTMLEditorKit();
		HTMLDocument defaultDocument = (HTMLDocument) editorKit.createDefaultDocument();
		pane.setEditorKit(editorKit);
		pane.setDocument(defaultDocument);
		StyleSheet css = editorKit.getStyleSheet();
		for (String entry : style.getFormattedStyle())
			css.addRule(entry);
	}

	@Override
	public boolean createWidget(Composite parent) {
		browserPanel = new BrowserSwingWidget(parent);
		Frame frame = SWT_AWT.new_Frame(browserPanel);

		if (Util.isWin32())
			style = new Style((int)(14 * ((double)Display.getCurrent().getDPI().x / 96.0)));
		else
			style = new Style(0);

		Panel root = new Panel();
		root.setLayout(new GridLayout());
		
		browser = new JTextPane();
		KeyListener[] listeners = browser.getKeyListeners();
		for (KeyListener listener: listeners)
			browser.removeKeyListener(listener);
		browser.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
				if (!(e.getKeyCode() == KeyEvent.VK_C))
					return;
				if (!(e.getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()))
					return;
				e.consume();
				browserPanel.getDisplay().asyncExec(new Runnable() {
					@Override
					public void run() {
{'fraction_non_alphanumeric': 0.11519386834986474, 'fraction_numerical': 0.0020288548241659153, 'mean_word_length': 5.196927374301676, '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': '3222595', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1393, 'n_words': 282}