Debian Codegraph @

src/dr/app/bss/RootSequenceEditor.java

raw symbols SCIP
1 /*
2 * RootSequenceEditor.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 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 * @author Filip Bielejec
47 * @version $Id$
48 */
49 public class RootSequenceEditor {
50
51 // Data
52 private PartitionDataList dataList = null;
53 private int row;
54
55 // Settings
56 private OptionsPanel optionPanel;
57 //TODO: class that checks for ACTG string values, maybe also with scroller
58 private JTextField ancestralSequenceField;
59
60 //Buttons
61 private JButton done;
62 private JButton cancel;
63
64 // Window
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 // Buttons
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 // Window
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 }//END: Constructor
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 }// END: setAncestralSequence
114
115 public void collectSettings() {
116
117 dataList.get(row).ancestralSequenceString = ancestralSequenceField.getText();
118
119 }// END: collectSettings
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 }// END: actionPerformed
158 }// END: ListenSaveLocationCoordinates
159
160 private class ListenCancel implements ActionListener {
161 public void actionPerformed(ActionEvent ev) {
162
163 window.setVisible(false);
164
165 }// END: actionPerformed
166 }// END: ListenCancel
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 }// END: showWindow
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 }// END: edt check
188
189 }// END: launch
190
191 }//END: class