From 2048bb8702d00ba7233d5463878ae7f2f1b99e40 Mon Sep 17 00:00:00 2001 From: kiramt Date: Fri, 2 Dec 2016 15:01:54 +0000 Subject: [PATCH] JAL-2316 GUI to allow to insert tokens into new URL by pressing button --- resources/lang/Messages.properties | 5 +- resources/lang/Messages_es.properties | 5 +- src/jalview/jbgui/GSequenceLink.java | 112 ++++++++++++++++++++++++++------- 3 files changed, 96 insertions(+), 26 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 045f58c..ffdf908 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1275,4 +1275,7 @@ label.do_not_display_again = Do not display this message again exception.url_cannot_have_miriam_id = {0} is a MIRIAM id and cannot be used as a custom url name exception.url_cannot_have_duplicate_id = {0} cannot be used as a label for more than one line label.filter = Filter text: -action.customfilter = Custom only \ No newline at end of file +action.customfilter = Custom only +label.insert = Insert: +action.seq_id = $SEQUENCE_ID$ +action.db_acc = $DB_ACCESSION$ \ No newline at end of file diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 9922e46..2ff5d71 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1276,4 +1276,7 @@ label.do_not_display_again = No mostrar este mensaje de nuevo exception.url_cannot_have_miriam_id = {0} is a MIRIAM id and cannot be used as a custom url name exception.url_cannot_have_duplicate_id = {0} cannot be used as a label for more than one link label.filter = Filter text: -action.customfilter = Custom only \ No newline at end of file +action.customfilter = Custom only +label.insert = Insert: +action.seq_id = $SEQUENCE_ID$ +action.db_acc = $DB_ACCESSION$ diff --git a/src/jalview/jbgui/GSequenceLink.java b/src/jalview/jbgui/GSequenceLink.java index f7914bf..46f64fe 100755 --- a/src/jalview/jbgui/GSequenceLink.java +++ b/src/jalview/jbgui/GSequenceLink.java @@ -29,10 +29,13 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.BorderFactory; +import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -41,6 +44,33 @@ import javax.swing.SwingConstants; public class GSequenceLink extends JPanel { + + JTextField nameTB = new JTextField(); + + JTextField urlTB = new JTextField(); + + JButton insertSeq = new JButton(); + + JButton insertDBAcc = new JButton(); + + JLabel insert = new JLabel(); + + JLabel jLabel1 = new JLabel(); + + JLabel jLabel2 = new JLabel(); + + JLabel jLabel3 = new JLabel(); + + JLabel jLabel4 = new JLabel(); + + JLabel jLabel5 = new JLabel(); + + JLabel jLabel6 = new JLabel(); + + JPanel jPanel1 = new JPanel(); + + GridBagLayout gridBagLayout1 = new GridBagLayout(); + public GSequenceLink() { try @@ -76,6 +106,36 @@ public class GSequenceLink extends JPanel urlTB_keyTyped(e); } }); + + insertSeq.setLocation(77, 75); + insertSeq.setSize(141, 24); + insertSeq.setText(MessageManager.getString("action.seq_id")); + insertSeq.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + insertSeq_action(e); + } + }); + + insertDBAcc.setLocation(210, 75); + insertDBAcc.setSize(141, 24); + insertDBAcc.setText(MessageManager.getString("action.db_acc")); + insertDBAcc.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + insertDBAcc_action(e); + } + }); + + insert.setText(MessageManager.getString("label.insert")); + insert.setFont(JvSwingUtils.getLabelFont()); + insert.setHorizontalAlignment(SwingConstants.RIGHT); + insert.setBounds(17, 78, 58, 16); + jLabel1.setFont(JvSwingUtils.getLabelFont()); jLabel1.setHorizontalAlignment(SwingConstants.TRAILING); jLabel1.setText(MessageManager.getString("label.link_name")); @@ -86,13 +146,13 @@ public class GSequenceLink extends JPanel jLabel2.setBounds(new Rectangle(17, 37, 54, 27)); jLabel3.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); jLabel3.setText(MessageManager.getString("label.use_sequence_id_1")); - jLabel3.setBounds(new Rectangle(21, 72, 351, 15)); + jLabel3.setBounds(new Rectangle(21, 102, 351, 15)); jLabel4.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); jLabel4.setText(MessageManager.getString("label.use_sequence_id_2")); - jLabel4.setBounds(new Rectangle(21, 88, 351, 15)); + jLabel4.setBounds(new Rectangle(21, 118, 351, 15)); jLabel5.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); jLabel5.setText(MessageManager.getString("label.use_sequence_id_3")); - jLabel5.setBounds(new Rectangle(21, 106, 351, 15)); + jLabel5.setBounds(new Rectangle(21, 136, 351, 15)); String lastLabel = MessageManager.getString("label.use_sequence_id_4"); if (lastLabel.length() > 0) @@ -100,7 +160,7 @@ public class GSequenceLink extends JPanel // e.g. Spanish version has longer text jLabel6.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); jLabel6.setText(lastLabel); - jLabel6.setBounds(new Rectangle(21, 122, 351, 15)); + jLabel6.setBounds(new Rectangle(21, 152, 351, 15)); } jPanel1.setBorder(BorderFactory.createEtchedBorder()); @@ -108,16 +168,19 @@ public class GSequenceLink extends JPanel jPanel1.add(jLabel1); jPanel1.add(nameTB); jPanel1.add(urlTB); + jPanel1.add(insertSeq); + jPanel1.add(insertDBAcc); + jPanel1.add(insert); jPanel1.add(jLabel2); jPanel1.add(jLabel3); jPanel1.add(jLabel4); jPanel1.add(jLabel5); - int height = 130; + int height = 160; if (lastLabel.length() > 0) { jPanel1.add(jLabel6); - height = 146; + height = 176; } this.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, @@ -162,25 +225,7 @@ public class GSequenceLink extends JPanel return false; } - JTextField nameTB = new JTextField(); - - JTextField urlTB = new JTextField(); - - JLabel jLabel1 = new JLabel(); - - JLabel jLabel2 = new JLabel(); - - JLabel jLabel3 = new JLabel(); - - JLabel jLabel4 = new JLabel(); - - JLabel jLabel5 = new JLabel(); - - JLabel jLabel6 = new JLabel(); - - JPanel jPanel1 = new JPanel(); - GridBagLayout gridBagLayout1 = new GridBagLayout(); public void nameTB_keyTyped(KeyEvent e) { @@ -199,4 +244,23 @@ public class GSequenceLink extends JPanel // } } + + public void insertSeq_action(ActionEvent e) + { + insertIntoUrl(insertSeq.getText()); + } + + public void insertDBAcc_action(ActionEvent e) + { + insertIntoUrl(insertDBAcc.getText()); + } + + private void insertIntoUrl(String insertion) + { + int pos = urlTB.getCaretPosition(); + String text = urlTB.getText(); + String newText = text.substring(0, pos) + insertion + + text.substring(pos); + urlTB.setText(newText); + } } -- 1.7.10.2