JAL-2909 Wire up coordinates dialog with bam file reader
[jalview.git] / src / jalview / gui / BamFileOptionsChooser.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import jalview.io.AlignmentFileReaderI;
24 import jalview.io.BamFile;
25 import jalview.util.MessageManager;
26
27 import java.awt.GridBagConstraints;
28 import java.awt.GridBagLayout;
29 import java.util.Arrays;
30
31 import javax.swing.BorderFactory;
32 import javax.swing.JComboBox;
33 import javax.swing.JLabel;
34 import javax.swing.JPanel;
35 import javax.swing.JTextField;
36
37 /**
38  * A dialog where a user can choose import options for a bam file
39  */
40 public class BamFileOptionsChooser extends JPanel
41 {
42
43   // text field for start of range
44   // JFormattedTextField startRange = new JFormattedTextField(
45   // new NumberFormatter(NumberFormat.getIntegerInstance()));
46
47   // text field for end of range
48   // JFormattedTextField endRange = new JFormattedTextField(
49   // new NumberFormatter(NumberFormat.getIntegerInstance()));
50
51   JTextField startRange = new JTextField(10);
52
53   JTextField endRange = new JTextField(10);
54
55   // combo box for chromosome list
56   JComboBox<String> chroCombo;
57
58   public BamFileOptionsChooser(AlignmentFileReaderI source)
59   {
60     Object[] preprocessResult = source.preprocess();
61     String[] chromosomes = Arrays.copyOf(preprocessResult,
62             preprocessResult.length, String[].class);
63
64     setLayout(new GridBagLayout());
65     GridBagConstraints c = new GridBagConstraints();
66
67     setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
68
69     // set up chromosome input
70     JLabel chroLabel = new JLabel(
71             MessageManager.getString("label.bam_chromosome"));
72     chroCombo = new JComboBox<>(chromosomes);
73     
74     // set up region input
75     JPanel range = new JPanel();
76     JLabel rangeLabel = new JLabel(
77             MessageManager.getString("label.bam_range"));
78     startRange.setColumns(8);
79     endRange.setColumns(8);
80
81     JLabel rangeSep = new JLabel("-");
82     range.add(startRange);
83     range.add(rangeSep);
84     range.add(endRange);
85
86     // chromosome label top left
87     c.gridx = 0;
88     c.gridy = 0;
89     c.anchor = GridBagConstraints.WEST;
90     c.fill = GridBagConstraints.NONE;
91     this.add(chroLabel, c);
92
93     // chromosome combo top right
94     c.gridx = 1;
95     c.weightx = 1;
96     c.anchor = GridBagConstraints.WEST;
97     c.fill = GridBagConstraints.HORIZONTAL;
98     this.add(chroCombo, c);
99
100     // region label mid left
101     c.gridx = 0;
102     c.gridy = 1;
103     c.anchor = GridBagConstraints.WEST;
104     c.fill = GridBagConstraints.NONE;
105     this.add(rangeLabel, c);
106
107     // region input mid right
108     c.gridx = 1;
109     c.weightx = 1;
110     c.anchor = GridBagConstraints.WEST;
111     c.fill = GridBagConstraints.HORIZONTAL;
112     this.add(range, c);
113   }
114
115   public void update(AlignmentFileReaderI source)
116   {
117
118     int start = Integer.parseInt(startRange.getText());
119     int end = Integer.parseInt(endRange.getText());
120     ((BamFile) source).setOptions((String) chroCombo.getSelectedItem(),
121             start, end);
122
123   }
124
125 }