<commit_before>// PathVisio,
// a tool for data visualization and analysis using Biological Pathways
// Copyright 2006-2007 BiGCaT Bioinformatics
//
// Licensed under the Apache License, Version 2.0 (the "License"); 
// you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at 
// 
// http://www.apache.org/licenses/LICENSE-2.0 
//  
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
// See the License for the specific language governing permissions and 
// limitations under the License.
//
package org.pathvisio.gui.swing;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.UIManager;

import org.pathvisio.Engine;
import org.pathvisio.Globals;
import org.pathvisio.debug.Logger;
import org.pathvisio.plugin.PluginManager;
import org.pathvisio.preferences.GlobalPreference;
import org.pathvisio.preferences.PreferenceManager;

/**
 * Main class for the Swing GUI. This class creates and shows the GUI.
 * Subclasses may override {@link #createAndShowGUI(MainPanel)} to perform custom
 * actions before showing the GUI.
 * @author thomas
 *
 */
public class GuiMain 
{
	private JFrame frame;
	protected MainPanelStandalone mainPanel;
	
	private void initLog()
	{
		String logDest = Engine.getCurrent().getPreferences().get(GlobalPreference.FILE_LOG);
		Logger.log.setDest (logDest);		
		Logger.log.setLogLevel(true, true, true, true, true, true);//Modify this to adjust log level
	}

	// plugin files specified at command line
	private List<File> pluginFiles = new ArrayList<File>();
	
	// pathway specified at command line
	private URL pathwayUrl = null;
	private File pgexFile = null;

	public void parseArgs(String [] args)
	{
		
		for(int i = 0; i < args.length - 1; i++) 
		{
			if("-p".equals(args[i])) 
			{
				pluginFiles.add(new File(args[i + 1]));
				i++;
			}
			else if ("-d".equals(args[i]))
			{
				pgexFile = new File(args[i + 1]);
				i++;
			}
			else if ("-o".equals(args[i])) 
			{
				String pws = args[i + 1];
				try {
					File f = new File(pws);
					//Assume the argument is a file
					if(f.exists()) {
						pathwayUrl = f.toURI().toURL();
					//If it doesn't exist, assume it's an url
					} else {
						pathwayUrl = new URL(pws);
					}
				} catch(MalformedURLException e) {
					printHelp();
					System.exit(-1);
				}
				i++;
			}
		}
	}
	
	/**
	 * Act upon the command line arguments
	 */
	public void processOptions()
	{
		//Create a plugin manager that loads the plugins
		if(pluginFiles.size() > 0) {
			PluginManager pluginManager = new PluginManager(
					pluginFiles.toArray(new File[0])
			);
		}
		
		if(pathwayUrl != null) {
			SwingEngine.getCurrent().openPathway(pathwayUrl);
		}
	
		if (pgexFile != null)
		{
			//TODO ask swingengine to open pgex directly
		}
	}
	
	/**
	 * Creates and shows the GUI. Creates and shows the Frame, sets the size, title and menubar.
	 * @param mainPanel The main panel to show in the frame<commit_msg>Option to specify pgex from the command line<commit_after>// PathVisio,
// a tool for data visualization and analysis using Biological Pathways
// Copyright 2006-2007 BiGCaT Bioinformatics
//
// Licensed under the Apache License, Version 2.0 (the "License"); 
// you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at 
// 
// http://www.apache.org/licenses/LICENSE-2.0 
//  
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
// See the License for the specific language governing permissions and 
// limitations under the License.
//
package org.pathvisio.gui.swing;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.UIManager;

import org.pathvisio.Engine;
import org.pathvisio.Globals;
import org.pathvisio.data.DataException;
import org.pathvisio.data.GexManager;
import org.pathvisio.data.SimpleGex;
import org.pathvisio.debug.Logger;
import org.pathvisio.plugin.PluginManager;
import org.pathvisio.preferences.GlobalPreference;
import org.pathvisio.preferences.PreferenceManager;

/**
 * Main class for the Swing GUI. This class creates and shows the GUI.
 * Subclasses may override {@link #createAndShowGUI(MainPanel)} to perform custom
 * actions before showing the GUI.
 * @author thomas
 *
 */
public class GuiMain 
{
	private JFrame frame;
	protected MainPanelStandalone mainPanel;
	
	private void initLog()
	{
		String logDest = Engine.getCurrent().getPreferences().get(GlobalPreference.FILE_LOG);
		Logger.log.setDest (logDest);		
		Logger.log.setLogLevel(true, true, true, true, true, true);//Modify this to adjust log level
	}

	// plugin files specified at command line
	private List<File> pluginFiles = new ArrayList<File>();
	
	// pathway specified at command line
	private URL pathwayUrl = null;
	private String pgexFile = null;

	public void parseArgs(String [] args)
	{
		
		for(int i = 0; i < args.length - 1; i++) 
		{
			if("-p".equals(args[i])) 
			{
				pluginFiles.add(new File(args[i + 1]));
				i++;
			}
			else if ("-d".equals(args[i]))
			{
				pgexFile = args[i + 1];
				if (!new File(pgexFile).exists())
				{
					printHelp();
					System.exit(-1);
				}
				i++;
			}
			else if ("-o".equals(args[i])) 
			{
				String pws = args[i + 1];
				try {
					File f = new File(pws);
					//Assume the argument is a file
					if(f.exists()) {
						pathwayUrl = f.toURI().toURL();
					//If it doesn't exist, assume it's an url
					} else {
						pathwayUrl = new URL(pws);
					}
				} catch(MalformedURLException e) {
					printHelp();
					System.exit(-1);
				}
				i++;
			}
		}
	}
	
	/**
	 * Act upon the command line arguments
	 */
	public void processOptions()
	{
		//Create a plugin manager that loads the plugins
		if(pluginFiles.size() > 0) {
			PluginManager pluginManager = new PluginManager(
					pluginFiles.toArray(new File[0])
			);
		}
		
		if(pathwayUrl != null) {
			SwingEngine.getCurrent().openPathway(pathwayUrl);
		}
	
		if (pgexFile != null)
		{
			try
			{
				GexManager.setCurrentGex(pgexFile, false);
				SwingEngine.getCurrent().loadGexCache();
				Logger.log.info ("Loaded pgex " + pgexFile);
			}
			catch (DataException e)
			{
				Logger.log.error ("Couldn't open pgex " + pgexFile, e);
			}
		}
	}
	
	/**
	 * Creates and shows the GUI. Creates and shows the Frame, sets the size, title and menubar.
	 * @param mainPanel The main panel to show in the frame
{'fraction_non_alphanumeric': 0.11596257442585767, 'fraction_numerical': 0.005812305075134676, 'mean_word_length': 3.25, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '362758', 'n_tokens_mistral': 2560, 'n_tokens_neox': 2204, 'n_words': 690}