Example usage for javax.swing DefaultListModel getSize

List of usage examples for javax.swing DefaultListModel getSize

Introduction

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

Prototype

public int getSize() 

Source Link

Document

Returns the number of components in this list.

Usage

From source file:de.pavloff.spark4knime.jsnippet.ui.JarListPanel.java

/**
 * Get the jar files defined in this panel.
 * @return the jar files/* w w w  . jav a 2 s . com*/
 */
public String[] getJarFiles() {
    DefaultListModel<String> jarListModel = (DefaultListModel<String>) m_addJarList.getModel();
    String[] copy = new String[jarListModel.getSize()];
    if (jarListModel.getSize() > 0) {
        jarListModel.copyInto(copy);
    }
    return copy;
}

From source file:misc.TextBatchPrintingDemo.java

/**
 * Print all selected pages in separate threads, one thread per page.
 *//*from  ww  w  .  j a  va 2s .  c  o m*/
void printSelectedPages() {
    DefaultListModel pages = (DefaultListModel) selectedPages.getModel();
    int n = pages.getSize();
    if (n < 1) {
        messageArea.setText("No pages selected");
        return;
    }
    if (printService == null) {
        messageArea.setText("No print service");
        return;
    }

    for (int i = 0; i < n; i++) {
        final PageItem item = (PageItem) pages.getElementAt(i);
        // This method is called from EDT.  Printing is a time-consuming
        // task, so it should be done outside EDT, in a separate thread.
        Runnable printTask = new Runnable() {
            public void run() {
                try {
                    item.print(
                            // Two "false" args mean "no print dialog" and
                            // "non-interactive" (ie, batch-mode printing).
                            null, null, false, printService, null, false);
                } catch (PrinterException pe) {
                    JOptionPane.showMessageDialog(null, "Error printing " + item.getPage() + "\n" + pe,
                            "Print Error", JOptionPane.WARNING_MESSAGE);
                }
            }
        };
        new Thread(printTask).start();
    }

    pages.removeAllElements();
    messageArea.setText(n + (n > 1 ? " pages" : " page") + " printed");
}

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

/**
 * Sets the selected formatter as the default.
 *//*from  www  .j a v a 2s. co m*/
protected void setAsDefFormatter() {
    UIFieldFormatter selected = (UIFieldFormatter) formatList.getSelectedValue();
    DefaultListModel model = (DefaultListModel) formatList.getModel();
    for (int i = 0; i < model.getSize(); i++) {
        UIFieldFormatter uif = (UIFieldFormatter) model.get(i);
        uif.setDefault(uif == selected);
    }

    if (fieldInfo != null) {
        fieldInfo.setFormatter(selected);
    }
    setHasChanged(true);
    formatList.repaint();
}

From source file:ca.uhn.hl7v2.testpanel.ui.AddMessageDialog.java

private void initLocal() {

    DefaultListModel versionListModel = new DefaultListModel();
    myVersionList.setModel(versionListModel);
    for (Version nextVersion : Version.values()) {
        versionListModel.addElement(nextVersion.getVersion());
    }//ww  w.java  2 s  .  c  om

    myVersionList.setSelectedIndex(versionListModel.getSize() - 1);
    myVersionList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent theE) {
            updateTypes();
        }
    });

    myMessageTypeListModel = new DefaultListModel();
    myMessageTypeList.setModel(myMessageTypeListModel);

    updateTypes();

}

From source file:misc.TextBatchPrintingDemo.java

/**
 * Create and display the main application frame.
 *///from   w ww .  j av  a  2  s.c  o  m
void createAndShowGUI() {
    messageArea = new JLabel(defaultMessage);

    selectedPages = new JList(new DefaultListModel());
    selectedPages.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    selectedPages.addListSelectionListener(this);

    setPage(homePage);

    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(pageItem),
            new JScrollPane(selectedPages));

    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);

    /** Menu item and keyboard shortcuts for the "add page" command.  */
    fileMenu.add(createMenuItem(new AbstractAction("Add Page") {
        public void actionPerformed(ActionEvent e) {
            DefaultListModel pages = (DefaultListModel) selectedPages.getModel();
            pages.addElement(pageItem);
            selectedPages.setSelectedIndex(pages.getSize() - 1);
        }
    }, KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.ALT_MASK)));

    /** Menu item and keyboard shortcuts for the "print selected" command.*/
    fileMenu.add(createMenuItem(new AbstractAction("Print Selected") {
        public void actionPerformed(ActionEvent e) {
            printSelectedPages();
        }
    }, KeyEvent.VK_P, KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK)));

    /** Menu item and keyboard shortcuts for the "clear selected" command.*/
    fileMenu.add(createMenuItem(new AbstractAction("Clear Selected") {
        public void actionPerformed(ActionEvent e) {
            DefaultListModel pages = (DefaultListModel) selectedPages.getModel();
            pages.removeAllElements();
        }
    }, KeyEvent.VK_C, KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK)));

    fileMenu.addSeparator();

    /** Menu item and keyboard shortcuts for the "home page" command.  */
    fileMenu.add(createMenuItem(new AbstractAction("Home Page") {
        public void actionPerformed(ActionEvent e) {
            setPage(homePage);
        }
    }, KeyEvent.VK_H, KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.ALT_MASK)));

    /** Menu item and keyboard shortcuts for the "quit" command.  */
    fileMenu.add(createMenuItem(new AbstractAction("Quit") {
        public void actionPerformed(ActionEvent e) {
            for (Window w : Window.getWindows()) {
                w.dispose();
            }
        }
    }, KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK)));

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);

    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    contentPane.add(pane);
    contentPane.add(messageArea);

    JFrame frame = new JFrame("Text Batch Printing Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(menuBar);
    frame.setContentPane(contentPane);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    if (printService == null) {
        // Actual printing is not possible, issue a warning message.
        JOptionPane.showMessageDialog(frame, "No default print service", "Print Service Alert",
                JOptionPane.WARNING_MESSAGE);
    }
}

From source file:dbseer.gui.actions.ExplainChartAction.java

public void togglePredicates() {
    DefaultListModel predicateListModel = panel.getControlPanel().getPredicateListModel();
    if (predicateListModel.getSize() == 0) {
        return;//from w  ww.  ja  v a2 s  . c  om
    }
    this.isPredicateAbsolute = !this.isPredicateAbsolute;
    printPredicates();
}

From source file:dbseer.gui.actions.ExplainChartAction.java

private void savePredicates() {
    DefaultListModel predicateListModel = panel.getControlPanel().getPredicateListModel();
    if (predicateListModel.getSize() == 0) {
        JOptionPane.showMessageDialog(null,
                "There are no predicates to save.\nPlease generate predicates first.", "Warning",
                JOptionPane.WARNING_MESSAGE);
        return;/* w  w  w .  j av  a  2  s  .co  m*/
    }
    final StatisticalPackageRunner runner = DBSeerGUI.runner;
    try {
        String cause = (String) JOptionPane.showInputDialog(null, "Enter the cause for predicates ",
                "New Causal Model", JOptionPane.PLAIN_MESSAGE, null, null, "New Causal Model");

        if (cause == null || cause.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Please enter the cause correctly to save the causal model",
                    "Warning", JOptionPane.WARNING_MESSAGE);
            return;
        }

        cause = cause.trim();

        if (cause == "" || cause.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Please enter the cause correctly to save the causal model",
                    "Warning", JOptionPane.WARNING_MESSAGE);
            return;
        }

        String path = cause;
        String actualPath = causalModelPath + File.separator + cause + ".mat";
        boolean exist = false;
        int idx = 0;

        File checkFile = new File(actualPath);
        while (checkFile.exists()) {
            exist = true;
            ++idx;
            actualPath = causalModelPath + File.separator + cause + "-" + idx + ".mat";
            checkFile = new File(actualPath);
        }

        if (exist) {
            path = cause + "-" + idx;
        }

        runner.eval("createCausalModel('" + causalModelPath + "','" + path + "','" + cause + "', predicates);");

        String output = String.format("A causal model with the cause '%s' has been saved as: \n%s", cause,
                actualPath);

        JOptionPane.showMessageDialog(null, output, "Information", JOptionPane.INFORMATION_MESSAGE);

    } catch (Exception e) {
        DBSeerExceptionHandler.handleException(e);
    }
}

From source file:de.dakror.virtualhub.client.dialog.ChooseCatalogDialog.java

public static void show(ClientFrame frame, final JSONArray data) {
    final JDialog dialog = new JDialog(frame, "Katalog whlen", true);
    dialog.setSize(400, 300);//from w  w w .jav a  2s  .  c o m
    dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            Client.currentClient.disconnect();
            System.exit(0);
        }
    });

    JPanel contentPane = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
    dialog.setContentPane(contentPane);
    DefaultListModel dlm = new DefaultListModel();
    for (int i = 0; i < data.length(); i++) {
        try {
            dlm.addElement(data.getJSONObject(i).getString("name"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    final JList catalogs = new JList(dlm);
    catalogs.setDragEnabled(false);
    catalogs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JScrollPane jsp = new JScrollPane(catalogs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jsp.setPreferredSize(new Dimension(396, 200));
    contentPane.add(jsp);

    JPanel mods = new JPanel(new GridLayout(1, 2));
    mods.setPreferredSize(new Dimension(50, 22));
    mods.add(new JButton(new AbstractAction("+") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            String name = JOptionPane.showInputDialog(dialog,
                    "Bitte geben Sie den Namen des neuen Katalogs ein.", "Katalog hinzufgen",
                    JOptionPane.PLAIN_MESSAGE);
            if (name != null && name.length() > 0) {
                DefaultListModel dlm = (DefaultListModel) catalogs.getModel();
                for (int i = 0; i < dlm.getSize(); i++) {
                    if (dlm.get(i).toString().equals(name)) {
                        JOptionPane.showMessageDialog(dialog,
                                "Es existert bereits ein Katalog mit diesem Namen!",
                                "Katalog bereits vorhanden!", JOptionPane.ERROR_MESSAGE);
                        actionPerformed(e);
                        return;
                    }
                }

                try {
                    dlm.addElement(name);
                    JSONObject o = new JSONObject();
                    o.put("name", name);
                    o.put("sources", new JSONArray());
                    o.put("tags", new JSONArray());
                    data.put(o);
                    Client.currentClient.sendPacket(new Packet0Catalogs(data));
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
    }));
    mods.add(new JButton(new AbstractAction("-") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (catalogs.getSelectedIndex() != -1) {
                if (JOptionPane.showConfirmDialog(dialog,
                        "Sind Sie sicher, dass Sie diesen\r\nKatalog unwiderruflich lschen wollen?",
                        "Katalog lschen", JOptionPane.YES_NO_CANCEL_OPTION,
                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
                    DefaultListModel dlm = (DefaultListModel) catalogs.getModel();
                    data.remove(catalogs.getSelectedIndex());
                    dlm.remove(catalogs.getSelectedIndex());
                    try {
                        Client.currentClient.sendPacket(new Packet0Catalogs(data));
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
    }));

    contentPane.add(mods);

    JLabel l = new JLabel("");
    l.setPreferredSize(new Dimension(396, 14));
    contentPane.add(l);

    JSeparator sep = new JSeparator(JSeparator.HORIZONTAL);
    sep.setPreferredSize(new Dimension(396, 10));
    contentPane.add(sep);

    JPanel buttons = new JPanel(new GridLayout(1, 2));
    buttons.setPreferredSize(new Dimension(396, 22));
    buttons.add(new JButton(new AbstractAction("Abbrechen") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            Client.currentClient.disconnect();
            System.exit(0);
        }
    }));
    buttons.add(new JButton(new AbstractAction("Katalog whlen") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (catalogs.getSelectedIndex() != -1) {
                try {
                    Client.currentClient
                            .setCatalog(new Catalog(data.getJSONObject(catalogs.getSelectedIndex())));
                    Client.currentClient.frame.setTitle("- " + Client.currentClient.getCatalog().getName());
                    dialog.dispose();
                } catch (JSONException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }));

    dialog.add(buttons);

    dialog.setLocationRelativeTo(frame);
    dialog.setResizable(false);
    dialog.setVisible(true);
}

From source file:ListInput.java

public void appendResultSet(ResultSet results, int index, boolean toTitleCase) {
    textfield.setText("");
    DefaultListModel model = new DefaultListModel();
    try {/* w w w .j  av a  2 s .  c  o m*/
        while (results.next()) {
            String str = results.getString(index);
            if (toTitleCase) {
                str = Character.toUpperCase(str.charAt(0)) + str.substring(1);
            }

            model.addElement(str);
        }
    } catch (SQLException ex) {
        System.err.println("appendResultSet: " + ex.toString());
    }
    list.setModel(model);
    if (model.getSize() > 0)
        list.setSelectedIndex(0);
}

From source file:br.upe.ecomp.dosa.view.wizard.WizardAction.java

private void pickListDownAction(final JList list) {
    final DefaultListModel selectedListModel = (DefaultListModel) list.getModel();
    final int selectedIndex = list.getSelectedIndex();
    final int listSize = selectedListModel.getSize();
    Object element;/*ww w  .  j av a2 s .c  om*/
    if (selectedIndex < listSize - 1) {
        element = list.getSelectedValue();
        selectedListModel.remove(selectedIndex);
        selectedListModel.add(selectedIndex + 1, element);
    }
}