Newer
Older
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/* ProjectProperty.java
* This file is part of Artemis
*
* Copyright(C) 2012 Genome Research Limited
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or(at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package uk.ac.sanger.artemis.components;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Properties;
import java.util.Vector;
import java.util.Map.Entry;
import java.util.Set;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import uk.ac.sanger.artemis.components.genebuilder.TextAreaDocumentListener;
class ProjectProperty extends JFrame
{
private static final long serialVersionUID = 1L;
private HashMap<String, HashMap<String, String>> projects;
private final static int REFERENCE = 1;
private final static int ANNOTATION = 2;
private final static int NEXT_GEN_DATA = 3;
private final static int CHADO = 4;
ProjectProperty()
{
final InputStream ins =
this.getClass().getClassLoader().getResourceAsStream("etc/project.properties");
final Properties projectProps = new Properties();
try
{
projectProps.load(ins);
ins.close();
projects = getProjectMap(projectProps);
}
catch (IOException e)
{
e.printStackTrace();
}
createProjectViewer((JPanel) getContentPane());
pack();
setVisible(true);
}
private void createProjectViewer(JPanel panel)
{
panel.setPreferredSize(new Dimension(650,400));
final JButton openArt = new JButton("OPEN");
final LaunchActionListener listener = new LaunchActionListener();
openArt.addActionListener(listener);
panel.add(openArt, BorderLayout.SOUTH);
final JList projectList = new JList(projects.keySet().toArray());
projectList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
panel.add(projectList, BorderLayout.WEST);
final GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.NORTHWEST;
c.fill = GridBagConstraints.VERTICAL;
c.ipadx = 10;
c.ipady = 10;
final Box props = Box.createVerticalBox();
projectList.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
if(e.getValueIsAdjusting() == false)
{
if(projectList.getSelectedIndex() > -1)
{
props.removeAll();
final HashMap<String, String> projProps = projects.get(projectList.getSelectedValue());
final HashMap<Integer, QualifierTextArea> settings = new HashMap<Integer, QualifierTextArea>();
for(String key: projProps.keySet())
{
Box xBox = Box.createHorizontalBox();
final QualifierTextArea qta = new QualifierTextArea();
Border loweredbevel = BorderFactory.createLoweredBevelBorder();
TitledBorder title = BorderFactory.createTitledBorder(
loweredbevel, key);
title.setTitlePosition(TitledBorder.ABOVE_TOP);
qta.setBorder(title);
qta.setText(projProps.get(key));
qta.getDocument().addDocumentListener(
new TextAreaDocumentListener(qta));
xBox.add(qta);
props.add(xBox);
if(key.equals("ref"))
settings.put(ProjectProperty.REFERENCE, qta);
else if(key.equals("annotation"))
settings.put(ProjectProperty.ANNOTATION, qta);
else if(key.equals("bam") || key.equals("vcf") || key.equals("bcf"))
settings.put(ProjectProperty.NEXT_GEN_DATA, qta);
else if(key.equals("chado"))
settings.put(ProjectProperty.CHADO, qta);
}
props.add(Box.createVerticalGlue());
props.revalidate();
props.repaint();
listener.setSettings(settings);
}
}
}
});
panel.add(props, BorderLayout.CENTER);
}
/**
* Create a project hash of the properties.
* @param projectProps
* @return
*/
private HashMap<String, HashMap<String, String>> getProjectMap(final Properties projectProps)
{
final HashMap<String, HashMap<String, String>> projects =
new HashMap<String, HashMap<String, String>>();
for (Entry<Object, Object> propItem : projectProps.entrySet())
{
String key = (String) propItem.getKey();
String value = (String) propItem.getValue();
if (key.startsWith("project."))
{
key = key.substring(8);
int ind = key.indexOf(".");
if (ind > -1)
{
String projName = key.substring(0, ind);
key = key.substring(ind + 1);
final HashMap<String, String> thisProj;
if (projects.containsKey(projName))
thisProj = projects.get(projName);
else
thisProj = new HashMap<String, String>();
thisProj.put(key, value);
projects.put(projName, thisProj);
}
}
}
return projects;
}
class LaunchActionListener implements ActionListener
{
private String args[] = new String[]{};
private void setSettings(HashMap<Integer, QualifierTextArea> settings)
{
try
{
System.getProperties().remove("bam");
System.getProperties().remove("chado");
}
catch(Exception e){ e.printStackTrace(); }
final Set<Integer> keys = settings.keySet();
final Vector<String> vargs = new Vector<String>();
final Vector<String> vann = new Vector<String>();
for(Integer key: keys)
{
switch(key)
{
case ProjectProperty.REFERENCE:
vargs.add( settings.get(key).getText() );
break;
case ProjectProperty.ANNOTATION:
vann.add( settings.get(key).getText() );
break;
case ProjectProperty.NEXT_GEN_DATA:
System.setProperty("bam", settings.get(key).getText().replaceAll("\\s+", ","));
break;
case ProjectProperty.CHADO:
System.setProperty("chado", settings.get(key).getText().trim());
break;
}
}
args = new String[vargs.size()+(vann.size()*2)];
for(int i=0; i<vargs.size(); i++)
args[i] = vargs.get(i);
for(int i=0; i<vann.size(); i++)
{
args[vargs.size()+(i*2)] = "+";
args[vargs.size()+(i*2)+1] = vann.get(i);
}
}
public void actionPerformed(ActionEvent arg0)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
final ArtemisMain main_window = new ArtemisMain(args);
main_window.setVisible(true);
main_window.readArgsAndOptions(args);
}
});
}
}
public static void main(String args[])
{
new ProjectProperty();
}
}