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

use JList

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@1692 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent 3f8b7b6f
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* *
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/AlignMatchViewer.java,v 1.1 2004-06-09 09:45:58 tjc Exp $ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/AlignMatchViewer.java,v 1.2 2004-07-01 13:41:26 tjc Exp $
*/ */
package uk.ac.sanger.artemis.components; package uk.ac.sanger.artemis.components;
...@@ -31,7 +31,8 @@ import java.awt.*; ...@@ -31,7 +31,8 @@ import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import java.util.Comparator; import java.util.Comparator;
import java.util.Collections; import java.util.Collections;
...@@ -39,10 +40,54 @@ import java.util.Collections; ...@@ -39,10 +40,54 @@ import java.util.Collections;
* A component for viewing AlignMatchVectors selected in an AlignmentViewer. * A component for viewing AlignMatchVectors selected in an AlignmentViewer.
* *
* @author Kim Rutherford * @author Kim Rutherford
* @version $Id: AlignMatchViewer.java,v 1.1 2004-06-09 09:45:58 tjc Exp $ * @version $Id: AlignMatchViewer.java,v 1.2 2004-07-01 13:41:26 tjc Exp $
**/
public class AlignMatchViewer extends JFrame
{
/**
* The AlignmentViewer to call alignAt () and setSelection () on when the
* user clicks on a match.
**/
private AlignmentViewer alignment_viewer = null;
/**
* The Vector of AlignMatch objects that was passed to the constructor.
**/
private AlignMatchVector matches = null;
/**
* The list that contains the matches.
**/
private JList list;
/**
* If selected the list items will be sorted by score.
**/
private JCheckBoxMenuItem sort_by_score_menu_item =
new JCheckBoxMenuItem ("Sort by Score");
/**
* If selected the list items will be sorted by percent identity.
**/
private JCheckBoxMenuItem sort_by_percent_id_menu_item =
new JCheckBoxMenuItem ("Sort by Percent Identity");
/**
* If selected the list items will be sorted by the start position of the
* query.
**/
private JCheckBoxMenuItem sort_by_query_start =
new JCheckBoxMenuItem ("Sort by Hit Query Start");
/**
* If selected the list items will be sorted by the start position of the
* subject.
**/ **/
private JCheckBoxMenuItem sort_by_subject_start =
new JCheckBoxMenuItem ("Sort by Hit Subject start");
public class AlignMatchViewer extends JFrame {
/** /**
* Create a new AlignMatchViewer which shows the given matches. * Create a new AlignMatchViewer which shows the given matches.
* @param alignment_viewer The AlignmentViewer to call alignAt () and * @param alignment_viewer The AlignmentViewer to call alignAt () and
...@@ -50,61 +95,67 @@ public class AlignMatchViewer extends JFrame { ...@@ -50,61 +95,67 @@ public class AlignMatchViewer extends JFrame {
* @param matches The Vector of AlignMatch objects to show. * @param matches The Vector of AlignMatch objects to show.
**/ **/
public AlignMatchViewer(final AlignmentViewer alignment_viewer, public AlignMatchViewer(final AlignmentViewer alignment_viewer,
final AlignMatchVector matches) { final AlignMatchVector matches)
{
this.alignment_viewer = alignment_viewer; this.alignment_viewer = alignment_viewer;
this.matches = matches; this.matches = matches;
final JMenuBar menu_bar = new JMenuBar(); final JMenuBar menu_bar = new JMenuBar();
final JMenu file_menu = new JMenu("File"); final JMenu file_menu = new JMenu("File");
final JMenuItem close = new JMenuItem("Close"); final JMenuItem close = new JMenuItem("Close");
close.addActionListener (new ActionListener () { close.addActionListener(new ActionListener ()
public void actionPerformed (ActionEvent event) { {
public void actionPerformed (ActionEvent event)
{
setVisible (false); setVisible (false);
AlignMatchViewer.this.dispose (); AlignMatchViewer.this.dispose ();
} }
}); });
file_menu.add (close); file_menu.add (close);
menu_bar.add (file_menu); menu_bar.add (file_menu);
final JMenu sort_menu = new JMenu("Sort"); final JMenu sort_menu = new JMenu("Sort");
sort_menu.add(sort_by_score_menu_item); sort_menu.add(sort_by_score_menu_item);
sort_by_score_menu_item.addItemListener (new ItemListener () { sort_by_score_menu_item.addItemListener(new ItemListener ()
public void itemStateChanged(ItemEvent e) { {
if (sort_by_score_menu_item.getState ()) { public void itemStateChanged(ItemEvent e)
{
if (sort_by_score_menu_item.getState())
{
sort_by_percent_id_menu_item.setState (false); sort_by_percent_id_menu_item.setState (false);
sort_by_query_start.setState (false); sort_by_query_start.setState (false);
sort_by_subject_start.setState (false); sort_by_subject_start.setState (false);
} }
setList (); setList ();
} }
}); });
sort_menu.add (sort_by_percent_id_menu_item); sort_menu.add (sort_by_percent_id_menu_item);
sort_by_percent_id_menu_item.addItemListener (new ItemListener () { sort_by_percent_id_menu_item.addItemListener(new ItemListener()
public void itemStateChanged(ItemEvent e) { {
if (sort_by_percent_id_menu_item.getState ()) { public void itemStateChanged(ItemEvent e)
{
if(sort_by_percent_id_menu_item.getState())
{
sort_by_score_menu_item.setState(false); sort_by_score_menu_item.setState(false);
sort_by_query_start.setState(false); sort_by_query_start.setState(false);
sort_by_subject_start.setState (false); sort_by_subject_start.setState (false);
} }
setList (); setList ();
} }
}); });
sort_menu.add (sort_by_query_start); sort_menu.add (sort_by_query_start);
sort_by_query_start.addItemListener (new ItemListener () { sort_by_query_start.addItemListener(new ItemListener()
public void itemStateChanged(ItemEvent e) { {
if (sort_by_query_start.getState ()) { public void itemStateChanged(ItemEvent e)
{
if(sort_by_query_start.getState())
{
sort_by_percent_id_menu_item.setState(false); sort_by_percent_id_menu_item.setState(false);
sort_by_score_menu_item.setState(false); sort_by_score_menu_item.setState(false);
sort_by_subject_start.setState(false); sort_by_subject_start.setState(false);
...@@ -116,14 +167,16 @@ public class AlignMatchViewer extends JFrame { ...@@ -116,14 +167,16 @@ public class AlignMatchViewer extends JFrame {
sort_menu.add(sort_by_subject_start); sort_menu.add(sort_by_subject_start);
sort_by_subject_start.addItemListener (new ItemListener () { sort_by_subject_start.addItemListener(new ItemListener()
public void itemStateChanged(ItemEvent e) { {
if (sort_by_subject_start.getState ()) { public void itemStateChanged(ItemEvent e)
{
if(sort_by_subject_start.getState())
{
sort_by_percent_id_menu_item.setState(false); sort_by_percent_id_menu_item.setState(false);
sort_by_score_menu_item.setState(false); sort_by_score_menu_item.setState(false);
sort_by_query_start.setState(false); sort_by_query_start.setState(false);
} }
setList (); setList ();
} }
}); });
...@@ -132,7 +185,7 @@ public class AlignMatchViewer extends JFrame { ...@@ -132,7 +185,7 @@ public class AlignMatchViewer extends JFrame {
setJMenuBar(menu_bar); setJMenuBar(menu_bar);
list = new List (); list = new JList();
list.setBackground(Color.white); list.setBackground(Color.white);
...@@ -143,22 +196,28 @@ public class AlignMatchViewer extends JFrame { ...@@ -143,22 +196,28 @@ public class AlignMatchViewer extends JFrame {
final JButton close_button = new JButton("Close"); final JButton close_button = new JButton("Close");
panel.add(close_button); panel.add(close_button);
close_button.addActionListener (new ActionListener () { close_button.addActionListener(new ActionListener()
public void actionPerformed (ActionEvent e) { {
public void actionPerformed(ActionEvent e)
{
AlignMatchViewer.this.dispose (); AlignMatchViewer.this.dispose ();
} }
}); });
close_button.addActionListener (new ActionListener () { close_button.addActionListener(new ActionListener()
public void actionPerformed (ActionEvent e) { {
public void actionPerformed(ActionEvent e)
{
AlignMatchViewer.this.dispose(); AlignMatchViewer.this.dispose();
} }
}); });
getContentPane().add(panel, "South"); getContentPane().add(panel, "South");
addWindowListener (new WindowAdapter () { addWindowListener(new WindowAdapter()
public void windowClosing (WindowEvent event) { {
public void windowClosing(WindowEvent event)
{
AlignMatchViewer.this.dispose(); AlignMatchViewer.this.dispose();
} }
}); });
...@@ -172,11 +231,10 @@ public class AlignMatchViewer extends JFrame { ...@@ -172,11 +231,10 @@ public class AlignMatchViewer extends JFrame {
int screen_height = screen.height; int screen_height = screen.height;
int screen_width = screen.width; int screen_width = screen.width;
if (screen_height <= 600) { if(screen_height <= 600)
setSize (350, screen_height * 9 / 10); setSize (350, screen_height * 9 / 10);
} else { else
setSize (350, screen_height - 200); setSize (350, screen_height - 200);
}
setLocation(new Point (screen.width - getSize ().width - 5, setLocation(new Point (screen.width - getSize ().width - 5,
(screen.height - getSize ().height) / 2)); (screen.height - getSize ().height) / 2));
...@@ -186,129 +244,154 @@ public class AlignMatchViewer extends JFrame { ...@@ -186,129 +244,154 @@ public class AlignMatchViewer extends JFrame {
* Sort the matches depending on the setting of sort_by_score_menu_item and * Sort the matches depending on the setting of sort_by_score_menu_item and
* sort_by_percent_id_menu_item. * sort_by_percent_id_menu_item.
**/ **/
private AlignMatchVector getSortedMatches () { private AlignMatchVector getSortedMatches()
{
final AlignMatchVector matches_copy = (AlignMatchVector)matches.clone(); final AlignMatchVector matches_copy = (AlignMatchVector)matches.clone();
final Comparator comparator; final Comparator comparator;
if (sort_by_score_menu_item.getState ()) { if(sort_by_score_menu_item.getState())
{
comparator = comparator =
new Comparator () { new Comparator ()
public int compare (Object fst, Object snd) { {
public int compare (Object fst, Object snd)
{
final int fst_score = ((AlignMatch)fst).getScore(); final int fst_score = ((AlignMatch)fst).getScore();
final int snd_score = ((AlignMatch)snd).getScore(); final int snd_score = ((AlignMatch)snd).getScore();
if (fst_score < snd_score) { if (fst_score < snd_score)
return 1; return 1;
} else { else
if (fst_score > snd_score) { {
if (fst_score > snd_score)
return -1; return -1;
} else { else
return 0; return 0;
} }
} }
}
}; };
} else { }
if (sort_by_percent_id_menu_item.getState ()) { else
{
if(sort_by_percent_id_menu_item.getState())
{
comparator = comparator =
new Comparator () { new Comparator()
public int compare (Object fst, Object snd) { {
public int compare (Object fst, Object snd)
{
final int fst_value = ((AlignMatch)fst).getPercentID(); final int fst_value = ((AlignMatch)fst).getPercentID();
final int snd_value = ((AlignMatch)snd).getPercentID(); final int snd_value = ((AlignMatch)snd).getPercentID();
if (fst_value < snd_value) { if (fst_value < snd_value)
return 1; return 1;
} else { else
if (fst_value > snd_value) { {
if(fst_value > snd_value)
return -1; return -1;
} else { else
return 0; return 0;
} }
} }
}
}; };
} else { }
if (sort_by_query_start.getState ()) { else
{
if(sort_by_query_start.getState())
{
comparator = comparator =
new Comparator () { new Comparator()
public int compare (Object fst, Object snd) { {
public int compare(Object fst, Object snd)
{
final int fst_value = final int fst_value =
((AlignMatch)fst).getQuerySequenceStart(); ((AlignMatch)fst).getQuerySequenceStart();
final int snd_value = final int snd_value =
((AlignMatch)snd).getQuerySequenceStart(); ((AlignMatch)snd).getQuerySequenceStart();
if (fst_value > snd_value) { if(fst_value > snd_value)
return 1; return 1;
} else { else
if (fst_value < snd_value) { {
if (fst_value < snd_value)
return -1; return -1;
} else { else
return 0; return 0;
} }
} }
}
}; };
} else { }
if (sort_by_subject_start.getState ()) { else
{
if(sort_by_subject_start.getState())
{
comparator = comparator =
new Comparator () { new Comparator()
public int compare (Object fst, Object snd) { {
public int compare (Object fst, Object snd)
{
final int fst_value = final int fst_value =
((AlignMatch)fst).getSubjectSequenceStart(); ((AlignMatch)fst).getSubjectSequenceStart();
final int snd_value = final int snd_value =
((AlignMatch)snd).getSubjectSequenceStart(); ((AlignMatch)snd).getSubjectSequenceStart();
if (fst_value > snd_value) { if (fst_value > snd_value)
return 1; return 1;
} else { else
if (fst_value < snd_value) { {
if (fst_value < snd_value)
return -1; return -1;
} else { else
return 0; return 0;
} }
} }
}
}; };
} else {
return matches;
} }
else
return matches;
} }
} }
} }
matches_copy.sort(comparator); matches_copy.sort(comparator);
return matches_copy; return matches_copy;
} }
/** /**
* Clear the List and then fill it with the matches in the order * Clear the List and then fill it with the matches in the order
**/ **/
private void setList () { private void setList ()
{
final AlignMatchVector sorted_matches = getSortedMatches(); final AlignMatchVector sorted_matches = getSortedMatches();
list.setEnabled(false); list.setEnabled(false);
list.setVisible(false); list.setVisible(false);
list.removeAll(); list.removeAll();
for (int i = 0 ; i < sorted_matches.size () ; ++i) { String listItems[] = new String[sorted_matches.size()];
for(int i = 0 ; i<sorted_matches.size() ; ++i)
{
final AlignMatch this_align_match = sorted_matches.elementAt(i); final AlignMatch this_align_match = sorted_matches.elementAt(i);
String match_string = listItems[i] = new String(
this_align_match.getQuerySequenceStart() + ".." + this_align_match.getQuerySequenceStart() + ".." +
this_align_match.getQuerySequenceEnd() + " -> " + this_align_match.getQuerySequenceEnd() + " -> " +
this_align_match.getSubjectSequenceStart() + ".." + this_align_match.getSubjectSequenceStart() + ".." +
this_align_match.getSubjectSequenceEnd() + " " + this_align_match.getSubjectSequenceEnd() + " " +
(this_align_match.isRevMatch() ? "rev " : "") + (this_align_match.isRevMatch() ? "rev " : "") +
this_align_match.getPercentID() + "% id score " + this_align_match.getPercentID() + "% id score " +
this_align_match.getScore (); this_align_match.getScore() );
list.add (match_string);
} }
list.addItemListener (new ItemListener () { list.setListData(listItems);
public void itemStateChanged (final ItemEvent _) {
list.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
final int item_number = list.getSelectedIndex(); final int item_number = list.getSelectedIndex();
final AlignMatch selected_match = matches.elementAt(item_number); final AlignMatch selected_match = matches.elementAt(item_number);
...@@ -322,45 +405,4 @@ public class AlignMatchViewer extends JFrame { ...@@ -322,45 +405,4 @@ public class AlignMatchViewer extends JFrame {
list.setVisible(true); list.setVisible(true);
} }
/**
* The AlignmentViewer to call alignAt () and setSelection () on when the
* user clicks on a match.
**/
private AlignmentViewer alignment_viewer = null;
/**
* The Vector of AlignMatch objects that was passed to the constructor.
**/
private AlignMatchVector matches = null;
/**
* The list that contains the matches.
**/
private List list;
/**
* If selected the list items will be sorted by score.
**/
private JCheckBoxMenuItem sort_by_score_menu_item =
new JCheckBoxMenuItem ("Sort by Score");
/**
* If selected the list items will be sorted by percent identity.
**/
private JCheckBoxMenuItem sort_by_percent_id_menu_item =
new JCheckBoxMenuItem ("Sort by Percent Identity");
/**
* If selected the list items will be sorted by the start position of the
* query.
**/
private JCheckBoxMenuItem sort_by_query_start =
new JCheckBoxMenuItem ("Sort by Hit Query Start");
/**
* If selected the list items will be sorted by the start position of the
* subject.
**/
private JCheckBoxMenuItem sort_by_subject_start =
new JCheckBoxMenuItem ("Sort by Hit Subject start");
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment