~ubuntu-branches/ubuntu/lucid/graphviz/lucid-updates

« back to all changes in this revision

Viewing changes to macosx/GVAttributeSchema.m

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2008-06-19 20:23:23 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080619202323-ls23h96ntj9ny94m
Tags: 2.18-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build depend on liblualib50-dev instead of liblua5.1-0-dev.
  - Drop libttf-dev (libttf-dev is in universe) (LP: #174749).
  - Replace gs-common with ghostscript.
  - Build-depend on python-dev instead of python2.4-dev or python2.5-dev.
  - Mention the correct python version for the python bindings in the
    package description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: GVAttributeSchema.m,v 1.1 2008/02/11 12:34:07 glenlow Exp $ $Revision: 1.1 $ */
 
2
/* vim:set shiftwidth=4 ts=8: */
 
3
 
 
4
/**********************************************************
 
5
*      This software is part of the graphviz package      *
 
6
*                http://www.graphviz.org/                 *
 
7
*                                                         *
 
8
*            Copyright (c) 1994-2008 AT&T Corp.           *
 
9
*                and is licensed under the                *
 
10
*            Common Public License, Version 1.0           *
 
11
*                      by AT&T Corp.                      *
 
12
*                                                         *
 
13
*        Information and Software Systems Research        *
 
14
*              AT&T Research, Florham Park NJ             *
 
15
**********************************************************/
 
16
 
 
17
#import "GVAttributeSchema.h"
 
18
 
 
19
static NSXMLDocument *_attributes = nil;
 
20
static NSTextFieldCell *_stringCell = nil;
 
21
static NSComboBoxCell *_enumCell = nil;
 
22
 
 
23
@implementation GVAttributeSchema
 
24
 
 
25
+ (void)initialize
 
26
{
 
27
        _attributes = [[NSXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"attributes" ofType:@"xml"]] options:0 error:nil];
 
28
        
 
29
        NSFont* smallFont = [NSFont labelFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]];
 
30
        
 
31
        _stringCell = [[NSTextFieldCell alloc] init];
 
32
        [_stringCell setControlSize:NSSmallControlSize];
 
33
        [_stringCell setDrawsBackground:NO];
 
34
        [_stringCell setEditable:YES];
 
35
        [_stringCell setEnabled:YES];
 
36
        [_stringCell setFont:smallFont];
 
37
 
 
38
        _enumCell = [[NSComboBoxCell alloc] init];
 
39
        [_enumCell setBezeled:NO];
 
40
        [_enumCell setButtonBordered:NO];
 
41
        [_enumCell setCompletes:YES];
 
42
        [_enumCell setControlSize:NSSmallControlSize];
 
43
        [_enumCell setDrawsBackground:NO];
 
44
        [_enumCell setEditable:YES];
 
45
        [_enumCell setEnabled:YES];
 
46
        [_enumCell setFont:smallFont];
 
47
        [_enumCell setHasVerticalScroller:NO];
 
48
}
 
49
 
 
50
+ (NSArray*)attributeSchemasWithComponent:(NSString *)component
 
51
{
 
52
        NSMutableArray* attributeSchemas = [NSMutableArray array];
 
53
        for (NSXMLElement* element in [_attributes nodesForXPath:[NSString stringWithFormat:@"/xsd:schema/xsd:complexType[@name='%@']/xsd:attribute", component] error:nil])
 
54
                [attributeSchemas addObject:[[[GVAttributeSchema alloc] initWithXMLElement:element] autorelease]];
 
55
        return attributeSchemas;
 
56
}
 
57
 
 
58
- (id)initWithXMLElement:(NSXMLElement *)element
 
59
{
 
60
        if (self = [super init])
 
61
                _element = [element retain];
 
62
        return self;
 
63
}
 
64
 
 
65
- (NSString*)name
 
66
{
 
67
        return [[_element attributeForName:@"ref"] stringValue];
 
68
}
 
69
 
 
70
- (NSCell*)cell
 
71
{
 
72
        NSCell *typeCell = _stringCell;
 
73
 
 
74
        /* determine which cell to return */
 
75
        NSString *type = [[[_attributes nodesForXPath:[NSString stringWithFormat:@"/xsd:schema/xsd:attribute[@name='%@']/@type[1]", [self name]] error:nil] lastObject] stringValue];
 
76
        if (type) {
 
77
                if (![type hasPrefix:@"xsd:"]) {
 
78
                                NSXMLElement *simpleType = [[_attributes nodesForXPath:[NSString stringWithFormat:@"/xsd:schema/xsd:simpleType[@name='%@'][1]", type] error:nil] lastObject];
 
79
                                NSArray *enumerations = [simpleType nodesForXPath:@"xsd:restriction/xsd:enumeration" error:nil];
 
80
                                if ([enumerations count]) {
 
81
                                        [_enumCell removeAllItems];
 
82
                                        for (NSXMLElement *enumeration in enumerations)
 
83
                                                [_enumCell addItemWithObjectValue: [[enumeration attributeForName: @"value"] stringValue]];
 
84
                                        typeCell = _enumCell;
 
85
                                }
 
86
                        }
 
87
        }
 
88
        
 
89
        /* determine the default value */
 
90
        NSString* defaultValue = [[_element attributeForName:@"default"] stringValue];
 
91
        if ([typeCell respondsToSelector:@selector(setPlaceholderString:)])
 
92
                [typeCell performSelector:@selector(setPlaceholderString:) withObject:defaultValue];
 
93
        return typeCell;
 
94
}
 
95
 
 
96
- (NSString*)documentation
 
97
{
 
98
        return [[[_attributes nodesForXPath:[NSString stringWithFormat:@"/xsd:schema/xsd:attribute[@name='%@']/xsd:annotation/xsd:documentation[1]", [self name]] error:nil] lastObject] XMLString];
 
99
}
 
100
        
 
101
- (void)dealloc
 
102
{
 
103
        [_element release];
 
104
        [super dealloc];
 
105
}
 
106
 
 
107
 
 
108
@end