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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
//
// MAHealthPage.m
// MySQL Administrator
//
// Created by Alfredo Kojima on 2/7/05.
// Copyright 2005 MySQL AB. All rights reserved.
//
#import "MAHealthPage.h"
#import "MAHealthGraph.h"
#import "MAMenuContextView.h"
#define GRAPH_SPACING 5
@implementation MAHealthPage
- (id)initWithProperties:(NSDictionary*)props
{
self= [super initWithIdentifier:[props objectForKey:@"title"]];
if (self)
{
MAMenuContextView *view= [[[MAMenuContextView alloc] init] autorelease];
[self setLabel:[props objectForKey:@"title"]];
/// description
_props= [props retain];
_groups= [[NSMutableArray alloc] init];
[view setAttachedObject:self];
[self setView:view];
}
return self;
}
- (void)dealloc
{
[_props release];
[_groups release];
[super dealloc];
}
- (void)addGroup:(MAHealthGroup*)group
{
[_groups addObject:group];
[[self view] addSubview:group];
[group setPage:self];
}
- (void)removeGroup:(MAHealthGroup*)group
{
[group setPage:nil];
[_groups removeObject:group];
[group removeFromSuperview];
[self rearrange];
}
- (void)rearrange
{
unsigned int i;
float y= [[self view] frame].size.height-10;
for (i= 0; i < [_groups count]; i++)
{
id group= [_groups objectAtIndex:i];
y-= [group frame].size.height+5;
[group setFrame:NSMakeRect(17.0, y,
[[self view] frame].size.width-17.0*2, [group frame].size.height)];
}
[[self view] setNeedsDisplay:YES];
}
- (void)setMenu:(NSMenu*)menu
{
[[self view] setMenu:menu];
}
- (void)setProperties:(NSDictionary*)props
{
if (_props != props)
{
[_props release];
_props= [props retain];
}
[self setLabel:[props objectForKey:@"title"]];
}
- (NSDictionary*)properties
{
return _props;
}
- (NSArray*)groups
{
return _groups;
}
@end
//=============================================================================
@implementation MAHealthGroup
- (id)initWithProperties:(NSDictionary*)props
{
self= [super init];
if (self)
{
MAMenuContextView *view= [[[MAMenuContextView alloc] init] autorelease];
NSSize margins;
[view setAttachedObject:self];
margins.width= 15;
margins.height= 15;
[self setContentViewMargins:margins];
[self setBoxType:NSBoxPrimary];
[self setTitle:[props objectForKey:@"title"]];
[self setContentView:view];
[self setAutoresizingMask:NSViewWidthSizable|NSViewMinYMargin];
NSSize size= [self contentSize];
size.height+= 15+[self contentViewMargins].height*2;
[self setFrameSize:size];
_graphs= [[NSMutableArray alloc] init];
_props= [props retain];
}
return self;
}
- (NSSize)contentSize
{
NSSize size= [[self contentView] frame].size;
unsigned int i;
size.height= 0.0;
for (i= 0; i < [_graphs count]; i++)
{
size.height+= [[_graphs objectAtIndex:i] frame].size.height;
size.height+= GRAPH_SPACING;
}
return size;
}
- (void)addGraph:(MAHealthGraph*)graph
{
NSRect rect= [graph frame];
NSSize size= [self contentSize];
float y= size.height;
[_graphs addObject:graph];
[graph setAutoresizingMask:NSViewWidthSizable|NSViewMaxYMargin];
[[self contentView] addSubview:graph];
size.height= y + rect.size.height + [self contentViewMargins].height*2 + 15.0;
[graph setFrame:NSMakeRect(0.0, y, size.width, rect.size.height)];
[self setFrameSize:size];
}
- (void)removeGraph:(MAHealthGraph*)graph
{
[graph removeFromSuperview];
[_graphs removeObject:graph];
NSSize size= [self contentSize];
size.height+= 15+[self contentViewMargins].height*2;
[self setFrameSize:size];
}
- (void)setProperties:(NSDictionary*)props
{
if (_props != props)
{
[_props release];
_props= [props retain];
}
[self setTitle:[props objectForKey:@"title"]];
}
- (NSDictionary*)properties
{
return _props;
}
- (void)setMenu:(NSMenu*)menu
{
[super setMenu:menu];
[[self contentView] setMenu:menu];
}
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
{
int i;
NSMenu *menu= [self menu];
for (i= 0; i < [menu numberOfItems]; i++)
{
[[menu itemAtIndex:i] setRepresentedObject:self];
}
return menu;
}
- (void)dealloc
{
[_props release];
[_graphs release];
[super dealloc];
}
- (void)setPage:(MAHealthPage*)page
{
if (_page != page)
{
[_page release];
_page= [page retain];
}
}
- (MAHealthPage*)page
{
return _page;
}
- (NSArray*)graphs
{
return _graphs;
}
@end
|