[kepler-dev] Kepler/Ptolemy on the Mac

Dan Higgins higgins at nceas.ucsb.edu
Thu May 20 08:30:07 PDT 2004


Matt,

    With regard to your question,  Apple ( 
http://developer.apple.com/documentation/Java/Conceptual/Java131Development/x_platform/chapter_5_section_5.html 
) makes the following suggestion

"Keyboard shortcuts for invoking menu actions are often set with an 
explicit |javax.swing.KeyStroke| specification. This becomes complicated 
when moving to a new platform with a different modifier key because new 
KeyStrokes need to be conditionally created based on the current client 
platform. The solution to this problem is to use 
java.awt.Tookit.getMenuShortcutKeyMask to ask the system for the 
appropriate key rather than defining it yourself.

When calling this method, the current platform's Toolkit implementation 
returns the proper mask for you. This single call checks for the current 
platform and then guesses which key is correct. In the case of adding a 
Copy item to a menu, this means that you can replace the complication of 
Listing 5-2 
<http://developer.apple.com/documentation/Java/Conceptual/Java131Development/x_platform/chapter_5_section_5.html#//apple_ref/doc/uid/TP30000708/TPXREF121> 
with the simplicity of Listing 5-3 
<http://developer.apple.com/documentation/Java/Conceptual/Java131Development/x_platform/chapter_5_section_5.html#//apple_ref/doc/uid/TP30000708/BCIEJCJI>.

*Listing 5-2 Explicitly setting KeyStrokes based on the host platform*

|JMenuItem jmi = new JMenuItem("Copy");|

	||

|    String vers = System.getProperty("os.name").toLowerCase();|

	||

|    if (s.indexOf("windows") != -1) {|

	||

|       jmi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK));|

	||

|    } else if (s.indexOf("mac") != -1) {|

	||

|       jmi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.META_MASK));|

	||

|    }|

	||

*Listing 5-3 Using getMenuShortcutKeyMask to set meta keys*

|JMenuItem jmi = new JMenuItem("Copy");|

	||

|jmi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,|

	||

|    Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));|

	||

Most common actions in Mac OS X have a keyboard equivalent that uses the 
Command key, previously known as the Apple key, as a modifier. There may 
be additional modifier keys like Shift, Option, or Control, but the 
Command key is the primary key that alerts an application that what 
follows is a command, not regular input. Not all platforms provided this 
consistency in user interface behavior."


Using the "getMenuSortcutKeyMask()" method allows the same code to work 
on both Macs and other OSs and maps all Ctrl keys to the Apple's Command 
key. It would appear that we just need tochange all the keystroke 
assignemnts in Kepler to use this call.


Dan Higgins



Matt Jones wrote:

> Dan,
>
> What became of your inquiry into using the apple command key instead 
> of the control key on the mac for all modifier operations?  As Mac 
> generally uses this command modifier, it seems like the right think to 
> do, which would then free up the control key modifier to act in the 
> Mac-standard way to get the context menu.  There must be a way to 
> automattically map all cntrl funcitons in ptolemy to command functions 
> when on the mac.
>
> Matt
>
> higgins at nceas.ucsb.edu wrote:
>
>> Hi All,
>>
>> I have been investigating the use of Kepler/Ptolemy on the Mac. I did 
>> find
>> some threads on Mac use (especial concerning the single button 
>> mouse), but I
>> was still having some problems. In particular, one can find in the
>> 'ActorEditorGraphController' class the code fragment
>>
>>         if (UIManager.getLookAndFeel().getName().startsWith("MacOS")) {
>>             // On the Mac, do not override Control-Click, which is
>>             // used to bring up the context menu
>>             _linkCreator.setMouseFilter(_metaFilter);
>>         } else {
>>             _linkCreator.setMouseFilter(_controlFilter);
>>         }
>>
>> Note the 'getName()' call and the string comparison to "MacOS". 
>> Unfortunately,
>> a test on my Mac (OS version 10.3.3) shows that the getName method 
>> returns "Mac OS X Aqua" (note the spaces!). Due to the spaces, the 
>> names do not match and the Mac is NEVER detected!
>>
>> Apple suggests in their tech note 2042 (http://developer.apple.com/
>> documentation/Java/Conceptual/Java131Development/x_platform/
>> chapter_5_section_5.html) that the statement
>>
>> System.getProperty("mrj.version")
>>
>> should be used to detect a mac, with any non-null result indicating 
>> that the machine is a mac. This approach is independent of the string 
>> value which may change.
>>
>> I did try changing the Kepler code to correct this detection problem. 
>> I was able to get it to properly detect my Mac, but it still does not 
>> popup the context menu using the control key + click. Anyone have any 
>> ideas?
>>
>> Incidently, a 2 button mouse plugged into the Mac USB port does work 
>> OK with current code.
>>
>> Dan Higgins
>> NCEAS
>>
>>
>> -------------------------------------------------
>> This mail sent through IMP: http://horde.org/imp/
>> _______________________________________________
>> kepler-dev mailing list
>> kepler-dev at ecoinformatics.org
>> http://www.ecoinformatics.org/mailman/listinfo/kepler-dev
>
>
>


-- 
*******************************************************************
Dan Higgins                                  higgins at nceas.ucsb.edu
http://www.nceas.ucsb.edu/    Ph: 805-892-2531
National Center for Ecological Analysis and Synthesis (NCEAS) 
735 State Street - Room 205
Santa Barbara, CA 93195
*******************************************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mercury.nceas.ucsb.edu/ecoinformatics/pipermail/kepler-dev/attachments/20040520/774d9d7f/attachment.htm


More information about the Kepler-dev mailing list