Example usage for javax.swing JComboBox getItemListeners

List of usage examples for javax.swing JComboBox getItemListeners

Introduction

In this page you can find the example usage for javax.swing JComboBox getItemListeners.

Prototype

@BeanProperty(bound = false)
public ItemListener[] getItemListeners() 

Source Link

Document

Returns an array of all the ItemListeners added to this JComboBox with addItemListener().

Usage

From source file:Main.java

public Main() {
    JComboBox jc = new JComboBox();
    jc.addItem("France");
    jc.addItem("Germany");
    jc.addItem("Italy");
    jc.addItem("Japan");
    jc.addItemListener(this);
    add(jc);//from  w  ww . j  av  a2 s  .  c o m
    ItemListener[] lis = jc.getItemListeners();

}

From source file:king.flow.action.DefaultMsgSendAction.java

protected void showDoneMsg(final TLSResult result) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override//from   w w w.j  a  v  a 2  s.  co  m
        public void run() {
            if (doneDisplayList.size() == 1) {
                showOnComponent(getBlockMeta(doneDisplayList.get(0)), result);
            } else {
                try {
                    JSONParser jsonParser = new JSONParser();
                    Object element = jsonParser.parse(result.getOkMsg());
                    if (element instanceof JSONArray) {
                        JSONArray jsonArray = (JSONArray) element;
                        int len = Integer.min(doneDisplayList.size(), jsonArray.size());
                        for (int i = 0; i < len; i++) {
                            TLSResult freshResult = new TLSResult(result.getRetCode(),
                                    jsonArray.get(i).toString(), result.getErrMsg(), result.getPrtMsg());
                            showOnComponent(getBlockMeta(doneDisplayList.get(i)), freshResult);
                        }
                    } else {
                        showOnComponent(getBlockMeta(doneDisplayList.get(0)), result);
                    }
                } catch (Exception e) {
                    getLogger(DefaultMsgSendAction.class.getName()).log(Level.WARNING,
                            "Exception encounters during successful json value parsing : \n{0}", e);
                }
            }

            CommonUtil.cachePrintMsg(result.getPrtMsg());
            if (result.getRedirection() != null) {
                String redirection = result.getRedirection();
                getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO,
                        "Be forced to jump to page[{0}], ignore designated page[{1}]",
                        new Object[] { redirection, String.valueOf(next.getNextPanel()) });
                int forwardPage = 0;
                try {
                    forwardPage = Integer.parseInt(redirection);
                } catch (Exception e) {
                    panelJump(next.getNextPanel());
                    return;
                }
                Object blockMeta = getBlockMeta(forwardPage);
                if (blockMeta == null || !(blockMeta instanceof Panel)) {
                    getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO,
                            "Be forced to jump to page[{0}], but page[{0}] is invalid Panel type. It is type[{1}]",
                            new Object[] { redirection,
                                    (blockMeta == null ? "NULL" : blockMeta.getClass().getSimpleName()) });
                    panelJump(next.getNextPanel());
                    return;
                }
                panelJump(forwardPage);
            } else {
                panelJump(next.getNextPanel());

                //trigger the action denoted in sendMsgAction
                Integer trigger = next.getTrigger();
                if (trigger != null && getBlockMeta(trigger) != null) {
                    final Component blockMeta = (Component) getBlockMeta(trigger);
                    switch (blockMeta.getType()) {
                    case COMBO_BOX:
                        JComboBox comboBlock = getBlock(trigger, JComboBox.class);
                        ItemListener[] itemListeners = comboBlock.getItemListeners();
                        ItemEvent e = new ItemEvent(comboBlock, ItemEvent.ITEM_STATE_CHANGED,
                                comboBlock.getItemAt(comboBlock.getItemCount() - 1).toString(),
                                ItemEvent.SELECTED);
                        for (ItemListener itemListener : itemListeners) {
                            itemListener.itemStateChanged(e);//wait and hang on util progress dialog gets to dispose
                        }
                        if (comboBlock.isEditable()) {
                            String value = comboBlock.getEditor().getItem().toString();
                            if (value.length() == 0) {
                                return;
                            }
                        }
                        break;
                    case BUTTON:
                        JButton btnBlock = getBlock(trigger, JButton.class);
                        btnBlock.doClick();
                        break;
                    default:
                        getLogger(DefaultMsgSendAction.class.getName()).log(Level.WARNING,
                                "Invalid trigger component[{0}] as unsupported type[{1}]",
                                new Object[] { trigger, blockMeta.getType() });
                        break;
                    }
                } //trigger dealing 
                  //keep next cursor on correct component
                Integer nextCursor = next.getNextCursor();
                if (nextCursor != null && getBlockMeta(nextCursor) != null) {
                    JComponent block = getBlock(nextCursor, JComponent.class);
                    block.requestFocusInWindow();
                }
            } // no redirection branch
        }
    });
}

From source file:org.forester.archaeopteryx.ControlPanel.java

public void setSequenceRelationQueries(final Collection<Sequence> sequenceRelationQueries) {
    final JComboBox box = getSequenceRelationBox();
    while (box.getItemCount() > 1) {
        box.removeItemAt(1);/*from   w  w w  .  j a  va2 s  . c  o m*/
    }
    final HashMap<String, Sequence> sequencesByName = new HashMap<String, Sequence>();
    final SequenceRelation.SEQUENCE_RELATION_TYPE relationType = (SequenceRelation.SEQUENCE_RELATION_TYPE) _sequence_relation_type_box
            .getSelectedItem();
    if (relationType == null) {
        return;
    }
    final ArrayList<String> sequenceNamesToAdd = new ArrayList<String>();
    for (final Sequence seq : sequenceRelationQueries) {
        if (seq.hasSequenceRelations()) {
            boolean fFoundForCurrentType = false;
            for (final SequenceRelation sq : seq.getSequenceRelations()) {
                if (sq.getType().equals(relationType)) {
                    fFoundForCurrentType = true;
                    break;
                }
            }
            if (fFoundForCurrentType) {
                sequenceNamesToAdd.add(seq.getName());
                sequencesByName.put(seq.getName(), seq);
            }
        }
    }
    // sort sequences by name before adding them to the combo
    final String[] sequenceNameArray = sequenceNamesToAdd.toArray(new String[sequenceNamesToAdd.size()]);
    Arrays.sort(sequenceNameArray, String.CASE_INSENSITIVE_ORDER);
    for (final String seqName : sequenceNameArray) {
        box.addItem(seqName);
    }
    for (final ItemListener oldItemListener : box.getItemListeners()) {
        box.removeItemListener(oldItemListener);
    }
    box.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            _selected_query_seq = sequencesByName.get(e.getItem());
            _mainpanel.getCurrentTreePanel().repaint();
        }
    });
}