Example usage for java.awt.event KeyEvent getKeyChar

List of usage examples for java.awt.event KeyEvent getKeyChar

Introduction

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

Prototype

public char getKeyChar() 

Source Link

Document

Returns the character associated with the key in this event.

Usage

From source file:GUI.MainWindow.java

private void VulnAffectedHostsTableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_VulnAffectedHostsTableKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        showNotesForSpecificHost();//from   ww  w . j  av  a  2  s.co m
    } else if (evt.getKeyChar() == KeyEvent.VK_DELETE) {
        deleteAffectedHosts();
    } else if (evt.getKeyCode() == KeyEvent.VK_INSERT) {
        addAffectedHost();
    }

}

From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryFieldPanel.java

/**
 * @param iconSize/* w w w.  java 2 s .c  o m*/
 * @param returnWidths
 * @return
 */
protected int[] buildControlLayout(final IconManager.IconSize iconSize, final boolean returnWidths,
        final Component saveBtn) {
    FocusListener focusListener = new FocusListener() {

        /*
         * (non-Javadoc)
         * 
         * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
         */
        // @Override
        public void focusGained(FocusEvent e) {
            //Checking oppositeComponent to work around
            //weird behavior after addBtn is clicked which
            //causes top queryFieldPanel to be selected.
            if (ownerQuery.getAddBtn() != null && e.getOppositeComponent() != ownerQuery.getAddBtn()) {
                ownerQuery.selectQFP(QueryFieldPanel.this);
            }

        }

        /*
         * (non-Javadoc)
         * 
         * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
         */
        // @Override
        public void focusLost(FocusEvent e) {
            // nada
        }

    };

    KeyListener enterListener = new KeyListener() {

        @Override
        public void keyPressed(KeyEvent arg0) {
            //nuthin
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
            //nuthin
        }

        @Override
        public void keyTyped(KeyEvent arg0) {
            if (arg0.getKeyChar() == KeyEvent.VK_ENTER && ownerQuery != null) {
                ownerQuery.doSearch();
            }

        }

    };

    comparators = getComparatorList(fieldQRI);
    //XXX need to build schemaItem for header panel too...
    if (schemaMapping != null) {
        schemaItemCBX = edu.ku.brc.ui.UIHelper.createComboBox();
        schemaItemCBX.addItem("empty"); //to work around validator blow up for empty lists.
        DataChangeNotifier dcnsi = validator.hookupComponent(schemaItemCBX, "sicbx", UIValidator.Type.Changed,
                "", true);
        schemaItemCBX.addActionListener(dcnsi);

        schemaItemCBX.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (!QueryFieldPanel.this.ownerQuery.isUpdatingAvailableConcepts()) {
                    if (e.getStateChange() == ItemEvent.SELECTED) {
                        if (e.getItem() instanceof SpExportSchemaItem) {
                            QueryFieldPanel.this.schemaItem = (SpExportSchemaItem) e.getItem();
                        } else {
                            SpExportSchemaItemMapping m = QueryFieldPanel.this.getItemMapping();
                            SpExportSchemaItem si = QueryFieldPanel.this.schemaItem;
                            String item = e.getItem().toString();
                            if (StringUtils.isNotBlank(item)
                                    && ownerQuery.isAvailableExportFieldName(QueryFieldPanel.this, item)) {
                                if (m != null) {
                                    m.setExportedFieldName(e.getItem().toString());
                                }
                                if (si != null) {
                                    si.setFieldName(e.getItem().toString());
                                }
                            } else {
                                if (StringUtils.isBlank(item)) {
                                    UIRegistry.displayErrorDlgLocalized(
                                            "QueryFieldPanel.ExportFieldNameInvalid", item);
                                } else {
                                    UIRegistry.displayErrorDlgLocalized(
                                            "QueryFieldPanel.ExportFieldNameAlreadyUsed", item);
                                }
                                schemaItemCBX.setSelectedIndex(0);
                            }
                        }
                        ownerQuery.updateAvailableConcepts();
                    }
                }
            }
        });
    } else {
        schemaItemCBX = null;
    }

    iconLabel = new JLabel(icon);
    iconLabel.addFocusListener(focusListener);
    String fieldLabelText = fieldQRI != null ? fieldQRI.getTitle() : "WXYZ";
    if (fieldQRI instanceof RelQRI) {
        DBRelationshipInfo.RelationshipType relType = ((RelQRI) fieldQRI).getRelationshipInfo().getType();
        if (relType.equals(DBRelationshipInfo.RelationshipType.OneToMany)
                || relType.equals(DBRelationshipInfo.RelationshipType.ManyToMany)) {
            fieldLabelText += " " + UIRegistry.getResourceString("QB_AGGREGATED");
        } else {
            fieldLabelText += " " + UIRegistry.getResourceString("QB_FORMATTED");
        }

    }
    fieldLabel = createLabel(fieldLabelText);
    fieldLabel.addFocusListener(focusListener);
    fieldLabel.addKeyListener(enterListener);
    isNotCheckbox = createCheckBox("isNotCheckbox");
    isNotCheckbox.addFocusListener(focusListener);
    isNotCheckbox.addKeyListener(enterListener);
    operatorCBX = createComboBox(comparators);
    operatorCBX.addFocusListener(focusListener);
    operatorCBX.addKeyListener(enterListener);
    boolean isBool = fieldQRI != null && fieldQRI.getDataClass().equals(Boolean.class);
    if (!isBool) {
        operatorCBX.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    criteria.setVisible(!operatorCBX.getSelectedItem().equals(SpQueryField.OperatorType.EMPTY));
                }
            }
        });
    }
    if (pickList == null) {
        boolean hasBetweenOp = false;
        for (int o = 0; o < comparators.length; o++) {
            if (comparators[o].equals(OperatorType.BETWEEN)) {
                hasBetweenOp = true;
                break;
            }
        }
        if (hasBetweenOp) {
            criteria = new CriteriaPair(enterListener);
            operatorCBX.addActionListener(this);
        } else {
            criteria = createTextField("1");
            criteria.addKeyListener(enterListener);
        }
    } else {
        criteria = createPickList(saveBtn);
        if (!ownerQuery.isPromptMode()) {
            ((PickListCriteriaCombo) criteria)
                    .setCurrentOp((SpQueryField.OperatorType) operatorCBX.getModel().getElementAt(0));
        }
        criteria.addKeyListener(enterListener);
        operatorCBX.addItemListener(new ItemListener() {

            /*
             * (non-Javadoc)
             * 
             * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
             */
            //@Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    // System.out.println("setting curront op");
                    ((PickListCriteriaCombo) criteria)
                            .setCurrentOp((SpQueryField.OperatorType) operatorCBX.getSelectedItem());
                }
            }

        });
    }
    //criteria.addFocusListener(focusListener);

    sortCheckbox = new MultiStateIconButon(
            new ImageIcon[] { IconManager.getImage("GrayDot", IconManager.IconSize.Std16),
                    IconManager.getImage("UpArrow", IconManager.IconSize.Std16),
                    IconManager.getImage("DownArrow", IconManager.IconSize.Std16) });
    DataChangeNotifier dcn = validator.hookupComponent(sortCheckbox, "scb", UIValidator.Type.Changed, "", true);
    sortCheckbox.addFocusListener(focusListener);
    sortCheckbox.addActionListener(dcn);
    sortCheckbox.addKeyListener(enterListener);
    if (!this.ownerQuery.isPromptMode()) {
        isEnforcedCkbx = createCheckBox("isEnforcedCkbx");
        dcn = validator.hookupComponent(isEnforcedCkbx, "iecb", UIValidator.Type.Changed, "", true);
        isEnforcedCkbx.addActionListener(dcn);
        isEnforcedCkbx.addFocusListener(focusListener);
        isEnforcedCkbx.addKeyListener(enterListener);
    }
    if (!this.ownerQuery.isPromptMode()) {
        isDisplayedCkbx = createCheckBox("isDisplayedCkbx");
        dcn = validator.hookupComponent(isDisplayedCkbx, "idcb", UIValidator.Type.Changed, "", true);
        isDisplayedCkbx.addFocusListener(focusListener);
        isDisplayedCkbx.addKeyListener(enterListener);
        isDisplayedCkbx.addActionListener(dcn);
        isDisplayedCkbx.addActionListener(new ActionListener() {

            /* (non-Javadoc)
             * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
             */
            @Override
            public void actionPerformed(ActionEvent arg0) {
                SwingUtilities.invokeLater(new Runnable() {

                    /* (non-Javadoc)
                     * @see java.lang.Runnable#run()
                     */
                    @Override
                    public void run() {
                        sortCheckbox.setEnabled(isDisplayedCkbx.isSelected());
                        ownerQuery.changeNotification(QueryFieldPanel.this);
                    }
                });
            }
        });
        isPromptCkbx = createCheckBox("isPromptCkbx");
        dcn = validator.hookupComponent(isPromptCkbx, "ipcb", UIValidator.Type.Changed, "", true);
        isPromptCkbx.addActionListener(dcn);
        isPromptCkbx.addFocusListener(focusListener);
        isPromptCkbx.addKeyListener(enterListener);
        closeBtn = edu.ku.brc.ui.UIHelper.createIconBtn("Close", "QB_REMOVE_FLD", new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                boolean clearIt = schemaItem != null;
                ownerQuery.removeQueryFieldItem((QueryFieldPanel) ((JComponent) ae.getSource()).getParent());
                if (clearIt) {
                    setField(null, null);
                }
            }
        });
        closeBtn.setEnabled(true);
        closeBtn.setFocusable(false);
        closeBtn.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseEntered(MouseEvent e) {
                ((JButton) e.getSource()).setIcon(IconManager.getIcon("CloseHover"));
                super.mouseEntered(e);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                ((JButton) e.getSource()).setIcon(IconManager.getIcon("Close"));
                super.mouseExited(e);
            }

        });
    } else {
        isDisplayedCkbx = null;
        this.isPromptCkbx = null;
        this.isEnforcedCkbx = null;
        this.closeBtn = null;
    }

    JComponent[] qComps = { iconLabel, fieldLabel, isNotCheckbox, operatorCBX, criteria, sortCheckbox,
            isDisplayedCkbx, isPromptCkbx, isEnforcedCkbx, closeBtn, null };
    JComponent[] sComps = { schemaItemCBX, iconLabel, fieldLabel, isNotCheckbox, operatorCBX, criteria,
            sortCheckbox, isDisplayedCkbx, isEnforcedCkbx, closeBtn, null };
    // 0 1 2 3 4 5 6 7 8 9
    if (schemaMapping == null) {
        comps = qComps;
    } else {
        comps = sComps;
    }

    StringBuilder sb = new StringBuilder();
    Integer[] qFixedCmps = { 300 };
    Integer[] sFixedCmps = { 268, 300 };
    Integer[] fixedCmps;
    if (schemaMapping != null) {
        fixedCmps = sFixedCmps;
    } else {
        fixedCmps = qFixedCmps;
    }
    if (columnDefStr == null) {
        for (int i = 0; i < comps.length; i++) {
            sb.append(i == 0 ? "" : ",");
            if (isCenteredComp(i))
                sb.append("c:");
            if (i >= fixedCmps.length) {
                sb.append("p");
            } else {
                sb.append(fixedCmps[i] + "px");
            }
            if (isGrowComp(i))
                sb.append(":g");
            sb.append(",4px");
        }
    } else {
        sb.append(columnDefStr);
    }

    PanelBuilder builder = new PanelBuilder(new FormLayout("3px, " + sb.toString() + ", 3px", "3px, p, 3px"),
            this);
    CellConstraints cc = new CellConstraints();

    int col = 1;
    for (JComponent comp : comps) {
        if (comp != null) {
            builder.add(comp, cc.xy(col + 1, 2));
        }
        col += 2;
    }

    if (fieldQRI != null) {
        icon = IconManager.getIcon(fieldQRI.getTableInfo().getName(), iconSize);
        setIcon(icon);
    }
    if (!ownerQuery.isPromptMode()) {
        isDisplayedCkbx.setSelected(true);
        isPromptCkbx.setSelected(!(fieldQRI instanceof RelQRI));
        isEnforcedCkbx.setSelected(false);
    }

    if (fieldQRI == null && !returnWidths) {
        for (int c = 1; c < comps.length; c++) {
            if (comps[c] != null) {
                comps[c].setVisible(false);
            }
        }
    } else {
        // for now
        boolean isRel = fieldQRI != null && fieldQRI instanceof RelQRI;
        boolean isTreeLevel = fieldQRI instanceof TreeLevelQRI;
        isNotCheckbox.setVisible(!isRel || pickList != null);
        operatorCBX.setVisible(!isRel || pickList != null);
        criteria.setVisible((!isRel && !isBool) || pickList != null);
        if (schemaMapping != null) {
            this.sortCheckbox.setVisible(!(isTreeLevel || isRel));
        } else {
            if (!isRel) {
                this.sortCheckbox.setVisible(true);
            } else {
                this.sortCheckbox.setVisible(
                        ((RelQRI) fieldQRI).getRelationshipInfo().getType() != RelationshipType.OneToMany);
            }
        }

        if (!ownerQuery.isPromptMode()) {
            isDisplayedCkbx.setVisible(!isRel);
            isPromptCkbx.setVisible(!isRel);
            isEnforcedCkbx.setVisible(!isRel);
        }
    }
    validate();
    doLayout();

    int[] widths = null;
    if (returnWidths) {
        widths = new int[comps.length];
        for (int i = 0; i < comps.length; i++) {
            widths[i] = comps[i] != null ? comps[i].getSize().width : 0;
        }
        if (this.schemaMapping == null) {
            widths[0] = iconSize.size();
            widths[1] = 200;
        } else {
            widths[1] = iconSize.size();
            widths[2] = 200;
        }
    }
    return widths;
}

From source file:ca.canuckcoding.wosqi.FeedViewer.java

private void jTextField7KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField7KeyTyped
    if (evt.getKeyChar() == '\n' || evt.getKeyChar() == '\r') {
        query();//from   www  .  j a  va2 s  .c o  m
    }
}

From source file:ca.canuckcoding.wosqi.FeedViewer.java

private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyTyped
    if (evt.getKeyChar() == '\n' || evt.getKeyChar() == '\r') {
        query();/* w ww.java  2 s  .c  o  m*/
    }
}

From source file:ca.canuckcoding.wosqi.FeedViewer.java

private void jTextField2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyTyped
    if (evt.getKeyChar() == '\n' || evt.getKeyChar() == '\r') {
        query();/*from  ww  w .ja  v  a 2s  .co  m*/
    }
}

From source file:ca.canuckcoding.wosqi.FeedViewer.java

private void jTextField3KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField3KeyTyped
    if (evt.getKeyChar() == '\n' || evt.getKeyChar() == '\r') {
        query();/* w  w  w .j av  a  2  s  . com*/
    }
}

From source file:ca.canuckcoding.wosqi.FeedViewer.java

private void jTextField4KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField4KeyTyped
    if (evt.getKeyChar() == '\n' || evt.getKeyChar() == '\r') {
        query();/*w  w w  . j  a  v a  2 s  . c o m*/
    }
}

From source file:ca.canuckcoding.wosqi.FeedViewer.java

private void jTextField9KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField9KeyTyped
    if (evt.getKeyChar() == '\n' || evt.getKeyChar() == '\r') {
        query();/* ww  w . j ava2s .  c  o  m*/
    }
}

From source file:ca.canuckcoding.wosqi.FeedViewer.java

private void jTextField5KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField5KeyTyped
    if (evt.getKeyChar() == '\n' || evt.getKeyChar() == '\r') {
        query();//  w ww . j  a  va2  s.  c  o m
    }
}

From source file:ca.canuckcoding.wosqi.FeedViewer.java

private void jTextField6KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField6KeyTyped
    if (evt.getKeyChar() == '\n' || evt.getKeyChar() == '\r') {
        query();/*  w w  w.ja va  2s  . co m*/
    }
}