1 package org.columba.calendar.ui.navigation; 19 20 import java.awt.Color ; 21 import java.awt.Font ; 22 import java.awt.Graphics2D ; 23 import java.awt.Rectangle ; 24 import java.awt.RenderingHints ; 25 import java.awt.geom.Rectangle2D ; 26 import java.beans.PropertyChangeEvent ; 27 import java.text.DateFormat ; 28 import java.text.SimpleDateFormat ; 29 import java.util.Calendar ; 30 31 import javax.swing.BorderFactory ; 32 import javax.swing.SwingConstants ; 33 import javax.swing.UIManager ; 34 35 import org.columba.calendar.ui.calendar.ActivityShapeFactory; 36 37 import com.miginfocom.ashape.shapes.RootAShape; 38 import com.miginfocom.ashape.shapes.TextAShape; 39 import com.miginfocom.beans.DateAreaBean; 40 import com.miginfocom.beans.DateHeaderBean; 41 import com.miginfocom.beans.GridDimensionLayoutBean; 42 import com.miginfocom.calendar.datearea.DateArea; 43 import com.miginfocom.calendar.datearea.DefaultDateArea; 44 import com.miginfocom.calendar.decorators.AbstractGridDecorator; 45 import com.miginfocom.calendar.decorators.DateSeparatorDecorator; 46 import com.miginfocom.calendar.decorators.SelectionGridDecorator; 47 import com.miginfocom.calendar.grid.DateGrid; 48 import com.miginfocom.calendar.grid.DefaultGridLineProvider; 49 import com.miginfocom.calendar.grid.Grid; 50 import com.miginfocom.calendar.grid.GridLineRepetition; 51 import com.miginfocom.calendar.grid.GridLineSpecProvider; 52 import com.miginfocom.calendar.grid.GridLineSpecification; 53 import com.miginfocom.calendar.header.CellDecorationRow; 54 import com.miginfocom.calendar.header.DateGridHeader; 55 import com.miginfocom.util.dates.DateFormatList; 56 import com.miginfocom.util.dates.DateRange; 57 import com.miginfocom.util.dates.DateRangeI; 58 import com.miginfocom.util.gfx.GfxUtil; 59 import com.miginfocom.util.gfx.geometry.AbsRect; 60 import com.miginfocom.util.gfx.geometry.SizeSpec; 61 import com.miginfocom.util.gfx.geometry.numbers.AtEnd; 62 import com.miginfocom.util.gfx.geometry.numbers.AtFixed; 63 import com.miginfocom.util.gfx.geometry.numbers.AtFraction; 64 import com.miginfocom.util.gfx.geometry.numbers.AtStart; 65 import com.miginfocom.util.repetition.DefaultRepetition; 66 67 public class DateAreaBeanFactory { 68 69 private static final Color labelColor = Color.DARK_GRAY; 70 71 private static final Color darkGrayColor = new Color (220, 220, 220); 73 74 private static final Color lightGrayColor = new Color (240, 240, 240); 75 76 private static final Color darkDarkGrayColor = new Color (180, 180, 180); 77 78 public static final RootAShape HORSHAPE = ActivityShapeFactory 79 .createDefaultShape(SwingConstants.HORIZONTAL); 80 81 public static final RootAShape VERSHAPE = ActivityShapeFactory 82 .createDefaultShape(SwingConstants.VERTICAL); 83 84 public static DateAreaBean initDateArea() { 85 86 GridDimensionLayoutBean monthlyVerticalGridDimensionLayout = new GridDimensionLayoutBean(); 87 GridDimensionLayoutBean monthlyHorizontalGridDimensionLayout = new GridDimensionLayoutBean(); 88 DateHeaderBean monthlyNorthDateHeaderBean = new DateHeaderBean(); 90 91 DateAreaBean monthlyDateAreaBean = new DateAreaBean(); 92 93 monthlyHorizontalGridDimensionLayout.setRowSizeNormal(new SizeSpec( 94 new AtFixed(17.0f), null, null)); 95 96 DateHeaderBean monthlyWestDateHeaderBean = new DateHeaderBean(); 97 100 monthlyWestDateHeaderBean.setHeaderRows(new CellDecorationRow[] { 101 new CellDecorationRow(DateRangeI.RANGE_TYPE_WEEK, 103 new DateFormatList("'w'w", null), new AtFixed(24f), 104 new AbsRect(new AtStart(0.0f), new AtStart(0.0f), 105 new AtEnd(0.0f), new AtEnd(0.0f), null, null, 106 null), (java.awt.Paint []) null, 107 new java.awt.Paint [] { labelColor }, 108 new DefaultRepetition(0, 1, null, null), 109 new java.awt.Font [] { UIManager.getFont("Label.font") 110 .deriveFont(9f) }, 111 new java.lang.Integer [] { null }, new AtFraction(0.5f), 112 new AtStart(4f)) }); 113 114 monthlyWestDateHeaderBean 115 .setBackgroundPaint(new com.miginfocom.util.gfx.ShapeGradientPaint( 116 new java.awt.Color (255, 255, 255), new java.awt.Color ( 117 247, 247, 247), 0.0f, 0.7f, 0.6f, false)); 118 119 monthlyWestDateHeaderBean 120 .setTextAntiAlias(com.miginfocom.util.gfx.GfxUtil.AA_HINT_ON); 121 122 DateHeaderBean eastDateHeaderBean = new DateHeaderBean(); 123 eastDateHeaderBean 124 .setHeaderRows(new CellDecorationRow[] { 125 new CellDecorationRow( 127 DateRangeI.RANGE_TYPE_MONTH, 128 new DateFormatList("MMMM|MMM", null), 129 new AtFixed(17f), 130 new AbsRect(new AtStart(0.0f), new AtStart(0.0f), 131 new AtEnd(0.0f), new AtEnd(0.0f), null, null, 132 null), 133 (java.awt.Paint []) null, 134 new java.awt.Paint [] { labelColor }, 135 new DefaultRepetition(0, 1, null, null), 136 new java.awt.Font [] { UIManager.getFont("Label.font") }, 137 new java.lang.Integer [] { null }, new AtFraction(0.5f), 138 new AtStart(4f)) }); 139 140 eastDateHeaderBean 141 .setBackgroundPaint(new com.miginfocom.util.gfx.ShapeGradientPaint( 142 new java.awt.Color (255, 255, 255), new java.awt.Color ( 143 247, 247, 247), 180.0f, 0.7f, 0.6f, false)); 144 145 eastDateHeaderBean 146 .setTextAntiAlias(com.miginfocom.util.gfx.GfxUtil.AA_HINT_ON); 147 148 eastDateHeaderBean.setLabelRotation(TextAShape.TYPE_SINGE_LINE_ROT_CW); 149 150 monthlyNorthDateHeaderBean 151 .setBackgroundPaint(new com.miginfocom.util.gfx.ShapeGradientPaint( 152 new java.awt.Color (240, 240, 240), new java.awt.Color ( 153 255, 255, 255), 90.0f, 0.7f, 0.6f, false)); 154 155 monthlyNorthDateHeaderBean 156 .setHeaderRows(new CellDecorationRow[] { new com.miginfocom.calendar.header.CellDecorationRow( 157 DateRangeI.RANGE_TYPE_DAY, new DateFormatList("1E", 158 null), new AtFixed(20.0f), new AbsRect( 159 new AtStart(0.0f), new AtStart(0.0f), 160 new AtEnd(0.0f), new AtEnd(0.0f), null, null, 161 null), (java.awt.Paint []) null, 162 new java.awt.Paint [] { labelColor }, null, 163 new Font [] { UIManager.getFont("Label.font") }, 164 new Integer [] { null }, new AtFraction(0.5f), 165 new AtFraction(0.5f)) }); 166 167 monthlyNorthDateHeaderBean.setTextAntiAlias(GfxUtil.AA_HINT_ON); 168 169 monthlyDateAreaBean.setDateAreaOuterBorder(BorderFactory 170 .createLineBorder(lightGrayColor)); 171 172 monthlyDateAreaBean.setNorthDateHeader(monthlyNorthDateHeaderBean); 173 monthlyDateAreaBean.setWestDateHeader(monthlyWestDateHeaderBean); 174 monthlyDateAreaBean.setEastDateHeader(eastDateHeaderBean); 175 monthlyDateAreaBean 176 .setPrimaryDimensionLayout(monthlyVerticalGridDimensionLayout); 177 monthlyDateAreaBean 178 .setSecondaryDimensionLayout(monthlyHorizontalGridDimensionLayout); 179 180 ((DateGridHeader) monthlyWestDateHeaderBean.getHeader()) 181 .setGridLineSpecification(new GridLineSpecification( 182 new DefaultGridLineProvider(new GridLineRepetition[] { 183 new GridLineRepetition(0, 1, new AtStart(0f), 185 null, 1, lightGrayColor, 186 new AtStart(3f), new AtEnd(-3f)) 187 188 }), null 189 190 )); 191 ((DateGridHeader) monthlyNorthDateHeaderBean.getHeader()) 192 .setGridLineSpecification(new GridLineSpecification( 193 new DefaultGridLineProvider(new GridLineRepetition[] { 194 new GridLineRepetition(0, 1, new AtStart(0f), 196 null, 1, lightGrayColor, 197 new AtStart(3f), new AtEnd(-3f)) 198 199 }), null 200 201 )); 202 monthlyDateAreaBean.getDateArea().setGridLineSpecProvider( 204 new GridLineSpecProvider() { 205 public GridLineSpecification createSpecification( 206 DateArea dateArea) { 207 return new GridLineSpecification( 208 new DefaultGridLineProvider( 210 new GridLineRepetition[] { 211 new GridLineRepetition(0, 1, 213 new AtStart(0.1f), new AtEnd( 214 -1f), 1, lightGrayColor) }), 215 new DefaultGridLineProvider( 217 new GridLineRepetition[] { 218 new GridLineRepetition(0, 1, null, 220 null, 1, lightGrayColor) }), new DefaultGridLineProvider( 224 new GridLineRepetition[] { 225 new GridLineRepetition(0, 1, 227 new AtStart(1f), 228 new AtEnd(-2f), 1, 229 lightGrayColor) })); 230 } 231 }); 232 233 monthlyDateAreaBean.setPrimaryDimension(SwingConstants.HORIZONTAL); 234 monthlyDateAreaBean 235 .setPrimaryDimensionCellType(DateRangeI.RANGE_TYPE_DAY); 236 monthlyDateAreaBean.setPrimaryDimensionCellTypeCount(1); 237 monthlyDateAreaBean.setWrapBoundary(DateRangeI.RANGE_TYPE_WEEK); 238 239 DefaultDateArea dateArea = monthlyDateAreaBean.getDateArea(); 240 dateArea.setActivitiesSupported(false); 241 242 monthlyDateAreaBean.getDateArea() 244 .addDecorator( 245 new AbstractGridDecorator(monthlyDateAreaBean 246 .getDateArea(), 20) { 247 public void doPaint(Graphics2D g2, Rectangle bounds) { 248 DateGrid dateGrid = (DateGrid) getGrid(); 249 250 DateRangeI dr = new DateRange(System 251 .currentTimeMillis(), 252 DateRangeI.RANGE_TYPE_DAY, 1, null, 253 null); 254 Rectangle [] rects = dateGrid 255 .getBoundsForDateRange(dr, 256 Grid.SIZE_MODE_INSIDE); 257 258 g2.setColor(new Color (250, 250, 250)); 259 for (int i = 0; i < rects.length; i++) 260 g2.fill(rects[i]); 261 } 262 263 public void gridChanged(PropertyChangeEvent e) { 264 } 265 266 public void dispose() { 267 } 268 }); 269 270 final DateFormat defaultFormat = new SimpleDateFormat ("MMMM dd"); 271 272 monthlyDateAreaBean.getDateArea() 273 .addDecorator( 274 new AbstractGridDecorator(monthlyDateAreaBean 275 .getDateArea(), 20) { 276 public void doPaint(Graphics2D g2, Rectangle bounds) { 277 DateGrid dateGrid = (DateGrid) getGrid(); 278 279 RenderingHints qualityHints = new RenderingHints ( 280 RenderingHints.KEY_ANTIALIASING, 281 RenderingHints.VALUE_ANTIALIAS_ON); 282 g2.setRenderingHints(qualityHints); 283 284 g2.setFont(UIManager.getFont("Label.font")); 285 286 for (int i = 0; i < dateGrid.getRowCount(); i++) { 287 for (int j = 0; j < dateGrid 288 .getColumnCount(); j++) { 289 Rectangle r = dateGrid.getBoundsOfCell( 290 i, j, Grid.SIZE_MODE_INSIDE, 291 true); 292 DateRangeI range = dateGrid 293 .getDateRangeForCell(i, j); 294 int day = range.getStart().get( 295 Calendar.DAY_OF_MONTH); 296 int weekday = range.getStart().get( 297 Calendar.DAY_OF_WEEK); 298 if (weekday == Calendar.SUNDAY) 299 g2 300 .setColor(new Color (255, 301 102, 102)); 302 else 303 g2.setColor(darkDarkGrayColor); 304 String dayString = new Integer (day) 305 .toString(); 306 307 Rectangle2D rect = g2.getFontMetrics() 308 .getStringBounds(dayString, g2); 309 310 int x2 = r.x + r.width / 2 - 1; 311 x2 -= Math.abs(rect.getWidth() / 2); 312 int y2 = r.y; 313 y2 += Math.abs(rect.getHeight()); 314 g2.drawString(dayString, x2, y2); 315 316 } 317 318 } 319 320 } 321 322 public void gridChanged(PropertyChangeEvent e) { 323 } 324 325 public void dispose() { 326 } 327 }); 328 monthlyDateAreaBean.getDateArea() 329 .addDecorator( 330 new SelectionGridDecorator(monthlyDateAreaBean 331 .getDateArea(), 10, new java.awt.Paint [] { 332 lightGrayColor, null, new Color (255,255,230,255), null }, 333 new int[] { Grid.SIZE_MODE_INSIDE, 334 Grid.SIZE_MODE_INSIDE, 335 Grid.SIZE_MODE_INSIDE, 336 Grid.SIZE_MODE_INSIDE })); 337 dateArea.addDecorator(new DateSeparatorDecorator(dateArea, 700, 338 DateRangeI.RANGE_TYPE_MONTH, darkDarkGrayColor)); 339 340 344 dateArea.setActivitiesSupported(false); 345 346 return monthlyDateAreaBean; 347 } 348 349 } 350 | Popular Tags |