Hello,

Yes, key event handling was been added to JMapPane recently in
response to a request from another list member. Here is the original
thread:

http://osgeo-org.1803224.n2.nabble.com/JAR-for-org-geotools-gui-swing-tp6749717p6749717.html

As you can see, the discussion stopped after the initial code was
added so the only testing that it has received, at least that I know
about, is the basic unit testing in the code base. I'm not surprised
to hear that it doesn't work perfectly yet - I've been waiting for bug
reports to appear and have been slightly worried that they haven't :)

As far as I understand my own code, the map pane is not *consuming*
the key events, it is listening to them via the MapPaneKeyHandler
class which is just an implementation of Swing's KeyListener
interface. So although it is breaking your original code I'm not sure
that there is a bug. Happy to be corrected on that if I'm missing
something.

Regarding your code example, what is it trying to do ?  Specifically,
why are you using reflection ?

A more general comment about the MapPaneKeyHandler class: I opted for
the KeyListener approach, rather than using Swing component key
bindings, partly because I thought it would be easier for gt-swt and
any future GeoTools GUI modules to follow the same track. Looking at
it now, that doesn't make much sense because there is no gt-swing
module interface involved for other modules to implement, plus it
makes it forces applications using JMapPane to handle component focus
(see the JMapFrame code as an example). So I'm thinking of swapping
the code over to using key bindings instead. If you have any thoughts
on this I'd be keen to hear.

Michael


On 23 October 2011 21:48,  <[email protected]> wrote:
> Hello,
> when I create my own jFrame/jDialog, and I use JMapPane like this:
>
> public class MapPositionChooser extends JDialog implements KeyListener {
>   private JMapPane mapPane;
>
>   public MapPositionChooser(File mapFile) {
>      //...
>      this.mapPane = new JMapPane(new MapContent());
>      this.getContentPane().add(this.mapPane);
>      this.addKeyListener(this);
>   }
>
>   @Override
>   public void keyPressed(KeyEvent e) {
>        for (Field f : KeyEvent.class.getDeclaredFields()) {
>                f.setAccessible(true);
>                try {
>                        if (f.get(null).equals(e.getKeyCode())) {
>                                log.debug("Unknown action for key pressed. 
> code=" + e.getKeyCode() + ", that is: " + f.getName());
>                                break;
>                        }
>                } catch (Exception e1) {
>                }
>        }
>        log.debug("Unknown action for key pressed. code=" + e.getKeyCode());
>   }
> }
>
> Than I do not receive any keypress event. In 2.7.2 geotools version it does 
> worked.
>
> Workaround is to add keylistener directly to map pane:
>
>      this.mapPane.addKeyListener(this);
>
> PS: Map pane is now handling panning map with left,right,up and down keys. I 
> see MapPaneKeyHandler class is used in setKeyHandler on map pane. Is there 
> any other types of map pane key handlers? Specifically I am searching for 
> some num pad key handler (I have made one, so if there is need for this type 
> of key handler, I could contribute it).
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Cisco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities.
> http://p.sf.net/sfu/cisco-dev2dev
> _______________________________________________
> Geotools-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-devel
>

------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Cisco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to