1 package org.columba.calendar.ui.calendar; 19 20 import java.awt.BasicStroke ; 21 import java.awt.Color ; 22 import java.awt.Cursor ; 23 import java.awt.Font ; 24 import java.awt.Insets ; 25 import java.awt.event.MouseEvent ; 26 27 import javax.swing.SwingConstants ; 28 import javax.swing.UIManager ; 29 30 import org.columba.calendar.parser.ParserHelper; 31 32 import com.miginfocom.ashape.AShapeUtil; 33 import com.miginfocom.ashape.interaction.DefaultInteractionBroker; 34 import com.miginfocom.ashape.interaction.MouseKeyInteractor; 35 import com.miginfocom.ashape.interaction.OverrideFilter; 36 import com.miginfocom.ashape.shapes.AShape; 37 import com.miginfocom.ashape.shapes.ContainerAShape; 38 import com.miginfocom.ashape.shapes.DrawAShape; 39 import com.miginfocom.ashape.shapes.FeatherAShape; 40 import com.miginfocom.ashape.shapes.FillAShape; 41 import com.miginfocom.ashape.shapes.RootAShape; 42 import com.miginfocom.ashape.shapes.TextAShape; 43 import com.miginfocom.calendar.activity.Activity; 44 import com.miginfocom.calendar.activity.ActivityInteractor; 45 import com.miginfocom.calendar.activity.view.ActivityView; 46 import com.miginfocom.calendar.datearea.DefaultDateArea; 47 import com.miginfocom.util.command.DefaultCommand; 48 import com.miginfocom.util.gfx.GfxUtil; 49 import com.miginfocom.util.gfx.RoundRectangle; 50 import com.miginfocom.util.gfx.SliceSpec; 51 import com.miginfocom.util.gfx.geometry.AbsRect; 52 import com.miginfocom.util.gfx.geometry.PlaceRect; 53 import com.miginfocom.util.gfx.geometry.numbers.AtEnd; 54 import com.miginfocom.util.gfx.geometry.numbers.AtStart; 55 import com.miginfocom.util.states.GenericStates; 56 57 public class ActivityShapeFactory { 58 59 public static final String DEFAULT_CONTAINER_SHAPE_NAME = "defaultContainer"; 60 61 public static final String DEFAULT_BACKGROUND_SHAPE_NAME = "defaultBackground"; 62 63 public static final String DEFAULT_TITLE_TEXT_SHAPE_NAME = "defaultTitleText"; 64 65 public static final String DEFAULT_MAIN_TEXT_SHAPE_NAME = "defaultMainText"; 66 67 public static final String DEFAULT_OUTLINE_SHAPE_NAME = "defaultOutline"; 68 69 public static final String DEFAULT_SHADOW_SHAPE_SHAPE_NAME = "defaultShadowShape"; 70 71 public static final String DEFAULT_SHADOW_SHAPE_NAME = "defaultShadow"; 72 73 80 public static RootAShape createDefaultShape(int dimension) { 81 Color bgPaint = new Color (0, 0, 255, 40); 82 Color outlinePaint = new Color (100, 100, 150); 83 Color textPaint = new Color (50, 50, 50); 84 Color shadowPaint = null; 86 87 Font textFont = UIManager.getFont("Label.font"); 88 89 RootAShape root = new RootAShape(); 90 ContainerAShape container = new ContainerAShape( 91 DEFAULT_CONTAINER_SHAPE_NAME, AbsRect.FILL); 92 93 FillAShape bgAShape = new FillAShape(DEFAULT_BACKGROUND_SHAPE_NAME, 94 new RoundRectangle(0, 0, 1, 1, 8, 8), AbsRect.FILL_INSIDE, 95 bgPaint, GfxUtil.AA_HINT_ON); 96 97 PlaceRect titleTextAbsRect = new AbsRect(new AtStart(2), 98 new AtStart(1), new AtEnd(0), new AtEnd(0), null, null, null); 99 TextAShape titleText = new TextAShape(DEFAULT_TITLE_TEXT_SHAPE_NAME, 100 "$startTime$ $summary$", 101 titleTextAbsRect, TextAShape.TYPE_WRAP_TEXT, textFont, 102 textPaint, new AtStart(0), new AtStart(-3), GfxUtil.AA_HINT_ON); 103 titleText.setAttribute(AShape.A_CLIP_TYPE, AShape.CLIP_PARENT_BOUNDS); 108 109 PlaceRect mainTextAbsRect = new AbsRect(new AtStart(2), 110 new AtStart(16), new AtEnd(0), new AtEnd(0), null, null, null); 111 112 TextAShape mainText = new TextAShape(DEFAULT_MAIN_TEXT_SHAPE_NAME, 113 "$summary$", mainTextAbsRect, TextAShape.TYPE_WRAP_TEXT, 114 textFont, textPaint, new AtStart(0), new AtStart(0), 115 GfxUtil.AA_HINT_ON); 116 117 DrawAShape outlineAShape = new DrawAShape(DEFAULT_OUTLINE_SHAPE_NAME, 118 new RoundRectangle(0, 0, 1, 1, 8, 8), AbsRect.FILL, 119 outlinePaint, new BasicStroke (1f), GfxUtil.AA_HINT_ON); 120 outlineAShape.setAttribute(AShape.A_MOUSE_CURSOR, Cursor 121 .getPredefinedCursor(Cursor.MOVE_CURSOR)); 122 outlineAShape.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 123 124 PlaceRect bgAbsRect = new AbsRect(new AtStart(0), new AtStart(0), 125 new AtEnd(0), new AtEnd(0), null, null, 126 new Insets (-2, -2, 2, 2)); 127 FillAShape filledShadow = new FillAShape( 128 DEFAULT_SHADOW_SHAPE_SHAPE_NAME, new RoundRectangle(0, 0, 1, 1, 129 5, 5), bgAbsRect, shadowPaint, GfxUtil.AA_HINT_ON); 130 SliceSpec shwSI = new SliceSpec(new Insets (10, 10, 10, 10), 131 SliceSpec.TYPE_TILE_CUT, SliceSpec.OPT_BORDER); 132 FeatherAShape shadowShape = new FeatherAShape( 133 DEFAULT_SHADOW_SHAPE_NAME, filledShadow, new Color (255, 255, 134 255, 0), 5, shwSI); 135 136 bgAShape.addSubShape(titleText); 137 139 container.addSubShape(shadowShape); 140 container.addSubShape(bgAShape); 141 container.addSubShape(outlineAShape); 142 root.addSubShape(container); 143 root.setRepaintPadding(new Insets (4, 4, 4, 4)); 144 145 if (dimension == SwingConstants.VERTICAL) { 146 AShapeUtil.enableMouseOverCursor(root); 147 AShapeUtil.enableMouseOverState(outlineAShape); 148 149 AShapeUtil.setResizeBoxes(outlineAShape, dimension, 4); 150 151 Integer button = new Integer (MouseEvent.BUTTON1); 153 154 AShapeUtil.addMouseFireEvent(outlineAShape, 155 MouseKeyInteractor.MOUSE_PRESS, 156 DefaultDateArea.AE_SELECTED_PRESSED, true, false, button); 157 AShapeUtil.addMouseFireEvent(outlineAShape, 158 MouseKeyInteractor.MOUSE_PRESS, 159 DefaultDateArea.AE_DRAG_PRESSED, true, true, button); 160 161 DefaultCommand entCmd = new DefaultCommand( 162 DefaultInteractionBroker.CMD_FIRE_INTERACTION_EVENT, null, 163 DefaultDateArea.AE_MOUSE_ENTERED, null); 164 DefaultCommand exitCmd = new DefaultCommand( 165 DefaultInteractionBroker.CMD_FIRE_INTERACTION_EVENT, null, 166 DefaultDateArea.AE_MOUSE_EXITED, null); 167 AShapeUtil.addEnterExitCommands(outlineAShape, entCmd, exitCmd, 168 true); 169 170 AShapeUtil.addMouseFireEvent(outlineAShape, 171 MouseKeyInteractor.MOUSE_CLICK, DefaultDateArea.AE_CLICKED, 172 true, false, button); 173 AShapeUtil.addMouseFireEvent(outlineAShape, 174 MouseKeyInteractor.MOUSE_DOUBLE_CLICK, 175 DefaultDateArea.AE_DOUBLE_CLICKED, true, true, button); 176 AShapeUtil.addMouseFireEvent(outlineAShape, 177 MouseKeyInteractor.MOUSE_POPUP_TRIGGER, 178 DefaultDateArea.AE_POPUP_TRIGGER, true, true, null); 179 180 AShapeUtil.addMouseEventBlock(outlineAShape, false, new Integer ( 183 MouseEvent.MOUSE_MOVED)); 184 185 ActivityInteractor.setStaticOverride( 187 AShapeUtil.DEFAULT_TITLE_TEXT_SHAPE_NAME, AShape.A_TEXT, 188 new OverrideFilter() { 189 190 private final String newTemplate = ActivityInteractor.TEMPL_SUMMARY.toString(); 191 192 public Object getOverride(Object subject, 193 Object defaultObject) { 194 Activity act = ((ActivityView) subject).getModel(); 195 return ParserHelper.isAllDayEvent(act 196 .getBaseDateRange().getStart(), act 197 .getBaseDateRange().getEnd()) ? newTemplate 198 : defaultObject; 199 } 200 }); 201 202 ActivityInteractor.setStaticOverride( 203 AShapeUtil.DEFAULT_MAIN_TEXT_SHAPE_NAME, AShape.A_TEXT, 204 new OverrideFilter() { 205 206 private final String newTemplate = ActivityInteractor.TEMPL_SUMMARY.toString(); 207 208 public Object getOverride(Object subject, 209 Object defaultObject) { 210 Activity act = ((ActivityView) subject).getModel(); 211 return ParserHelper.isAllDayEvent(act 212 .getBaseDateRange().getStart(), act 213 .getBaseDateRange().getEnd()) ? newTemplate 214 : defaultObject; 215 } 216 }); 217 218 } else { 219 AShapeUtil.enableMouseOverCursor(root); 220 AShapeUtil.enableMouseOverState(outlineAShape); 221 222 224 226 Integer button = new Integer (MouseEvent.BUTTON1); 227 AShapeUtil.addMouseFireEvent(outlineAShape, 228 MouseKeyInteractor.MOUSE_PRESS, 229 DefaultDateArea.AE_SELECTED_PRESSED, true, false, button); 230 AShapeUtil.addMouseFireEvent(outlineAShape, 231 MouseKeyInteractor.MOUSE_PRESS, 232 DefaultDateArea.AE_DRAG_PRESSED, true, true, button); 233 234 AShapeUtil.addMouseEventBlock(outlineAShape, false, new Integer ( 235 MouseEvent.MOUSE_MOVED)); 236 237 } 238 239 252 AShapeUtil.setStateOverride(outlineAShape, GenericStates.SELECTED, 254 AShape.A_PAINT, new Color (150, 200, 0)); 255 256 AShapeUtil.setStateOverride(outlineAShape, GenericStates.SELECTED, 258 AShape.A_STROKE, new BasicStroke (2.0f)); 259 260 return root; 261 } 262 263 } 264 | Popular Tags |