<commit_before>// Copyright MWC 1999, Debrief 3 Project
// $RCSfile$
// @author $Author$
// @version $Revision$
// $Log$
// Revision 1.11  2005-06-15 14:30:11  Ian.Mayo
// Refactor, so that we can call it more easily from WMF painter
//
// Revision 1.10  2005/06/15 11:03:42  Ian.Mayo
// Overcome tidying error
//
// Revision 1.9  2005/06/14 09:49:28  Ian.Mayo
// Eclipse-triggered tidying (unused variables)
//
// Revision 1.8  2005/05/26 14:04:50  Ian.Mayo
// Tidy up double-buffering
//
// Revision 1.7  2005/05/26 07:53:56  Ian.Mayo
// Minor tidying
//
// Revision 1.6  2005/05/25 15:31:54  Ian.Mayo
// Get double-buffering going
//
// Revision 1.5  2005/05/25 14:18:17  Ian.Mayo
// Refactor to provide more useful SWT GC wrapper (hopefully suitable for buffered images)
//
// Revision 1.4  2005/05/24 13:26:42  Ian.Mayo
// Start including double-click support.
//
// Revision 1.3  2005/05/24 07:35:57  Ian.Mayo
// Ignore anti-alias bits, sort out text-writing in filling areas
//
// Revision 1.2  2005/05/20 15:34:44  Ian.Mayo
// Hey, practically working!
//
// Revision 1.1  2005/05/20 13:45:03  Ian.Mayo
// Start doing chart
//
//

package org.mwc.cmap.plotViewer.editors.chart;

import java.awt.Dimension;
import java.util.Enumeration;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.*;
import org.mwc.cmap.core.property_support.ColorHelper;

import MWC.GUI.CanvasType;

/**
 * Swing implementation of a canvas.
 */
public class SWTCanvas extends SWTCanvasAdapter
{

	// ///////////////////////////////////////////////////////////
	// member variables
	// //////////////////////////////////////////////////////////

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	org.eclipse.swt.widgets.Canvas _myCanvas = null;
	

	/**
	 * our double-buffering safe copy.
	 */
	private transient Image _dblBuff;	

	// ///////////////////////////////////////////////////////////
	// constructor
	// //////////////////////////////////////////////////////////

	/**
	 * default constructor.
	 */
	public SWTCanvas(Composite parent)
	{
		super(null);
		
		_myCanvas = new Canvas(parent, SWT.NO_BACKGROUND);

		// add handler to catch canvas resizes
		_myCanvas.addControlListener(new ControlAdapter()
		{

			public void controlResized(final ControlEvent e)
			{
				Point pt = _myCanvas.getSize();
				Dimension dim = new Dimension(pt.x, pt.y);
				setScreenSize(dim);
			}
		});

		// switch on tooltips for this panel
		_myCanvas.setToolTipText("blank");

		// setup our own painter
		_myCanvas.addPaintListener(new org.eclipse.swt.events.PaintListener()
		{

			public void paintControl(PaintEvent e)
			{
				repaintMe(e);
			}
		});
		
		_myCanvas.setBackground(ColorHelper.getColor(java.awt.Color.black));
	}


	// ////////////////////////////////////////////////////
	// screen redraw related
	// ////////////////////////////////////////////////////
	
	protected void repaintMe(PaintEvent pe)
	{

//		paintPlot(pe.gc);
		// get the graphics destination
		GC gc = pe.gc;

		// put double-buffering code in here.<commit_msg>Experiment with right-click support (copy location)<commit_after>// Copyright MWC 1999, Debrief 3 Project
// $RCSfile$
// @author $Author$
// @version $Revision$
// $Log$
// Revision 1.12  2005-06-20 08:06:10  Ian.Mayo
// Experiment with right-click support (copy location)
//
// Revision 1.11  2005/06/15 14:30:11  Ian.Mayo
// Refactor, so that we can call it more easily from WMF painter
//
// Revision 1.10  2005/06/15 11:03:42  Ian.Mayo
// Overcome tidying error
//
// Revision 1.9  2005/06/14 09:49:28  Ian.Mayo
// Eclipse-triggered tidying (unused variables)
//
// Revision 1.8  2005/05/26 14:04:50  Ian.Mayo
// Tidy up double-buffering
//
// Revision 1.7  2005/05/26 07:53:56  Ian.Mayo
// Minor tidying
//
// Revision 1.6  2005/05/25 15:31:54  Ian.Mayo
// Get double-buffering going
//
// Revision 1.5  2005/05/25 14:18:17  Ian.Mayo
// Refactor to provide more useful SWT GC wrapper (hopefully suitable for buffered images)
//
// Revision 1.4  2005/05/24 13:26:42  Ian.Mayo
// Start including double-click support.
//
// Revision 1.3  2005/05/24 07:35:57  Ian.Mayo
// Ignore anti-alias bits, sort out text-writing in filling areas
//
// Revision 1.2  2005/05/20 15:34:44  Ian.Mayo
// Hey, practically working!
//
// Revision 1.1  2005/05/20 13:45:03  Ian.Mayo
// Start doing chart
//
//

package org.mwc.cmap.plotViewer.editors.chart;

import java.awt.Dimension;
import java.util.Enumeration;

import org.eclipse.jface.action.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.mwc.cmap.core.property_support.ColorHelper;

import MWC.GUI.CanvasType;
import MWC.GenericData.WorldLocation;

/**
 * Swing implementation of a canvas.
 */
public class SWTCanvas extends SWTCanvasAdapter
{

	// ///////////////////////////////////////////////////////////
	// member variables
	// //////////////////////////////////////////////////////////

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	org.eclipse.swt.widgets.Canvas _myCanvas = null;
	

	/**
	 * our double-buffering safe copy.
	 */
	private transient Image _dblBuff;


	private Action _copyLocation;	

	// ///////////////////////////////////////////////////////////
	// constructor
	// //////////////////////////////////////////////////////////

	/**
	 * default constructor.
	 */
	public SWTCanvas(Composite parent)
	{
		super(null);
		
		_myCanvas = new Canvas(parent, SWT.NO_BACKGROUND);

		// add handler to catch canvas resizes
		_myCanvas.addControlListener(new ControlAdapter()
		{

			public void controlResized(final ControlEvent e)
			{
				Point pt = _myCanvas.getSize();
				Dimension dim = new Dimension(pt.x, pt.y);
				setScreenSize(dim);
			}
		});

		// switch on tooltips for this panel
		_myCanvas.setToolTipText("blank");

		// setup our own painter
		_myCanvas.addPaintListener(new org.eclipse.swt.events.PaintListener()
		{

			public void paintControl(PaintEvent e)
			{
				repaintMe(e);
			}
		});
		
		_myCanvas.setBackground(ColorHelper.getColor(java.awt.Color.black));
		
			
		_myCanvas.addMouseListener(new MouseAdapter()
		{

			/**
			 * @param e
			 */
			public void mouseUp(MouseEvent e)
			{
				if(e.button == 3)
				{
					// cool, right-had button. process it
					MenuManager mmgr = new MenuManager();
					Point display = Display.getCurrent().getCursorLocation();
					Point control =  _myCanvas.toControl(display);
					WorldLocation targetLoc = getProjection().toWorld(new java.awt.Point(control.x, control.y));
					fillContextMenu(mmgr, targetLoc);
					Menu thisM = mmgr.createContextMenu(_myCanvas);
					thisM.setVisible(true);					
				}
			}
			
		});
		
//		Menu rhMenu = new Menu(_myCanvas);
//		MenuItem copyLocation = new MenuItem(rhMenu, SWT.POP_UP);
//		copyLocation.setText("here");
//		copyLocation.addSelectionListener(new SelectionListener(){
//
//			public void widgetSelected(SelectionEvent e)
//			{
//				Point pt = Display.getCurrent().getCursorLocation();
//				Point pt2 = _myCanvas.toControl(pt);
//				System.out.println("clicked at:" + e.x + ", " + e.y + " -- " + pt + " : " + pt2);
//				WorldLocation toLoc = getProjection().toWorld(new java.awt.Point(pt2.x, pt2.y));
//				System.out.println("clicked at:" + e.x + ", " + e.y + " -- " + pt + " : " + pt2 + " loc:" + BriefFormatLocation.toString(toLoc));
//			}
//
//			public void widgetDefaultSelected(SelectionEvent e)
//			{
//			}});
//		
//		_myCanvas.setMenu(rhMenu);
	}


	/** ok - insert the right-hand button related items
	 * 
	 * @param mmgr
	 */
	protected void fillContextMenu(MenuManager mmgr, final WorldLocation target)
	{
		_copyLocation = new Action("Copy cursor location", SWT.PUSH)
		{
			public void run()
			{
				System.out.println("clicked at:" + target);
			}
			
		};
		mmgr.add(_copyLocation);
	}


	// ////////////////////////////////////////////////////
	// screen redraw related
	// ////////////////////////////////////////////////////
	
	protected void repaintMe(PaintEvent pe)
	{

//		paintPlot(pe.gc);
		// get the graphics destination
		GC gc = pe.gc;

		// put double-buffering code in here.
{'fraction_non_alphanumeric': 0.20620738302374794, 'fraction_numerical': 0.045967552316012225, 'mean_word_length': 2.2041431261770246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4446554', 'n_tokens_mistral': 3247, 'n_tokens_neox': 2752, 'n_words': 637}