|
| 1 | +package cbit.vcell.solver.ode.gui; |
| 2 | + |
| 3 | +import cbit.vcell.client.data.ODEDataViewer; |
| 4 | +import cbit.vcell.client.desktop.biomodel.DocumentEditorSubPanel; |
| 5 | +import cbit.vcell.simdata.LangevinSolverResultSet; |
| 6 | +import cbit.vcell.solver.SimulationModelInfo; |
| 7 | +import cbit.vcell.solver.ode.ODESolverResultSet; |
| 8 | +import cbit.vcell.util.ColumnDescription; |
| 9 | +import org.vcell.util.gui.CollapsiblePanel; |
| 10 | + |
| 11 | +import javax.swing.*; |
| 12 | +import javax.swing.border.EmptyBorder; |
| 13 | +import javax.swing.event.ChangeEvent; |
| 14 | +import javax.swing.event.ChangeListener; |
| 15 | +import javax.swing.event.ListSelectionEvent; |
| 16 | +import javax.swing.event.ListSelectionListener; |
| 17 | +import java.awt.*; |
| 18 | +import java.awt.event.ActionEvent; |
| 19 | +import java.awt.event.ActionListener; |
| 20 | +import java.beans.PropertyChangeEvent; |
| 21 | +import java.beans.PropertyChangeListener; |
| 22 | + |
| 23 | +public class ClusterSpecificationPanel extends DocumentEditorSubPanel { |
| 24 | + |
| 25 | + private final ODEDataViewer owner; |
| 26 | + ClusterSpecificationPanel.IvjEventHandler ivjEventHandler = new ClusterSpecificationPanel.IvjEventHandler(); |
| 27 | + |
| 28 | + private DefaultListModel defaultListModelY = null; |
| 29 | + |
| 30 | + private CollapsiblePanel displayOptionsCollapsiblePanel = null; |
| 31 | + private JScrollPane jScrollPaneYAxis = null; |
| 32 | + private JList yAxisChoiceList = null; |
| 33 | + |
| 34 | + |
| 35 | + private enum DisplayMode { COUNTS, MEAN, OVERALL }; |
| 36 | + LangevinSolverResultSet langevinSolverResultSet = null; |
| 37 | + SimulationModelInfo simulationModelInfo = null; |
| 38 | + |
| 39 | + |
| 40 | + class IvjEventHandler implements ActionListener, PropertyChangeListener, ChangeListener, ListSelectionListener { |
| 41 | + @Override |
| 42 | + public void actionPerformed(ActionEvent e) { |
| 43 | + System.out.println("ClusterSpecificationPanel.IvjEventHandler.actionPerformed() called"); |
| 44 | + System.out.println(" Source: " + e.getSource() + ", Action Command: " + e.getActionCommand()); |
| 45 | + Object source = e.getSource(); |
| 46 | + String cmd = e.getActionCommand(); |
| 47 | + |
| 48 | + if (source instanceof JRadioButton) { |
| 49 | + JRadioButton rb = (JRadioButton) source; |
| 50 | + System.out.println(" Source is JRadioButton with text: " + rb.getText()); |
| 51 | + switch (cmd) { |
| 52 | + case "COUNTS": |
| 53 | + populateYAxisChoices(DisplayMode.COUNTS); |
| 54 | + break; |
| 55 | + case "MEAN": |
| 56 | + populateYAxisChoices(DisplayMode.MEAN); |
| 57 | + break; |
| 58 | + case "OVERALL": |
| 59 | + populateYAxisChoices(DisplayMode.OVERALL); |
| 60 | + break; |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + @Override |
| 65 | + public void propertyChange(PropertyChangeEvent evt) { |
| 66 | + System.out.println("ClusterSpecificationPanel.IvjEventHandler.propertyChange() called"); |
| 67 | + System.out.println(" Source: " + evt.getSource() + ", Property Name: " + evt.getPropertyName() + ", Old Value: " + evt.getOldValue() + ", New Value: " + evt.getNewValue()); |
| 68 | + } |
| 69 | + @Override |
| 70 | + public void stateChanged(ChangeEvent e) { |
| 71 | + System.out.println("ClusterSpecificationPanel.IvjEventHandler.stateChanged() called"); |
| 72 | + System.out.println(" Source: " + e.getSource() + ", Class: " + e.getSource().getClass().getName()); |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public void valueChanged(ListSelectionEvent e) { |
| 77 | + System.out.println("ClusterSpecificationPanel.IvjEventHandler.valueChanged() called"); |
| 78 | + System.out.println(" Source: " + e.getSource() + ", Class: " + e.getSource().getClass().getName()); |
| 79 | + Object source = e.getSource(); |
| 80 | + |
| 81 | + } |
| 82 | + }; |
| 83 | + |
| 84 | + private void populateYAxisChoices(DisplayMode mode) { |
| 85 | + DefaultListModel model = getDefaultListModelY(); |
| 86 | + model.clear(); |
| 87 | + getYAxisChoice().setEnabled(false); |
| 88 | + |
| 89 | + ODESolverResultSet srs = null; |
| 90 | + ColumnDescription[] cd = null; |
| 91 | + |
| 92 | + if (langevinSolverResultSet == null) { |
| 93 | + model.addElement("<no data>"); |
| 94 | + return; |
| 95 | + } |
| 96 | + switch (mode) { |
| 97 | + case COUNTS: |
| 98 | + // we may never get non-trivial clusters if there's no binding reaction |
| 99 | + srs = langevinSolverResultSet.getClusterCounts(); |
| 100 | + cd = srs.getColumnDescriptions(); |
| 101 | + break; |
| 102 | + case MEAN: |
| 103 | + srs = langevinSolverResultSet.getClusterMean(); |
| 104 | + cd = srs.getColumnDescriptions(); |
| 105 | + break; |
| 106 | + case OVERALL: |
| 107 | + srs = langevinSolverResultSet.getClusterOverall(); |
| 108 | + cd = srs.getColumnDescriptions(); |
| 109 | + break; |
| 110 | + } |
| 111 | + if(cd == null || cd.length == 1) { |
| 112 | + model.addElement("<no data>"); // if only "t" column is present, treat as no data |
| 113 | + return; |
| 114 | + } |
| 115 | + for (ColumnDescription columnDescription : cd) { |
| 116 | + if(columnDescription.getName().equals("t")) { |
| 117 | + continue; // skip time column |
| 118 | + } |
| 119 | + model.addElement(columnDescription.getName()); |
| 120 | + getYAxisChoice().setEnabled(true); |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + public ClusterSpecificationPanel(ODEDataViewer odeDataViewer) { |
| 125 | + super(); |
| 126 | + this.owner = odeDataViewer; |
| 127 | + initialize(); |
| 128 | + } |
| 129 | + |
| 130 | + private void initialize() { |
| 131 | + System.out.println("ClusterSpecificationPanel.initialize() called"); |
| 132 | + setPreferredSize(new Dimension(213, 600)); |
| 133 | + setLayout(new GridBagLayout()); |
| 134 | + setSize(248, 604); |
| 135 | + setMinimumSize(new Dimension(125, 300)); |
| 136 | + |
| 137 | + JLabel xAxisLabel = new JLabel("X Axis:"); |
| 138 | + GridBagConstraints gbc = new GridBagConstraints(); |
| 139 | + gbc.anchor = GridBagConstraints.WEST; |
| 140 | + gbc.gridx = 0; gbc.gridy = 0; |
| 141 | + gbc.insets = new Insets(4, 4, 0, 4); |
| 142 | + add(xAxisLabel, gbc); |
| 143 | + |
| 144 | + JTextField xAxisTextBox = new JTextField("t"); |
| 145 | + xAxisTextBox.setEnabled(false); |
| 146 | + xAxisTextBox.setEditable(false); |
| 147 | + gbc = new GridBagConstraints(); |
| 148 | + gbc.gridx = 0; gbc.gridy = 1; |
| 149 | + gbc.fill = GridBagConstraints.HORIZONTAL; |
| 150 | + gbc.weightx = 1.0; |
| 151 | + gbc.insets = new Insets(0, 4, 4, 4); |
| 152 | + add(xAxisTextBox, gbc); |
| 153 | + |
| 154 | + JLabel yAxisLabel = new JLabel("Y Axis:"); |
| 155 | + gbc = new GridBagConstraints(); |
| 156 | + gbc.anchor = GridBagConstraints.WEST; |
| 157 | + gbc.insets = new Insets(4, 4, 0, 4); |
| 158 | + gbc.gridx = 0; gbc.gridy = 2; |
| 159 | + add(yAxisLabel, gbc); |
| 160 | + |
| 161 | + gbc = new GridBagConstraints(); |
| 162 | + gbc.fill = GridBagConstraints.BOTH; |
| 163 | + gbc.insets = new Insets(4, 4, 5, 4); |
| 164 | + gbc.gridx = 0; |
| 165 | + gbc.gridy = 3; |
| 166 | + add(getDisplayOptionsPanel(), gbc); |
| 167 | + |
| 168 | + gbc = new GridBagConstraints(); |
| 169 | + gbc.gridx = 0; gbc.gridy = 4; |
| 170 | + gbc.fill = GridBagConstraints.BOTH; |
| 171 | + gbc.weightx = 1.0; |
| 172 | + gbc.weighty = 1.0; |
| 173 | + gbc.insets = new Insets(0, 4, 4, 4); |
| 174 | + add(getJScrollPaneYAxis(), gbc); |
| 175 | + |
| 176 | + initConnections(); |
| 177 | + } |
| 178 | + |
| 179 | + private CollapsiblePanel getDisplayOptionsPanel() { |
| 180 | + if(displayOptionsCollapsiblePanel == null) { |
| 181 | + displayOptionsCollapsiblePanel = new CollapsiblePanel("Display Options", true); |
| 182 | + JPanel content = displayOptionsCollapsiblePanel.getContentPanel(); |
| 183 | + content.setLayout(new GridBagLayout()); |
| 184 | + |
| 185 | + ButtonGroup group = new ButtonGroup(); |
| 186 | + JRadioButton rbCounts = new JRadioButton("Cluster Counts"); |
| 187 | + JRadioButton rbMean = new JRadioButton("Cluster Mean"); |
| 188 | + JRadioButton rbOverall = new JRadioButton("Cluster Overall"); |
| 189 | + |
| 190 | + rbCounts.setActionCommand("COUNTS"); |
| 191 | + rbMean.setActionCommand("MEAN"); |
| 192 | + rbOverall.setActionCommand("OVERALL"); |
| 193 | + |
| 194 | + rbCounts.addActionListener(ivjEventHandler); |
| 195 | + rbMean.addActionListener(ivjEventHandler); |
| 196 | + rbOverall.addActionListener(ivjEventHandler); |
| 197 | + |
| 198 | + group.add(rbCounts); |
| 199 | + group.add(rbMean); |
| 200 | + group.add(rbOverall); |
| 201 | + |
| 202 | + rbCounts.setSelected(true); |
| 203 | + |
| 204 | + GridBagConstraints gbc = new GridBagConstraints(); |
| 205 | + gbc.gridx = 0; |
| 206 | + gbc.anchor = GridBagConstraints.WEST; |
| 207 | + gbc.insets = new Insets(2, 4, 2, 4); |
| 208 | + gbc.gridy = 0; |
| 209 | + content.add(rbCounts, gbc); |
| 210 | + gbc.gridy = 1; |
| 211 | + content.add(rbMean, gbc); |
| 212 | + gbc.gridy = 2; |
| 213 | + content.add(rbOverall, gbc); |
| 214 | + } |
| 215 | + return displayOptionsCollapsiblePanel; |
| 216 | + } |
| 217 | + |
| 218 | + private JScrollPane getJScrollPaneYAxis() { |
| 219 | + if(jScrollPaneYAxis == null) { |
| 220 | + jScrollPaneYAxis = new JScrollPane(); |
| 221 | + jScrollPaneYAxis.setName("JScrollPaneYAxis"); |
| 222 | + jScrollPaneYAxis.setViewportView(getYAxisChoice()); |
| 223 | + } |
| 224 | + return jScrollPaneYAxis; |
| 225 | + } |
| 226 | + private JList getYAxisChoice() { |
| 227 | + if ((yAxisChoiceList == null)) { |
| 228 | + yAxisChoiceList = new JList(); |
| 229 | + yAxisChoiceList.setName("YAxisChoice"); |
| 230 | + yAxisChoiceList.setBounds(0, 0, 160, 120); |
| 231 | + yAxisChoiceList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
| 232 | + } |
| 233 | + return yAxisChoiceList; |
| 234 | + } |
| 235 | + |
| 236 | + private void initConnections() { |
| 237 | + getDisplayOptionsPanel().addPropertyChangeListener(ivjEventHandler); |
| 238 | + getYAxisChoice().addListSelectionListener(ivjEventHandler); |
| 239 | + this.addPropertyChangeListener(ivjEventHandler); |
| 240 | + getYAxisChoice().setModel(getDefaultListModelY()); |
| 241 | + } |
| 242 | + |
| 243 | + private DefaultListModel getDefaultListModelY() { |
| 244 | + if (defaultListModelY == null) { |
| 245 | + defaultListModelY = new DefaultListModel(); |
| 246 | + } |
| 247 | + return defaultListModelY; |
| 248 | + } |
| 249 | + |
| 250 | + private void handleException(java.lang.Throwable exception) { |
| 251 | + System.out.println("--------- UNCAUGHT EXCEPTION ---------"); |
| 252 | + exception.printStackTrace(System.out); |
| 253 | + } |
| 254 | + |
| 255 | + @Override |
| 256 | + protected void onSelectedObjectsChange(Object[] selectedObjects) { |
| 257 | + System.out.println("ClusterSpecificationPanel.onSelectedObjectsChange() called with " + selectedObjects.length + " objects"); |
| 258 | + } |
| 259 | + |
| 260 | + public void refreshData() { |
| 261 | + simulationModelInfo = owner.getSimulationModelInfo(); |
| 262 | + langevinSolverResultSet = owner.getLangevinSolverResultSet(); |
| 263 | + System.out.println("ClusterSpecificationPanel.refreshData() called"); |
| 264 | + |
| 265 | + // find the selected radio button inside the collapsible panel |
| 266 | + JPanel content = displayOptionsCollapsiblePanel.getContentPanel(); |
| 267 | + for (Component c : content.getComponents()) { |
| 268 | + if (c instanceof JRadioButton rb && rb.isSelected()) { |
| 269 | + ivjEventHandler.actionPerformed(new ActionEvent(rb, ActionEvent.ACTION_PERFORMED, rb.getActionCommand())); |
| 270 | + break; |
| 271 | + } |
| 272 | + } |
| 273 | + } |
| 274 | + |
| 275 | +} |
0 commit comments