<commit_before>package org.openlca.app.editors.graphical.action;

import java.util.Objects;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.FormDialog;
import org.eclipse.ui.forms.IManagedForm;
import org.openlca.app.M;
import org.openlca.app.editors.graphical.GraphConfig;
import org.openlca.app.editors.graphical.GraphEditor;
import org.openlca.app.editors.graphical.themes.Themes;
import org.openlca.app.rcp.images.Icon;
import org.openlca.app.util.Controls;
import org.openlca.app.util.UI;

public class GraphSettingsAction extends Action {

	private final GraphEditor editor;

	public GraphSettingsAction(GraphEditor editor) {
		this.editor = editor;
		setId("GraphSettingsAction");
		setText(M.Settings);
		setImageDescriptor(Icon.PREFERENCES.descriptor());
	}

	@Override
	public void run() {
		if (editor == null)
			return;
		var config = GraphConfig.from(editor.config);
		if (new Dialog(config).open() == Window.OK) {
			config.applyOn(editor.config);
			editor.refresh();
			editor.setDirty();
			editor.getModel().figure.repaint();
		}
	}

	private static class Dialog extends FormDialog {

		private final GraphConfig config;

		Dialog(GraphConfig config) {
			super(UI.shell());
			setBlockOnOpen(true);
			this.config = config;
		}

		@Override
		protected void createFormContent(IManagedForm mform) {
			var tk = mform.getToolkit();
			var body = UI.formBody(mform.getForm(), tk);
			UI.gridLayout(body, 1);

			var icons = tk.createButton(body, "Show flow icons", SWT.CHECK);
			icons.setSelection(config.showFlowIcons);
			Controls.onSelect(icons,
					e -> config.showFlowIcons = icons.getSelection());

			var elems = tk.createButton(body, "Show elementary flows", SWT.CHECK);
			elems.setSelection(config.showElementaryFlows);
			Controls.onSelect(elems,
					e -> config.showElementaryFlows = elems.getSelection());

			var amounts = tk.createButton(body, "Show flow amounts", SWT.CHECK);
			amounts.setSelection(config.showFlowAmounts);
			Controls.onSelect(amounts,
					e -> config.showFlowAmounts = amounts.getSelection());

			// theme combo
			var comp = tk.createComposite(body);
			UI.gridLayout(comp, 2, 10, 0);
			var themeCombo = UI.formCombo(comp, tk, "Theme");
			var themes = Themes.all();
			var current = config.theme();
			int currentIdx = 0;
			for (int i = 0; i < themes.length; i++) {
				var theme = themes[i];
				themeCombo.add(theme.label());
				if (Objects.equals(theme.id(), current.id())) {
					currentIdx = i;
				}
			}
			themeCombo.select(currentIdx);
			Controls.onSelect(themeCombo, _e -> {
				var next = themes[themeCombo.getSelectionIndex()];
				config.theme(next);
			});
		}

		@Override
		protected Point getInitialSize() {
			var shell = getShell().getDisplay().getBounds();
			int width = shell.x > 0 && shell.x < 600
					? shell.x
					: 600;
			int height = shell.y > 0 && shell.y < 350
					? shell.y
					: 350;
			return new Point(width, height);
		}

		@Override
		protected void configureShell(Shell newShell) {
			super.configureShell(newShell);
			newShell.setText(M.Settings);
		}
	}
}
<commit_msg>make the graph settings dialog a bit nicer<commit_after>package org.openlca.app.editors.graphical.action;

import java.util.Objects;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.FormDialog;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.openlca.app.M;
import org.openlca.app.editors.graphical.GraphConfig;
import org.openlca.app.editors.graphical.GraphEditor;
import org.openlca.app.editors.graphical.themes.Themes;
import org.openlca.app.rcp.images.Icon;
import org.openlca.app.util.Controls;
import org.openlca.app.util.UI;

public class GraphSettingsAction extends Action {

	private final GraphEditor editor;

	public GraphSettingsAction(GraphEditor editor) {
		this.editor = editor;
		setId("GraphSettingsAction");
		setText(M.Settings);
		setImageDescriptor(Icon.PREFERENCES.descriptor());
	}

	@Override
	public void run() {
		if (editor == null)
			return;
		var config = GraphConfig.from(editor.config);
		if (new Dialog(config).open() == Window.OK) {
			config.applyOn(editor.config);
			editor.refresh();
			editor.setDirty();
			editor.getModel().figure.repaint();
		}
	}

	private static class Dialog extends FormDialog {

		private final GraphConfig config;

		Dialog(GraphConfig config) {
			super(UI.shell());
			setBlockOnOpen(true);
			this.config = config;
		}

		@Override
		protected void createFormContent(IManagedForm mform) {
			var tk = mform.getToolkit();
			var body = UI.formBody(mform.getForm(), tk);
			UI.gridLayout(body, 2);
			themeCombo(tk, body);

			// show icons
			UI.filler(body, tk);
			var icons = tk.createButton(body, "Show flow icons", SWT.CHECK);
			icons.setSelection(config.showFlowIcons);
			Controls.onSelect(icons,
					e -> config.showFlowIcons = icons.getSelection());

			// show elementary flows
			UI.filler(body, tk);
			var elems = tk.createButton(body, "Show elementary flows", SWT.CHECK);
			elems.setSelection(config.showElementaryFlows);
			Controls.onSelect(elems,
					e -> config.showElementaryFlows = elems.getSelection());

			// show amounts
			UI.filler(body, tk);
			var amounts = tk.createButton(body, "Show flow amounts", SWT.CHECK);
			amounts.setSelection(config.showFlowAmounts);
			Controls.onSelect(amounts,
					e -> config.showFlowAmounts = amounts.getSelection());
		}

		private void themeCombo(FormToolkit tk, Composite comp) {
			var combo = UI.formCombo(comp, tk, "Theme");
			UI.gridData(combo, true, false);
			var themes = Themes.all();
			var current = config.theme();
			int currentIdx = 0;
			for (int i = 0; i < themes.length; i++) {
				var theme = themes[i];
				combo.add(theme.label());
				if (Objects.equals(theme.id(), current.id())) {
					currentIdx = i;
				}
			}
			combo.select(currentIdx);
			Controls.onSelect(combo, _e -> {
				var next = themes[combo.getSelectionIndex()];
				config.theme(next);
			});
		}

		@Override
		protected Point getInitialSize() {
			var shell = getShell().getDisplay().getBounds();
			int width = shell.x > 0 && shell.x < 600
					? shell.x
					: 600;
			int height = shell.y > 0 && shell.y < 350
					? shell.y
					: 350;
			return new Point(width, height);
		}

		@Override
		protected void configureShell(Shell newShell) {
			super.configureShell(newShell);
			newShell.setText(M.Settings);
		}
	}
}

{'fraction_non_alphanumeric': 0.1341138114997036, 'fraction_numerical': 0.005631298162418494, 'mean_word_length': 3.8694083694083696, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '682255', 'n_tokens_mistral': 2611, 'n_tokens_neox': 2239, 'n_words': 454}