Example usage for javax.swing DefaultListModel DefaultListModel

List of usage examples for javax.swing DefaultListModel DefaultListModel

Introduction

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

Prototype

DefaultListModel

Source Link

Usage

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

/**
 * Filter target lists by selected continents
 *//*from   w ww.j  a  v a 2s  .  com*/
private void fireFilterTargetByContinentEvent() {
    Object[] conts = jTargetContinentList.getSelectedValues();
    //build list of allowed continents
    List<Integer> allowedContinents = new LinkedList<Integer>();
    for (Object cont : conts) {
        int contId = Integer.parseInt(((String) cont).replaceAll("K", ""));
        allowedContinents.add(contId);
    }

    List<Tribe> tribes = new ArrayList<Tribe>();
    for (Object tribe : jTargetTribeList.getSelectedValues()) {
        tribes.add((Tribe) tribe);
    }

    Village[] filtered = VillageUtils.getVillagesByContinent(
            VillageUtils.getVillages(tribes.toArray(new Tribe[tribes.size()])),
            allowedContinents.toArray(new Integer[allowedContinents.size()]), Village.CASE_INSENSITIVE_ORDER);

    DefaultListModel villageModel = new DefaultListModel();
    for (Village v : filtered) {
        villageModel.addElement(v);
    }
    jTargetVillageList.setModel(villageModel);
}

From source file:edu.ku.brc.af.ui.forms.FormViewObj.java

/**
 * Sets the appropriate index in the list box
 * @param list the list box//from   ww w.  jav a 2  s .  c  o  m
 * @param data the data value
 */
protected static void setListValue(final JList list, final Object data) {

    Iterator<?> iter = null;
    if (data instanceof Set<?>) {
        iter = ((Set<?>) data).iterator();

    } else if (data instanceof org.hibernate.collection.PersistentSet) {
        iter = ((org.hibernate.collection.PersistentSet) data).iterator();
    }

    if (iter != null) {
        DefaultListModel defModel = new DefaultListModel();
        while (iter.hasNext()) {
            defModel.addElement(iter.next());
        }
        list.setModel(defModel);

    } else {
        ListModel model = list.getModel();
        for (int i = 0; i < model.getSize(); i++) {
            Object item = model.getElementAt(i);
            if (item instanceof String) {
                if (((String) item).equals(data)) {
                    list.setSelectedIndex(i);
                    return;
                }
            } else if (item.equals(data)) {
                list.setSelectedIndex(i);
                return;
            }
        }
    }
}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

@Override
public void dataChangedEvent(String pGroup) {
    List<ManageableType> elements = TagManager.getSingleton().getAllElements();

    List<Tag> tags = new ArrayList<Tag>();
    for (ManageableType e : elements) {
        Tag t = (Tag) e;/*from w  ww. j a v a 2 s  . c o m*/
        tags.add(t);
    }

    Collections.sort(tags, new Comparator<Tag>() {

        @Override
        public int compare(Tag o1, Tag o2) {
            try {
                return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());
            } catch (Exception e) {
                return 0;
            }
        }
    });

    DefaultListModel tagModel = new DefaultListModel();
    tagModel.addElement(NoTag.getSingleton());
    for (Tag t : tags) {
        tagModel.addElement(t);
    }
    jVillageGroupList.setModel(tagModel);
    //select all groups and initialize lists
    jVillageGroupList.getSelectionModel().setSelectionInterval(0, (elements.size() > 0) ? elements.size() : 0);

}

From source file:src.gui.ItSIMPLE.java

/**
 * @return the planListFramePanel/* w ww.  j ava 2s . c om*/
 */
private ItFramePanel getPlanListFramePanel() {
    if (planListFramePanel == null) {
        planListFramePanel = new ItFramePanel(":: Plan", ItFramePanel.MINIMIZE_MAXIMIZE);
        planListFramePanel.setParentSplitPane(planDetailsSplitPane);

        planListModel = new DefaultListModel();
        planList = new JList(planListModel);
        planList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                // this is done to enable or disable the remove plan action button
                if (planList.getSelectedIndex() < 0) {
                    removePlanActionButton.setEnabled(false);
                    editPlanActionButton.setEnabled(false);
                } else {
                    removePlanActionButton.setEnabled(true);
                    editPlanActionButton.setEnabled(true);
                }
            }
        });

        planList.addMouseListener(new MouseListener() {
            public void mouseClicked(MouseEvent e) {
                if (planList.getSelectedIndex() > 0 && e.getClickCount() == 2) {
                    editPlanAction.actionPerformed(null);
                }
            }

            public void mouseEntered(MouseEvent arg0) {
            }

            public void mouseExited(MouseEvent arg0) {
            }

            public void mousePressed(MouseEvent arg0) {
            }

            public void mouseReleased(MouseEvent arg0) {
            }

        });

        // initialize the buttons
        addPlanActionButton = new JButton(addPlanAction);
        addPlanActionButton.setToolTipText("Add an action to the plan");

        removePlanActionButton = new JButton(removePlanAction);
        removePlanActionButton.setToolTipText("Remove selected action");

        editPlanActionButton = new JButton(editPlanAction);
        editPlanActionButton.setToolTipText("Edit selected action");

        importPlanButton = new JButton(importPlanAction);
        importPlanButton.setToolTipText("Import plan from xml file");

        exportPlanButton = new JButton(exportPlanAction);
        exportPlanButton.setToolTipText("Export current plan");

        checkPlanValidityButton = new JButton(checkPlanValidity);
        checkPlanValidityButton.setToolTipText(
                "<html>Validate plan with validator VAL <br>(based on the generated PDDL model).</html>");

        //quickEvaluateButton = new JButton(quickEvaluation);
        //quickEvaluateButton.setToolTipText("Quick evaluation of the selected plan");

        //fullEvaluationButton = new JButton(generateEvaluatioReport);
        //fullEvaluationButton.setToolTipText("<html>Full evaluation of the selected plan. <br> Generate a plan evaluation in the planReport. <br> This is restricted to non-time-based domain only.</html>");
        //fullEvaluationButton.setText("");

        addPlanActionButton.setEnabled(false);
        removePlanActionButton.setEnabled(false);
        editPlanActionButton.setEnabled(false);
        checkPlanValidityButton.setEnabled(false);
        //quickEvaluateButton.setEnabled(false);
        //fullEvaluationButton.setEnabled(false);
        importPlanButton.setEnabled(false);
        exportPlanButton.setEnabled(false);

        JToolBar planListToolBar = new JToolBar();
        planListToolBar.add(addPlanActionButton);
        planListToolBar.add(removePlanActionButton);
        planListToolBar.add(editPlanActionButton);
        planListToolBar.addSeparator();
        planListToolBar.add(checkPlanValidityButton);
        //planListToolBar.add(quickEvaluateButton);
        //planListToolBar.add(fullEvaluationButton);
        planListToolBar.addSeparator();
        planListToolBar.add(importPlanButton);
        planListToolBar.add(exportPlanButton);

        JScrollPane listScrollPane = new JScrollPane(planList);

        JPanel listPanel = new JPanel(new BorderLayout());
        listPanel.add(listScrollPane, BorderLayout.CENTER);
        listPanel.add(planListToolBar, BorderLayout.SOUTH);

        planListFramePanel.setContent(listPanel, false);

    }

    return planListFramePanel;
}

From source file:src.gui.ItSIMPLE.java

/**
 * @return Returns the PetriContainer.// ww  w  .j a  va  2  s  . co m
 */
private JXTaskPaneContainer getPetriContainer() {
    if (projectPetriContainer == null) {
        projectPetriContainer = new JXTaskPaneContainer();

        //project
        projectPetriTaskPane = new JXTaskPane();
        projectPetriTaskPane.setTitle("Project");
        projectPetriTaskPane.setIcon(new ImageIcon("resources/images/projects.png"));
        projectPetriTaskPane.setSpecial(true);

        //state chart diagrams
        stateMachinePetriTaskPane = new JXTaskPane();
        stateMachinePetriTaskPane.setTitle("State Chart Diagrams");
        stateMachinePetriTaskPane.setIcon(new ImageIcon("resources/images/planningProblem.png"));
        stateMachinePetriTaskPane.setLayout(new BorderLayout());
        stateMachinePetriPanel = new JPanel(new BorderLayout());

        stateMachineJList = new JList(new DefaultListModel());
        ItListRenderer renderer = new ItListRenderer();
        renderer.setIcon(new ImageIcon("resources/images/stateMachineDiagram.png"));
        stateMachineJList.setCellRenderer(renderer);

        stateMachinePetriPanel.add(stateMachineJList, BorderLayout.CENTER);
        JToolBar toolBar = new JToolBar();
        toolBar.setRollover(true);
        stateMachineButton = new JButton(openPetriNetGroup);
        toolBar.add(stateMachineButton);

        stateMachinePetriTaskPane.add(stateMachinePetriPanel, BorderLayout.CENTER);
        stateMachinePetriTaskPane.add(toolBar, BorderLayout.SOUTH);
        /*petriCheckBoxList = new CheckBoxList();
        stateMachinePetriTaskPane.add(petriCheckBoxList, BorderLayout.CENTER);*/

        //details
        detailPetriTaskPane = new JXTaskPane();
        detailPetriTaskPane.setTitle("Details");
        detailPetriTaskPane.setIcon(new ImageIcon("resources/images/details.png"));

        detailPetriTaskPane.add(getPetriDetailsTextPane());
        petriDetailsTextPane.setBackground(petriDetailsTextPane.getParent().getBackground());

        projectPetriContainer.add(projectPetriTaskPane);
        projectPetriContainer.add(stateMachinePetriTaskPane);
        projectPetriContainer.add(detailPetriTaskPane);

    }

    return projectPetriContainer;
}

From source file:net.sourceforge.squirrel_sql.client.preferences.WikiTablePreferencesPanel.java

/**
 * The overview panel contains a list of all available configurations.
 * There are some methods provided for creating, copying or deleting configurations.
 * @return//  w  w  w. ja  va 2  s . co m
 */
private Component createOverviewPanel() {
    JPanel jp = new JPanel(new BorderLayout());
    jp.setBorder(
            BorderFactory.createTitledBorder(s_stringMgr.getString("WikiTablePreferencesPanel.titleOverview"))); //$NON-NLS-1$

    wikiConfigListModel = new DefaultListModel();

    wikiConfigList = new JList(wikiConfigListModel);
    wikiConfigList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    wikiConfigList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    IWikiTableConfiguration selectedValue = (IWikiTableConfiguration) wikiConfigList
                            .getSelectedValue();
                    showDataFor(selectedValue);
                    if (selectedValue != null) {
                        copyButton.setEnabled(true);
                    } else {
                        copyButton.setEnabled(false);
                    }
                }
            });

        }
    });

    JScrollPane sp = new JScrollPane(wikiConfigList);

    JPanel buttonPanel = new JPanel(new FlowLayout());
    newButton = new JButton(s_stringMgr.getString("WikiTablePreferencesPanel.new")); //$NON-NLS-1$
    newButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            IWikiTableConfiguration newConfig = new GenericWikiTableConfigurationBean();
            addNewConfigToList(newConfig);
        }

        private void addNewConfigToList(IWikiTableConfiguration newConfig) {
            wikiConfigListModel.addElement(newConfig);
            wikiConfigList.setSelectedValue(newConfig, true);
        }
    });
    buttonPanel.add(newButton);

    copyButton = new JButton(s_stringMgr.getString("WikiTablePreferencesPanel.copy")); //$NON-NLS-1$
    copyButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            IWikiTableConfiguration newConfig = ((IWikiTableConfiguration) wikiConfigList.getSelectedValue())
                    .copyAsUserSpecific();

            int suffix = 0;

            String originalName = newConfig.getName();

            do {
                suffix++;
                newConfig.setName(originalName + "_" + suffix); //$NON-NLS-1$
            } while (!isUniqueName(newConfig));

            addNewConfigToList(newConfig);
        }

    });

    buttonPanel.add(copyButton);

    deleteButton = new JButton(s_stringMgr.getString("WikiTablePreferencesPanel.delete")); //$NON-NLS-1$
    deleteButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int selectedIndex = wikiConfigList.getSelectedIndex();
            wikiConfigList.setSelectedIndex(0);
            wikiConfigListModel.remove(selectedIndex);
            // we always have at least on item - the build in configuration
            //            wikiConfigList.invalidate();
        }
    });
    buttonPanel.add(deleteButton);

    jp.add(sp, BorderLayout.CENTER);
    jp.add(buttonPanel, BorderLayout.SOUTH);

    return jp;
}

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

private void setupForm(final String settingsPath) {
    this.setTitle("System Properties");
    try {//  w w w. ja va 2s . c o m
        theFormControl = new FormControl(this, settingsPath);
    } catch (Exception ex) {
        LOG.error("Error loading form parameters", ex);
    }
    // Set fonts
    isSystemChange = true;
    final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final Font[] fonts = env.getAllFonts();
    DefaultListModel model = new DefaultListModel();
    for (int i = 0; i < fonts.length; i++) {
        final Font font = fonts[i];
        model.add(i, font.getName());
    }
    lstFont.setModel(model);

    // Set styles
    model = new DefaultListModel();
    model.addElement("Plain");
    model.addElement("Bold");
    model.addElement("Italic");
    model.addElement("Bold Italic");
    lstStyle.setModel(model);

    // Set sizes
    model = new DefaultListModel();
    model.addElement("8");
    model.addElement("10");
    model.addElement("12");
    model.addElement("14");
    model.addElement("18");
    model.addElement("20");
    model.addElement("22");
    model.addElement("24");
    lstSize.setModel(model);
    txtFontSize.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(final DocumentEvent e) {
            updateFontSize();
        }

        public void removeUpdate(final DocumentEvent e) {
            updateFontSize();
        }

        public void insertUpdate(final DocumentEvent e) {
            updateFontSize();
        }
    });

    model = new DefaultListModel();
    for (String favourite : personalSettings.getFavourites()) {
        model.addElement(favourite);
    }
    lstFavourites.setModel(model);

    model = new DefaultListModel();
    for (PersonalSettings.FileDescriptions descriptions : personalSettings.getFilesToIgnore()) {
        model.addElement(descriptions);
    }
    lstFilesToIgnore.setModel(model);

    final DefaultComboBoxModel cmbModel = new DefaultComboBoxModel();
    for (PersonalSettings.TextPosition position : PersonalSettings.TextPosition.values()) {
        cmbModel.addElement(position);
    }
    cmbTextPosition.setModel(cmbModel);

    chkSortRunning.setSelected(personalSettings.isSortRunningAscending());
    chkSortPending.setSelected(personalSettings.isSortPendingAscending());
    chkSortFailed.setSelected(personalSettings.isSortFailedAscending());
    chkSortDeposited.setSelected(personalSettings.isSortDepositedAscending());
    chkSortComplete.setSelected(personalSettings.isSortCompleteAscending());
    txtNoOfRetries.setText(String.format("%d", personalSettings.getNoOfRetries()));

    isSystemChange = false;
}

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

private void showMissingFiles() {
    final DefaultListModel model = new DefaultListModel();
    lstDuplicateFiles.setModel(model);/*from ww  w  .ja v  a2  s  .  co m*/
    for (String fileName : theDuplicateFiles) {
        model.addElement(fileName);
    }
}

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

private void showMissingFiles() {
    final DefaultListModel model = new DefaultListModel();
    lstMissingFiles.setModel(model);//w w w .  j a  v  a  2  s. c om
    for (FileSystemObject fso : theMissingFiles) {
        model.addElement(fso.getFullPath());
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

private void loadProducersList() {
    try {//from   w w w .  ja v  a2s .  c o  m
        LOG.debug("loadProducersList, start");
        DefaultListModel model;
        if (theProducerList.getModel() instanceof DefaultListModel) {
            model = (DefaultListModel) theProducerList.getModel();
            model.clear();
        } else {
            model = new DefaultListModel();
        }
        LOG.debug("loadProducersList, Before create deposit");
        IDeposit deposit = applicationProperties.getApplicationData().getDeposit();
        producers = deposit.getProducers(applicationProperties.getLoggedOnUser());
        LOG.debug("loadProducersList, After get list");
        for (Producer data : producers) {
            model.addElement(data);
        }
        theProducerList.setModel(model);
        theProducerList.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstProducersValueChanged(evt);
            }
        });
        theProducerList.repaint();
        LOG.debug("loadProducersList, end");
    } catch (Exception ex) {
        manualDepositFrame.showError("Error loading producers", "Unable to load producer list", ex);
        reportException(ex);
    }
}