Debian Codegraph @

src/dr/app/bss/SimulationPanel.java

raw symbols SCIP
1 /*
2 * SimulationPanel.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.bss;
27
28 import dr.app.gui.components.WholeNumberField;
29 import dr.evolution.alignment.SimpleAlignment;
30 import jam.framework.Exportable;
31 import jam.panels.OptionsPanel;
32
33 import javax.swing.*;
34
35 import java.awt.*;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.ActionListener;
38 import java.awt.event.ItemEvent;
39 import java.awt.event.ItemListener;
40
41 /**
42 * @author Filip Bielejec
43 * @version $Id$
44 */
45 @SuppressWarnings({ "rawtypes", "serial" })
46 public class SimulationPanel extends JPanel implements Exportable {
47
48 private MainFrame frame;
49 private PartitionDataList dataList;
50 private OptionsPanel optionPanel;
51
52 private WholeNumberField simulationsNumberField;
53 private WholeNumberField startingSeedNumberField;
54
55 // Buttons
56 private JButton simulate;
57 private JButton generateXML;
58
59 // Check boxes
60 private JCheckBox setSeed;
61 private JCheckBox useParallel;
62 private JCheckBox outputAncestralSequences;
63
64 //Combo boxes
65 private JComboBox outputFormat;
66 private ComboBoxModel outputFormatModel;
67
68 @SuppressWarnings({ "unchecked" })
69 public SimulationPanel(final MainFrame frame,
70 final PartitionDataList dataList) {
71
72 this.frame = frame;
73 this.dataList = dataList;
74
75 optionPanel = new OptionsPanel(12, 12, SwingConstants.CENTER);
76
77 simulationsNumberField = new WholeNumberField(1, Integer.MAX_VALUE);
78 simulationsNumberField.setColumns(10);
79 simulationsNumberField.setValue(dataList.simulationsCount);
80 optionPanel.addComponentWithLabel("Number of simulations:",
81 simulationsNumberField);
82
83 setSeed = new JCheckBox();
84 setSeed.addItemListener(new SetSeedCheckBoxListener());
85 setSeed.setSelected(dataList.setSeed);
86 optionPanel.addComponentWithLabel("Set seed:", setSeed);
87
88 startingSeedNumberField = new WholeNumberField(1, Long.MAX_VALUE);
89 startingSeedNumberField.setColumns(10);
90 startingSeedNumberField.setValue(dataList.startingSeed);
91 startingSeedNumberField.setEnabled(dataList.setSeed);
92 optionPanel.addComponentWithLabel("Starting seed:",
93 startingSeedNumberField);
94
95 outputFormat = new JComboBox();
96 optionPanel.addComponentWithLabel("Output format:", outputFormat);
97 outputFormatModel = new DefaultComboBoxModel(SimpleAlignment.OutputType.values());
98 outputFormat.setModel(outputFormatModel);
99
100 outputAncestralSequences = new JCheckBox();
101 outputAncestralSequences.addItemListener(new outputAncestralSequencesCheckBoxListener());
102 outputAncestralSequences.setSelected(dataList.useParallel);
103 optionPanel.addComponentWithLabel("Output ancestral sequences:",
104 outputAncestralSequences);
105
106 useParallel = new JCheckBox();
107 useParallel.addItemListener(new UseParallelCheckBoxListener());
108 useParallel.setSelected(dataList.useParallel);
109 optionPanel.addComponentWithLabel("Use parallel implementation:",
110 useParallel);
111
112 // Buttons holder
113 JPanel buttonsHolder = new JPanel();
114 buttonsHolder.setOpaque(false);
115
116 // simulate button
117 simulate = new JButton("Simulate",
118 Utils.createImageIcon(Utils.BIOHAZARD_ICON));
119 simulate.addActionListener(new ListenSimulate());
120 buttonsHolder.add(simulate);
121
122 generateXML = new JButton("Generate XML",
123 Utils.createImageIcon(Utils.HAMMER_ICON));
124 generateXML.addActionListener(new ListenGenerateXML());
125 buttonsHolder.add(generateXML);
126
127 setOpaque(false);
128 setLayout(new BorderLayout());
129 add(optionPanel, BorderLayout.NORTH);
130 add(buttonsHolder, BorderLayout.SOUTH);
131
132 }// END: SimulationPanel
133
134 public final void collectSettings() {
135
136 dataList.simulationsCount = simulationsNumberField.getValue();
137 if (dataList.setSeed) {
138 dataList.startingSeed = startingSeedNumberField.getValue();
139 }
140
141 dataList.outputFormat = SimpleAlignment.OutputType.parseFromString(
142 outputFormat.getSelectedItem().toString());
143
144 }// END: collectSettings
145
146 private class SetSeedCheckBoxListener implements ItemListener {
147 public void itemStateChanged(ItemEvent e) {
148
149 if (setSeed.isSelected()) {
150 startingSeedNumberField.setEnabled(true);
151 dataList.setSeed = true;
152 } else {
153 startingSeedNumberField.setEnabled(false);
154 dataList.setSeed = false;
155 }
156
157 }
158 }// END: CheckBoxListener
159
160 private class UseParallelCheckBoxListener implements ItemListener {
161 public void itemStateChanged(ItemEvent e) {
162
163 if (useParallel.isSelected()) {
164 dataList.useParallel = true;
165 } else {
166 dataList.useParallel = false;
167 }
168
169 }
170 }// END: CheckBoxListener
171
172 private class outputAncestralSequencesCheckBoxListener implements ItemListener {
173 public void itemStateChanged(ItemEvent e) {
174
175 if (outputAncestralSequences.isSelected()) {
176 dataList.outputAncestralSequences = true;
177 } else {
178 dataList.outputAncestralSequences = false;
179 }
180
181 }
182 }// END: CheckBoxListener
183
184 private class ListenSimulate implements ActionListener {
185 public void actionPerformed(ActionEvent ev) {
186
187 frame.doExport();
188
189 }// END: actionPerformed
190 }// END: ListenSimulate
191
192 private class ListenGenerateXML implements ActionListener {
193 public void actionPerformed(ActionEvent ev) {
194
195 frame.doGenerateXML();
196
197 }// END: actionPerformed
198 }// END: ListenSaveLocationCoordinates
199
200 public void setBusy() {
201 simulate.setEnabled(false);
202 generateXML.setEnabled(false);
203 }// END: setBusy
204
205 public void setIdle() {
206 simulate.setEnabled(true);
207 generateXML.setEnabled(true);
208 }// END: setIdle
209
210 public JComponent getExportableComponent() {
211 return this;
212 }// END: getExportableComponent
213
214 public void updateSimulationPanel(PartitionDataList dataList) {
215
216 setDataList(dataList);
217
218 // TODO: DOES NOT WORK
219 outputFormatModel.setSelectedItem(dataList.outputFormat);
220 outputFormat.setSelectedItem(dataList.outputFormat);
221
222 }//END: updateSimulationPanel
223
224 public void setDataList(PartitionDataList dataList) {
225 this.dataList = dataList;
226 }// END: setDataList
227
228 }// END: class