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.nuclos.client.wizard.steps.NuclosEntitySQLLayoutStep.java

@Override
public void prepare() {
    this.setComplete(true);
    mpFieldNameChanged = new HashMap<String, String>();

    if (this.model.getAttributeModel().getAttributes().size() == 0)
        cbLayout.setEnabled(false);//ww w  . j  av a2 s .c o  m
    else
        cbLayout.setEnabled(true);

    hasEntityLayout = hasEntityLayout();
    if (hasEntityLayout) {
        lbLayout.setText(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entitysqllayout.16",
                "Wollen Sie die bestehende Maske aktualisieren:"));
    }
    DefaultListModel listmodel = new DefaultListModel();
    List<Attribute> lstAttr = new ArrayList<Attribute>(this.model.getAttributeModel().getAttributes());

    for (Attribute attr : lstAttr) {
        listmodel.addElement(attr);
    }
    treeModel = new MyTreeModel(model.getAttributeModel().getAttributeMap());

    try {
        treeAttributeOrder.setModel(treeModel);
        treeModel.expandWholeTree();
    }
    // TODO: Avoid this NPE (tp)
    catch (NullPointerException e) {
        LOG.info("prepare failed: " + e);
    } catch (Exception e) {
        LOG.info("prepare failed: " + e, e);
    }
    listAttributeOrder.setModel(listmodel);

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            try {
                validateEntity();
            } catch (CommonValidationException ex) {
                NuclosEntitySQLLayoutStep.this.setComplete(false);
                Errors.getInstance().showExceptionDialog(NuclosEntitySQLLayoutStep.this, ex);
            }
        }
    });
}

From source file:org.omegat.gui.issues.IssuesPanelController.java

void reset() {
    if (loader != null) {
        loader.cancel(true);/*from w  w  w.  java 2  s  .c  o m*/
        loader = null;
    }
    frame.setTitle(OStrings.getString("ISSUES_WINDOW_TITLE"));
    panel.table.setModel(new DefaultTableModel());
    panel.typeList.setModel(new DefaultListModel<>());
    panel.outerSplitPane.setBottomComponent(panel.messageLabel);
    panel.messageLabel.setText(OStrings.getString("ISSUES_LOADING"));
    StaticUIUtils.setHierarchyEnabled(panel, false);
    panel.closeButton.setEnabled(true);
    panel.showAllButtonPanel.setVisible(!isShowingAllFiles());
    panel.instructionsPanel.setVisible(!instructions.equals(NO_INSTRUCTIONS));
    panel.instructionsTextArea.setText(instructions);
}

From source file:org.opendatakit.briefcase.ui.CharsetConverterDialog.java

protected void initialize() {
    DefaultListModel<CharsetEntry> defaultListModel = new DefaultListModel<CharsetEntry>();

    for (CharsetEntry commonCharsetEntry : commonCharsetEntries) {
        try {/*from  w w  w .  ja  v  a2 s .  c  om*/
            if (Charset.isSupported(commonCharsetEntry.getCharsetName())) {
                defaultListModel.addElement(commonCharsetEntry);
            }
        } catch (IllegalCharsetNameException e) {
            // just ignore it. It will happen for "Mac OS Roman" under Windows
        }
    }

    SortedMap<String, Charset> charsetSortedMap = Charset.availableCharsets();
    for (Map.Entry<String, Charset> charsetMapEntry : charsetSortedMap.entrySet()) {
        CharsetEntry charsetEntry = new CharsetEntry(charsetMapEntry.getValue().displayName(),
                charsetMapEntry.getKey());
        if (!defaultListModel.contains(charsetEntry)) {
            defaultListModel.addElement(charsetEntry);
        }
    }

    listCharset.setModel(defaultListModel);

    if (defaultListModel.size() > 0) {
        listCharset.setSelectedIndex(0);

        listCharset.addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                updatePreview();
            }
        });
    } else {
        JOptionPane.showMessageDialog(this,
                "It appears that your installed Java Runtime Environment does not support any charset encodings!",
                "Error!", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * Requests the list of Rule descriptions belonging to the currently worked on user
 *//* w  w w. j ava 2 s  .c o  m*/
private void requestRuleList() {
    try {
        URL url = new URL(strRelURL + "/" + privilegedServlet + "CreateConsentServiceServlet?type=rulelist");
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("cookie", strCookie);
        conn.setDoInput(true);

        InputStream is = conn.getInputStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(new InputStreamReader(is, "UTF8"), writer);
        String s = writer.toString();

        JSONArray jsa = new JSONArray(s);

        ruleListModel = new DefaultListModel();

        for (int i = 0; i < jsa.length(); i++) {

            JSONObject jsoo = (JSONObject) jsa.get(i);

            OIDObject oi = new OIDObject(jsoo.getString("ruleID"), jsoo.getString("description"), true);

            ruleListModel.addElement(oi);
        }

        is.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.openestate.tool.helloworld.HelloWorldFrameSidebarExtension.java

@Override
public JComponent createComponent() {
    // create the component, that is shown in the sidebar
    final HelloWorldList list = new HelloWorldList();
    list.setModel(ObjectUtils.defaultIfNull(createListModel(), new DefaultListModel<>()));
    list.setCellRenderer(new HelloWorldListRenderer());

    // register keyboard events
    list.addKeyListener(new KeyAdapter() {
        @Override//w w  w  .j  av a2s.  c  o m
        public void keyPressed(KeyEvent e) {
            if (!list.isEnabled())
                return;

            // ENTER was pressed
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                DbHelloWorldObject object = list.getSelectedValue();
                if (object != null)
                    new HelloWorldPlugin.ObjectFormAction(object.id).actionPerformed(null);
            }
        }
    });

    // register mouse events
    list.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (!list.isEnabled())
                return;

            // single click with the right mouse button
            if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
                // fetch the clicked element
                int index = list.locationToIndex(e.getPoint());
                if (index >= 0)
                    list.setSelectedIndex(index);

                // show popup menu with further actions
                DbHelloWorldObject object = list.getSelectedValue();
                JPopupMenu popup = createActionMenu(object);
                if (popup != null)
                    popup.show(list, e.getPoint().x, e.getPoint().y);
            }

            // double click with the left mouse button
            else if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                DbHelloWorldObject object = list.getSelectedValue();
                if (object != null)
                    new HelloWorldPlugin.ObjectFormAction(object.id).actionPerformed(null);
            }
        }
    });

    return list;
}

From source file:org.openestate.tool.helloworld.HelloWorldFrameSidebarExtension.java

public static DefaultListModel<DbHelloWorldObject> createListModel(Connection c,
        DbHelloWorldHandler dbHelloWorldHandler) throws SQLException {
    DefaultListModel<DbHelloWorldObject> model = new DefaultListModel<>();
    for (DbHelloWorldObject object : dbHelloWorldHandler.getObjects(c)) {
        model.addElement(object);/*from  ww w.ja v  a2 s.c o m*/
    }
    return model;
}

From source file:org.openmicroscopy.shoola.agents.measurement.util.ui.ResultsCellRenderer.java

/**
 * Creates and returns a {@link JList} from the passed object.
 * /*from  w  ww. j a va 2  s .c  o  m*/
 * @param value The object to handle.
 * @return See above.
 */
private JList createList(Object value) {
    List elementList = (List) value;
    JList list = new JList();
    DefaultListModel model = new DefaultListModel();
    String v;
    for (Object element : elementList) {
        if (element instanceof Float) {
            v = twoDecimalPlaces((Float) element);
            if (v == null)
                return list;
            model.addElement(v);
        } else if (element instanceof Double) {
            v = twoDecimalPlaces((Double) element);
            if (v == null)
                return list;
            model.addElement(v);
        }
    }
    list.setModel(model);
    return list;
}

From source file:org.openmrs.module.muzimabiometrics.panels.EnrollFromScanner.java

@Override
protected void initGUI() {
    panelMain = new JPanel();
    panelScanners = new JPanel();
    scrollPaneList = new JScrollPane();
    scannerList = new JList();
    panelButtons = new JPanel();
    btnRefresh = new JButton();
    btnScan = new JButton();
    btnCancel = new JButton();
    btnForce = new JButton();
    cbAutomatic = new JCheckBox();
    scrollPane = new JScrollPane();
    panelSouth = new JPanel();
    panelInfo = new JPanel();
    lblInfo = new JLabel();
    panelSave = new JPanel();
    btnIdentifyPatient = new JButton();
    btnRegisterPatient = new JButton();
    cbShowProcessed = new JCheckBox();

    setLayout(new BorderLayout());

    panelMain.setLayout(new BorderLayout());

    panelScanners.setBorder(BorderFactory.createTitledBorder("Scanners list"));
    panelScanners.setLayout(new BorderLayout());

    scrollPaneList.setPreferredSize(new Dimension(0, 90));

    scannerList.setModel(new DefaultListModel());
    scannerList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    scannerList.setBorder(LineBorder.createBlackLineBorder());
    scrollPaneList.setViewportView(scannerList);

    panelScanners.add(scrollPaneList, BorderLayout.CENTER);

    panelButtons.setLayout(new FlowLayout(FlowLayout.LEADING));

    btnRefresh.setText("Refresh list");
    panelButtons.add(btnRefresh);//w  w  w. jav a2  s.c  o  m

    btnScan.setText("Scan");
    panelButtons.add(btnScan);

    btnCancel.setText("Cancel");
    btnCancel.setEnabled(false);
    panelButtons.add(btnCancel);

    btnForce.setText("Force");
    panelButtons.add(btnForce);

    cbAutomatic.setSelected(true);
    cbAutomatic.setText("Scan automatically");
    panelButtons.add(cbAutomatic);

    panelScanners.add(panelButtons, BorderLayout.SOUTH);

    panelMain.add(panelScanners, BorderLayout.NORTH);
    panelMain.add(scrollPane, BorderLayout.CENTER);

    panelSouth.setLayout(new BorderLayout());

    panelInfo.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
    panelInfo.setLayout(new GridLayout(1, 1));

    lblInfo.setText(" ");
    panelInfo.add(lblInfo);

    panelSouth.add(panelInfo, BorderLayout.NORTH);

    panelSave.setLayout(new FlowLayout(FlowLayout.LEADING));

    btnIdentifyPatient.setText("Scan fingerprint");
    btnIdentifyPatient.setEnabled(true);
    panelSave.add(btnIdentifyPatient);

    btnRegisterPatient.setText("Register Patient");
    btnRegisterPatient.setEnabled(true);
    panelSave.add(btnRegisterPatient);

    cbShowProcessed.setSelected(true);
    cbShowProcessed.setText("Show processed image");
    panelSave.add(cbShowProcessed);

    panelSouth.add(panelSave, BorderLayout.SOUTH);

    panelMain.add(panelSouth, BorderLayout.SOUTH);

    add(panelMain, BorderLayout.CENTER);

    panelLicensing = new LicensingPanel(requiredLicenses, optionalLicenses);
    add(panelLicensing, java.awt.BorderLayout.NORTH);

    fcImage = new JFileChooser();
    fcImage.setFileFilter(new Utils.ImageFileFilter(NImages.getSaveFileFilter()));
    fcTemplate = new JFileChooser();
    view = new NFingerView();
    view.setShownImage(ShownImage.RESULT);
    view.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent ev) {
            super.mouseClicked(ev);
            if (ev.getButton() == MouseEvent.BUTTON3) {
                cbShowProcessed.doClick();
            }
        }

    });
    scrollPane.setViewportView(view);

    btnRefresh.addActionListener(this);
    btnScan.addActionListener(this);
    btnCancel.addActionListener(this);
    btnForce.addActionListener(this);
    btnIdentifyPatient.addActionListener(this);
    btnRegisterPatient.addActionListener(this);
    cbShowProcessed.addActionListener(this);
    scannerList.addListSelectionListener(new ScannerSelectionListener());
}

From source file:org.openmrs.module.muzimabiometrics.panels.ScanFingerprint.java

@Override
protected void initGUI() throws IOException, JSONException {
    panelMain = new JPanel();
    panelMain.setBackground(Color.white);
    panelMain.setLayout(new BoxLayout(panelMain, BoxLayout.PAGE_AXIS));

    panelMessage = new JPanel();
    panelMessage.setBackground(Color.white);
    panelMessage.add(lblProgressMessage);
    panelMessage.setLayout(new FlowLayout(FlowLayout.TRAILING));

    panelButtons = new JPanel();
    panelButtons.setBackground(Color.white);
    panelButtons.setLayout(new FlowLayout(FlowLayout.LEADING));

    btnTryAgain.setVisible(false);/*from   ww w .j a  v a  2  s .  c  om*/
    btnTryAgain.addActionListener(this);

    btnLaunchApplet.setVisible(true);
    btnLaunchApplet.addActionListener(this);

    panelButtons.add(btnTryAgain);
    panelButtons.add(btnLaunchApplet);

    panelMain.add(panelMessage);
    panelMain.add(panelButtons);

    add(panelMain);

    scannerList = new JList();
    scannerList.setModel(new DefaultListModel());
    scannerList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    scannerList.addListSelectionListener(new ScannerSelectionListener());
}

From source file:org.openuat.apps.BedaApp.java

private void updateDeviceList() {
    devices = peerManager.getPeers();/* w  ww.j ava2s  .  co  m*/
    DefaultListModel listModel = new DefaultListModel();
    for (RemoteDevice device : devices) {
        try {
            listModel.addElement(device.getFriendlyName(false));
        } catch (IOException e) {
            listModel.addElement("Unknown device");
        }
    }
    deviceList.setModel(listModel);
}