WWDC2001 Session 506

Transcript

Kind: captions
Language: en
good mornin my name is Pete Steiner I'm
the engineering manager of the Java
platform classes team here at Apple
Computer what I'm gonna be going over
today
is some of the things that you need to
do to take your 100% pure java
application and bring it to Mac OS 10
you have to excuse me this is early for
me so well we're good
what our goals are in this session is to
go over some minimal changes that you
need to make to your applications to be
able to make it run and behave well on
Mac OS 10 before we get into that I want
to make it clear that on Mac OS 10 even
better than Mac OS 9 you can take jars
and other applications from other
platforms and just run them on Mac OS 10
there's no changes that you have to make
to your application to make them run
what I'm gonna be talking about today is
the kinds of things that you can do to
your application so that they'll they'll
mesh better with Mac OS 10 and the goal
with these changes is that these changes
be very minor that you don't have to do
much of anything to make things run very
well on Mac OS 10 in designing our
implementation of Java on top of Mac OS
10 some of our goals for some of these
tweaks were to make api's that blend
very well with sun so that you can do
very minor things to your applications
and have them behave much more closely
to have them match much more closely
other applications that are running on
Mac OS 10 and with the ultimate goal
being applications that feel like Mac OS
10 applications so I'm gonna go over
first is some of the basics the things
that you should be doing in your design
already but become more important when
you're doing this kind of work so these
the first thing I'm going to be going
over is pure Java cross-platform changes
that will aid you in the step so you're
going to be doing further and then I'm
going to go into some simple tweaks that
you can do that require often ok code
changes but sometimes very minor code
changes and then I'm going to go into
some more complex features that you can
you can take or leave you don't need to
adopt but will make your application run
that much faster and at the very end I'm
going to go into some of the packaging
details that you need to take advantage
to be aware of to deploy your
application on Mac OS 10 so the basics
cross-platform changes what I want to
emphasize here is first of all that
everything that we're going to be
demoing today is based on clean a
hundred percent pure swing
implementations the reason I say swing
is you can implement and classic AWT
runs perfectly fine on Mac OS 10 but
we've discovered over the years that
when you implement in classic AWT and
you implement expecting certain
behaviors on one platform it's very hard
to carry them to the other platforms the
classic AWT doesn't work well for that
kind of situation so what we recommend
is that you focus on swing application
they run much better on mac OS tanning
you have to make far fewer changes a
huge number of the bugs that we get into
apple on the classic AWT are this widget
doesn't behave like windows it's like
well no it's a it's a Mac OS choice or
it's a Mac OS button they're not gonna
behave like windows swing does a much
better job of making those kind of
things match mesh the other thing you
need to be aware of and a lot of this is
just good design I mean there's nothing
nothing new here but it becomes much
more important things like modularity
things like keeping an eye on platform
differences you need to be aware that
even if you write a hundred percent pure
java application there are differences
in platforms and there are minor tweaks
that you're gonna make and if you design
your code in a way that it's modular
that you constants up on the fly as you
need to and factor out these sections of
your code that you expect may require
platform differences it's gonna be that
much easier to make the minor tweaks
that you need to make to make your
application run well on multiple
platforms native methods is another
thing the minute you start going down
the native method path you're really
tying yourself into the platform and you
need to make sure that you factor out
your native methods you isolate how you
do those because the behavior of native
native methods how you bind those up
that kind of thing it's very different
from platform to platform to platform I
mean we've got Jay and I we've got those
kind of things we also support Jay
direct which I'll talk about in a second
but the fact of the matter is the minute
you start talking about native methods
you're going you're binding yourself
much more closely to the platform that
you're running
so isolating those is always a good
thing and then launch ability that's a
totally simple thing but will allow you
allow us to help you out in a lot of
ways if you follow some spec as far as
as far as packaging things up in jars
using the dark spent extension
mechanisms and also making sure you do
things like specifying your main met
your main method in the jar and that
kind of thing you're gonna get that much
closer to something that we can help you
out with later so with that I'm gonna
bring Eric up to run through the the
beginnings of the demo that we're gonna
be building on throughout the course of
the session the Eric Albert he's one of
the engineers on the Java platform
classes - okay so what we have here
actually
okay.i is basically the way that you
would end up launching in java
application on a variety of different
platforms so from the command line
chocolate - char you can use suggest the
- char flag as long as your manifest is
correctly configured and so when I hit
return then this application comes up
and this is basically how this app would
look on on Solaris or on Windows this is
using Suns I default cross-platform
look and feel which is metal it's the
default on on Solaris and on Windows and
what we have here actually is something
that lets us navigate through the file
system from javis perspective which is
from a UNIX perspective and so you can
see all of our files here and you can
see if I go through and say take a look
at my applications and I well your users
at least on the Mac are expecting or
will typically expect to see mail app as
say a rake your application but in fact
it is actually a directory because
that's the way that applications are
packaged on this system and within there
we have a contents directory inside that
all kinds of different things and the
actual application binaries is way on
down here so this is an application and
just as it would book on other systems
nothing at all has been done here to get
it to run specially on the Mac OS and so
if you just take your code in port then
this may be what you end up with but
Pete was talking about modularity and
at the same time so even though this
application doesn't look like a Mac os10
app it's been written in a way to make
adding support for additional platforms
and adding any platform specific code
relatively easy so one a good example of
this is the way that the menu bar is
designed here I'm sure I should go back
to this briefly and show that I we have
file and edit menus here of course your
users will expect those on all platforms
and homeless troll applications do have
that and so we've got new open save and
close the notice closes option F for
edit cut copy and paste or control X
control C control V etc but if you've
factored out your menu your menu items
in such a way that allows you to add in
additional ones for specific platforms
then you'll end up being in very good
shape when the time comes to add say
specific accelerators for Mac OS 10 so
in this case our menu bar class actually
takes advantage of Java's resourcebundle
class to load the appropriate resources
for the platform that it's actually
running on and so it grabs those
resources and then goes through and
constructs menus dynamically based on
what those resources happens to be there
happen to be building the keystrokes
that cars then it gets out of those
resources and grabbing appropriate
actions out of those resources they
correspond to the given menu items that
it has so ideally what you end up doing
then is saying rather than say
associating specific actions with
platform specific code I'm going to
write generic Anthony generic actions
within my application that I can then
use as a bottleneck for all platform
code let's see here
oh that's right one other thing that I
did want to mention is that this also
works great actually for localization so
when you have something like this that
lets you vote specific resources and
then you can trivially add specific
locos a localizations your application
ship in multiple languages and we'll get
a chance to show that to you later so
okay great so so that's just the kind of
setting the stage for some of the
changes that we're going to be
making necks so now what I want to do is
if we can get the slides back up on here
is talk about the simple tweaks that we
can make to slide slide slides the
simple tweaks that we can make to
applications that will make them
harmonized much better with Mac OS 10
the first thing that you'll need you'll
need to be aware of is how to
distinguish between the platforms the
the two kinds of things that you're
going to want to be aware of is how to
distinguish between platforms and how to
distinguish between specific features
and versions on a platform and the most
common way and the way that we recommend
for distinguishing between the platforms
is you it using the OS name property
this is the way that any number of other
Java applications use on Mac OS 9 mrj
the OS 10 name property will be Mac's
base OS Center capped and a Mac OS 10
because the infrastructure is
fundamentally different we've changed
the OS name to be Mac OS 10 as far as
features what you should be doing and
this is where it gets a little touchy
and it depends very much on the platform
you should be looking on Mac OS 9 or on
Mac OS in general Mac OS 10 and Mac OS 9
at the mrj version property we've
carried the mrj version property through
from mrj into Java on Mac OS 10 and this
is the best way to tell between features
each major release that we do we're
going to bump this and so if you're
relying on specific bug fixes that we've
got or specific api's and features the
best thing to be checking for is the
energy version property in that in that
situation then the look and feel we
actually cheated in this demo just for
dramatic effect I guess the on Mac OS 10
the standard look and feel that's
enabled by default is the Mac OS look
and feel so if you do nothing if you
create a simple java application with
using standard swing without setting a
look and feel you're gonna get the Mac
OS the Aqua look and feel we actually on
this demo forced it just for dramatic
effect but if you need to for whatever
reason later in your application force a
look and feel other than the standard
platform look and feel what you need to
use is the UI manager set look and feel
and within that you just call UI manager
to get system look and feel class name
or if you want the metal
can feel call get cross-platform look
and feel and that will force it what you
then need to make sure that you do is
call update component tree UI because
that will force any UI elements that
you've already instantiated to be bound
the thing you need to be aware of is
this is called on a frame and it'll walk
down a frame so if you've done things
like creating a frame creating a menu
bar but you haven't associated them you
need to associate them before you call
get component tree UI otherwise the menu
bar won't pick up the the look and feel
changes the next thing is menu
definition one of the coolest things
that I found about the Mac look and feel
that we've implemented is that it allows
you to put the menu bar in the right
place menu bars and Windows drive me
insane I just I can't stand them and so
I'm on swing we've allowed you to move
the menu bar out of the frame into the
menu bar we didn't put this on by
default for two reasons first of all
it's part of sense conformance kit that
they check to make sure that behaviors
are correct but more importantly from my
perspective you need to be aware of
where the menu bar is in your
application and your application needs
to take into account that the menu bar
may may be up there the best example of
why this is a problem is if you look at
an application like the bean box the
bean box has three frames that it
operates on the menu bar is associated
with the main frame we've run into this
on mrj in the past where the menu bar
being up in the actual menu bar on the
system if you activate another frame the
menu bar goes away that's not what your
users are going to expect so you need to
meet be aware that when frames activate
the menu bar that's associated with that
frame is active so we didn't want to
force it up to the top to begin with
because it we got a lot of user feedback
too that's just it's wonky and weird and
so we wanted to make sure that your
application is architected for that but
assuming that it is it's totally easy to
enable this all you need to do is call
set J menu bar on your frame or on your
dialog and you should be doing that
anyway that's just standard the standard
practice for swing the thing you need to
be aware of is you can't have any heavy
weights AWT menu bars associated with it
at the time and currently menu bars and
J dialogues don't work right now we
don't see a lot of applications and it's
kind of weird on the Macintosh to have
menu bars
you're in your dialogue anyway so I'd
recommend that you don't do that but if
you do don't expect to go to the top of
that doesn't work right now but once
you've called see a menu bar on your
frame or your dialog all you need to do
is enable the comm a polemic OSU's
screen menu bar property and set that to
true you can either do that
programmatically in your code or you can
do that as a command-line switch but
it's as easy as that
so what I'm gonna do now is go into some
of the simple H I things that you need
to be aware of when you're working on
your application to make it harmonize
best with yet with a Natchitoches one of
the things that Macintosh users and
actually it not just Macintosh users any
platform users come to expect is that
the UI is laid out in a way that they
expect things like menus menus are laid
out with on the Macintosh File menu new
new open closed save quit edit menu has
has things in the right place the
Preferences on Mac OS 10 is in is in the
right place that kind of thing
preferences on Mac OS 9 is in the in the
Edit menu and that the accelerators are
what you expect and the accelerators are
where I found actually in writing this
demo very wildly from platform to
platform I don't use Windows much at all
and looking at the windows accelerators
it was just completely wonky and that
Mac OS doesn't have the same keyboard
mnemonics so when you're architecting
your application you need to be aware
that those are the kind of things the
users are gonna depend on windows in
dialog layout this is less critical but
you still need to be aware of it I'm in
so far as things like dialogues
Macintosh users expect and okay in the
bottom right that's the default button
that is activated when you hit return
the cancels right next to it that's that
that is clicked on when you hit escape
that certain dialogues are laid out in a
certain way those kind of things you
need to be aware of if you take
advantage of the standard things like
the J option pane and that kind of thing
will do it for you but if you're
counting up your own dialogues
on-the-fly then you need to be aware of
this the best way to do to figure out
this kind of stuff is just sit down and
use the standard application sit down
and use TextEdit on the Mac for a little
while look at how things are laid out
that's the best way also pick up the the
latest h-i guidelines we actually have
just publish
the latest aqua user interface
guidelines you can go to the web I've
actually got a link at the end of the
presentation on where to get that that
kind of stuff so just splash around
there so with that I'm gonna kick it
back over to Eric and I'll show you how
to turn this on okay looking at the
wrong screen okay so the first thing
that people do s name property to
determine what platform that you're
running on and also then checking by
either the mrj that version property or
whatever property is appropriate for
whatever platform you're on to determine
features and in this application
actually all that we need to determine
is the platform that we're running on
we're not too worried about platform
specific features there and a good way
of doing that is to abstract all of that
out into one class and this in this case
we have a class called configuration
they have constants a they correspond to
every platform that you could
potentially be running on and then is
simply to resolve those on on
application launcher run the first
reference to this class and then you can
trivially check everything anywhere else
in your code where you might need to
check to see what platform you're
running on and run the appropriate code
for that system so Pete mentioned that
we cheated and we did so in this case
we'd hard code the platform string to
Sun OS which is why we got metal and I'm
going to change that back now and so
merely by doing make by making that one
change by setting our platform string
variable to system that kept property of
OS name then as a result of the way the
rest of the code is written all of this
is magically going to change we're going
to pick up the aqua book and feel and
this will look a lot more like a Mac
os10 application so how do we end up
accessing this information elsewhere we
have this one method here get platform
which returns the integer that
corresponds to the platform that we're
running on and two other methods that
come in handy from time to time one is
get platform string which will actually
get saved Mac os10 on on Mac OS or Sun
OS on Solaris and so on and so forth the
other turns out to be useful for the
menu bar abstraction that I mentioned
this is get platform prefix and what
this actually does is to take a look at
at the OS and at the platform name so at
the platform string and to remove all
whitespace from it so we can actually
then construct class names from that and
use those to reference resources within
our application ok so how do we end up
using that well we've we've got our
platform and so now back in our main
class and in the dirt shrew browser
class we can actually check that
platform and if we are on a generic Java
platform which is what we said Solaris
was then use the trust platform look and
feel so UI manager dot said look and
feel your I mentored I get
cross-platform looking fuel class name
that's how we got metal and it's
actually useful from time to time for
testing and also if you're doing any
custom UI or anything like that to use
metal on Mac os10
but of course we'd actually prefer that
you end up using aqua which is the
system look and feel and so free for any
platform here other than a generic Java
platform we use the system look and feel
class name and then of course cost when
utility is not update component tree UI
that gives us aqua that's a really good
start and that's with changing
practically nothing in our code now we
need a menu bar so step one create a
menu bar and I mean on this frame and
call such a menu bar on that that's
right
as long as you're doing that right now
in your code hopefully you are for your
menu bar rather than say I adding it to
a J panel and laying that out within
your window but if you do call such a
menu bar then you're halfway there
the next step is to set this property
calm Apple Mac OS you screen menu bar
you can do this cross-platform of course
I so you can actually you can run this
on all platforms there's no platform
check here on other platforms that of
course just be ignored and you do again
have to do this before calling such a
menu bar as long as you do that before
you before calling that method then when
you do call that method your menu bar
will be grabbed inserted up at the top
of the screen in the global menu bar in
your Mac users will be a lot happier
than they'd otherwise be so here now
we've got the look and feel we've got
the global menu bar
what about things like the menu layout
and the keyboard shortcuts well I
mentioned before that we had platform
specific resources for all of those that
are loading by our generic main menu bar
class here for example is the classic
Mac OS version of this so we've got a
two-dimensional array of objects here
the first the first element in that
array is I just it's just a list of the
menus that we actually have on this
platform in this case we have file and
edit menus and then for each menu we
have each of the menu items in turn so
the name of the menu item whatever its
mnemonic is and since there since a
keyboard navigation of menus does not
exist on classic Mac OS or on Mac OS 10
then we simply set that to know a string
that corresponds to the shortcut for
that menu item and so meta n may look a
little bit strange
Amida is the is the generic java term
for what corresponds to the command key
on the mac OS and perhaps other keys on
other platforms so it turns out that
swings keystroke class when it sees this
string well actually I grabbed meta and
translate that into the command key
cliff and so you'll actually get the
correct width within the menu and then
perhaps the most important part here in
action associated with that menu item
and so we can then do this on all
platforms and point all of our platforms
and say the new action on all platforms
through to exactly the same bottleneck
in our code meaning that we don't have
to change the new action or opening
files or closing documents or anything
like that for yeah for any platform
specific stuff and since this is classic
Mac OS then we've got open close say if
we've got quit at the bottom of the file
menu and then our edit menu is undo cut
copy paste and preferences how does this
change on Mac os10
well in a couple of ways most notably
the quit menu is not in the file menu
it'll end up in the application menu and
we'll show you later how to take
advantage of that the other item that's
worth noting here is that we've got two
help menu so if you go and you take a
look at the h-i guidelines then you'll
see that strongly recommended that all
applications do provide some sort of
help your users will definitely
appreciate that if you do and so I
because we're
we unfortunately didn't have time to
write complete help we just wanted to
show them then you've been we actually
put our about box here even though that
should really be in the application menu
and we'll show you how to I create how
to create an about box within the app
menu later um the other thing that I
should mention is just to reiterate
again that these actions are exactly the
same so again this is going to point
through exactly the same bottleneck in
the code now I mentioned previously that
that creating your resources in this
format makes localization easy and in
fact it actually does here we've got the
and we've got a German version of our
Mac os10 menu bar layout so you'll
notice that the class name has an
underscore de at the end de being the
localization code for German and well
all the strings are different I have no
idea of what all of them mean but I
presume since file edit and help and
well Pete wrote that he knows German but
when so when you run this and your
language is actually set to German as
I'll show you in a minute then your
application will just automatically
appear in German so if you are at all
interested in supporting multiple
languages this is definitely the way
that you want to go and of course
there's Windows and so Windows is I
think quite different there's no closed
item there for example I have exit
instead of quit and all of your all for
menu items actually have them onyx
associated with them and preferences
actually end up in a view menu and are
called options instead of preferences
and strange things like that so in any
case I now that we have the menu layout
how does make sure you all of that work
and so I I've made two changes to the
code from before and one to take out our
hack to get it to the Sun OS and instead
we are going to run as if we are on the
Mac and with the appropriate menu bar
and so when I go forth and run this
application then it comes up and there
we have an aqua application we have a
global menu bar and this most would
behaves as a Mac user would expect with
a minimal change to your code so the
icons are pretty much all the same and
everything like that again we changed
very little
code and all of a sudden we have an
application that looks much more like
what your users will expect a much more
like all other applications on the
system ok cool ok so that was the easy
stuff that was the like no code changes
essentially to be able to get this stuff
up and running so now what I'm gonna go
into and take deep breaths in between
them like flying through as I always do
is some of the more complex features
these actually do require a code changes
they should be relatively minimal and
we're gonna show you how to make these
code changes in such a way that it
should be very unobtrusive in your code
and in very isolated spots and have a
big bang for the buck or whatever you
want to call it so I'm gonna go through
drag and drop I'm gonna go through the
emerge a toolkit those of you that have
been here in years past have heard me
talk about this over and over again I'm
gonna go through that briefly and in
conjunction with that handling some of
the basic Apple events things like open
dock quit those kind of things I'm going
to talk about some new file system
manipulation stuff that we've done that
we expect to kind of grow that has kind
of grown out of the mrj toolkit and we
hope to in the future replace the old
mrj toolkit with some new work that
we've got going on right now and I'm
gonna spend some time talking about J
direct so drag and drop drag and drop we
fully implement Suns implementation of
drag and drop on Mac OS 10 so the Java
to drag and drop works just fine and my
recommendation for the vast majority of
apps is that you use sends an
implementation it's fine for the 90%
case and we're working with them on some
of some of the issues that caused us to
have to implement some of our own stuff
so in addition to the Sun drag-and-drop
which works for the 90% case we've also
got a merge a drag and drop and mrj data
transfer and those are more closely
modeled after and those came out of mr j
2 to more closely modeled after the mac
OS drag manager they support things like
multiple non file drag items Suns API so
you to drag multiple files but for other
things you need to use ours I'm in it
and in addition conversion and coercion
between multiple data types a good
example of an application that might
need to use our drag and drop versus
Suns
is an application like a pre-press I can
see a pre-press application where you're
trying to write something that has to
interact with Macintosh applications
Photoshop Illustrator that kind of thing
in that kind of situation you might need
to get more information from the scrap
manager and from the Macintosh drag and
drop mechanism then Suns api's allow you
we're working with Sun to get some of
those kind of bubbled back up so that
they can be available in on all
platforms but for right now we've
provided you with with a stopgap the
only thing that you're gonna need to be
aware of is some of the visual cues and
that kind of thing when you're doing
drag-and-drop Eric will show that in a
little in a little bit in the demo but
visual cues are the only things that
you're really gonna need to be aware of
and drag and drop the rest of it just
works and it was actually in plane
method surprisingly easy to wire up
standard and send drag-and-drop to do
more complex things obviously it gets
more complex but for standard
drag-and-drop it's very easy emerge a
toolkit emerge a toolkit we've talked
about in the past I'm not gonna spend a
ton of time on this our stance on the
mrj toolkit API is is we brought them
over from MRJ because they're very
valuable to a number of applications
unfortunately they're also very dated
they came from mrj in the past the API
is were very specific to mac os9 and a
lot of the mac os9 paradigms and so
we're working on new api is then bind
much more closely to Suns api's and make
a lot more sense
going forward unfortunately those aren't
ready yet we're working on those
in-house we're gonna roll those out to
you but they're not quite ready yet and
the mrj toolkit still has a lot of
values so things like the OS type class
that allows you to get at before get at
and manipulate and create the four byte
the four character key codes that are
used throughout the Mac OS the emerge a
file you dole's is a set of very
rudimentary functions on a class that
allow you to manipulate Mac OS specific
attributes on files things like file
types and creators locating apps and
special folders that kind of thing there
are certain paradigms that we don't
support in the MRJ the mrj toolkit on
Mac OS on Mac OS 10 because the paradigm
isn't quite the same something things
like setting the default type and
creator for applications the Mac OS 10
mechanism
four types and craters as well but we're
encouraging and file naming extensions
as well so things like that aren't
aren't supportive of mac OS 10
the emergency application noodles is a
set is a class that allows you to handle
things like installing the standard
apple event handlers so if you want to
be able to respond to the quit event
wouldn't send your application if you
need to be able to open documents about
those kind of things that's where the
application needles come in and that's
actually the the one thing that is
actually makes a lot of sense when we
don't have a replacement for yet so
adopting the EAP is for the basic Apple
events is totally easy it's really
simple
all you have to do is implement an
interface and register the class that
implements that interface and I've
actually found that it provided that you
have standard bottlenecks in your code
for handling these things which you
would normally have to do anyways your
application needs to be able to deal
with an open document if you've got a
standard bottleneck for where your
application deals with that all you have
to do is call it the right thing or
funnel funnel this call through to the
right thing and you're good to go same
thing with quit same thing with all
those kind of things I in my application
that I wrote all I had to do was change
method name and it worked like a charm
file system access this is something
that we've been working on in-house
actually Eric has been poring over for
the last for the last while what we're
what our goal is here is to create a set
of API is that bind much more closely to
the Sun api's match the paradigms much
more closely and allow you to get at a
number of the Mac os10 features this API
right now is a proposal it's not in the
release we're actually going to release
it to you in sample code by the end of
next week so that we can push it out to
you what we want is for you to play with
it you to give us feedback on what makes
sense what doesn't what's there what's
not so that we can eventually roll this
into the system and be able to take
advantage of this throughout the
throughout our applications and yours
but we didn't want to do that
prematurely when we wanted to get
feedback from you all first so I'm gonna
go through the details of it but make
sure that you go to our website and pull
down this source play with it see if it
makes sense for your application the two
things we've implemented right now and
it are the
while in the Mac application class the
Mac file class is intended to be able to
deal with Mac OS 10 specific file
attributes again very similar to the mrj
file utils insofar as getting types of
creators that kind of thing finder
attributes and and more which I'll go
into a second the Mac application is for
launch ability kinds of things one of
the things that we get feedback from
developers a lot is I need to launch an
application runtime exec is totally
obscure for my application and doesn't
make sense on the Mac on the Mac as well
actually it doesn't really work on a lot
of platforms for real well and we need a
more standard way of doing that so
that's what the Mac application class is
for and it's also for dealing with mime
type mapping mapping files to
applications so the nak file class like
I said is a totally standard
straightforward API it allows you to
check if it's an alias file directory
package get canonical path is an
interesting one because the this has
come up on our lists before and we've
gotten a lot of discussion about what we
should do with a lea sis and we've
discovered over the course of mrj that
if you do the right thing for one
application with aliases resolve the
alias as to what they really should be
another class of application busts and
so what we wanted to do here is allow
you to resolve it if you need to but not
change the underlying classes because we
found that changing the way Sun a Java
IO file works just busts a whole
collection of applications so we're
allowing you to get at aliases and
manipulate aliases without busting
everyone is visible and finder is
another Mac OS 10 specific kind of
paradigm there's a distinction between
what the file API is expects is visible
ie what UNIX shows as visible versus
invisible and what the Mac OS shows is
visible or unvisible there's actually a
whole slew of things that you can see in
the UNIX file system as visible that
your user won't see you need to be able
to make that distinction in a lot of
situations and get icons the standard
kinds of stuff Mac application is again
for dealing with opening documents
manipulating documents that kind of
thing and so first of all get file it
just gets you the Mac file
but more interesting is the open open
documents and open the open and open
document API is that allow you to
essentially launch applications the way
that the finder would so that if you
need to launch a web browser launch a
web browser with a page that kind of
thing this is how you would go about
doing that
it also chat it also deals with fine
with application specific finder
attributes and bundle type style
attributes so Eric will show how this is
this is used in a second J direct 3 if
you went to Blaine's talked on it I
guess was Tuesday on the VM he talked
briefly about J direct 3 I'm also going
to talk briefly about J direct 3 on J
direct 3 is one of these things that I
find insanely powerful because it means
that I never have to wander into C code
but in general people don't end up using
it a ton and so I'm not gonna spend a
ton of time on that there's a lot of
developer documentation the thing to
keep in mind here is if you've already
got J direct code out there the
difference between J direct 2 and J
direct 3 is important to note the
biggest deal is the new linker class
that you see here you need to be able to
do that to tell the VM to bind your
native classes to to your libraries so
this is this is the sample code that he
threw on the screen the other day what I
wanted to do is point out kind of more
importantly to us how you bind at the
toolbox because that's where we use J
direct all over the place this is how
you buy into carbon are you buying to
other system applications the only thing
that's different between this and the
previous example is the library that
you're linking against it's not your
normal it's not it's not your personal
library its system library frame our
spark core services framework core
services and the call that you're
linking against this new pointer but
this allows you to and it allows us in
our implementation to get at the entire
toolbox and this is how we implement a
good portion of the AWT in swing is
using J direct there's more examples of
this and actually the DMACC file AP is
and that kind of stuff that we're going
to roll out we're gonna roll out the
whole source code to the implementation
and you can see how to use J direct it
using it is pretty straightforward once
you get used to it but there's some
paradigms you need to get used to it's
tool box like we've been telling you
over and over again over the years that
the Mac OS toolbox carbon is not
pre-emptive it's not preemptive it's not
it's it's not reentry your if you
interrupt the tool box your application
will potentially behave poorly or crash
on Mac OS 9 this wasn't as big of a deal
because as long as you were down in your
native code your tool box calls weren't
going to be preempted on Mac OS 10 this
is a huge deal this is a really huge
deal because suddenly we've got a real
pre-emptive system Carbon can you can be
running from multiple threads in the
nature of Java's you've got multiple
threads running so you need to make sure
that if you're calling the toolbox in
your application that you acquire this
carbon lock this is what we do
throughout our code and this is how you
make sure that you don't clobber us or
we don't clobber you we try to be real
meticulous about making sure that we
maintain this lock and you'll notice
that this lock has changed slightly and
that we're not acquiring a lock on a
specific global piece of information
like we did on mrj as a function call
this allows us to do some magic things
behind the scenes that allow us to clean
it up later but you need to be aware of
this so kick it over to Eric and he'll
show how to wire this stuff up okay okay
so the first thing you want to talk
about there's a very long list of things
to go through here is drag and drop so
we've got our application running here
which you've seen before
and we open our app let's say the
applications folder scroll down here
find now app just to bring that over
here
and drag this over and you'll note that
when I drag this over the tree so I can
drop this into the tree and it's going
to actually open up the entire tree go
through the hierarchy and select me I'll
add a pin there then I get a little
highlight ring around that that's
something that we would prefer that you
do Suns drag and drop API does not do
that for you automatically and it turns
out to be relatively easy I'll show you
how to do that in a second but it's
always a good idea to give your users
feedback when using drag and drop to let
them know where you can't actually drop
something so when I'm when I drag this
back here then they high like us way and
back and so I let it go and switch in
here and everything opens up and they
all die nap is actually selected in
there so to get all of that to work and
go back to our treat class here so
within der tree within the trees
constructor we create a new drop target
this is using the standard Sun JDK 1.2
and later drag and drop ap is create a
new drop target using this as the
component and this also as the event
listener so you'll see here this
implements drop target listener so drop
target listener requires that you
implement a couple of methods here all
the way down to the end first drag over
and drop action changed we're not
actually going to worry about and in
general you don't have to worry about
them all that much the two important
ones here first of all are drag enter
and drag exit so again when you're
entered with a drag that you want to
accept then it's a good idea to you take
advantage of swings border facilities
and add a border to and to the component
of the right color in this case the text
highlight color and to show that you
can't actually drop something in there
and of course on drag exit you want to
remove that border on the other hand you
may potentially run into some slight
layout issues if you end up actually
removing that border or at least we did
in this case and so instead we create a
border just have the regular text color
and so and that ends up showing up in
black instead of in yellin so the color
goes back and forth there's one other
well one thing that you absolutely have
to do if you if you choose not to go
with it with a highlight border that's
okay but you really do have to find some
way of accepting the drop and so this
again uses this Sun standard API to get
the transferable object from it and from
the drop target drop event I check to
ensure that the final flavor is
supported by whatever's being dragged
grab the transfer data out this is a
list of files and Suns API but since we
can only process one file at a time with
this application then we I ensure that
there is actually file there get the
first file out and then act
we navigate to it so we have to navigate
to method that opens up the tree and
goes through it and selects the object
that it's asked to select so that's
drag-and-drop the next thing is handling
the Apple events and so in our main
class here we implement common apple MRJ
mrj quit handler mrj open document
handler and mrj about handlers so we can
handle the quit apple van open document
apple event and about apple event and
that only requires changing a couple
other lines in the codes they're adding
three additional lines so that when we
are on the Mac then we call through to
the mrj application kills and register
to quit open document and about handlers
there the reason actually why this can
be included in the main class and still
have a compile cross-platform is that we
do distribute in mrj toolkit stubs that
simply has my implementations of these
of all of these methods that are stubbed
out when not running on the Mac OS so
you can actually you could even run
those in other platforms they would
simply do nothing
so because we factored this code well
then we have bottleneck routines for
quitting for opening a file and for
handling in and out box and all we have
to do is ensure that the names of those
are the names that are in our
implementation and so for example handle
quit here and I have some basic just
call system exit of zero but if you
wanted to do something like prompt the
user to save a document or something
like that then you'd go through there
and handle Open File there and handle
about.i
right here so so that's how you go about
handling the basic Apple events and then
there's one additional thing to show
everything okay maybe two so we have a
class called inspector panel that draws
that panel on the right that shows the
basic file attributes that you can get
from the standard 11.3 file API so can
you read a file can you write a file
when was it modified and so on and so
forth there's one thing that we had
actually taken out of here which is if
we are on the Mac I mean it's wrong
shortcut
then we want to add this thing that we
factored out into a separate class
called Mac properties panel and what
that actually does is to take advantage
of the Mac file and Mac application
api's and to show you Macintosh specific
file attributes about them and before I
go forth and actually run that I want to
show one additional thing which is how
we can take advantage of get icon then
for our individual tree nodes and
grabbed a Mac file for the file that
corresponds to each node in the tree and
if it's an application then because the
application icons look really pretty on
Mac OS 10 I will grab the icon and I
like calling get icon on the Mac file
grab it as an image create an image icon
and then set the icon for that tree node
to be the icon of that file so what does
all of this look like oh go forth and
run it and this comes up and we've got
an additional properties panel in there
so for everything on the system now you
can see is this an application is the
package is it an alias does it actually
show up in the finder what does it look
like and what's its canonical path so
for example I four aliases we have an
alias to the java vm framework that's at
the root level of the system and so
we've got a little bit of a painting
glitch with the icon right now but we'll
take care of that we've got a check box
here that says is this an alias yes it
is here is the canonical path so we've
done the OAS resolution that's what it
points to you can then create a file
with that string and you get the actual
file on the system that corresponds to
we've also got open here and so now hit
open and even though that appeared at
the root level you can see what opened
in the finder was the java vm framework
folder i within system library
frameworks so that's always resolution
on Mac OS 10 you also may notice that
this this list of files was a lot or is
now a lot shorter than it was when we
ran the application back at the
beginning the reason for that is that
we're only showing me the files that are
actually visible in the finder so we're
displaying an interface that looks more
like what your users will expect when
they're navigating through a file dialog
you don't see user and dev in quarters
and everything like that and here
anymore and when you go into the
Applications folder in here then you'll
notice that the applications are
actually no longer folders and instead
they appear to the user as if they are
standard applications and in fact I'm
gonna take me out up here and hit open
and you see the doc open up and nail gun
app pops up and there we go we have mail
and so this is how you can take
advantage of a Mac file and Mac
application api's it to do things that
your users on Mac os10 will really
appreciate so now back to Pete to talk
about packaging thanks the slides back
up here real quick the last thing I want
to go over is packaging and packaging is
totally straightforward on Mac os10
first of all like I said earlier the
first step in getting your application
packaged up right is getting it packaged
up in a jar that's available in all
applications one of the things that
we're working on in-house that isn't
ready yet but will be a will be
available very soon I don't have
specific dates yet or actually probably
just shouldn't make specific promises
yet but we're going to have a mechanism
for allowing it for double clickable
jars so you'll be able to in the finder
just double click on a jar itself and
just have it launched so we've got that
running in houses there's just some
minor glitches that we need to work out
with that but in addition like you saw
on the demos Mac and Mac OS 10
applications are packages there's a
whole bunch of other things that you can
bundle up in Mac OS 10 bundles and so
there's a number of tools that you can
use for creating Mac OS 10 bundles if
you notice jbuilder is jar is bundled up
as a standard Mac OS 10 application our
app builder all of the job applications
on the system are bundled up that way so
you can either use a tool like project
builder if you're using project builder
to design your code project builder will
burp out a Mac a standard java
application package that will look like
a standard application jbuilder
apparently I heard rumors of the J
builder session yesterday talking about
bundling up double clickable
applications in addition we've also got
amen
Gizem for bundling it up inside of
bundling up standard jars so you can
just drag a jar over and use mrj app
builder to bundle up jars and that's
totally straightforward - so the
bundling mechanism is very easy and
really powerful in addition there's a
technology called Web Start that you've
seen if you went to Steve Narrows talk
on Tuesday you saw a web start being
demonstrated that's a technology that
we've got running in-house that we're
hoping to push out very soon it's
actually very functional and there's
just some like licensing and legal
issues that we need to deal with to get
that bundle pushed out that's a feature
of the Java - standard edition version
1/4 that's coming out we're hoping to
get it out to you earlier and that's a
web born mechanism for distributing
applications so there's a number of ways
to get your applications out to users so
let me kick it over to Eric one last
time and he'll show you the app builder
okay so what we have here is mrj app
builder which is the simplest tool that
you can use to build up in a double
clickable application on Mac os10
comes up just like this and the most
straightforward thing to do assuming
that you have a jar with a correct
manifest setup as we do is to just click
on shoes navigate through the file
system I should mention by the way that
I so I so when I showed you the
directory tree browser just now none of
things like user and var and temp
etcetera didn't actually show up and yet
they do in the jfilechooser II that's
because the Mac file API is relatively
new and we do hope to actually grab the
jfilechooser
and the AWT file dialog - when you say
that your application is willing to or
intends to take advantage of the Mac bio
API to display a layout of the file
system that your users will expect so
here to navigate through
and actually signal select the jar that
we built in J builder and asked me to
choose the main class of course that's
Jerry browser so the main class name
automatically gets inserted here the
class path gets set up correctly and
over in the merge files tab here if the
jar that I've selected will
automatically be merged into the double
clickable application so you can
distribute something that to your ears
to your users looks just like one file
although of course it's a packaged
application so it's the directory etc
but they don't need to worry about that
too much
um and then we have to sit where we want
to save that so we'll save it right next
to where that jar is navigate back
through to there
and select that and then hit build and
actually I guess I had one already okay
um
tells me that it did actually finish
building it and it actually managed to
build it successfully yay
so then we can hide that and add the
gate through and here's the third tree
browser application just double-click on
it looks like a standard application and
there we go we have a Mac os10
application so so if you take advantage
of these technologies if you use the
screen menu bar use the aqua book and
feel build double clickable application
I do only take advantage of the extra
functionality that we're providing that
we're providing you to integrate your
application better with the rest of the
system then as far as your users can
tell this is not a Java app this is a
Mac OS 10 application and that'll make
them all a lot happier thank you
you get the slides back up here one last
time what I want to do now is point you
at some resources first of all the Mac
os10 h:i guidelines you can either write
that down or you can just go to the Mac
os10 developer page under documentation
under the general documentation there's
a new version the Aqua h-i guidelines I
definitely recommend you pick up that
and just leave through it and see how
that compares to your current
application there's also a Mac os10 Java
web site that has will have all of the
stuff that we've got oh actually that's
is that right
okay okay you flinched up front
so the Mac OS 10 Java web site has a
bunch of documentation on the different
technologies we've got it's where the
release the latest release notes go
pointers to the latest builds and sample
code and the sample code the sample code
that we've been demonstrating in this
session will be posted on that website
so you can go there if you're in a super
hurry to get it it's actually on my eye
disk if you go to pas it's on my eye
disk and we're just gonna push it up
there so I just didn't make the cut I
pushed it up last night so if you want
to pull it from there you can go ahead
and pull it otherwise the sample code
will go up on the website so you can
look at what
and the changes that we made in detail
and the Java update I'm actually
probably going to get in trouble here
but it's ready it's not it's it's it it
will be posted tomorrow we pushed it up
to the Wii we finished it packed it up
yesterday and gave it to Alan and it'll
be up on the website tomorrow so this
has all the stuff you've been hearing in
all the different Java sessions and I
got to announce when it was ready first
so anyway from from here on out there's
actually still more Java sessions I find
it amazing we've gone from like two or
three Java sessions to ten just on our
stuff right after actually a two o'clock
over in Civic there's more information
and QuickTime for Java the Java graphics
stuff will actually be really
interesting if you go this afternoon
we're going to be talking about some of
the stuff that we've been doing with
hardware acceleration some of the things
that you can do in your code to take
advantage of this and form and take and
modify your code slightly to take
advantage of some of the new features
we've done Java security tomorrow
morning at 9 o'clock in the morning
Scott down here will talk about some of
the security related issues and please
please please come to the feedback forum
tomorrow morning and let us know how
we're doing if you got any questions
that kind of thing
so who to contact Alan Alan knows where
to find me Alan is art is is the best
person to talk to you if you've got any
issues if you want to get your code to
us to add it to our test suite that kind
of thing Alan's the best person to talk
to you
you can come directly to me and you're
welcome to but I tend to go dark during
development time
you