KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > DateTitle


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * --------------
23  * DateTitle.java
24  * --------------
25  * (C) Copyright 2000-2003, by David Berry and Contributors.
26  *
27  * Original Author: David Berry;
28  * Contributor(s): David Gilbert (for Object Refinery Limited);
29  *
30  * $Id: DateTitle.java,v 1.5 2003/09/22 12:58:20 taqua Exp $
31  *
32  * Changes (from 18-Sep-2001)
33  * --------------------------
34  * 18-Sep-2001 : Added standard header (DG);
35  * 09-Jan-2002 : Updated Javadoc comments (DG);
36  * 07-Feb-2002 : Changed blank space around title from Insets --> Spacer, to allow for relative
37  * or absolute spacing (DG);
38  * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
39  *
40  */

41
42 package org.jfree.chart;
43
44 import java.awt.Color JavaDoc;
45 import java.awt.Font JavaDoc;
46 import java.awt.Paint JavaDoc;
47 import java.text.DateFormat JavaDoc;
48 import java.util.Date JavaDoc;
49 import java.util.Locale JavaDoc;
50
51 /**
52  * A chart title that displays the date.
53  * <p>
54  * Keep in mind that a chart can have several titles, and that they can appear at the top, left,
55  * right or bottom of the chart - a <code>DateTitle</code> will commonly appear at the bottom of
56  * a chart, although you can place it anywhere.
57  * <P>
58  * By specifying the locale, dates are formatted to the correct standard for
59  * the given locale. For example, a date would appear as "January 17, 2000" in
60  * the US, but "17 January 2000" in most European locales.
61  *
62  * @author David Berry
63  */

64 public class DateTitle extends TextTitle {
65
66     /**
67      * Creates a new chart title that displays the current date in the default
68      * (LONG) format for the locale, positioned to the bottom right of the chart.
69      * <P>
70      * The color will be black in 12 point, plain Helvetica font (maps to Arial
71      * on Win32 systems without Helvetica).
72      */

73     public DateTitle() {
74
75         this(DateFormat.LONG);
76
77     }
78
79     /**
80      * Creates a new chart title that displays the current date with the specified style
81      * (for the default locale).
82      * <P>
83      * The date style should be one of: <code>SHORT</code>, <code>MEDIUM</code>,
84      * <code>LONG</code> or <code>FULL</code> (defined in <code>java.util.DateFormat<code>).
85      *
86      * @param style the date style.
87      */

88     public DateTitle(int style) {
89         this(style, Locale.getDefault(),
90              new Font JavaDoc("Dialog", Font.PLAIN, 12), Color.black);
91     }
92
93     /**
94      * Creates a new chart title that displays the current date.
95      * <p>
96      * The date style should be one of: <code>SHORT</code>, <code>MEDIUM</code>,
97      * <code>LONG</code> or <code>FULL</code> (defined in <code>java.util.DateFormat<code>).
98      * <P>
99      * For the locale, you can use <code>Locale.getDefault()</code> for the default locale.
100      *
101      * @param style the date style.
102      * @param locale the locale.
103      * @param font the font.
104      * @param paint the text color.
105      */

106     public DateTitle(int style, Locale JavaDoc locale, Font JavaDoc font, Paint JavaDoc paint) {
107
108         this(style, locale, font, paint,
109              AbstractTitle.BOTTOM,
110              AbstractTitle.RIGHT,
111              AbstractTitle.MIDDLE,
112              AbstractTitle.DEFAULT_SPACER);
113     }
114
115     /**
116      * Creates a new chart title that displays the current date.
117      * <p>
118      * The date style should be one of: <code>SHORT</code>, <code>MEDIUM</code>,
119      * <code>LONG</code> or <code>FULL</code> (defined in <code>java.util.DateFormat<code>).
120      * <P>
121      * For the locale, you can use <code>Locale.getDefault()</code> for the default locale.
122      *
123      * @param style the date style.
124      * @param locale the locale.
125      * @param font the font (not null).
126      * @param paint the text color (not null).
127      * @param position the relative location of this title (use constants in AbstractTitle).
128      * @param horizontalAlignment the horizontal text alignment of this title (use constants
129      * in AbstractTitle).
130      * @param verticalAlignment the vertical text alignment of this title (use constants in
131      * AbstractTitle).
132      * @param spacer determines the blank space around the outside of the title (not null).
133      */

134     public DateTitle(int style, Locale JavaDoc locale, Font JavaDoc font, Paint JavaDoc paint,
135                      int position, int horizontalAlignment, int verticalAlignment,
136                      Spacer spacer) {
137
138         super(DateFormat.getDateInstance(style, locale).format(new Date JavaDoc()),
139               font, paint,
140               position, horizontalAlignment, verticalAlignment,
141               spacer);
142
143     }
144
145     /**
146      * Set the format of the date.
147      * <P>
148      * The date style should be one of: <code>SHORT</code>, <code>MEDIUM</code>,
149      * <code>LONG</code> or <code>FULL</code> (defined in <code>java.util.DateFormat<code>).
150      * <P>
151      * For the locale, you can use <code>Locale.getDefault()</code> for the default locale.
152      *
153      * @param style the date style.
154      * @param locale the locale.
155      */

156     public void setDateFormat(int style, Locale JavaDoc locale) {
157
158         setText(DateFormat.getDateInstance(style, locale).format(new Date JavaDoc()));
159
160     }
161
162 }
163
Popular Tags