Search in sources :

Example 21 with DefaultListCellRenderer

use of javax.swing.DefaultListCellRenderer in project n2a by frothga.

the class SettingsBackend method getPanel.

@SuppressWarnings("serial")
@Override
public Component getPanel() {
    if (scrollPane != null)
        return scrollPane;
    JPanel view = new JPanel();
    scrollPane = new JScrollPane(view);
    for (Host h : Host.getHosts()) model.addElement(h);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            Host h = (Host) list.getSelectedValue();
            if (h == null)
                return;
            bind(h.config.childOrCreate("backend", key));
        }
    });
    list.setCellRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Host h = (Host) value;
            String name = h.name;
            if (h.config.get("backend", key).equals("0"))
                name = "<html><s>" + name + "</s></html>";
            return super.getListCellRendererComponent(list, name, index, isSelected, cellHasFocus);
        }
    });
    InputMap inputMap = list.getInputMap();
    inputMap.put(KeyStroke.getKeyStroke("DELETE"), "toggleEnable");
    inputMap.put(KeyStroke.getKeyStroke("BACK_SPACE"), "toggleEnable");
    inputMap.put(KeyStroke.getKeyStroke("SPACE"), "toggleEnable");
    ActionMap actionMap = list.getActionMap();
    actionMap.put("toggleEnable", new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            Host h = (Host) list.getSelectedValue();
            if (h == null)
                return;
            boolean disabled = h.config.get("backend", key).equals("0");
            if (disabled)
                h.config.set(null, "backend", key);
            else
                h.config.set("0", "backend", key);
            list.repaint();
        }
    });
    JPanel panelList = Lay.BL("C", list, "pref=[100,200]");
    panelList.setBorder(LineBorder.createBlackLineBorder());
    panelList = (JPanel) Lay.eb(Lay.BL("C", panelList), "5");
    editor = getEditor();
    Lay.BLtg(view, "N", Lay.BL("W", Lay.BxL("H", Lay.BL("N", panelList), Box.createHorizontalStrut(5), Lay.BL("N", editor))));
    if (list.getModel().getSize() > 0)
        list.setSelectedIndex(0);
    return scrollPane;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Host(gov.sandia.n2a.host.Host) ListSelectionListener(javax.swing.event.ListSelectionListener) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) InputMap(javax.swing.InputMap) Component(java.awt.Component) AbstractAction(javax.swing.AbstractAction)

Example 22 with DefaultListCellRenderer

use of javax.swing.DefaultListCellRenderer in project vcell by virtualcell.

the class EventAssignmentsTableModel method updateSteComboBox.

private void updateSteComboBox() {
    if (fieldSimContext == null) {
        return;
    }
    if (steComboBox == null) {
        steComboBox = new JComboBox<>();
    }
    populateVariableComboBoxModel(aModel, fieldSimContext);
    // steComboBox.addFocusListener(new java.awt.event.FocusAdapter() {
    // @Override
    // public void focusGained(java.awt.event.FocusEvent evt) {
    // 
    // DefaultComboBoxModel<String> aModel = (DefaultComboBoxModel<String>) steComboBox.getModel();
    // ArrayList<String> varNameList = EventPanel.filterEventAssignmentVariables(fieldSimContext);
    // // TODO: repopulate aModel
    // }
    // });
    steComboBox.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            setHorizontalTextPosition(SwingConstants.LEFT);
            if (value == null) {
                setText("");
            } else if (value instanceof String) {
                setText((String) value);
            } else {
                setText(value.toString());
                System.out.println("not String");
            }
            return this;
        }
    });
    steComboBox.setModel(aModel);
    ownerTable.getColumnModel().getColumn(COLUMN_EVENTASSGN_VARNAME).setCellEditor(new DefaultCellEditor(steComboBox));
}
Also used : DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) Component(java.awt.Component) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 23 with DefaultListCellRenderer

use of javax.swing.DefaultListCellRenderer in project vcell by virtualcell.

the class DBReactionWizardPanel method getParameterNamesJList.

/**
 * Return the ParameterNamesJList property value.
 * @return javax.swing.JList
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private JList<MapStringToObject> getParameterNamesJList() {
    if (ivjParameterNamesJList == null) {
        try {
            ivjParameterNamesJList = new JList<MapStringToObject>();
            ivjParameterNamesJList.setName("ParameterNamesJList");
            ivjParameterNamesJList.setBounds(0, 0, 160, 120);
            ivjParameterNamesJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
            ivjParameterNamesJList.setCellRenderer(new DefaultListCellRenderer() {

                @Override
                public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    // TODO Auto-generated method stub
                    Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                    comp.setEnabled(((MapStringToObject) value).isEnabled());
                    return comp;
                }
            });
            ivjParameterNamesJList.setSelectionModel(new DefaultListSelectionModel() {

                @Override
                public void setSelectionInterval(int index0, int index1) {
                    if (ivjParameterNamesJList.getModel().getElementAt(index0).isEnabled())
                        super.setSelectionInterval(index0, index1);
                }
            });
        // user code begin {1}
        // user code end
        } catch (java.lang.Throwable ivjExc) {
            // user code begin {2}
            // user code end
            handleException(ivjExc);
        }
    }
    return ivjParameterNamesJList;
}
Also used : DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) Component(java.awt.Component)

Example 24 with DefaultListCellRenderer

use of javax.swing.DefaultListCellRenderer in project vcell by virtualcell.

the class StructurePropertiesPanel method initialize.

/**
 * Initialize the class.
 */
private void initialize() {
    try {
        setName(this.getClass().getName());
        setLayout(new GridBagLayout());
        nameTextField = new JTextField();
        nameTextField.setEditable(false);
        nameTextField.addActionListener(eventHandler);
        sizeTextField = new JTextField();
        sizeTextField.setEditable(false);
        voltageLabel = new JLabel("Voltage Variable Name");
        voltageTextField = new JTextField();
        voltageTextField.setEditable(false);
        electrophysiologyLabel = new JLabel("<html><u>Electrophysiology</u></html>");
        electrophysiologyExplanationLabel = new JLabel();
        positiveFeatureLabel = new JLabel("Positive (inside feature)");
        positiveFeatureComboBox = new JComboBox<String>();
        negativeFeatureLabel = new JLabel("Negative (outside feature)");
        negativeFeatureComboBox = new JComboBox<String>();
        // annotationTextArea = new javax.swing.JTextArea("", 1, 30);
        // annotationTextArea.setLineWrap(true);
        // annotationTextArea.setWrapStyleWord(true);
        // annotationTextArea.setFont(new Font("monospaced", Font.PLAIN, 11));
        // annotationTextArea.setEditable(false);
        int gridy = 0;
        GridBagConstraints gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 2;
        gbc.insets = new java.awt.Insets(0, 4, 0, 4);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        JLabel label = new JLabel("<html><u>Select only one structure to edit properties</u></html>");
        label.setHorizontalAlignment(SwingConstants.CENTER);
        label.setFont(label.getFont().deriveFont(Font.BOLD));
        add(label, gbc);
        // name
        gridy++;
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.anchor = GridBagConstraints.LINE_END;
        label = new JLabel("Structure Name");
        add(label, gbc);
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.anchor = GridBagConstraints.LINE_START;
        add(nameTextField, gbc);
        // size
        gridy++;
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.anchor = GridBagConstraints.LINE_END;
        label = new JLabel("Size Variable Name");
        add(label, gbc);
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.anchor = GridBagConstraints.LINE_START;
        add(sizeTextField, gbc);
        // electrophysiology
        gbc = new java.awt.GridBagConstraints();
        gridy++;
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 2;
        gbc.insets = new java.awt.Insets(0, 4, 0, 4);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        electrophysiologyLabel.setHorizontalAlignment(SwingConstants.CENTER);
        electrophysiologyLabel.setFont(label.getFont().deriveFont(Font.BOLD));
        add(electrophysiologyLabel, gbc);
        // voltage
        gridy++;
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.anchor = GridBagConstraints.LINE_END;
        add(voltageLabel, gbc);
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.anchor = GridBagConstraints.LINE_START;
        voltageTextField.setForeground(Color.blue);
        add(voltageTextField, gbc);
        // positive (feature) voltage
        gridy++;
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.anchor = GridBagConstraints.LINE_END;
        add(positiveFeatureLabel, gbc);
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.anchor = GridBagConstraints.LINE_START;
        positiveFeatureComboBox.setForeground(Color.blue);
        add(positiveFeatureComboBox, gbc);
        // negative (feature) voltage
        gbc = new java.awt.GridBagConstraints();
        gridy++;
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.anchor = GridBagConstraints.LINE_END;
        add(negativeFeatureLabel, gbc);
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.anchor = GridBagConstraints.LINE_START;
        negativeFeatureComboBox.setForeground(Color.blue);
        add(negativeFeatureComboBox, gbc);
        // electrophysiology
        gbc = new java.awt.GridBagConstraints();
        gridy++;
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 2;
        gbc.insets = new java.awt.Insets(0, 4, 0, 4);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        electrophysiologyExplanationLabel.setHorizontalAlignment(SwingConstants.CENTER);
        // electrophysiologyExplanationLabel.setFont(label.getFont().deriveFont(Font.BOLD));
        add(electrophysiologyExplanationLabel, gbc);
        // // annotation
        // gridy ++;
        // gbc = new java.awt.GridBagConstraints();
        // gbc.gridx = 0;
        // gbc.gridy = gridy;
        // gbc.insets = new Insets(9, 8, 4, 6);
        // gbc.anchor = GridBagConstraints.FIRST_LINE_END;
        // add(new JLabel("Annotation "), gbc);
        // 
        // javax.swing.JScrollPane jsp = new javax.swing.JScrollPane(annotationTextArea);
        gbc = new java.awt.GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.weighty = 1;
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.LINE_START;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        // empty space filling
        add(new JLabel(), gbc);
        DefaultListCellRenderer comboBoxListCellRenderer = new DefaultListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (value instanceof Feature) {
                    setText(((Structure) value).getName());
                }
                return this;
            }
        };
        positiveFeatureComboBox.setRenderer(comboBoxListCellRenderer);
        negativeFeatureComboBox.setRenderer(comboBoxListCellRenderer);
        setBackground(Color.white);
        initConnections();
    } catch (java.lang.Throwable ivjExc) {
        handleException(ivjExc);
    }
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) GridBagConstraints(java.awt.GridBagConstraints) Feature(cbit.vcell.model.Feature) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) JList(javax.swing.JList)

Example 25 with DefaultListCellRenderer

use of javax.swing.DefaultListCellRenderer in project vcell by virtualcell.

the class ElectricalStimulusPanel method getJPanel1.

/**
 * Return the JPanel1 property value.
 * @return javax.swing.JPanel
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JPanel getJPanel1() {
    if (ivjJPanel1 == null) {
        try {
            ivjJPanel1 = new javax.swing.JPanel();
            ivjJPanel1.setName("JPanel1");
            ivjJPanel1.setLayout(new BoxLayout(ivjJPanel1, BoxLayout.X_AXIS));
            JLabel label = new javax.swing.JLabel();
            label.setText("Electrical Stimulus:");
            label.setFont(label.getFont().deriveFont(Font.BOLD));
            ivjJPanel1.add(label);
            clampComboBox = new JComboBox();
            for (Clamp clamp : Clamp.values()) {
                clampComboBox.addItem(clamp);
            }
            clampComboBox.setRenderer(new DefaultListCellRenderer() {

                @Override
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                    if (value instanceof Clamp) {
                        setText(((Clamp) value).title);
                    }
                    return this;
                }
            });
            ivjJPanel1.add(Box.createHorizontalStrut(4));
            ivjJPanel1.add(clampComboBox);
            ivjJPanel1.add(Box.createHorizontalGlue());
            ivjJPanel1.add(getBtnGraphElectricalStimulus());
        } catch (java.lang.Throwable ivjExc) {
            handleException(ivjExc);
        }
    }
    return ivjJPanel1;
}
Also used : JComboBox(javax.swing.JComboBox) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) Component(java.awt.Component) JList(javax.swing.JList)

Aggregations

DefaultListCellRenderer (javax.swing.DefaultListCellRenderer)55 Component (java.awt.Component)45 JList (javax.swing.JList)30 JLabel (javax.swing.JLabel)19 JComboBox (javax.swing.JComboBox)18 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)14 JComponent (javax.swing.JComponent)13 JPanel (javax.swing.JPanel)11 JScrollPane (javax.swing.JScrollPane)10 Dimension (java.awt.Dimension)9 GridBagConstraints (java.awt.GridBagConstraints)9 BorderLayout (java.awt.BorderLayout)8 GridBagLayout (java.awt.GridBagLayout)8 Point (java.awt.Point)6 ArrayList (java.util.ArrayList)6 Insets (java.awt.Insets)5 ActionEvent (java.awt.event.ActionEvent)5 Feature (cbit.vcell.model.Feature)4 Membrane (cbit.vcell.model.Membrane)4 SpeciesContext (cbit.vcell.model.SpeciesContext)3