Re: Custom drawing and cacheing
Re: Custom drawing and cacheing
- Subject: Re: Custom drawing and cacheing
- From: tlr <email@hidden>
- Date: Fri, 29 Jun 2001 23:46:47 +0200
I would like to port a geographical mapping software I wrote originally
in Java to MacOS X. Of course, I'd prefer to use the Java-Cocoa
interface, so I'm trying to learn just that.
Basically, the first thing to do is to have a map drawn in a window. The
program gets the map data through a URL, parses the data, and eventually
draws the data.
Until now, I've tried 2 things: 1) extending NSView; 2) extending
NSImageRep.
1) extending NSView: works, but the whole things is redrawn every time
the window is resized.
2) extending NSImageRep. Since the data I get is not exactly a "file
type", but just raw data, I'm enclined to use the NSData way of
instantiating an NSImage (or NSImageRep). I tried subclassing
NSImageRep, to override its draw () method. I made the canInitWithData
(NSData data) return true. But then I thought the NSData needed to be
something special I could rely on to determine if its type is correct
(so my custom imageRep can parse it); so I wrote a subclass to NSData
which I called mapData. And there I got strange errors not at all
related with java but with a mapping thing related with a "Bridge to
Objective-C" or something... I tried several other things, but that's
not really interesting.
You don't need to have to do either of them. Just put your pixels in a big
array, and use NSBitmapRep to get a representation of this array (you need
to specify some parameters indicating how the pixels have to be understood,
see the doc of the init...). Then put the representation in a new image,
and voila!
2 questions:
- does someone know how I could begin to do what I want ?
- what's the real status of java in cocoa. Seems like it really depends
on some of Objective-C's features. I fell several times on strange
errors that I can not relate to Java...
I made my first program in MacOS X using Java, and I think it was a
mistake. Java is not really intended for that purpose (though very
efficient for Internet things), and its security restrictions are just
annoying and unecessary for a standalone application. Moreover, Obj-C is
VERY simple (if you already know C, it can be learned in two hours).
Despite Apple's efforts toward Java (which have no counterparts from Sun's
side, incidentally), the Cocoa toolbox is much better in Objective C. So I
switched to Obj-C, and would be even more happy if I could have Obj-C++!
My opinion anyway.
Thomas Lachand-Robert
********************** email@hidden
The Commandant Project:
http://lachand.free.fr/
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.