46580a29d44c0c462a00446ab4cd7b04632c614f
[jalview.git] / src / jalview / jbgui / GSequenceLink.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.jbgui;
22
23 import jalview.gui.JvSwingUtils;
24 import jalview.util.MessageManager;
25 import jalview.util.UrlLink;
26
27 import java.awt.Font;
28 import java.awt.GridBagConstraints;
29 import java.awt.GridBagLayout;
30 import java.awt.Insets;
31 import java.awt.Panel;
32 import java.awt.Rectangle;
33 import java.awt.event.KeyAdapter;
34 import java.awt.event.KeyEvent;
35
36 import javax.swing.BorderFactory;
37 import javax.swing.JLabel;
38 import javax.swing.JOptionPane;
39 import javax.swing.JPanel;
40 import javax.swing.JTextField;
41 import javax.swing.SwingConstants;
42
43 public class GSequenceLink extends Panel
44 {
45   public GSequenceLink()
46   {
47     try
48     {
49       jbInit();
50     } catch (Exception ex)
51     {
52       ex.printStackTrace();
53     }
54   }
55
56   private void jbInit() throws Exception
57   {
58     this.setLayout(gridBagLayout1);
59     nameTB.setFont(JvSwingUtils.getLabelFont());
60     nameTB.setBounds(new Rectangle(77, 10, 310, 23));
61     nameTB.addKeyListener(new KeyAdapter()
62     {
63       public void keyTyped(KeyEvent e)
64       {
65         nameTB_keyTyped(e);
66       }
67     });
68     urlTB.setFont(JvSwingUtils.getLabelFont());
69     urlTB.setText("http://www.");
70     urlTB.setBounds(new Rectangle(78, 40, 309, 23));
71     urlTB.addKeyListener(new KeyAdapter()
72     {
73       public void keyTyped(KeyEvent e)
74       {
75         urlTB_keyTyped(e);
76       }
77     });
78     jLabel1.setFont(JvSwingUtils.getLabelFont());
79     jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
80     jLabel1.setText(MessageManager.getString("label.link_name"));
81     jLabel1.setBounds(new Rectangle(4, 10, 71, 24));
82     jLabel2.setFont(JvSwingUtils.getLabelFont());
83     jLabel2.setHorizontalAlignment(SwingConstants.TRAILING);
84     jLabel2.setText(MessageManager.getString("label.url"));
85     jLabel2.setBounds(new Rectangle(17, 37, 54, 27));
86     jLabel3.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
87     jLabel3.setText(MessageManager.getString("label.use_sequence_id_1"));
88     jLabel3.setBounds(new Rectangle(21, 72, 351, 15));
89     jLabel4.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
90     jLabel4.setText(MessageManager.getString("label.use_sequence_id_2"));
91     jLabel4.setBounds(new Rectangle(21, 93, 351, 15));
92     jPanel1.setBorder(BorderFactory.createEtchedBorder());
93     jPanel1.setLayout(null);
94     jPanel1.add(jLabel1);
95     jPanel1.add(nameTB);
96     jPanel1.add(urlTB);
97     jPanel1.add(jLabel2);
98     jPanel1.add(jLabel3);
99     jPanel1.add(jLabel4);
100     this.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
101             GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
102                     5, 4, 6, 5), 390, 130));
103   }
104
105   public void setName(String name)
106   {
107     nameTB.setText(name);
108   }
109
110   public void setURL(String url)
111   {
112     urlTB.setText(url);
113   }
114
115   public String getName()
116   {
117     return nameTB.getText();
118   }
119
120   public String getURL()
121   {
122     return urlTB.getText();
123   }
124
125   public boolean checkValid()
126   {
127     UrlLink ul = new UrlLink("foo|" + urlTB.getText().trim());
128     if (ul.isValid() && ul.isDynamic())
129     {
130       return true;
131     }
132
133     JOptionPane.showInternalMessageDialog(jalview.gui.Desktop.desktop,
134             MessageManager.getString("warn.url_must_contain"),
135             MessageManager.getString("label.invalid_url"),
136             JOptionPane.WARNING_MESSAGE);
137     return false;
138   }
139
140   JTextField nameTB = new JTextField();
141
142   JTextField urlTB = new JTextField();
143
144   JLabel jLabel1 = new JLabel();
145
146   JLabel jLabel2 = new JLabel();
147
148   JLabel jLabel3 = new JLabel();
149
150   JLabel jLabel4 = new JLabel();
151
152   JPanel jPanel1 = new JPanel();
153
154   GridBagLayout gridBagLayout1 = new GridBagLayout();
155
156   public void nameTB_keyTyped(KeyEvent e)
157   {
158     if (e.getKeyChar() == '|')
159     {
160       e.consume();
161     }
162   }
163
164   public void urlTB_keyTyped(KeyEvent e)
165   {
166     // URLLink object validation takes care of incorrect regexes.
167     // if (e.getKeyChar() == '|' || e.getKeyChar() == ' ')
168     // {
169     // e.consume();
170     // }
171
172   }
173 }