<commit_before>/**
 * ***************************************************************
 * Agent.GUI is a framework to develop Multi-agent based simulation 
 * applications based on the JADE - Framework in compliance with the 
 * FIPA specifications. 
 * Copyright (C) 2010 <NAME> and DAWIS
 * http://www.dawis.wiwi.uni-due.de
 * http://sourceforge.net/projects/agentgui/
 * http://www.agentgui.org 
 *
 * GNU Lesser General Public License
 *
 * This library 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,
 * version 2.1 of the License.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 * **************************************************************
 */
package agentgui.core.gui.projectwindow.simsetup;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collections;
import java.util.Iterator;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JToolBar;

import agentgui.core.application.Application;
import agentgui.core.application.Language;
import agentgui.core.project.Project;
import agentgui.core.sim.setup.SimulationSetup;
import agentgui.core.sim.setup.SimulationSetups;
import agentgui.core.sim.setup.SimulationSetupsChangeNotification;

/**
 * The Class SetupSelectorToolbar is used in the main toolbar of the application
 * and manages different simulation setups for a current project.
 * 
 * @author <NAME> - DAWIS - ICB - University of Duisburg - Essen
 */
public class SetupSelectorToolbar implements ActionListener {

	private final String pathImage = Application.RunInfo.PathImageIntern();
	
	private final Integer SETUP_add = 1;
	private final Integer SETUP_rename = 2;
	private final Integer SETUP_copy = 3;
	
	private Project currProject = null;
	private SimulationSetup currSimSetup = null;
	
	private MyObserver myProjectMyObserver = null;
	private JToolBar jToolBar2Add2 = null;
	
	private JLabel jLabelSetupSelector = null;
	private JComboBox jComboBoxSetupSelector = null;
	private DefaultComboBoxModel jComboBoxModel4Setups = new DefaultComboBoxModel(); 
	
	private JButton jButtonSetupRename = null;
	private JButton jButtonSetupCopy = null;
	private JButton jButtonSetupNew = null;
	private JButton jButtonSetupDelete = null;
	
	
	/**
	 * Instantiates a new setup selector toolbar.
	 * @param jToolBar2Add2 the JToolBar, on which the elements of this class are added
	 */
	public SetupSelectorToolbar(JToolBar jToolBar2Add2) {
		this.jToolBar2Add2 = jToolBar2Add2;
		this.initialize();
	}
	
	/**
	 * Initialize.
	 */
	private void initialize() {
		
		this.jToolBar2Add2.add(this.getJLabel4SetupSelection());
		this.jToolBar2Add2.add(this.getJComboBoxSetupSelector());
		
		this.jToolBar2Add2.add(this.getJButtonSetupRename());
		this.jToolBar2Add2.add(this.getJButtonSetupCopy());
		this.jToolBar2Add2.add(this.getJButtonSetupNew());
		this.jToolBar2Add2.add(this.getJButtonSetupDelete());
		
		
		// --- bersetzungen laden ------------------------
		this.jComboBoxSetupSelector.setToolTipText(Language.translate("Setup auswhlen"));
		this.jButtonSetupRename.setToolTipText(Language.translate("Setup umbenennen"));
		this.jButtonSetupCopy.setToolTipText(Language.translate("Setup kopieren"));
		this.jButtonSetupNew.setToolTipText(Language.translate("Setup hinzufgen"));
		this.jButtonSetupDelete.setToolTipText(Language.translate("Setup lschen"));
		
		this.setEnabled(false);
		
	}
	
	/**
	 * Sets the project.
	 * @param project the new project
	 */
	public void setProject(Project project) {
		
		if (project==null) {
			this.setEnabled(false);
			this.myProjectMyObserver = null;
			this.currProject = null;
			this.jComboBoxSetupSelector.removeActionListener(this);
			this.jComboBoxModel4Setups.removeAllElements();
			
		} else {
			this.setEnabled(true);
			if (project!=this.currProject) {
				this.myProjectMyObserver = null;
				this.myProjectMyObserver = new MyObserver();
				this.currProject = project;
				this.currProject.addObserver(this.myProjectMyObserver);
				this.setupLoad();
			}
		}
	}
	
	/**
	 * Sets the enabled.
	 * @param enable the new enabled
	 */
	public void setEnabled(boolean enable) {
		
		this.jLabelSetupSelector.setEnabled(enable);
		this.jComboBoxSetupSelector.setEnabled(enable);
		this.jButtonSetupRename.setEnabled(enable);
		this.jButtonSetupCopy.setEnabled(enable);
		this.jButtonSetupNew.setEnabled(enable);
		this.jButtonSetupDelete.setEnabled(enable);
		
	}
	
	/**
	 * Gets the JLabel for the setup selection.
	 * @return the JLabel for the setup selection
	 */
	private JLabel getJLabel4SetupSelection() {
		if (jLabelSetupSelector==null){
			jLabelSetupSelector = new JLabel();
			jLabelSetupSelector.setText(" Setup:  ");
			jLabelSetupSelector.setFont(new Font("Dialog", Font.BOLD, 12));	
		}
		return jLabelSetupSelector;
	}
	/**
	 * This method initialises jComboBoxSetupSelector	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBoxSetupSelector() {
		if (jComboBoxSetupSelector == null) {
			jComboBoxSetupSelector = new JComboBox(jComboBoxModel4Setups);
			jComboBoxSetupSelector.setToolTipText("Setup auswhlen");
			jComboBoxSetupSelector.setPreferredSize(new Dimension(200, 26));
			jComboBoxSetupSelector.addActionListener(this);
		}
		return jComboBoxSetupSelector;
	}
	/**
	 * This method initialises jButtonSetupRename	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonSetupRename() {
		if (jButtonSetupRename == null) {
			jButtonSetupRename = new JButton();
			jButtonSetupRename.setPreferredSize(new Dimension(26, 26));
			jButtonSetupRename.setIcon(new ImageIcon(getClass().getResource(pathImage + "Rename.gif")));
			jButtonSetupRename.setToolTipText("Setup umbenennen");
			jButtonSetupRename.addActionListener(this);

		}
		return jButtonSetupRename;
	}
	
	/**
	 * This method initialises jButtonSetupCopy	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonSetupCopy() {
		if (jButtonSetupCopy == null) {
			jButtonSetupCopy = new JButton();
			jButtonSetupCopy.setPreferredSize(new Dimension(26, 26));
			jButtonSetupCopy.setIcon(new ImageIcon(getClass().getResource(pathImage + "Copy.png")));
			jButtonSetupCopy.setToolTipText("Setup kopieren");<commit_msg>Extended the maximum row number of the setup selector<commit_after>/**
 * ***************************************************************
 * Agent.GUI is a framework to develop Multi-agent based simulation 
 * applications based on the JADE - Framework in compliance with the 
 * FIPA specifications. 
 * Copyright (C) 2010 <NAME> and DAWIS
 * http://www.dawis.wiwi.uni-due.de
 * http://sourceforge.net/projects/agentgui/
 * http://www.agentgui.org 
 *
 * GNU Lesser General Public License
 *
 * This library 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,
 * version 2.1 of the License.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 * **************************************************************
 */
package agentgui.core.gui.projectwindow.simsetup;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collections;
import java.util.Iterator;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JToolBar;

import agentgui.core.application.Application;
import agentgui.core.application.Language;
import agentgui.core.project.Project;
import agentgui.core.sim.setup.SimulationSetup;
import agentgui.core.sim.setup.SimulationSetups;
import agentgui.core.sim.setup.SimulationSetupsChangeNotification;

/**
 * The Class SetupSelectorToolbar is used in the main toolbar of the application
 * and manages different simulation setups for a current project.
 * 
 * @author <NAME> - DAWIS - ICB - University of Duisburg - Essen
 */
public class SetupSelectorToolbar implements ActionListener {

	private final String pathImage = Application.RunInfo.PathImageIntern();
	
	private final Integer SETUP_add = 1;
	private final Integer SETUP_rename = 2;
	private final Integer SETUP_copy = 3;
	
	private Project currProject = null;
	private SimulationSetup currSimSetup = null;
	
	private MyObserver myProjectMyObserver = null;
	private JToolBar jToolBar2Add2 = null;
	
	private JLabel jLabelSetupSelector = null;
	private JComboBox jComboBoxSetupSelector = null;
	private DefaultComboBoxModel jComboBoxModel4Setups = new DefaultComboBoxModel(); 
	
	private JButton jButtonSetupRename = null;
	private JButton jButtonSetupCopy = null;
	private JButton jButtonSetupNew = null;
	private JButton jButtonSetupDelete = null;
	
	
	/**
	 * Instantiates a new setup selector toolbar.
	 * @param jToolBar2Add2 the JToolBar, on which the elements of this class are added
	 */
	public SetupSelectorToolbar(JToolBar jToolBar2Add2) {
		this.jToolBar2Add2 = jToolBar2Add2;
		this.initialize();
	}
	
	/**
	 * Initialize.
	 */
	private void initialize() {
		
		this.jToolBar2Add2.add(this.getJLabel4SetupSelection());
		this.jToolBar2Add2.add(this.getJComboBoxSetupSelector());
		
		this.jToolBar2Add2.add(this.getJButtonSetupRename());
		this.jToolBar2Add2.add(this.getJButtonSetupCopy());
		this.jToolBar2Add2.add(this.getJButtonSetupNew());
		this.jToolBar2Add2.add(this.getJButtonSetupDelete());
		
		
		// --- bersetzungen laden ------------------------
		this.jComboBoxSetupSelector.setToolTipText(Language.translate("Setup auswhlen"));
		this.jButtonSetupRename.setToolTipText(Language.translate("Setup umbenennen"));
		this.jButtonSetupCopy.setToolTipText(Language.translate("Setup kopieren"));
		this.jButtonSetupNew.setToolTipText(Language.translate("Setup hinzufgen"));
		this.jButtonSetupDelete.setToolTipText(Language.translate("Setup lschen"));
		
		this.setEnabled(false);
		
	}
	
	/**
	 * Sets the project.
	 * @param project the new project
	 */
	public void setProject(Project project) {
		
		if (project==null) {
			this.setEnabled(false);
			this.myProjectMyObserver = null;
			this.currProject = null;
			this.jComboBoxSetupSelector.removeActionListener(this);
			this.jComboBoxModel4Setups.removeAllElements();
			
		} else {
			this.setEnabled(true);
			if (project!=this.currProject) {
				this.myProjectMyObserver = null;
				this.myProjectMyObserver = new MyObserver();
				this.currProject = project;
				this.currProject.addObserver(this.myProjectMyObserver);
				this.setupLoad();
			}
		}
	}
	
	/**
	 * Sets the enabled.
	 * @param enable the new enabled
	 */
	public void setEnabled(boolean enable) {
		
		this.jLabelSetupSelector.setEnabled(enable);
		this.jComboBoxSetupSelector.setEnabled(enable);
		this.jButtonSetupRename.setEnabled(enable);
		this.jButtonSetupCopy.setEnabled(enable);
		this.jButtonSetupNew.setEnabled(enable);
		this.jButtonSetupDelete.setEnabled(enable);
		
	}
	
	/**
	 * Gets the JLabel for the setup selection.
	 * @return the JLabel for the setup selection
	 */
	private JLabel getJLabel4SetupSelection() {
		if (jLabelSetupSelector==null){
			jLabelSetupSelector = new JLabel();
			jLabelSetupSelector.setText(" Setup:  ");
			jLabelSetupSelector.setFont(new Font("Dialog", Font.BOLD, 12));	
		}
		return jLabelSetupSelector;
	}
	/**
	 * This method initialises jComboBoxSetupSelector	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBoxSetupSelector() {
		if (jComboBoxSetupSelector == null) {
			jComboBoxSetupSelector = new JComboBox(jComboBoxModel4Setups);
			jComboBoxSetupSelector.setToolTipText("Setup auswhlen");
			jComboBoxSetupSelector.setMaximumRowCount(18);
			jComboBoxSetupSelector.setPreferredSize(new Dimension(200, 26));
			jComboBoxSetupSelector.addActionListener(this);
		}
		return jComboBoxSetupSelector;
	}
	/**
	 * This method initialises jButtonSetupRename	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonSetupRename() {
		if (jButtonSetupRename == null) {
			jButtonSetupRename = new JButton();
			jButtonSetupRename.setPreferredSize(new Dimension(26, 26));
			jButtonSetupRename.setIcon(new ImageIcon(getClass().getResource(pathImage + "Rename.gif")));
			jButtonSetupRename.setToolTipText("Setup umbenennen");
			jButtonSetupRename.addActionListener(this);

		}
		return jButtonSetupRename;
	}
	
	/**
	 * This method initialises jButtonSetupCopy	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonSetupCopy() {
		if (jButtonSetupCopy == null) {
			jButtonSetupCopy = new JButton();
			jButtonSetupCopy.setPreferredSize(new Dimension(26, 26));
			jButtonSetupCopy.setIcon(new ImageIcon(getClass().getResource(pathImage + "Copy.png")));
			jButtonSetupCopy.setToolTipText("Setup kopieren");
{'fraction_non_alphanumeric': 0.11584932480454868, 'fraction_numerical': 0.009381663113006396, 'mean_word_length': 4.7620802620802625, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '7488829', 'n_tokens_mistral': 4535, 'n_tokens_neox': 4117, 'n_words': 990}