Example usage for java.awt.event KeyAdapter KeyAdapter

List of usage examples for java.awt.event KeyAdapter KeyAdapter

Introduction

In this page you can find the example usage for java.awt.event KeyAdapter KeyAdapter.

Prototype

KeyAdapter

Source Link

Usage

From source file:com.SCI.centraltoko.utility.UtilityTools.java

public static void setAutoUpperCase(final JTextArea textArea) {
    textArea.addKeyListener(new KeyAdapter() {

        @Override/* w  w  w  . ja  v  a 2 s  . co m*/
        public void keyReleased(KeyEvent e) {
            if (Character.isLetter(e.getKeyChar())) {
                convertToUpperCase((JTextArea) e.getSource());
            }
        }

    });
}

From source file:com.sec.ose.osi.ui.frm.main.identification.common.JComboComponentName.java

private void init() {

    final JTextField tfComponentName = (JTextField) this.getEditor().getEditorComponent();

    tfComponentName.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            char ch = e.getKeyChar();
            if (ch != KeyEvent.VK_ENTER && ch != KeyEvent.VK_BACK_SPACE && ch != KeyEvent.VK_SPACE
                    && (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)))
                return;

            if (ch == KeyEvent.VK_ENTER) {

                JComboComponentName.this.hidePopup();
                return;
            }//from   ww  w.j  av a2  s  . co m
            // 1. save string
            String keyword = tfComponentName.getText();//.trim();
            updateComboBoxList(keyword);

        }
    });

    tfComponentName.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            if (tfComponentName.getText().length() > 0)
                showPopup();
        }

        public void focusLost(FocusEvent e) {
            hidePopup();
        }
    });

}

From source file:com.haulmont.cuba.desktop.sys.vcl.DatePicker.DatePicker.java

@Override
public void setEditor(final JFormattedTextField editor) {
    final int ENTER_CODE = 10;

    editor.addKeyListener(new KeyAdapter() {
        @Override/*from  ww w . ja v a 2s . c o m*/
        public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() == '\u007F' && editor.getCaretPosition() < format.length()) {
                editor.setCaretPosition(editor.getCaretPosition() + 1);
            }
        }

        @Override
        public void keyPressed(KeyEvent event) {
            if (ENTER_CODE == event.getKeyCode())
                try {
                    editor.commitEdit();
                } catch (ParseException e) {
                    //
                }
        }
    });

    editor.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            editor.setCaretPosition(0);
        }
    });

    super.setEditor(editor);

    if (format == null) {
        setFormats(
                Datatypes.getFormatStrings(AppBeans.get(UserSessionSource.class).getLocale()).getDateFormat());
    } else
        setFormats(format);
}

From source file:Main.java

public Main(Synthesizer synth) {
    super("Drums");

    // Channel 10 is the GeneralMidi percussion channel. In Java code, we
    // number channels from 0 and use channel 9 instead.
    channel = synth.getChannels()[9];//  ww w  . j av a  2 s . com

    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            int key = e.getKeyCode();
            if (key >= 35 && key <= 81) {
                channel.noteOn(key, velocity);
            }
        }

        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
            if (key >= 35 && key <= 81)
                channel.noteOff(key);
        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseMoved(MouseEvent e) {
            velocity = e.getX();
        }
    });
}

From source file:Drums.java

public Drums(Synthesizer synth) {
    super("Drums");

    // Channel 10 is the GeneralMidi percussion channel. In Java code, we
    // number channels from 0 and use channel 9 instead.
    channel = synth.getChannels()[9];/*  w  ww .  ja  v a 2 s.c  o m*/

    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            int key = e.getKeyCode();
            if (key >= 35 && key <= 81) {
                channel.noteOn(key, velocity);
            }
        }

        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
            if (key >= 35 && key <= 81)
                channel.noteOff(key);
        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseMoved(MouseEvent e) {
            velocity = e.getX();
        }
    });
}

From source file:org.jcurl.demo.smack.ChatSimpleSwingBean.java

public ChatSimpleSwingBean() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    text = new JTextField();
    // see//  ww  w .j  ava  2 s . c  o m
    // http://java.sun.com/products/jfc/tsc/tech_topics/jlist_1/jlist.html:
    final KeyListener keyListener = new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent evt) {
            if ('\n' == evt.getKeyChar())
                try {
                    send(text.getText());
                    text.setText("");
                } catch (XMPPException e) {
                    log.error("Sending \"" + text.getText() + "\"", e);
                }
        }
    };
    text.addKeyListener(keyListener);
    add(text);
    setEnabled(false);
}

From source file:de.tor.tribes.ui.components.GroupSelectionList.java

public GroupSelectionList(String pResourceURL) {
    super(pResourceURL);

    setCellRenderer(renderer);/*from   ww w . j  av  a  2s.c om*/

    addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                fireDecrementEvent();
            } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                fireIncrementEvent();
            } else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                fireResetEvent();
            } else if (e.getKeyCode() == KeyEvent.VK_O) {
                fireSetStateEvent(ListItem.RELATION_TYPE.OR);
            } else if (e.getKeyCode() == KeyEvent.VK_U) {
                fireSetStateEvent(ListItem.RELATION_TYPE.AND);
            } else if (e.getKeyCode() == KeyEvent.VK_N) {
                fireSetStateEvent(ListItem.RELATION_TYPE.NOT);
            } else if (e.getKeyCode() == KeyEvent.VK_I) {
                fireSetStateEvent(ListItem.RELATION_TYPE.DISABLED);
            } else if (e.getKeyCode() == KeyEvent.VK_H) {
                JOptionPaneHelper.showInformationBox(GroupSelectionList.this, getRelationAsPlainText(),
                        "Information");
            }
        }
    });
    addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                if (e.getButton() == MouseEvent.BUTTON1) {
                    fireClickedEvent(e.getPoint());
                } else {
                    fireResetEvent(e.getPoint());
                }
            }
        }
    });
    TagManager.getSingleton().addManagerListener(GroupSelectionList.this);
}

From source file:finalproject.BloodGlucoseGUI.java

/**
 * Constructor//from   w ww. j  av  a 2  s . com
 * Creates new form BloodGlucoseGUI
 */
// I would put most of it in initComponents if I could 
// edit that generated code.
public BloodGlucoseGUI() {
    initComponents();
    //jfc = new JFileChooser("Resources/Data");

    // For "commercial" use
    //jfc = new JFileChooser("C:\\Program Files\\BGDataAnalysis\\Data");
    jfc = new JFileChooser("C:\\BGDataAnalysis\\Data");

    tabMod = new MyTableModel();
    jTable2.setModel(tabMod);

    listMod = new DefaultListModel();
    jList1.setModel(listMod);

    JTableHeader th = jTable2.getTableHeader();
    TableColumnModel tcm = th.getColumnModel();
    TableColumn tc = tcm.getColumn(0);
    tc.setHeaderValue("Time");
    tc = tcm.getColumn(1);
    tc.setHeaderValue("Blood Glucose");
    th.repaint();

    notesTextArea.setLineWrap(true);
    notesTextArea.setWrapStyleWord(true);

    notesTextArea.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                e.consume();

                ErrorGUIs.Popup pu = new ErrorGUIs.Popup();
                pu.add("Please don't press the ENTER button!");
                pu.display();
            }
        }
    });
}

From source file:ve.zoonosis.controller.seguridad.LoginController.java

public LoginController(Index index) {
    nombreUsuario.setPlaceHolder("Usuario");
    PromptSupport.setPrompt("Contrasea", contrasena);
    JMenuBar m = index.getJMenuBar();
    m.setVisible(false);//from w  w w. ja  v  a2  s  .co  m
    iniciar.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            iniciarSesion();
        }
    });
    contrasena.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            iniciarSesion(e);
        }

    });
    invitado.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            usuario = null;
            LOG.LOGGER.log(Level.INFO, "Usuario : Sesion de invitado");
            new ScanWeek().start();
            validarPermisos();
        }
    });
    nombreUsuario.requestFocus();
}

From source file:edu.mit.fss.tutorial.part4.ControlPanel.java

/**
 * Instantiates a new control panel.//ww  w  .j  av  a 2s  . c o m
 */
public ControlPanel() {
    setFocusable(true); // required for key listener
    setPreferredSize(new Dimension(300, 300));
    setBackground(Color.white);

    // Add a new KeyAdapter object instance to bind actions to key presses.
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (boundElement == null) {
                // Do nothing if no element is bound.
                return;
            }
            if (e.getKeyCode() == KeyEvent.VK_UP) {
                // Increment Y-velocity.
                boundElement.setVelocity(boundElement.getVelocity().add(new Vector3D(0, 1, 0)));
            } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                // Decrement Y-velocity.
                boundElement.setVelocity(boundElement.getVelocity().add(new Vector3D(0, -1, 0)));
            } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                // Decrement X-velocity.
                boundElement.setVelocity(boundElement.getVelocity().add(new Vector3D(-1, 0, 0)));
            } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                // Increment X-velocity.
                boundElement.setVelocity(boundElement.getVelocity().add(new Vector3D(1, 0, 0)));
            }
        }
    });
}