JAL-2326 updated references of JOptionPane to JvOptionPane
[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.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.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.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       @Override
64       public void keyTyped(KeyEvent e)
65       {
66         nameTB_keyTyped(e);
67       }
68     });
69     urlTB.setFont(JvSwingUtils.getLabelFont());
70     urlTB.setText("http://");
71     urlTB.setBounds(new Rectangle(78, 40, 309, 23));
72     urlTB.addKeyListener(new KeyAdapter()
73     {
74       @Override
75       public void keyTyped(KeyEvent e)
76       {
77         urlTB_keyTyped(e);
78       }
79     });
80     jLabel1.setFont(JvSwingUtils.getLabelFont());
81     jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
82     jLabel1.setText(MessageManager.getString("label.link_name"));
83     jLabel1.setBounds(new Rectangle(4, 10, 71, 24));
84     jLabel2.setFont(JvSwingUtils.getLabelFont());
85     jLabel2.setHorizontalAlignment(SwingConstants.TRAILING);
86     jLabel2.setText(MessageManager.getString("label.url"));
87     jLabel2.setBounds(new Rectangle(17, 37, 54, 27));
88     jLabel3.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
89     jLabel3.setText(MessageManager.getString("label.use_sequence_id_1"));
90     jLabel3.setBounds(new Rectangle(21, 72, 351, 15));
91     jLabel4.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
92     jLabel4.setText(MessageManager.getString("label.use_sequence_id_2"));
93     jLabel4.setBounds(new Rectangle(21, 88, 351, 15));
94     jLabel5.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
95     jLabel5.setText(MessageManager.getString("label.use_sequence_id_3"));
96     jLabel5.setBounds(new Rectangle(21, 106, 351, 15));
97
98     String lastLabel = MessageManager.getString("label.use_sequence_id_4");
99     if (lastLabel.length() > 0)
100     {
101       // e.g. Spanish version has longer text
102       jLabel6.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
103       jLabel6.setText(lastLabel);
104       jLabel6.setBounds(new Rectangle(21, 122, 351, 15));
105     }
106
107     jPanel1.setBorder(BorderFactory.createEtchedBorder());
108     jPanel1.setLayout(null);
109     jPanel1.add(jLabel1);
110     jPanel1.add(nameTB);
111     jPanel1.add(urlTB);
112     jPanel1.add(jLabel2);
113     jPanel1.add(jLabel3);
114     jPanel1.add(jLabel4);
115     jPanel1.add(jLabel5);
116
117     int height = 130;
118     if (lastLabel.length() > 0)
119     {
120       jPanel1.add(jLabel6);
121       height = 146;
122     }
123
124     this.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
125             GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
126                     5, 4, 6, 5), 390, height));
127   }
128
129   @Override
130   public void setName(String name)
131   {
132     nameTB.setText(name);
133   }
134
135   public void setURL(String url)
136   {
137     urlTB.setText(url);
138   }
139
140   @Override
141   public String getName()
142   {
143     return nameTB.getText();
144   }
145
146   public String getURL()
147   {
148     return urlTB.getText();
149   }
150
151   public boolean checkValid()
152   {
153     UrlLink ul = new UrlLink("foo|" + urlTB.getText().trim());
154     if (ul.isValid() && ul.isDynamic())
155     {
156       return true;
157     }
158
159     JvOptionPane.showInternalMessageDialog(jalview.gui.Desktop.desktop,
160             MessageManager.getString("warn.url_must_contain"),
161             MessageManager.getString("label.invalid_url"),
162             JvOptionPane.WARNING_MESSAGE);
163     return false;
164   }
165
166   JTextField nameTB = new JTextField();
167
168   JTextField urlTB = new JTextField();
169
170   JLabel jLabel1 = new JLabel();
171
172   JLabel jLabel2 = new JLabel();
173
174   JLabel jLabel3 = new JLabel();
175
176   JLabel jLabel4 = new JLabel();
177
178   JLabel jLabel5 = new JLabel();
179
180   JLabel jLabel6 = new JLabel();
181
182   JPanel jPanel1 = new JPanel();
183
184   GridBagLayout gridBagLayout1 = new GridBagLayout();
185
186   public void nameTB_keyTyped(KeyEvent e)
187   {
188     if (e.getKeyChar() == '|')
189     {
190       e.consume();
191     }
192   }
193
194   public void urlTB_keyTyped(KeyEvent e)
195   {
196     // URLLink object validation takes care of incorrect regexes.
197     // if (e.getKeyChar() == '|' || e.getKeyChar() == ' ')
198     // {
199     // e.consume();
200     // }
201
202   }
203 }