2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import java.awt.BorderLayout;
24 import java.awt.Button;
25 import java.awt.Choice;
26 import java.awt.Color;
27 import java.awt.Dimension;
29 import java.awt.Graphics;
30 import java.awt.GridLayout;
31 import java.awt.Label;
32 import java.awt.Panel;
33 import java.awt.ScrollPane;
34 import java.awt.TextArea;
35 import java.awt.TextField;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.ActionListener;
38 import java.util.Hashtable;
40 import jalview.datamodel.SearchResults;
41 import jalview.datamodel.SequenceFeature;
42 import jalview.datamodel.SequenceI;
43 import jalview.schemes.AnnotationColourGradient;
44 import jalview.schemes.GraduatedColor;
45 import jalview.util.MessageManager;
46 import jalview.viewmodel.AlignmentViewport;
54 public class FeatureRenderer extends
55 jalview.renderer.seqfeatures.FeatureRenderer
58 // Holds web links for feature groups and feature types
59 // in the form label|link
60 Hashtable featureLinks = null;
63 * Creates a new FeatureRenderer object.
68 public FeatureRenderer(AlignmentViewport av)
73 setTransparencyAvailable(!System.getProperty("java.version")
77 static String lastFeatureAdded;
79 static String lastFeatureGroupAdded;
81 static String lastDescriptionAdded;
85 boolean deleteFeature = false;
87 FeatureColourPanel colourPanel;
89 class FeatureColourPanel extends Panel
95 private boolean isColourByLabel, isGcol;
98 * render a feature style in the amend feature dialog box
100 public void updateColor(Object newcol)
103 Color bg, col = null;
104 GraduatedColor gcol = null;
106 if (newcol instanceof Color)
109 col = (Color) newcol;
112 else if (newcol instanceof GraduatedColor)
115 gcol = (GraduatedColor) newcol;
122 .getString("error.invalid_colour_for_mycheckbox"));
126 setBackground(bg = col);
130 if (gcol.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
133 + ((gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD) ? "(>)"
136 if (isColourByLabel = gcol.isColourByLabel())
138 setBackground(bg = Color.white);
139 vlabel += " (by Label)";
143 setBackground(bg = gcol.getMinColor());
144 maxCol = gcol.getMaxColor();
157 public void paint(Graphics g)
159 Dimension d = getSize();
164 g.setColor(Color.white);
165 g.fillRect(d.width / 2, 0, d.width / 2, d.height);
166 g.setColor(Color.black);
167 Font f = new Font("Verdana", Font.PLAIN, 10);
169 g.drawString(MessageManager.getString("label.label"), 0, 0);
174 g.fillRect(d.width / 2, 0, d.width / 2, d.height);
182 boolean amendFeatures(final SequenceI[] sequences,
183 final SequenceFeature[] features, boolean newFeatures,
184 final AlignmentPanel ap)
186 Panel bigPanel = new Panel(new BorderLayout());
187 final TextField name = new TextField(16);
188 final TextField source = new TextField(16);
189 final TextArea description = new TextArea(3, 35);
190 final TextField start = new TextField(8);
191 final TextField end = new TextField(8);
192 final Choice overlaps;
193 Button deleteButton = new Button("Delete");
194 deleteFeature = false;
196 colourPanel = new FeatureColourPanel();
197 colourPanel.setSize(110, 15);
198 final FeatureRenderer fr = this;
200 Panel panel = new Panel(new GridLayout(3, 1));
202 featureIndex = 0; // feature to be amended.
205 // /////////////////////////////////////
206 // /MULTIPLE FEATURES AT SELECTED RESIDUE
207 if (!newFeatures && features.length > 1)
209 panel = new Panel(new GridLayout(4, 1));
211 tmp.add(new Label("Select Feature: "));
212 overlaps = new Choice();
213 for (int i = 0; i < features.length; i++)
215 String item = features[i].getType() + "/" + features[i].getBegin()
216 + "-" + features[i].getEnd();
218 if (features[i].getFeatureGroup() != null)
220 item += " (" + features[i].getFeatureGroup() + ")";
223 overlaps.addItem(item);
228 overlaps.addItemListener(new java.awt.event.ItemListener()
230 public void itemStateChanged(java.awt.event.ItemEvent e)
232 int index = overlaps.getSelectedIndex();
235 featureIndex = index;
236 name.setText(features[index].getType());
237 description.setText(features[index].getDescription());
238 source.setText(features[index].getFeatureGroup());
239 start.setText(features[index].getBegin() + "");
240 end.setText(features[index].getEnd() + "");
242 SearchResults highlight = new SearchResults();
243 highlight.addResult(sequences[0], features[index].getBegin(),
244 features[index].getEnd());
246 ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
249 Object col = getFeatureStyle(name.getText());
252 col = new jalview.schemes.UserColourScheme()
253 .createColourFromName(name.getText());
256 colourPanel.updateColor(col);
263 // ////////////////////////////////////
267 tmp.add(new Label("Name: ", Label.RIGHT));
272 tmp.add(new Label("Group: ", Label.RIGHT));
277 tmp.add(new Label("Colour: ", Label.RIGHT));
278 tmp.add(colourPanel);
280 bigPanel.add(panel, BorderLayout.NORTH);
283 panel.add(new Label("Description: ", Label.RIGHT));
284 panel.add(new ScrollPane().add(description));
288 bigPanel.add(panel, BorderLayout.SOUTH);
291 panel.add(new Label(" Start:", Label.RIGHT));
293 panel.add(new Label(" End:", Label.RIGHT));
295 bigPanel.add(panel, BorderLayout.CENTER);
299 bigPanel.add(panel, BorderLayout.CENTER);
302 if (lastFeatureAdded == null)
304 if (features[0].type != null)
306 lastFeatureAdded = features[0].type;
310 lastFeatureAdded = "feature_1";
314 if (lastFeatureGroupAdded == null)
316 if (features[0].featureGroup != null)
318 lastFeatureGroupAdded = features[0].featureGroup;
322 lastFeatureAdded = "Jalview";
326 String title = newFeatures ? MessageManager
327 .getString("label.create_new_sequence_features")
328 : MessageManager.formatMessage("label.amend_delete_features",
330 { sequences[0].getName() });
332 final JVDialog dialog = new JVDialog(ap.alignFrame, title, true, 385,
335 dialog.setMainPanel(bigPanel);
339 name.setText(lastFeatureAdded);
340 source.setText(lastFeatureGroupAdded);
344 dialog.ok.setLabel(MessageManager.getString("label.amend"));
345 dialog.buttonPanel.add(deleteButton, 1);
346 deleteButton.addActionListener(new ActionListener()
348 public void actionPerformed(ActionEvent evt)
350 deleteFeature = true;
351 dialog.setVisible(false);
354 name.setText(features[0].getType());
355 source.setText(features[0].getFeatureGroup());
358 start.setText(features[0].getBegin() + "");
359 end.setText(features[0].getEnd() + "");
360 description.setText(features[0].getDescription());
361 Color col = getColour(name.getText());
364 col = new jalview.schemes.UserColourScheme()
365 .createColourFromName(name.getText());
367 Object fcol = getFeatureStyle(name.getText());
368 // simply display the feature color in a box
369 colourPanel.updateColor(fcol);
370 dialog.setResizable(true);
371 // TODO: render the graduated color in the box.
372 colourPanel.addMouseListener(new java.awt.event.MouseAdapter()
374 public void mousePressed(java.awt.event.MouseEvent evt)
376 if (!colourPanel.isGcol)
378 new UserDefinedColours(fr, ap.alignFrame);
382 FeatureColourChooser fcc = new FeatureColourChooser(
383 ap.alignFrame, name.getText());
384 dialog.transferFocus();
388 dialog.setVisible(true);
390 jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
394 // This ensures that the last sequence
395 // is refreshed and new features are rendered
397 lastFeatureAdded = name.getText().trim();
398 lastFeatureGroupAdded = source.getText().trim();
399 lastDescriptionAdded = description.getText().replace('\n', ' ');
402 if (lastFeatureGroupAdded != null && lastFeatureGroupAdded.length() < 1)
404 lastFeatureGroupAdded = null;
410 SequenceFeature sf = features[featureIndex];
413 sf.type = lastFeatureAdded;
414 sf.featureGroup = lastFeatureGroupAdded;
415 sf.description = lastDescriptionAdded;
416 if (!colourPanel.isGcol)
418 // update colour - otherwise its already done.
419 setColour(sf.type, colourPanel.getBackground());
423 sf.begin = Integer.parseInt(start.getText());
424 sf.end = Integer.parseInt(end.getText());
425 } catch (NumberFormatException ex)
429 ffile.parseDescriptionHTML(sf, false);
430 setVisible(lastFeatureAdded); // if user edited name then make sure new
435 sequences[0].deleteFeature(sf);
441 if (dialog.accept && name.getText().length() > 0)
443 for (int i = 0; i < sequences.length; i++)
445 features[i].type = lastFeatureAdded;
446 features[i].featureGroup = lastFeatureGroupAdded;
447 features[i].description = lastDescriptionAdded;
448 sequences[i].addSequenceFeature(features[i]);
449 ffile.parseDescriptionHTML(features[i], false);
452 Color newColour = colourPanel.getBackground();
453 // setColour(lastFeatureAdded, fcol);
455 if (lastFeatureGroupAdded != null)
457 setGroupVisibility(lastFeatureGroupAdded, true);
459 setColour(lastFeatureAdded, newColour); // was fcol
460 setVisible(lastFeatureAdded);
461 findAllFeatures(false); // different to original applet behaviour ?
462 // findAllFeatures();
466 // no update to the alignment
470 // refresh the alignment and the feature settings dialog
471 if (((jalview.appletgui.AlignViewport) av).featureSettings != null)
473 ((jalview.appletgui.AlignViewport) av).featureSettings.refreshTable();
475 // findAllFeatures();
477 ap.paintAlignment(true);