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