File: MAGraphEditor.m

package info (click to toggle)
mysql-gui-tools 5.0r12-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 105,540 kB
  • ctags: 50,897
  • sloc: sql: 348,439; pascal: 285,780; cpp: 94,578; ansic: 90,768; objc: 33,761; sh: 25,629; xml: 10,924; yacc: 10,755; java: 9,986; php: 2,806; python: 2,068; makefile: 1,945; perl: 3
file content (156 lines) | stat: -rw-r--r-- 3,409 bytes parent folder | download | duplicates (4)
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
149
150
151
152
153
154
155
156

#import "MAGraphEditor.h"

@implementation MAGraphEditor

- (id)init
{
  self= [super init];
  if (self)
  {
    [NSBundle loadNibNamed:@"HealthGraphEditor" owner:self];

    [window makeKeyAndOrderFront:self];
  }

  return self;
}


+ (MAGraphEditor*)editGraph:(NSDictionary*)graph
{
  MAGraphEditor *editor;

  editor= [[MAGraphEditor alloc] init];

  [editor setGraph:graph];

  return [editor autorelease];
}

- (void)dealloc
{
  [[NSNotificationCenter defaultCenter] removeObserver:self];
  [_editedGraph release];
  [super dealloc];
}


- (void)setGraph:(NSDictionary*)graph
{
  [autoMax setState:[[graph objectForKey:@"autoExtend"] boolValue]?NSOnState:NSOffState];
  [formula setString: [graph objectForKey:@"valueFormula"]?:@""];
  [graphType selectItemAtIndex: [[graph objectForKey:@"graphType"] intValue]-1];
  [maxCaption setStringValue: [graph objectForKey:@"maxCaption"]?:@""];
  [maxFormula setStringValue: [graph objectForKey:@"maxFormula"]?:@""];
  [maxValue setDoubleValue: [[graph objectForKey:@"maxValue"] doubleValue]];
  [minValue setDoubleValue: [[graph objectForKey:@"minValue"] doubleValue]];
  [showTitle setState:[[graph objectForKey:@"showTitle"] boolValue]?NSOnState:NSOffState];
  [title setStringValue:[graph objectForKey:@"title"]?:@""];
  [unit selectItemAtIndex:[[graph objectForKey:@"graphUnit"] intValue]];
  [valueCaption setStringValue:[graph objectForKey:@"valueCaption"]?:@""];
  
  [graphType setEnabled:NO];
}

- (NSDictionary*)graph
{
  id keys[12];
  id values[12];
  int c= 0;
  
  values[c]= [NSNumber numberWithBool:[autoMax state] == NSOnState];
  keys[c]= @"autoExtend";
  c++;
  values[c]= [formula string];
  keys[c]= @"valueFormula";
  c++;
  values[c]= [NSNumber numberWithInt:[[graphType selectedItem] tag]];
  keys[c]= @"graphType";
  c++;
  if ([[maxCaption stringValue] length] > 0)
  {
	values[c]= [maxCaption stringValue];
	keys[c]= @"maxCaption";
	c++;
  }
  if ([[maxFormula stringValue] length] > 0)
  {
	values[c]= [maxFormula stringValue];
	keys[c]=  @"maxFormula";
	c++;
  }
  values[c]= [NSNumber numberWithDouble:[maxValue doubleValue]];
  keys[c]= @"maxValue";
  c++;
  values[c]= [NSNumber numberWithDouble:[minValue doubleValue]];
  keys[c]= @"minValue";
  c++;
  values[c]= [NSNumber numberWithBool:[showTitle state] == NSOnState];
  keys[c]= @"showTitle";
  c++;
  values[c]= [title stringValue];
  keys[c]= @"title";
  c++;
  values[c]= [NSNumber numberWithInt:[unit indexOfItem:[unit selectedItem]]];
  keys[c]= @"graphUnit";
  c++;
  if ([[valueCaption stringValue] length] > 0)
  {
	values[c]= [valueCaption stringValue];
	keys[c]= @"valueCaption";
	c++;
  }
  
  return [NSDictionary dictionaryWithObjects:values forKeys:keys count:c];
}

- (IBAction)cancelClicked:(id)sender
{
  [window performClose:sender];
}

- (IBAction)okClicked:(id)sender
{
  if (_target && _applySelector)
    [_target performSelector:_applySelector withObject:self];
  
  [window performClose:sender];
}

- (NSWindow*)window
{
  return window;
}

- (void)windowWillClose:(NSNotification *)aNotification
{
  [self autorelease];
}

- (void)setApplyAction:(SEL)selector
{
  _applySelector= selector;
}

- (void)setTarget:(id)target
{
  _target= target;
}


- (void)setEditedGraphObject:(id)graph
{
  if (_editedGraph != graph)
  {
    [_editedGraph release];
    _editedGraph= [graph retain];
  }
}

- (id)editedGraphObject
{
  return _editedGraph;
}

@end