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:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java

@Override
public void refreshView(final ViewState state) {
    this.removeAll();

    tableMenu = new JPopupMenu("TableMenu");
    this.add(tableMenu);
    override = new JMenuItem(OVERRIDE);
    override.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition());
            String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state);
            Metadata staticMet = state.getSelected().getModel().getStaticMetadata();
            if (staticMet == null) {
                staticMet = new Metadata();
            }/* w  ww .  j a va 2 s.co m*/
            if (e.getActionCommand().equals(OVERRIDE)) {
                if (!staticMet.containsKey(key)) {
                    staticMet.addMetadata(key, (String) DefaultPropView.this.table.getValueAt(row, 2));
                    String envReplace = (String) DefaultPropView.this.table.getValueAt(row, 3);
                    if (Boolean.valueOf(envReplace)) {
                        staticMet.addMetadata(key + "/envReplace", envReplace);
                    }
                    state.getSelected().getModel().setStaticMetadata(staticMet);
                    DefaultPropView.this.notifyListeners();
                }
            }
        }
    });
    delete = new JMenuItem(DELETE);
    delete.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition());
            String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state);
            Metadata staticMet = state.getSelected().getModel().getStaticMetadata();
            if (staticMet == null) {
                staticMet = new Metadata();
            }
            staticMet.removeMetadata(key);
            staticMet.removeMetadata(key + "/envReplace");
            state.getSelected().getModel().setStaticMetadata(staticMet);
            DefaultPropView.this.notifyListeners();
        }

    });
    tableMenu.add(override);
    tableMenu.add(delete);

    if (state.getSelected() != null) {
        JPanel masterPanel = new JPanel();
        masterPanel.setLayout(new BoxLayout(masterPanel, BoxLayout.Y_AXIS));
        masterPanel.add(this.getModelIdPanel(state.getSelected(), state));
        masterPanel.add(this.getModelNamePanel(state.getSelected(), state));
        if (!state.getSelected().getModel().isParentType()) {
            masterPanel.add(this.getInstanceClassPanel(state.getSelected(), state));
        }
        masterPanel.add(this.getExecutionTypePanel(state.getSelected(), state));
        masterPanel.add(this.getPriorityPanel(state));
        masterPanel.add(this.getExecusedIds(state.getSelected()));
        if (state.getSelected().getModel().getExecutionType().equals("condition")) {
            masterPanel.add(this.getTimeout(state.getSelected(), state));
            masterPanel.add(this.getOptional(state.getSelected(), state));
        }
        JScrollPane scrollPane = new JScrollPane(table = this.createTable(state),
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.getHorizontalScrollBar().setUnitIncrement(10);
        scrollPane.getVerticalScrollBar().setUnitIncrement(10);
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.setBorder(new EtchedBorder());
        final JLabel metLabel = new JLabel("Static Metadata");
        metLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        final JLabel extendsLabel = new JLabel("<extends>");
        extendsLabel.setFont(new Font("Serif", Font.PLAIN, 10));
        extendsLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        extendsLabel.addMouseListener(new MouseListener() {

            private JScrollPane availableScroller;
            private JScrollPane mineScroller;
            private JList mineList;
            private JList availableList;
            private DefaultListModel mineModel;
            private DefaultListModel availableModel;

            public void mouseClicked(MouseEvent e) {
                final JPopupMenu popup = new JPopupMenu();
                popup.setLayout(new BorderLayout());

                JPanel main = new JPanel();
                main.setLayout(new BoxLayout(main, BoxLayout.X_AXIS));

                JPanel mine = new JPanel();
                mine.setBorder(new EtchedBorder());
                mine.setLayout(new BorderLayout());
                JLabel mineLabel = new JLabel("Mine");
                mineScroller = new JScrollPane(mineList = createJList(mineModel = new DefaultListModel(),
                        state.getSelected().getModel().getExtendsConfig()));
                mineScroller.setPreferredSize(new Dimension(250, 80));
                mine.add(mineLabel, BorderLayout.NORTH);
                mine.add(mineScroller, BorderLayout.CENTER);

                JPanel available = new JPanel();
                available.setBorder(new EtchedBorder());
                available.setLayout(new BorderLayout());
                JLabel availableLabel = new JLabel("Available");
                Vector<String> availableGroups = new Vector<String>(state.getGlobalConfigGroups().keySet());
                availableGroups.removeAll(state.getSelected().getModel().getExtendsConfig());
                availableScroller = new JScrollPane(availableList = this
                        .createJList(availableModel = new DefaultListModel(), availableGroups));
                availableScroller.setPreferredSize(new Dimension(250, 80));
                available.add(availableLabel, BorderLayout.NORTH);
                available.add(availableScroller, BorderLayout.CENTER);

                JPanel buttons = new JPanel();
                buttons.setLayout(new BoxLayout(buttons, BoxLayout.Y_AXIS));
                JButton addButton = new JButton("<---");
                addButton.addMouseListener(new MouseListener() {

                    public void mouseClicked(MouseEvent e) {
                        String selected = availableList.getSelectedValue().toString();
                        Vector<String> extendsConfig = new Vector<String>(
                                state.getSelected().getModel().getExtendsConfig());
                        extendsConfig.add(selected);
                        state.getSelected().getModel().setExtendsConfig(extendsConfig);
                        availableModel.remove(availableList.getSelectedIndex());
                        mineModel.addElement(selected);
                        popup.revalidate();
                        DefaultPropView.this.notifyListeners();
                    }

                    public void mouseEntered(MouseEvent e) {
                    }

                    public void mouseExited(MouseEvent e) {
                    }

                    public void mousePressed(MouseEvent e) {
                    }

                    public void mouseReleased(MouseEvent e) {
                    }

                });
                JButton removeButton = new JButton("--->");
                removeButton.addMouseListener(new MouseListener() {

                    public void mouseClicked(MouseEvent e) {
                        String selected = mineList.getSelectedValue().toString();
                        Vector<String> extendsConfig = new Vector<String>(
                                state.getSelected().getModel().getExtendsConfig());
                        extendsConfig.remove(selected);
                        state.getSelected().getModel().setExtendsConfig(extendsConfig);
                        mineModel.remove(mineList.getSelectedIndex());
                        availableModel.addElement(selected);
                        popup.revalidate();
                        DefaultPropView.this.notifyListeners();
                    }

                    public void mouseEntered(MouseEvent e) {
                    }

                    public void mouseExited(MouseEvent e) {
                    }

                    public void mousePressed(MouseEvent e) {
                    }

                    public void mouseReleased(MouseEvent e) {
                    }

                });
                buttons.add(addButton);
                buttons.add(removeButton);

                main.add(mine);
                main.add(buttons);
                main.add(available);
                popup.add(main, BorderLayout.CENTER);
                popup.show(extendsLabel, e.getX(), e.getY());
            }

            public void mouseEntered(MouseEvent e) {
                extendsLabel.setForeground(Color.blue);
            }

            public void mouseExited(MouseEvent e) {
                extendsLabel.setForeground(Color.black);
            }

            public void mousePressed(MouseEvent e) {
            }

            public void mouseReleased(MouseEvent e) {
            }

            private JList createJList(DefaultListModel model, final List<String> list) {
                for (String value : list) {
                    model.addElement(value);
                }
                JList jList = new JList(model);
                jList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
                jList.setLayoutOrientation(JList.VERTICAL);
                return jList;
            }
        });
        JLabel metGroupLabel = new JLabel("(Sub-Group: "
                + (state.getCurrentMetGroup() != null ? state.getCurrentMetGroup() : "<base>") + ")");
        metGroupLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        JPanel labelPanel = new JPanel();
        labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));
        JPanel top = new JPanel();
        top.setLayout(new BoxLayout(top, BoxLayout.Y_AXIS));
        top.add(extendsLabel);
        top.add(metLabel);
        labelPanel.add(top);
        labelPanel.add(metGroupLabel);
        panel.add(labelPanel, BorderLayout.NORTH);
        panel.add(scrollPane, BorderLayout.CENTER);
        masterPanel.add(panel);
        this.add(masterPanel);
    } else {
        this.add(new JPanel());
    }
    this.revalidate();
}

From source file:org.cloudml.ui.graph.Visu.java

public DefaultListModel fillList() {
    DefaultListModel lm = new DefaultListModel();
    for (ExternalComponent n : dmodel.getComponents().onlyExternals()) {
        lm.addElement(n.getName());/*from w w w  .ja  va2s .co m*/
    }
    for (Component n : dmodel.getComponents()) {
        lm.addElement(n.getName());
    }
    for (Relationship b : dmodel.getRelationships()) {
        lm.addElement(b.getName());
    }
    return lm;
}

From source file:org.executequery.gui.drivers.AbstractDriverPanel.java

private void init() {

    ReflectiveAction action = new ReflectiveAction(this);

    JButton browseButton = new DefaultButton(action, getString("AbstractDriverPanel.addLibraryButton"),
            "browseDrivers");
    JButton removeButton = new DefaultButton(action, getString("AbstractDriverPanel.addRemoveButton"),
            "removeDrivers");

    JButton findButton = new DefaultInlineFieldButton(action);
    findButton.setText(getString("AbstractDriverPanel.addFindButton"));
    findButton.setActionCommand("findDriverClass");

    jarPathListModel = new DefaultListModel();

    nameField = textFieldWithKey("AbstractDriverPanel.driverNameToolTip");
    descField = textFieldWithKey("AbstractDriverPanel.descriptionToolTip");
    //        classField = textFieldWithKey("AbstractDriverPanel.classNameToolTip");

    classComboModel = new DynamicComboBoxModel();
    classField = WidgetFactory.createComboBox(classComboModel);
    classField.setToolTipText(getString("AbstractDriverPanel.classNameToolTip"));
    classField.setEditable(true);/* w  ww .  j  a v a 2 s  .c om*/

    jarPathList = new JList(jarPathListModel);
    jarPathList.setToolTipText(getString("AbstractDriverPanel.pathToolTip"));
    JScrollPane jarPathListScrollPane = new JScrollPane(jarPathList) {
        private int height = 120;

        @Override
        public Dimension getPreferredSize() {

            Dimension size = super.getPreferredSize();
            size.height = height;
            return size;
        }

        @Override
        public Dimension getMinimumSize() {

            Dimension size = super.getMinimumSize();
            size.height = height;
            return size;
        }
    };

    nameField.addFocusListener(new DriverNameFieldListener(this));

    databaseNameCombo = WidgetFactory.createComboBox(createDatabaseComboValues());
    databaseNameCombo.setToolTipText(getString("AbstractDriverPanel.databaseToolTip"));
    databaseNameCombo.addItemListener(this);

    urlComboModel = new DynamicComboBoxModel();
    driverUrlCombo = WidgetFactory.createComboBox(urlComboModel);
    driverUrlCombo.setToolTipText(getString("AbstractDriverPanel.jdbcUrlToolTip"));
    driverUrlCombo.setEditable(true);

    JPanel base = new TextFieldPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridy++;
    gbc.insets = new Insets(10, 10, 5, 0);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    base.add(labelWithKey("AbstractDriverPanel.driverNameLabel"), gbc);
    gbc.gridy++;
    gbc.insets.top = 0;
    base.add(labelWithKey("AbstractDriverPanel.descriptionLabel"), gbc);
    gbc.gridy++;
    base.add(labelWithKey("AbstractDriverPanel.databaseLabel"), gbc);
    gbc.gridy++;
    base.add(labelWithKey("AbstractDriverPanel.jdbcUrlLabel"), gbc);
    gbc.gridy++;
    base.add(labelWithKey("AbstractDriverPanel.pathLabel"), gbc);
    gbc.gridy += 4;
    base.add(labelWithKey("AbstractDriverPanel.classNameLabel"), gbc);
    gbc.gridy = 0;
    gbc.gridx = 1;
    gbc.insets.right = 10;
    gbc.insets.top = 10;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    base.add(nameField, gbc);
    gbc.gridy++;
    gbc.insets.top = 0;
    base.add(descField, gbc);
    gbc.gridy++;
    base.add(databaseNameCombo, gbc);
    gbc.gridy++;
    base.add(driverUrlCombo, gbc);
    gbc.gridy++;
    gbc.gridwidth = 1;
    gbc.insets.right = 0;
    gbc.gridheight = 2;
    gbc.insets.top = 5;
    base.add(jarPathListScrollPane, gbc);
    gbc.gridx = 2;
    gbc.weightx = 0;
    gbc.insets.right = 10;
    gbc.gridheight = 1;
    gbc.insets.left = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    base.add(browseButton, gbc);
    gbc.gridy++;
    gbc.insets.top = 0;
    base.add(removeButton, gbc);

    gbc.gridy += 3;
    gbc.gridx = 1;
    gbc.weightx = 1.0;
    gbc.insets.right = 0;
    gbc.insets.left = 10;
    gbc.insets.top = 0;
    base.add(classField, gbc);
    gbc.gridx = 2;
    gbc.weightx = 0;
    gbc.weighty = 1.0;
    gbc.insets.right = 10;
    gbc.insets.left = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    base.add(findButton, gbc);

    add(base, BorderLayout.CENTER);
}

From source file:org.interreg.docexplore.ServerConfigPanel.java

public ServerConfigPanel(final File config, final File serverDir) throws Exception {
    super(new LooseGridLayout(0, 1, 5, 5, true, false, SwingConstants.LEFT, SwingConstants.TOP, true, false));

    this.serverDir = serverDir;
    this.books = new Vector<Book>();
    this.bookList = new JList(new DefaultListModel());

    JPanel listPanel = new JPanel(new BorderLayout());
    listPanel.setBorder(BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgBooksLabel")));
    bookList.setOpaque(false);//from   w  ww  . j  a  va  2s  .com
    bookList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    bookList.setCellRenderer(new ListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            Book book = (Book) value;
            JLabel label = new JLabel("<html><b>" + book.name + "</b> - " + book.nPages + " pages</html>");
            label.setOpaque(true);
            if (isSelected) {
                label.setBackground(TextToolbar.styleHighLightedBackground);
                label.setForeground(Color.white);
            }
            if (book.deleted)
                label.setForeground(Color.red);
            else if (!book.used)
                label.setForeground(Color.gray);
            return label;
        }
    });
    bookList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            setFields((Book) bookList.getSelectedValue());
        }
    });
    JScrollPane scrollPane = new JScrollPane(bookList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setPreferredSize(new Dimension(500, 300));
    scrollPane.getVerticalScrollBar().setUnitIncrement(10);
    listPanel.add(scrollPane, BorderLayout.CENTER);

    JPanel importPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    importPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgImportLabel")) {
        public void actionPerformed(ActionEvent e) {
            final File inFile = DocExploreTool.getFileDialogs().openFile(DocExploreTool.getIBookCategory());
            if (inFile == null)
                return;

            try {
                final File tmpDir = new File(serverDir, "tmp");
                tmpDir.mkdir();

                GuiUtils.blockUntilComplete(new ProgressRunnable() {
                    float[] progress = { 0 };

                    public void run() {
                        try {
                            ZipUtils.unzip(inFile, tmpDir, progress);
                        } catch (Exception ex) {
                            ErrorHandler.defaultHandler.submit(ex);
                        }
                    }

                    public float getProgress() {
                        return (float) progress[0];
                    }
                }, ServerConfigPanel.this);

                File tmpFile = new File(tmpDir, "index.tmp");
                ObjectInputStream input = new ObjectInputStream(new FileInputStream(tmpFile));
                String bookFile = input.readUTF();
                String bookName = input.readUTF();
                String bookDesc = input.readUTF();
                input.close();

                new PresentationImporter().doImport(ServerConfigPanel.this, bookName, bookDesc,
                        new File(tmpDir, bookFile));
                FileUtils.cleanDirectory(tmpDir);
                FileUtils.deleteDirectory(tmpDir);
                updateBooks();
            } catch (Exception ex) {
                ErrorHandler.defaultHandler.submit(ex);
            }
        }
    }));
    listPanel.add(importPanel, BorderLayout.SOUTH);
    add(listPanel);

    JPanel setupPanel = new JPanel(
            new LooseGridLayout(0, 1, 5, 5, true, false, SwingConstants.LEFT, SwingConstants.TOP, true, false));
    setupPanel.setBorder(
            BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgBookInfoLabel")));
    usedBox = new JCheckBox(XMLResourceBundle.getBundledString("cfgUseLabel"));
    usedBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Book book = (Book) bookList.getSelectedValue();
            if (book != null) {
                book.used = usedBox.isSelected();
                bookList.repaint();
            }
        }
    });
    setupPanel.add(usedBox);

    JPanel fieldPanel = new JPanel(new LooseGridLayout(0, 2, 5, 5, false, false, SwingConstants.LEFT,
            SwingConstants.TOP, true, false));
    fieldPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgTitleLabel")));
    nameField = new JTextField(50);
    nameField.getDocument().addDocumentListener(new DocumentListener() {
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        public void changedUpdate(DocumentEvent e) {
            Book book = (Book) bookList.getSelectedValue();
            if (book == null)
                return;
            book.name = nameField.getText();
            bookList.repaint();
        }
    });
    fieldPanel.add(nameField);

    fieldPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgDescriptionLabel")));
    descField = new JTextPane();
    //descField.setWrapStyleWord(true);
    descField.getDocument().addDocumentListener(new DocumentListener() {
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        public void changedUpdate(DocumentEvent e) {
            Book book = (Book) bookList.getSelectedValue();
            if (book == null)
                return;
            book.desc = descField.getText();
        }
    });
    scrollPane = new JScrollPane(descField, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setPreferredSize(new Dimension(420, 50));
    scrollPane.getVerticalScrollBar().setUnitIncrement(10);
    fieldPanel.add(scrollPane);

    setupPanel.add(fieldPanel);

    exportButton = new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgExportLabel")) {
        public void actionPerformed(ActionEvent e) {
            File file = DocExploreTool.getFileDialogs().saveFile(DocExploreTool.getIBookCategory());
            if (file == null)
                return;
            final Book book = (Book) bookList.getSelectedValue();
            final File indexFile = new File(serverDir, "index.tmp");
            try {
                final File outFile = file;
                ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(indexFile));
                out.writeUTF(book.bookFile.getName());
                out.writeUTF(book.name);
                out.writeUTF(book.desc);
                out.close();

                GuiUtils.blockUntilComplete(new ProgressRunnable() {
                    float[] progress = { 0 };

                    public void run() {
                        try {
                            ZipUtils.zip(serverDir, new File[] { indexFile, book.bookFile, book.bookDir },
                                    outFile, progress, 0, 1, 9);
                        } catch (Exception ex) {
                            ErrorHandler.defaultHandler.submit(ex);
                        }
                    }

                    public float getProgress() {
                        return (float) progress[0];
                    }
                }, ServerConfigPanel.this);
            } catch (Exception ex) {
                ErrorHandler.defaultHandler.submit(ex);
            }
            if (indexFile.exists())
                indexFile.delete();
        }
    });
    deleteButton = new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgDeleteRestoreLabel")) {
        public void actionPerformed(ActionEvent e) {
            Book book = (Book) bookList.getSelectedValue();
            if (book == null)
                return;
            book.deleted = !book.deleted;
            bookList.repaint();
        }
    });

    JPanel actionsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    actionsPanel.add(exportButton);
    actionsPanel.add(deleteButton);
    setupPanel.add(actionsPanel);

    add(setupPanel);

    JPanel optionsPanel = new JPanel(new LooseGridLayout(0, 2, 5, 5, false, false, SwingConstants.LEFT,
            SwingConstants.TOP, true, false));
    optionsPanel
            .setBorder(BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgOptionsLabel")));
    JPanel timeoutPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    timeoutField = new JTextField(5);
    timeoutPanel.add(timeoutField);
    timeoutPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgTimeoutLabel")));
    optionsPanel.add(timeoutPanel);
    add(optionsPanel);

    updateBooks();
    setFields(null);

    final String xml = config.exists() ? StringUtils.readFile(config) : "<config></config>";
    String idle = StringUtils.getTagContent(xml, "idle");
    if (idle != null)
        try {
            timeoutField.setText("" + Integer.parseInt(idle));
        } catch (Throwable e) {
        }
}

From source file:org.isatools.isacreatorconfigurator.configui.DataEntryPanel.java

private JPanel createTableListPanel() {

    JPanel container = new JPanel();
    container.setBackground(UIHelper.BG_COLOR);
    container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));

    JLabel lab = new JLabel(tableListTitle);

    container.add(UIHelper.wrapComponentInPanel(lab));
    container.add(Box.createVerticalStrut(5));

    tableModel = new DefaultListModel();
    tableList = new JList(tableModel);
    tableList.setCellRenderer(new TableListRenderer());
    tableList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    tableList.setBackground(UIHelper.BG_COLOR);
    tableList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            try {
                saveCurrentField(false, false);
            } catch (DataNotCompleteException dce) {
                showMessagePane(dce.getMessage(), JOptionPane.ERROR_MESSAGE);
            }//from  w  w  w.  j  a v  a2s.co  m

            MappingObject currentlyEditedTable = getCurrentlySelectedTable();
            ApplicationManager.setCurrentMappingObject(currentlyEditedTable);

            // update the view error button visibility depending on selected tables error state.
            viewErrorsButton.setVisible(areThereErrorsInThisCurrentObject());

            updateTableInfoDisplay(currentlyEditedTable);
            reformFieldList(currentlyEditedTable);
        }
    });

    JScrollPane listScroller = new JScrollPane(tableList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    listScroller.getViewport().setBackground(UIHelper.BG_COLOR);
    listScroller.setBorder(null);
    listScroller.setPreferredSize(new Dimension(((int) (WIDTH * 0.25)), ((int) (HEIGHT * 0.75))));

    IAppWidgetFactory.makeIAppScrollPane(listScroller);

    container.add(listScroller);
    container.add(Box.createVerticalStrut(5));

    tableCountInfo = UIHelper.createLabel("", UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR);
    container.add(UIHelper.wrapComponentInPanel(tableCountInfo));
    container.add(Box.createVerticalStrut(5));

    // create button panel to add and remove tables
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
    buttonPanel.setBackground(UIHelper.BG_COLOR);

    final JLabel addTableButton = new JLabel(addTable, JLabel.LEFT);
    UIHelper.renderComponent(addTableButton, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    addTableButton.setOpaque(false);

    addTableButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            addTableButton.setIcon(addTableOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            addTableButton.setIcon(addTable);
        }

        public void mousePressed(MouseEvent event) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    addTableButton.setIcon(addTable);
                    applicationContainer.showJDialogAsSheet(addTableUI);
                }
            });

        }

    });

    addTableButton.setToolTipText("<html><b>Add table</b><p>Add a new table definition.</p></html>");

    final JLabel removeTableButton = new JLabel(removeTable, JLabel.LEFT);
    UIHelper.renderComponent(removeTableButton, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    removeTableButton.setOpaque(false);

    removeTableButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            removeTableButton.setIcon(removeTableOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            removeTableButton.setIcon(removeTable);
        }

        public void mousePressed(MouseEvent event) {
            removeTableButton.setIcon(removeTable);
            if (tableList.getSelectedValue() != null) {
                String selectedTable = tableList.getSelectedValue().toString();
                MappingObject toRemove = null;
                for (MappingObject mo : tableFields.keySet()) {
                    if (mo.getAssayName().equals(selectedTable)) {
                        toRemove = mo;
                        break;
                    }
                }

                if (toRemove != null) {
                    tableFields.remove(toRemove);
                    reformTableList();
                }
            }
        }

    });

    removeTableButton.setToolTipText("<html><b>Remove table</b><p>Remove table from definitions?</p></html>");

    viewErrorsButton = new JLabel(viewErrorsIcon);
    viewErrorsButton.setVisible(false);
    viewErrorsButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            viewErrorsButton.setIcon(viewErrorsIcon);
            // show error pane for current table only.

            Validator validator = new Validator();
            validateFormOrTable(validator, ApplicationManager.getCurrentMappingObject());

            ValidationReport report = validator.getReport();

            ConfigurationValidationUI validationUI = new ConfigurationValidationUI(tableFields.keySet(),
                    report);
            validationUI.createGUI();
            validationUI.setLocationRelativeTo(getApplicationContainer());
            validationUI.setAlwaysOnTop(true);
            validationUI.setVisible(true);
        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            viewErrorsButton.setIcon(viewErrorsIconOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            viewErrorsButton.setIcon(viewErrorsIcon);
        }
    });

    buttonPanel.add(addTableButton);
    buttonPanel.add(removeTableButton);
    buttonPanel.add(viewErrorsButton);
    buttonPanel.add(Box.createHorizontalGlue());

    container.add(buttonPanel);

    container.add(Box.createVerticalGlue());

    return container;
}

From source file:org.isatools.isacreatorconfigurator.configui.DataEntryPanel.java

private JPanel createFieldListPanel() {

    JPanel container = new JPanel();
    container.setBackground(UIHelper.BG_COLOR);
    container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));

    JPanel headerLab = new JPanel(new GridLayout(1, 1));
    headerLab.setOpaque(false);//  w  ww  .j a  v  a 2s. co  m

    JLabel lab = new JLabel(fieldListTitle);
    headerLab.add(lab);

    container.add(headerLab);
    container.add(Box.createVerticalStrut(5));

    elementModel = new DefaultListModel();
    elementList = new ReOrderableJList(elementModel);
    elementList.setCellRenderer(new CustomReOrderableListCellRenderer(elementList));
    elementList.setDragEnabled(true);
    elementList.setBackground(UIHelper.BG_COLOR);

    elementList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            Display selectedNode = (Display) elementList.getSelectedValue();
            if (selectedNode != null) {
                try {
                    saveCurrentField(false, false);
                } catch (DataNotCompleteException dce) {
                    showMessagePane(dce.getMessage(), JOptionPane.ERROR_MESSAGE);
                }
                if (selectedNode instanceof FieldElement) {
                    fieldInterface.setCurrentField((FieldElement) selectedNode);
                    if (currentPage != fieldInterface) {
                        setCurrentPage(fieldInterface);
                    }
                    removeElementButton.setEnabled(!standardISAFields.isFieldRequired(selectedNode.toString()));
                } else {
                    setCurrentPage(structureElement);
                }
            }
        }
    });

    elementList.addPropertyChangeListener("orderChanged", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            updateFieldOrder();

            if (tableList.getSelectedValue() instanceof MappingObject) {
                validateFormOrTable(ApplicationManager.getCurrentMappingObject());
            }
        }
    });

    JScrollPane listScroller = new JScrollPane(elementList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    listScroller.getViewport().setBackground(UIHelper.BG_COLOR);
    listScroller.setBorder(new EmptyBorder(2, 2, 2, 10));
    listScroller.setPreferredSize(new Dimension(((int) (WIDTH * 0.25)), ((int) (HEIGHT * 0.75))));
    IAppWidgetFactory.makeIAppScrollPane(listScroller);

    container.add(listScroller);
    container.add(Box.createVerticalStrut(5));

    elementCountInfo = UIHelper.createLabel("", UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR);

    container.add(UIHelper.wrapComponentInPanel(elementCountInfo));
    container.add(Box.createVerticalStrut(5));

    // create button panel to add and remove tables
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
    buttonPanel.setBackground(UIHelper.BG_COLOR);

    final JLabel addFieldButton = new JLabel(addElement, JLabel.LEFT);
    addFieldButton.setOpaque(false);

    addFieldButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            addFieldButton.setIcon(addElementOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            addFieldButton.setIcon(addElement);
        }

        public void mousePressed(MouseEvent event) {
            addFieldButton.setIcon(addElement);
            showAddFieldUI();
        }

    });

    addFieldButton.setToolTipText(
            "<html><b>Add Field to table</b><p>Add a new field to currently selected table</b></p></html>");

    removeElementButton = new JLabel(removeElement, JLabel.LEFT);
    removeElementButton.setOpaque(false);

    removeElementButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            removeElementButton.setIcon(removeElementOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            removeElementButton.setIcon(removeElement);
        }

        public void mousePressed(MouseEvent event) {
            removeElementButton.setIcon(removeElement);
            if (removeElementButton.isEnabled()) {
                removeSelectedElement();
            }
        }

    });

    removeElementButton.setToolTipText(
            "<html><b>Remove Field from table</b><p>Remove this field from this list and the currently selected table.</b></p></html>");

    final JLabel moveDownButton = new JLabel(moveDown);
    moveDownButton.setOpaque(false);
    moveDownButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            moveDownButton.setIcon(moveDownOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            moveDownButton.setIcon(moveDown);
        }

        public void mousePressed(MouseEvent event) {
            moveDownButton.setIcon(moveDown);
            if (elementList.getSelectedIndex() != -1) {
                int toMoveDown = elementList.getSelectedIndex();

                if (toMoveDown != (elementModel.getSize() - 1)) {
                    swapElements(elementList, elementModel, toMoveDown, toMoveDown + 1);
                }

                updateFieldOrder();
                validateFormOrTable(ApplicationManager.getCurrentMappingObject());
            }
        }
    });

    moveDownButton.setToolTipText(
            "<html><b>Move Field Down</b><p>Move the selected field down <b>one</b> position in the list.</p></html>");

    final JLabel moveUpButton = new JLabel(moveUp);
    moveUpButton.setOpaque(false);
    moveUpButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            moveUpButton.setIcon(moveUpOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            moveUpButton.setIcon(moveUp);
        }

        public void mousePressed(MouseEvent event) {
            moveUpButton.setIcon(moveUp);
            if (elementList.getSelectedIndex() != -1) {
                int toMoveUp = elementList.getSelectedIndex();

                if (toMoveUp != 0) {
                    swapElements(elementList, elementModel, toMoveUp, toMoveUp - 1);
                }

                updateFieldOrder();
                validateFormOrTable(ApplicationManager.getCurrentMappingObject());

            }
        }

    });

    moveUpButton.setToolTipText(
            "<html><b>Move Field Up</b><p>Move the selected field up <b>one</b> position in the list.</p></html>");

    buttonPanel.add(addFieldButton);
    buttonPanel.add(removeElementButton);
    buttonPanel.add(moveDownButton);
    buttonPanel.add(moveUpButton);

    container.add(buttonPanel);

    container.add(Box.createVerticalGlue());

    return container;
}

From source file:org.isatools.isacreatorconfigurator.ontologyconfigurationtool.OntologyConfigUI.java

private void createOntologySelectionPanel() {

    OntologyListRenderer listRenderer = new OntologyListRenderer();

    JPanel westPanel = new JPanel(new BorderLayout());

    JPanel selectedOntologiesContainer = new JPanel(new BorderLayout());
    selectedOntologiesContainer.setOpaque(false);

    // create List containing selected ontologies
    selectedOntologyListModel = new DefaultListModel();
    selectedOntologyList = new JList(selectedOntologyListModel);
    selectedOntologyList.setCellRenderer(new SelectedOntologyListRenderer());
    selectedOntologyList.setBackground(UIHelper.BG_COLOR);

    selectedOntologyList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            setOntologySelectionPanelPlaceholder(infoImage);

            setSelectedOntologyButtonVisibility(selectedOntologyList.isSelectionEmpty());
        }//from w  w  w  . j av a 2  s.  c om
    });

    JScrollPane selectedOntologiesScroller = new JScrollPane(selectedOntologyList,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    selectedOntologiesScroller.setPreferredSize(new Dimension(200, 255));
    selectedOntologiesScroller.setBackground(UIHelper.BG_COLOR);
    selectedOntologiesScroller.getViewport().setBackground(UIHelper.BG_COLOR);

    IAppWidgetFactory.makeIAppScrollPane(selectedOntologiesScroller);

    selectedOntologiesContainer.setBorder(new TitledBorder(new RoundedBorder(UIHelper.LIGHT_GREEN_COLOR, 7),
            "selected ontologies", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
            UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR));

    selectedOntologiesContainer.add(selectedOntologiesScroller, BorderLayout.CENTER);

    // ADD BUTTONS
    removeOntologyButton = new JLabel(removeOntologyButtonIcon);
    removeOntologyButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent mouseEvent) {

            if (!selectedOntologyList.isSelectionEmpty()) {
                String ontologyToRemove = selectedOntologyList.getSelectedValue().toString();
                System.out.println("Removing  " + ontologyToRemove);
                selectedOntologies.remove(ontologyToRemove);
                setOntologySelectionPanelPlaceholder(infoImage);

                updateSelectedOntologies();
            }

            removeOntologyButton.setIcon(removeOntologyButtonIcon);
        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            removeOntologyButton.setIcon(removeOntologyButtonIconOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            removeOntologyButton.setIcon(removeOntologyButtonIcon);
        }
    });

    removeOntologyButton.setVisible(false);

    viewOntologyButton = new JLabel(browseOntologyButtonIcon);
    viewOntologyButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            performTransition();
            viewOntologyButton.setIcon(browseOntologyButtonIcon);
        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            viewOntologyButton.setIcon(browseOntologyButtonIconOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            viewOntologyButton.setIcon(browseOntologyButtonIcon);
        }
    });

    viewOntologyButton.setVisible(false);

    removeRestrictionButton = new JLabel(removeRestrictionButtonIcon);
    removeRestrictionButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            if (!selectedOntologyList.isSelectionEmpty()) {
                ((RecommendedOntology) selectedOntologyList.getSelectedValue()).setBranchToSearchUnder(null);
                removeRestrictionButton.setVisible(false);
                selectedOntologyList.repaint();
            }

            removeRestrictionButton.setIcon(removeRestrictionButtonIcon);
        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            removeRestrictionButton.setIcon(removeRestrictionButtonIconOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            removeRestrictionButton.setIcon(removeRestrictionButtonIcon);
        }
    });

    removeRestrictionButton.setVisible(false);

    Box selectedOntologiesOptionContainer = Box.createHorizontalBox();
    selectedOntologiesOptionContainer.setOpaque(false);

    selectedOntologiesOptionContainer.add(removeOntologyButton);
    selectedOntologiesOptionContainer.add(viewOntologyButton);
    selectedOntologiesOptionContainer.add(removeRestrictionButton);

    selectedOntologiesContainer.add(selectedOntologiesOptionContainer, BorderLayout.SOUTH);

    // create panel populated with all available ontologies inside a filterable list!
    JPanel availableOntologiesListContainer = new JPanel(new BorderLayout());
    availableOntologiesListContainer
            .setBorder(new TitledBorder(new RoundedBorder(UIHelper.LIGHT_GREEN_COLOR, 7),
                    "available ontologies", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
                    UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR));

    final ExtendedJList availableOntologies = new ExtendedJList(listRenderer);

    final JLabel addOntologyButton = new JLabel(addOntologyButtonIcon);
    addOntologyButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            if (!availableOntologies.isSelectionEmpty()) {
                Ontology ontology = (Ontology) availableOntologies.getSelectedValue();

                selectedOntologies.put(ontology.getOntologyDisplayLabel(), new RecommendedOntology(ontology));
                updateSelectedOntologies();

                setOntologySelectionPanelPlaceholder(infoImage);
            }

            addOntologyButton.setIcon(addOntologyButtonIcon);
        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            addOntologyButton.setIcon(addOntologyButtonIconOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            addOntologyButton.setIcon(addOntologyButtonIcon);
        }
    });

    final JLabel info = UIHelper.createLabel("", UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR);

    availableOntologies.addPropertyChangeListener("update", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            info.setText("<html>viewing <b>" + availableOntologies.getFilteredItems().size()
                    + "</b> ontologies</html>");
        }
    });

    Box optionsBox = Box.createVerticalBox();

    optionsBox.add(UIHelper.wrapComponentInPanel(info));

    Box availableOntologiesOptionBox = Box.createHorizontalBox();
    availableOntologiesOptionBox.add(addOntologyButton);
    availableOntologiesOptionBox.add(Box.createHorizontalGlue());

    optionsBox.add(availableOntologiesOptionBox);

    availableOntologiesListContainer.add(optionsBox, BorderLayout.SOUTH);

    if (ontologiesToBrowseOn == null) {
        ontologiesToBrowseOn = new ArrayList<Ontology>();
        List<Ontology> bioportalQueryResult = bioportalClient.getAllOntologies();
        if (bioportalQueryResult != null) {
            ontologiesToBrowseOn.addAll(bioportalQueryResult);
        }
        ontologiesToBrowseOn.addAll(olsClient.getAllOntologies());
    }

    // precautionary check in case of having no ontologies available to search on.
    if (ontologiesToBrowseOn != null) {
        for (Ontology o : ontologiesToBrowseOn) {
            availableOntologies.addItem(o);
        }
    }

    info.setText(
            "<html>viewing <b>" + availableOntologies.getFilteredItems().size() + "</b> ontologies</html>");

    // need to get ontologies available from bioportal and add them here.
    JScrollPane availableOntologiesScroller = new JScrollPane(availableOntologies,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    availableOntologiesScroller.getViewport().setBackground(UIHelper.BG_COLOR);
    availableOntologiesScroller.setPreferredSize(new Dimension(200, 125));
    availableOntologiesScroller.setBorder(new EmptyBorder(0, 0, 0, 0));

    IAppWidgetFactory.makeIAppScrollPane(availableOntologiesScroller);

    availableOntologiesListContainer.add(availableOntologiesScroller);
    availableOntologiesListContainer.add(availableOntologies.getFilterField(), BorderLayout.NORTH);

    westPanel.add(selectedOntologiesContainer, BorderLayout.CENTER);
    westPanel.add(availableOntologiesListContainer, BorderLayout.SOUTH);

    add(westPanel, BorderLayout.WEST);
}

From source file:org.kuali.test.ui.components.dialogs.ImportPlatformTestsDlg.java

private void loadTestList(String platformName) {
    Platform p = Utils.findPlatform(getMainframe().getConfiguration(), platformName);

    availableTests.removeAll();//  w w w.  j av  a2  s.  co m
    DefaultListModel lm = new DefaultListModel();
    availableTests.setModel(lm);

    List<String> l = new ArrayList<String>();
    for (TestHeader th : p.getPlatformTests().getTestHeaderArray()) {
        if (!existingTargetPlatformTestNames.contains(th.getTestName())) {
            l.add(th.getTestName());
        }
    }

    if (!l.isEmpty()) {
        Collections.sort(l);

        for (String s : l) {
            lm.addElement(s);
        }
    }
}

From source file:org.n52.ifgicopter.spf.output.GpxOutputPlugin.java

/**
 * /*  w  ww  . j a  v  a  2 s .  co  m*/
 * @return
 */
private JPanel makeGUI() {
    if (this.panel == null) {
        this.panel = new JPanel(new BorderLayout());
        JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
        JButton selectFileButton = new JButton(SELECT_GPX_FILE_TEXT);
        selectFileButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                selectGpxFileAction();
            }
        });
        controlPanel.add(selectFileButton);

        this.outputFileLabel = new JLabel();
        controlPanel.add(this.outputFileLabel);

        JButton saveFileButton = new JButton(SAVE_CURRENT_FILE_TEXT);
        saveFileButton.setToolTipText("Does also save manual changes undless model changes were made.");
        saveFileButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                saveCurrentFile();
            }
        });
        controlPanel.add(saveFileButton);

        // JCheckBox scrollLockCheckBox = new JCheckBox("scroll lock");
        // scrollLockCheckBox.setSelected(true);
        // scrollLockCheckBox.addActionListener(new ActionListener() {
        // @Override
        // public void actionPerformed(final ActionEvent e) {
        // EventQueue.invokeLater(new Runnable() {
        //
        // @Override
        // public void run() {
        // JCheckBox source = (JCheckBox) e.getSource();
        // // GpxOutputPlugin.this.textPane.setAutoscrolls(source.isSelected());
        // }
        // });
        // }
        // });
        // controlPanel.add(scrollLockCheckBox);

        this.panel.add(controlPanel, BorderLayout.NORTH);

        JPanel valuesPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT));
        DefaultListModel listModel = new DefaultListModel();
        listModel.addElement(NO_DATA_LIST_ELEMENT);
        this.valuesToSaveList = new JList(listModel);
        this.valuesToSaveList.setVisibleRowCount(2);
        this.valuesToSaveList
                .setToolTipText("Select (multiple) values to include in the GPX file [Multiple using <Ctrl>].");
        this.valuesToSaveList.addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(final ListSelectionEvent e) {
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        JList list = (JList) e.getSource();
                        // DefaultListModel listModel = (DefaultListModel) list.getModel();
                        Object[] selectedValues = list.getSelectedValues();
                        log.debug("New selection in value list:" + Arrays.toString(selectedValues));

                        GpxOutputPlugin.this.valuesToSave.clear();

                        for (Object o : selectedValues) {
                            if (o instanceof String) {
                                String s = (String) o;
                                if (!GpxOutputPlugin.this.valuesToSave.contains(s))
                                    GpxOutputPlugin.this.valuesToSave.add(s);
                            }
                        }
                    }
                });
            }
        });
        this.valuesToSaveList.setSize(200, 22);
        this.valuesToSaveList.setAlignmentY(Component.CENTER_ALIGNMENT);
        valuesPanel.add(new JLabel("Saved attributes:"));
        valuesPanel.add(this.valuesToSaveList);
        valuesPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
        this.panel.add(valuesPanel, BorderLayout.EAST);

        this.textPane = new XmlTextPane();
        this.textPane.setEditable(true);
        this.textPane.setFont(Font.getFont(Font.MONOSPACED));

        JScrollPane scrollPane = new JScrollPane(this.textPane);
        this.panel.add(scrollPane, BorderLayout.CENTER);
        JButton refreshTextFieldButton = new JButton("Update");
        refreshTextFieldButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        updateGUI();
                    }
                });
            }
        });
        this.panel.add(refreshTextFieldButton, BorderLayout.SOUTH);

        updateGUI();
    }

    return this.panel;
}

From source file:org.netbeans.modules.php.fuel.options.FuelPhpOptionsPanel.java

private void setAvailableNodes() {
    DefaultListModel<String> defaultListModel = new DefaultListModel<String>();
    for (String node : FuelPhp.CUSTOM_NODES) {
        defaultListModel.addElement(node);
    }/*from www.  ja  v  a2  s .  c  o m*/
    nodeList.setModel(defaultListModel);
    List<String> availableNodes = FuelPhpOptions.getInstance().getAvailableNodes();
    for (String node : availableNodes) {
        int indexOf = defaultListModel.indexOf(node);
        nodeList.addSelectionInterval(indexOf, indexOf);
    }
}