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