Programming
NUndoManager project started
Since I miss the amazing undo manager from Apples Cocoa Framework, I started to implement my own version of an undo manager, using the same recording techniques.
The so called NUndoManager is the first .NET 3.5 undo manager, recording lambda expressions of methods reverting the state of an object. Additionally NUndoManager groups single operations for undoing at once. Reverted undo operations are automatically to the redo stack.
The project is hosted here. Have a look or join the project if you want to add your own ideas.
Model view presenter - make your live easier
The MVC (Model View Controller) patter is a well known object pattern for GUI abstraction, which is taught on every it school. But many programing language don’t support the programmer to use this pattern from scratch.
For example Java, or C# .NET are based on a inheritance topology, the IDE’s create subclasses of the GUI components, resulting in huge source files, which are mixed up with everything. Not to mention that there is no compatibility to other GUI components, e.g. ASP .NET.
Apple with it’s Objective-C / Cocoa framework made a good step in the right direction, the programmer is forced to use the MVC pattern, since the GUI is described in so called NIB files. A controller class contains the code. The NIB file can theoretically be changed without changing the controller.
Also .NET 3.5 has a good answer to this technology, the windows presentation foundation. The GUI is described in XAML files, which are linked to classes. The XAML file could also be exchanged without changing the source code.
These technologies are based on the MVC patter, which still has a string connection between view and model. Further the controller has direct references to the controls within the view. If we want to change a windows forms view with a ASP .NET view, or change the model, the MVL pattern is not flexible enough. This is where the MVP pattern starts to unfold its strength.
The MVP, or more precisely the passive model view pattern is based on three simple interfaces; Model, View and Presenter. View and model are independent entities, only the presenter links the three parts together.
Compared to the MVC pattern, the presenter has no direct connection to the GUI controls of the view and the view does not know the model.
The presenter can observe the view and the model, if any changes happens within the model, the presenter gets notified and tells the view what to do. The same procedure happens, if any user interaction happens on the view; The presenter gets notified and has to handle the interaction.
In this case, we can easy implement the view in ASP .NET, Windows Forms, WPF etc. and run it with the same model and presenter.
In some cases, we need a container view, which can maintain any sub views. For this, we extend the passive view pattern with a sub view. The presenter of the container only knows the presenter of the sub view. Sub views are added by adding the presenter of the sub view to the presenter of the container view, model and view are not referenced by the container view presenter.
Since the container view needs no know the sub view, the presenter forwards the sub view to its own view. With this MVP pattern and IoC (Inversion of Control) it’s also possible to use different technologies to implement the views with only one restriction: All views need to be compatible among each other.
The most nice advantage at all is, that we can use dependency injection to create our object structure. To describe this technology would be beyond the scope of this article, but I can provide you some links:
How to check whether a class implements an interface
If we work with objects, it is not difficult to determine if a class implements an interface. This can be done with the is keyword.
But it gets difficult if we work with reflection. The type object of a class, contains a method called IsSubclassOf, but if we try to use it with an interface it returns false in any case and if we try to get all implemented interfaces and search the one we need, we’ll have to much work with this simple issue.
So how can we do this in a very easy way? I found the answer here. To shorten this long description, I’ll give you the answer right here:
typeof(IFoo).IsAssignableFrom(bar.GetType()); typeof(IFoo).IsAssignableFrom(typeof(BarClass));
The method IsAssignableFrom checks whether the type can be assigned from another. It takes a type objects as an argument an returns true if the type can be assigned.
IPhone SDK on G5 PPC
<!–adsense#Google Adsense-Banner–>Officially the iPhone SDK requires an Intel Mac with OSX 10.5. Since I have a four year old dual G5, which is still running like a young dear, I don’t want to buy a new Mac just for writing iPhone Applications.
After some research, I found out, that it’s possible to make it work on PPC since the iPhone SDK are universal binaries.
To share my knowledge, I write a small tutorial. Note, that I don’t take responsibility, for any defects cause somebody used my code!
How to get the iPhone SDK to work on PPC Macs
Most of the tutorials I found in the Web are not up to date, because there where no “Aspen” packages anymore. With the iPhone SDK for IPhone OS 2.1 (build 9M2517) you can follow these steps:
1. Download the official iPhone SDK here.
2. Mount the .dmg image and install the iPhone SDK (the iPhone SDK will be grayed out!).
3. After rebooting the Mac, mount the image again and go to the folder Package. Install all packages which have iphone in the name (e.g. Simulator, SDK, Documentation).
4. Go to the folder /Platforms on the local HD and copy the iPhone.platform and the iPhoneSimulator.platform folders to /Developer/Platform.
Don’t copy the whole platforms folder, Xcode will not run correctly anymore!
5. Now we come to the interesting part. Xcode has now access to the iPhone SDK, you can already create iPhone projects, but Xcode still wants to compile the sources for the Intel architecture. To change that, open the folder /Developer/Platforms/iPhoneSimulator.platform/Developer/
Library/Xcode/Specifications/ .
In this folder you will find the file iPhone Simulator Architectures.xcspec. Make a backup and open it in any text editor. The content should look something like this:
(
// 32-Bit
{ Type = Architecture;
Identifier = Standard;
Name = "Standard (iPhone Simulator: i386)";
Description = "32-bit iPhone Simulator architectures";
ListInEnum = YES;
SortNumber = 1;
RealArchitectures = ( i386);
ArchitectureSetting = "ARCHS_STANDARD_32_BIT";
},
// Old-style Debug
{ Type = Architecture;
Identifier = Native;
Name = "Native Architecture of Build Machine";
Description = "32-bit for build machine";
ListInEnum = YES;
SortNumber = 101;
ArchitectureSetting = "NATIVE_ARCH";
},
// Intel
{ Type = Architecture;
Identifier = i386;
Name = "Intel";
Description = "32-bit Intel";
PerArchBuildSettingName = "Intel";
ByteOrder = little;
ListInEnum = NO;
SortNumber = 105;
},
)
6. Change the line “RealArchitectures = ( i386);” to “RealArchitectures = ( i386, ppc);“.
7. Add the architecture configuration for G3, G4 an G5, the edited file should now look like this.
(
// 32-Bit
{ Type = Architecture;
Identifier = Standard;
Name = "Standard (iPhone Simulator: i386, ppc)";
Description = "32-bit iPhone Simulator architectures";
ListInEnum = YES;
SortNumber = 1;
RealArchitectures = ( i386, ppc7400 );
ArchitectureSetting = "ARCHS_STANDARD_32_BIT";
},
// Old-style Debug
{ Type = Architecture;
Identifier = Native;
Name = "Native Architecture of Build Machine";
Description = "32-bit for build machine";
ListInEnum = YES;
SortNumber = 101;
ArchitectureSetting = "NATIVE_ARCH";
},
// G3
{ Type = Architecture;
Identifier = ppc;
Name = "Minimal (32-bit PowerPC only)";
Description = "32-bit PowerPC ";
PerArchBuildSettingName = "PowerPC";
ByteOrder = big;
ListInEnum = No;
SortNumber = 201;
},
// G4
{ Type = Architecture;
Identifier = ppc7400;
Name = "PowerPC G4";
Description = "32-bit PowerPC for G4 processor";
ByteOrder = big;
ListInEnum = NO;
SortNumber = 202;
},
// G5 32-bit
{ Type = Architecture;
Identifier = ppc970;
Name = "PowerPC G5 32-bit";
Description = "32-bit PowerPC for G5 processor";
ByteOrder = big;
ListInEnum = NO;
SortNumber = 203;
},
// Intel
{ Type = Architecture;
Identifier = i386;
Name = "Intel";
Description = "32-bit Intel";
PerArchBuildSettingName = "Intel";
ByteOrder = little;
ListInEnum = NO;
SortNumber = 105;
},
)
Now you should be able to compile the iPhone project and run the app in the iPhoneSimulator. I never tried to put an App into the AppStore, but I think it should work.
Please let me know if my post could help you, or if you have any questions!
Further links to this issue:
- http://linuxclub.blogspot.com/2008/07/iphone-sdk-installtion-on-powerpc-g4.html
- http://forums.ilounge.com/showthread.php?t=223546
- http://www.iphoneatlas.com/2008/03/10/surprise-iphone-sdk-also-works-on-powerpc-macs/
Apple looses the NDA for IPhone
After months of protest, Apple has announced that they decided to drop the non-disclosure agreement (NDA) for released iPhone software.
Whatever that means exactly, Apple is working on the new terms and will send it to the developers within the next few days and we’ll see.
According to Apple, the NDA is in place to protect there inventions and innovations for the IPhone technology. Now, they think the NDA was too much burden for the developers, authors and others interested in helping further the iPhone’s success, so they are dropping it for released software.
A cappuccino please
Amazing which ideas some people have, there has been released a JavaScript browser application engine named Cappuccino, copying the Cocoa framework from Apple.
The frameworks language is Objective-J, the JavaScript equivalent to Objective-C and is built up on the GNUStep/Cocoa framework. It is designed to build applications and not webpages and the nice thing is, it’s open source and can be downloaded for free!
Objective-J is very similar to both JavaScript and Objective-C. Any valid JavaScript is also valid Objective-J but the language adds dynamic message passing, traditional inheritance and other features we know from Objective-C. Even the code looks very familiar!
Classes:
@implementation Person : CPObject
{
CPString name;
}
@end
Methods:
- (void)setName:(CPString)aName
{
name = aName;
}
- (CPString)name
{
return name;
}
Using objects and classes:
var myPerson = [[Person alloc] init]; [myPerson setName: "John"];
I like this new framework, cause it opens the world of Cocoa with it’s Objective-C to a wider world the just Apple and perhaps it will get more popular.
JStringLocalizer 1.0.b1 released
I’m glad to announce the release of the JStringLocalizer library version 1.0.b1. The beta version contains only the basics of the planned features, and is hardly tested. But so fare it should work, if you find some bugs, please let me know, I’ll fix them as soon as possible.
Release notes 1.0.b1:
- Localized XML files based on number tags (id).
- Debug mode (Sets an ‘!’ in front of each string to mark the already localized strings)
- Tag information (Sets the string tag after the string to see the localization tag information on the running system.)
Planned for version 1.0.b2
- Swing localizer (Should localize every component on a frame)
- JAR / ZIP resource file loading
License:
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, o any later version. This library is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
Download:
JStringLocalizer project started
I started a small java project for the localization of java applications. The localized strings are stored in a XML file where every string has its unique identifier, called language tag. For every addition language you can add a translated XML file.
The localizer will have at least followeing features:
- Debug mode (It will be possible to switch in a debug mode to see which strings are localized.)
- Tag information (You can switch on the identifiers for viewing these tags directly within the application.)
- SWING Localizer (Localizes directly the swing elements of the application.)
- Resource files directory vs. resource jar loading.
In one or two days I will release a first version, testers are very welcome.
Interfaces with explicit methods
Have you already been in a situation, where you are forced to extend a class and can not inherit from another class anymore, but you would like to make a proper structure? Usually interfaces are used in this situations, but its quite boring to implement it twice or three times exactly in the same way. Since .NET 3.5 there is a solution for this problem - Extension Methods.
Lets have a look on this solution. First you make the interface:
pubic interface IFoo
{
...
}
Then you create the extension method:
pubic static class IFooExtension
{
public static void DoSomething(this IFoo foo)
{
...
}
}
Next you create an implementation of the interface:
pubic class Foo : IFoo
{
...
}
And finally, you can use it:
Foo foo = new Foo(); foo.DoSomething();


