updated to jalview 2.1 and begun ArchiveClient/VamsasClient/VamsasStore updates.
[jalview.git] / src / jalview / jbgui / GSequenceLink.java
1 /*
2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18 */
19 package jalview.jbgui;
20
21 import java.awt.*;
22 import javax.swing.JTextField;
23 import javax.swing.JLabel;
24 import javax.swing.*;
25 import java.awt.event.KeyAdapter;
26 import java.awt.event.KeyEvent;
27
28 public class GSequenceLink
29     extends Panel
30 {
31   public GSequenceLink()
32   {
33     try
34     {
35       jbInit();
36     }
37     catch (Exception ex)
38     {
39       ex.printStackTrace();
40     }
41   }
42
43   private void jbInit()
44       throws Exception
45   {
46     this.setLayout(gridBagLayout1);
47     nameTB.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
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(new java.awt.Font("Verdana", Font.PLAIN, 11));
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(new java.awt.Font("Verdana", Font.PLAIN, 11));
67     jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
68     jLabel1.setText("Link Name");
69     jLabel1.setBounds(new Rectangle(4, 10, 71, 24));
70     jLabel2.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
71     jLabel2.setHorizontalAlignment(SwingConstants.TRAILING);
72     jLabel2.setText("URL");
73     jLabel2.setBounds(new Rectangle(17, 37, 54, 27));
74     jLabel3.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
75     jLabel3.setText("Use $SEQUENCE_ID$ to specify where sequence id is in URL");
76     jLabel3.setBounds(new Rectangle(21, 72, 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     this.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
85                                              , GridBagConstraints.CENTER,
86                                              GridBagConstraints.BOTH,
87                                              new Insets(5, 4, 6, 5), 390, 100));
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     if(urlTB.getText().indexOf("$SEQUENCE_ID$")==-1)
113     {
114       JOptionPane.showInternalMessageDialog(jalview.gui.Desktop.desktop,
115                                             "Sequence URL must contain $SEQUENCE_ID$",
116            "URL not valid", JOptionPane.WARNING_MESSAGE);
117       return false;
118     }
119     return true;
120   }
121
122
123
124   JTextField nameTB = new JTextField();
125   JTextField urlTB = new JTextField();
126   JLabel jLabel1 = new JLabel();
127   JLabel jLabel2 = new JLabel();
128   JLabel jLabel3 = new JLabel();
129   JPanel jPanel1 = new JPanel();
130   GridBagLayout gridBagLayout1 = new GridBagLayout();
131   public void nameTB_keyTyped(KeyEvent e)
132   {
133     if(e.getKeyChar()=='|')
134      {
135        e.consume();
136      }
137   }
138
139   public void urlTB_keyTyped(KeyEvent e)
140   {
141     if (e.getKeyChar() == '|' || e.getKeyChar()==' ')
142     {
143       e.consume();
144     }
145
146   }
147 }
148