001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.calendar.ui.navigation;
019:
020: import java.awt.Color;
021: import java.awt.Font;
022: import java.awt.Graphics2D;
023: import java.awt.Rectangle;
024: import java.awt.RenderingHints;
025: import java.awt.geom.Rectangle2D;
026: import java.beans.PropertyChangeEvent;
027: import java.text.DateFormat;
028: import java.text.SimpleDateFormat;
029: import java.util.Calendar;
030:
031: import javax.swing.BorderFactory;
032: import javax.swing.SwingConstants;
033: import javax.swing.UIManager;
034:
035: import org.columba.calendar.ui.calendar.ActivityShapeFactory;
036:
037: import com.miginfocom.ashape.shapes.RootAShape;
038: import com.miginfocom.ashape.shapes.TextAShape;
039: import com.miginfocom.beans.DateAreaBean;
040: import com.miginfocom.beans.DateHeaderBean;
041: import com.miginfocom.beans.GridDimensionLayoutBean;
042: import com.miginfocom.calendar.datearea.DateArea;
043: import com.miginfocom.calendar.datearea.DefaultDateArea;
044: import com.miginfocom.calendar.decorators.AbstractGridDecorator;
045: import com.miginfocom.calendar.decorators.DateSeparatorDecorator;
046: import com.miginfocom.calendar.decorators.SelectionGridDecorator;
047: import com.miginfocom.calendar.grid.DateGrid;
048: import com.miginfocom.calendar.grid.DefaultGridLineProvider;
049: import com.miginfocom.calendar.grid.Grid;
050: import com.miginfocom.calendar.grid.GridLineRepetition;
051: import com.miginfocom.calendar.grid.GridLineSpecProvider;
052: import com.miginfocom.calendar.grid.GridLineSpecification;
053: import com.miginfocom.calendar.header.CellDecorationRow;
054: import com.miginfocom.calendar.header.DateGridHeader;
055: import com.miginfocom.util.dates.DateFormatList;
056: import com.miginfocom.util.dates.DateRange;
057: import com.miginfocom.util.dates.DateRangeI;
058: import com.miginfocom.util.gfx.GfxUtil;
059: import com.miginfocom.util.gfx.geometry.AbsRect;
060: import com.miginfocom.util.gfx.geometry.SizeSpec;
061: import com.miginfocom.util.gfx.geometry.numbers.AtEnd;
062: import com.miginfocom.util.gfx.geometry.numbers.AtFixed;
063: import com.miginfocom.util.gfx.geometry.numbers.AtFraction;
064: import com.miginfocom.util.gfx.geometry.numbers.AtStart;
065: import com.miginfocom.util.repetition.DefaultRepetition;
066:
067: public class DateAreaBeanFactory {
068:
069: private static final Color labelColor = Color.DARK_GRAY;
070:
071: // glocal grid line colors
072: private static final Color darkGrayColor = new Color(220, 220, 220);
073:
074: private static final Color lightGrayColor = new Color(240, 240, 240);
075:
076: private static final Color darkDarkGrayColor = new Color(180, 180,
077: 180);
078:
079: public static final RootAShape HORSHAPE = ActivityShapeFactory
080: .createDefaultShape(SwingConstants.HORIZONTAL);
081:
082: public static final RootAShape VERSHAPE = ActivityShapeFactory
083: .createDefaultShape(SwingConstants.VERTICAL);
084:
085: public static DateAreaBean initDateArea() {
086:
087: GridDimensionLayoutBean monthlyVerticalGridDimensionLayout = new GridDimensionLayoutBean();
088: GridDimensionLayoutBean monthlyHorizontalGridDimensionLayout = new GridDimensionLayoutBean();
089: // monthlyActivityAShapeBean = new ActivityAShapeBean();
090: DateHeaderBean monthlyNorthDateHeaderBean = new DateHeaderBean();
091:
092: DateAreaBean monthlyDateAreaBean = new DateAreaBean();
093:
094: monthlyHorizontalGridDimensionLayout
095: .setRowSizeNormal(new SizeSpec(new AtFixed(17.0f),
096: null, null));
097:
098: DateHeaderBean monthlyWestDateHeaderBean = new DateHeaderBean();
099: // monthlyWestDateHeaderBean
100: // .setLabelRotation(TextAShape.TYPE_SINGE_LINE_ROT_CCW);
101:
102: monthlyWestDateHeaderBean
103: .setHeaderRows(new CellDecorationRow[] {
104: // showing the week number
105: new CellDecorationRow(DateRangeI.RANGE_TYPE_WEEK,
106: new DateFormatList("'w'w", null), new AtFixed(
107: 24f), new AbsRect(new AtStart(0.0f),
108: new AtStart(0.0f), new AtEnd(0.0f),
109: new AtEnd(0.0f), null, null, null),
110: (java.awt.Paint[]) null,
111: new java.awt.Paint[] { labelColor },
112: new DefaultRepetition(0, 1, null, null),
113: new java.awt.Font[] { UIManager.getFont(
114: "Label.font").deriveFont(9f) },
115: new java.lang.Integer[] { null },
116: new AtFraction(0.5f), new AtStart(4f)) });
117:
118: monthlyWestDateHeaderBean
119: .setBackgroundPaint(new com.miginfocom.util.gfx.ShapeGradientPaint(
120: new java.awt.Color(255, 255, 255),
121: new java.awt.Color(247, 247, 247), 0.0f, 0.7f,
122: 0.6f, false));
123:
124: monthlyWestDateHeaderBean
125: .setTextAntiAlias(com.miginfocom.util.gfx.GfxUtil.AA_HINT_ON);
126:
127: DateHeaderBean eastDateHeaderBean = new DateHeaderBean();
128: eastDateHeaderBean.setHeaderRows(new CellDecorationRow[] {
129: // showing the month number
130: new CellDecorationRow(DateRangeI.RANGE_TYPE_MONTH,
131: new DateFormatList("MMMM|MMM", null),
132: new AtFixed(17f), new AbsRect(
133: new AtStart(0.0f), new AtStart(0.0f),
134: new AtEnd(0.0f), new AtEnd(0.0f), null,
135: null, null), (java.awt.Paint[]) null,
136: new java.awt.Paint[] { labelColor },
137: new DefaultRepetition(0, 1, null, null),
138: new java.awt.Font[] { UIManager
139: .getFont("Label.font") },
140: new java.lang.Integer[] { null },
141: new AtFraction(0.5f), new AtStart(4f)) });
142:
143: eastDateHeaderBean
144: .setBackgroundPaint(new com.miginfocom.util.gfx.ShapeGradientPaint(
145: new java.awt.Color(255, 255, 255),
146: new java.awt.Color(247, 247, 247), 180.0f,
147: 0.7f, 0.6f, false));
148:
149: eastDateHeaderBean
150: .setTextAntiAlias(com.miginfocom.util.gfx.GfxUtil.AA_HINT_ON);
151:
152: eastDateHeaderBean
153: .setLabelRotation(TextAShape.TYPE_SINGE_LINE_ROT_CW);
154:
155: monthlyNorthDateHeaderBean
156: .setBackgroundPaint(new com.miginfocom.util.gfx.ShapeGradientPaint(
157: new java.awt.Color(240, 240, 240),
158: new java.awt.Color(255, 255, 255), 90.0f, 0.7f,
159: 0.6f, false));
160:
161: monthlyNorthDateHeaderBean
162: .setHeaderRows(new CellDecorationRow[] { new com.miginfocom.calendar.header.CellDecorationRow(
163: DateRangeI.RANGE_TYPE_DAY, new DateFormatList(
164: "1E", null), new AtFixed(20.0f),
165: new AbsRect(new AtStart(0.0f),
166: new AtStart(0.0f), new AtEnd(0.0f),
167: new AtEnd(0.0f), null, null, null),
168: (java.awt.Paint[]) null,
169: new java.awt.Paint[] { labelColor }, null,
170: new Font[] { UIManager.getFont("Label.font") },
171: new Integer[] { null }, new AtFraction(0.5f),
172: new AtFraction(0.5f)) });
173:
174: monthlyNorthDateHeaderBean.setTextAntiAlias(GfxUtil.AA_HINT_ON);
175:
176: monthlyDateAreaBean.setDateAreaOuterBorder(BorderFactory
177: .createLineBorder(lightGrayColor));
178:
179: monthlyDateAreaBean
180: .setNorthDateHeader(monthlyNorthDateHeaderBean);
181: monthlyDateAreaBean
182: .setWestDateHeader(monthlyWestDateHeaderBean);
183: monthlyDateAreaBean.setEastDateHeader(eastDateHeaderBean);
184: monthlyDateAreaBean
185: .setPrimaryDimensionLayout(monthlyVerticalGridDimensionLayout);
186: monthlyDateAreaBean
187: .setSecondaryDimensionLayout(monthlyHorizontalGridDimensionLayout);
188:
189: ((DateGridHeader) monthlyWestDateHeaderBean.getHeader())
190: .setGridLineSpecification(new GridLineSpecification(
191: new DefaultGridLineProvider(
192: new GridLineRepetition[] {
193: // horizontal light gray column separator line
194: new GridLineRepetition(0, 1,
195: new AtStart(0f), null, 1,
196: lightGrayColor,
197: new AtStart(3f), new AtEnd(-3f))
198:
199: }), null
200:
201: ));
202: ((DateGridHeader) monthlyNorthDateHeaderBean.getHeader())
203: .setGridLineSpecification(new GridLineSpecification(
204: new DefaultGridLineProvider(
205: new GridLineRepetition[] {
206: // vertical light gray column separator line
207: new GridLineRepetition(0, 1,
208: new AtStart(0f), null, 1,
209: lightGrayColor,
210: new AtStart(3f), new AtEnd(-3f))
211:
212: }), null
213:
214: ));
215: // date area grid line
216: monthlyDateAreaBean.getDateArea().setGridLineSpecProvider(
217: new GridLineSpecProvider() {
218: public GridLineSpecification createSpecification(
219: DateArea dateArea) {
220: return new GridLineSpecification(
221: // horizontal grid lines
222: new DefaultGridLineProvider(
223: new GridLineRepetition[] {
224: // dark gray line at 12 and 13
225: new GridLineRepetition(0, 1,
226: new AtStart(0.1f),
227: new AtEnd(-1f), 1,
228: lightGrayColor) }),
229: // vertical grid lines
230: new DefaultGridLineProvider(
231: new GridLineRepetition[] {
232: // light gray line every day
233: new GridLineRepetition(0, 1,
234: null, null, 1,
235: lightGrayColor) }),// vertical
236: // grid
237: // lines
238: new DefaultGridLineProvider(
239: new GridLineRepetition[] {
240: // light gray line every day
241: new GridLineRepetition(0, 1,
242: new AtStart(1f),
243: new AtEnd(-2f), 1,
244: lightGrayColor) }));
245: }
246: });
247:
248: monthlyDateAreaBean
249: .setPrimaryDimension(SwingConstants.HORIZONTAL);
250: monthlyDateAreaBean
251: .setPrimaryDimensionCellType(DateRangeI.RANGE_TYPE_DAY);
252: monthlyDateAreaBean.setPrimaryDimensionCellTypeCount(1);
253: monthlyDateAreaBean.setWrapBoundary(DateRangeI.RANGE_TYPE_WEEK);
254:
255: DefaultDateArea dateArea = monthlyDateAreaBean.getDateArea();
256: dateArea.setActivitiesSupported(false);
257:
258: // select current day
259: monthlyDateAreaBean.getDateArea().addDecorator(
260: new AbstractGridDecorator(monthlyDateAreaBean
261: .getDateArea(), 20) {
262: public void doPaint(Graphics2D g2, Rectangle bounds) {
263: DateGrid dateGrid = (DateGrid) getGrid();
264:
265: DateRangeI dr = new DateRange(System
266: .currentTimeMillis(),
267: DateRangeI.RANGE_TYPE_DAY, 1, null,
268: null);
269: Rectangle[] rects = dateGrid
270: .getBoundsForDateRange(dr,
271: Grid.SIZE_MODE_INSIDE);
272:
273: g2.setColor(new Color(250, 250, 250));
274: for (int i = 0; i < rects.length; i++)
275: g2.fill(rects[i]);
276: }
277:
278: public void gridChanged(PropertyChangeEvent e) {
279: }
280:
281: public void dispose() {
282: }
283: });
284:
285: final DateFormat defaultFormat = new SimpleDateFormat("MMMM dd");
286:
287: monthlyDateAreaBean.getDateArea().addDecorator(
288: new AbstractGridDecorator(monthlyDateAreaBean
289: .getDateArea(), 20) {
290: public void doPaint(Graphics2D g2, Rectangle bounds) {
291: DateGrid dateGrid = (DateGrid) getGrid();
292:
293: RenderingHints qualityHints = new RenderingHints(
294: RenderingHints.KEY_ANTIALIASING,
295: RenderingHints.VALUE_ANTIALIAS_ON);
296: g2.setRenderingHints(qualityHints);
297:
298: g2.setFont(UIManager.getFont("Label.font"));
299:
300: for (int i = 0; i < dateGrid.getRowCount(); i++) {
301: for (int j = 0; j < dateGrid
302: .getColumnCount(); j++) {
303: Rectangle r = dateGrid.getBoundsOfCell(
304: i, j, Grid.SIZE_MODE_INSIDE,
305: true);
306: DateRangeI range = dateGrid
307: .getDateRangeForCell(i, j);
308: int day = range.getStart().get(
309: Calendar.DAY_OF_MONTH);
310: int weekday = range.getStart().get(
311: Calendar.DAY_OF_WEEK);
312: if (weekday == Calendar.SUNDAY)
313: g2
314: .setColor(new Color(255,
315: 102, 102));
316: else
317: g2.setColor(darkDarkGrayColor);
318: String dayString = new Integer(day)
319: .toString();
320:
321: Rectangle2D rect = g2.getFontMetrics()
322: .getStringBounds(dayString, g2);
323:
324: int x2 = r.x + r.width / 2 - 1;
325: x2 -= Math.abs(rect.getWidth() / 2);
326: int y2 = r.y;
327: y2 += Math.abs(rect.getHeight());
328: g2.drawString(dayString, x2, y2);
329:
330: }
331:
332: }
333:
334: }
335:
336: public void gridChanged(PropertyChangeEvent e) {
337: }
338:
339: public void dispose() {
340: }
341: });
342: monthlyDateAreaBean.getDateArea().addDecorator(
343: new SelectionGridDecorator(monthlyDateAreaBean
344: .getDateArea(), 10, new java.awt.Paint[] {
345: lightGrayColor, null,
346: new Color(255, 255, 230, 255), null },
347: new int[] { Grid.SIZE_MODE_INSIDE,
348: Grid.SIZE_MODE_INSIDE,
349: Grid.SIZE_MODE_INSIDE,
350: Grid.SIZE_MODE_INSIDE }));
351: dateArea.addDecorator(new DateSeparatorDecorator(dateArea, 700,
352: DateRangeI.RANGE_TYPE_MONTH, darkDarkGrayColor));
353:
354: //
355: // activity setup
356: //
357:
358: dateArea.setActivitiesSupported(false);
359:
360: return monthlyDateAreaBean;
361: }
362:
363: }
|