2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.jbgui;
23 import jalview.gui.JvOptionPane;
24 import jalview.gui.JvSwingUtils;
25 import jalview.util.MessageManager;
26 import jalview.util.UrlLink;
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;
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;
45 public class GSequenceLink extends JPanel
48 JTextField nameTB = new JTextField();
50 JTextField urlTB = new JTextField();
52 JButton insertSeq = new JButton();
54 JButton insertDBAcc = new JButton();
56 JLabel insert = new JLabel();
58 JLabel jLabel1 = new JLabel();
60 JLabel jLabel2 = new JLabel();
62 JLabel jLabel3 = new JLabel();
64 JLabel jLabel4 = new JLabel();
66 JLabel jLabel5 = new JLabel();
68 JLabel jLabel6 = new JLabel();
70 JPanel jPanel1 = new JPanel();
72 GridBagLayout gridBagLayout1 = new GridBagLayout();
74 public GSequenceLink()
79 } catch (Exception ex)
85 private void jbInit() throws Exception
87 this.setLayout(gridBagLayout1);
88 nameTB.setFont(JvSwingUtils.getLabelFont());
89 nameTB.setBounds(new Rectangle(77, 10, 310, 23));
90 nameTB.addKeyListener(new KeyAdapter()
93 public void keyTyped(KeyEvent e)
98 urlTB.setFont(JvSwingUtils.getLabelFont());
99 urlTB.setText("http://");
100 urlTB.setBounds(new Rectangle(78, 40, 309, 23));
101 urlTB.addKeyListener(new KeyAdapter()
104 public void keyTyped(KeyEvent e)
110 insertSeq.setLocation(77, 75);
111 insertSeq.setSize(141, 24);
112 insertSeq.setText(MessageManager.getString("action.seq_id"));
113 insertSeq.addActionListener(new ActionListener()
116 public void actionPerformed(ActionEvent e)
122 insertDBAcc.setLocation(210, 75);
123 insertDBAcc.setSize(141, 24);
124 insertDBAcc.setText(MessageManager.getString("action.db_acc"));
125 insertDBAcc.addActionListener(new ActionListener()
128 public void actionPerformed(ActionEvent e)
130 insertDBAcc_action(e);
134 insert.setText(MessageManager.getString("label.insert"));
135 insert.setFont(JvSwingUtils.getLabelFont());
136 insert.setHorizontalAlignment(SwingConstants.RIGHT);
137 insert.setBounds(17, 78, 58, 16);
139 jLabel1.setFont(JvSwingUtils.getLabelFont());
140 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
141 jLabel1.setText(MessageManager.getString("label.link_name"));
142 jLabel1.setBounds(new Rectangle(4, 10, 71, 24));
143 jLabel2.setFont(JvSwingUtils.getLabelFont());
144 jLabel2.setHorizontalAlignment(SwingConstants.TRAILING);
145 jLabel2.setText(MessageManager.getString("label.url:"));
146 jLabel2.setBounds(new Rectangle(17, 37, 54, 27));
147 jLabel3.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
148 jLabel3.setText(MessageManager.getString("label.use_sequence_id_1"));
149 jLabel3.setBounds(new Rectangle(21, 102, 351, 15));
150 jLabel4.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
151 jLabel4.setText(MessageManager.getString("label.use_sequence_id_2"));
152 jLabel4.setBounds(new Rectangle(21, 118, 351, 15));
153 jLabel5.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
154 jLabel5.setText(MessageManager.getString("label.use_sequence_id_3"));
155 jLabel5.setBounds(new Rectangle(21, 136, 351, 15));
157 String lastLabel = MessageManager.getString("label.use_sequence_id_4");
158 if (lastLabel.length() > 0)
160 // e.g. Spanish version has longer text
161 jLabel6.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
162 jLabel6.setText(lastLabel);
163 jLabel6.setBounds(new Rectangle(21, 152, 351, 15));
166 jPanel1.setBorder(BorderFactory.createEtchedBorder());
167 jPanel1.setLayout(null);
168 jPanel1.add(jLabel1);
171 jPanel1.add(insertSeq);
172 jPanel1.add(insertDBAcc);
174 jPanel1.add(jLabel2);
175 jPanel1.add(jLabel3);
176 jPanel1.add(jLabel4);
177 jPanel1.add(jLabel5);
180 if (lastLabel.length() > 0)
182 jPanel1.add(jLabel6);
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));
193 public void setName(String name)
195 nameTB.setText(name);
198 public void setURL(String url)
204 public String getName()
206 return nameTB.getText();
209 public String getURL()
211 return urlTB.getText();
214 public boolean checkValid()
216 UrlLink ul = new UrlLink("foo|" + urlTB.getText().trim());
217 if (ul.isValid() && ul.isDynamic())
222 JvOptionPane.showInternalMessageDialog(jalview.gui.Desktop.desktop,
223 MessageManager.getString("warn.url_must_contain"),
224 MessageManager.getString("label.invalid_url"),
225 JvOptionPane.WARNING_MESSAGE);
229 public void notifyDuplicate()
231 JvOptionPane.showInternalMessageDialog(jalview.gui.Desktop.desktop,
232 MessageManager.getString("warn.name_cannot_be_duplicate"),
233 MessageManager.getString("label.invalid_name"),
234 JvOptionPane.WARNING_MESSAGE);
237 public void nameTB_keyTyped(KeyEvent e)
239 if (e.getKeyChar() == '|')
245 public void urlTB_keyTyped(KeyEvent e)
247 // URLLink object validation takes care of incorrect regexes.
248 // if (e.getKeyChar() == '|' || e.getKeyChar() == ' ')
255 public void insertSeq_action(ActionEvent e)
257 insertIntoUrl(insertSeq.getText());
260 public void insertDBAcc_action(ActionEvent e)
262 insertIntoUrl(insertDBAcc.getText());
265 private void insertIntoUrl(String insertion)
267 int pos = urlTB.getCaretPosition();
268 String text = urlTB.getText();
269 String newText = text.substring(0, pos) + insertion
270 + text.substring(pos);
271 urlTB.setText(newText);