X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FFeatureSettings.java;h=2eb203c37c5aad625b1937f9e3ac4cd6215a0680;hb=f2287ae5b61b6bf36ee90bd6bbf38d44331bf273;hp=4649786f1c363ff5c37f6b6736824885ac20a662;hpb=506d60f0e188723ddc91c26824b41ac7034df3fe;p=jalview.git diff --git a/src/jalview/appletgui/FeatureSettings.java b/src/jalview/appletgui/FeatureSettings.java index 4649786..2eb203c 100755 --- a/src/jalview/appletgui/FeatureSettings.java +++ b/src/jalview/appletgui/FeatureSettings.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) - * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1) + * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,6 +23,8 @@ import java.util.*; import java.awt.*; import java.awt.event.*; +import jalview.analysis.AlignmentSorter; +import jalview.commands.OrderCommand; import jalview.datamodel.*; public class FeatureSettings extends Panel implements ItemListener, @@ -152,6 +154,78 @@ public class FeatureSettings extends Panel implements ItemListener, g.drawString("(Features can be added from searches or", 10, 40); g.drawString("from Jalview / GFF features files)", 10, 60); } + protected void popupSort(final String type, final Hashtable minmax, + int x, int y) + { + java.awt.PopupMenu men = new PopupMenu("Settings for " + type); + java.awt.MenuItem scr = new MenuItem("Sort by Score"); + men.add(scr); + final FeatureSettings me = this; + scr.addActionListener(new ActionListener() + { + + public void actionPerformed(ActionEvent e) + { + me.sortByScore(new String[] + { type }); + } + + }); + MenuItem dens = new MenuItem("Sort by Density"); + dens.addActionListener(new ActionListener() + { + + public void actionPerformed(ActionEvent e) + { + me.sortByDens(new String[] + { type }); + } + + }); + men.add(dens); + if (minmax != null) + { + final Object typeMinMax = minmax.get(type); + final java.awt.CheckboxMenuItem chb = new java.awt.CheckboxMenuItem("Vary Height"); + // this is broken at the moment + chb.setState(minmax.get(type) != null); + chb.addActionListener(new ActionListener() + { + + public void actionPerformed(ActionEvent e) + { + chb.setState(chb.getState()); + if (chb.getState()) + { + minmax.put(type, null); + } + else + { + minmax.put(type, typeMinMax); + } + } + + }); + men.add(chb); + if (typeMinMax != null && ((float[][]) typeMinMax)[0] != null) + { + // graduated colourschemes for those where minmax exists for the positional features + MenuItem mxcol = new MenuItem("Min Max Colour"); + men.add(mxcol); + mxcol.addActionListener(new ActionListener() + { + + public void actionPerformed(ActionEvent e) + { + new FeatureColourChooser(me, type); + } + + }); + } + } + this.featurePanel.add(men); + men.show(this.featurePanel, x, y); + } public void setTableData() { @@ -502,7 +576,10 @@ public class FeatureSettings extends Panel implements ItemListener, public void mouseClicked(MouseEvent evt) { MyCheckbox check = (MyCheckbox) evt.getSource(); - + if ((evt.getModifiers() & InputEvent.BUTTON3_MASK)!=0) + { + this.popupSort(check.getLabel(), fr.minmax, evt.getX(), evt.getY()); + } if (fr.featureLinks != null && fr.featureLinks.containsKey(check.getLabel())) { @@ -562,4 +639,81 @@ public class FeatureSettings extends Panel implements ItemListener, } } } + protected void sortByDens(String[] typ) + { + sortBy(typ, "Sort by Density", AlignmentSorter.FEATURE_DENSITY); + } + private String[] getDisplayedFeatureTypes() + { + String[] typ = null; + if (fr != null) + { + synchronized (fr.renderOrder) + { + typ = new String[fr.renderOrder.length]; + System.arraycopy(fr.renderOrder, 0, typ, 0, typ.length); + for (int i = 0; i < typ.length; i++) + { + if (av.featuresDisplayed.get(typ[i]) == null) + { + typ[i] = null; + } + } + } + } + return typ; + } + + + protected void sortBy(String[] typ, String methodText, final String method) + { + if (typ == null) + { + typ = getDisplayedFeatureTypes(); + } + String gps[] = null; + gps = fr.getGroups(true); + if (typ != null) + { + for (int i = 0; i < typ.length; i++) + { + System.err.println("Sorting on Types:" + typ[i]); + } + } + if (gps != null) + { + + for (int i = 0; i < gps.length; i++) + { + System.err.println("Sorting on groups:" + gps[i]); + } + } + AlignmentPanel alignPanel = ap; + AlignmentI al = alignPanel.av.getAlignment(); + + int start, stop; + SequenceGroup sg = alignPanel.av.getSelectionGroup(); + if (sg != null) + { + start = sg.getStartRes(); + stop = sg.getEndRes(); + } + else + { + start = 0; + stop = al.getWidth(); + } + SequenceI[] oldOrder = al.getSequencesArray(); + AlignmentSorter.sortByFeature(typ, gps, start, stop, al, method); + this.ap.alignFrame.addHistoryItem(new OrderCommand(methodText, oldOrder, alignPanel.av + .getAlignment())); + alignPanel.paintAlignment(true); + + } + + protected void sortByScore(String[] typ) + { + sortBy(typ, "Sort by Feature Score", AlignmentSorter.FEATURE_SCORE); + } + }