JAL-1432 updated copyright notices
[jalview.git] / src / jalview / jbgui / GSequenceLink.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.jbgui;
20
21 import jalview.gui.JvSwingUtils;
22 import jalview.util.UrlLink;
23
24 import java.awt.*;
25 import java.awt.event.*;
26 import javax.swing.*;
27
28 public class GSequenceLink extends Panel
29 {
30   public GSequenceLink()
31   {
32     try
33     {
34       jbInit();
35     } catch (Exception ex)
36     {
37       ex.printStackTrace();
38     }
39   }
40
41   private void jbInit() throws Exception
42   {
43     this.setLayout(gridBagLayout1);
44     nameTB.setFont(JvSwingUtils.getLabelFont());
45     nameTB.setBounds(new Rectangle(77, 10, 310, 23));
46     nameTB.addKeyListener(new KeyAdapter()
47     {
48       public void keyTyped(KeyEvent e)
49       {
50         nameTB_keyTyped(e);
51       }
52     });
53     urlTB.setFont(JvSwingUtils.getLabelFont());
54     urlTB.setText("http://www.");
55     urlTB.setBounds(new Rectangle(78, 40, 309, 23));
56     urlTB.addKeyListener(new KeyAdapter()
57     {
58       public void keyTyped(KeyEvent e)
59       {
60         urlTB_keyTyped(e);
61       }
62     });
63     jLabel1.setFont(JvSwingUtils.getLabelFont());
64     jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
65     jLabel1.setText("Link Name");
66     jLabel1.setBounds(new Rectangle(4, 10, 71, 24));
67     jLabel2.setFont(JvSwingUtils.getLabelFont());
68     jLabel2.setHorizontalAlignment(SwingConstants.TRAILING);
69     jLabel2.setText("URL");
70     jLabel2.setBounds(new Rectangle(17, 37, 54, 27));
71     jLabel3.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
72     jLabel3.setText("Use $SEQUENCE_ID$ or $SEQUENCE_ID=/<regex>/=$");
73     jLabel3.setBounds(new Rectangle(21, 72, 351, 15));
74     jLabel4.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
75     jLabel4.setText("\nto embed sequence id in URL");
76     jLabel4.setBounds(new Rectangle(21, 93, 351, 15));
77     jPanel1.setBorder(BorderFactory.createEtchedBorder());
78     jPanel1.setLayout(null);
79     jPanel1.add(jLabel1);
80     jPanel1.add(nameTB);
81     jPanel1.add(urlTB);
82     jPanel1.add(jLabel2);
83     jPanel1.add(jLabel3);
84     jPanel1.add(jLabel4);
85     this.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
86             GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
87                     5, 4, 6, 5), 390, 130));
88   }
89
90   public void setName(String name)
91   {
92     nameTB.setText(name);
93   }
94
95   public void setURL(String url)
96   {
97     urlTB.setText(url);
98   }
99
100   public String getName()
101   {
102     return nameTB.getText();
103   }
104
105   public String getURL()
106   {
107     return urlTB.getText();
108   }
109
110   public boolean checkValid()
111   {
112     UrlLink ul = new UrlLink("foo|" + urlTB.getText().trim());
113     if (ul.isValid() && ul.isDynamic())
114     {
115       return true;
116     }
117
118     JOptionPane
119             .showInternalMessageDialog(
120                     jalview.gui.Desktop.desktop,
121                     "Sequence URL must contain $SEQUENCE_ID$ or a regex $SEQUENCE_ID=/<regex>/=$",
122                     "URL not valid", JOptionPane.WARNING_MESSAGE);
123     return false;
124   }
125
126   JTextField nameTB = new JTextField();
127
128   JTextField urlTB = new JTextField();
129
130   JLabel jLabel1 = new JLabel();
131
132   JLabel jLabel2 = new JLabel();
133
134   JLabel jLabel3 = new JLabel();
135
136   JLabel jLabel4 = new JLabel();
137
138   JPanel jPanel1 = new JPanel();
139
140   GridBagLayout gridBagLayout1 = new GridBagLayout();
141
142   public void nameTB_keyTyped(KeyEvent e)
143   {
144     if (e.getKeyChar() == '|')
145     {
146       e.consume();
147     }
148   }
149
150   public void urlTB_keyTyped(KeyEvent e)
151   {
152     // URLLink object validation takes care of incorrect regexes.
153     // if (e.getKeyChar() == '|' || e.getKeyChar() == ' ')
154     // {
155     // e.consume();
156     // }
157
158   }
159 }