00001
00002
00003
00004
00005
00006
00007 package org.swtchart.internal.axis;
00008
00009 import java.text.Format;
00010 import java.util.List;
00011
00012 import org.eclipse.swt.SWT;
00013 import org.eclipse.swt.graphics.Color;
00014 import org.eclipse.swt.graphics.Font;
00015 import org.eclipse.swt.graphics.Rectangle;
00016 import org.swtchart.Chart;
00017 import org.swtchart.IAxisTick;
00018 import org.swtchart.IAxis.Position;
00019
00023 public class AxisTick implements IAxisTick {
00024
00026 private Chart chart;
00027
00029 private Axis axis;
00030
00032 private AxisTickLabels axisTickLabels;
00033
00035 private AxisTickMarks axisTickMarks;
00036
00038 private boolean isVisible;
00039
00041 private int tickMarkStepHint;
00042
00044 private int tickLabelAngle;
00045
00047 private static final int DEFAULT_TICK_MARK_STEP_HINT = 64;
00048
00057 protected AxisTick(Chart chart, Axis axis) {
00058 this.chart = chart;
00059 this.axis = axis;
00060
00061 axisTickLabels = new AxisTickLabels(chart, axis);
00062 axisTickMarks = new AxisTickMarks(chart, axis);
00063 isVisible = true;
00064 tickLabelAngle = 0;
00065 tickMarkStepHint = DEFAULT_TICK_MARK_STEP_HINT;
00066 }
00067
00073 public AxisTickMarks getAxisTickMarks() {
00074 return axisTickMarks;
00075 }
00076
00082 public AxisTickLabels getAxisTickLabels() {
00083 return axisTickLabels;
00084 }
00085
00086
00087
00088
00089 public void setForeground(Color color) {
00090 if (color != null && color.isDisposed()) {
00091 SWT.error(SWT.ERROR_INVALID_ARGUMENT);
00092 }
00093 axisTickMarks.setForeground(color);
00094 axisTickLabels.setForeground(color);
00095 }
00096
00097
00098
00099
00100 public Color getForeground() {
00101 return axisTickMarks.getForeground();
00102 }
00103
00104
00105
00106
00107 public void setFont(Font font) {
00108 if (font != null && font.isDisposed()) {
00109 SWT.error(SWT.ERROR_INVALID_ARGUMENT);
00110 }
00111 axisTickLabels.setFont(font);
00112 chart.updateLayout();
00113 }
00114
00115
00116
00117
00118 public Font getFont() {
00119 return axisTickLabels.getFont();
00120 }
00121
00122
00123
00124
00125 public boolean isVisible() {
00126 return isVisible;
00127 }
00128
00129
00130
00131
00132 public void setVisible(boolean isVisible) {
00133 this.isVisible = isVisible;
00134 chart.updateLayout();
00135 }
00136
00137
00138
00139
00140 public int getTickMarkStepHint() {
00141 return tickMarkStepHint;
00142 }
00143
00144
00145
00146
00147 public void setTickMarkStepHint(int tickMarkStepHint) {
00148 if (tickMarkStepHint < MIN_GRID_STEP_HINT) {
00149 this.tickMarkStepHint = DEFAULT_TICK_MARK_STEP_HINT;
00150 } else {
00151 this.tickMarkStepHint = tickMarkStepHint;
00152 }
00153 chart.updateLayout();
00154 }
00155
00156
00157
00158
00159 public int getTickLabelAngle() {
00160 return tickLabelAngle;
00161 }
00162
00163
00164
00165
00166 public void setTickLabelAngle(int angle) {
00167 if (angle < 0 || 90 < angle) {
00168 SWT.error(SWT.ERROR_INVALID_ARGUMENT);
00169 }
00170
00171 if (tickLabelAngle != angle) {
00172 tickLabelAngle = angle;
00173 chart.updateLayout();
00174 }
00175 }
00176
00177
00178
00179
00180 public void setFormat(Format format) {
00181 axisTickLabels.setFormat(format);
00182 chart.updateLayout();
00183 }
00184
00185
00186
00187
00188 public Format getFormat() {
00189 return axisTickLabels.getFormat();
00190 }
00191
00192
00193
00194
00195 public Rectangle getBounds() {
00196 Rectangle r1 = axisTickMarks.getBounds();
00197 Rectangle r2 = axisTickLabels.getBounds();
00198 Position position = axis.getPosition();
00199
00200 if (position == Position.Primary && axis.isHorizontalAxis()) {
00201 return new Rectangle(r1.x, r1.y, r1.width, r1.height + r2.height);
00202 } else if (position == Position.Secondary && axis.isHorizontalAxis()) {
00203 return new Rectangle(r1.x, r2.y, r1.width, r1.height + r2.height);
00204 } else if (position == Position.Primary && !axis.isHorizontalAxis()) {
00205 return new Rectangle(r2.x, r1.y, r1.width + r2.width, r1.height);
00206 } else if (position == Position.Secondary && !axis.isHorizontalAxis()) {
00207 return new Rectangle(r1.x, r1.y, r1.width + r2.width, r1.height);
00208 } else {
00209 throw new IllegalStateException("unknown axis position");
00210 }
00211 }
00212
00213
00214
00215
00216 public double[] getTickLabelValues() {
00217 List<Double> list = axisTickLabels.getTickLabelValues();
00218
00219 double[] values = new double[list.size()];
00220 for (int i = 0; i < values.length; i++) {
00221 values[i] = list.get(i);
00222 }
00223
00224 return values;
00225 }
00226
00233 public void updateTick(int length) {
00234 if (length <= 0) {
00235 axisTickLabels.update(1);
00236 } else {
00237 axisTickLabels.update(length);
00238 }
00239 }
00240
00244 protected void updateLayoutData() {
00245 axisTickLabels.updateLayoutData();
00246 axisTickMarks.updateLayoutData();
00247 }
00248
00249 }