00001 /******************************************************************************* 00002 * Copyright (c) 2008-2014 SWTChart project. All rights reserved. 00003 * 00004 * This code is distributed under the terms of the Eclipse Public License v1.0 00005 * which is available at http://www.eclipse.org/legal/epl-v10.html 00006 *******************************************************************************/ 00007 package org.swtchart.internal.axis; 00008 00009 import org.eclipse.swt.SWT; 00010 import org.eclipse.swt.graphics.Font; 00011 import org.eclipse.swt.widgets.Display; 00012 import org.swtchart.Chart; 00013 import org.swtchart.Constants; 00014 import org.swtchart.IAxis.Direction; 00015 import org.swtchart.internal.Title; 00016 00020 public class AxisTitle extends Title { 00021 00023 private static final String DEFAULT_TEXT_FOR_XAXIS = "X Axis"; 00024 00026 private static final String DEFAULT_TEXT_FOR_YAXIS = "Y Axis"; 00027 00029 private static final int DEFAULT_FONT_SIZE = Constants.MEDIUM_FONT_SIZE; 00030 00032 private final Font defaultFont; 00033 00035 private final Axis axis; 00036 00038 private final Direction direction; 00039 00052 public AxisTitle(Chart chart, int style, Axis axis, Direction direction) { 00053 super(chart); 00054 this.axis = axis; 00055 this.direction = direction; 00056 defaultFont = new Font(Display.getDefault(), "Tahoma", 00057 DEFAULT_FONT_SIZE, SWT.BOLD); 00058 setFont(defaultFont); 00059 setText(getDefaultText()); 00060 } 00061 00062 /* 00063 * @see Title#getDefaultText() 00064 */ 00065 @Override 00066 protected String getDefaultText() { 00067 if (direction == Direction.X) { 00068 return DEFAULT_TEXT_FOR_XAXIS; 00069 } 00070 return DEFAULT_TEXT_FOR_YAXIS; 00071 } 00072 00073 /* 00074 * @see Title#isHorizontal() 00075 */ 00076 @Override 00077 protected boolean isHorizontal() { 00078 return axis.isHorizontalAxis(); 00079 } 00080 00081 /* 00082 * @see Title#dispose() 00083 */ 00084 @Override 00085 public void dispose() { 00086 super.dispose(); 00087 if (!defaultFont.isDisposed()) { 00088 defaultFont.dispose(); 00089 } 00090 } 00091 }