/*******************************************************************************_x000D_
 * Copyright (c) 2008, 2018 SWTChart project._x000D_
 *_x000D_
 * All rights reserved. This program and the accompanying materials_x000D_
 * are made available under the terms of the Eclipse Public License v1.0_x000D_
 * which accompanies this distribution, and is available at_x000D_
 * http://www.eclipse.org/legal/epl-v10.html_x000D_
 * _x000D_
 * Contributors:_x000D_
 * yoshitaka - initial API and implementation_x000D_
 *******************************************************************************/_x000D_
package org.eclipse.swtchart.internal.axis;_x000D_
_x000D_
import java.text.Format;_x000D_
import java.util.List;_x000D_
_x000D_
import org.eclipse.swt.SWT;_x000D_
import org.eclipse.swt.graphics.Color;_x000D_
import org.eclipse.swt.graphics.Font;_x000D_
import org.eclipse.swt.graphics.Rectangle;_x000D_
import org.eclipse.swtchart.Chart;_x000D_
import org.eclipse.swtchart.IAxis.Position;_x000D_
import org.eclipse.swtchart.IAxisTick;_x000D_
_x000D_
/**_x000D_
 * An axis tick._x000D_
 */_x000D_
public class AxisTick implements IAxisTick {_x000D_
_x000D_
	/** the chart */_x000D_
	private Chart chart;_x000D_
	/** the axis */_x000D_
	private Axis axis;_x000D_
	/** the axis tick labels */_x000D_
	private AxisTickLabels axisTickLabels;_x000D_
	/** the axis tick marks */_x000D_
	private AxisTickMarks axisTickMarks;_x000D_
	/** true if tick is visible */_x000D_
	private boolean isVisible;_x000D_
	/** the tick mark step hint */_x000D_
	private int tickMarkStepHint;_x000D_
	/** the tick label angle in degree */_x000D_
	private int tickLabelAngle;_x000D_
	/** the default tick mark step hint */_x000D_
	private static final int DEFAULT_TICK_MARK_STEP_HINT = 64;_x000D_
_x000D_
	/**_x000D_
	 * Constructor._x000D_
	 *_x000D_
	 * @param chart_x000D_
	 *            the chart_x000D_
	 * @param axis_x000D_
	 *            the axis_x000D_
	 */_x000D_
	protected AxisTick(Chart chart, Axis axis) {_x000D_
		this.chart = chart;_x000D_
		this.axis = axis;_x000D_
		axisTickLabels = new AxisTickLabels(chart, axis);_x000D_
		axisTickMarks = new AxisTickMarks(chart, axis);_x000D_
		isVisible = true;_x000D_
		tickLabelAngle = 0;_x000D_
		tickMarkStepHint = DEFAULT_TICK_MARK_STEP_HINT;_x000D_
	}_x000D_
_x000D_
	/**_x000D_
	 * Gets the axis tick marks._x000D_
	 *_x000D_
	 * @return the axis tick marks_x000D_
	 */_x000D_
	public AxisTickMarks getAxisTickMarks() {_x000D_
_x000D_
		return axisTickMarks;_x000D_
	}_x000D_
_x000D_
	/**_x000D_
	 * Gets the axis tick labels._x000D_
	 *_x000D_
	 * @return the axis tick labels_x000D_
	 */_x000D_
	public AxisTickLabels getAxisTickLabels() {_x000D_
_x000D_
		return axisTickLabels;_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#setForeground(Color)_x000D_
	 */_x000D_
	public void setForeground(Color color) {_x000D_
_x000D_
		if(color != null && color.isDisposed()) {_x000D_
			SWT.error(SWT.ERROR_INVALID_ARGUMENT);_x000D_
		}_x000D_
		axisTickMarks.setForeground(color);_x000D_
		axisTickLabels.setForeground(color);_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getForeground()_x000D_
	 */_x000D_
	public Color getForeground() {_x000D_
_x000D_
		return axisTickMarks.getForeground();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#setFont(Font)_x000D_
	 */_x000D_
	public void setFont(Font font) {_x000D_
_x000D_
		if(font != null && font.isDisposed()) {_x000D_
			SWT.error(SWT.ERROR_INVALID_ARGUMENT);_x000D_
		}_x000D_
		axisTickLabels.setFont(font);_x000D_
		chart.updateLayout();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getFont()_x000D_
	 */_x000D_
	public Font getFont() {_x000D_
_x000D_
		return axisTickLabels.getFont();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#isVisible()_x000D_
	 */_x000D_
	public boolean isVisible() {_x000D_
_x000D_
		return isVisible;_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#setVisible(boolean)_x000D_
	 */_x000D_
	public void setVisible(boolean isVisible) {_x000D_
_x000D_
		this.isVisible = isVisible;_x000D_
		chart.updateLayout();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getTickMarkStepHint()_x000D_
	 */_x000D_
	public int getTickMarkStepHint() {_x000D_
_x000D_
		return tickMarkStepHint;_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#setTickMarkStepHint(int)_x000D_
	 */_x000D_
	public void setTickMarkStepHint(int tickMarkStepHint) {_x000D_
_x000D_
		if(tickMarkStepHint < MIN_GRID_STEP_HINT) {_x000D_
			this.tickMarkStepHint = DEFAULT_TICK_MARK_STEP_HINT;_x000D_
		} else {_x000D_
			this.tickMarkStepHint = tickMarkStepHint;_x000D_
		}_x000D_
		chart.updateLayout();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getTickLabelAngle()_x000D_
	 */_x000D_
	public int getTickLabelAngle() {_x000D_
_x000D_
		return tickLabelAngle;_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#setTickLabelAngle(int)_x000D_
	 */_x000D_
	public void setTickLabelAngle(int angle) {_x000D_
_x000D_
		if(angle < 0 || 90 < angle) {_x000D_
			SWT.error(SWT.ERROR_INVALID_ARGUMENT);_x000D_
		}_x000D_
		if(tickLabelAngle != angle) {_x000D_
			tickLabelAngle = angle;_x000D_
			chart.updateLayout();_x000D_
		}_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#setFormat(Format)_x000D_
	 */_x000D_
	public void setFormat(Format format) {_x000D_
_x000D_
		axisTickLabels.setFormat(format);_x000D_
		chart.updateLayout();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getFormat()_x000D_
	 */_x000D_
	public Format getFormat() {_x000D_
_x000D_
		return axisTickLabels.getFormat();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getBounds()_x000D_
	 */_x000D_
	public Rectangle getBounds() {_x000D_
_x000D_
		Rectangle r1 = axisTickMarks.getBounds();_x000D_
		Rectangle r2 = axisTickLabels.getBounds();_x000D_
		Position position = axis.getPosition();_x000D_
		if(position == Position.Primary && axis.isHorizontalAxis()) {_x000D_
			return new Rectangle(r1.x, r1.y, r1.width, r1.height + r2.height);_x000D_
		} else if(position == Position.Secondary && axis.isHorizontalAxis()) {_x000D_
			return new Rectangle(r1.x, r2.y, r1.width, r1.height + r2.height);_x000D_
		} else if(position == Position.Primary && !axis.isHorizontalAxis()) {_x000D_
			return new Rectangle(r2.x, r1.y, r1.width + r2.width, r1.height);_x000D_
		} else if(position == Position.Secondary && !axis.isHorizontalAxis()) {_x000D_
			return new Rectangle(r1.x, r1.y, r1.width + r2.width, r1.height);_x000D_
		} else {_x000D_
			throw new IllegalStateException("unknown axis position");_x000D_
		}_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getTickLabelValues()_x000D_
	 */_x000D_
	public double[] getTickLabelValues() {_x000D_
_x000D_
		List<Double> list = axisTickLabels.getTickLabelValues();_x000D_
		double[] values = new double[list.size()];_x000D_
		for(int i = 0; i < values.length; i++) {_x000D_
			values[i] = list.get(i);_x000D_
		}_x000D_
		return values;_x000D_
	}_x000D_
_x000D_
	/**_x000D_
	 * Updates the tick around per 64 pixel._x000D_
	 *_x000D_
	 * @param length_x000D_
	 *            the axis length_x000D_
	 */_x000D_
	public void updateTick(int length) {_x000D_
_x000D_
		if(length <= 0) {_x000D_
			axisTickLabels.update(1);_x000D_
		} else {_x000D_
			axisTickLabels.update(length);_x000D_
		}_x000D_
	}_x000D_
_x000D_
	/**_x000D_
	 * Updates the tick layout._x000D_
	 */_x000D_
	protected void updateLayoutData() {_x000D_
_x000D_
		axisTickLabels.updateLayoutData();_x000D_
		axisTickMarks.updateLayoutData();_x000D_
	}_x000D_
}_x000D_

/*_x000D_
	 * @see IAxisTick#getBounds()_x000D_
	 */
/*******************************************************************************_x000D_
 * Copyright (c) 2008, 2018 SWTChart project._x000D_
 *_x000D_
 * All rights reserved. This program and the accompanying materials_x000D_
 * are made available under the terms of the Eclipse Public License v1.0_x000D_
 * which accompanies this distribution, and is available at_x000D_
 * http://www.eclipse.org/legal/epl-v10.html_x000D_
 * _x000D_
 * Contributors:_x000D_
 * yoshitaka - initial API and implementation_x000D_
 *******************************************************************************/_x000D_
package org.eclipse.swtchart.internal.axis;_x000D_
_x000D_
import java.text.Format;_x000D_
import java.util.List;_x000D_
_x000D_
import org.eclipse.swt.SWT;_x000D_
import org.eclipse.swt.graphics.Color;_x000D_
import org.eclipse.swt.graphics.Font;_x000D_
import org.eclipse.swt.graphics.Rectangle;_x000D_
import org.eclipse.swtchart.Chart;_x000D_
import org.eclipse.swtchart.IAxis.Position;_x000D_
import org.eclipse.swtchart.IAxisTick;_x000D_
_x000D_
/**_x000D_
 * An axis tick._x000D_
 */_x000D_
public class AxisTick implements IAxisTick {_x000D_
_x000D_
	/** the chart */_x000D_
	private Chart chart;_x000D_
	/** the axis */_x000D_
	private Axis axis;_x000D_
	/** the axis tick labels */_x000D_
	private AxisTickLabels axisTickLabels;_x000D_
	/** the axis tick marks */_x000D_
	private AxisTickMarks axisTickMarks;_x000D_
	/** true if tick is visible */_x000D_
	private boolean isVisible;_x000D_
	/** the tick mark step hint */_x000D_
	private int tickMarkStepHint;_x000D_
	/** the tick label angle in degree */_x000D_
	private int tickLabelAngle;_x000D_
	/** the default tick mark step hint */_x000D_
	private static final int DEFAULT_TICK_MARK_STEP_HINT = 64;_x000D_
_x000D_
	/**_x000D_
	 * Constructor._x000D_
	 *_x000D_
	 * @param chart_x000D_
	 *            the chart_x000D_
	 * @param axis_x000D_
	 *            the axis_x000D_
	 */_x000D_
	protected AxisTick(Chart chart, Axis axis) {_x000D_
		this.chart = chart;_x000D_
		this.axis = axis;_x000D_
		axisTickLabels = new AxisTickLabels(chart, axis);_x000D_
		axisTickMarks = new AxisTickMarks(chart, axis);_x000D_
		isVisible = true;_x000D_
		tickLabelAngle = 0;_x000D_
		tickMarkStepHint = DEFAULT_TICK_MARK_STEP_HINT;_x000D_
	}_x000D_
_x000D_
	/**_x000D_
	 * Gets the axis tick marks._x000D_
	 *_x000D_
	 * @return the axis tick marks_x000D_
	 */_x000D_
	public AxisTickMarks getAxisTickMarks() {_x000D_
_x000D_
		return axisTickMarks;_x000D_
	}_x000D_
_x000D_
	/**_x000D_
	 * Gets the axis tick labels._x000D_
	 *_x000D_
	 * @return the axis tick labels_x000D_
	 */_x000D_
	public AxisTickLabels getAxisTickLabels() {_x000D_
_x000D_
		return axisTickLabels;_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#setForeground(Color)_x000D_
	 */_x000D_
	public void setForeground(Color color) {_x000D_
_x000D_
		if(color != null && color.isDisposed()) {_x000D_
			SWT.error(SWT.ERROR_INVALID_ARGUMENT);_x000D_
		}_x000D_
		axisTickMarks.setForeground(color);_x000D_
		axisTickLabels.setForeground(color);_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getForeground()_x000D_
	 */_x000D_
	public Color getForeground() {_x000D_
_x000D_
		return axisTickMarks.getForeground();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#setFont(Font)_x000D_
	 */_x000D_
	public void setFont(Font font) {_x000D_
_x000D_
		if(font != null && font.isDisposed()) {_x000D_
			SWT.error(SWT.ERROR_INVALID_ARGUMENT);_x000D_
		}_x000D_
		axisTickLabels.setFont(font);_x000D_
		chart.updateLayout();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getFont()_x000D_
	 */_x000D_
	public Font getFont() {_x000D_
_x000D_
		return axisTickLabels.getFont();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#isVisible()_x000D_
	 */_x000D_
	public boolean isVisible() {_x000D_
_x000D_
		return isVisible;_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#setVisible(boolean)_x000D_
	 */_x000D_
	public void setVisible(boolean isVisible) {_x000D_
_x000D_
		this.isVisible = isVisible;_x000D_
		chart.updateLayout();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getTickMarkStepHint()_x000D_
	 */_x000D_
	public int getTickMarkStepHint() {_x000D_
_x000D_
		return tickMarkStepHint;_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#setTickMarkStepHint(int)_x000D_
	 */_x000D_
	public void setTickMarkStepHint(int tickMarkStepHint) {_x000D_
_x000D_
		if(tickMarkStepHint < MIN_GRID_STEP_HINT) {_x000D_
			this.tickMarkStepHint = DEFAULT_TICK_MARK_STEP_HINT;_x000D_
		} else {_x000D_
			this.tickMarkStepHint = tickMarkStepHint;_x000D_
		}_x000D_
		chart.updateLayout();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getTickLabelAngle()_x000D_
	 */_x000D_
	public int getTickLabelAngle() {_x000D_
_x000D_
		return tickLabelAngle;_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#setTickLabelAngle(int)_x000D_
	 */_x000D_
	public void setTickLabelAngle(int angle) {_x000D_
_x000D_
		if(angle < 0 || 90 < angle) {_x000D_
			SWT.error(SWT.ERROR_INVALID_ARGUMENT);_x000D_
		}_x000D_
		if(tickLabelAngle != angle) {_x000D_
			tickLabelAngle = angle;_x000D_
			chart.updateLayout();_x000D_
		}_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#setFormat(Format)_x000D_
	 */_x000D_
	public void setFormat(Format format) {_x000D_
_x000D_
		axisTickLabels.setFormat(format);_x000D_
		chart.updateLayout();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getFormat()_x000D_
	 */_x000D_
	public Format getFormat() {_x000D_
_x000D_
		return axisTickLabels.getFormat();_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getBounds()_x000D_
<SUF>*/_x000D_
	public Rectangle getBounds() {_x000D_
_x000D_
		Rectangle r1 = axisTickMarks.getBounds();_x000D_
		Rectangle r2 = axisTickLabels.getBounds();_x000D_
		Position position = axis.getPosition();_x000D_
		if(position == Position.Primary && axis.isHorizontalAxis()) {_x000D_
			return new Rectangle(r1.x, r1.y, r1.width, r1.height + r2.height);_x000D_
		} else if(position == Position.Secondary && axis.isHorizontalAxis()) {_x000D_
			return new Rectangle(r1.x, r2.y, r1.width, r1.height + r2.height);_x000D_
		} else if(position == Position.Primary && !axis.isHorizontalAxis()) {_x000D_
			return new Rectangle(r2.x, r1.y, r1.width + r2.width, r1.height);_x000D_
		} else if(position == Position.Secondary && !axis.isHorizontalAxis()) {_x000D_
			return new Rectangle(r1.x, r1.y, r1.width + r2.width, r1.height);_x000D_
		} else {_x000D_
			throw new IllegalStateException("unknown axis position");_x000D_
		}_x000D_
	}_x000D_
_x000D_
	/*_x000D_
	 * @see IAxisTick#getTickLabelValues()_x000D_
	 */_x000D_
	public double[] getTickLabelValues() {_x000D_
_x000D_
		List<Double> list = axisTickLabels.getTickLabelValues();_x000D_
		double[] values = new double[list.size()];_x000D_
		for(int i = 0; i < values.length; i++) {_x000D_
			values[i] = list.get(i);_x000D_
		}_x000D_
		return values;_x000D_
	}_x000D_
_x000D_
	/**_x000D_
	 * Updates the tick around per 64 pixel._x000D_
	 *_x000D_
	 * @param length_x000D_
	 *            the axis length_x000D_
	 */_x000D_
	public void updateTick(int length) {_x000D_
_x000D_
		if(length <= 0) {_x000D_
			axisTickLabels.update(1);_x000D_
		} else {_x000D_
			axisTickLabels.update(length);_x000D_
		}_x000D_
	}_x000D_
_x000D_
	/**_x000D_
	 * Updates the tick layout._x000D_
	 */_x000D_
	protected void updateLayoutData() {_x000D_
_x000D_
		axisTickLabels.updateLayoutData();_x000D_
		axisTickMarks.updateLayoutData();_x000D_
	}_x000D_
}_x000D_
