Example usage for java.awt Component removeKeyListener

List of usage examples for java.awt Component removeKeyListener

Introduction

In this page you can find the example usage for java.awt Component removeKeyListener.

Prototype

public synchronized void removeKeyListener(KeyListener l) 

Source Link

Document

Removes the specified key listener so that it no longer receives key events from this component.

Usage

From source file:Main.java

/**
 * Inserts the key listener at the particular index in the listeners' chain.
 *
 * @param component/*w w w  .  ja  va  2 s  . co m*/
 * @param l
 * @param index
 */
public static void insertKeyListener(Component component, KeyListener l, int index) {
    KeyListener[] listeners = component.getKeyListeners();

    for (KeyListener listener : listeners) {
        component.removeKeyListener(listener);
    }

    for (int i = 0; i < listeners.length; i++) {
        KeyListener listener = listeners[i];

        if (index == i) {
            component.addKeyListener(l);
        }

        component.addKeyListener(listener);
    }

    // inex is too large, add to the end.
    if (index > listeners.length - 1) {
        component.addKeyListener(l);
    }
}

From source file:Main.java

/**
 * Remove key listeners form the argument component.
 * //w ww  .j a v a2 s  . c o m
 * @param cmp The component.
 */
public static void removeKeyListeners(Component cmp) {
    KeyListener[] listeners = cmp.getKeyListeners();
    if (listeners != null) {
        for (KeyListener listener : listeners) {
            cmp.removeKeyListener(listener);
        }
    }
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Removes all the focus listeners for a component.
 * @param comp the comp//from   ww w . j  a v  a 2  s  . c  o  m
 */
public static void removeKeyListeners(final Component comp) {
    if (comp != null) {
        for (KeyListener l : comp.getKeyListeners()) {
            comp.removeKeyListener(l);
        }
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.Uploader.java

/**
 * Shuts down upload UI.//from w w w.ja v  a 2s . c o  m
 * @param notifyWB - If true, notify this Uploader's WorkBench.
 */
public void closeMainForm(boolean notifyWB) {
    try {
        logDebug("closing main form");
        mainPanel.setVisible(false);
        mainPanel = null;
        closeUploadedDataViewers();

        for (Component c : keyListeningTo) {
            logDebug("removing key listener");
            c.removeKeyListener(this);
        }
        keyListeningTo.clear();

        if (notifyWB) {
            wbSS.uploadDone();
        }
    } finally {
        currentUpload = null;
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.Uploader.java

/**
 * Moves to dataset cell corresponding to currently selected validation issue and starts editor.
 *//*from   w ww. j a v  a  2  s .  c o  m*/
protected void goToMsgWBCell(final Component c, boolean stopEdit) {
    if (mainPanel == null) {
        throw new RuntimeException("Upload form does not exist.");
    }
    if (wbSS != null) {
        UploadMessage msg;
        if (c == mainPanel.getValidationErrorList()) {
            msg = (UploadMessage) mainPanel.getValidationErrorList().getSelectedValue();
        } else {
            msg = (UploadMessage) mainPanel.getMsgList().getSelectedValue();
        }

        if (msg == null) {
            logDebug("gotToMsgWBCell: null message");
            return;
        }

        if (msg.getRow() != -1) {
            if (msg.getCol() == -1) {
                wbSS.getSpreadSheet().scrollToRow(msg.getRow());
                wbSS.getSpreadSheet().getSelectionModel().clearSelection();
                wbSS.getSpreadSheet().getSelectionModel().setSelectionInterval(msg.getRow(), msg.getRow());
            } else {
                wbSS.getSpreadSheet().getSelectionModel().clearSelection();
                Rectangle rect = wbSS.getSpreadSheet().getCellRect(msg.getRow(), msg.getCol(), false);
                wbSS.getSpreadSheet().scrollRectToVisible(rect);
                if (msg instanceof UploadTableInvalidValue && msg.getCol() != -1) {
                    if (!stopEdit) {

                        wbSS.getSpreadSheet().editCellAt(msg.getRow(), msg.getCol(), null);

                        // Now, if necessary, add this as a listener to the editorComponent to
                        // allow moving to
                        // next/prev
                        // invalid cell after ENTER/TAB/UP/DOWN
                        Component editor = wbSS.getSpreadSheet().getEditorComponent();
                        boolean addListener = true;
                        if (editor != null) {
                            KeyListener[] listeners = editor.getKeyListeners();
                            for (int k = 0; k < listeners.length; k++) {
                                if (listeners[k] instanceof Uploader) {
                                    if (listeners[k] == this) {
                                        logDebug("already listening to spreadsheet editor");
                                        addListener = false;
                                        break;
                                    }
                                    // should never get here, but just in case:
                                    logDebug("removing previous listener");
                                    editor.removeKeyListener(listeners[k]);
                                }
                            }
                            if (addListener) {
                                logDebug("adding this as listener to spreadsheet editor");
                                editor.addKeyListener(this);
                                this.keyListeningTo.add(editor);
                            }
                            editor.requestFocusInWindow();
                        }
                    } else {
                        if (wbSS.getSpreadSheet().getCellEditor() != null) {
                            wbSS.getSpreadSheet().getCellEditor().stopCellEditing();
                        }
                    }
                }
            }
        }
    }
    if (mainPanel == null) {
        throw new RuntimeException("Upload form does not exist.");
    }
}