Example usage for javax.swing AbstractListModel getSize

List of usage examples for javax.swing AbstractListModel getSize

Introduction

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

Prototype

int getSize();

Source Link

Document

Returns the length of the list.

Usage

From source file:edu.ku.brc.specify.datamodel.busrules.AgentBusRules.java

/**
 * Enables/Disables both the control and the Label
 * @param id the id of the control// w ww  . j av a2 s.com
 * @param enabled enable it
 * @param value the value it should set
 * @param thisObj the main data object
 */
protected void enableFieldAndLabel(final String id, final boolean enabled, final String value,
        final Agent agent) {
    Component field = formViewObj.getCompById(id);
    if (field != null) {
        field.setEnabled(enabled);

        if (field instanceof TextFieldFromPickListTable) {
            String title = "";
            PickListDBAdapterIFace adaptor = ((TextFieldFromPickListTable) field).getPickListAdapter();
            if (adaptor != null) {
                for (PickListItemIFace pli : adaptor.getList()) {
                    if (pli.getValue().equals(value)) {
                        title = pli.getTitle();
                        break;
                    }
                }
                ((TextFieldFromPickListTable) field).setText(title);
            } else {
                log.error("Adapter was null for id [" + id + "] on the Agent Form.");
            }
            return;
        }

        if (field instanceof JComboBox || field instanceof ValComboBox) {
            JComboBox<?> cbx = field instanceof ValComboBox ? ((ValComboBox) field).getComboBox()
                    : (JComboBox<?>) field;
            int inx = -1;
            if (value != null) {
                AbstractListModel<?> model = (AbstractListModel<?>) cbx.getModel();
                for (int i = 0; i < model.getSize(); i++) {
                    Object item = model.getElementAt(i);
                    if (item instanceof PickListItemIFace) {
                        PickListItemIFace pli = (PickListItemIFace) item;
                        if (pli.getValue().equals(value)) {
                            inx = i;
                            break;
                        }
                    } else if (item.toString().equals(value)) {
                        inx = i;
                        break;
                    }
                }
            }
            //System.err.println("AgentBusRules - id "+id+" setting to "+inx);
            cbx.setSelectedIndex(inx);

        } else if (field instanceof JTextComponent) {
            ((JTextComponent) field).setText(value != null ? value : "");

        } else if (field instanceof PartialDateUI) {
            PartialDateUI plugin = (PartialDateUI) field;
            plugin.setValue(agent, null);

        } else {
            log.debug("******** unhandled component type: " + field);
        }
        JLabel label = formViewObj.getLabelFor(field);
        if (label != null) {
            label.setEnabled(enabled);
        }
    }
}

From source file:org.ut.biolab.medsavant.client.filter.TabularFilterView.java

protected final void initContentPanel() {

    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    if (availableValues == null) {
        JTextArea label = new JTextArea(
                "There are too many unique values to generate this list. You will not be able to filter on this column. ");
        label.setOpaque(false);/*w ww  .  ja  v  a  2 s . com*/
        label.setLineWrap(true);
        label.setWrapStyleWord(true);

        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.insets = new Insets(3, 3, 3, 3);
        add(label, gbc);
        this.showViewCard();
        return;
    }

    applyButton = new JButton("Apply");
    applyButton.setEnabled(false);

    AbstractListModel model = new SimpleListModel();

    field = new QuickListFilterField(model);
    field.setHintText("Type here to filter options");

    // the width of the field has to be less than the width
    // provided to the filter, otherwise, it will push the grid wider
    // and components will be inaccessible
    field.setPreferredSize(new Dimension(FIELD_WIDTH, 22));

    filterableList = new FilterableCheckBoxList(field.getDisplayListModel()) {
        @Override
        public int getNextMatch(String prefix, int startIndex, Position.Bias bias) {
            return -1;
        }

        @Override
        public boolean isCheckBoxEnabled(int index) {
            return true;
        }
    };
    filterableList.getCheckBoxListSelectionModel()
            .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    if (model.getSize() > 0) {
        filterableList.setPrototypeCellValue(model.getElementAt(0)); // Makes it much faster to determine the view's preferred size.
    }

    SearchableUtils.installSearchable(filterableList);

    filterableList.getCheckBoxListSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                applyButton.setEnabled(true);
            }
        }
    });

    setAllSelected(true);

    applyButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            applyFilter();
        }
    });

    JScrollPane jsp = new JScrollPane(filterableList) {
        @Override
        public Dimension getPreferredSize() {
            Dimension result = super.getPreferredSize();
            result = new Dimension(Math.min(result.width, TabularFilterView.this.getWidth() - 20),
                    result.height);
            return result;
        }
    };

    selectAll = ViewUtil.createHyperLinkButton("Select All");
    selectAll.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setAllSelected(true);
            applyButton.setEnabled(true);
        }
    });

    JButton selectNone = ViewUtil.createHyperLinkButton("Select None");

    selectNone.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setAllSelected(false);
            applyButton.setEnabled(true);
        }
    });

    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(3, 15, 3, 15);
    add(field, gbc);

    gbc.weighty = 1.0;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets = new Insets(3, 3, 3, 3);
    add(jsp, gbc);

    gbc.gridwidth = 1;
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.fill = GridBagConstraints.NONE;
    add(selectAll, gbc);
    add(selectNone, gbc);

    gbc.weightx = 1.0;
    gbc.anchor = GridBagConstraints.EAST;
    add(applyButton, gbc);

    this.showViewCard();

}

From source file:org.ut.biolab.medsavant.client.view.component.SelectableListView.java

protected final void initContentPanel() {

    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    if (availableValues == null) {
        JTextArea label = new JTextArea("There are too many values to display.");
        label.setOpaque(false);/*from   w  w w  . j  a v a  2 s .  c o  m*/
        label.setLineWrap(true);
        label.setWrapStyleWord(true);

        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.insets = new Insets(3, 3, 3, 3);
        add(label, gbc);
        return;
    }

    AbstractListModel model = new SelectableListView.SimpleListModel();

    field = new QuickListFilterField(model);
    field.setHintText("Type here to filter options");

    // the width of the field has to be less than the width
    // provided to the filter, otherwise, it will push the grid wider
    // and components will be inaccessible
    field.setPreferredSize(new Dimension(FIELD_WIDTH, 22));

    filterableList = new FilterableCheckBoxList(field.getDisplayListModel()) {
        @Override
        public int getNextMatch(String prefix, int startIndex, Position.Bias bias) {
            return -1;
        }

        @Override
        public boolean isCheckBoxEnabled(int index) {
            return true;
        }
    };
    filterableList.getCheckBoxListSelectionModel()
            .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    if (model.getSize() > 0) {
        filterableList.setPrototypeCellValue(model.getElementAt(0)); // Makes it much faster to determine the view's preferred size.
    }

    SearchableUtils.installSearchable(filterableList);

    setAllSelected(true);

    JScrollPane jsp = new JScrollPane(filterableList) {
        @Override
        public Dimension getPreferredSize() {
            Dimension result = super.getPreferredSize();
            result = new Dimension(Math.min(result.width, SelectableListView.this.getWidth() - 20),
                    result.height);
            return result;
        }
    };

    selectAll = ViewUtil.createHyperLinkButton("Select All");
    selectAll.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setAllSelected(true);
        }
    });

    JButton selectNone = ViewUtil.createHyperLinkButton("Select None");

    selectNone.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setAllSelected(false);
        }
    });

    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(3, 15, 3, 15);
    add(field, gbc);

    gbc.weighty = 1.0;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets = new Insets(3, 3, 3, 3);
    add(jsp, gbc);

    gbc.gridwidth = 1;
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;

    JPanel bottom = new JPanel();
    ViewUtil.applyHorizontalBoxLayout(bottom);

    bottom.add(selectAll);
    bottom.add(selectNone);
    bottom.add(Box.createHorizontalGlue());

    JButton applyButton = new JButton("Apply");
    applyButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            saveSelections();
        }

    });
    bottom.add(applyButton);
    add(bottom, gbc);
}