Archive for February 2008

Pica type cursus en Mac: geen goede combinatie

The following article is in Dutch because it’s only relevant for people in the Netherlands.

Helaas heb ik moeten constateren dat Instituut Pica in het verhaal rond haar cursus computertypen geen eerlijke voorlichting geeft aan klanten. Nadat we onze belangstelling hadden doorgegeven om onze zoon deze cursus te laten volgen kwam er iemand langs om uit te leggen hoe een en ander in zijn werk gaat bij deze cursus. Uiteraard hebben we hierbij aangegeven dat we een Apple Mac gebruiken, en gevraagd of dit een probleem zou zijn. Ons werd verzekerd dat men hier een aantekening van zou maken en dat dit verder geen problemen op zou leveren.
Nu onze zoon een aantal weken bezig is en ik de lessen bekeken heb, vind ik dit geen correcte voorstelling van zaken. De cursus is duidelijk georiënteerd op het gebruik van Windows in combinatie met Microsoft Word. Alle uitleg over computer specifieke zaken richt zich hierop. Enkele voorbeelden: de wekelijkse toets moet aangeleverd worden in .doc formaat, er worden allerlei toets-combinaties uitgelegd die Windows specifiek zijn, net als de uitleg van het gebruik van speciale tekens zoals é of ë. Voor het leren typen op zichzelf is dit niet zo’n probleem, maar een deel van de overige informatie is dus gewoon onbruikbaar. Het minste dat je dan mag verwachten is dat dat tijdens zo’n voorafgaand gesprek gemeld wordt, zeker wanneer je daar expliciet naar vraagt!
Daarom zou ik iedereen die met een Mac werkt en overweegt om zijn kind een Pica cursus te laten doen, aanraden om hier nog eens goed over na te denken. In het geval men niet over Word beschikt zou ik er zeker niet aan beginnen.

District Line

Yesterday the new CD from Bob Mould appeared on emusic (at least for those located in Europe). Some songs similar to his previous solo work, some similar to what he did with Sugar and some tracks that could also have gone on Blowoff. After 3 listens I’m not yet able to judge the quality.

I’ve read the SPIN interview with him, and as has happened before the subject of a Hüsker Dü reunion came up. According to Bob it’s not going to happen, and I can only agree with him. Sure, if they would get together and play in Holland I would certainly go and see them, but I would know up front it can only be disappointing. Those guys are 20 years older (and like he said he can’t scream that way or play as fast anymore), but what’s even more important is that I’m 20 years older as well. And when you’re 40 you can try to relive your youth by going to reunion concerts but in the end you’re still an old guy.

So it’s better to keep the memory of what once was. Plus I’m lucky enough to have seen them perform live in the Warehouse tour.

Multiline cells in NSTableView

When you’re building an application that is based on data records, and each record contains a significant amount of data that you want to display in a table row, the space per row may be too small to fit everything. You can add every data element in its own column, but this leads to horizontal scrolling which can be cumbersome. A better solution to this problem is combining multiple data elements in a single cell. I’ll demonstrate how this can be done with a core data based application using data binding through a basic example. The end result of the finalized sample will look like this:


MultilineCell Sample App

For the sample I have made a core data entity named Order with 2 real attributes, orderNumber and orderLine. To combine these two elements into a single cell I add another transient attribute to the entity, named orderNumberLine.


Datamodel.png

Because the attribute is transient it will not become part of a file when you save the model. This is fine because whenever we need the value for the orderNumberLine attribute we will compose it from the orderNumber and orderLine values.

The entity is linked to the class Order, in which we override the standard key-value method orderNumberLine:


// Compose an attributed string that combines the values of the
// orderNumber and orderLine attributes.
- (NSString*)orderNumberLine
{
	NSString *tmpValue;
	NSMutableAttributedString *attrValue;
	NSDictionary *boldFont =
		[NSDictionary dictionaryWithObject:[NSFont boldSystemFontOfSize:10.0]
					forKey:NSFontAttributeName];
	NSDictionary *normalFont =
		[NSDictionary dictionaryWithObject:[NSFont systemFontOfSize:10.0]
					forKey:NSFontAttributeName];

	[self willAccessValueForKey:@"orderNumberLine"];
	// Put the order number in bold
	attrValue = [[NSMutableAttributedString alloc]
				initWithString:(self.orderNumber?self.orderNumber:@”“)
				attributes:boldFont];
	// Then add a newline
	[attrValue appendAttributedString:[[NSAttributedString alloc]
				initWithString:@”\n”]];
	// And finally add the order line in normal font
	[attrValue appendAttributedString:[[NSAttributedString alloc]
				initWithString:(self.orderLine?[self.orderLine stringValue]:@”“)
				attributes:normalFont]];

	tmpValue = [[NSAttributedString alloc] initWithAttributedString:attrValue];
	[self didAccessValueForKey:@"orderNumberLine"];

	return tmpValue;
}

The orderNumberLine method will compose a NSAttributedString that consist of the orderNumber and orderLine, separated by a newline. Because we’re using an attributed string we can also use different fonts for different elements, here the orderNumber is in 10 point bold, while the orderLine is in 10 point regular.

We can now bind the orderNumberLine value to a cell in an NSTableView in Interface Builder, then the cell will show a 2 line value. To properly display you need to increase the row height of the table view (in this case for a 10 point font size it to 26).

When you build the application adding only the orderNumberLine method to the Order class, you will notice that the cell that is bound to this method will display properly when it is redrawn (for example through scrolling or selecting the row). But when the value of either orderNumber or orderLine is changed elsewhere in the interface, the cell containing the composite string will not automatically redraw. This can easily be solved by doing an update to orderNumberLine attribute whenever one of its components (orderNumber or orderLine) changes. Then the bindings will take care that the UI is updated immediately. It doesn’t matter what you set the value of orderNumberLine to because it will be calculated upon retrieval anyway. The two following two methods demonstrate this:


// Override to trigger update of transient attribute orderNumberLine
- (void)setOrderNumber:(NSString*)value
{
	[self willChangeValueForKey:@"orderNumber"];
	[self setPrimitiveValue:value forKey: @"orderNumber"];
	[self didChangeValueForKey:@"orderNumber"];

	// Set the orderNumberLine to trigger updates to bound UI elements
	// The value we set it do doesn’t matter as the actual value
	// is calculated whenever the orderNumberLine is fetched.
	self.orderNumberLine = @”";
}

// Override to trigger update of transient attribute orderNumberLine
- (void)setOrderLine:(NSNumber*)value
{
	[self willChangeValueForKey:@"orderLine"];
	[self setPrimitiveValue:value forKey: @"orderLine"];
	[self didChangeValueForKey:@"orderLine"];

	// Set the orderNumberLine to trigger updates to bound UI elements
	// The value we set it do doesn’t matter as the actual value
	// is calculated whenever the orderNumberLine is fetched.
	self.orderNumberLine = @”";
}

To conclude, by adding a transient attribute, and writing three methods we can display a composed string in a cell. As this string can be an attributed string, we can apply different formatting to the elements composing the string. To look at the complete example, download it
here and open it in XCode.