<commit_before>package org.cytoscape.browser.internal.view;

/*
 * #%L
 * Cytoscape Table Browser Impl (table-browser-impl)
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2010 - 2013 The Cytoscape Consortium
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 2.1 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */

import static javax.swing.GroupLayout.DEFAULT_SIZE;
import static javax.swing.GroupLayout.PREFERRED_SIZE;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.BreakIterator;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Stack;

import javax.swing.AbstractAction;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.cytoscape.browser.internal.util.TableBrowserUtil;
import org.cytoscape.equations.Equation;
import org.cytoscape.equations.EquationCompiler;
import org.cytoscape.equations.EquationParser;
import org.cytoscape.equations.EquationUtil;
import org.cytoscape.equations.Function;
import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyRow;
import org.cytoscape.model.CyTable;
import org.cytoscape.util.swing.LookAndFeelUtil;


enum ApplicationDomain {
	CURRENT_CELL("Current cell only"),      // The currently selected cell in the browser.
	CURRENT_SELECTION("Current selection"), // All entries in the browser.
	ENTIRE_ATTRIBUTE("Entire column");   // All values of the current attribute.

	private final String asString;
	
	ApplicationDomain(final String asString) { this.asString = asString; }
	@Override public String toString() { return asString; }
}


@SuppressWarnings("serial")
public class FormulaBuilderDialog extends JDialog {
	
	private static final String FUNC_SELECTION_MESSAGE = "Please select a function...";
	
	private JPanel functionPanel;
	private JPanel argumentPanel;
	private JPanel applyToPanel;
	private JList<Function> functionList;
	private JLabel infoLabel;
	private JLabel usageLabel;
	private JTextField formulaTextField;
	private JButton addButton1;
	private JButton addButton2;
	private JButton undoButton;
	private JComboBox<String> attribNamesComboBox;
	private JTextField constantValuesTextField;
	private JLabel applyToLabel;
	private JComboBox<ApplicationDomain> applyToComboBox;
	private JButton okButton;
	private JButton cancelButton;
	private Function function;
	private ArrayList<Class<?>> leadingArgs;
	private ApplicationDomain applicationDomain;
	private Stack<Integer> undoStack;
	private final EquationCompiler compiler;
	private final BrowserTable table;
	private final BrowserTableModel tableModel;
	private final String targetAttrName;

	public FormulaBuilderDialog(final EquationCompiler compiler, final BrowserTable table, final Frame parent,
			final String targetAttrName) {
		super(parent, "Create Function For: " + targetAttrName, ModalityType.APPLICATION_MODAL);

		this.compiler = compiler;
		this.table = table;
		this.tableModel = (BrowserTableModel) table.getModel();
		this.targetAttrName = targetAttrName;
		this.leadingArgs = new ArrayList<>();
		this.applicationDomain = ApplicationDomain.CURRENT_CELL;
		this.undoStack = new Stack<>();

		initComponents();
	}

	private void initComponents() {
		final JLabel fnIconLabel = new JLabel("f(x)");
		Font iconFont = null;
		
		try {
			iconFont = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/fonts/jsMath-cmti10.ttf"));
			iconFont = iconFont.deriveFont(36.0f);
			fnIconLabel.setFont(iconFont);
		} catch (Exception e) {
			throw new RuntimeException("Error loading font", e);
		}
		
		final JPanel buttonPanel = LookAndFeelUtil.createOkCancelPanel(getOkButton(), getCancelButton());
		
		final JPanel contents = new JPanel();<commit_msg>add help to formula dlog<commit_after>package org.cytoscape.browser.internal.view;

/*
 * #%L
 * Cytoscape Table Browser Impl (table-browser-impl)
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2010 - 2013 The Cytoscape Consortium
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 2.1 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */

import static javax.swing.GroupLayout.DEFAULT_SIZE;
import static javax.swing.GroupLayout.PREFERRED_SIZE;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.BreakIterator;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Stack;

import javax.swing.AbstractAction;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.cytoscape.browser.internal.util.TableBrowserUtil;
import org.cytoscape.equations.Equation;
import org.cytoscape.equations.EquationCompiler;
import org.cytoscape.equations.EquationParser;
import org.cytoscape.equations.EquationUtil;
import org.cytoscape.equations.Function;
import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyRow;
import org.cytoscape.model.CyTable;
import org.cytoscape.util.swing.LookAndFeelUtil;


enum ApplicationDomain {
	CURRENT_CELL("Current cell only"),      // The currently selected cell in the browser.
	CURRENT_SELECTION("Current selection"), // All entries in the browser.
	ENTIRE_ATTRIBUTE("Entire column");   // All values of the current attribute.

	private final String asString;
	
	ApplicationDomain(final String asString) { this.asString = asString; }
	@Override public String toString() { return asString; }
}


@SuppressWarnings("serial")
public class FormulaBuilderDialog extends JDialog {
	
	private static final String FUNC_SELECTION_MESSAGE = "Please select a function...";
	
	private JPanel functionPanel;
	private JPanel argumentPanel;
	private JPanel applyToPanel;
	private JList<Function> functionList;
	private JLabel infoLabel;
	private JLabel usageLabel;
	private JTextField formulaTextField;
	private JButton addButton1;
	private JButton addButton2;
	private JButton undoButton;
	private JComboBox<String> attribNamesComboBox;
	private JTextField constantValuesTextField;
	private JLabel applyToLabel;
	private JComboBox<ApplicationDomain> applyToComboBox;
	private JButton okButton;
	private JButton cancelButton;
	private Function function;
	private ArrayList<Class<?>> leadingArgs;
	private ApplicationDomain applicationDomain;
	private Stack<Integer> undoStack;
	private final EquationCompiler compiler;
	private final BrowserTable table;
	private final BrowserTableModel tableModel;
	private final String targetAttrName;

	public FormulaBuilderDialog(final EquationCompiler compiler, final BrowserTable table, final Frame parent,
			final String targetAttrName) {
		super(parent, "Create Function For: " + targetAttrName, ModalityType.APPLICATION_MODAL);

		this.compiler = compiler;
		this.table = table;
		this.tableModel = (BrowserTableModel) table.getModel();
		this.targetAttrName = targetAttrName;
		this.leadingArgs = new ArrayList<>();
		this.applicationDomain = ApplicationDomain.CURRENT_CELL;
		this.undoStack = new Stack<>();

		initComponents();
	}

	private void initComponents() {
		final JLabel fnIconLabel = new JLabel("f(x)");
		Font iconFont = null;
		
		try {
			iconFont = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/fonts/jsMath-cmti10.ttf"));
			iconFont = iconFont.deriveFont(36.0f);
			fnIconLabel.setFont(iconFont);
		} catch (Exception e) {
			throw new RuntimeException("Error loading font", e);
		}
		
		final JPanel buttonPanel = LookAndFeelUtil.createOkCancelPanel(getOkButton(), getCancelButton(), "Column_Data_Functions_and_Equations");
		
		final JPanel contents = new JPanel();
{'fraction_non_alphanumeric': 0.08935648235516135, 'fraction_numerical': 0.0035855821853179844, 'mean_word_length': 5.408101571946796, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2410113', 'n_tokens_mistral': 3184, 'n_tokens_neox': 3003, 'n_words': 870}