Skip to content

Commit

Permalink
Merge pull request #1123 from virtualcell/dan-ss-molecule-edit2
Browse files Browse the repository at this point in the history
Springsalad UI and math parser improvements and bug fixing
  • Loading branch information
danv61 authored Feb 1, 2024
2 parents 9106c95 + 95a4b65 commit 578ac79
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class MolecularStructuresPanel extends DocumentEditorSubPanel implements

private JTextField linkLengthField = null;
private JButton addLinkButton = null;

private JButton deleteLinkButton = null;
//
// TODO: make it possible to use right click menu to delete links
//
Expand Down Expand Up @@ -123,6 +123,9 @@ public void actionPerformed(ActionEvent e) {
} else if(source == addLinkButton) {
addLinkActionPerformed();
refreshSiteLinksList();
} else if(source == deleteLinkButton) {
deleteLinkActionPerformed();
refreshSiteLinksList();
} else if(source == getSiteColorComboBox()) {
updateSiteColor();
}
Expand Down Expand Up @@ -203,6 +206,7 @@ private void initConnections() throws java.lang.Exception { // listeners here!

linkLengthField.addActionListener(eventHandler);
addLinkButton.addActionListener(eventHandler);
deleteLinkButton.addActionListener(eventHandler);

getSiteColorComboBox().addActionListener(eventHandler);

Expand Down Expand Up @@ -231,10 +235,12 @@ private void initialize() {
siteLinksList.setCellRenderer(siteLinksCellRenderer);
linkLengthField = new JTextField("");
addLinkButton = new JButton("Add Link");
deleteLinkButton = new JButton("Delete Link");
siteXField.setEditable(false);
siteYField.setEditable(false);
siteZField.setEditable(false);
linkLengthField.setEditable(false);
deleteLinkButton.setEnabled(false);

// ------------------------------------------- The 2 group boxes --------------------------
JPanel thePanel = new JPanel();
Expand Down Expand Up @@ -585,7 +591,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
gbc.gridwidth = 3;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
Expand All @@ -603,6 +609,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
gbc.gridx = 1;
gbc.gridy = 1;
gbc.weightx = 1.0;
gbc.gridwidth = 2;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 2, 2, 3); // top, left, bottom, right
linksPanel.add(linkLengthField, gbc);
Expand All @@ -613,7 +620,14 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 2, 2, 3);
linksPanel.add(addLinkButton, gbc);


gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 2;
// gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 2, 2, 3);
linksPanel.add(deleteLinkButton, gbc);

getMolecularTypeSpecsTable().setDefaultRenderer(String.class, new DefaultScrollTableCellRenderer());
getMolecularTypeSpecsTable().setDefaultRenderer(Structure.class, structuresTableCellRenderer); // The Structures combobox cell renderer

Expand Down Expand Up @@ -768,6 +782,12 @@ private void updateInterface() {
addLinkButton.setEnabled(false);
refreshSiteLinksList();
}
if(!siteLinksListModel.isEmpty() && siteLinksList.getSelectedValue() != null) { // there are links we can delete
deleteLinkButton.setEnabled(true);
} else {
deleteLinkButton.setEnabled(false);
}

if(bNonNullMolecularComponentPattern) {
SiteAttributesSpec sas = fieldSpeciesContextSpec.getSiteAttributesMap().get(fieldMolecularComponentPattern);
siteXField.setEditable(true);
Expand Down Expand Up @@ -875,22 +895,30 @@ private void addLinkActionPerformed() {
fieldSpeciesContextSpec.getInternalLinkSet().add(mils);
return;
} else {

return;
}
}

private void deleteLinkActionPerformed() {

MolecularInternalLinkSpec selectedValue = siteLinksList.getSelectedValue();
if(selectedValue != null) {
fieldSpeciesContextSpec.getInternalLinkSet().remove(selectedValue);
}
return;
}

private void showLinkLength(MolecularInternalLinkSpec selectedValue) {
if(selectedValue == null) {
System.out.println("showLinkLength: SelectedValue is null");
deleteLinkButton.setEnabled(false);
linkLengthField.setEditable(false);
linkLengthField.setText(null);
return; // nothing selected
}
System.out.println("showLinkLength(): Selected row is '" + siteLinksList.getSelectedIndex() + "'");
deleteLinkButton.setEnabled(true);
linkLengthField.setEditable(false); // make it editable here, for now it's a derived value only
linkLengthField.setText(selectedValue.getLinkLength()+"");
};

}

Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void read(CommentStringTokenizer tokens) throws MathFormatException {
if(token.equalsIgnoreCase(VCML.Is2D)) {
token = tokens.nextToken();
setIs2D(Boolean.getBoolean(token));
continue;
}
if (token.equalsIgnoreCase(VCML.Links)) {
token = tokens.nextToken();
Expand Down

0 comments on commit 578ac79

Please sign in to comment.