X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FFeatureSettings.java;h=5e15364d48c229f1f90bb65b762328007c14c758;hb=32c56f877253fa8917d4f4640ed65d6e63376dac;hp=40a2ce5fc497e39c74de1eeb81ec2c79d88aa193;hpb=2672f9a72ffb8ffaf4b48a08e64de7f3d83ce061;p=jalview.git diff --git a/src/jalview/appletgui/FeatureSettings.java b/src/jalview/appletgui/FeatureSettings.java index 40a2ce5..5e15364 100755 --- a/src/jalview/appletgui/FeatureSettings.java +++ b/src/jalview/appletgui/FeatureSettings.java @@ -20,11 +20,10 @@ */ package jalview.appletgui; +import jalview.api.FeatureColourI; import jalview.api.FeatureSettingsControllerI; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceFeature; -import jalview.schemes.AnnotationColourGradient; -import jalview.schemes.GraduatedColor; import jalview.util.MessageManager; import java.awt.BorderLayout; @@ -59,13 +58,15 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; 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 +public class FeatureSettings extends Panel + implements ItemListener, MouseListener, MouseMotionListener, + ActionListener, AdjustmentListener, FeatureSettingsControllerI { FeatureRenderer fr; @@ -95,14 +96,7 @@ public class FeatureSettings extends Panel implements ItemListener, transparency = new Scrollbar(Scrollbar.HORIZONTAL, 100 - (int) (fr.getTransparency() * 100), 1, 1, 100); - if (fr.isTransparencyAvailable()) - { - transparency.addAdjustmentListener(this); - } - else - { - transparency.setEnabled(false); - } + transparency.addAdjustmentListener(this); java.net.URL url = getClass().getResource("/images/link.gif"); if (url != null) @@ -114,6 +108,7 @@ public class FeatureSettings extends Panel implements ItemListener, { fr.findAllFeatures(true); // was default - now true to make all visible } + groupPanel = new Panel(); discoverAllFeatureData(); @@ -134,33 +129,29 @@ public class FeatureSettings extends Panel implements ItemListener, Panel tPanel = new Panel(new BorderLayout()); - if (fr.isTransparencyAvailable()) - { - tPanel.add(transparency, BorderLayout.CENTER); - tPanel.add(new Label("Transparency"), BorderLayout.EAST); - } - else - { - tPanel.add( - new Label("Transparency not available in this web browser"), - BorderLayout.CENTER); - } + tPanel.add(transparency, BorderLayout.CENTER); + tPanel.add(new Label("Transparency"), BorderLayout.EAST); lowerPanel.add(tPanel, BorderLayout.SOUTH); add(lowerPanel, BorderLayout.SOUTH); - if (groupPanel != null) - { - groupPanel.setLayout(new GridLayout( - (fr.getFeatureGroupsSize()) / 4 + 1, 4)); // JBPNote - this was - // scaled on number of - // visible groups. seems - // broken - groupPanel.validate(); + groupPanel.setLayout( + new GridLayout((fr.getFeatureGroupsSize()) / 4 + 1, 4)); // JBPNote + // - this + // was + // scaled + // on + // number + // of + // visible + // groups. + // seems + // broken + groupPanel.validate(); + + add(groupPanel, BorderLayout.NORTH); - add(groupPanel, BorderLayout.NORTH); - } frame = new Frame(); frame.add(this); final FeatureSettings me = this; @@ -191,24 +182,22 @@ public class FeatureSettings extends Panel implements ItemListener, public void paint(Graphics g) { g.setColor(Color.black); - g.drawString(MessageManager - .getString("label.no_features_added_to_this_alignment"), 10, 20); - g.drawString(MessageManager - .getString("label.features_can_be_added_from_searches_1"), 10, - 40); - g.drawString(MessageManager - .getString("label.features_can_be_added_from_searches_2"), 10, - 60); + g.drawString(MessageManager.getString( + "label.no_features_added_to_this_alignment"), 10, 20); + g.drawString(MessageManager.getString( + "label.features_can_be_added_from_searches_1"), 10, 40); + g.drawString(MessageManager.getString( + "label.features_can_be_added_from_searches_2"), 10, 60); } protected void popupSort(final MyCheckbox check, - final Map minmax, - int x, int y) + final Map minmax, int x, int y) { final String type = check.type; - final Object typeCol = fr.getFeatureStyle(type); - java.awt.PopupMenu men = new PopupMenu(MessageManager.formatMessage( - "label.settings_for_type", new String[] { type })); + final FeatureColourI typeCol = fr.getFeatureStyle(type); + PopupMenu men = new PopupMenu(MessageManager + .formatMessage("label.settings_for_type", new String[] + { type })); java.awt.MenuItem scr = new MenuItem( MessageManager.getString("label.sort_by_score")); men.add(scr); @@ -219,8 +208,9 @@ public class FeatureSettings extends Panel implements ItemListener, @Override public void actionPerformed(ActionEvent e) { - me.ap.alignFrame.avc.sortAlignmentByFeatureScore(Arrays - .asList(new String[] { type })); + me.ap.alignFrame.avc + .sortAlignmentByFeatureScore(Arrays.asList(new String[] + { type })); } }); @@ -232,12 +222,14 @@ public class FeatureSettings extends Panel implements ItemListener, @Override public void actionPerformed(ActionEvent e) { - me.ap.alignFrame.avc.sortAlignmentByFeatureDensity(Arrays - .asList(new String[] { type })); + me.ap.alignFrame.avc + .sortAlignmentByFeatureDensity(Arrays.asList(new String[] + { type })); } }); men.add(dens); + if (minmax != null) { final float[][] typeMinMax = minmax.get(type); @@ -258,7 +250,7 @@ public class FeatureSettings extends Panel implements ItemListener, // graduated colourschemes for those where minmax exists for the // positional features MenuItem mxcol = new MenuItem( - (typeCol instanceof Color) ? "Graduated Colour" + (typeCol.isSimpleColour()) ? "Graduated Colour" : "Single Colour"); men.add(mxcol); mxcol.addActionListener(new ActionListener() @@ -267,7 +259,7 @@ public class FeatureSettings extends Panel implements ItemListener, @Override public void actionPerformed(ActionEvent e) { - if (typeCol instanceof Color) + if (typeCol.isSimpleColour()) { new FeatureColourChooser(me, type); // write back the current colour object to update the table @@ -275,14 +267,64 @@ public class FeatureSettings extends Panel implements ItemListener, } else { - new UserDefinedColours(me, check.type, - ((GraduatedColor) typeCol)); + new UserDefinedColours(me, check.type, typeCol); } } }); } } + + MenuItem selectContaining = new MenuItem( + MessageManager.getString("label.select_columns_containing")); + selectContaining.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + me.ap.alignFrame.avc.markColumnsContainingFeatures(false, false, + false, type); + } + }); + men.add(selectContaining); + + MenuItem selectNotContaining = new MenuItem(MessageManager + .getString("label.select_columns_not_containing")); + selectNotContaining.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + me.ap.alignFrame.avc.markColumnsContainingFeatures(true, false, + false, type); + } + }); + men.add(selectNotContaining); + + MenuItem hideContaining = new MenuItem( + MessageManager.getString("label.hide_columns_containing")); + hideContaining.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + hideFeatureColumns(type, true); + } + }); + men.add(hideContaining); + + MenuItem hideNotContaining = new MenuItem( + MessageManager.getString("label.hide_columns_not_containing")); + hideNotContaining.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + hideFeatureColumns(type, false); + } + }); + men.add(hideNotContaining); + this.featurePanel.add(men); men.show(this.featurePanel, x, y); } @@ -293,44 +335,43 @@ public class FeatureSettings extends Panel implements ItemListener, if (fr.getAllFeatureColours() != null && fr.getAllFeatureColours().size() > 0) { - rebuildGroups(); + // rebuildGroups(); } resetTable(false); } /** - * rebuilds the group panel + * Answers the visibility of the given group, and adds a checkbox for it if + * there is not one already */ - public void rebuildGroups() + public boolean checkGroupState(String group) { - boolean rdrw = false; - if (groupPanel == null) - { - groupPanel = new Panel(); - } - else - { - rdrw = true; - groupPanel.removeAll(); - } - // TODO: JAL-964 - smoothly incorporate new group entries if panel already - // displayed and new groups present - for (String group : fr.getFeatureGroups()) - { - boolean vis = fr.checkGroupVisibility(group, false); - Checkbox check = new MyCheckbox(group, vis, false); - check.addMouseListener(this); - check.setFont(new Font("Serif", Font.BOLD, 12)); - check.addItemListener(groupItemListener); - // note - visibility seems to correlate with displayed. ???wtf ?? - check.setVisible(vis); - groupPanel.add(check); - } - if (rdrw) + boolean visible = fr.checkGroupVisibility(group, true); + + /* + * is there already a checkbox for this group? + */ + for (int g = 0; g < groupPanel.getComponentCount(); g++) { - groupPanel.validate(); + if (((Checkbox) groupPanel.getComponent(g)).getLabel().equals(group)) + { + ((Checkbox) groupPanel.getComponent(g)).setState(visible); + return visible; + } } + + /* + * add a new checkbox + */ + Checkbox check = new MyCheckbox(group, visible, false); + check.addMouseListener(this); + check.setFont(new Font("Serif", Font.BOLD, 12)); + check.addItemListener(groupItemListener); + groupPanel.add(check); + + groupPanel.validate(); + return visible; } // This routine adds and removes checkboxes depending on @@ -340,7 +381,9 @@ public class FeatureSettings extends Panel implements ItemListener, SequenceFeature[] tmpfeatures; String group = null, type; Vector visibleChecks = new Vector(); + Set foundGroups = new HashSet(); AlignmentI alignment = av.getAlignment(); + for (int i = 0; i < alignment.getHeight(); i++) { if (alignment.getSequenceAt(i).getSequenceFeatures() == null) @@ -353,8 +396,9 @@ public class FeatureSettings extends Panel implements ItemListener, while (index < tmpfeatures.length) { 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)) @@ -366,6 +410,11 @@ public class FeatureSettings extends Panel implements ItemListener, } } + /* + * remove any checkboxes for groups not present + */ + pruneGroups(foundGroups); + Component[] comps; int cSize = featurePanel.getComponentCount(); MyCheckbox check; @@ -412,8 +461,8 @@ public class FeatureSettings extends Panel implements ItemListener, addCheck(groupsChanged, en.nextElement().toString()); } - featurePanel.setLayout(new GridLayout(featurePanel.getComponentCount(), - 1, 10, 5)); + featurePanel.setLayout( + new GridLayout(featurePanel.getComponentCount(), 1, 10, 5)); featurePanel.validate(); if (scrollPane != null) @@ -425,6 +474,25 @@ public class FeatureSettings extends Panel implements ItemListener, } /** + * Remove from the groups panel any checkboxes for groups that are not in the + * foundGroups set. This enables removing a group from the display when the + * last feature in that group is deleted. + * + * @param foundGroups + */ + protected void pruneGroups(Set foundGroups) + { + for (int g = 0; g < groupPanel.getComponentCount(); g++) + { + Checkbox checkbox = (Checkbox) groupPanel.getComponent(g); + if (!foundGroups.contains(checkbox.getLabel())) + { + groupPanel.remove(checkbox); + } + } + } + + /** * update the checklist of feature types with the given type * * @param groupsChanged @@ -484,7 +552,7 @@ public class FeatureSettings extends Panel implements ItemListener, Checkbox check = (Checkbox) featurePanel.getComponent(i); check.setState(!check.getState()); } - selectionChanged(); + selectionChanged(true); } private ItemListener groupItemListener = new ItemListener() @@ -507,10 +575,10 @@ public class FeatureSettings extends Panel implements ItemListener, @Override public void itemStateChanged(ItemEvent evt) { - selectionChanged(); + selectionChanged(true); } - void selectionChanged() + void selectionChanged(boolean updateOverview) { Component[] comps = featurePanel.getComponents(); int cSize = comps.length; @@ -531,7 +599,7 @@ public class FeatureSettings extends Panel implements ItemListener, fr.setFeaturePriority(data); - ap.paintAlignment(true); + ap.paintAlignment(updateOverview); } MyCheckbox selectedCheck; @@ -573,8 +641,8 @@ public class FeatureSettings extends Panel implements ItemListener, } else { - comp = featurePanel.getComponentAt(evt.getX(), evt.getY() - + evt.getComponent().getLocation().y); + comp = featurePanel.getComponentAt(evt.getX(), + evt.getY() + evt.getComponent().getLocation().y); } if (comp != null && comp instanceof Checkbox) @@ -601,19 +669,9 @@ public class FeatureSettings extends Panel implements ItemListener, } } - public void setUserColour(String feature, Object originalColour) + public void setUserColour(String feature, FeatureColourI originalColour) { - if (originalColour instanceof Color - || originalColour instanceof GraduatedColor) - { - fr.setColour(feature, originalColour); - } - else - { - throw new Error( - MessageManager - .getString("error.implementation_error_unsupported_feature_colour_object")); - } + fr.setColour(feature, originalColour); refreshTable(); } @@ -650,10 +708,10 @@ public class FeatureSettings extends Panel implements ItemListener, if (evt.getClickCount() > 1) { - Object fcol = fr.getFeatureStyle(check.type); - if (fcol instanceof Color) + FeatureColourI fcol = fr.getFeatureStyle(check.type); + if (fcol.isSimpleColour()) { - new UserDefinedColours(this, check.type, (Color) fcol); + new UserDefinedColours(this, check.type, fcol.getColour()); } else { @@ -673,8 +731,7 @@ public class FeatureSettings extends Panel implements ItemListener, public void adjustmentValueChanged(AdjustmentEvent evt) { fr.setTransparency((100 - transparency.getValue()) / 100f); - ap.seqPanel.seqCanvas.repaint(); - + ap.paintAlignment(true); } class MyCheckbox extends Checkbox @@ -685,49 +742,34 @@ public class FeatureSettings extends Panel implements ItemListener, boolean hasLink; - GraduatedColor gcol; + FeatureColourI col; - Color col; - - public void updateColor(Object newcol) + public void updateColor(FeatureColourI newcol) { - if (newcol instanceof Color) - { - col = (Color) newcol; - gcol = null; - } - else if (newcol instanceof GraduatedColor) + col = newcol; + if (col.isSimpleColour()) { - gcol = (GraduatedColor) newcol; - col = null; - } - else - { - throw new Error( - MessageManager - .getString("error.invalid_colour_for_mycheckbox")); - } - if (col != null) - { - setBackground(col); + setBackground(col.getColour()); } else { String vlabel = type; - if (gcol.getThreshType() != AnnotationColourGradient.NO_THRESHOLD) + if (col.isAboveThreshold()) + { + vlabel += " (>)"; + } + else if (col.isBelowThreshold()) { - vlabel += " " - + ((gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD) ? "(>)" - : "(<)"); + vlabel += " (<)"; } - if (gcol.isColourByLabel()) + if (col.isColourByLabel()) { setBackground(Color.white); vlabel += " (by Label)"; } else { - setBackground(gcol.getMinColor()); + setBackground(col.getMinColour()); } this.setLabel(vlabel); } @@ -744,7 +786,7 @@ public class FeatureSettings extends Panel implements ItemListener, } public MyCheckbox(String type, boolean selected, boolean b, - Object featureStyle) + FeatureColourI featureStyle) { this(type, selected, b); updateColor(featureStyle); @@ -754,9 +796,9 @@ public class FeatureSettings extends Panel implements ItemListener, public void paint(Graphics g) { Dimension d = getSize(); - if (gcol != null) + if (col != null) { - if (gcol.isColourByLabel()) + if (col.isColourByLabel()) { g.setColor(Color.white); g.fillRect(d.width / 2, 0, d.width / 2, d.height); @@ -772,9 +814,9 @@ public class FeatureSettings extends Panel implements ItemListener, */ } - else + else if (col.isGraduatedColour()) { - Color maxCol = gcol.getMaxColor(); + Color maxCol = col.getMaxColour(); g.setColor(maxCol); g.fillRect(d.width / 2, 0, d.width / 2, d.height); @@ -789,9 +831,30 @@ public class FeatureSettings extends Panel implements ItemListener, } } + /** + * Hide columns containing (or not containing) a given feature type + * + * @param type + * @param columnsContaining + */ + void hideFeatureColumns(final String type, boolean columnsContaining) + { + if (ap.alignFrame.avc.markColumnsContainingFeatures(columnsContaining, + false, false, type)) + { + if (ap.alignFrame.avc.markColumnsContainingFeatures( + !columnsContaining, false, false, type)) + { + ap.alignFrame.viewport.hideSelectedColumns(); + } + } + } + @Override public void mousePressed(MouseEvent e) { + // TODO Auto-generated method stub + } }