Class |
Line # |
Actions |
|||
---|---|---|---|---|---|
GSequenceLink | 45 | 84 | 23 |
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.jbgui; | |
22 | ||
23 | import jalview.gui.JvOptionPane; | |
24 | import jalview.gui.JvSwingUtils; | |
25 | import jalview.util.MessageManager; | |
26 | import jalview.util.UrlLink; | |
27 | ||
28 | import java.awt.Font; | |
29 | import java.awt.GridBagConstraints; | |
30 | import java.awt.GridBagLayout; | |
31 | import java.awt.Insets; | |
32 | import java.awt.Rectangle; | |
33 | import java.awt.event.ActionEvent; | |
34 | import java.awt.event.ActionListener; | |
35 | import java.awt.event.KeyAdapter; | |
36 | import java.awt.event.KeyEvent; | |
37 | ||
38 | import javax.swing.BorderFactory; | |
39 | import javax.swing.JButton; | |
40 | import javax.swing.JLabel; | |
41 | import javax.swing.JPanel; | |
42 | import javax.swing.JTextField; | |
43 | import javax.swing.SwingConstants; | |
44 | ||
45 | public class GSequenceLink extends JPanel | |
46 | { | |
47 | ||
48 | JTextField nameTB = new JTextField(); | |
49 | ||
50 | JTextField urlTB = new JTextField(); | |
51 | ||
52 | JButton insertSeq = new JButton(); | |
53 | ||
54 | JButton insertDBAcc = new JButton(); | |
55 | ||
56 | JLabel insert = new JLabel(); | |
57 | ||
58 | JLabel jLabel1 = new JLabel(); | |
59 | ||
60 | JLabel jLabel2 = new JLabel(); | |
61 | ||
62 | JLabel jLabel3 = new JLabel(); | |
63 | ||
64 | JLabel jLabel4 = new JLabel(); | |
65 | ||
66 | JLabel jLabel5 = new JLabel(); | |
67 | ||
68 | JLabel jLabel6 = new JLabel(); | |
69 | ||
70 | JPanel jPanel1 = new JPanel(); | |
71 | ||
72 | GridBagLayout gridBagLayout1 = new GridBagLayout(); | |
73 | ||
74 | 0 | public GSequenceLink() |
75 | { | |
76 | 0 | try |
77 | { | |
78 | 0 | jbInit(); |
79 | } catch (Exception ex) | |
80 | { | |
81 | 0 | ex.printStackTrace(); |
82 | } | |
83 | } | |
84 | ||
85 | 0 | private void jbInit() throws Exception |
86 | { | |
87 | 0 | this.setLayout(gridBagLayout1); |
88 | 0 | nameTB.setFont(JvSwingUtils.getLabelFont()); |
89 | 0 | nameTB.setBounds(new Rectangle(77, 10, 310, 23)); |
90 | 0 | nameTB.addKeyListener(new KeyAdapter() |
91 | { | |
92 | 0 | @Override |
93 | public void keyTyped(KeyEvent e) | |
94 | { | |
95 | 0 | nameTB_keyTyped(e); |
96 | } | |
97 | }); | |
98 | 0 | urlTB.setFont(JvSwingUtils.getLabelFont()); |
99 | 0 | urlTB.setText("http://"); |
100 | 0 | urlTB.setBounds(new Rectangle(78, 40, 309, 23)); |
101 | 0 | urlTB.addKeyListener(new KeyAdapter() |
102 | { | |
103 | 0 | @Override |
104 | public void keyTyped(KeyEvent e) | |
105 | { | |
106 | 0 | urlTB_keyTyped(e); |
107 | } | |
108 | }); | |
109 | ||
110 | 0 | insertSeq.setLocation(77, 75); |
111 | 0 | insertSeq.setSize(141, 24); |
112 | 0 | insertSeq.setText(MessageManager.getString("action.seq_id")); |
113 | 0 | insertSeq.addActionListener(new ActionListener() |
114 | { | |
115 | 0 | @Override |
116 | public void actionPerformed(ActionEvent e) | |
117 | { | |
118 | 0 | insertSeq_action(e); |
119 | } | |
120 | }); | |
121 | ||
122 | 0 | insertDBAcc.setLocation(210, 75); |
123 | 0 | insertDBAcc.setSize(141, 24); |
124 | 0 | insertDBAcc.setText(MessageManager.getString("action.db_acc")); |
125 | 0 | insertDBAcc.addActionListener(new ActionListener() |
126 | { | |
127 | 0 | @Override |
128 | public void actionPerformed(ActionEvent e) | |
129 | { | |
130 | 0 | insertDBAcc_action(e); |
131 | } | |
132 | }); | |
133 | ||
134 | 0 | insert.setText(MessageManager.getString("label.insert")); |
135 | 0 | insert.setFont(JvSwingUtils.getLabelFont()); |
136 | 0 | insert.setHorizontalAlignment(SwingConstants.RIGHT); |
137 | 0 | insert.setBounds(17, 78, 58, 16); |
138 | ||
139 | 0 | jLabel1.setFont(JvSwingUtils.getLabelFont()); |
140 | 0 | jLabel1.setHorizontalAlignment(SwingConstants.TRAILING); |
141 | 0 | jLabel1.setText(MessageManager.getString("label.link_name")); |
142 | 0 | jLabel1.setBounds(new Rectangle(4, 10, 71, 24)); |
143 | 0 | jLabel2.setFont(JvSwingUtils.getLabelFont()); |
144 | 0 | jLabel2.setHorizontalAlignment(SwingConstants.TRAILING); |
145 | 0 | jLabel2.setText(MessageManager.getString("label.url:")); |
146 | 0 | jLabel2.setBounds(new Rectangle(17, 37, 54, 27)); |
147 | 0 | jLabel3.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); |
148 | 0 | jLabel3.setText(MessageManager.getString("label.use_sequence_id_1")); |
149 | 0 | jLabel3.setBounds(new Rectangle(21, 102, 351, 15)); |
150 | 0 | jLabel4.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); |
151 | 0 | jLabel4.setText(MessageManager.getString("label.use_sequence_id_2")); |
152 | 0 | jLabel4.setBounds(new Rectangle(21, 118, 351, 15)); |
153 | 0 | jLabel5.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); |
154 | 0 | jLabel5.setText(MessageManager.getString("label.use_sequence_id_3")); |
155 | 0 | jLabel5.setBounds(new Rectangle(21, 136, 351, 15)); |
156 | ||
157 | 0 | String lastLabel = MessageManager.getString("label.use_sequence_id_4"); |
158 | 0 | if (lastLabel.length() > 0) |
159 | { | |
160 | // e.g. Spanish version has longer text | |
161 | 0 | jLabel6.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); |
162 | 0 | jLabel6.setText(lastLabel); |
163 | 0 | jLabel6.setBounds(new Rectangle(21, 152, 351, 15)); |
164 | } | |
165 | ||
166 | 0 | jPanel1.setBorder(BorderFactory.createEtchedBorder()); |
167 | 0 | jPanel1.setLayout(null); |
168 | 0 | jPanel1.add(jLabel1); |
169 | 0 | jPanel1.add(nameTB); |
170 | 0 | jPanel1.add(urlTB); |
171 | 0 | jPanel1.add(insertSeq); |
172 | 0 | jPanel1.add(insertDBAcc); |
173 | 0 | jPanel1.add(insert); |
174 | 0 | jPanel1.add(jLabel2); |
175 | 0 | jPanel1.add(jLabel3); |
176 | 0 | jPanel1.add(jLabel4); |
177 | 0 | jPanel1.add(jLabel5); |
178 | ||
179 | 0 | int height = 160; |
180 | 0 | if (lastLabel.length() > 0) |
181 | { | |
182 | 0 | jPanel1.add(jLabel6); |
183 | 0 | height = 176; |
184 | } | |
185 | ||
186 | 0 | this.add(jPanel1, |
187 | new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, | |
188 | GridBagConstraints.CENTER, GridBagConstraints.BOTH, | |
189 | new Insets(5, 4, 6, 5), 390, height)); | |
190 | } | |
191 | ||
192 | 0 | @Override |
193 | public void setName(String name) | |
194 | { | |
195 | 0 | nameTB.setText(name); |
196 | } | |
197 | ||
198 | 0 | public void setURL(String url) |
199 | { | |
200 | 0 | urlTB.setText(url); |
201 | } | |
202 | ||
203 | 0 | @Override |
204 | public String getName() | |
205 | { | |
206 | 0 | return nameTB.getText(); |
207 | } | |
208 | ||
209 | 0 | public String getURL() |
210 | { | |
211 | 0 | return urlTB.getText(); |
212 | } | |
213 | ||
214 | 0 | public boolean checkValid() |
215 | { | |
216 | 0 | UrlLink ul = new UrlLink("foo|" + urlTB.getText().trim()); |
217 | 0 | if (ul.isValid() && ul.isDynamic()) |
218 | { | |
219 | 0 | return true; |
220 | } | |
221 | ||
222 | 0 | JvOptionPane.showInternalMessageDialog(jalview.gui.Desktop.desktop, |
223 | MessageManager.getString("warn.url_must_contain"), | |
224 | MessageManager.getString("label.invalid_url"), | |
225 | JvOptionPane.WARNING_MESSAGE); | |
226 | 0 | return false; |
227 | } | |
228 | ||
229 | 0 | public void notifyDuplicate() |
230 | { | |
231 | 0 | JvOptionPane.showInternalMessageDialog(jalview.gui.Desktop.desktop, |
232 | MessageManager.getString("warn.name_cannot_be_duplicate"), | |
233 | MessageManager.getString("label.invalid_name"), | |
234 | JvOptionPane.WARNING_MESSAGE); | |
235 | } | |
236 | ||
237 | 0 | public void nameTB_keyTyped(KeyEvent e) |
238 | { | |
239 | 0 | if (e.getKeyChar() == '|') |
240 | { | |
241 | 0 | e.consume(); |
242 | } | |
243 | } | |
244 | ||
245 | 0 | public void urlTB_keyTyped(KeyEvent e) |
246 | { | |
247 | // URLLink object validation takes care of incorrect regexes. | |
248 | // if (e.getKeyChar() == '|' || e.getKeyChar() == ' ') | |
249 | // { | |
250 | // e.consume(); | |
251 | // } | |
252 | ||
253 | } | |
254 | ||
255 | 0 | public void insertSeq_action(ActionEvent e) |
256 | { | |
257 | 0 | insertIntoUrl(insertSeq.getText()); |
258 | } | |
259 | ||
260 | 0 | public void insertDBAcc_action(ActionEvent e) |
261 | { | |
262 | 0 | insertIntoUrl(insertDBAcc.getText()); |
263 | } | |
264 | ||
265 | 0 | private void insertIntoUrl(String insertion) |
266 | { | |
267 | 0 | int pos = urlTB.getCaretPosition(); |
268 | 0 | String text = urlTB.getText(); |
269 | 0 | String newText = text.substring(0, pos) + insertion |
270 | + text.substring(pos); | |
271 | 0 | urlTB.setText(newText); |
272 | } | |
273 | } |