Skip to content
Snippets Groups Projects
Commit ff4be7c8 authored by tjc's avatar tjc
Browse files

further development - addition of overwrite function and changes to the look of the tool

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@10218 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent 0898f022
Branches
Tags
No related merge requests found
/* TransferAnnotationTool.java /* TransferAnnotationTool.java
* *
* created: 2008 * created: 2009
* *
* This file is part of Artemis * This file is part of Artemis
* *
* Copyright (C) 2008 Genome Research Limited * Copyright (C) 2009 Genome Research Limited
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
package uk.ac.sanger.artemis.components; package uk.ac.sanger.artemis.components;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.FlowLayout; import java.awt.FlowLayout;
...@@ -44,11 +45,13 @@ import java.util.Vector; ...@@ -44,11 +45,13 @@ import java.util.Vector;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import uk.ac.sanger.artemis.Entry; import uk.ac.sanger.artemis.Entry;
...@@ -95,9 +98,18 @@ class TransferAnnotationTool extends JFrame ...@@ -95,9 +98,18 @@ class TransferAnnotationTool extends JFrame
"transmembrane", "transmembrane",
"previous_systematic_id" "previous_systematic_id"
}; };
private static org.apache.log4j.Logger logger4j = private static org.apache.log4j.Logger logger4j =
org.apache.log4j.Logger.getLogger(TransferAnnotationTool.class); org.apache.log4j.Logger.getLogger(TransferAnnotationTool.class);
private Color STEEL_BLUE = new Color(25, 25, 112);
/**
* Tool for transferring annotation from one feature to other feature(s)
* @param feature
* @param entryGroup
* @param geneNames
*/
public TransferAnnotationTool(final Feature feature, public TransferAnnotationTool(final Feature feature,
final EntryGroup entryGroup, final EntryGroup entryGroup,
final List geneNames) final List geneNames)
...@@ -109,19 +121,48 @@ class TransferAnnotationTool extends JFrame ...@@ -109,19 +121,48 @@ class TransferAnnotationTool extends JFrame
JPanel panel = new JPanel(flow); JPanel panel = new JPanel(flow);
JPanel pane = new JPanel(new GridBagLayout()); JPanel pane = new JPanel(new GridBagLayout());
JScrollPane jsp = new JScrollPane(panel); JScrollPane jsp = new JScrollPane(panel);
panel.setBackground(Color.white);
pane.setBackground(Color.white);
panel.add(pane); panel.add(pane);
JPanel framePanel = (JPanel)getContentPane(); JPanel framePanel = (JPanel)getContentPane();
framePanel.add(jsp, BorderLayout.CENTER); framePanel.add(jsp, BorderLayout.CENTER);
framePanel.setPreferredSize(new Dimension(600,600)); framePanel.setPreferredSize(new Dimension(600,600));
final Vector geneNameCheckBoxes = new Vector();
final Hashtable qualifierCheckBoxes = new Hashtable();
addMainPanel(feature, pane, qualifierCheckBoxes,
geneNameCheckBoxes, geneNames);
addBottomButtons(qualifierCheckBoxes, geneNameCheckBoxes,
framePanel, feature, entryGroup);
pack();
setVisible(true);
}
/**
* Construct the panel for setting up the gene list and the
* list of qualifiers to transfer.
* @param feature
* @param pane
* @param qualifierCheckBoxes
* @param geneNameCheckBoxes
* @param geneNames
*/
private void addMainPanel(final Feature feature,
final JPanel pane,
final Hashtable qualifierCheckBoxes,
final Vector geneNameCheckBoxes,
final List geneNames)
{
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
int nrows = 0; int nrows = 0;
c.anchor = GridBagConstraints.NORTHWEST; c.anchor = GridBagConstraints.NORTHWEST;
c.gridx = 2; c.gridx = 2;
c.gridy = 0; c.gridy = 0;
c.ipadx = 0;
JLabel geneLabel = new JLabel(feature.getIDString() + " Qualifiers"); JLabel geneLabel = new JLabel(feature.getIDString() + " Qualifiers");
geneLabel.setFont(geneLabel.getFont().deriveFont(Font.BOLD)); geneLabel.setFont(geneLabel.getFont().deriveFont(Font.BOLD));
...@@ -136,7 +177,6 @@ class TransferAnnotationTool extends JFrame ...@@ -136,7 +177,6 @@ class TransferAnnotationTool extends JFrame
c.gridy = ++nrows; c.gridy = ++nrows;
c.anchor = GridBagConstraints.WEST; c.anchor = GridBagConstraints.WEST;
final Hashtable qualifierCheckBoxes = new Hashtable();
final QualifierVector qualifiers = feature.getQualifiers(); final QualifierVector qualifiers = feature.getQualifiers();
for(int i = 0; i < qualifiers.size(); i++) for(int i = 0; i < qualifiers.size(); i++)
{ {
...@@ -179,7 +219,6 @@ class TransferAnnotationTool extends JFrame ...@@ -179,7 +219,6 @@ class TransferAnnotationTool extends JFrame
c.gridheight = nrows; c.gridheight = nrows;
c.fill = GridBagConstraints.BOTH; c.fill = GridBagConstraints.BOTH;
final Vector geneNameCheckBoxes = new Vector();
final Box geneNameBox = Box.createVerticalBox(); final Box geneNameBox = Box.createVerticalBox();
pane.add(geneNameBox, c); pane.add(geneNameBox, c);
...@@ -213,7 +252,7 @@ class TransferAnnotationTool extends JFrame ...@@ -213,7 +252,7 @@ class TransferAnnotationTool extends JFrame
}); });
pane.add(toggle, c); pane.add(toggle, c);
Box xBox = Box.createHorizontalBox();
final JButton toggleGeneList = new JButton("Toggle"); final JButton toggleGeneList = new JButton("Toggle");
toggleGeneList.addActionListener(new ActionListener() toggleGeneList.addActionListener(new ActionListener()
{ {
...@@ -226,25 +265,76 @@ class TransferAnnotationTool extends JFrame ...@@ -226,25 +265,76 @@ class TransferAnnotationTool extends JFrame
} }
} }
}); });
xBox.add(toggleGeneList);
final JButton addGenes = new JButton("Add");
addGenes.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JTextArea geneNameTextArea = new JTextArea();
geneNameTextArea.setEditable(true);
JScrollPane jsp = new JScrollPane(geneNameTextArea);
int res = JOptionPane.showConfirmDialog(TransferAnnotationTool.this,
jsp, "Paste Features to Add",
JOptionPane.OK_CANCEL_OPTION);
if(res == JOptionPane.CANCEL_OPTION)
return;
String geneNames[] = geneNameTextArea.getText().split("\\s");
for(int i=0;i<geneNames.length; i++)
{
if(geneNames[i] == null || geneNames[i].equals(""))
continue;
JCheckBox cb = new JCheckBox(geneNames[i],true);
geneNameBox.add(cb);
geneNameCheckBoxes.add(cb);
}
pane.revalidate();
}
});
xBox.add(addGenes);
c.gridx = 0; c.gridx = 0;
pane.add(toggleGeneList, c); pane.add(xBox, c);
}
/**
* Add panel for the transfer and close button.
* @param qualifierCheckBoxes
* @param geneNameCheckBoxes
* @param framePanel
* @param feature
* @param entryGroup
*/
private void addBottomButtons(final Hashtable qualifierCheckBoxes,
final Vector geneNameCheckBoxes,
final JPanel framePanel,
final Feature feature,
final EntryGroup entryGroup)
{
final JCheckBox sameKeyCheckBox = new JCheckBox("Add to feature of same key", true); final JCheckBox sameKeyCheckBox = new JCheckBox("Add to feature of same key", true);
final JCheckBox overwriteCheckBox = new JCheckBox("Overwrite", false);
overwriteCheckBox.setToolTipText("overwrite rather than append values");
Box buttonBox = Box.createHorizontalBox(); Box buttonBox = Box.createHorizontalBox();
final JButton transfer = new JButton(">>TRANSFER"); final JButton transfer = new JButton(">>TRANSFER");
transfer.setToolTipText("transfer annotation");
transfer.addActionListener(new ActionListener() transfer.addActionListener(new ActionListener()
{ {
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
transferAnnotation(qualifierCheckBoxes, geneNameCheckBoxes, feature, transferAnnotation(qualifierCheckBoxes, geneNameCheckBoxes, feature,
entryGroup, sameKeyCheckBox.isSelected()); entryGroup, sameKeyCheckBox.isSelected(),
overwriteCheckBox.isSelected());
} }
}); });
Box yBox = Box.createVerticalBox(); Box yBox = Box.createVerticalBox();
yBox.add(transfer); yBox.add(transfer);
yBox.add(sameKeyCheckBox); yBox.add(sameKeyCheckBox);
yBox.add(overwriteCheckBox);
buttonBox.add(yBox); buttonBox.add(yBox);
final JButton close = new JButton("CLOSE"); final JButton close = new JButton("CLOSE");
...@@ -261,11 +351,17 @@ class TransferAnnotationTool extends JFrame ...@@ -261,11 +351,17 @@ class TransferAnnotationTool extends JFrame
buttonBox.add(yBox); buttonBox.add(yBox);
buttonBox.add(Box.createHorizontalGlue()); buttonBox.add(Box.createHorizontalGlue());
framePanel.add(buttonBox, BorderLayout.SOUTH); framePanel.add(buttonBox, BorderLayout.SOUTH);
pack();
setVisible(true);
} }
/**
* Set up the expander button to display qualifier values.
* @param butt - expander button
* @param qualifier - the qualifer that is being displayed
* @param qualifierValueBox - Box containing the values
* @param qualifierNameCheckBox - JCheckBox for the given qualifier
* @param pane
* @return
*/
private Vector setExpanderButton(final JButton butt, private Vector setExpanderButton(final JButton butt,
final Qualifier qualifier, final Qualifier qualifier,
final Box qualifierValueBox, final Box qualifierValueBox,
...@@ -274,24 +370,21 @@ class TransferAnnotationTool extends JFrame ...@@ -274,24 +370,21 @@ class TransferAnnotationTool extends JFrame
{ {
butt.setMargin(new Insets(0, 0, 0, 0)); butt.setMargin(new Insets(0, 0, 0, 0));
butt.setHorizontalAlignment(SwingConstants.RIGHT); butt.setHorizontalAlignment(SwingConstants.RIGHT);
butt.setHorizontalTextPosition(SwingConstants.RIGHT);
butt.setBorderPainted(false); butt.setBorderPainted(false);
butt.setFont(new Font("SansSerif", Font.BOLD, 11)); butt.setFont(butt.getFont().deriveFont(Font.BOLD));
butt.setPreferredSize(new Dimension(butt.getPreferredSize().width,11)); butt.setForeground(STEEL_BLUE);
butt.addActionListener(new ActionListener() butt.addActionListener(new ActionListener()
{ {
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
if (butt.getText().equals("+")) if (butt.getText().equals("+"))
{
butt.setText("-"); butt.setText("-");
qualifierValueBox.setVisible(true);
}
else else
{
butt.setText("+"); butt.setText("+");
qualifierValueBox.setVisible(false);
} qualifierValueBox.setVisible(butt.getText().equals("-"));
pane.revalidate(); pane.revalidate();
} }
}); });
...@@ -304,6 +397,7 @@ class TransferAnnotationTool extends JFrame ...@@ -304,6 +397,7 @@ class TransferAnnotationTool extends JFrame
{ {
JCheckBox cb = new JCheckBox((String) values.get(i), JCheckBox cb = new JCheckBox((String) values.get(i),
qualifierNameCheckBox.isSelected()); qualifierNameCheckBox.isSelected());
cb.setFont(cb.getFont().deriveFont(Font.ITALIC));
qualifierValueBox.add(cb); qualifierValueBox.add(cb);
qualifierValuesCheckBox.add(cb); qualifierValuesCheckBox.add(cb);
} }
...@@ -327,17 +421,20 @@ class TransferAnnotationTool extends JFrame ...@@ -327,17 +421,20 @@ class TransferAnnotationTool extends JFrame
/** /**
* Transfer selected qualifiers to the list of features defined * Transfer selected qualifiers to the list of features defined
* by the names in the JTextArea * by the selected names.
* @param qualifierCheckBoxes - list of qualifier check boxes * @param qualifierCheckBoxes - list of qualifier check boxes
* @param geneNameTextArea - text with a list of feature names to transfer to * @param geneNameTextArea - text with a list of feature names to transfer to
* @param feature - feature to copy from * @param feature - feature to copy from
* @param entryGroup * @param entryGroup
* @param sameKey
* @param overwrite
*/ */
private void transferAnnotation(final Hashtable qualifierCheckBoxes, private void transferAnnotation(final Hashtable qualifierCheckBoxes,
final Vector geneNameCheckBoxes, final Vector geneNameCheckBoxes,
final Feature orginatingFeature, final Feature orginatingFeature,
final EntryGroup entryGroup, final EntryGroup entryGroup,
final boolean sameKey) final boolean sameKey,
final boolean overwrite)
{ {
setCursor(new Cursor(Cursor.WAIT_CURSOR)); setCursor(new Cursor(Cursor.WAIT_CURSOR));
// transfer selected annotation to genes // transfer selected annotation to genes
...@@ -407,7 +504,8 @@ class TransferAnnotationTool extends JFrame ...@@ -407,7 +504,8 @@ class TransferAnnotationTool extends JFrame
// transfer selected annotation // transfer selected annotation
entryGroup.getActionController().startAction(); entryGroup.getActionController().startAction();
geneNames = transfer(features, qualifiersToTransfer, key, geneNames = transfer(features, qualifiersToTransfer, key,
sameKey, GeneUtils.isDatabaseEntry(entryGroup), geneNames); sameKey, overwrite,
GeneUtils.isDatabaseEntry(entryGroup), geneNames);
entryGroup.getActionController().endAction(); entryGroup.getActionController().endAction();
// //
...@@ -453,7 +551,7 @@ class TransferAnnotationTool extends JFrame ...@@ -453,7 +551,7 @@ class TransferAnnotationTool extends JFrame
ctm.setEntryGroup(entry_group); ctm.setEntryGroup(entry_group);
transfer(entry.getAllFeatures(), qualifiersToTransfer, key, sameKey, transfer(entry.getAllFeatures(), qualifiersToTransfer, key, sameKey,
true, geneNames); overwrite, true, geneNames);
ChadoTransactionManager.commit((DatabaseDocument) newDbEntry ChadoTransactionManager.commit((DatabaseDocument) newDbEntry
.getDocument(), false, ctm); .getDocument(), false, ctm);
...@@ -485,6 +583,7 @@ class TransferAnnotationTool extends JFrame ...@@ -485,6 +583,7 @@ class TransferAnnotationTool extends JFrame
final QualifierVector qualifiersToTransfer, final QualifierVector qualifiersToTransfer,
final String key, final String key,
final boolean sameKey, final boolean sameKey,
final boolean overwrite,
final boolean isDatabaseEntry, final boolean isDatabaseEntry,
String[] geneNames) String[] geneNames)
{ {
...@@ -501,20 +600,25 @@ class TransferAnnotationTool extends JFrame ...@@ -501,20 +600,25 @@ class TransferAnnotationTool extends JFrame
Qualifier newQualifier = (Qualifier) qualifiersToTransfer.elementAt(j); Qualifier newQualifier = (Qualifier) qualifiersToTransfer.elementAt(j);
try try
{
if(overwrite)
thisFeature.setQualifier(newQualifier);
else
{ {
final StringVector oldValues; final StringVector oldValues;
if (thisFeature.getQualifierByName(newQualifier.getName()) == null) if (thisFeature.getQualifierByName(newQualifier.getName()) == null)
oldValues = null; oldValues = null;
else else
oldValues = oldValues = thisFeature.getQualifierByName(
thisFeature.getQualifierByName(newQualifier.getName()).getValues(); newQualifier.getName()).getValues();
final Qualifier newQualifierTmp = final Qualifier newQualifierTmp = getQualifierWithoutDuplicateValues(
getQualifierWithoutDuplicateValues(newQualifier, oldValues); newQualifier, oldValues);
if (newQualifierTmp == null) if (newQualifierTmp == null)
continue; continue;
thisFeature.addQualifierValues(newQualifierTmp); thisFeature.addQualifierValues(newQualifierTmp);
} }
}
catch (Exception e1) catch (Exception e1)
{ {
e1.printStackTrace(); e1.printStackTrace();
...@@ -647,4 +751,5 @@ class TransferAnnotationTool extends JFrame ...@@ -647,4 +751,5 @@ class TransferAnnotationTool extends JFrame
return geneName; return geneName;
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment