Search in sources :

Example 46 with DefaultListCellRenderer

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

the class ChomboSimpleDataViewer method initialize.

private void initialize() {
    setSize(1000, 500);
    BeanUtils.centerOnScreen(this);
    solTable.setModel(solTableModel);
    solTable.setDefaultRenderer(Number.class, new SolTableCellRenderer());
    meshMetricsTable.setModel(meshMetricsTableModel);
    timePlotTable.setModel(timePlotTableModel);
    varList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    mainPanel.setLayout(new GridBagLayout());
    JPanel meshMetricsPanel = new JPanel(new BorderLayout());
    meshMetricsPanel.add(new JScrollPane(meshMetricsTable), BorderLayout.CENTER);
    dataTabbedPane.addTab("Solution", createSolPanel());
    dataTabbedPane.addTab("Mesh Metrics", meshMetricsPanel);
    dataTabbedPane.addTab("Time Plot", createTimePlotPanel());
    int gridy = 0;
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.weightx = 0.4;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(2, 2, 2, 2);
    mainPanel.add(createInputPanel(), gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = gridy;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.gridheight = GridBagConstraints.REMAINDER;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.insets = new Insets(2, 2, 2, 2);
    gbc.fill = GridBagConstraints.BOTH;
    mainPanel.add(dataTabbedPane, gbc);
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.insets = new Insets(2, 2, 2, 2);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 1.0;
    gbc.weightx = 0.2;
    mainPanel.add(createSelectionPanel(), gbc);
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.insets = new Insets(2, 2, 20, 20);
    gbc.anchor = GridBagConstraints.LINE_END;
    mainPanel.add(exitButton, gbc);
    add(mainPanel);
    reset();
    resetButton.addActionListener(listener);
    okButton.addActionListener(listener);
    timeComboBox.addActionListener(listener);
    exitButton.addActionListener(listener);
    varList.addListSelectionListener(listener);
    timePlotButton.setEnabled(false);
    timePlotButton.addActionListener(listener);
    solTable.getSelectionModel().addListSelectionListener(listener);
    dataDirTextField.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            dataDirTextField.setToolTipText(dataDirTextField.getText());
        }
    });
    varList.setCellRenderer(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 DataSetIdentifier) {
                setText(((DataSetIdentifier) value).getName());
            }
            return this;
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) MouseEvent(java.awt.event.MouseEvent) GridBagLayout(java.awt.GridBagLayout) DataSetIdentifier(cbit.vcell.simdata.DataSetIdentifier) MouseAdapter(java.awt.event.MouseAdapter) BorderLayout(java.awt.BorderLayout) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) Component(java.awt.Component) JList(javax.swing.JList)

Example 47 with DefaultListCellRenderer

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

the class AssignmentRulesSummaryTableModel method updateSubdomainComboBox.

private void updateSubdomainComboBox() {
    if (steComboBox == null) {
        steComboBox = new JComboBox<>();
    }
    if (simulationContext == null) {
        return;
    }
    SpeciesContext[] scs = simulationContext.getModel().getSpeciesContexts();
    ModelParameter[] mps = simulationContext.getModel().getModelParameters();
    DefaultComboBoxModel<String> aModel = new DefaultComboBoxModel<>();
    for (SpeciesContext sc : scs) {
        aModel.addElement(sc.getName());
    }
    for (ModelParameter mp : mps) {
        aModel.addElement(mp.getName());
    }
    steComboBox.addFocusListener(new java.awt.event.FocusAdapter() {

        @Override
        public void focusGained(java.awt.event.FocusEvent evt) {
            DefaultComboBoxModel<String> aModel = (DefaultComboBoxModel<String>) steComboBox.getModel();
            SpeciesContext[] scs = simulationContext.getModel().getSpeciesContexts();
            ModelParameter[] mps = simulationContext.getModel().getModelParameters();
            for (SpeciesContext sc : scs) {
                int position = aModel.getIndexOf(sc.getName());
                if (position == -1) {
                    // element is missing, add it
                    aModel.addElement(sc.getName());
                }
            }
            for (ModelParameter mp : mps) {
                int position = aModel.getIndexOf(mp.getName());
                if (position == -1) {
                    aModel.addElement(mp.getName());
                }
            }
            Set<String> elementsToRemove = new HashSet<>();
            for (int i = 0; i < aModel.getSize(); i++) {
                String candidate = aModel.getElementAt(i);
                SpeciesContext sc = simulationContext.getModel().getSpeciesContext(candidate);
                ModelParameter mp = simulationContext.getModel().getModelParameter(candidate);
                if (sc == null && mp == null) {
                    elementsToRemove.add(candidate);
                }
                if (sc != null && simulationContext.getRateRule(sc) != null) {
                    elementsToRemove.add(candidate);
                    continue;
                }
                if (mp != null && simulationContext.getRateRule(mp) != null) {
                    elementsToRemove.add(candidate);
                    continue;
                }
                if (simulationContext.getBioEvents() == null) {
                    continue;
                }
                boolean found = false;
                for (BioEvent event : simulationContext.getBioEvents()) {
                    ArrayList<EventAssignment> eas = event.getEventAssignments();
                    if (eas == null) {
                        continue;
                    }
                    for (EventAssignment ea : eas) {
                        if (ea.getTarget() != null && candidate.contentEquals(ea.getTarget().getName())) {
                            found = true;
                            break;
                        }
                    }
                    if (found) {
                        break;
                    }
                }
                if (found) {
                    elementsToRemove.add(candidate);
                    continue;
                }
            }
            for (String candidate : elementsToRemove) {
                aModel.removeElement(candidate);
            }
        }
    });
    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_ASSIGNMENTRULE_VAR).setCellEditor(new DefaultCellEditor(steComboBox));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) SpeciesContext(cbit.vcell.model.SpeciesContext) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) Component(java.awt.Component) EventAssignment(cbit.vcell.mapping.BioEvent.EventAssignment) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DefaultCellEditor(javax.swing.DefaultCellEditor) ModelParameter(cbit.vcell.model.Model.ModelParameter) BioEvent(cbit.vcell.mapping.BioEvent)

Example 48 with DefaultListCellRenderer

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

the class BioModelEditorConversionTableModel method updateStructureComboBox.

protected void updateStructureComboBox() {
    JComboBox structureComboBoxCellEditor = (JComboBox) getStructureComboBoxEditor().getComponent();
    if (structureComboBoxCellEditor == null) {
        structureComboBoxCellEditor = new JComboBox();
    }
    Structure[] structures = bioModel.getModel().getStructures();
    DefaultComboBoxModel aModel = new DefaultComboBoxModel();
    for (Structure s : structures) {
        aModel.addElement(s);
    }
    DefaultListCellRenderer defaultListCellRenderer = new DefaultListCellRenderer() {

        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 instanceof Structure) {
                setText(((Structure) value).getName());
            }
            return this;
        }
    };
    structureComboBoxCellEditor.setRenderer(defaultListCellRenderer);
    structureComboBoxCellEditor.setModel(aModel);
    structureComboBoxCellEditor.setSelectedIndex(0);
}
Also used : JComboBox(javax.swing.JComboBox) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) BioPaxObject(org.vcell.pathway.BioPaxObject) RelationshipObject(org.vcell.relationship.RelationshipObject) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Structure(cbit.vcell.model.Structure) JList(javax.swing.JList)

Example 49 with DefaultListCellRenderer

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

the class RateRulesSummaryTableModel method updateSubdomainComboBox.

private void updateSubdomainComboBox() {
    if (steComboBox == null) {
        steComboBox = new JComboBox<>();
    }
    if (simulationContext == null) {
        return;
    }
    SpeciesContext[] scs = simulationContext.getModel().getSpeciesContexts();
    ModelParameter[] mps = simulationContext.getModel().getModelParameters();
    DefaultComboBoxModel<String> aModel = new DefaultComboBoxModel<>();
    for (SpeciesContext sc : scs) {
        aModel.addElement(sc.getName());
    }
    for (ModelParameter mp : mps) {
        aModel.addElement(mp.getName());
    }
    steComboBox.addMouseListener(new java.awt.event.MouseAdapter() {

        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
        }

        @Override
        public void mouseEntered(java.awt.event.MouseEvent evt) {
        }
    });
    steComboBox.addFocusListener(new java.awt.event.FocusAdapter() {

        @Override
        public void focusGained(java.awt.event.FocusEvent evt) {
            DefaultComboBoxModel<String> aModel = (DefaultComboBoxModel<String>) steComboBox.getModel();
            SpeciesContext[] scs = simulationContext.getModel().getSpeciesContexts();
            ModelParameter[] mps = simulationContext.getModel().getModelParameters();
            for (SpeciesContext sc : scs) {
                int position = aModel.getIndexOf(sc.getName());
                if (position == -1) {
                    // element is missing, add it
                    aModel.addElement(sc.getName());
                }
            }
            for (ModelParameter mp : mps) {
                int position = aModel.getIndexOf(mp.getName());
                if (position == -1) {
                    aModel.addElement(mp.getName());
                }
            }
            Set<String> elementsToRemove = new HashSet<>();
            for (int i = 0; i < aModel.getSize(); i++) {
                String candidate = aModel.getElementAt(i);
                SpeciesContext sc = simulationContext.getModel().getSpeciesContext(candidate);
                ModelParameter mp = simulationContext.getModel().getModelParameter(candidate);
                if (sc == null && mp == null) {
                    elementsToRemove.add(candidate);
                }
                if (sc != null && simulationContext.getAssignmentRule(sc) != null) {
                    elementsToRemove.add(candidate);
                    continue;
                }
                if (mp != null && simulationContext.getAssignmentRule(mp) != null) {
                    elementsToRemove.add(candidate);
                    continue;
                }
            }
            for (String candidate : elementsToRemove) {
                aModel.removeElement(candidate);
            }
        }
    });
    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_RATERULE_VAR).setCellEditor(new DefaultCellEditor(steComboBox));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) SpeciesContext(cbit.vcell.model.SpeciesContext) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DefaultCellEditor(javax.swing.DefaultCellEditor) ModelParameter(cbit.vcell.model.Model.ModelParameter) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) Component(java.awt.Component)

Example 50 with DefaultListCellRenderer

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

the class OutputFunctionsPanel method getSubdomainComboBox.

private JComboBox getSubdomainComboBox() {
    if (subdomainComboBox == null) {
        try {
            subdomainComboBox = new JComboBox();
            subdomainComboBox.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 GeometryClass) {
                        setText(((GeometryClass) value).getName());
                    } else if (value instanceof VariableType) {
                        setText(((VariableType) value).getTypeName());
                    }
                    return this;
                }
            });
        } catch (java.lang.Throwable e) {
            e.printStackTrace(System.out);
        }
    }
    return subdomainComboBox;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) JComboBox(javax.swing.JComboBox) VariableType(cbit.vcell.math.VariableType) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) Component(java.awt.Component) JList(javax.swing.JList)

Aggregations

DefaultListCellRenderer (javax.swing.DefaultListCellRenderer)54 Component (java.awt.Component)44 JList (javax.swing.JList)29 JLabel (javax.swing.JLabel)19 JComboBox (javax.swing.JComboBox)17 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)13 JComponent (javax.swing.JComponent)12 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 ArrayList (java.util.ArrayList)6 Insets (java.awt.Insets)5 Point (java.awt.Point)5 Feature (cbit.vcell.model.Feature)4 Membrane (cbit.vcell.model.Membrane)4 SpeciesContext (cbit.vcell.model.SpeciesContext)3 Font (java.awt.Font)3