use of cbit.vcell.graph.gui.StructureToolShapeIcon in project vcell by virtualcell.
the class BioModelEditorModelPanel method newButton2Pressed.
private void newButton2Pressed() throws ModelException, PropertyVetoException {
computeCurrentSelectedTable();
if (currentSelectedTable == reactionsTable) {
if (bioModel.getModel().getRbmModelContainer().getMolecularTypeList().isEmpty()) {
PopupGenerator.showInfoDialog(this, VCellErrorMessages.MustBeRuleBased);
return;
}
if (bioModel.getModel().getNumStructures() == 1) {
Structure s = bioModel.getModel().getStructure(0);
newObject = makeReactionRule(s);
if (newObject != null) {
for (int i = 0; i < currentSelectedTableModel.getRowCount(); i++) {
if (currentSelectedTableModel.getValueAt(i) == newObject) {
currentSelectedTable.setRowSelectionInterval(i, i);
break;
}
}
}
} else if (bioModel.getModel().getNumStructures() > 1) {
final JPopupMenu menu = new JPopupMenu("Choose compartment");
for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
Structure s = bioModel.getModel().getStructure(i);
String sName = s.getName();
JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
menuItem.setIcon(new StructureToolShapeIcon(17));
menu.add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
newObject = makeReactionRule(s);
if (newObject != null) {
for (int i = 0; i < currentSelectedTableModel.getRowCount(); i++) {
if (currentSelectedTableModel.getValueAt(i) == newObject) {
currentSelectedTable.setRowSelectionInterval(i, i);
break;
}
}
}
}
});
}
menu.show(newButton2, 0, newButton2.getHeight());
}
}
}
use of cbit.vcell.graph.gui.StructureToolShapeIcon in project vcell by virtualcell.
the class BioModelEditorModelPanel method newButtonPressed.
private void newButtonPressed() throws ModelException, PropertyVetoException {
newObject = null;
computeCurrentSelectedTable();
if (currentSelectedTable == speciesTable) {
if (bioModel.getModel().getNumStructures() == 1) {
newObject = bioModel.getModel().createSpeciesContext(bioModel.getModel().getStructures()[0]);
} else if (bioModel.getModel().getNumStructures() > 1) {
final JPopupMenu menu = new JPopupMenu("Choose compartment");
for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
Structure s = bioModel.getModel().getStructure(i);
String sName = s.getName();
JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
menuItem.setIcon(new StructureToolShapeIcon(17));
menu.add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
newObject = bioModel.getModel().createSpeciesContext(s);
}
});
}
menu.show(newButton, 0, newButton.getHeight());
}
} else if (currentSelectedTable == molecularTypeTable) {
if (bioModel.getModel().getRbmModelContainer() != null) {
MolecularType mt = bioModel.getModel().getRbmModelContainer().createMolecularType();
bioModel.getModel().getRbmModelContainer().addMolecularType(mt, true);
newObject = mt;
}
} else if (currentSelectedTable == observablesTable) {
if (bioModel.getModel().getRbmModelContainer() != null) {
if (bioModel.getModel().getRbmModelContainer().getMolecularTypeList().isEmpty()) {
PopupGenerator.showInfoDialog(this, VCellErrorMessages.MustBeRuleBased);
return;
}
if (bioModel.getModel().getNumStructures() == 1) {
RbmObservable o = bioModel.getModel().getRbmModelContainer().createObservable(RbmObservable.ObservableType.Molecules);
bioModel.getModel().getRbmModelContainer().addObservable(o);
SpeciesPattern sp = new SpeciesPattern();
o.addSpeciesPattern(sp);
newObject = o;
} else if (bioModel.getModel().getNumStructures() > 1) {
final JPopupMenu menu = new JPopupMenu("Choose compartment");
for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
Structure s = bioModel.getModel().getStructure(i);
String sName = s.getName();
JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
menuItem.setIcon(new StructureToolShapeIcon(17));
menu.add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
RbmObservable o = bioModel.getModel().getRbmModelContainer().createObservable(RbmObservable.ObservableType.Molecules, null, s);
o.setStructure(s);
try {
bioModel.getModel().getRbmModelContainer().addObservable(o);
} catch (ModelException | PropertyVetoException e1) {
e1.printStackTrace();
throw new RuntimeException(e1.getMessage(), e1);
}
SpeciesPattern sp = new SpeciesPattern();
o.addSpeciesPattern(sp);
newObject = o;
if (newObject != null) {
for (int i = 0; i < currentSelectedTableModel.getRowCount(); i++) {
if (currentSelectedTableModel.getValueAt(i) == newObject) {
currentSelectedTable.setRowSelectionInterval(i, i);
break;
}
}
}
}
});
}
menu.show(newButton, 0, newButton.getHeight());
}
}
} else if (currentSelectedTable == structuresTable) {
try {
Feature feature = bioModel.getModel().createFeature();
newObject = feature;
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(this, e.getMessage(), e);
}
} else if (currentSelectedTable == reactionsTable) {
if (bioModel.getModel().getNumStructures() == 1) {
SimpleReaction reactionStep = bioModel.getModel().createSimpleReaction(bioModel.getModel().getStructures()[0]);
newObject = reactionStep;
} else {
addNewReaction();
}
}
if (newObject != null) {
for (int i = 0; i < currentSelectedTableModel.getRowCount(); i++) {
if (currentSelectedTableModel.getValueAt(i) == newObject) {
currentSelectedTable.setRowSelectionInterval(i, i);
break;
}
}
}
}
use of cbit.vcell.graph.gui.StructureToolShapeIcon in project vcell by virtualcell.
the class BioModelEditorModelPanel method duplicateButtonPressed.
private void duplicateButtonPressed() {
computeCurrentSelectedTable();
int row = currentSelectedTable.getSelectedRow();
System.out.println("Duplicate Button Pressed for row " + row);
if (currentSelectedTable == reactionsTable) {
ModelProcess mp = reactionTableModel.getValueAt(row);
if (!(mp instanceof ReactionRule)) {
return;
}
ReactionRule oldRule = (ReactionRule) mp;
if (bioModel.getModel().getNumStructures() == 1) {
duplicateReactionRule(oldRule, oldRule.getStructure());
} else if (bioModel.getModel().getNumStructures() > 1) {
final JPopupMenu menu = new JPopupMenu("Choose compartment");
for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
String ourType = oldRule.getStructure().getTypeName();
Structure s = bioModel.getModel().getStructure(i);
String theirType = s.getTypeName();
if (!ourType.equals(theirType)) {
// offer to duplicate only within structures of the same type as the original,
continue;
// otherwise units will be meaningless (surface vs volume)
}
String sName = s.getName();
JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
menuItem.setIcon(new StructureToolShapeIcon(17));
menu.add(menuItem);
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
newObject = duplicateReactionRule(oldRule, s);
// moves selection on the newly created object
// if (newObject != null) {
// for (int i = 0; i < currentSelectedTableModel.getRowCount(); i ++) {
// if (currentSelectedTableModel.getValueAt(i) == newObject) {
// currentSelectedTable.setRowSelectionInterval(i, i);
// break;
// }
// }
// }
}
});
}
menu.show(duplicateButton, 0, duplicateButton.getHeight());
}
} else if (currentSelectedTable == speciesTable) {
SpeciesContext sc = speciesTableModel.getValueAt(row);
if (!sc.hasSpeciesPattern()) {
return;
}
if (bioModel.getModel().getNumStructures() == 1) {
duplicateSpecies(sc, sc.getStructure(), bioModel.getModel());
} else if (bioModel.getModel().getNumStructures() > 1) {
final JPopupMenu menu = new JPopupMenu("Choose compartment");
for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
String ourType = sc.getStructure().getTypeName();
Structure s = bioModel.getModel().getStructure(i);
String theirType = s.getTypeName();
if (!ourType.equals(theirType)) {
continue;
}
String sName = s.getName();
JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
menuItem.setIcon(new StructureToolShapeIcon(17));
menu.add(menuItem);
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
newObject = duplicateSpecies(sc, s, bioModel.getModel());
}
});
}
menu.show(duplicateButton, 0, duplicateButton.getHeight());
}
} else if (currentSelectedTable == observablesTable) {
RbmObservable o = observableTableModel.getValueAt(row);
if (o.getSpeciesPatternList().isEmpty()) {
return;
}
if (bioModel.getModel().getNumStructures() == 1) {
duplicateObservable(o, o.getStructure(), bioModel.getModel());
} else if (bioModel.getModel().getNumStructures() > 1) {
final JPopupMenu menu = new JPopupMenu("Choose compartment");
for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
Structure s = bioModel.getModel().getStructure(i);
String sName = s.getName();
JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
menuItem.setIcon(new StructureToolShapeIcon(17));
menu.add(menuItem);
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
newObject = duplicateObservable(o, s, bioModel.getModel());
}
});
}
menu.show(duplicateButton, 0, duplicateButton.getHeight());
}
}
}
Aggregations