<commit_before>/*
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 * Created on Dec 1, 2004
 *
 */
package org.biojava.spice.gui;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.Box;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JRootPane;
import javax.swing.JTextField;

import org.biojava.spice.ResourceManager;
import org.biojava.spice.SPICEFrame;
import org.biojava.spice.SpiceApplication;
import org.biojava.spice.SpiceStartParameters;
import org.biojava.spice.config.SpiceDefaults;
import org.biojava.spice.gui.msdkeyword.*;

import javax.swing.JLabel;


/**
 * Enter a new PDB, UniProt, or ENSP code to be loaded in SPICE.
 * 
 * @author <NAME>
 *
 */
public class OpenDialog 
extends JDialog 
{

	private static final long serialVersionUID = 2832023723402743924L;

    public static Logger logger =  Logger.getLogger(SpiceDefaults.LOGGER);
    
	static int H_SIZE = 350;
	static int V_SIZE = 150 ;
	SpiceApplication spice       ;
	JTextField getCom      ;
	JComboBox  list        ;
	String     currentType ;
	JTextField kwsearch;     


	/** a dialog responsible for opening new entries.
	 * 
	 * @param parent the parent SpiceApplication instance
	 */
	public OpenDialog(SpiceApplication parent){
		// Calls the parent telling it this
		// dialog is modal(i.e true)


		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent evt) {
                
                Object o = evt.getSource();
                JFrame frame = null;
                if ( o instanceof JFrame) {
                
                     frame =  (JFrame) o;
                    
                } else if ( o instanceof JRootPane){
                    JRootPane root = (JRootPane)o;
                    frame = (JFrame) root.getTopLevelAncestor();
                }
                if ( frame != null){
                    frame.setVisible(false);
                    frame.dispose();
                }
			}
		});

		spice = parent ;

		this.setTitle("enter code") ;

		JPanel p = new JPanel();

		Box vBox  = Box.createVerticalBox();
		Box hBox1 = Box.createHorizontalBox();
		Box hBox2 = Box.createHorizontalBox();
		Box hBox3 = Box.createHorizontalBox();

		int startpos   = 0;
        
		currentType    = (String) SpiceDefaults.argumentTypes.get(startpos);
        // filter supported coords by startup arguments ...
        SpiceStartParameters params = spice.getSpiceStartParameters();
        String openDialogCoords = params.getOpenDialogCoords();
        
        String[] displayCoords = getOpenDialogCoords(openDialogCoords);
        
		list = new JComboBox(displayCoords) ;		
		list.setEditable(false);
		list.setMaximumSize(new Dimension(Short.MAX_VALUE,30));
		list.setSelectedIndex(startpos);

		list.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
			
				setHelpToolTip();     

			}        
		});



		hBox1.add(list);


		getCom = new JTextField(10);

        

		getCom.addActionListener(new ActionListener()  {

			public void actionPerformed(ActionEvent e) {

				String code = getCom.getText();
				String type = (String)list.getSelectedItem() ;

				type = getTypeCoordMapping(type,spice.getSpiceStartParameters());
				
				if ( SpiceDefaults.argumentTypes.contains(type) ) {
					spice.load(type,code);
					dispose();			    
				} else {
					System.out.println("unknown type " + type + " code " + code);
				}
			}
		});



		hBox1.add(getCom);


		JButton openB =new JButton(ResourceManager.getString("org.biojava.spice.action.open"));
		openB.addActionListener(new OpenActionListener(spice,this));

		JButton cancelB = new JButton(ResourceManager.getString("org.biojava.spice.action.cancel"));
		cancelB.addActionListener(new OpenActionListener(spice,this));

		hBox1.add(openB);
		hBox3.add(cancelB);
		setHelpToolTip();

		kwsearch = new JTextField(10);
		kwsearch.addActionListener(new ActionListener()  {
			public void actionPerformed(ActionEvent e) {
				String kw  = kwsearch.getText();            
				new MSDWindow(spice,kw);              
				dispose();			    
			}

		});

		JButton openKw = new JButton(ResourceManager.getString("org.biojava.spice.gui.ConfigPanel.Search"));
		openKw.addActionListener(new OpenActionListener(spice,this));
		JLabel kwl = new JLabel("keyword:");
		hBox2.add(kwl);
		hBox2.add(kwsearch);
		hBox2.add(openKw);


		vBox.add(hBox1);
		vBox.add(hBox2);
		vBox.add(hBox3);


		p.add(vBox);
		this.getContentPane().add(p);

		this.setSize(H_SIZE, V_SIZE);
        getCom.requestFocus();
	}

    /** smebody wants to restrict the "Open menu" coordiante systems.<commit_msg>nicer label of MSD keyword search<commit_after>/*
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 * Created on Dec 1, 2004
 *
 */
package org.biojava.spice.gui;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.Box;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JRootPane;
import javax.swing.JTextField;

import org.biojava.spice.ResourceManager;
import org.biojava.spice.SPICEFrame;
import org.biojava.spice.SpiceApplication;
import org.biojava.spice.SpiceStartParameters;
import org.biojava.spice.config.SpiceDefaults;
import org.biojava.spice.gui.msdkeyword.*;

import javax.swing.JLabel;


/**
 * Enter a new PDB, UniProt, or ENSP code to be loaded in SPICE.
 * 
 * @author <NAME>
 *
 */
public class OpenDialog 
extends JDialog 
{

	private static final long serialVersionUID = 2832023723402743924L;

    public static Logger logger =  Logger.getLogger(SpiceDefaults.LOGGER);
    
	static int H_SIZE = 350;
	static int V_SIZE = 150 ;
	SpiceApplication spice       ;
	JTextField getCom      ;
	JComboBox  list        ;
	String     currentType ;
	JTextField kwsearch;     


	/** a dialog responsible for opening new entries.
	 * 
	 * @param parent the parent SpiceApplication instance
	 */
	public OpenDialog(SpiceApplication parent){
		// Calls the parent telling it this
		// dialog is modal(i.e true)


		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent evt) {
                
                Object o = evt.getSource();
                JFrame frame = null;
                if ( o instanceof JFrame) {
                
                     frame =  (JFrame) o;
                    
                } else if ( o instanceof JRootPane){
                    JRootPane root = (JRootPane)o;
                    frame = (JFrame) root.getTopLevelAncestor();
                }
                if ( frame != null){
                    frame.setVisible(false);
                    frame.dispose();
                }
			}
		});

		spice = parent ;

		this.setTitle("enter code") ;

		JPanel p = new JPanel();

		Box vBox  = Box.createVerticalBox();
		Box hBox1 = Box.createHorizontalBox();
		Box hBox2 = Box.createHorizontalBox();
		Box hBox3 = Box.createHorizontalBox();

		int startpos   = 0;
        
		currentType    = (String) SpiceDefaults.argumentTypes.get(startpos);
        // filter supported coords by startup arguments ...
        SpiceStartParameters params = spice.getSpiceStartParameters();
        String openDialogCoords = params.getOpenDialogCoords();
        
        String[] displayCoords = getOpenDialogCoords(openDialogCoords);
        
		list = new JComboBox(displayCoords) ;		
		list.setEditable(false);
		list.setMaximumSize(new Dimension(Short.MAX_VALUE,30));
		list.setSelectedIndex(startpos);

		list.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
			
				setHelpToolTip();     

			}        
		});



		hBox1.add(list);


		getCom = new JTextField(10);

        

		getCom.addActionListener(new ActionListener()  {

			public void actionPerformed(ActionEvent e) {

				String code = getCom.getText();
				String type = (String)list.getSelectedItem() ;

				type = getTypeCoordMapping(type,spice.getSpiceStartParameters());
				
				if ( SpiceDefaults.argumentTypes.contains(type) ) {
					spice.load(type,code);
					dispose();			    
				} else {
					System.out.println("unknown type " + type + " code " + code);
				}
			}
		});



		hBox1.add(getCom);


		JButton openB =new JButton(ResourceManager.getString("org.biojava.spice.action.open"));
		openB.addActionListener(new OpenActionListener(spice,this));

		JButton cancelB = new JButton(ResourceManager.getString("org.biojava.spice.action.cancel"));
		cancelB.addActionListener(new OpenActionListener(spice,this));

		hBox1.add(openB);
		hBox3.add(cancelB);
		setHelpToolTip();

		kwsearch = new JTextField(10);
		kwsearch.addActionListener(new ActionListener()  {
			public void actionPerformed(ActionEvent e) {
				String kw  = kwsearch.getText();            
				new MSDWindow(spice,kw);              
				dispose();			    
			}

		});

		JButton openKw = new JButton(ResourceManager.getString("org.biojava.spice.gui.ConfigPanel.Search"));
		openKw.addActionListener(new OpenActionListener(spice,this));
		JLabel kwl = new JLabel("MSD keyword search:");
		hBox2.add(kwl);
		hBox2.add(kwsearch);
		hBox2.add(openKw);


		vBox.add(hBox1);
		vBox.add(hBox2);
		vBox.add(hBox3);


		p.add(vBox);
		this.getContentPane().add(p);

		this.setSize(H_SIZE, V_SIZE);
        getCom.requestFocus();
	}

    /** smebody wants to restrict the "Open menu" coordiante systems.
{'fraction_non_alphanumeric': 0.10526315789473684, 'fraction_numerical': 0.009271884374147804, 'mean_word_length': 2.8603508771929826, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '964806', 'n_tokens_mistral': 3760, 'n_tokens_neox': 3350, 'n_words': 780}