Example usage for javax.swing JComboBox removeItemListener

List of usage examples for javax.swing JComboBox removeItemListener

Introduction

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

Prototype

public void removeItemListener(ItemListener aListener) 

Source Link

Document

Removes an ItemListener.

Usage

From source file:Main.java

/**
 * remove all items silently/*from   ww  w .j  av  a2 s  .com*/
 * @param aComboBox combo box
 * @param aListener listener
 */
public final static void RemoveAllItemsSilently(JComboBox aComboBox, ItemListener aListener) {
    aComboBox.removeItemListener(aListener);
    aComboBox.removeAllItems();
    aComboBox.addItemListener(aListener);
}

From source file:Main.java

/**
 * select index silently//from w ww  .  j  av  a2  s .  com
 * @param aComboBox combo box
 * @param anIndex index
 * @param aListener listener to be removed when selecting index
 */
public final static void SelectIndexSilently(JComboBox aComboBox, int anIndex, ItemListener aListener) {
    aComboBox.removeItemListener(aListener);
    aComboBox.setSelectedIndex(anIndex);
    aComboBox.addItemListener(aListener);
}

From source file:Main.java

/**
 * add item silently/*from w ww  .j  a  v  a  2 s  .  co  m*/
 * @param aComboBox combo box
 * @param anObject object to be added
 * @param aListener listener
 */
public final static void AddItemSilently(JComboBox aComboBox, Object anObject, ItemListener aListener) {
    aComboBox.removeItemListener(aListener);
    aComboBox.addItem(anObject);
    aComboBox.addItemListener(aListener);
}

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   ww  w .j  a v  a2 s.  co 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();
        }
    });
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.LocationDialog.java

/**
 * Populates the JComboBox with the items provided adding hover tooltips,
 * selecting the specified item and attaching the listener.
 * //  ww  w.  j  a  va 2s  .  c  om
 * @param comboBox The JComboBox to populate
 * @param listItems The items to populate the box with
 * @param select The item to select in the JComboBox
 * @param itemListener An item listener to add for the JComboBox
 */
private void displayItems(JComboBox comboBox, List<DataNode> listItems, DataNode select,
        ItemListener itemListener) {
    if (comboBox == null || listItems == null)
        return;
    //Only add the item the user can actually select
    if (itemListener != null)
        comboBox.removeItemListener(itemListener);
    comboBox.removeAllItems();

    List<String> tooltips = new ArrayList<String>(listItems.size());
    List<String> lines;
    ExperimenterData exp;
    SelectableComboBoxModel model = new SelectableComboBoxModel();
    Selectable<DataNode> selected = null;

    GroupData group = getSelectedGroup();
    ExperimenterData user = getSelectedUser();
    long userID = -1;
    if (user != null)
        userID = user.getId();
    ExperimenterData loggedIn = ImporterAgent.getUserDetails();
    boolean isAdmin = ImporterAgent.isAdministrator();
    long loggedInID = loggedIn.getId();
    boolean userIsAdmin = isAdmin(userID);
    for (DataNode node : listItems) {
        exp = getExperimenter(node.getOwner());
        lines = new ArrayList<String>();
        if (exp != null) {
            lines.add("<b>Owner: </b>" + EditorUtil.formatExperimenter(exp));
        }
        lines.addAll(UIUtilities.wrapStyleWord(node.getFullName()));
        tooltips.add(UIUtilities.formatToolTipText(lines));

        boolean selectable = true;
        if (!node.isDefaultNode()) {
            selectable = canLink(node.getDataObject(), userID, group, loggedInID, isAdmin, userIsAdmin);
        }

        Selectable<DataNode> comboBoxItem = new Selectable<DataNode>(node, selectable);
        if (select != null && node.getDataObject().getId() == select.getDataObject().getId())
            selected = comboBoxItem;

        model.addElement(comboBoxItem);
    }

    ComboBoxToolTipRenderer renderer = createComboboxRenderer();
    renderer.setTooltips(tooltips);
    comboBox.setModel(model);
    comboBox.setRenderer(renderer);

    if (selected != null)
        comboBox.setSelectedItem(selected);

    if (itemListener != null)
        comboBox.addItemListener(itemListener);
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.LocationDialog.java

/**
 * Populates the JComboBox with the user details provided, 
 * selecting the logged in user and attaching the item listener.
 * /*from   w ww. j  a v a2s  . com*/
 * @param comboBox The JComboBox to populate
 * @param group The group being displayed
 * @param itemListener An item listener to add for the JComboBox
 * @param userID The id of the user.
 */
private void displayUsers(JComboBox comboBox, GroupData group, ItemListener itemListener, long userID) {

    if (comboBox == null || group == null)
        return;

    if (itemListener != null)
        comboBox.removeItemListener(itemListener);
    comboBox.removeAllItems();

    DefaultComboBoxModel model = new SelectableComboBoxModel();
    Selectable<ExperimenterDisplay> selected = null;

    List<ExperimenterData> members = sort(group.getExperimenters());
    boolean canImportAs;
    Selectable<ExperimenterDisplay> item;
    List<String> tooltips = new ArrayList<String>(members.size());
    List<String> lines;
    for (ExperimenterData user : members) {
        canImportAs = canImportForUserInGroup(user, group);
        item = new Selectable<ExperimenterDisplay>(new ExperimenterDisplay(user), canImportAs);
        if (user.getId() == userID)
            selected = item;
        lines = new ArrayList<String>();
        lines.addAll(UIUtilities.wrapStyleWord(EditorUtil.formatExperimenter(user)));
        tooltips.add(UIUtilities.formatToolTipText(lines));
        model.addElement(item);
    }
    ComboBoxToolTipRenderer renderer = createComboboxRenderer();
    renderer.setTooltips(tooltips);
    comboBox.setModel(model);
    comboBox.setRenderer(renderer);

    if (selected != null)
        comboBox.setSelectedItem(selected);

    if (itemListener != null)
        comboBox.addItemListener(itemListener);
}

From source file:shuffle.fwk.service.teams.EditTeamService.java

private void updateKeybindComboBoxes() {
    Team curTeam = getCurrentTeam();/*from   w  ww  . java 2s.c o  m*/
    for (String name : curTeam.getNames()) {
        ItemListener itemListener = nameToItemListenerMap.get(name);
        JComboBox<Character> box = nameToKeybindComboboxMap.get(name);
        box.removeItemListener(itemListener);
        Character prevSelected = box.getItemAt(box.getSelectedIndex());
        box.removeAllItems();
        Character curBinding = curTeam.getBinding(name);
        LinkedHashSet<Character> availableBindings = new LinkedHashSet<Character>(Arrays.asList(curBinding));
        availableBindings.addAll(myData.getAllAvailableBindingsFor(name, curTeam));
        for (Character ch : availableBindings) {
            if (ch != null) {
                box.addItem(ch);
            }
        }
        box.setSelectedItem(prevSelected);
        if (box.getSelectedIndex() < 0) {
            LOG.warning(getString(KEY_NO_BINDINGS));
        }
        box.addItemListener(itemListener);
    }
}