Skip to content

Commit

Permalink
Merge pull request #1391 from virtualcell/dan-ss-links
Browse files Browse the repository at this point in the history
Links are now editable
  • Loading branch information
danv61 authored Nov 22, 2024
2 parents adce77c + ecfc7f7 commit 048f6a6
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import cbit.vcell.model.Structure;
import cbit.vcell.parser.Expression;
import org.vcell.model.rbm.*;
import org.vcell.util.Coordinate;
import org.vcell.util.gui.GuiUtils;
import org.vcell.util.gui.ScrollTable;
import org.vcell.util.springsalad.NamedColor;

import javax.swing.*;
import java.beans.PropertyChangeEvent;
import java.util.*;

Expand Down Expand Up @@ -86,13 +88,40 @@ public Object getValueAt(int row, int col) {
@Override
public void setValueAt(Object aValue, int row, int col) {
MolecularInternalLinkSpec mils = getValueAt(row);
if(mils == null) {
return;
}
ColumnType columnType = columns.get(col);
switch (columnType) {
case COLUMN_LINK:
SpeciesContextSpec scs = getSpeciesContextSpec();

MolecularComponentPattern mcpOne = mils.getMolecularComponentPatternOne();
MolecularComponentPattern mcpTwo = mils. getMolecularComponentPatternTwo();
SiteAttributesSpec sasOne = mils. getSite1();
SiteAttributesSpec sasTwo = mils. getSite2();

switch (columnType) {
case COLUMN_LINK: // not editable
return;
case COLUMN_LENGTH:

if (aValue instanceof String newExpressionString) {
double res = 0.0;
try {
res = Double.parseDouble(newExpressionString);
} catch(NumberFormatException ex) {
JOptionPane.showMessageDialog(null, "Number expected", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
// the link is a derived value, we don't store it - we just show it in the table
// instead, we adjust the x, y, z of the molecules involved
double[] unitVector = mils.unitVector();
double newX = sasOne.getX() + res*unitVector[0];
double newY = sasOne.getY() + res*unitVector[1];
double newZ = sasOne.getZ() + res*unitVector[2];
Coordinate coord = new Coordinate (newX, newY, newZ);
sasTwo.setCoordinate(coord);
refreshData();
scs.firePropertyChange(SpeciesContextSpec.PROPERTY_NAME_LINK_LENGTH, null, mils);
}
return;
default:
return;
Expand All @@ -103,8 +132,9 @@ public boolean isCellEditable(int row, int col) {
ColumnType columnType = columns.get(col);
switch (columnType) {
case COLUMN_LINK:
case COLUMN_LENGTH:
return false;
case COLUMN_LENGTH:
return true;
default:
return false;
}
Expand All @@ -131,9 +161,6 @@ public int compare(MolecularInternalLinkSpec mils1, MolecularInternalLinkSpec mi
};
}




public void setSimulationContext(SimulationContext simulationContext) {
SimulationContext oldValue = fieldSimulationContext;
int oldColumnCount = getColumnCount();
Expand Down Expand Up @@ -259,8 +286,6 @@ public void propertyChange(PropertyChangeEvent evt) {
refreshColumns();
fireTableStructureChanged();
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
import java.util.List;

import javax.swing.JTable;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;

import cbit.vcell.graph.GraphConstants;
import cbit.vcell.parser.Expression;
import org.vcell.model.rbm.SpeciesPattern;
import org.vcell.util.gui.DefaultScrollTableCellRenderer;
import org.vcell.util.gui.sorttable.JSortTable;
Expand All @@ -38,6 +41,9 @@
import cbit.vcell.model.ReactantPattern;
import cbit.vcell.model.ReactionRule;
import cbit.vcell.model.ReactionStep;
import org.vcell.util.springsalad.NamedColor;

import static cbit.vcell.mapping.gui.ModelProcessSpecsTableModel.ColumnType.COLUMN_BOND_LENGTH;

/**
* Insert the type's description here.
Expand Down Expand Up @@ -294,10 +300,53 @@ public void paintComponent(Graphics g) {
}
}
};



// The Expression cell renderer in the ModelProcessSpecsTable
DefaultScrollTableCellRenderer expressionTableCellRenderer = new DefaultScrollTableCellRenderer() {
String darkRed = NamedColor.getHex(GraphConstants.darkred); // "#8B0000"
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof ModelProcessSpecsTableModel) {
if (value instanceof Double) {
TableColumn tc = table.getColumnModel().getColumn(column);
Object headerValue = tc.getHeaderValue();
if(!(headerValue instanceof String)) {
throw new RuntimeException("Expecting HeaderValue to be a String");
}
/*
* This is the correct way to recover the column type - using the label!!!
* Because the index may be wrong if some columns have been removed or relocated
*/
ModelProcessSpecsTableModel.ColumnType columnType = ModelProcessSpecsTableModel.ColumnType.fromLabel((String) headerValue);
int cellWidth = table.getColumnModel().getColumn(column).getWidth();
switch (columnType) {
case COLUMN_BOND_LENGTH:
if(cellWidth > 70) {
if(!isSelected) {
String text = "<html>" + value + "<span style='color:" + darkRed + ";'> [nm]</span></html>";
setText(text);
} else {
setText(value + " [nm]");
}
} else {
setText(value + ""); // if it's too busy, just show the numbers
}
setToolTipText(value + " [nm]"); // we always show the units in the tooltip
break;
default:
break;
}
}
}
return this;
}
};

getScrollPaneTable().setDefaultRenderer(SpeciesPattern.class, rbmReactionShapeDepictionCellRenderer);

getScrollPaneTable().setDefaultRenderer(Expression.class, expressionTableCellRenderer); // Expression field cell renderer

// ivjScrollPaneTable.getColumnModel().getColumn(ModelProcessSpecsTableModel.ColumnType.COLUMN_DEPICTION.ordinal()).setCellRenderer(rbmReactionShapeDepictionCellRenderer);
// ivjScrollPaneTable.getColumnModel().getColumn(ModelProcessSpecsTableModel.ColumnType.COLUMN_DEPICTION.ordinal()).setPreferredWidth(180);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,28 @@ public enum ColumnType {
COLUMN_NAME("Name"),
COLUMN_DEPICTION("Depiction"),
COLUMN_TYPE("Type"),
COLUMN_SUBTYPE("Subtype"),
COLUMN_CONDITION("Condition"),
COLUMN_ENABLED("Enabled"),
COLUMN_FAST("Fast"),
COLUMN_SUBTYPE("Subtype"),
COLUMN_CONDITION("Condition"),
COLUMN_BOND_LENGTH("Bond Length");

public final String label;
private ColumnType(String label){
private ColumnType(String label) {
this.label = label;
}

public static ColumnType fromLabel(String label) {
for (ColumnType value : ColumnType.values()) {
if (value.label.equals(label)) {
return value;
}
}
throw new IllegalArgumentException("No enum constant with label " + label);
}
}
ArrayList<ColumnType> columns = new ArrayList<ColumnType>();

ArrayList<ColumnType> columns = new ArrayList<ColumnType>();
private SimulationContext fieldSimulationContext = null;

/**
Expand Down Expand Up @@ -92,10 +101,10 @@ private void refreshColumns(){
columns.remove(ColumnType.COLUMN_FAST);
}
if(getSimulationContext().getApplicationType() == Application.SPRINGSALAD) {
columns.add(ColumnType.COLUMN_BOND_LENGTH);
columns.remove(ColumnType.COLUMN_FAST);
columns.add(ColumnType.COLUMN_SUBTYPE);
columns.add(ColumnType.COLUMN_CONDITION);
columns.remove(ColumnType.COLUMN_FAST);
columns.add(ColumnType.COLUMN_BOND_LENGTH);
}
}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public void actionPerformed(java.awt.event.ActionEvent e) {
public void propertyChange(PropertyChangeEvent evt) {
if(evt.getSource() instanceof SpeciesContextSpec && evt.getPropertyName().equals(SpeciesContextSpec.PROPERTY_NAME_SITE_ATTRIBUTE)) {
updateShape();
} else if(evt.getSource() instanceof SpeciesContextSpec && evt.getPropertyName().equals(SpeciesContextSpec.PROPERTY_NAME_LINK_LENGTH)) {
updateShape();
}
}
}
Expand Down
Loading

0 comments on commit 048f6a6

Please sign in to comment.