<commit_before>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation. All rights reserved. This program and
 * the accompanying materials are made available under the terms of the Eclipse
 * Public License v1.0 which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: Actuate Corporation - initial API and implementation
 ******************************************************************************/

package org.eclipse.birt.report.designer.internal.ui.editors.schematic.tools;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.birt.report.designer.internal.ui.editors.ReportColorConstants;
import org.eclipse.birt.report.designer.internal.ui.editors.parts.DeferredGraphicalViewer;
import org.eclipse.birt.report.designer.internal.ui.editors.schematic.editparts.DummyEditpart;
import org.eclipse.birt.report.designer.nls.Messages;
import org.eclipse.birt.report.designer.ui.views.attributes.providers.ChoiceSetFactory;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.elements.ReportDesignConstants;
import org.eclipse.birt.report.model.api.metadata.IChoice;
import org.eclipse.birt.report.model.api.metadata.IChoiceSet;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.FigureUtilities;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.tools.DragEditPartsTracker;
import org.eclipse.swt.widgets.Display;

/**
 * TableDragGuideTracker
 */
public abstract class TableDragGuideTracker extends DragEditPartsTracker
{
	protected static final DecimalFormat FORMAT = new DecimalFormat("#0.000"); //$NON-NLS-1$
	public static final String PIXELS_LABEL = Messages.getString("TableDragGuideTracker.Pixels"); //$NON-NLS-1$
	private static final int DISTANCE = 30;
	private static final Insets INSETS = new Insets(2,4,2,4);
	private int start;

	private int maxWidth;
	private int end;

	private Figure marqueeRectangleFigure;
	private Label labelFigure;
	IChoiceSet choiceSet = ChoiceSetFactory.getElementChoiceSet(
			ReportDesignConstants.REPORT_DESIGN_ELEMENT,
			ReportDesignHandle.UNITS_PROP );

	/**
	 * Constructor
	 * @param sourceEditPart
	 * @param start
	 * @param end
	 */
	public TableDragGuideTracker( EditPart sourceEditPart, int start, int end )
	{
		super( sourceEditPart );
		this.start = start;
		this.end = end;
	}

	protected boolean handleDragInProgress( )
	{
		return super.handleDragInProgress( );
	}

	protected boolean handleButtonUp( int button )
	{
		boolean bool =  super.handleButtonUp( button );
		eraseSourceFeedback();
		return bool;
	}

	@Override
	protected boolean handleButtonDown( int button )
	{
		
		boolean bool =  super.handleButtonDown( button );
		if (button == 1)
		{
			showSourceFeedback( );
		}
		return bool;
	}
	protected void performSelection( )
	{
	}

	protected void showSourceFeedback( )
	{
		//super.showSourceFeedback();
		Rectangle rect = getMarqueeSelectionRectangle( ).getCopy( );
		getMarqueeFeedbackFigure( ).translateToRelative( rect );
		getMarqueeFeedbackFigure( ).setBounds( rect );
		
		getInfomationLabel( ).setText( getInfomation( ) );

	}

	private Dimension getDistance()
	{
		Point p = getStartLocation( );
		
		FigureCanvas canvas = ((DeferredGraphicalViewer)getSourceEditPart( ).getViewer( )).getFigureCanvas( );
		org.eclipse.swt.graphics.Rectangle rect = canvas.getBounds( );
	
		Dimension retValue = new Dimension(rect.width - p.x, p.y);
		if (canvas.getVerticalBar( ).isVisible( ))
		{
			retValue.width = retValue.width - canvas.getVerticalBar( ).getSize( ).x;
		}
		return retValue;
	}
	
	private void adjustLocation()
	{
		if (labelFigure == null)
		{
			return;
		}
		Rectangle rect = labelFigure.getBounds( );
		Dimension dim = getDistance( );
		Point p = labelFigure.getLocation( ).getCopy( );
		if (dim.width < rect.width)
		{
			p.x = p.x - (rect.width - dim.width);
		}
		if (dim.height < rect.height + DISTANCE)
		{
			p.y = p.y + (rect.height + DISTANCE - dim.height);
		}
		
		labelFigure.setLocation( p );
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.gef.tools.TargetingTool#showTargetFeedback()
	 */
	protected void showTargetFeedback( )
	{
	}

	protected void performDrag( )
	{
		resize( );
		EditPart part = getSourceEditPart( );
		part.getViewer( ).setSelection( part.getViewer( ).getSelection( ) );
	}

	private IFigure getMarqueeFeedbackFigure( )
	{
		if ( marqueeRectangleFigure == null )
		{
			marqueeRectangleFigure = new MarqueeRectangleFigure( );
			addFeedback( marqueeRectangleFigure );
		}
		return marqueeRectangleFigure;
	}
	
	private Label getInfomationLabel()
	{
		if ( labelFigure == null )
		{
			labelFigure = new Label( );
			labelFigure.setBorder( new LineBorder(1) );
			labelFigure.setLabelAlignment( PositionConstants.LEFT );
			labelFigure.setOpaque( true );
			labelFigure.setBackgroundColor( ReportColorConstants.TableGuideFillColor );
		<commit_msg>- Summary:Add the  left padding of the info label.<commit_after>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation. All rights reserved. This program and
 * the accompanying materials are made available under the terms of the Eclipse
 * Public License v1.0 which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: Actuate Corporation - initial API and implementation
 ******************************************************************************/

package org.eclipse.birt.report.designer.internal.ui.editors.schematic.tools;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.birt.report.designer.internal.ui.editors.ReportColorConstants;
import org.eclipse.birt.report.designer.internal.ui.editors.parts.DeferredGraphicalViewer;
import org.eclipse.birt.report.designer.internal.ui.editors.schematic.editparts.DummyEditpart;
import org.eclipse.birt.report.designer.nls.Messages;
import org.eclipse.birt.report.designer.ui.views.attributes.providers.ChoiceSetFactory;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.elements.ReportDesignConstants;
import org.eclipse.birt.report.model.api.metadata.IChoice;
import org.eclipse.birt.report.model.api.metadata.IChoiceSet;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.FigureUtilities;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.tools.DragEditPartsTracker;
import org.eclipse.swt.widgets.Display;

/**
 * TableDragGuideTracker
 */
public abstract class TableDragGuideTracker extends DragEditPartsTracker
{
	protected static final DecimalFormat FORMAT = new DecimalFormat("#0.000"); //$NON-NLS-1$
	public static final String PIXELS_LABEL = Messages.getString("TableDragGuideTracker.Pixels"); //$NON-NLS-1$
	private static final int DISTANCE = 30;
	private static final Insets INSETS = new Insets(2,4,2,4);
	private int start;

	private int maxWidth;
	private int end;

	private Figure marqueeRectangleFigure;
	private Label labelFigure;
	IChoiceSet choiceSet = ChoiceSetFactory.getElementChoiceSet(
			ReportDesignConstants.REPORT_DESIGN_ELEMENT,
			ReportDesignHandle.UNITS_PROP );

	/**
	 * Constructor
	 * @param sourceEditPart
	 * @param start
	 * @param end
	 */
	public TableDragGuideTracker( EditPart sourceEditPart, int start, int end )
	{
		super( sourceEditPart );
		this.start = start;
		this.end = end;
	}

	protected boolean handleDragInProgress( )
	{
		return super.handleDragInProgress( );
	}

	protected boolean handleButtonUp( int button )
	{
		boolean bool =  super.handleButtonUp( button );
		eraseSourceFeedback();
		return bool;
	}

	@Override
	protected boolean handleButtonDown( int button )
	{
		
		boolean bool =  super.handleButtonDown( button );
		if (button == 1)
		{
			showSourceFeedback( );
		}
		return bool;
	}
	protected void performSelection( )
	{
	}

	protected void showSourceFeedback( )
	{
		//super.showSourceFeedback();
		Rectangle rect = getMarqueeSelectionRectangle( ).getCopy( );
		getMarqueeFeedbackFigure( ).translateToRelative( rect );
		getMarqueeFeedbackFigure( ).setBounds( rect );
		
		getInfomationLabel( ).setText( getInfomation( ) );

	}

	private Dimension getDistance()
	{
		Point p = getStartLocation( );
		
		FigureCanvas canvas = ((DeferredGraphicalViewer)getSourceEditPart( ).getViewer( )).getFigureCanvas( );
		org.eclipse.swt.graphics.Rectangle rect = canvas.getBounds( );
	
		Dimension retValue = new Dimension(rect.width - p.x, p.y);
		if (canvas.getVerticalBar( ).isVisible( ))
		{
			retValue.width = retValue.width - canvas.getVerticalBar( ).getSize( ).x;
		}
		return retValue;
	}
	
	private void adjustLocation()
	{
		if (labelFigure == null)
		{
			return;
		}
		Rectangle rect = labelFigure.getBounds( );
		Dimension dim = getDistance( );
		Point p = labelFigure.getLocation( ).getCopy( );
		if (dim.width < rect.width)
		{
			p.x = p.x - (rect.width - dim.width);
		}
		if (dim.height < rect.height + DISTANCE)
		{
			p.y = p.y + (rect.height + DISTANCE - dim.height);
		}
		
		labelFigure.setLocation( p );
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.gef.tools.TargetingTool#showTargetFeedback()
	 */
	protected void showTargetFeedback( )
	{
	}

	protected void performDrag( )
	{
		resize( );
		EditPart part = getSourceEditPart( );
		part.getViewer( ).setSelection( part.getViewer( ).getSelection( ) );
	}

	private IFigure getMarqueeFeedbackFigure( )
	{
		if ( marqueeRectangleFigure == null )
		{
			marqueeRectangleFigure = new MarqueeRectangleFigure( );
			addFeedback( marqueeRectangleFigure );
		}
		return marqueeRectangleFigure;
	}
	
	private Label getInfomationLabel()
	{
		if ( labelFigure == null )
		{
			labelFigure = new Label( );
			labelFigure.setBorder( new MarginBorder(new Insets(0,3,0,0)) 
			{
				public void paint(IFigure figure, Graphics graphics, Insets insets) 
				{ 
					tempRect.setBounds(getPaintRectangle(figure, insets));
					if (getWidth() % 2 == 1) {
						tempRect.width--;
						tempRect.height--;
					}
					tempRect.shrink(getWidth() / 2, getWidth() / 2);
					graphics.setLineWidth(getWidth());
					
					graphics.drawRectangle(tempRect);
				}
				
				private int getWidth()
				{
					return 1;
				}

			});
			labelFigure.setLabelAlignment( PositionConstants.LEFT );
			labelFigure.setOpaque( true );

			labelFigure.setBackgroundColor( ReportColorConstants.TableGuideFillColor );
		
{'fraction_non_alphanumeric': 0.13578205239794586, 'fraction_numerical': 0.006876142397075464, 'mean_word_length': 4.474035254883278, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '6895527', 'n_tokens_mistral': 3937, 'n_tokens_neox': 3564, 'n_words': 724}