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