From 0eca27bca577e774acd5aefb165e7c6396a1995e Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Wed, 11 Apr 2007 13:00:48 +0000 Subject: [PATCH] Amend features/annotations in applet --- src/jalview/appletgui/APopupMenu.java | 43 +- src/jalview/appletgui/AnnotationLabels.java | 112 ++- src/jalview/appletgui/AnnotationPanel.java | 359 +++++++- src/jalview/appletgui/AppletJmol.java | 5 +- src/jalview/appletgui/EditNameDialog.java | 68 +- src/jalview/appletgui/FeatureRenderer.java | 1201 +++++++++++++++---------- src/jalview/appletgui/Finder.java | 48 +- src/jalview/appletgui/ScalePanel.java | 9 +- src/jalview/appletgui/SeqPanel.java | 94 +- src/jalview/appletgui/UserDefinedColours.java | 74 +- 10 files changed, 1338 insertions(+), 675 deletions(-) diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index a103073..ede493e 100755 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -68,6 +68,7 @@ public class APopupMenu MenuItem hideSeqs = new MenuItem(); MenuItem repGroup = new MenuItem(); MenuItem sequenceName = new MenuItem("Edit Name/Description"); + MenuItem sequenceFeature = new MenuItem("Create Sequence Feature"); Sequence seq; MenuItem revealAll = new MenuItem(); @@ -302,8 +303,9 @@ public class APopupMenu getGroup().getDescription(), " Group Name", "Group Description", - ap, - "Edit Group Name / Description"); + ap.alignFrame, + "Edit Group Name / Description", + 500,100); if (dialog.accept) { @@ -398,6 +400,35 @@ public class APopupMenu } } + else if(source == sequenceFeature) + { + SequenceGroup sg = ap.av.getSelectionGroup(); + if (sg == null) + { + return; + } + + int gSize = sg.getSize(); + SequenceI[] seqs = new SequenceI[gSize]; + SequenceFeature[] features = new SequenceFeature[gSize]; + + for (int i = 0; i < gSize; i++) + { + seqs[i] = sg.getSequenceAt(i); + int start = sg.getSequenceAt(i).findPosition(sg.getStartRes()); + int end = sg.findEndRes(sg.getSequenceAt(i)); + features[i] = new SequenceFeature(null, null, null, start, end, + "Jalview"); + } + + if (ap.seqPanel.seqCanvas.getFeatureRenderer() + .createNewFeatures(seqs, features, ap)) + { + ap.alignFrame.sequenceFeatures.setState(true); + ap.av.showSequenceFeatures(true); + ap.highlightSearchResults(null); + } + } else { outputText(evt); @@ -429,8 +460,9 @@ public class APopupMenu seq.getDescription(), " Sequence Name", "Sequence Description", - ap, - "Edit Sequence Name / Description"); + ap.alignFrame, + "Edit Sequence Name / Description", + 500,100); if (dialog.accept) { @@ -455,6 +487,7 @@ public class APopupMenu { groupMenu.setLabel("Group"); groupMenu.setLabel("Selection"); + sequenceFeature.addActionListener(this); editGroupName.addActionListener(this); unGroupMenuItem.setLabel("Remove Group"); @@ -488,7 +521,9 @@ public class APopupMenu groupMenu.add(editGroupName); groupMenu.add(editMenu); groupMenu.add(outputmenu); + groupMenu.add(sequenceFeature); groupMenu.add(menu1); + colourMenu.add(noColourmenuItem); colourMenu.add(clustalColour); colourMenu.add(BLOSUM62Colour); diff --git a/src/jalview/appletgui/AnnotationLabels.java b/src/jalview/appletgui/AnnotationLabels.java index cb17e64..a952f9d 100755 --- a/src/jalview/appletgui/AnnotationLabels.java +++ b/src/jalview/appletgui/AnnotationLabels.java @@ -35,15 +35,16 @@ public class AnnotationLabels AlignViewport av; boolean resizing = false; int oldY, mouseX; - static String EDITNAME = "Edit label/description"; - static String HIDE = "Hide this row"; - static String DELETE = "Delete this row"; - static String SHOWALL = "Show all hidden rows"; + + static String ADDNEW = "Add New Row"; + static String EDITNAME = "Edit Label/Description"; + static String HIDE = "Hide This Row"; + static String SHOWALL = "Show All Hidden Rows"; static String OUTPUT_TEXT = "Show Values In Textbox"; static String COPYCONS_SEQ = "Copy Consensus Sequence"; - int selectedRow = 0; int scrollOffset = 0; + int selectedRow = -1; Tooltip tooltip; @@ -67,14 +68,14 @@ public class AnnotationLabels repaint(); } - void getSelectedRow(int y) + int getSelectedRow(int y) { - selectedRow = -1; + int row = -1; AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation(); if (aa == null) { - return; + return row; } int height = 0; @@ -88,34 +89,37 @@ public class AnnotationLabels height += aa[i].height; if (y < height) { - selectedRow = i; + row = i; break; } } + + return row; } public void actionPerformed(ActionEvent evt) { AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - if (evt.getActionCommand().equals(EDITNAME)) + if (evt.getActionCommand().equals(ADDNEW)) { - EditNameDialog dialog = new EditNameDialog( - aa[selectedRow].label, - aa[selectedRow].description, - " Annotation Label", - "Annotation Description", - ap, - "Edit Annotation Name / Description"); - - if (dialog.accept) + AlignmentAnnotation newAnnotation = new AlignmentAnnotation("", + null, + new Annotation[ap.av.alignment.getWidth()]); + + if (!editLabelDescription(newAnnotation)) { - aa[selectedRow].label = dialog.getName(); - aa[selectedRow].description = dialog.getDescription(); - repaint(); + return; } + + ap.av.alignment.addAnnotation(newAnnotation); + ap.av.alignment.setAnnotationIndex(newAnnotation, 0); + } + else if (evt.getActionCommand().equals(EDITNAME)) + { + editLabelDescription(aa[selectedRow]); } - if (evt.getActionCommand().equals(HIDE)) + else if (evt.getActionCommand().equals(HIDE)) { aa[selectedRow].visible = false; } @@ -151,23 +155,46 @@ public class AnnotationLabels ap.paintAlignment(true); } + boolean editLabelDescription(AlignmentAnnotation annotation) + { + EditNameDialog dialog = new EditNameDialog( + annotation.label, + annotation.description, + " Annotation Label", + "Annotation Description", + ap.alignFrame, + "Edit Annotation Name / Description", + 500, 100); + + if (dialog.accept) + { + annotation.label = dialog.getName(); + annotation.description = dialog.getDescription(); + repaint(); + return true; + } + else + return false; + + } + public void mouseMoved(MouseEvent evt) { - getSelectedRow(evt.getY() - scrollOffset); + int row = getSelectedRow(evt.getY() - scrollOffset); - if (selectedRow > -1) + if (row > -1) { if (tooltip == null) { tooltip = new Tooltip(ap.av.alignment. - getAlignmentAnnotation()[selectedRow]. + getAlignmentAnnotation()[row]. description, this); } else { tooltip.setTip(ap.av.alignment. - getAlignmentAnnotation()[selectedRow].description); + getAlignmentAnnotation()[row].description); } } else if (tooltip != null) @@ -194,27 +221,32 @@ public class AnnotationLabels public void mousePressed(MouseEvent evt) { + selectedRow = getSelectedRow(evt.getY() - scrollOffset); + AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation(); - PopupMenu pop = new PopupMenu("Annotations"); + PopupMenu popup = new PopupMenu("Annotations"); - MenuItem item = new MenuItem(EDITNAME); + MenuItem item = new MenuItem(ADDNEW); + item.addActionListener(this); + popup.add(item); + item = new MenuItem(EDITNAME); item.addActionListener(this); - pop.add(item); + popup.add(item); item = new MenuItem(HIDE); item.addActionListener(this); - pop.add(item); + popup.add(item); item = new MenuItem(SHOWALL); item.addActionListener(this); - pop.add(item); - this.add(pop); + popup.add(item); + this.add(popup); item = new MenuItem(OUTPUT_TEXT); item.addActionListener(this); - pop.add(item); + popup.add(item); if (aa[selectedRow] == ap.av.consensus) { - pop.addSeparator(); + popup.addSeparator(); final CheckboxMenuItem cbmi = new CheckboxMenuItem( "Ignore Gaps In Consensus", ap.av.getIgnoreGapsConsensus()); @@ -227,13 +259,13 @@ public class AnnotationLabels ap.paintAlignment(true); } }); - pop.add(cbmi); - final MenuItem cpcons = new MenuItem(COPYCONS_SEQ); - cpcons.addActionListener(this); - pop.add(cpcons); + popup.add(cbmi); + item = new MenuItem(COPYCONS_SEQ); + item.addActionListener(this); + popup.add(item); } - pop.show(this, evt.getX(), evt.getY()); + popup.show(this, evt.getX(), evt.getY()); } diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java index 9c45d5e..5242752 100755 --- a/src/jalview/appletgui/AnnotationPanel.java +++ b/src/jalview/appletgui/AnnotationPanel.java @@ -27,7 +27,8 @@ import java.awt.event.*; import jalview.datamodel.*; public class AnnotationPanel - extends Panel implements AdjustmentListener + extends Panel + implements AdjustmentListener, ActionListener, MouseListener, MouseMotionListener { AlignViewport av; AlignmentPanel ap; @@ -65,13 +66,10 @@ public class AnnotationPanel setLayout(null); adjustPanelHeight(); - addMouseMotionListener(new MouseMotionAdapter() - { - public void mouseMoved(MouseEvent evt) - { - doMouseMoved(evt); - } - }); + addMouseMotionListener(this); + + addMouseListener(this); + // ap.annotationScroller.getVAdjustable().addAdjustmentListener( this ); } @@ -86,6 +84,288 @@ public class AnnotationPanel ap.alabels.setScrollOffset( -evt.getValue()); } + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void actionPerformed(ActionEvent evt) + { + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + Annotation[] anot = aa[activeRow].annotations; + + if (anot.length < av.getColumnSelection().getMax()) + { + Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2]; + System.arraycopy(anot, 0, temp, 0, anot.length); + anot = temp; + aa[activeRow].annotations = anot; + } + + String label = ""; + if (av.colSel != null && av.colSel.size() > 0 + && anot[av.colSel.getMin()] != null) + label = anot[av.getColumnSelection().getMin()].displayCharacter; + + + if (evt.getActionCommand().equals(REMOVE)) + { + for (int i = 0; i < av.getColumnSelection().size(); i++) + { + anot[av.getColumnSelection().columnAt(i)] = null; + } + } + else if (evt.getActionCommand().equals(LABEL)) + { + label = enterLabel(label, "Enter Label"); + + if (label == null) + { + return; + } + + if ( (label.length() > 0) && !aa[activeRow].hasText) + { + aa[activeRow].hasText = true; + } + + for (int i = 0; i < av.getColumnSelection().size(); i++) + { + int index = av.getColumnSelection().columnAt(i); + + if(!av.colSel.isVisible(index)) + continue; + + if (anot[index] == null) + { + anot[index] = new Annotation(label, "", ' ', 0); + } + + anot[index].displayCharacter = label; + } + } + else if (evt.getActionCommand().equals(COLOUR)) + { + UserDefinedColours udc = new UserDefinedColours( + this, + Color.black, ap.alignFrame); + + Color col = udc.getColor(); + + for (int i = 0; i < av.getColumnSelection().size(); i++) + { + int index = av.getColumnSelection().columnAt(i); + + if(!av.colSel.isVisible(index)) + continue; + + if (anot[index] == null) + { + anot[index] = new Annotation("", "", ' ', 0); + } + + anot[index].colour = col; + } + } + else // HELIX OR SHEET + { + char type = 0; + String symbol = "\u03B1"; + + if (evt.getActionCommand().equals(HELIX)) + { + type = 'H'; + } + else if (evt.getActionCommand().equals(SHEET)) + { + type = 'E'; + symbol = "\u03B2"; + } + + if (!aa[activeRow].hasIcons) + { + aa[activeRow].hasIcons = true; + } + + label = enterLabel(symbol, "Enter Label"); + + if (label == null) + { + return; + } + + if ( (label.length() > 0) && !aa[activeRow].hasText) + { + aa[activeRow].hasText = true; + } + + for (int i = 0; i < av.getColumnSelection().size(); i++) + { + int index = av.getColumnSelection().columnAt(i); + + if(!av.colSel.isVisible(index)) + continue; + + if (anot[index] == null) + { + anot[index] = new Annotation(label, "", type, 0); + } + + anot[index].secondaryStructure = type; + anot[index].displayCharacter = label; + } + } + + adjustPanelHeight(); + repaint(); + + return; + } + + String enterLabel(String text, String label) + { + EditNameDialog dialog = new EditNameDialog(text,null,label,null, + ap.alignFrame,"Enter Label", 400,200); + + if(dialog.accept) + return dialog.getName(); + else + return null; + } + + public void mousePressed(MouseEvent evt) + { + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + if (aa == null) + { + return; + } + + int height = 0; + activeRow = -1; + + + for (int i = 0; i < aa.length; i++) + { + if (aa[i].visible) + { + height += aa[i].height; + } + + if (evt.getY() < height) + { + if (aa[i].editable) + { + activeRow = i; + } + + break; + } + } + + if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) == + InputEvent.BUTTON3_MASK && activeRow != -1) + { + if (av.getColumnSelection() == null) + { + return; + } + + PopupMenu pop = new PopupMenu("Structure type"); + MenuItem item = new MenuItem(HELIX); + item.addActionListener(this); + pop.add(item); + item = new MenuItem(SHEET); + item.addActionListener(this); + pop.add(item); + item = new MenuItem(LABEL); + item.addActionListener(this); + pop.add(item); + item = new MenuItem(COLOUR); + item.addActionListener(this); + pop.add(item); + item = new MenuItem(REMOVE); + item.addActionListener(this); + pop.add(item); + ap.alignFrame.add(pop); + pop.show(this, evt.getX(), evt.getY()); + + return; + } + + if (aa == null) + { + return; + } + + ap.scalePanel.mousePressed(evt); + } + + public void mouseReleased(MouseEvent evt) + { + ap.scalePanel.mouseReleased(evt); + } + + public void mouseClicked(MouseEvent evt) + {} + + public void mouseDragged(MouseEvent evt) + { + ap.scalePanel.mouseDragged(evt); + } + + public void mouseMoved(MouseEvent evt) + { + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + if (aa == null) + { + return; + } + + int row = -1; + int height = 0; + for (int i = 0; i < aa.length; i++) + { + + if (aa[i].visible) + { + height += aa[i].height; + } + + if (evt.getY() < height) + { + row = i; + break; + } + } + + int res = evt.getX() / av.getCharWidth() + av.getStartRes(); + + if (av.hasHiddenColumns) + { + res = av.getColumnSelection().adjustForHiddenColumns(res); + } + + if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null) + { + StringBuffer text = new StringBuffer("Sequence position " + (res + 1)); + if (aa[row].annotations[res].description != null) + { + text.append(" " + aa[row].annotations[res].description); + } + ap.alignFrame.statusBar.setText(text.toString()); + } + } + public void mouseEntered(MouseEvent evt) + { + ap.scalePanel.mouseEntered(evt); + } + public void mouseExited(MouseEvent evt) + { + ap.scalePanel.mouseExited(evt); + } + + public int adjustPanelHeight() { // setHeight of panels @@ -167,48 +447,6 @@ public class AnnotationPanel activeRes.addElement(String.valueOf(i)); } - public void doMouseMoved(MouseEvent evt) - { - AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - if (aa == null) - { - return; - } - - int row = -1; - int height = 0; - for (int i = 0; i < aa.length; i++) - { - - if (aa[i].visible) - { - height += aa[i].height; - } - - if (evt.getY() < height) - { - row = i; - break; - } - } - - int res = evt.getX() / av.getCharWidth() + av.getStartRes(); - - if (av.hasHiddenColumns) - { - res = av.getColumnSelection().adjustForHiddenColumns(res); - } - - if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null) - { - StringBuffer text = new StringBuffer("Sequence position " + (res + 1)); - if (aa[row].annotations[res].description != null) - { - text.append(" " + aa[row].annotations[res].description); - } - ap.alignFrame.statusBar.setText(text.toString()); - } - } public void update(Graphics g) { @@ -387,6 +625,27 @@ public class AnnotationPanel validRes = true; } + if (activeRow == i) + { + g.setColor(Color.red); + + if (av.getColumnSelection() != null) + { + for (int n = 0; n < av.getColumnSelection().size(); n++) + { + int v = av.getColumnSelection().columnAt(n); + + if (v == column) + { + g.fillRect(x * av.charWidth, y, + av.charWidth, av.charHeight); + } + } + } + } + + + if (av.validCharWidth && validRes && (row.annotations[column].displayCharacter.length() > 0)) { diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index a48e77e..375fe4d 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -29,6 +29,8 @@ import jalview.io.*; import org.jmol.api.*; import org.jmol.adapter.smarter.SmarterJmolAdapter; + + import org.jmol.popup.*; import jalview.schemes.*; @@ -621,8 +623,7 @@ public class AppletJmol extends Frame pdbentry.setId(pdb.id); ssm.addStructureViewerListener(this); - if (fr!=null) - fr.featuresAdded(); + Vector chains = new Vector(); for (int i = 0; i < pdb.chains.size(); i++) { diff --git a/src/jalview/appletgui/EditNameDialog.java b/src/jalview/appletgui/EditNameDialog.java index 3e197f0..1c365ba 100644 --- a/src/jalview/appletgui/EditNameDialog.java +++ b/src/jalview/appletgui/EditNameDialog.java @@ -20,15 +20,11 @@ package jalview.appletgui; import java.awt.*; -import java.awt.event.*; -public class EditNameDialog - extends Dialog implements ActionListener + +public class EditNameDialog extends JVDialog { TextField id, description; - Button ok = new Button("Accept"); - Button cancel = new Button("Cancel"); - boolean accept = false; public String getName() { @@ -51,61 +47,35 @@ public class EditNameDialog String desc, String label1, String label2, - AlignmentPanel ap, - String title) + Frame owner, + String title, + int width, int height) { - super(ap.alignFrame, title, true); + super(owner, title, true, width, height); - id = new TextField(name, 40); - description = new TextField(desc, 40); Panel panel = new Panel(new BorderLayout()); Panel panel2 = new Panel(new BorderLayout()); + + id = new TextField(name, 40); Label label = new Label(label1); label.setFont(new Font("Monospaced", Font.PLAIN, 12)); + panel2.add(label, BorderLayout.WEST); panel2.add(id, BorderLayout.CENTER); panel.add(panel2, BorderLayout.NORTH); - panel2 = new Panel(new BorderLayout()); - label = new Label(label2); - label.setFont(new Font("Monospaced", Font.PLAIN, 12)); - panel2.add(label, BorderLayout.WEST); - panel2.add(description, BorderLayout.CENTER); - panel.add(panel2, BorderLayout.CENTER); - - panel2 = new Panel(new FlowLayout()); - - panel2.add(ok); - panel2.add(cancel); - ok.addActionListener(this); - cancel.addActionListener(this); - - panel.add(panel2, BorderLayout.SOUTH); - - add(panel, BorderLayout.NORTH); - int width = 500, height = 100; - pack(); - - height += getInsets().top + getInsets().bottom; - - setBounds(ap.alignFrame.getBounds().x - + (ap.alignFrame.getSize().width - width) / 2, - ap.alignFrame.getBounds().y - + (ap.alignFrame.getSize().height - height) / 2, - width, height); - - show(); - - } - - public void actionPerformed(ActionEvent evt) - { - if (evt.getSource() == ok) + if(label2!=null) { - accept = true; + panel2 = new Panel(new BorderLayout()); + description = new TextField(desc, 40); + label = new Label(label2); + label.setFont(new Font("Monospaced", Font.PLAIN, 12)); + panel2.add(label, BorderLayout.WEST); + panel2.add(description, BorderLayout.CENTER); + panel.add(panel2, BorderLayout.CENTER); } - - setVisible(false); + setMainPanel(panel); + show(); } } diff --git a/src/jalview/appletgui/FeatureRenderer.java b/src/jalview/appletgui/FeatureRenderer.java index adfa518..ff58125 100755 --- a/src/jalview/appletgui/FeatureRenderer.java +++ b/src/jalview/appletgui/FeatureRenderer.java @@ -1,463 +1,738 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 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 - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ -package jalview.appletgui; - -import java.util.*; - -import java.awt.*; - -import jalview.datamodel.*; - -/** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ - */ -public class FeatureRenderer -{ - AlignViewport av; - - Hashtable featureColours = new Hashtable(); - - // A higher level for grouping features of a - // particular type - Hashtable featureGroups = null; - - // Holds web links for feature groups and feature types - // in the form label|link - Hashtable featureLinks = null; - - // This is actually an Integer held in the hashtable, - // Retrieved using the key feature type - Object currentColour; - - String[] renderOrder; - - FontMetrics fm; - int charOffset; - - float transparency = 1f; - - TransparencySetter transparencySetter = null; - - /** - * Creates a new FeatureRenderer object. - * - * @param av DOCUMENT ME! - */ - public FeatureRenderer(AlignViewport av) - { - this.av = av; - - if (!System.getProperty("java.version").startsWith("1.1")) - { - transparencySetter = new TransparencySetter(); - } - } - - public void transferSettings(FeatureRenderer fr) - { - renderOrder = fr.renderOrder; - featureGroups = fr.featureGroups; - featureColours = fr.featureColours; - transparency = fr.transparency; - } - - public Color findFeatureColour(Color initialCol, SequenceI seq, int i) - { - overview = true; - if (!av.showSequenceFeatures) - { - return initialCol; - } - - lastSequence = seq; - sequenceFeatures = lastSequence.getSequenceFeatures(); - if (sequenceFeatures == null) - { - return initialCol; - } - - sfSize = sequenceFeatures.length; - - if (jalview.util.Comparison.isGap(lastSequence.getCharAt(i))) - { - return Color.white; - } - - currentColour = null; - - drawSequence(null, lastSequence, lastSequence.findPosition(i), -1, -1); - - if (currentColour == null) - { - return initialCol; - } - - return new Color( ( (Integer) currentColour).intValue()); - } - - /** - * This is used by the Molecule Viewer to get the accurate colour - * of the rendered sequence - */ - boolean overview = false; - - int white = Color.white.getRGB(); - public int findFeatureColour(int initialCol, int seqIndex, int column) - { - if (!av.showSequenceFeatures) - { - return initialCol; - } - - if (seqIndex != lastSequenceIndex) - { - lastSequence = av.alignment.getSequenceAt(seqIndex); - lastSequenceIndex = seqIndex; - sequenceFeatures = lastSequence.getSequenceFeatures(); - if (sequenceFeatures == null) - { - return initialCol; - } - - sfSize = sequenceFeatures.length; - } - - if (jalview.util.Comparison.isGap(lastSequence.getCharAt(column))) - { - return Color.white.getRGB(); - } - - currentColour = null; - - drawSequence(null, lastSequence, lastSequence.findPosition(column), -1, -1); - - if (currentColour == null) - { - return initialCol; - } - - return ( (Integer) currentColour).intValue(); - } - - /** - * DOCUMENT ME! - * - * @param g DOCUMENT ME! - * @param seq DOCUMENT ME! - * @param sg DOCUMENT ME! - * @param start DOCUMENT ME! - * @param end DOCUMENT ME! - * @param x1 DOCUMENT ME! - * @param y1 DOCUMENT ME! - * @param width DOCUMENT ME! - * @param height DOCUMENT ME! - */ - // String type; - // SequenceFeature sf; - int lastSequenceIndex = -1; - SequenceI lastSequence; - SequenceFeature[] sequenceFeatures; - int sfSize, sfindex, spos, epos; - - public void drawSequence(Graphics g, SequenceI seq, - int start, int end, int y1) - { - if (seq.getSequenceFeatures() == null - || seq.getSequenceFeatures().length == 0) - { - return; - } - - if (transparencySetter != null && g != null) - { - transparencySetter.setTransparency(g, transparency); - } - - if (lastSequence == null || seq != lastSequence || sequenceFeatures!=seq.getSequenceFeatures()) - { - lastSequence = seq; - sequenceFeatures = seq.getSequenceFeatures(); - sfSize = sequenceFeatures.length; - } - - if (av.featuresDisplayed == null || renderOrder == null) - { - findAllFeatures(); - if (av.featuresDisplayed.size() < 1) - { - return; - } - - sequenceFeatures = seq.getSequenceFeatures(); - sfSize = sequenceFeatures.length; - } - if (!overview) - { - spos = lastSequence.findPosition(start); - epos = lastSequence.findPosition(end); - if (g != null) - { - fm = g.getFontMetrics(); - } - } - String type; - for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++) - { - type = renderOrder[renderIndex]; - if (!av.featuresDisplayed.containsKey(type)) - { - continue; - } - - // loop through all features in sequence to find - // current feature to render - for (sfindex = 0; sfindex < sfSize; sfindex++) - { - if (!sequenceFeatures[sfindex].type.equals(type)) - { - continue; - } - - if (featureGroups != null - && sequenceFeatures[sfindex].featureGroup != null - && - featureGroups.containsKey(sequenceFeatures[sfindex].featureGroup) - && - ! ( (Boolean) featureGroups.get(sequenceFeatures[sfindex]. - featureGroup)). - booleanValue()) - { - continue; - } - - if (!overview && (sequenceFeatures[sfindex].getBegin() > epos - || sequenceFeatures[sfindex].getEnd() < spos)) - { - continue; - } - - if (overview) - { - if (sequenceFeatures[sfindex].begin <= start && - sequenceFeatures[sfindex].end >= start) - { - currentColour = av.featuresDisplayed.get(sequenceFeatures[sfindex]. - type); - } - - } - else if (sequenceFeatures[sfindex].type.equals("disulfide bond")) - { - - renderFeature(g, seq, - seq.findIndex(sequenceFeatures[sfindex].begin) - 1, - seq.findIndex(sequenceFeatures[sfindex].begin) - 1, - new Color( ( (Integer) av.featuresDisplayed.get( - sequenceFeatures[sfindex].type)).intValue()), - start, end, y1); - renderFeature(g, seq, - seq.findIndex(sequenceFeatures[sfindex].end) - 1, - seq.findIndex(sequenceFeatures[sfindex].end) - 1, - new Color( ( (Integer) av.featuresDisplayed.get( - sequenceFeatures[sfindex].type)).intValue()), - start, end, y1); - - } - else - { - renderFeature(g, seq, - seq.findIndex(sequenceFeatures[sfindex].begin) - 1, - seq.findIndex(sequenceFeatures[sfindex].end) - 1, - getColour(sequenceFeatures[sfindex].type), - start, end, y1); - } - - } - } - - if (transparencySetter != null && g != null) - { - transparencySetter.setTransparency(g, 1.0f); - } - } - - char s; - int i; - void renderFeature(Graphics g, SequenceI seq, - int fstart, int fend, Color featureColour, int start, - int end, int y1) - { - - if ( ( (fstart <= end) && (fend >= start))) - { - if (fstart < start) - { // fix for if the feature we have starts before the sequence start, - fstart = start; // but the feature end is still valid!! - } - - if (fend >= end) - { - fend = end; - } - - for (i = fstart; i <= fend; i++) - { - s = seq.getCharAt(i); - - if (jalview.util.Comparison.isGap(s)) - { - continue; - } - - g.setColor(featureColour); - - g.fillRect( (i - start) * av.charWidth, y1, av.charWidth, av.charHeight); - - if (!av.validCharWidth) - { - continue; - } - - g.setColor(Color.white); - charOffset = (av.charWidth - fm.charWidth(s)) / 2; - g.drawString(String.valueOf(s), - charOffset + (av.charWidth * (i - start)), - (y1 + av.charHeight) - av.charHeight / 5); //pady = height / 5; - - } - } - } - - void findAllFeatures() - { - jalview.schemes.UserColourScheme ucs = new - jalview.schemes.UserColourScheme(); - - av.featuresDisplayed = new Hashtable(); - Vector allfeatures = new Vector(); - for (int i = 0; i < av.alignment.getHeight(); i++) - { - SequenceFeature[] features = av.alignment.getSequenceAt(i). - getSequenceFeatures(); - - if (features == null) - { - continue; - } - - int index = 0; - while (index < features.length) - { - if (!av.featuresDisplayed.containsKey(features[index].getType())) - { - if (getColour(features[index].getType()) == null) - { - featureColours.put(features[index].getType(), - ucs.createColourFromName(features[index]. - getType())); - } - - av.featuresDisplayed.put(features[index].getType(), - new Integer(getColour(features[index]. - getType()).getRGB())); - allfeatures.addElement(features[index].getType()); - } - index++; - } - } - - renderOrder = new String[allfeatures.size()]; - Enumeration en = allfeatures.elements(); - int i = allfeatures.size() - 1; - while (en.hasMoreElements()) - { - renderOrder[i] = en.nextElement().toString(); - i--; - } - } - - public Color getColour(String featureType) - { - return (Color) featureColours.get(featureType); - } - - public void addNewFeature(String name, Color col) - { - - setColour(name, col); - if (av.featuresDisplayed == null) - { - av.featuresDisplayed = new Hashtable(); - } - - av.featuresDisplayed.put(name, "NOGROUP"); - } - - public void setColour(String featureType, Color col) - { - featureColours.put(featureType, col); - } - - public void setFeaturePriority(Object[][] data) - { - // The feature table will display high priority - // features at the top, but theses are the ones - // we need to render last, so invert the data - if (av.featuresDisplayed != null) - { - av.featuresDisplayed.clear(); - } - - renderOrder = new String[data.length]; - - if (data.length > 0) - { - for (int i = 0; i < data.length; i++) - { - String type = data[i][0].toString(); - setColour(type, (Color) data[i][1]); - if ( ( (Boolean) data[i][2]).booleanValue()) - { - av.featuresDisplayed.put(type, new Integer(getColour(type).getRGB())); - } - - renderOrder[data.length - i - 1] = type; - } - } - } - - public void featuresAdded() - { - findAllFeatures(); - } -} - -class TransparencySetter -{ - void setTransparency(Graphics g, float value) - { - Graphics2D g2 = (Graphics2D) g; - g2.setComposite( - AlphaComposite.getInstance( - AlphaComposite.SRC_OVER, value)); - } -} +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2007 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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ +package jalview.appletgui; + +import java.util.*; + +import java.awt.*; + +import java.awt.event.*; + + +import jalview.datamodel.*; + +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class FeatureRenderer +{ + AlignViewport av; + + Hashtable featureColours = new Hashtable(); + + // A higher level for grouping features of a + // particular type + Hashtable featureGroups = null; + + // Holds web links for feature groups and feature types + // in the form label|link + Hashtable featureLinks = null; + + // This is actually an Integer held in the hashtable, + // Retrieved using the key feature type + Object currentColour; + + String[] renderOrder; + + FontMetrics fm; + int charOffset; + + float transparency = 1f; + + TransparencySetter transparencySetter = null; + + /** + * Creates a new FeatureRenderer object. + * + * @param av DOCUMENT ME! + */ + public FeatureRenderer(AlignViewport av) + { + this.av = av; + + if (!System.getProperty("java.version").startsWith("1.1")) + { + transparencySetter = new TransparencySetter(); + } + } + + public void transferSettings(FeatureRenderer fr) + { + renderOrder = fr.renderOrder; + featureGroups = fr.featureGroups; + featureColours = fr.featureColours; + transparency = fr.transparency; + } + + + static String lastFeatureAdded; + static String lastFeatureGroupAdded; + static String lastDescriptionAdded; + + public boolean createNewFeatures(SequenceI[] sequences, + SequenceFeature[] features, + AlignmentPanel ap) + { + return amendFeatures(sequences, features, true, ap); + } + + + int featureIndex = 0; + boolean deleteFeature = false; + Panel colourPanel; + boolean amendFeatures(final SequenceI[] sequences, + final SequenceFeature[] features, + boolean newFeatures, + final AlignmentPanel ap) + { + Panel bigPanel = new Panel(new BorderLayout()); + final TextField name = new TextField(16); + final TextField source = new TextField(16); + final TextArea description = new TextArea(3, 35); + final TextField start = new TextField(8); + final TextField end = new TextField(8); + final Choice overlaps; + Button deleteButton = new Button("Delete"); + deleteFeature = false; + + colourPanel = new Panel(null); + colourPanel.setSize(110,15); + final FeatureRenderer fr = this; + + Panel panel = new Panel(new GridLayout(3, 1)); + + Panel tmp; + + /////////////////////////////////////// + ///MULTIPLE FEATURES AT SELECTED RESIDUE + if(!newFeatures && features.length>1) + { + panel = new Panel(new GridLayout(4, 1)); + tmp = new Panel(); + tmp.add(new Label("Select Feature: ")); + overlaps = new Choice(); + for(int i=0; i0) + { + for (int i = 0; i < sequences.length; i++) + { + features[i].type = lastFeatureAdded; + features[i].featureGroup = lastFeatureGroupAdded; + features[i].description = lastDescriptionAdded; + sequences[i].addSequenceFeature(features[i]); + ffile.parseDescriptionHTML(features[i], false); + } + + if (av.featuresDisplayed == null) + { + av.featuresDisplayed = new Hashtable(); + } + + if (featureGroups == null) + { + featureGroups = new Hashtable(); + } + + + + col = colourPanel.getBackground(); + setColour(lastFeatureAdded, col); + + if(lastFeatureGroupAdded!=null) + { + featureGroups.put(lastFeatureGroupAdded, new Boolean(true)); + av.featuresDisplayed.put(lastFeatureGroupAdded, + new Integer(col.getRGB())); + } + findAllFeatures(); + + return true; + } + else + { + return false; + } + } + + findAllFeatures(); + + return true; + } + + + public Color findFeatureColour(Color initialCol, SequenceI seq, int i) + { + overview = true; + if (!av.showSequenceFeatures) + { + return initialCol; + } + + lastSeq = seq; + sequenceFeatures = lastSeq.getSequenceFeatures(); + if (sequenceFeatures == null) + { + return initialCol; + } + + sfSize = sequenceFeatures.length; + + if (jalview.util.Comparison.isGap(lastSeq.getCharAt(i))) + { + return Color.white; + } + + currentColour = null; + + drawSequence(null, lastSeq, lastSeq.findPosition(i), -1, -1); + + if (currentColour == null) + { + return initialCol; + } + + return new Color( ( (Integer) currentColour).intValue()); + } + + /** + * This is used by the Molecule Viewer to get the accurate colour + * of the rendered sequence + */ + boolean overview = false; + + + /** + * DOCUMENT ME! + * + * @param g DOCUMENT ME! + * @param seq DOCUMENT ME! + * @param sg DOCUMENT ME! + * @param start DOCUMENT ME! + * @param end DOCUMENT ME! + * @param x1 DOCUMENT ME! + * @param y1 DOCUMENT ME! + * @param width DOCUMENT ME! + * @param height DOCUMENT ME! + */ + // String type; + // SequenceFeature sf; + + SequenceI lastSeq; + SequenceFeature[] sequenceFeatures; + int sfSize, sfindex, spos, epos; + + public void drawSequence(Graphics g, SequenceI seq, + int start, int end, int y1) + { + if (seq.getSequenceFeatures() == null + || seq.getSequenceFeatures().length == 0) + { + return; + } + + if (transparencySetter != null && g != null) + { + transparencySetter.setTransparency(g, transparency); + } + + if (lastSeq == null || seq != lastSeq || sequenceFeatures!=seq.getSequenceFeatures()) + { + lastSeq = seq; + sequenceFeatures = seq.getSequenceFeatures(); + sfSize = sequenceFeatures.length; + } + + if (av.featuresDisplayed == null || renderOrder == null) + { + findAllFeatures(); + if (av.featuresDisplayed.size() < 1) + { + return; + } + + sequenceFeatures = seq.getSequenceFeatures(); + sfSize = sequenceFeatures.length; + } + if (!overview) + { + spos = lastSeq.findPosition(start); + epos = lastSeq.findPosition(end); + if (g != null) + { + fm = g.getFontMetrics(); + } + } + String type; + for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++) + { + type = renderOrder[renderIndex]; + if (!av.featuresDisplayed.containsKey(type)) + { + continue; + } + + // loop through all features in sequence to find + // current feature to render + for (sfindex = 0; sfindex < sfSize; sfindex++) + { + if (!sequenceFeatures[sfindex].type.equals(type)) + { + continue; + } + + if (featureGroups != null + && sequenceFeatures[sfindex].featureGroup != null + && + featureGroups.containsKey(sequenceFeatures[sfindex].featureGroup) + && + ! ( (Boolean) featureGroups.get(sequenceFeatures[sfindex]. + featureGroup)). + booleanValue()) + { + continue; + } + + if (!overview && (sequenceFeatures[sfindex].getBegin() > epos + || sequenceFeatures[sfindex].getEnd() < spos)) + { + continue; + } + + if (overview) + { + if (sequenceFeatures[sfindex].begin <= start && + sequenceFeatures[sfindex].end >= start) + { + currentColour = av.featuresDisplayed.get(sequenceFeatures[sfindex]. + type); + } + + } + else if (sequenceFeatures[sfindex].type.equals("disulfide bond")) + { + + renderFeature(g, seq, + seq.findIndex(sequenceFeatures[sfindex].begin) - 1, + seq.findIndex(sequenceFeatures[sfindex].begin) - 1, + new Color( ( (Integer) av.featuresDisplayed.get( + sequenceFeatures[sfindex].type)).intValue()), + start, end, y1); + renderFeature(g, seq, + seq.findIndex(sequenceFeatures[sfindex].end) - 1, + seq.findIndex(sequenceFeatures[sfindex].end) - 1, + new Color( ( (Integer) av.featuresDisplayed.get( + sequenceFeatures[sfindex].type)).intValue()), + start, end, y1); + + } + else + { + renderFeature(g, seq, + seq.findIndex(sequenceFeatures[sfindex].begin) - 1, + seq.findIndex(sequenceFeatures[sfindex].end) - 1, + getColour(sequenceFeatures[sfindex].type), + start, end, y1); + } + + } + } + + if (transparencySetter != null && g != null) + { + transparencySetter.setTransparency(g, 1.0f); + } + } + + char s; + int i; + void renderFeature(Graphics g, SequenceI seq, + int fstart, int fend, Color featureColour, int start, + int end, int y1) + { + + if ( ( (fstart <= end) && (fend >= start))) + { + if (fstart < start) + { // fix for if the feature we have starts before the sequence start, + fstart = start; // but the feature end is still valid!! + } + + if (fend >= end) + { + fend = end; + } + + for (i = fstart; i <= fend; i++) + { + s = seq.getCharAt(i); + + if (jalview.util.Comparison.isGap(s)) + { + continue; + } + + g.setColor(featureColour); + + g.fillRect( (i - start) * av.charWidth, y1, av.charWidth, av.charHeight); + + if (!av.validCharWidth) + { + continue; + } + + g.setColor(Color.white); + charOffset = (av.charWidth - fm.charWidth(s)) / 2; + g.drawString(String.valueOf(s), + charOffset + (av.charWidth * (i - start)), + (y1 + av.charHeight) - av.charHeight / 5); //pady = height / 5; + + } + } + } + + void findAllFeatures() + { + jalview.schemes.UserColourScheme ucs = new + jalview.schemes.UserColourScheme(); + + av.featuresDisplayed = new Hashtable(); + Vector allfeatures = new Vector(); + for (int i = 0; i < av.alignment.getHeight(); i++) + { + SequenceFeature[] features = av.alignment.getSequenceAt(i). + getSequenceFeatures(); + + if (features == null) + { + continue; + } + + int index = 0; + while (index < features.length) + { + if (!av.featuresDisplayed.containsKey(features[index].getType())) + { + if (getColour(features[index].getType()) == null) + { + featureColours.put(features[index].getType(), + ucs.createColourFromName(features[index]. + getType())); + } + + av.featuresDisplayed.put(features[index].getType(), + new Integer(getColour(features[index]. + getType()).getRGB())); + allfeatures.addElement(features[index].getType()); + } + index++; + } + } + + renderOrder = new String[allfeatures.size()]; + Enumeration en = allfeatures.elements(); + int i = allfeatures.size() - 1; + while (en.hasMoreElements()) + { + renderOrder[i] = en.nextElement().toString(); + i--; + } + } + + public Color getColour(String featureType) + { + return (Color) featureColours.get(featureType); + } + + public void addNewFeature(String name, Color col) + { + + setColour(name, col); + if (av.featuresDisplayed == null) + { + av.featuresDisplayed = new Hashtable(); + } + + av.featuresDisplayed.put(name, "NOGROUP"); + } + + public void setColour(String featureType, Color col) + { + featureColours.put(featureType, col); + } + + public void setFeaturePriority(Object[][] data) + { + // The feature table will display high priority + // features at the top, but theses are the ones + // we need to render last, so invert the data + if (av.featuresDisplayed != null) + { + av.featuresDisplayed.clear(); + } + + renderOrder = new String[data.length]; + + if (data.length > 0) + { + for (int i = 0; i < data.length; i++) + { + String type = data[i][0].toString(); + setColour(type, (Color) data[i][1]); + if ( ( (Boolean) data[i][2]).booleanValue()) + { + av.featuresDisplayed.put(type, new Integer(getColour(type).getRGB())); + } + + renderOrder[data.length - i - 1] = type; + } + } + } +} + +class TransparencySetter +{ + void setTransparency(Graphics g, float value) + { + Graphics2D g2 = (Graphics2D) g; + g2.setComposite( + AlphaComposite.getInstance( + AlphaComposite.SRC_OVER, value)); + } +} diff --git a/src/jalview/appletgui/Finder.java b/src/jalview/appletgui/Finder.java index 4f698d2..2b742b2 100755 --- a/src/jalview/appletgui/Finder.java +++ b/src/jalview/appletgui/Finder.java @@ -42,6 +42,7 @@ public class Finder try { jbInit(); + } catch (Exception e) { @@ -61,6 +62,7 @@ public class Finder ap.highlightSearchResults(null); } }); + textfield.requestFocus(); } public void actionPerformed(ActionEvent evt) @@ -89,43 +91,27 @@ public class Finder public void createNewGroup_actionPerformed() { - - CutAndPasteTransfer cap = new CutAndPasteTransfer(true, null); - cap.accept.setLabel("Accept"); - Dialog dialog = new Dialog(ap.alignFrame, "Enter New Feature Name", true); - dialog.add(cap); - - cap.setText(textfield.getText()); - - dialog.setBounds(frame.getLocation().x + frame.getSize().width + 5, - frame.getLocation().y + 20, 300, 100); - dialog.show(); - - String featureName = cap.getText().trim(); - if (featureName.length() < 1) - { - return; - } + SequenceI[] seqs = new SequenceI[searchResults.getSize()]; + SequenceFeature[] features = new SequenceFeature[searchResults.getSize()]; for (int i = 0; i < searchResults.getSize(); i++) { - SequenceI seq = searchResults.getResultSequence(i); - - SequenceFeature sf = new SequenceFeature(featureName, - null, null, - searchResults.getResultStart(i), - searchResults.getResultEnd(i), - "Search Results"); + seqs[i] = searchResults.getResultSequence(i); - ap.seqPanel.seqCanvas.getFeatureRenderer().addNewFeature( - featureName, new Color(60, 160, 115)); - seq.addSequenceFeature(sf); + features[i] = new SequenceFeature(textfield.getText().trim(), + "Search Results", null, + searchResults.getResultStart(i), + searchResults.getResultEnd(i), + "Search Results"); } - ap.seqPanel.seqCanvas.getFeatureRenderer().featuresAdded(); - ap.alignFrame.sequenceFeatures.setState(true); - av.showSequenceFeatures(true); - ap.highlightSearchResults(null); + if (ap.seqPanel.seqCanvas.getFeatureRenderer() + .createNewFeatures(seqs, features, ap)) + { + ap.alignFrame.sequenceFeatures.setState(true); + av.showSequenceFeatures(true); + ap.highlightSearchResults(null); + } } void doSearch(boolean findAll) diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java index b35fa6c..4db8054 100755 --- a/src/jalview/appletgui/ScalePanel.java +++ b/src/jalview/appletgui/ScalePanel.java @@ -259,15 +259,18 @@ public class ScalePanel sg.setStartRes(res); } + int col; for (int i = min; i <= max; i++) { - if ( (i < sg.getStartRes()) || (i > sg.getEndRes())) + col = av.getColumnSelection().adjustForHiddenColumns(i); + + if ( (col < sg.getStartRes()) || (col > sg.getEndRes())) { - av.getColumnSelection().removeElement(i); + av.getColumnSelection().removeElement(col); } else { - av.getColumnSelection().addElement(i); + av.getColumnSelection().addElement(col); } } diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index f4f2cfd..f9304cf 100755 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -448,7 +448,40 @@ public class SeqPanel } public void mouseClicked(MouseEvent evt) - {} + { + SequenceI sequence = av.alignment.getSequenceAt(findSeq(evt)); + if (evt.getClickCount() > 1) + { + if (av.getSelectionGroup().getSize() == 1 + && av.getSelectionGroup().getEndRes() + - av.getSelectionGroup().getStartRes() < 2) + { + av.setSelectionGroup(null); + } + + SequenceFeature[] features = findFeaturesAtRes( + sequence, + sequence.findPosition(findRes(evt)) + ); + + if (features != null && features.length > 0) + { + SearchResults highlight = new SearchResults(); + highlight.addResult(sequence, + features[0].getBegin(), + features[0].getEnd()); + seqCanvas.highlightSearchResults(highlight); + } + if (features != null && features.length > 0) + { + seqCanvas.getFeatureRenderer().amendFeatures( + new SequenceI[] + {sequence}, features, false, ap); + + seqCanvas.highlightSearchResults(null); + } + } + } public void mouseReleased(MouseEvent evt) { @@ -554,6 +587,8 @@ public class SeqPanel return seq; } + + public void doMousePressed(MouseEvent evt) { @@ -691,18 +726,13 @@ public class SeqPanel } // use aa to see if the mouse pointer is on a - if (av.showSequenceFeatures - && sequence.getSequenceFeatures() != null - && av.featuresDisplayed != null) - { - - Vector allFeatures = getAllFeaturesAtRes(sequence, + SequenceFeature [] allFeatures = findFeaturesAtRes(sequence, sequence.findPosition(res)); int index = 0; - while (index < allFeatures.size()) + while (index < allFeatures.length) { - SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(index); + SequenceFeature sf = allFeatures[index]; tooltipText.append(sf.getType() + " " + sf.begin + ":" + sf.end); @@ -723,7 +753,6 @@ public class SeqPanel index++; } - } if (tooltip == null) { @@ -735,29 +764,35 @@ public class SeqPanel } } - Vector getAllFeaturesAtRes(SequenceI seq, int res) + SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res) { - Vector allFeatures = new Vector(); - int index = 0; - if (seq.getSequenceFeatures() != null) + Vector tmp = new Vector(); + SequenceFeature[] features = sequence.getSequenceFeatures(); + if (features != null) { - while (index < seq.getSequenceFeatures().length) + for (int i = 0; i < features.length; i++) { - SequenceFeature sf = seq.getSequenceFeatures()[index]; - if (sf.getBegin() <= res && - sf.getEnd() >= res) + if (av.featuresDisplayed == null + || !av.featuresDisplayed.containsKey(features[i].getType())) { - if (av.featuresDisplayed.containsKey(sf.getType())) - { - allFeatures.addElement(sf); - } + continue; + } + + if ( (features[i].getBegin() <= res) && + (features[i].getEnd() >= res)) + { + tmp.addElement(features[i]); } - index++; } } - return allFeatures; + + features = new SequenceFeature[tmp.size()]; + tmp.copyInto(features); + + return features; } + Tooltip tooltip; public void mouseDragged(MouseEvent evt) @@ -1320,21 +1355,20 @@ public class SeqPanel if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { - Vector allFeatures = getAllFeaturesAtRes(sequence, + SequenceFeature [] allFeatures = findFeaturesAtRes(sequence, sequence.findPosition(res)); Vector links = null; if (allFeatures != null) { - for (int i = 0; i < allFeatures.size(); i++) + for (int i = 0; i < allFeatures.length; i++) { - SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(i); - if (sf.links != null) + if (allFeatures[i].links != null) { links = new Vector(); - for (int j = 0; j < sf.links.size(); j++) + for (int j = 0; j < allFeatures[i].links.size(); j++) { - links.addElement(sf.links.elementAt(j)); + links.addElement(allFeatures[i].links.elementAt(j)); } } } diff --git a/src/jalview/appletgui/UserDefinedColours.java b/src/jalview/appletgui/UserDefinedColours.java index ecb3265..aa260c5 100755 --- a/src/jalview/appletgui/UserDefinedColours.java +++ b/src/jalview/appletgui/UserDefinedColours.java @@ -40,6 +40,7 @@ public class UserDefinedColours MCview.AppletPDBCanvas pdbcanvas; AppletJmol jmol; + Dialog dialog; Object caller; String originalLabel; Color originalColour; @@ -81,6 +82,29 @@ public class UserDefinedColours init(); } + public UserDefinedColours(FeatureRenderer fr, Frame alignframe) + { + caller = fr; + originalColour = fr.colourPanel.getBackground(); + originalLabel = "Feature Colour"; + setTargetColour(fr.colourPanel.getBackground()); + + setForDialog("Select Feature Colour", alignframe); + } + + public UserDefinedColours(Component caller, + Color col1, + Frame alignframe) + { + this.caller = caller; + originalColour = col1; + originalLabel = "Select Colour"; + setTargetColour(col1); + + setForDialog("Select Colour", alignframe); + } + + public UserDefinedColours(Object caller, String label, Color colour) @@ -98,6 +122,28 @@ public class UserDefinedColours frame.setSize(420, 200); } + void setForDialog(String title, Frame alignframe) + { + init(); + frame.setVisible(false); + remove(buttonPanel); + dialog = new Dialog(alignframe, title, true); + + dialog.add(this); + this.setSize(400,123); + okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35)); + int height = 160 + alignframe.getInsets().top + getInsets().bottom; + int width = 400; + + dialog.setBounds(alignframe.getBounds().x + + (alignframe.getSize().width - width) / 2, + alignframe.getBounds().y + + (alignframe.getSize().height - height) / 2, + width, height); + + dialog.show(); + } + public void actionPerformed(ActionEvent evt) { if (evt.getSource() == okButton) @@ -298,9 +344,17 @@ public class UserDefinedColours protected void okButton_actionPerformed() { applyButton_actionPerformed(); + if (dialog != null) + dialog.setVisible(false); + frame.setVisible(false); } + public Color getColor() + { + return new Color(R, G, B); + } + protected void applyButton_actionPerformed() { if (caller != null) @@ -308,21 +362,26 @@ public class UserDefinedColours if (caller instanceof FeatureSettings) { ( (FeatureSettings) caller).setUserColour - (originalLabel, new Color(R, G, B)); + (originalLabel, getColor()); } else if (caller instanceof AnnotationColourChooser) { if (originalLabel.equals("Min Colour")) { ( (AnnotationColourChooser) caller).minColour_actionPerformed - (new Color(R, G, B)); + (getColor()); } else { ( (AnnotationColourChooser) caller).maxColour_actionPerformed - (new Color(R, G, B)); + (getColor()); } } + else if(caller instanceof FeatureRenderer) + { + ((FeatureRenderer)caller).colourPanel.setBackground(getColor()); + } + return; } @@ -384,6 +443,15 @@ public class UserDefinedColours (originalColour); } } + else if (caller instanceof FeatureRenderer) + { + ( (FeatureRenderer) caller).colourPanel.setBackground(originalColour); + + } + + if(dialog!=null) + dialog.setVisible(false); + frame.setVisible(false); return; } -- 1.7.10.2