Example usage for java.awt.event ItemEvent ItemEvent

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

Introduction

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

Prototype

public ItemEvent(ItemSelectable source, int id, Object item, int stateChange) 

Source Link

Document

Constructs an ItemEvent object.

Usage

From source file:Main.java

void fireItemEvent(Object item, boolean sel) {
    ItemEvent evt = new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, item,
            sel ? ItemEvent.SELECTED : ItemEvent.DESELECTED);

    Object[] listeners = listenerList.getListenerList();

    for (int i = 0; i < listeners.length - 2; i += 2) {
        if (listeners[i] == ItemListener.class) {
            ((ItemListener) listeners[i + 1]).itemStateChanged(evt);
        }//from  ww  w . jav a 2s . c om
    }
}

From source file:ItemEventComponent.java

public void processEvent(AWTEvent e) {
    if (e.getID() == MouseEvent.MOUSE_PRESSED) {
        if (itemListener != null) {
            selected = !selected;/*from w  ww  . j  a  v  a 2  s  .c  om*/
            i++;
            itemListener.itemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
                    getSelectedObjects(), (selected ? ItemEvent.SELECTED : ItemEvent.DESELECTED)));
        }
    }
}

From source file:mulavito.gui.control.CountingPickedState.java

@Override
public boolean pick(T v, boolean b) {
    boolean prior_state = picked.contains(v);
    if (b) {/*from w w  w. ja  va  2  s.co m*/
        if (prior_state == false)
            fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, v, ItemEvent.SELECTED));

        picked.add(v);
    } else {
        if (prior_state == true) {
            picked.remove(v, 1);

            if (!picked.contains(v))
                fireItemStateChanged(
                        new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, v, ItemEvent.DESELECTED));
        }
    }
    return prior_state;
}

From source file:Java2sAutoTextField.java

void setSelectedValue(Object obj) {
        if (isFired) {
            return;
        } else {//from   www . j  a v a  2 s . c  om
            isFired = true;
            setSelectedItem(obj);
            fireItemStateChanged(new ItemEvent(this, 701, selectedItemReminder, 1));
            isFired = false;
            return;
        }
    }

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

protected void showDoneMsg(final TLSResult result) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override/* w ww .j  a v  a 2 s  . c o 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
        }
    });
}