| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.app.bss; |
| 27 |
|
| 28 |
import jam.panels.OptionsPanel; |
| 29 |
|
| 30 |
import java.awt.BorderLayout; |
| 31 |
import java.awt.Dimension; |
| 32 |
import java.awt.Frame; |
| 33 |
import java.awt.event.ActionEvent; |
| 34 |
import java.awt.event.ActionListener; |
| 35 |
|
| 36 |
import javax.swing.JButton; |
| 37 |
import javax.swing.JDialog; |
| 38 |
import javax.swing.JFrame; |
| 39 |
import javax.swing.JLabel; |
| 40 |
import javax.swing.JPanel; |
| 41 |
import javax.swing.JTextField; |
| 42 |
import javax.swing.SwingConstants; |
| 43 |
import javax.swing.SwingUtilities; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public class RootSequenceEditor { |
| 50 |
|
| 51 |
|
| 52 |
private PartitionDataList dataList = null; |
| 53 |
private int row; |
| 54 |
|
| 55 |
|
| 56 |
private OptionsPanel optionPanel; |
| 57 |
|
| 58 |
private JTextField ancestralSequenceField; |
| 59 |
|
| 60 |
|
| 61 |
private JButton done; |
| 62 |
private JButton cancel; |
| 63 |
|
| 64 |
|
| 65 |
private JDialog window; |
| 66 |
private Frame owner; |
| 67 |
|
| 68 |
public RootSequenceEditor(PartitionDataList dataList, int row) { |
| 69 |
|
| 70 |
this.dataList = dataList; |
| 71 |
this.row = row; |
| 72 |
|
| 73 |
ancestralSequenceField = new JTextField("", 10); |
| 74 |
window = new JDialog(owner, "Setup root sequence for partition " + (row + 1)); |
| 75 |
optionPanel = new OptionsPanel(12, 12, SwingConstants.CENTER); |
| 76 |
|
| 77 |
optionPanel.setOpaque(false); |
| 78 |
|
| 79 |
setAncestralSequence(); |
| 80 |
|
| 81 |
|
| 82 |
JPanel buttonsHolder = new JPanel(); |
| 83 |
buttonsHolder.setOpaque(false); |
| 84 |
|
| 85 |
cancel = new JButton("Cancel", Utils.createImageIcon(Utils.CLOSE_ICON)); |
| 86 |
cancel.addActionListener(new ListenCancel()); |
| 87 |
buttonsHolder.add(cancel); |
| 88 |
|
| 89 |
done = new JButton("Done", Utils.createImageIcon(Utils.CHECK_ICON)); |
| 90 |
done.addActionListener(new ListenOk()); |
| 91 |
buttonsHolder.add(done); |
| 92 |
|
| 93 |
|
| 94 |
owner = Utils.getActiveFrame(); |
| 95 |
window.setLocationRelativeTo(owner); |
| 96 |
window.getContentPane().setLayout(new BorderLayout()); |
| 97 |
window.getContentPane().add(optionPanel, BorderLayout.CENTER); |
| 98 |
window.getContentPane().add(buttonsHolder, BorderLayout.SOUTH); |
| 99 |
window.pack(); |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
private void setAncestralSequence() { |
| 104 |
|
| 105 |
optionPanel.removeAll(); |
| 106 |
|
| 107 |
ancestralSequenceField.setText(dataList.get(row).ancestralSequenceString); |
| 108 |
optionPanel.addComponents(new JLabel("Root sequence:"), |
| 109 |
ancestralSequenceField); |
| 110 |
|
| 111 |
window.validate(); |
| 112 |
window.repaint(); |
| 113 |
} |
| 114 |
|
| 115 |
public void collectSettings() { |
| 116 |
|
| 117 |
dataList.get(row).ancestralSequenceString = ancestralSequenceField.getText(); |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
private class ListenOk implements ActionListener { |
| 122 |
public void actionPerformed(ActionEvent ev) { |
| 123 |
|
| 124 |
int ancestralSequenceLength = ancestralSequenceField.getText() |
| 125 |
.length(); |
| 126 |
int partitionSiteCount = dataList.get(row) |
| 127 |
.createPartitionSiteCount(); |
| 128 |
|
| 129 |
if (ancestralSequenceLength == partitionSiteCount) { |
| 130 |
|
| 131 |
if (ancestralSequenceField.getText().contains("-")) { |
| 132 |
|
| 133 |
Utils.showDialog("Ancestral sequence contains one or more gaps."); |
| 134 |
|
| 135 |
} else { |
| 136 |
|
| 137 |
window.setVisible(false); |
| 138 |
collectSettings(); |
| 139 |
|
| 140 |
} |
| 141 |
|
| 142 |
} else { |
| 143 |
|
| 144 |
if (ancestralSequenceLength != 0) { |
| 145 |
|
| 146 |
Utils.showDialog("Ancestral sequence length of " |
| 147 |
+ ancestralSequenceLength |
| 148 |
+ " does not match partition site count of " |
| 149 |
+ partitionSiteCount + "."); |
| 150 |
} else { |
| 151 |
|
| 152 |
window.setVisible(false); |
| 153 |
|
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
private class ListenCancel implements ActionListener { |
| 161 |
public void actionPerformed(ActionEvent ev) { |
| 162 |
|
| 163 |
window.setVisible(false); |
| 164 |
|
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
public void showWindow() { |
| 169 |
window.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); |
| 170 |
window.setSize(new Dimension(450, 200)); |
| 171 |
window.setMinimumSize(new Dimension(100, 100)); |
| 172 |
window.setResizable(true); |
| 173 |
window.setModal(true); |
| 174 |
window.setVisible(true); |
| 175 |
} |
| 176 |
|
| 177 |
public void launch() { |
| 178 |
|
| 179 |
if (SwingUtilities.isEventDispatchThread()) { |
| 180 |
showWindow(); |
| 181 |
} else { |
| 182 |
SwingUtilities.invokeLater(new Runnable() { |
| 183 |
public void run() { |
| 184 |
showWindow(); |
| 185 |
} |
| 186 |
}); |
| 187 |
} |
| 188 |
|
| 189 |
} |
| 190 |
|
| 191 |
} |