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;
}
});
}
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));
}
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);
}
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));
}
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;
}
Aggregations