Skip to content

Instantly share code, notes, and snippets.

View jfahrenkrug's full-sized avatar

Johannes Fahrenkrug jfahrenkrug

View GitHub Profile
/*
* AppController.j
* Locations
*
* Created by Johannes Fahrenkrug on September 8, 2009.
* Copyright 2009, Your Company All rights reserved.
*/
@import <Foundation/CPObject.j>
@import "Location.j"
@import <AppKit/CPCollectionView.j>
@implementation LocationListView : CPCollectionView
{
CPCollectionViewItem itemPrototype;
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
/* ------------ Locations --------------- */
locationListView = [[LocationListView alloc] initWithFrame:CGRectMake(0.0, 0.0, 226.0, 400.0)];
[locationListView setContent:[locationsController locations]];
//1: we'll add something later
/* --------- Locations ScrollView ---------- */
var locationScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(10.0, 65.0, 243.0, 400.0)];
[locationScrollView setDocumentView:locationListView];
[locationScrollView setAutohidesScrollers:YES];
[[locationScrollView contentView] setBackgroundColor:[CPColor whiteColor]];
@import <Foundation/CPObject.j>
@import <MapKit/MKMapView.j>
@import "Location.j"
@implementation MapController : CPObject
{
MKMapView mapView @accessors;
CPTextField coordinatesLabel @accessors;
CPString latitude;
CPString longitude;
/* ----- Map Controller --------------- */
mapController = [[MapController alloc] init];
/* ------------- Map View ----------------- */
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(510, 65, 400, 400) apiKey:''];
[mapView setDelegate:self];
mapController.mapView = mapView;
[contentView addSubview:mapView];
/* ---------- Coordinates Label -------------- */
@import <Foundation/CPObject.j>
@import "Location.j"
@import "DemoData.j"
@import "LocationListView.j"
@implementation LocationsController : CPObject
{
CPArray locations;
LocationListView locationListView @accessors;
}
// Delegate method for the locationListView
- (void)collectionViewDidChangeSelection:(CPCollectionView)aCollectionView
{
var loc = [locationsController selectedLocation];
[mapController moveMapToLat:[loc latitude] andLng:[loc longitude]];
}
@import <AppKit/CPView.j>
@implementation LocationsToolbar : CPView
{
CPButton addButton;
CPButton removeButton;
id delegate @accessors;
}
- (id)initWithFrame:(CGRect)aFrame
/* ---- Locations Toolbar ----- */
locationsToolbar = [[LocationsToolbar alloc] initWithFrame:CGRectMake(10.0, 467.0, 226.0, 25.0)];
[locationsToolbar setDelegate:locationsController];
[contentView addSubview:locationsToolbar];
- (void)addLocation {
if (!locations) {
locations = [[CPArray alloc] init];
}
loc = [[Location alloc] init];
[loc setDescription:@""];
[loc setPosition:([locations count] + 1)];
[locations addObject:loc];
[locationListView setContent:locations];