<commit_before>/*******************************************************************************
 * Copyright (c) 2010 Oak Ridge National Laboratory.
 * 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
 ******************************************************************************/
package org.csstudio.swt.widgets.figures;

import org.csstudio.swt.widgets.figureparts.RoundScale;
import org.csstudio.swt.widgets.figureparts.RoundScaleTickMarks;
import org.csstudio.swt.widgets.figureparts.RoundScaledRamp;
import org.csstudio.swt.widgets.util.GraphicsUtil;
import org.csstudio.swt.widgets.util.PointsUtil;
import org.csstudio.swt.xygraph.linearscale.AbstractScale.LabelSide;
import org.csstudio.ui.util.CustomMediaFactory;
import org.eclipse.draw2d.AbstractLayout;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.FigureListener;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.Polygon;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Pattern;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;


/**
 * The figure of gauge
 * @author <NAME>
 *
 */
public class GaugeFigure extends AbstractRoundRampedFigure {

	private final Color WHITE_COLOR = CustomMediaFactory.getInstance().getColor(
			CustomMediaFactory.COLOR_WHITE); 
	private final Color BORDER_COLOR = CustomMediaFactory.getInstance().getColor(
			new RGB(100, 100, 100)); 
	private final Color GRAY_COLOR = CustomMediaFactory.getInstance().getColor(
			CustomMediaFactory.COLOR_GRAY); 
	private final Color DEFAULT_NEEDLE_COLOR = CustomMediaFactory.getInstance().getColor(
			CustomMediaFactory.COLOR_RED);
	private final Font DEFAULT_LABEL_FONT = CustomMediaFactory.getInstance().getFont(
			new FontData("Arial", 12, SWT.BOLD));
	private final static int BORDER_WIDTH = 2;
	
	private boolean effect3D = true;
	
	private NeedleCenter needleCenter;
	
	private Needle needle;
	
	private Label valueLabel;
	
	public GaugeFigure() {
		super();
		transparent = true;
		scale.setScaleLineVisible(false);
		scale.setTickLableSide(LabelSide.Secondary);
		ramp.setRampWidth(10);
		
		valueLabel = new Label();	
		valueLabel.setFont(DEFAULT_LABEL_FONT);
		
		needle = new Needle();
		needle.setFill(true);
		needle.setOutline(false);
		
		needleCenter = new NeedleCenter();
		needleCenter.setOutline(false);
		
		setLayoutManager(new GaugeLayout());
		add(ramp, GaugeLayout.RAMP);
		add(scale, GaugeLayout.SCALE);		
		add(valueLabel, GaugeLayout.VALUE_LABEL);
		add(needle, GaugeLayout.NEEDLE);
		add(needleCenter, GaugeLayout.NEEDLE_CENTER);		
		addFigureListener(new FigureListener() {			
			public void figureMoved(IFigure source) {
				ramp.setDirty(true);
				revalidate();	
			}
		});	
		
	}
	@Override
	public void setBounds(Rectangle rect) {
		
		super.setBounds(rect);
	}
	
	@Override
	public void setValue(double value) {
		super.setValue(value);
		valueLabel.setText(getValueText());			
	}
	
	@Override
	protected void paintClientArea(Graphics graphics) {
		graphics.setAntialias(SWT.ON);
		Rectangle area = getClientArea();
		area.width = Math.min(area.width, area.height);
		area.height = area.width;
		Pattern pattern = null;
		graphics.pushState();
		graphics.setBackgroundColor(GRAY_COLOR);
		boolean support3D = GraphicsUtil.testPatternSupported(graphics);
		if(effect3D && support3D) {		
			//add this to eliminate the repaint bug on Mac
			graphics.fillOval(new Rectangle());
			pattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), area.x, area.y, 
				area.x+area.width, area.y + area.height, BORDER_COLOR, WHITE_COLOR);
			graphics.setBackgroundPattern(pattern);					
		}	
		graphics.fillOval(area);
		graphics.popState();
		
		if(effect3D && support3D){			
			pattern.dispose();
			area.shrink(BORDER_WIDTH, BORDER_WIDTH);
		}else
			area.shrink(1, 1);
		
		graphics.fillOval(area);	
	
		
		super.paintClientArea(graphics);
		
			//glossy effect
		if(effect3D && support3D) {
			graphics.pushState();
			graphics.setAntialias(SWT.ON);
			final double R = area.width/2.0d;
			final double UD_FILL_PART = 9.5d/10d;
			final double UP_DOWN_RATIO = 1d/2d;
			final double LR_FILL_PART = 8.5d/10d;
			final double UP_ANGLE = 0d * Math.PI/180d;
			final double DOWN_ANGLE = 35d * Math.PI/180d;
			//add this to eliminate the repaint bug on Mac

			graphics.fillOval(new Rectangle());

			Pattern glossyPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), 
					area.x + area.width/2, (float)(area.y + area.height/2 - R * UD_FILL_PART),
					area.x + area.width/2, (float) (area.y + area.height/2 + R * UP_DOWN_RATIO),
					WHITE_COLOR, 90, WHITE_COLOR, 0);
			graphics.setBackgroundPattern(glossyPattern);
			Rectangle rectangle = new Rectangle(
					(int)(area.x + area.width/2 - R * LR_FILL_PART *Math.cos(UP_ANGLE)),
					(int)(area.y + area.height/2 - R * UD_FILL_PART),
					(int)(2*R* LR_FILL_PART*Math.cos(UP_ANGLE)), (int)(R*UD_FILL_PART + R*UP_DOWN_RATIO));			
			graphics.fillOval(rectangle);
			glossyPattern.dispose();
			
			glossyPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), 
					area.x + area.width/2, (float)(area.y + area.height/2 + R * UP_DOWN_RATIO -1),
					area.x + area.width/2, (float) (area.y + area.height/2 + R * UD_FILL_PART + 1),
					WHITE_COLOR, 0, WHITE_COLOR, 40);
			graphics.setBackgroundPattern(glossyPattern);
			rectangle = new Rectangle(
					(int)(area.x + area.width/2 - R*LR_FILL_PART*Math.sin(DOWN_ANGLE)),
					(int)Math.ceil(area.y + area.height/2 + R * UP_DOWN_RATIO),
					(int)(2*R*LR_FILL_PART*Math.sin(DOWN_ANGLE)), 
					(int)Math.ceil(R*UD_FILL_PART - R*UP_DOWN_RATIO));	
			graphics.fillOval(rectangle);
			glossyPattern.dispose();
			graphics.popState();			
		}<commit_msg>BOY: fix a zoom bug on gauge figure by commenting out the code someone introduced to fix a repaint bug on Mac.<commit_after>/*******************************************************************************
 * Copyright (c) 2010 Oak Ridge National Laboratory.
 * 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
 ******************************************************************************/
package org.csstudio.swt.widgets.figures;

import org.csstudio.swt.widgets.figureparts.RoundScale;
import org.csstudio.swt.widgets.figureparts.RoundScaleTickMarks;
import org.csstudio.swt.widgets.figureparts.RoundScaledRamp;
import org.csstudio.swt.widgets.util.GraphicsUtil;
import org.csstudio.swt.widgets.util.PointsUtil;
import org.csstudio.swt.xygraph.linearscale.AbstractScale.LabelSide;
import org.csstudio.ui.util.CustomMediaFactory;
import org.eclipse.draw2d.AbstractLayout;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.FigureListener;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.Polygon;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Pattern;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;


/**
 * The figure of gauge
 * @author <NAME>
 *
 */
public class GaugeFigure extends AbstractRoundRampedFigure {

	private final Color WHITE_COLOR = CustomMediaFactory.getInstance().getColor(
			CustomMediaFactory.COLOR_WHITE); 
	private final Color BORDER_COLOR = CustomMediaFactory.getInstance().getColor(
			new RGB(100, 100, 100)); 
	private final Color GRAY_COLOR = CustomMediaFactory.getInstance().getColor(
			CustomMediaFactory.COLOR_GRAY); 
	private final Color DEFAULT_NEEDLE_COLOR = CustomMediaFactory.getInstance().getColor(
			CustomMediaFactory.COLOR_RED);
	private final Font DEFAULT_LABEL_FONT = CustomMediaFactory.getInstance().getFont(
			new FontData("Arial", 12, SWT.BOLD));
	private final static int BORDER_WIDTH = 2;
	
	private boolean effect3D = true;
	
	private NeedleCenter needleCenter;
	
	private Needle needle;
	
	private Label valueLabel;
	private Boolean support3D;
	
	public GaugeFigure() {
		super();
		transparent = true;
		scale.setScaleLineVisible(false);
		scale.setTickLableSide(LabelSide.Secondary);
		ramp.setRampWidth(10);
		
		valueLabel = new Label();	
		valueLabel.setFont(DEFAULT_LABEL_FONT);
		
		needle = new Needle();
		needle.setFill(true);
		needle.setOutline(false);
		
		needleCenter = new NeedleCenter();
		needleCenter.setOutline(false);
		
		setLayoutManager(new GaugeLayout());
		add(ramp, GaugeLayout.RAMP);
		add(scale, GaugeLayout.SCALE);		
		add(valueLabel, GaugeLayout.VALUE_LABEL);
		add(needle, GaugeLayout.NEEDLE);
		add(needleCenter, GaugeLayout.NEEDLE_CENTER);		
		addFigureListener(new FigureListener() {			
			public void figureMoved(IFigure source) {
				ramp.setDirty(true);
				revalidate();	
			}
		});	
		
	}
	@Override
	public void setBounds(Rectangle rect) {
		
		super.setBounds(rect);
	}
	
	@Override
	public void setValue(double value) {
		super.setValue(value);
		valueLabel.setText(getValueText());			
	}
	
	@Override
	protected void paintClientArea(Graphics graphics) {
		graphics.setAntialias(SWT.ON);
		Rectangle area = getClientArea();
		area.width = Math.min(area.width, area.height);
		area.height = area.width;
		Pattern pattern = null;
		graphics.pushState();
		graphics.setBackgroundColor(GRAY_COLOR);
		if(support3D == null)
			support3D = GraphicsUtil.testPatternSupported(graphics);
		if(effect3D && support3D) {		
			//add this to eliminate the repaint bug on Mac
			//Who added this? this will cause problem in zoom.
//			graphics.fillOval(new Rectangle());
			pattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), area.x, area.y, 
				area.x+area.width, area.y + area.height, BORDER_COLOR, WHITE_COLOR);
			graphics.setBackgroundPattern(pattern);				
		}	
		graphics.fillOval(area);		
		if(effect3D && support3D){	
			pattern.dispose();
			area.shrink(BORDER_WIDTH, BORDER_WIDTH);
		}else
			area.shrink(1, 1);
		graphics.popState();
		
		graphics.fillOval(area);
		
		super.paintClientArea(graphics);
		
			//glossy effect
		if(effect3D && support3D) {
			graphics.pushState();
			graphics.setAntialias(SWT.ON);
			final double R = area.width/2.0d;
			final double UD_FILL_PART = 9.5d/10d;
			final double UP_DOWN_RATIO = 1d/2d;
			final double LR_FILL_PART = 8.5d/10d;
			final double UP_ANGLE = 0d * Math.PI/180d;
			final double DOWN_ANGLE = 35d * Math.PI/180d;
			//add this to eliminate the repaint bug on Mac

//			graphics.fillOval(new Rectangle());

			Pattern glossyPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), 
					area.x + area.width/2, (float)(area.y + area.height/2 - R * UD_FILL_PART),
					area.x + area.width/2, (float) (area.y + area.height/2 + R * UP_DOWN_RATIO),
					WHITE_COLOR, 90, WHITE_COLOR, 0);
			graphics.setBackgroundPattern(glossyPattern);
			Rectangle rectangle = new Rectangle(
					(int)(area.x + area.width/2 - R * LR_FILL_PART *Math.cos(UP_ANGLE)),
					(int)(area.y + area.height/2 - R * UD_FILL_PART),
					(int)(2*R* LR_FILL_PART*Math.cos(UP_ANGLE)), (int)(R*UD_FILL_PART + R*UP_DOWN_RATIO));			
			graphics.fillOval(rectangle);
			glossyPattern.dispose();
			
			glossyPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), 
					area.x + area.width/2, (float)(area.y + area.height/2 + R * UP_DOWN_RATIO -1),
					area.x + area.width/2, (float) (area.y + area.height/2 + R * UD_FILL_PART + 1),
					WHITE_COLOR, 0, WHITE_COLOR, 40);
			graphics.setBackgroundPattern(glossyPattern);
			rectangle = new Rectangle(
					(int)(area.x + area.width/2 - R*LR_FILL_PART*Math.sin(DOWN_ANGLE)),
					(int)Math.ceil(area.y + area.height/2 + R * UP_DOWN_RATIO),
					(int)(2*R*LR_FILL_PART*Math.sin(DOWN_ANGLE)), 
					(int)Math.ceil(R*UD_FILL_PART - R*UP_DOWN_RATIO));	
			graphics.fillOval(rectangle);
			glossyPattern.dispose();
			graphics.popState();			
		}
{'fraction_non_alphanumeric': 0.14072577511850182, 'fraction_numerical': 0.013676276322946617, 'mean_word_length': 4.55699481865285, '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': '6966416', 'n_tokens_mistral': 4904, 'n_tokens_neox': 4284, 'n_words': 820}