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