/YEDNodeViewConnector.j

http://github.com/rheimbuch/YED · Unknown · 49 lines · 40 code · 9 blank · 0 comment · 0 complexity · da81093aed583432882e6c0c812ad815 MD5 · raw file

  1. @import <AppKit/CPPasteboard.j>
  2. @import "YEDNodeView.j"
  3. YEDNodeViewConnectorDragType = @"YEDNodeViewConnectorDragType";
  4. @implementation YEDNodeViewConnector : CPView
  5. {
  6. YEDNodeView nodeView @accessors;
  7. CPEvent mouseDownEvent;
  8. }
  9. - (void)drawRect:(CGRect)rect
  10. {
  11. var context = [[CPGraphicsContext currentContext] graphicsPort];
  12. CGContextSetFillColor(context, [CPColor yellowColor]);
  13. CGContextSetStrokeColor(context, [CPColor grayColor]);
  14. CGContextFillEllipseInRect(context, rect);
  15. CGContextStrokeEllipseInRect(context, rect);
  16. }
  17. - (void)mouseDown:(CPEvent)event
  18. {
  19. mouseDownEvent = event;
  20. }
  21. - (void)mouseDragged:(CPEvent)event
  22. {
  23. var dragTypes = [YEDNodeViewConnectorDragType];
  24. [[CPPasteboard pasteboardWithName:CPDragPboard] declareTypes:dragTypes owner:self];
  25. var dragView = [[YEDNodeViewConnector alloc] init];
  26. [dragView setFrame:CGRectMakeCopy([self frame])];
  27. [self dragView:dragView
  28. at:[dragView bounds].origin
  29. offset:CGSizeMakeZero()
  30. event:mouseDownEvent
  31. pasteboard:nil
  32. source:self
  33. slideBack:YES];
  34. }
  35. - (void)pasteboard:(CPPasteboard)aPasteboard provideDataForType:(CPString)aType
  36. {
  37. if(aType === YEDNodeViewConnectorDragType)
  38. [aPasteboard setData:@"Retreive nodeView from drag source." forType:aType];
  39. }
  40. @end