<commit_before>/*
 *  Copyright (C) 2004  The Concord Consortium, Inc.,
 *  10 Concord Crossing, Concord, MA 01742
 *
 *  Web Site: http://www.concord.org
 *  Email: <EMAIL>
 *
 *  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; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  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
 *
 * END LICENSE */

/*
 * Created on Apr 4, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.concord.datagraph.state;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.geom.Point2D;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.EventObject;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.concord.data.Unit;
import org.concord.data.state.OTDataProducer;
import org.concord.data.ui.DataStoreLabel;
import org.concord.data.ui.StartableToolBar;
import org.concord.datagraph.engine.ControllableDataGraphable;
import org.concord.datagraph.engine.DataGraphable;
import org.concord.datagraph.log.LogHelper;
import org.concord.datagraph.log.OTEventLog;
import org.concord.datagraph.ui.DataAnnotation;
import org.concord.datagraph.ui.DataGraph;
import org.concord.datagraph.ui.DataGraphToolbar;
import org.concord.datagraph.ui.DataPointLabel;
import org.concord.datagraph.ui.SingleDataAxisGrid;
import org.concord.framework.data.DataDimension;
import org.concord.framework.data.stream.DataProducer;
import org.concord.framework.otrunk.OTChangeEvent;
import org.concord.framework.otrunk.OTChangeListener;
import org.concord.framework.otrunk.OTControllerService;
import org.concord.framework.otrunk.OTObject;
import org.concord.framework.otrunk.OTObjectList;
import org.concord.framework.otrunk.OTObjectService;
import org.concord.framework.otrunk.OTResourceMap;
import org.concord.framework.otrunk.OTrunk;
import org.concord.framework.otrunk.view.OTControllerServiceFactory;
import org.concord.framework.otrunk.view.OTJComponentViewContext;
import org.concord.framework.otrunk.view.OTViewContext;
import org.concord.framework.startable.Startable;
import org.concord.framework.startable.StartableEvent;
import org.concord.framework.startable.StartableListener;
import org.concord.framework.util.CheckedColorTreeModel;
import org.concord.framework.util.Copyable;
import org.concord.graph.engine.CoordinateSystem;
import org.concord.graph.engine.Drawable;
import org.concord.graph.engine.Graphable;
import org.concord.graph.engine.GraphableList;
import org.concord.graph.engine.SelectableList;
import org.concord.graph.event.GraphableListListener;
import org.concord.graph.examples.GraphWindowToolBar;
import org.concord.graph.ui.GraphTreeView;
import org.concord.graph.ui.Grid2D;
import org.concord.graph.ui.SingleAxisGrid;
import org.concord.view.CheckedColorTreeControler;

/**
 * @author scott
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class DataGraphManager implements OTChangeListener, ChangeListener,
		CheckedColorTreeModel {
	private static final Logger logger = Logger
			.getLogger(DataGraphManager.class.getCanonicalName());
	
	OTDataCollector otDataCollector;
	OTDataGraph otDataGraph;
	DataGraph dataGraph;

	DataGraphable sourceGraphable;
	DataStoreLabel valueLabel;

	OTObjectList labels;
	SelectableList notesLayer;

	OTDataAxis xOTAxis;
	OTDataAxis yOTAxis;
	
	OTDataAxis authoredXOTAxis;
	OTDataAxis authoredYOTAxis;

	JPanel bottomPanel;
	StartableToolBar toolBar = null;

	boolean isCausingOTChange = false;
	boolean isCausingRealObjChange = false;
	
	boolean instantRestart = false;				//sets whether start button is enabled after stop

	boolean showDataControls;

	Color[] colors = { Color.BLUE, Color.CYAN, Color.GRAY, Color.GREEN,
			Color.MAGENTA, Color.ORANGE, Color.PINK, Color.RED, Color.YELLOW,
			Color.BLACK };

	protected OTControllerService controllerService;
	private OTViewContext viewContext;
	private OTJComponentViewContext jComponentViewContext;
	private KeyEventDispatcher treeDispatcher;
	private DataGraphManagerStartable startable;
	private StartableListener listener;
	private OTrunk otrunk;

	/**
	 * @param serviceProvider
	 * @param jComponentViewContext
	 *            TODO
	 * 
	 */
	public DataGraphManager(OTDataGraph pfObject,
			OTViewContext serviceProvider, boolean showDataControls,
			OTJComponentViewContext jComponentViewContext) {
		this.otDataGraph = pfObject;
		if (pfObject instanceof OTDataCollector) {
			otDataCollector = (OTDataCollector) pfObject;
		}
		this.showDataControls = showDataControls;
		this.viewContext = serviceProvider;
		this.jComponentViewContext = jComponentViewContext;

		this.listener = new StartableListener(){
			public void startableEvent(StartableEvent event) {
				if(startable != null){
					startable.relayEvent(event);
				}
			}					
		};
		
		initialize();
		
		if (otDataCollector != null) {
			final OTEventLog log = (OTEventLog) otDataCollector.getEventLog();
			if (log != null && startable != null) {
				startable.addStartableListener(new StartableListener() {<commit_msg>Bugfix: create eventLog early, not when presenting the view<commit_after>/*
 *  Copyright (C) 2004  The Concord Consortium, Inc.,
 *  10 Concord Crossing, Concord, MA 01742
 *
 *  Web Site: http://www.concord.org
 *  Email: <EMAIL>
 *
 *  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; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  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
 *
 * END LICENSE */

/*
 * Created on Apr 4, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.concord.datagraph.state;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.geom.Point2D;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.EventObject;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.concord.data.Unit;
import org.concord.data.state.OTDataProducer;
import org.concord.data.ui.DataStoreLabel;
import org.concord.data.ui.StartableToolBar;
import org.concord.datagraph.engine.ControllableDataGraphable;
import org.concord.datagraph.engine.DataGraphable;
import org.concord.datagraph.log.LogHelper;
import org.concord.datagraph.log.OTEventLog;
import org.concord.datagraph.ui.DataAnnotation;
import org.concord.datagraph.ui.DataGraph;
import org.concord.datagraph.ui.DataGraphToolbar;
import org.concord.datagraph.ui.DataPointLabel;
import org.concord.datagraph.ui.SingleDataAxisGrid;
import org.concord.framework.data.DataDimension;
import org.concord.framework.data.stream.DataProducer;
import org.concord.framework.otrunk.OTChangeEvent;
import org.concord.framework.otrunk.OTChangeListener;
import org.concord.framework.otrunk.OTControllerService;
import org.concord.framework.otrunk.OTObject;
import org.concord.framework.otrunk.OTObjectList;
import org.concord.framework.otrunk.OTObjectService;
import org.concord.framework.otrunk.OTResourceMap;
import org.concord.framework.otrunk.OTrunk;
import org.concord.framework.otrunk.view.OTControllerServiceFactory;
import org.concord.framework.otrunk.view.OTJComponentViewContext;
import org.concord.framework.otrunk.view.OTViewContext;
import org.concord.framework.startable.Startable;
import org.concord.framework.startable.StartableEvent;
import org.concord.framework.startable.StartableListener;
import org.concord.framework.util.CheckedColorTreeModel;
import org.concord.framework.util.Copyable;
import org.concord.graph.engine.CoordinateSystem;
import org.concord.graph.engine.Drawable;
import org.concord.graph.engine.Graphable;
import org.concord.graph.engine.GraphableList;
import org.concord.graph.engine.SelectableList;
import org.concord.graph.event.GraphableListListener;
import org.concord.graph.examples.GraphWindowToolBar;
import org.concord.graph.ui.GraphTreeView;
import org.concord.graph.ui.Grid2D;
import org.concord.graph.ui.SingleAxisGrid;
import org.concord.view.CheckedColorTreeControler;

/**
 * @author scott
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class DataGraphManager implements OTChangeListener, ChangeListener,
		CheckedColorTreeModel {
	private static final Logger logger = Logger
			.getLogger(DataGraphManager.class.getCanonicalName());
	
	OTDataCollector otDataCollector;
	OTDataGraph otDataGraph;
	DataGraph dataGraph;

	DataGraphable sourceGraphable;
	DataStoreLabel valueLabel;

	OTObjectList labels;
	SelectableList notesLayer;

	OTDataAxis xOTAxis;
	OTDataAxis yOTAxis;
	
	OTDataAxis authoredXOTAxis;
	OTDataAxis authoredYOTAxis;

	JPanel bottomPanel;
	StartableToolBar toolBar = null;

	boolean isCausingOTChange = false;
	boolean isCausingRealObjChange = false;
	
	boolean instantRestart = false;				//sets whether start button is enabled after stop

	boolean showDataControls;

	Color[] colors = { Color.BLUE, Color.CYAN, Color.GRAY, Color.GREEN,
			Color.MAGENTA, Color.ORANGE, Color.PINK, Color.RED, Color.YELLOW,
			Color.BLACK };

	protected OTControllerService controllerService;
	private OTViewContext viewContext;
	private OTJComponentViewContext jComponentViewContext;
	private KeyEventDispatcher treeDispatcher;
	private DataGraphManagerStartable startable;
	private StartableListener listener;
	private OTrunk otrunk;

	/**
	 * @param serviceProvider
	 * @param jComponentViewContext
	 *            TODO
	 * 
	 */
	public DataGraphManager(OTDataGraph pfObject,
			OTViewContext serviceProvider, boolean showDataControls,
			OTJComponentViewContext jComponentViewContext) {
		this.otDataGraph = pfObject;
		if (pfObject instanceof OTDataCollector) {
			otDataCollector = (OTDataCollector) pfObject;
		}
		this.showDataControls = showDataControls;
		this.viewContext = serviceProvider;
		this.jComponentViewContext = jComponentViewContext;

		this.listener = new StartableListener(){
			public void startableEvent(StartableEvent event) {
				if(startable != null){
					startable.relayEvent(event);
				}
			}					
		};
		
		initialize();
		
		if (otDataCollector != null) {
			if (otDataCollector.getEventLog() == null) {
				try {
					OTEventLog log2 = (OTEventLog) otDataCollector.getOTObjectService().createObject(OTEventLog.class);
					otDataCollector.setEventLog(log2);
				}
				catch (Exception e) {
					e.printStackTrace();
				}
			}
			final OTEventLog log = (OTEventLog) otDataCollector.getEventLog();
			if (log != null && startable != null) {
				startable.addStartableListener(new StartableListener() {
{'fraction_non_alphanumeric': 0.08709175738724728, 'fraction_numerical': 0.005443234836702955, 'mean_word_length': 5.052235294117647, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3871550', 'n_tokens_mistral': 4108, 'n_tokens_neox': 3850, 'n_words': 947}