Impersonation hotkeys, and where to lodge them

The RPTools applications are written in Java. If you're interested in contributing to any project here by submitting patches to the source code, this is the forum to ask questions about how to do so. Please put the two-letter tool name abbreviation in your thread Title. To enter this group, go to the Usergroups page of your User Control Panel and join the Java Developer group.

Moderators: dorpond, trevor, Azhrei

Post Reply
User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Impersonation hotkeys, and where to lodge them

Post by Rumble »

I've been working on a means to impersonate tokens using a shortcut key pair (namely, Ctrl-. and Ctrl-, to go back and forth through the list of token on the map). I've achieved this goal, but I don't know if I've done it the right way (either "properly according to programming convention" or "properly according to the way the devs want it done").

So here are my questions:

1. Right now, I have the code for handling the cycling through the tokens to impersonate as part of the PointerTool class. It went there because a) that's where I found many other accelerator key functions (which I used as a model for how to implement my stuff), so it seemed appropriate. It works fine, or appears to. Is that an acceptable place for it? Is it an undesirable, or wrong place for something like that? If it's the wrong place, what would the devs suggest is a better plan?

2. I note that there are a number of accelerator keys defined in I18N.properties, and it would be great to define these impersonation key combos there to make localization easier. However, I don't actually know how to use what's defined in I18N.properties...I see most of the defined codes are part of AppActions, but does the impersonation bit belong there instead?

3. If it's okay where it is (in PointerTool), is there a way to define the key combination in I18N.properties, and somehow use that definition in my existing code? I'm hazy on how that interacts with AppActions, for instance, so I don't know what's possible.

Thanks!

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: Impersonation hotkeys, and where to lodge them

Post by Azhrei »

Rumble wrote:1. Right now, I have the code for handling the cycling through the tokens to impersonate as part of the PointerTool class. It went there because a) that's where I found many other accelerator key functions (which I used as a model for how to implement my stuff), so it seemed appropriate. It works fine, or appears to. Is that an acceptable place for it? Is it an undesirable, or wrong place for something like that? If it's the wrong place, what would the devs suggest is a better plan?
I'm not sure about whether I like this or not. :roll:

MT installs key handlers based on the "mode" the application is in, where the modes are defined as the toolbar buttons on the far left of the screen: Pointer, Drawing, and so on. So that means that the keystrokes can be different from one to the next. There have been numerous instances where I've wanted to type a keystroke (like the letter "T" to cycle through tokens) only to realize that I'm in the Distance Measuring mode and the "T" doesn't work there. :(

In 1.4 I hope to see a thought-out-in-advance list of keystrokes and a hierarchy so that most keystrokes would be "global" and then a small portion only work in certain modes. And while in those modes, the keystrokes are a superset, possibly redefining existing keystrokes but that would be avoided if possible.

The short answer to your question is "Yes, that's where I'd put them." 8)
2. I note that there are a number of accelerator keys defined in I18N.properties, and it would be great to define these impersonation key combos there to make localization easier. However, I don't actually know how to use what's defined in I18N.properties...I see most of the defined codes are part of AppActions, but does the impersonation bit belong there instead?
AppActions is really for UI actions AFAICT. That code should demonstrate how to retrieve the keycodes from the I18N file and convert it so that it can be used elsewhere. (Now that I think about it, the actual code is in I18N.java but AppActions would be one place where those methods are called.)
3. If it's okay where it is (in PointerTool), is there a way to define the key combination in I18N.properties, and somehow use that definition in my existing code? I'm hazy on how that interacts with AppActions, for instance, so I don't know what's possible.
Search the code for the CUT and PASTE actions which are mapped to "Ctrl C" and "Ctrl V". That would also be a good place to put your new keystrokes. Just be sure you get the ones that go with the PointerTool as the CUT and PASTE keystrokes are defined in multiple places, IIRC.

Thanks![/quote]

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Impersonation hotkeys, and where to lodge them

Post by Rumble »

Excellent. I had the feeling after looking things over that while Impersonation is (in my experience) almost always happening while I was in Pointer mode, that was probably due more to the fact that Pointer mode is a) the default mode, and b) the mode that lets you bring up the right-click menu.

However, impersonation didn't really have anything to do with pointing and selecting, so it felt out of place (of course it felt out of place after I'd gone and got it working, but...what can you do). Fortunately, the code itself is pretty simple and once I figure out how to use all the other fancy I18N stuff, it should be trivial to move.

Also, thanks for mentioning I18N.java; didn't think to look there.

Post Reply

Return to “Java Programming Info”