Example usage for java.awt.event ItemEvent ITEM_STATE_CHANGED

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

Introduction

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

Prototype

int ITEM_STATE_CHANGED

To view the source code for java.awt.event ItemEvent ITEM_STATE_CHANGED.

Click Source Link

Document

This event id indicates that an item's state changed.

Usage

From source file:Main.java

public void itemStateChanged(ItemEvent ie) {
    System.out.println(ie.getID() == ItemEvent.ITEM_STATE_CHANGED);
}

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 a2 s. c om*/
    }
}

From source file:ItemEventComponent.java

public void processEvent(AWTEvent e) {
    if (e.getID() == MouseEvent.MOUSE_PRESSED) {
        if (itemListener != null) {
            selected = !selected;//from ww  w.ja va 2  s .  co  m
            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) {/*  w ww  .  j av a2  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:king.flow.action.DefaultMsgSendAction.java

protected void showDoneMsg(final TLSResult result) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override//from w  w w  .  ja v a2 s . c  om
        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
        }
    });
}