Cannot get KeyListener to work with JAI ScrollImagePanel

I am trying to display a TIF image and use the page up and page down keys to show page 1 and page 2 of the image. I started with an example for the JAI documentation.
The problem is that I can't get the key event listener to "see" keystokes.
I think ScrollImagePanel() is doing its own event listening and I don't know how to get at it.
Here is the code:
// http://java.sun.com/products/java-media/jai/forDevelopers/samples/MultiPageRead.java
A single page of a multi-page TIFF file may loaded most easily by using the page
parameter with the "TIFF" operator which is documented in the class comments of
javax.media.jai.operator.TIFFDescriptor. This example shows a
means of loading a single page of a multi-page TIFF file using the ancillary codec
classes directly.
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.awt.image.RenderedImage;
import java.awt.image.renderable.ParameterBlock;
import javax.media.jai.*;
import javax.media.jai.widget.*;
import com.sun.media.jai.codec.*;
public class MultiPageRead4 extends Frame
            implements KeyListener {                              //1
    ScrollingImagePanel panel;
    File file = null;
    ImageDecoder dec = null;
    RenderedImage op = null;
    // side to load, 0=front and 1=back
    static int imageToLoad = 0;
    /** The key code to flip between back and front images */
    private static final int FLIP_IMAGE_KEY1 = KeyEvent.VK_PAGE_UP;
    private static final int FLIP_IMAGE_KEY2 = KeyEvent.VK_PAGE_DOWN;
    /** Short cut key to exit the application */
    private static final int EXIT_KEY = KeyEvent.VK_ESCAPE;
    public MultiPageRead4(String filename) throws IOException {  //2
        super("Multi page TIFF Reader");
        // won't work here either
        // addKeyListener(this);
        addWindowListener(new WindowAdapter() {                  //3
           public void windowClosing(WindowEvent we) {           //4
           System.exit(0);
           }                                                     //4
        });                                                      //3
        if(file == null) {                                       //3
            file = new File(filename);
            SeekableStream s = new FileSeekableStream(file);
            TIFFDecodeParam param = null;
            dec = ImageCodec.createImageDecoder("tiff", s, param);
            System.out.println("Number of images in this TIFF: " +
                               dec.getNumPages());
            // Which of the multiple images in the TIFF file do we want to load
            // 0 refers to the first, 1 to the second and so on.
            // int imageToLoad = 1;
            }                                                    //3
        // display side of tiff indicated by imageToLoad which is initialized to 0
        // and set by page up / page down
        displaySide();
        }                                                         //2
    // Methods required by the KeyListener interface.
     * Process a key being pressed. Does nothing as we wait for the
     * release before moving.
     * @param evt The event that caused this method to be called
    public void keyPressed(KeyEvent evt)
         System.out.println("Key pressed.");   // debug -- see if it works
        // do nothing
     * Process a key being type (press and release). Does nothing as this is
     * always dodgy about when we get the event. Better to look for the
     * release.
     * @param evt The event that caused this method to be called
    public void keyTyped(KeyEvent evt)
         System.out.println("Key typed.");    // debug -- see if it works
        // do nothing
     * Process a key being pressed. Does nothing as we wait for the
     * release before moving.
     * @param evt The event that caused this method to be called
    public void keyReleased(KeyEvent evt)
    {                                                              //2
        System.out.println("Key released.");  // debug -- see if it works
        switch(evt.getKeyCode())
        {                                                         //3
            case EXIT_KEY:
                System.exit(0);
                break;
            case FLIP_IMAGE_KEY1:
               if(imageToLoad == 1) {                             //4
                  imageToLoad = 0;
                  displaySide();
                  break;
               }                                                  //4
            case FLIP_IMAGE_KEY2:
               if(imageToLoad == 0) {                             //4
                  imageToLoad = 1;
                  displaySide();
                  break;
               }                                                  //4
        }                                                         //3
    }                                                             //2
    public void displaySide() {                                   //2
        try {
            op = new NullOpImage(dec.decodeAsRenderedImage(imageToLoad),
                            null,
                            OpImage.OP_IO_BOUND,
                            null);
            }  catch (java.io.IOException ioe) {
                  System.out.println(ioe);
    * Create a standard bilinear interpolation object to be
    * used with the �scale� operator.
       Interpolation interp = Interpolation.getInstance(
             Interpolation.INTERP_BILINEAR);
    * Stores the required input source and parameters in a
    * ParameterBlock to be sent to the operation registry,
    * and eventually to the �scale� operator.
       ParameterBlock params = new ParameterBlock();
    // params.addSource(image1);
       params.addSource(op);
       params.add(0.70F); // x scale factor
       params.add(0.70F); // y scale factor
       params.add(0.0F); // x translate
       params.add(0.0F); // y translate
       params.add(interp); // interpolation method
    /* Create an operator to scale image1. */
       RenderedOp image2 = JAI.create("scale", params);
    /* Get the width and height of image2 + 3% */
       int width = (int)(image2.getWidth() * 1.03);
       int height = (int)(image2.getHeight() * 1.03);
    /* Attach image2 to a scrolling panel to be displayed. */
       panel = new ScrollingImagePanel(
          image2, width, height);
       panel.addKeyListener(this);
       // Display the original in a 800x800 scrolling window
       // panel = new ScrollingImagePanel(op, 1000, 600);
       add(panel);
       pack();
       show();
                                                                  //2
    public static void main(String [] args) {
        String filename = "034363331.TIF";
        try {
            MultiPageRead4 window = new MultiPageRead4(filename);
            }  catch (java.io.IOException ioe) {
                  System.out.println(ioe);
        System.out.println("finished.");
// http://java.sun.com/products/java-media/jai/forDevelopers/samples/MultiPageRead.javaI can't get the KeyListener to act (or send the debug messages to System.out.println()).
If "add( panel );" is removed and the comment before " keyListener(this); " in the constructor the key listening logic works -- of course no image is displayed.
Thanks for any help.
Bill Blalock

Thanks for exanding your explanation. I am not yet skilled enough in Java to follow you completely but I am getting the idea.
I would appreciate a code snippet using my example so I can better understand. In the mean time I found one way to make it work.
In the example I eventually found that this change ..
       show();
       panel.requestFocus();enabled the key listener. Bringing the window, even clicking on the panel, didn't give it focus. I understand that the window has to have the focus in order for the key listener to function (different from the mouse listender). I don't understand why the application did not have "focus" even though it was on top and active.
Oh well, lots to learn.
Thanks for your suggestion!

Similar Messages

  • HT4437 The airplay on my i pad works with music and pictures but I cannot get it to work with safari and mirroring.  Does anyone know what I could be doing wrong? Thanks!!

    The airplay on my i pad works with music and pictures but I cannot get it to work with safari and mirroring.  Can someone help me to get things working?  Thanks!

    As an IT person, I can put my hands up to the same difficulty.  Then on double clicking on Home button, find AirTV symbol amongst Music control
    Solved my problem having spent hours looking for a complicated answer.  Well done Apple for hiding it so well.
    Brian

  • Cannot get Mail to work with BT

    I have suddenly encountered a problem with Mail. I cannot now get it to work with my BT account.
    When I Get Mail the progress bar shows from 7 to 15 items for download. The download speed decays to zero the progress bar stalls and nothing arrives.
    My .Mac mail is fine though. So I have attempted to get BT to forward my mail to .Mac having deleted the BT account in Mail, but as yet no sign of that work-around helping either.
    Is there a bug somewhere? Have had no problem with Mail for years and years.
    17 inch iMac and fully up to date.

    It may be frustrating, but there's a reason it's doing that; we just need to figure out why. So, what kind of email account do you have, and how long have you had it? When did this problem start, and what did you install just prior to this happening, if anything?
    Mulder

  • Cannot get printer to work with iMac

    I cannot get my Epson printer to work with my iMac , It just keeps saying it cannot find printer.
    All the other settings are correct , its just the server that fails. I have downloaded printer files ,
    sometimes it does recongise it and works, then it stops, I have tried downloading the program again but it makes no difference.
    Need to use printer and scanner for my job, and this is driving me mad!!

    It sounds like BT's hardware may have a firewall that's blocking more than it should.
    http://support.apple.com/kb/HT3669
    is the printer/scanner listing from Apple.
    Use this link: http://support.apple.com/kb/dl1398 to get the latest Epson drivers if your printer/scanner is compatible.
    If it isn't, here are some alternatives from my macmaps page:
    Epson, alternate Australian site may have more up-to-date drivers for Epson, Epson RIP and colormatching drivers from iProof Systems, Guten-Print (formerly known as Gimp-print), and Printfab. http://www.linuxprinting.org/macosx/

  • Cannot get HDR to work with files from Canon 40D

    Hello,
    I have read various tutorials and the forum and there seem to be a number of things that have to be just right to get the Automate Merge to HDR Pro to work.
    I obtain the images on a tripod using a timer and auto expose a stop bracket.  I understand white balance setting may be a problem...
    But no matter what I do I get a merged file with very bight colors essentially all over.
    I have trief JPEG and TIFF conversions from RAW.
    Any ideas/checklist?  THis is CS5, completely updated.
    Thanks

    It sounds like BT's hardware may have a firewall that's blocking more than it should.
    http://support.apple.com/kb/HT3669
    is the printer/scanner listing from Apple.
    Use this link: http://support.apple.com/kb/dl1398 to get the latest Epson drivers if your printer/scanner is compatible.
    If it isn't, here are some alternatives from my macmaps page:
    Epson, alternate Australian site may have more up-to-date drivers for Epson, Epson RIP and colormatching drivers from iProof Systems, Guten-Print (formerly known as Gimp-print), and Printfab. http://www.linuxprinting.org/macosx/

  • Cannot get ODBC to work with Instant Client

    Hi,
    I am having problems getting ODBC working with instant client. This is what I have done so far:
    1. I installed Instant Client from this page: http://www.oracle.com/technetwork/topics/winsoft-085727.html
    The file I downloaded was: instantclient-basic-win32-10.2.0.3-20061115.zip
    2. Next, I installed SQL*Plus with this file: instantclient-sqlplus-win32-10.2.0.3-20061115.zip
    Now I have SQL*Plus working with instant client.
    3. After that I downloaded instantclient-odbc-win32-10.2.0.3-20061115.zip for ODBC.
    4. I unzipped the odbc zip file into the Instant Client folder and ran odbc_install.exe. Now I have 'Oracle in instantclient 10_2' showing up in the drivers tab of ODBC Data Source Administrator.
    5. Now, if I try to add add a DSN and choose 'Oracle in instantclient 10_2' as the data source, I get an error "ODBC Administrator has stopped working" (http://i50.tinypic.com/jifl2g.png)
    I can add DSNs using any other data source without problems. The aforementioned error comes up only when I use 'Oracle in instantclient 10_2' as the data source.
    Can someone please let me know how to resolve this?
    I am running Windows Vista Business edition 32-bit.
    Thanks & Regards,
    Ubaidullah Nubar.
    Edited by: unubar on Dec 17, 2012 9:42 PM

    Two dimensions of compatibility/requirements:
    Vertically - This is your application, APIs, .Net, operating system etc. that may define requirements on Oracle Client version, and vice versa.
    Horisontally - "on the wire" or connectivity wise - Oracle certifies client - server interoperability at least two releases or major versions back/apart, so yes, 10.2 is/was* supported. See MOS interoperability matrix for your specific case.
    (*was since 10.2 Database is out of support or even Extended support by now. Perhaps it is time to upgrade the server side also ;-))

  • I cannot get anything to work with the iPhone Configuration Utility

    I have to set up 30 ipad 2's with restrictions set on them for the students...i created the configuration profile and click install and nothing happens...i have been to the extensive (two article) help tutorial...i have done everything it says to do...i cannot email the config to them because we don't want them using email...so not wanting to set up 30 ipads with an email addy...was wondering if there was another program with better tech support articles and is easy to set up and use...this is kinda useless...

    Jaheedi, it sounds like you've tried a lot to make this work....my experience has been that in mlost cases if a profile fails to install it is usually due to a required payload not having been configured.  It can happen if a payload category gets opened(General for example) inadvertently and then payloads within that category are not completed.(Identifier for example), then the profile will fail to install.  Also, I've only got it to reliably work over a USB connection ( we use encrypted profiles with a "with authentication" removal option).....you might try installing a very basic profile with just the General Payload category expanded ( and required payloads completed) and see if that works..if that works, it  probably is one of the other categories is incomplete.  If you haven't tried the above, I hope this helps a bit. 

  • Cannot get "passwd" to work with pam_winbind (Active Directory/Samba)

    I've have a Samba Active Directory server and AD users can log in to linux boxes. I'd like them to be able to change their passwords from Linux.
    I've set up winbind and PAM and users can log in fine. However, users cannot change passwords.
    I used the PAM configuration as per the wiki, although I note that /etc/pam.d/passwd doesn't include the "system-auth" file that the Wiki instructions describe. I can either paste the "password" entries into /etc/pam.d/passwd or modify it to include "system-auth". I've tried both ways without any luck. Here is the PAM config I have (from the Wiki instructions):
    password [success=1 default=ignore] pam_localuser.so
    password [success=2 default=die] pam_winbind.so
    password [success=1 default=die] pam_unix.so sha512 shadow
    password requisite pam_deny.so
    password optional pam_permit.so
    and here is a typical session
    $ passwd
    Changing password for MYDOMAIN\myuser
    (current) NT password:
    Enter new NT password:
    Retype new NT password:
    passwd: Authentication failure
    passwd: password unchanged
    and the journal (I enabled debug in the above config)
    Mar 02 13:59:48 tsodium passwd[981]: pam_winbind(passwd:chauthtok): [pamh: 0x9c1fe98] ENTER: pam_sm_chauthtok (flags: 0x4000)
    Mar 02 13:59:48 tsodium passwd[981]: pam_winbind(passwd:chauthtok): username [MYDOMAIN\myuser] obtained
    Mar 02 13:59:48 tsodium passwd[981]: pam_winbind(passwd:chauthtok): getting password (0x00000021)
    Mar 02 13:59:51 tsodium passwd[981]: pam_winbind(passwd:chauthtok): request wbcLogonUser succeeded
    Mar 02 13:59:51 tsodium passwd[981]: pam_winbind(passwd:chauthtok): user 'MYDOMAIN\myuser' granted access
    Mar 02 13:59:51 tsodium passwd[981]: pam_winbind(passwd:chauthtok): [pamh: 0x9c1fe98] LEAVE: pam_sm_chauthtok returning 0 (PAM_SUCCESS)
    Mar 02 13:59:51 tsodium passwd[981]: pam_winbind(passwd:chauthtok): [pamh: 0x9c1fe98] ENTER: pam_sm_chauthtok (flags: 0x2000)
    Mar 02 13:59:51 tsodium passwd[981]: pam_winbind(passwd:chauthtok): username [MYDOMAIN\myuser] obtained
    Mar 02 13:59:51 tsodium passwd[981]: pam_winbind(passwd:chauthtok): getting password (0x00000001)
    Mar 02 13:59:58 tsodium passwd[981]: pam_winbind(passwd:chauthtok): user 'MYDOMAIN\myuser' denied access (incorrect password or invalid membership)
    Mar 02 13:59:58 tsodium passwd[981]: pam_winbind(passwd:chauthtok): [pamh: 0x9c1fe98] LEAVE: pam_sm_chauthtok returning 7 (PAM_AUTH_ERR)
    I've done a bit of searching and have seen others reporting the same "incorrect password or invalid membership" but nothing concreate on how this should be configured. So I'd really appreciate anyone who can share a working configuration...

    Hello,
    We are getting the same message output: "com.sco.tta.common.asadutils", but ours say: "com.sco.tta.common.asadutils.ExpiredEvaluationException: ErrEvalExpired\Session failed: Command execution failed"
    Does anyone know where can I get info about this output?
    cs0aluc, how did you get your error fixed?
    Thanks in advance.

  • Cannot get VPN to work with new WRT400N router - wired works

    After successfully using VPN with my WRT45G v3 wireless router for years the internet connection suddenly quit working. Called Linksys and they suggested buying support or getting a new router. I bought a WRT400n dual band router.
    I have a work laptop that is Windows XP and a personal laptop that is Vista. The wireless network is up and running; both laptops can connect to the internet. The problem is when I try to use my work laptop and VPN to the company network the internet connection on that loptop drops and I have to reboot to reconnect. If I use the ethernet port on the router the VPN works fine.
    I can use a limited access version of the VPN software on my personal laptop with no issues (limited due to security restrictions). 
    I have called linksys support, my ISP support, and company support. My company support suggest that it is a security setting on the Linksys wireless network.
    Has anyone run into similar issues? The VPN software is by Juniper Networks  - Network Connect 6.4.0.

    Make sure all the Ports required for your VPN software are forwarded on your router...Try to reduce the Security to WEP on your Linksys router...
    Also change the MTU Size to 1300 and see if you are able to connect to your VPN...
    If nothing works you should reset and then re-configure your router...

  • (Visual C#) Cannot Get ReadFile to work with a Physical Drive

    I can get ReadFile to read a simple text file, but when I attempt to read a physical drive, I get the error "The
    parameter is incorrect."
    using System;
    using System.Runtime.InteropServices;
    namespace ReadFileTest
    class Program
    [DllImport("kernel32.dll")]
    static extern unsafe uint GetLastError();
    [DllImport("kernel32", SetLastError = true)]
    static extern unsafe System.IntPtr CreateFile
    string FileName, // file name
    uint DesiredAccess, // access mode
    uint ShareMode, // share mode
    uint SecurityAttributes, // Security Attributes
    uint CreationDisposition, // how to create
    uint FlagsAndAttributes, // file attributes
    int hTemplateFile // handle to template file
    [DllImport("kernel32.dll", SetLastError = true)]
    static extern unsafe bool ReadFile
    IntPtr hFile,
    [Out] byte[] lpBuffer,
    uint nNumberOfBytesToRead,
    out uint lpNumberOfBytesRead,
    IntPtr lpOverlapped
    const uint GENERIC_READ = 0x80000000;
    const uint GENERIC_WRITE = 0x050000000;
    const uint GENERIC_ALL = 0x10000000;
    const uint FILE_SHARE_READ = 1;
    const uint FILE_SHARE_WRITE = 2;
    const uint OPEN_EXISTING = 3;
    const int INVALID_HANDLE_VALUE = -1;
    static void Main(string[] args)
    unsafe
    // Reading a simple text file works perfectly:
    //IntPtr handle = CreateFile("D:\\Test.txt", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
    // CreateFile of a physical drive gives me a valid handle.
    // But when attempting to read the drive, (all of my drives give the same result), I get the error "The parameter is incorrect."
    IntPtr handle = CreateFile(@"\\.\PHYSICALDRIVE2", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
    // GetLastError returns this:
    // ERROR_INVALID_PARAMETER87 (0x57)
    // The parameter is incorrect.
    byte[] b = { 1, 2, 3, 4, 5 };
    uint n = 1;
    while (n != 0)
    bool ret = ReadFile(handle, b, (uint)5, out n, (IntPtr)0);
    uint e = GetLastError();
    // I have unmounted the physical drive and run the test with the same results.
    // I tried using pointers for the parameters, same result.
    // I tried different variations of options for CreateFile.
    // Don't know which parameter is giving the error.

    If the drive has real partitions on it, you will not be able to open the drive because of security.  This has been the case for a number of versions. What are you trying to do?
    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

  • I have installed the latest version of Adobe Flash but I still cannot get Firefox to work with it???

    I have installed the latest version of Adobe Flash. However I still can not get any videos to play nor can I upload photos to other sites???
    == This happened ==
    Every time Firefox opened
    == I tried to view videos/upload pics to sites requiring the latest version of Adobe Flash

    I would strongly suggest updating Firefox to 3.6.6 to begin with by following these instructions: [[Updating Firefox]].
    Then I would follow these instructions to install flash in Firefox: [[Installing the Flash plugin]]

  • I cannot get firefox to work with my internet browser firefox. unfortunatelt\y i have to use explorer if i want to see my email

    i can't use firefox for getting my email. comcast is my internet provider and they can't fix the problem. i have to use explorer which works fine. i have a hp pavilion entertainment pc laptop that uses the XP operating system. i would prefer to use firefox.
    == This happened ==
    Every time Firefox opened
    == it's been over a year

    What kind of problem do you have when you try to access your email? What do you see or not see that is different from what you expect?
    You said that Comcast can't fix the problem. Have you contacted their support? What did they say was the problem?

  • Cannot Get Airplay to Work with Airpot Express on PC Laptop

    Until recently, I had Airplay available on both my PC Laptop (Windows 7) and MacBook Pro (OS 10.8.4). I have had to reboot Airport Express because of a power failure. The MacBook immediately picked up the Airport Express and iTines Airplay works fine. However, the laptop cannot find Airport Express, When I run Airport Utiliity, it scans and rescans but cannot locate it. iTunes on the PC does not let me configure for Airplay. Any help would be appreciated.

    Sure ...
    To disable the Windows 7 software firewall:
    Right-click on the Network icon in the System Tray (lower-right corner of the Windows desktop.)
    Click on "Open Network and Sharing Center."
    In the lower left of the Network and Sharing Center window, click on Windows Firewall.
    In the next window, click on "Turn Windows Firewall on or off."
    In the Customize Settings window click on the "Turn off Windows Firewall (not recommended)" option to disable it. (Note: You will return here to re-enable the Windows Firewall.)
    Click OK to close the window.
    To enable IPv6 on your laptop's wireless interface:
    Right-click on the Network icon in the System Tray.
    Click on "Open Network and Sharing Center."
    Click on "Change adapter settings" in the left side of the window.
    Right-click on your wireless connection, and then, choose Properties.
    In the Properties list verify that "Internet Protocol Version 6 (TCP/IPv6)" option is checked. If it's not, enabled it.
    Click OK to close the window.
    Close the Network and Sharing Center window to return to the Windows Desktop.

  • Cannot get eprint to work with my email address

    Hey Guys,
    I cannot seem to setup my eprint with my existing email address.  Here are my settings:
    IMAP config
    Incoming: mail.hover.com port: 993 SSL: enabled
    Outgoing: mail.hover.com port 465 SSL: enabled
    Please help!

    Greenhitman wrote:
    Hey Guys,
    I cannot seem to setup my eprint with my existing email address.  Here are my settings:
    IMAP config
    Incoming: mail.hover.com port: 993 SSL: enabled
    Outgoing: mail.hover.com port 465 SSL: enabled
    Please help!
    Looks like your email domain is @hover.com, is that right? 
    Can you provide a little more information?
    What device are you sending the email from (laptop, pc, smartphone, etc.)? 
    What printer model? 
    Have you added your printer to your account on www.hpeprintcenter.com?  If you check your ePrint log there, what is the status of the print jobs you sent? 
    Do you receive confirmation emails when you send an ePrint to your printer's email address?
    Have you confirmed your emails meet formatting requirements, e.g., less than 5MB in size, email is only addressed to the printer (no CC's or other email addresses in the "To" field).  
    Thanks! 
    I am an HP employee.

  • Cannot get iChat to work with my 2-wire router

    I have gone into the router and opened all the ports necessary to iChat but I still cannot connect to co-workers.
    My AIM works as does SKYPE.
    I can invite to chat but the other person cannot connect.
    Anyone else have this problem?

    Hi,
    Which 2Wire device do you have ?
    Have you turned off the Firewall in the router ?
    Have you disabled Ping Blocking in the router ?
    (I take it you mean Video Chats ?)
    9:07 PM      Wednesday; December 21, 2011
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
      iMac 2.5Ghz 5i 2011 (Lion 10.7.2)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

Maybe you are looking for