Skip to content

Commit

Permalink
Manage tricky selection for LangevinSpeciesContext step class, stub f…
Browse files Browse the repository at this point in the history
…or Molecular structures properties panel
  • Loading branch information
danv61 committed Oct 3, 2024
1 parent 00c216b commit e294a61
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.swing.ListSelectionModel;

import cbit.vcell.mapping.*;
import cbit.vcell.mapping.gui.*;
import org.vcell.model.rbm.MolecularType;
import org.vcell.model.rbm.SpeciesPattern;
import org.vcell.pathway.BioPaxObject;
Expand Down Expand Up @@ -60,11 +61,6 @@
import cbit.vcell.mapping.SimulationContext.Application;
import cbit.vcell.mapping.SimulationContext.MathMappingCallback;
import cbit.vcell.mapping.SimulationContext.NetworkGenerationRequirements;
import cbit.vcell.mapping.gui.DataSymbolsSpecPanel;
import cbit.vcell.mapping.gui.ReactionRuleSpecPropertiesPanel;
import cbit.vcell.mapping.gui.SpatialObjectPropertyPanel;
import cbit.vcell.mapping.gui.SpatialProcessPropertyPanel;
import cbit.vcell.mapping.gui.SpeciesContextSpecPanel;
import cbit.vcell.mapping.spatial.SpatialObject;
import cbit.vcell.mapping.spatial.processes.SpatialProcess;
import cbit.vcell.model.Model;
Expand Down Expand Up @@ -127,6 +123,7 @@ public class BioModelEditor extends DocumentEditor {
private ReactionParticipantPropertiesPanel reactionParticipantPropertiesPanel = null;
private ApplicationPropertiesPanel applicationPropertiesPanel = null;
private SpeciesContextSpecPanel speciesContextSpecPanel = null;
private MolecularStructuresPropertiesPanel molecularStructuresPropertiesPanel = null;
private KineticsTypeTemplatePanel kineticsTypeTemplatePanel = null;
private ReactionRuleSpecPropertiesPanel reactionRuleSpecPropertiesPanel = null;
private SimulationSummaryPanel simulationSummaryPanel = null;
Expand Down Expand Up @@ -626,6 +623,17 @@ private SpeciesContextSpecPanel getSpeciesContextSpecPanel() {
}
return speciesContextSpecPanel;
}
private MolecularStructuresPropertiesPanel getMolecularStructuresPropertiesPanel() {
if (molecularStructuresPropertiesPanel == null) {
try {
molecularStructuresPropertiesPanel = new MolecularStructuresPropertiesPanel();
molecularStructuresPropertiesPanel.setName("MolecularStructuresPropertiesPanel");
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
return molecularStructuresPropertiesPanel;
}

private void initialize() {
try {
Expand Down Expand Up @@ -676,6 +684,7 @@ private void initialize() {
getReactionRulePropertiesPanel().setSelectionManager(selectionManager);
getReactionPropertiesPanel().setSelectionManager(selectionManager);
getSpeciesContextSpecPanel().setSelectionManager(selectionManager);
getMolecularStructuresPropertiesPanel().setSelectionManager(selectionManager);
getReactionRuleSpecPropertiesPanel().setSelectionManager(selectionManager);
getSpatialObjectPropertyPanel().setSelectionManager(selectionManager);
getSpatialProcessPropertyPanel().setSelectionManager(selectionManager);
Expand Down Expand Up @@ -764,7 +773,7 @@ protected void setRightBottomPanelOnSelection(Object[] selections) {
bShowInDatabaseProperties = true;
bottomComponent = geometryMetaDataPanel;
} else if (singleSelection instanceof LangevinSpeciesContextSpec) {
bottomComponent = getSpeciesContextSpecPanel();
bottomComponent = getMolecularStructuresPropertiesPanel();
} else if (singleSelection instanceof SpeciesContextSpec) {
bottomComponent = getSpeciesContextSpecPanel();
} else if (singleSelection instanceof ReactionSpec) {
Expand Down Expand Up @@ -1012,6 +1021,7 @@ public void setBioModel(BioModel bioModel) {
bioModelEditorModelPanel.setBioModel(bioModel);
getBioModelEditorApplicationsPanel().setBioModel(bioModel);
getSpeciesContextSpecPanel().setBioModel(bioModel);
getMolecularStructuresPropertiesPanel().setBioModel(bioModel);
getReactionRuleSpecPropertiesPanel().setBioModel(bioModel);
getScriptingPanel().setBioModel(bioModel);
getBioModelEditorPathwayPanel().setBioModel(bioModel);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package cbit.vcell.graph.gui;

import javax.swing.*;

public class SsldLargeShapePanel extends JPanel {

// private boolean showDifferencesOnly = false;
// private boolean bShowMoleculeColor = false;
// private boolean bShowNonTrivialOnly = false;


// zooming the shape, 0 means normal size, a negative number means smaller shape
private static final int SmallestZoomFactor = -7; // -7 is the smallest where the shapes scale decently well
private static final int DefaultZoomFactor = 0;
private static final int LargestZoomFactor = 0;
private int zoomFactor = DefaultZoomFactor;

// by default the shapes are editable and their border and text is black / gray, aso
// otherwise they are a shade of brown, very much alike the DefaultScrollTableCellRenderer.uneditableForeground
private boolean editable = true;



// public void setShowMoleculeColor(boolean bShowMoleculeColor) {
// this.bShowMoleculeColor = bShowMoleculeColor;
// }
// public void setShowNonTrivialOnly(boolean bShowNonTrivialOnly) {
// this.bShowNonTrivialOnly = bShowNonTrivialOnly;
// }


public boolean zoomLarger() { // returns false when upper limit was reached
zoomFactor++;
if(zoomFactor >= LargestZoomFactor) {
zoomFactor = LargestZoomFactor;
System.out.println("MAX. Factor is " + zoomFactor);
return false;
} else {
System.out.println("Up. Factor is " + zoomFactor);
return true;
}
}
public void setZoomFactor(int newZoomFactor) {
if(newZoomFactor > LargestZoomFactor || newZoomFactor < SmallestZoomFactor) {
throw new RuntimeException("Large Shape Panel zoom factor is out of bounds");
}
zoomFactor = newZoomFactor;
}
public boolean zoomSmaller() { // returns false when lower limit was reached
zoomFactor--;
if(zoomFactor <= SmallestZoomFactor) {
zoomFactor = SmallestZoomFactor;
System.out.println("MIN. Factor is " + zoomFactor);
return false;
} else {
System.out.println("Down. Factor is " + zoomFactor);
return true;
}
}
public boolean isLargestZoomFactor() {
return zoomFactor >= LargestZoomFactor ? true : false;
}
public boolean isSmallestZoomFactor() {
return zoomFactor <= SmallestZoomFactor ? true : false;
}
public int getZoomFactor() {
return zoomFactor;
}

public void setEditable(boolean editable) {
this.editable = editable;
}
public boolean isEditable() {
return editable;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
package cbit.vcell.mapping.gui;

import cbit.vcell.biomodel.BioModel;
import cbit.vcell.client.desktop.biomodel.DocumentEditorSubPanel;
import cbit.vcell.graph.PointLocationInShapeContext;
import cbit.vcell.graph.SpeciesPatternLargeShape;
import cbit.vcell.graph.gui.LargeShapePanel;
import cbit.vcell.graph.gui.SsldLargeShapePanel;
import cbit.vcell.graph.gui.ZoomShapeIcon;
import cbit.vcell.mapping.LangevinSpeciesContextSpec;
import cbit.vcell.mapping.SpeciesContextSpec;
import cbit.vcell.model.Model;
import cbit.vcell.model.SpeciesContext;
import cbit.vcell.parser.ExpressionException;
import org.vcell.model.rbm.SpeciesPattern;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

public class MolecularStructuresPropertiesPanel extends DocumentEditorSubPanel {

private BioModel bioModel = null;
private SpeciesContext speciesContext = null;
private EventHandler eventHandler = new EventHandler();

private JScrollPane scrollPane; // shapePanel lives inside this
private SpeciesPatternLargeShape spls; // make the real thing
private SsldLargeShapePanel shapePanel = null;


private JButton zoomLargerButton = null;
private JButton zoomSmallerButton = null;


private class EventHandler implements ActionListener {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (e.getSource() == getZoomLargerButton()) {
boolean ret = shapePanel.zoomLarger();
getZoomLargerButton().setEnabled(ret);
getZoomSmallerButton().setEnabled(true);
updateShape();
} else if (e.getSource() == getZoomSmallerButton()) {
boolean ret = shapePanel.zoomSmaller();
getZoomLargerButton().setEnabled(true);
getZoomSmallerButton().setEnabled(ret);
updateShape();
}
}
}


public MolecularStructuresPropertiesPanel() {
super();
initialize();
}

private void handleException(Throwable exception) {
/* Uncomment the following lines to print uncaught exceptions to stdout */
if (exception instanceof ExpressionException){
javax.swing.JOptionPane.showMessageDialog(this, exception.getMessage(), "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
}
System.out.println("--------- UNCAUGHT EXCEPTION --------- in SpeciesContextSpecPanel");
exception.printStackTrace(System.out);
}

private void initialize() {
try {
shapePanel = new SsldLargeShapePanel() { // glyph (shape) panel
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (spls != null) {
spls.paintSelf(g);
}
}


};
shapePanel.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
Point overWhat = e.getPoint();
PointLocationInShapeContext locationContext = new PointLocationInShapeContext(overWhat);
spls.contains(locationContext);
shapePanel.setToolTipText("View-Only panel");
}
});
shapePanel.setBackground(new Color(0xe0e0e0));
shapePanel.setZoomFactor(-2);
shapePanel.setEditable(false);

scrollPane = new JScrollPane(shapePanel);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

// -----------------------------------------------------------------------------------------

JPanel optionsPanel = new JPanel(); // ------- left panel with zoom buttons
optionsPanel.setLayout(new GridBagLayout());

getZoomSmallerButton().setEnabled(true);
getZoomLargerButton().setEnabled(true);

GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(4,4,0,10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanel.add(getZoomLargerButton(), gbc);

gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.insets = new Insets(4,4,4,10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanel.add(getZoomSmallerButton(), gbc);

gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 2;
gbc.weightx = 1;
gbc.weighty = 1; // fake cell used for filling all the vertical empty space
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(4, 4, 4, 10);
optionsPanel.add(new JLabel(""), gbc);


// ------------------------------------------------------------------------------------------
JPanel containerOfScrollPanel = new JPanel();
containerOfScrollPanel.setLayout(new BorderLayout());
containerOfScrollPanel.add(optionsPanel, BorderLayout.WEST);
containerOfScrollPanel.add(scrollPane, BorderLayout.CENTER);

setLayout(new BorderLayout());
add(containerOfScrollPanel, BorderLayout.CENTER);
setBackground(Color.white);
setName("MolecularStructuresPropertiesPanel");



} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}

private void updateInterface() {
if(speciesContext == null) {
return;
}
updateShape();
}

public static final int xOffsetInitial = 20;
public static final int yOffsetInitial = 10;
private void updateShape() {
if(speciesContext == null) {
return;
}
SpeciesPattern sp = speciesContext.getSpeciesPattern();
// spls = new SpeciesPatternLargeShape(xOffsetInitial, yOffsetInitial, -1, sp, shapePanel, speciesContext, issueManager);
//
// Dimension preferredSize = new Dimension(spls.getRightEnd()+40, yOffsetInitial+80);
// shapePanel.setPreferredSize(preferredSize);
// shapePanel.repaint();
}

public void setSpeciesContextSpec(SpeciesContextSpec scSpec) {
if(scSpec == null) {
this.speciesContext = null;
} else {
this.speciesContext = scSpec.getSpeciesContext();
}
// getSpeciesContextSpecParameterTableModel().setSpeciesContextSpec(scSpec);
updateInterface();
}
public void setBioModel(BioModel newValue) {
if (bioModel == newValue) {
return;
}
bioModel = newValue;
if(bioModel == null) {
return;
}
Model model = bioModel.getModel();
if(model != null & model.getRbmModelContainer().getMolecularTypeList().size() > 0) {
// splitPaneHorizontal.setDividerLocation(165);
} else {
// since we have no molecular types we initialize a much smaller shape panel
// because we can only show a trivial shape (circle)
// splitPaneHorizontal.setDividerLocation(195);
}
}


@Override
protected void onSelectedObjectsChange(Object[] selectedObjects) {
SpeciesContextSpec speciesContextSpec = null;
if (selectedObjects != null && selectedObjects.length == 1 && selectedObjects[0] instanceof LangevinSpeciesContextSpec) {
LangevinSpeciesContextSpec lscs = (LangevinSpeciesContextSpec)selectedObjects[0];
speciesContextSpec = lscs.getTheSpeciesContextSpec();
}
setSpeciesContextSpec(speciesContextSpec);

}

private JButton getZoomLargerButton() {
if (zoomLargerButton == null) {
zoomLargerButton = new JButton(); // "+"
// ResizeCanvasShape.setCanvasNormalMod(zoomLargerButton, ResizeCanvasShape.Sign.expand);
ZoomShapeIcon.setZoomMod(zoomLargerButton, ZoomShapeIcon.Sign.plus);
zoomLargerButton.addActionListener(eventHandler);
}
return zoomLargerButton;
}
private JButton getZoomSmallerButton() {
if (zoomSmallerButton == null) {
zoomSmallerButton = new JButton(); // -
// ResizeCanvasShape.setCanvasNormalMod(zoomSmallerButton, ResizeCanvasShape.Sign.shrink);
ZoomShapeIcon.setZoomMod(zoomSmallerButton, ZoomShapeIcon.Sign.minus);
zoomSmallerButton.addActionListener(eventHandler);
}
return zoomSmallerButton;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

import cbit.vcell.mapping.LangevinSpeciesContextSpec;
import org.vcell.model.rbm.MolecularComponentPattern;
import org.vcell.model.rbm.MolecularTypePattern;
import org.vcell.model.rbm.SpeciesPattern;
Expand Down Expand Up @@ -307,7 +308,8 @@ public void setBioModel(BioModel newValue) {
@Override
protected void onSelectedObjectsChange(Object[] selectedObjects) {
SpeciesContextSpec speciesContextSpec = null;
if (selectedObjects != null && selectedObjects.length == 1 && selectedObjects[0] instanceof SpeciesContextSpec) {
if (selectedObjects != null && selectedObjects.length == 1 && selectedObjects[0] instanceof SpeciesContextSpec
&& !(selectedObjects[0] instanceof LangevinSpeciesContextSpec)) {
speciesContextSpec = (SpeciesContextSpec) selectedObjects[0];
}
setSpeciesContextSpec(speciesContextSpec);
Expand Down
Loading

0 comments on commit e294a61

Please sign in to comment.