X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FFeatureSettings.java;h=489cbb145d0bf7941f320502430479403782f43a;hb=71b8b157747abb849fb50316450a22d4559873da;hp=5e15364d48c229f1f90bb65b762328007c14c758;hpb=3d0101179759ef157b088ea135423cd909512d9f;p=jalview.git diff --git a/src/jalview/appletgui/FeatureSettings.java b/src/jalview/appletgui/FeatureSettings.java index 5e15364..489cbb1 100755 --- a/src/jalview/appletgui/FeatureSettings.java +++ b/src/jalview/appletgui/FeatureSettings.java @@ -23,8 +23,9 @@ package jalview.appletgui; import jalview.api.FeatureColourI; import jalview.api.FeatureSettingsControllerI; import jalview.datamodel.AlignmentI; -import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceI; import jalview.util.MessageManager; +import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean; import java.awt.BorderLayout; import java.awt.Button; @@ -56,17 +57,16 @@ import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.util.ArrayList; import java.util.Arrays; -import java.util.Enumeration; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.Vector; public class FeatureSettings extends Panel implements ItemListener, MouseListener, MouseMotionListener, - ActionListener, AdjustmentListener, FeatureSettingsControllerI + AdjustmentListener, FeatureSettingsControllerI { FeatureRenderer fr; @@ -121,8 +121,17 @@ public class FeatureSettings extends Panel add(scrollPane, BorderLayout.CENTER); } - Button invert = new Button("Invert Selection"); - invert.addActionListener(this); + Button invert = new Button( + MessageManager.getString("label.invert_selection")); + invert.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + invertSelection(); + } + }); Panel lowerPanel = new Panel(new GridLayout(2, 1, 5, 10)); lowerPanel.add(invert); @@ -378,36 +387,38 @@ public class FeatureSettings extends Panel // Group selection states void resetTable(boolean groupsChanged) { - SequenceFeature[] tmpfeatures; - String group = null, type; - Vector visibleChecks = new Vector(); - Set foundGroups = new HashSet(); + List displayableTypes = new ArrayList<>(); + Set foundGroups = new HashSet<>(); + AlignmentI alignment = av.getAlignment(); for (int i = 0; i < alignment.getHeight(); i++) { - if (alignment.getSequenceAt(i).getSequenceFeatures() == null) - { - continue; - } + SequenceI seq = alignment.getSequenceAt(i); - tmpfeatures = alignment.getSequenceAt(i).getSequenceFeatures(); - int index = 0; - while (index < tmpfeatures.length) + /* + * get the sequence's groups for positional features + * and keep track of which groups are visible + */ + Set groups = seq.getFeatures().getFeatureGroups(true); + Set visibleGroups = new HashSet<>(); + for (String group : groups) { - group = tmpfeatures[index].featureGroup; - foundGroups.add(group); - + // if (group == null || fr.checkGroupVisibility(group, true)) if (group == null || checkGroupState(group)) { - type = tmpfeatures[index].getType(); - if (!visibleChecks.contains(type)) - { - visibleChecks.addElement(type); - } + visibleGroups.add(group); } - index++; } + foundGroups.addAll(groups); + + /* + * get distinct feature types for visible groups + * record distinct visible types + */ + Set types = seq.getFeatures().getFeatureTypesForGroups(true, + visibleGroups.toArray(new String[visibleGroups.size()])); + displayableTypes.addAll(types); } /* @@ -424,7 +435,7 @@ public class FeatureSettings extends Panel { comps = featurePanel.getComponents(); check = (MyCheckbox) comps[i]; - if (!visibleChecks.contains(check.type)) + if (!displayableTypes.contains(check.type)) { featurePanel.remove(i); cSize--; @@ -441,24 +452,24 @@ public class FeatureSettings extends Panel { String item = rol.get(ro); - if (!visibleChecks.contains(item)) + if (!displayableTypes.contains(item)) { continue; } - visibleChecks.removeElement(item); + displayableTypes.remove(item); addCheck(false, item); } } - // now add checkboxes which should be visible, - // if they have not already been added - Enumeration en = visibleChecks.elements(); - - while (en.hasMoreElements()) + /* + * now add checkboxes which should be visible, + * if they have not already been added + */ + for (String type : displayableTypes) { - addCheck(groupsChanged, en.nextElement().toString()); + addCheck(groupsChanged, type); } featurePanel.setLayout( @@ -544,8 +555,7 @@ public class FeatureSettings extends Panel } } - @Override - public void actionPerformed(ActionEvent evt) + protected void invertSelection() { for (int i = 0; i < featurePanel.getComponentCount(); i++) { @@ -582,24 +592,21 @@ public class FeatureSettings extends Panel { Component[] comps = featurePanel.getComponents(); int cSize = comps.length; - - Object[][] tmp = new Object[cSize][3]; - int tmpSize = 0; - for (int i = 0; i < cSize; i++) - { - MyCheckbox check = (MyCheckbox) comps[i]; - tmp[tmpSize][0] = check.type; - tmp[tmpSize][1] = fr.getFeatureStyle(check.type); - tmp[tmpSize][2] = new Boolean(check.getState()); - tmpSize++; + FeatureSettingsBean[] rowData = new FeatureSettingsBean[cSize]; + int i = 0; + for (Component comp : comps) + { + MyCheckbox check = (MyCheckbox) comp; + // feature filter set to null as not (yet) offered in applet + FeatureColourI colour = fr.getFeatureStyle(check.type); + rowData[i] = new FeatureSettingsBean(check.type, colour, null, + check.getState()); + i++; } - Object[][] data = new Object[tmpSize][3]; - System.arraycopy(tmp, 0, data, 0, tmpSize); - - fr.setFeaturePriority(data); + fr.setFeaturePriority(rowData); - ap.paintAlignment(updateOverview); + ap.paintAlignment(updateOverview, updateOverview); } MyCheckbox selectedCheck; @@ -679,7 +686,7 @@ public class FeatureSettings extends Panel { featurePanel.removeAll(); resetTable(false); - ap.paintAlignment(true); + ap.paintAlignment(true, true); } @Override @@ -696,7 +703,7 @@ public class FeatureSettings extends Panel public void mouseClicked(MouseEvent evt) { MyCheckbox check = (MyCheckbox) evt.getSource(); - if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) != 0) + if ((evt.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0) { this.popupSort(check, fr.getMinMax(), evt.getX(), evt.getY()); } @@ -731,7 +738,7 @@ public class FeatureSettings extends Panel public void adjustmentValueChanged(AdjustmentEvent evt) { fr.setTransparency((100 - transparency.getValue()) / 100f); - ap.paintAlignment(true); + ap.paintAlignment(true, true); } class MyCheckbox extends Checkbox