Example usage for javax.swing DefaultListModel get

List of usage examples for javax.swing DefaultListModel get

Introduction

In this page you can find the example usage for javax.swing DefaultListModel get.

Prototype

public E get(int index) 

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java

private void fireAddTroopFilterEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireAddTroopFilterEvent
    UnitHolder unit = (UnitHolder) jFilterUnitBox.getSelectedItem();
    DefaultListModel filterModel = (DefaultListModel) jFilterList.getModel();
    TroopFilterElement elem = null;/*from   w ww  . j  a v  a 2s . com*/
    int min = Integer.MIN_VALUE;
    int max = Integer.MAX_VALUE;
    try {
        min = Integer.parseInt(jMinValue.getText());
    } catch (Exception e) {
        min = Integer.MIN_VALUE;
    }
    try {
        max = Integer.parseInt(jMaxValue.getText());
    } catch (Exception e) {
        max = Integer.MAX_VALUE;
    }
    if (min > max) {
        int tmp = min;
        min = max;
        max = tmp;
        jMinValue.setText("" + min);
        jMaxValue.setText("" + max);
    }

    for (int i = 0; i < filterModel.size(); i++) {
        TroopFilterElement listElem = (TroopFilterElement) filterModel.get(i);
        if (listElem.getUnit().equals(unit)) {
            //update min and max and return
            listElem.setMin(min);
            listElem.setMax(max);
            jFilterList.repaint();
            return;
        }
    }
    if (elem == null) {
        elem = new TroopFilterElement(unit, min, max);
        filterModel.addElement(elem);
    }
}

From source file:edu.ku.brc.specify.plugins.TaxonLabelFormatting.java

/**
 * Formats the same String./*from  ww w  . ja v  a2  s .c o  m*/
 */
protected void doFormatting() {
    drawList.clear();

    Object fmtObj = formatCBX.getValue();
    if (fmtObj == null) {
        return;
    }

    String format = fmtObj.toString();
    //System.out.println("["+format+"]");
    if (StringUtils.isNotEmpty(format) && format.length() > 0) {
        DefaultListModel model = (DefaultListModel) authorsList.getModel();

        StringBuilder chars = new StringBuilder();
        StringBuilder exp = new StringBuilder();
        int len = format.length();
        StringBuilder pat = new StringBuilder();
        for (int i = 0; i < len; i++) {
            char ch = format.charAt(i);
            if (ch == '%') {
                if (chars.length() > 0) {
                    drawList.add(new TextDrawInfo(FormatType.Plain, chars.toString()));
                    chars.setLength(0);
                }
                ch = format.charAt(++i);
                pat.setLength(0);
                pat.append('%');
                do {
                    if (Character.isLetter(ch) || Character.isDigit(ch)) {
                        pat.append(ch);
                    } else {
                        i--;
                        break;
                    }
                    i++;
                    if (i < len) {
                        ch = format.charAt(i);
                    }
                } while (i < len);

                FormatType ft = FormatType.Plain;
                String val = "";
                String token = pat.toString();
                if (token.equals("%S")) {
                    val = getByRank(taxon, 220).getName();
                    ft = FormatType.Italic;

                } else if (token.equals("%G")) {
                    val = getByRank(taxon, 180).getName();
                    ft = FormatType.Italic;

                } else if (token.charAt(1) == 'A') {
                    int authNum = Integer.parseInt(token.substring(2)) - 1;
                    if (authNum < model.getSize()) {
                        val = ((Agent) model.get(authNum)).getLastName();
                    } else {
                        val = token;
                    }
                }
                exp.append(val);
                drawList.add(new TextDrawInfo(ft, val));
            } else {
                exp.append(ch);
                chars.append(ch);
            }
        }
        if (chars.length() > 0) {
            drawList.add(new TextDrawInfo(FormatType.Plain, chars.toString()));
            chars.setLength(0);
        }
        specialLabel.repaint();
    }
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private String checkInfos(final boolean submodel) {
    final DefaultListModel listModel = (DefaultListModel) parameterList.getModel();
    for (int i = 0; i < listModel.getSize(); ++i) {
        final AvailableParameter param = (AvailableParameter) listModel.get(i);
        final String invalid = submodel ? checkSubmodelInfo(param.info) : checkFileInfo(param);
        if (invalid != null)
            return invalid;
    }//from  w  w  w . j ava 2  s .c  o  m

    for (final ParameterCombinationGUI pGUI : parameterTreeBranches) {
        final DefaultMutableTreeNode root = pGUI.combinationRoot;
        @SuppressWarnings("rawtypes")
        final Enumeration nodes = root.breadthFirstEnumeration();
        nodes.nextElement(); // root
        while (nodes.hasMoreElements()) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement();
            final ParameterInATree userObj = (ParameterInATree) node.getUserObject();
            final String invalid = submodel ? checkSubmodelInfo(userObj.info) : checkFileInfo(userObj);
            if (invalid != null)
                return invalid;
        }
    }

    return null;
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private ParameterTree createParameterTreeFromParamSweepGUI() throws ModelInformationException {
    final ParameterTree result = new ParameterTree();

    final DefaultListModel listModel = (DefaultListModel) parameterList.getModel();
    for (int i = 0; i < listModel.getSize(); ++i) {
        final AvailableParameter param = (AvailableParameter) listModel.get(i);
        final AbstractParameterInfo<?> batchParameter = InfoConverter.parameterInfo2ParameterInfo(param.info);
        ParameterTreeUtils.addConstantParameterToParameterTree(batchParameter, result, currentModelHandler);
    }/* w  w  w  . j  a va  2s  .  c  o m*/

    for (final ParameterCombinationGUI pGUI : parameterTreeBranches) {
        final DefaultMutableTreeNode root = pGUI.combinationRoot;
        @SuppressWarnings("rawtypes")
        final Enumeration nodes = root.breadthFirstEnumeration();
        nodes.nextElement(); // root;
        while (nodes.hasMoreElements()) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement();
            final ParameterInATree userObj = (ParameterInATree) node.getUserObject();
            ParameterTreeUtils.filterConstants(userObj, result, currentModelHandler);
        }
    }

    for (final ParameterCombinationGUI pGUI : parameterTreeBranches) {
        final DefaultMutableTreeNode root = pGUI.combinationRoot;
        @SuppressWarnings("rawtypes")
        final Enumeration nodes = root.preorderEnumeration();
        nodes.nextElement(); // root
        ParameterNode parent = result.getRoot();
        while (nodes.hasMoreElements()) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement();
            final ParameterInATree userObj = (ParameterInATree) node.getUserObject();
            if (ParameterTreeUtils.isMutableParameter(userObj)) {
                final AbstractParameterInfo<?> batchParameter = InfoConverter
                        .parameterInfo2ParameterInfo(userObj.info);
                batchParameter.setRunNumber(1);
                final ParameterNode parameterNode = new ParameterNode(batchParameter);
                parent.add(parameterNode);
                parent = parameterNode;
            }
        }
    }

    return result;
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private void savePSParameterList(final ObjectFactory factory, final Model model) {
    final DefaultListModel listModel = (DefaultListModel) parameterList.getModel();

    if (!listModel.isEmpty()) {
        for (int i = 0; i < listModel.getSize(); ++i) {
            final AvailableParameter availableParameter = (AvailableParameter) listModel.get(i);

            final DefaultParameter defaultParameter = factory.createDefaultParameter();
            defaultParameter.setName(availableParameter.info.getName());
            model.getDefaultParameterList().add(defaultParameter);
        }//from w w w . j  av  a 2s  .co  m
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.ApplicationProperties.java

private void saveAndClose() {
    personalSettings.clearFavourites();/*w w  w.  j  a  va 2 s.  c  om*/
    DefaultListModel model = (DefaultListModel) lstFavourites.getModel();
    int size = model.getSize();
    for (int i = 0; i < size; i++) {
        final String favourite = (String) model.get(i);
        personalSettings.addFavourite(favourite);
    }
    personalSettings.clearFilesToIgnore();
    model = (DefaultListModel) lstFilesToIgnore.getModel();
    size = model.getSize();
    for (int i = 0; i < size; i++) {
        final PersonalSettings.FileDescriptions fileToIgnore = (PersonalSettings.FileDescriptions) model.get(i);
        personalSettings.addFileToIgnore(fileToIgnore);
    }
    personalSettings.setStandardFont(theStandardFont);
    personalSettings.setSortRunningAscending(chkSortRunning.isSelected());
    personalSettings.setSortPendingAscending(chkSortPending.isSelected());
    personalSettings.setSortFailedAscending(chkSortFailed.isSelected());
    personalSettings.setSortDepositedAscending(chkSortDeposited.isSelected());
    personalSettings.setSortCompleteAscending(chkSortComplete.isSelected());
    try {
        personalSettings.setNoOfRetries(Integer.parseInt(txtNoOfRetries.getText()));
    } catch (Exception ex) {
        LOG.error("Error setting no of retries", ex);
    }

    theParent.setFormFont(theStandardFont);
    closeForm();
}

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java

private void lstUsersValueChanged(javax.swing.event.ListSelectionEvent evt) {
    int selectedIndex = theUserList.getSelectedIndex();
    if (selectedIndex >= 0) {
        DefaultListModel model = (DefaultListModel) theUserList.getModel();
        configuratorFrame.showUser((IndigoUser) model.get(selectedIndex));
    }// w  ww  . ja v a  2s  .  c om
}

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java

public void deleteSipStatus() {
    if (theSipList == null) {
        return;// w  ww .ja v  a2 s.  co  m
    }
    DefaultListModel model = (DefaultListModel) theSipList.getModel();
    int selectedIndex = theSipList.getSelectedIndex();
    SIPStatus status = (SIPStatus) model.get(selectedIndex);
    sipStatusCollection.deleteStatus(status);
    model.remove(selectedIndex);
    int newSize = model.size();
    if (newSize > 0) {
        if (selectedIndex >= (newSize - 1)) {
            selectedIndex = newSize - 1;
        }
        theSipList.setSelectedIndex(selectedIndex);
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java

public void deleteUser() {
    if (theUserList == null) {
        return;//  www  .  j  ava 2  s .co  m
    }
    DefaultListModel model = (DefaultListModel) theUserList.getModel();
    int selectedIndex = theUserList.getSelectedIndex();
    IndigoUser user = (IndigoUser) model.get(selectedIndex);
    userData.deleteUser(user);
    model.remove(selectedIndex);
    int newSize = model.size();
    if (newSize > 0) {
        if (selectedIndex >= (newSize - 1)) {
            selectedIndex = newSize - 1;
        }
        theUserList.setSelectedIndex(selectedIndex);
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java

public void moveItem(boolean up) {
    if (canMoveItem(up)) {
        int currentIndex = theDataList.getSelectedIndex();
        int otherIndex;
        if (up) {
            otherIndex = currentIndex - 1;
        } else {/*w  w  w .  j a  va  2 s .  co m*/
            otherIndex = currentIndex + 1;
        }
        MetaDataTypeImpl dataFrom = (MetaDataTypeImpl) theDataList.getSelectedValue();
        DefaultListModel model = (DefaultListModel) theDataList.getModel();
        MetaDataTypeImpl dataTo = (MetaDataTypeImpl) model.get(otherIndex);
        int orderFrom = dataFrom.getSortOrder();
        dataFrom.setSortOrder(dataTo.getSortOrder());
        dataTo.setSortOrder(orderFrom);
        metaData.reSort();
        loadMetaData();
        theDataList.setSelectedIndex(otherIndex);
        saveConfigurationFile();
    }
}