-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppController.j
150 lines (120 loc) · 5.06 KB
/
AppController.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* AppController.j
* YEDDiagram
*
* Created by You on October 27, 2009.
* Copyright 2009, Your Company All rights reserved.
*/
@import <AppKit/CPCollectionView.j>
@import <Foundation/CPObject.j>
@import "YEDEdgeView.j"
@import "YEDGraph.j"
@import "YEDGraphViewController.j"
@import "YEDNode.j"
@import "YEDNodeView.j"
@import "YEDNodeViewRegistry.j"
@import "YEDOperationNode.j"
@import "YEDSubjectNode.j"
@import "YEDNodeViewCollectionItem.j"
CPLogRegister(CPLogConsole);
@implementation AppController : CPObject
{
CPWindow theWindow; //this "outlet" is connected automatically by the Cib
CPView contentView;
CPView sideView;
CPView canvasView;
YEDNodeViewRegistry registry;
CPCollectionView nodeCollectionView;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
// This is called when the application is done loading.
// [[YEDEditorView sharedEditor] setBackgroundColor:[CPColor blueColor]];
// Setup default Node Views
CPLog.trace("Setting up view registry");
registry = [YEDNodeViewRegistry registry];
var subjectNodeView = [[YEDNodeView alloc] initWithFrame:CPRectMake(0,0,150,50)];
[subjectNodeView setBorderWidth:4.0];
[subjectNodeView setBorderColor:[CPColor redColor]];
[subjectNodeView setCornerRadius:0];
[subjectNodeView setFillColor:[CPColor whiteColor]];
[registry registerPrototype:subjectNodeView
for:YEDSubjectNode];
var operationNodeView = [[YEDNodeView alloc] initWithFrame:CPRectMake(0,0,100,80)];
[operationNodeView setBorderWidth:3.0];
[operationNodeView setBorderColor:[CPColor greenColor]];
[operationNodeView setCornerRadius:20];
[operationNodeView setFillColor:[CPColor whiteColor]];
[registry registerPrototype:operationNodeView
for:YEDOperationNode];
// Setup graph and graph controller
graph = [YEDGraph graph];
graphViewController = [[YEDGraphViewController alloc] init];
[graphViewController setNodeViewRegistry:registry];
[graphViewController setRepresentedObject:graph];
var selectionManager = [[YEDSelectionManager alloc] init];
[selectionManager setDelegate:graphViewController];
[graphViewController setSelectionManager:selectionManager];
var canvasScroll = [[CPScrollView alloc] initWithFrame:CGRectMakeCopy([canvasView bounds])];
[canvasScroll setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[canvasScroll setAutohidesScrollers:YES];
[canvasView addSubview:canvasScroll];
graphView = [graphViewController view];
[graphView setFrame:CPRectMake(0,0,1000,1000)];
// [graphView setAutoresizingMask:(CPViewWidthSizable | CPViewHeightSizable)];
[canvasScroll setDocumentView:graphView];
//console.debug("Registry");
//console.debug(registry);
// rat1 = [YEDSubjectNode nodeWithName:"Rat1"];
// [graph addNode:rat1];
// fed1 = [YEDOperationNode nodeWithName:"Fed 5cc glucose"];
// [graph addNode:fed1];
// fedRat1 = [YEDSubjectNode nodeWithName:"Rat1 Fed"];
// [graph addNode:fedRat1];
//
// [graph createDirectedEdgeFrom:rat1 to:fed1];
// [graph createDirectedEdgeFrom:fed1 to:fedRat1];
// var nodeCollectionView = [[CPCollectionView alloc] initWithFrame:CGRectMake(0,0,200,400)];
// [nodeCollectionView setBackgroundColor:[CPColor greenColor]];
[nodeCollectionView setMinItemSize:CGSizeMake(200, 50)];
[nodeCollectionView setMaxItemSize:CGSizeMake(10000, 50)];
// [sideView addSubview:nodeCollectionView];
var nodeItemPrototype = [[CPCollectionViewItem alloc] init];
[nodeItemPrototype setView:[[YEDNodeViewCollectionItem alloc] initWithFrame:CGRectMakeZero()]];
[nodeCollectionView setItemPrototype:nodeItemPrototype];
[nodeCollectionView setDelegate:self];
preparedNodeViews = [[registry viewFor:[YEDOperationNode nodeWithName:@"Operation"]], [registry viewFor:[YEDSubjectNode nodeWithName:@"Subject"]]];
[nodeCollectionView setContent:preparedNodeViews];
//console.debug(nodeCollectionView);
}
- (CPData)collectionView:(CPCollectionView)collectionView dataForItemsAtIndexes:(CPIndexSet)indices forType:(CPString)type
{
return [CPKeyedArchiver archivedDataWithRootObject:[preparedNodeViews objectAtIndex:[indices firstIndex]]];
}
- (CPArray)collectionView:(CPCollectionView)collectionView dragTypesForItemsAtIndexes:(CPIndexSet)indices
{
return [YEDNodeViewDragType];
}
- (void)awakeFromCib
{
// This is called when the cib is done loading.
// You can implement this method on any object instantiated from a Cib.
// It's a useful hook for setting up current UI values, and other things.
// In this case, we want the window from Cib to become our full browser window
[theWindow setFullBridge:YES];
}
- (void)newNode:(id)sender
{
var name = prompt("Node Name:");
if(name)
{
var node = [YEDSubjectNode nodeWithName:name];
[graph addNode:node];
}
}
- (void)delete:(id)sender
{
CPLog.trace("delete:");
[graphViewController deleteSelected];
}
@end