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 jalview.datamodel.SearchResults;
24 import jalview.datamodel.SequenceFeature;
25 import jalview.datamodel.SequenceI;
26 import jalview.schemes.AnnotationColourGradient;
27 import jalview.schemes.GraduatedColor;
28 import jalview.util.MessageManager;
29 import jalview.viewmodel.AlignmentViewport;
31 import java.awt.BorderLayout;
32 import java.awt.Button;
33 import java.awt.Choice;
34 import java.awt.Color;
35 import java.awt.Dimension;
37 import java.awt.Graphics;
38 import java.awt.GridLayout;
39 import java.awt.Label;
40 import java.awt.Panel;
41 import java.awt.ScrollPane;
42 import java.awt.TextArea;
43 import java.awt.TextField;
44 import java.awt.event.ActionEvent;
45 import java.awt.event.ActionListener;
53 public class FeatureRenderer extends
54 jalview.renderer.seqfeatures.FeatureRenderer
57 * Creates a new FeatureRenderer object.
62 public FeatureRenderer(AlignmentViewport av)
68 static String lastFeatureAdded;
70 static String lastFeatureGroupAdded;
72 static String lastDescriptionAdded;
76 boolean deleteFeature = false;
78 FeatureColourPanel colourPanel;
80 class FeatureColourPanel extends Panel
86 private boolean isColourByLabel, isGcol;
89 * render a feature style in the amend feature dialog box
91 public void updateColor(Object newcol)
95 GraduatedColor gcol = null;
97 if (newcol instanceof Color)
100 col = (Color) newcol;
103 else if (newcol instanceof GraduatedColor)
106 gcol = (GraduatedColor) newcol;
113 .getString("error.invalid_colour_for_mycheckbox"));
117 setBackground(bg = col);
121 if (gcol.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
124 + ((gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD) ? "(>)"
127 if (isColourByLabel = gcol.isColourByLabel())
129 setBackground(bg = Color.white);
130 vlabel += " (by Label)";
134 setBackground(bg = gcol.getMinColor());
135 maxCol = gcol.getMaxColor();
149 public void paint(Graphics g)
151 Dimension d = getSize();
156 g.setColor(Color.white);
157 g.fillRect(d.width / 2, 0, d.width / 2, d.height);
158 g.setColor(Color.black);
159 Font f = new Font("Verdana", Font.PLAIN, 10);
161 g.drawString(MessageManager.getString("label.label"), 0, 0);
166 g.fillRect(d.width / 2, 0, d.width / 2, d.height);
174 boolean amendFeatures(final SequenceI[] sequences,
175 final SequenceFeature[] features, boolean newFeatures,
176 final AlignmentPanel ap)
178 Panel bigPanel = new Panel(new BorderLayout());
179 final TextField name = new TextField(16);
180 final TextField source = new TextField(16);
181 final TextArea description = new TextArea(3, 35);
182 final TextField start = new TextField(8);
183 final TextField end = new TextField(8);
184 final Choice overlaps;
185 Button deleteButton = new Button("Delete");
186 deleteFeature = false;
188 colourPanel = new FeatureColourPanel();
189 colourPanel.setSize(110, 15);
190 final FeatureRenderer fr = this;
192 Panel panel = new Panel(new GridLayout(3, 1));
194 featureIndex = 0; // feature to be amended.
197 // /////////////////////////////////////
198 // /MULTIPLE FEATURES AT SELECTED RESIDUE
199 if (!newFeatures && features.length > 1)
201 panel = new Panel(new GridLayout(4, 1));
203 tmp.add(new Label("Select Feature: "));
204 overlaps = new Choice();
205 for (int i = 0; i < features.length; i++)
207 String item = features[i].getType() + "/" + features[i].getBegin()
208 + "-" + features[i].getEnd();
210 if (features[i].getFeatureGroup() != null)
212 item += " (" + features[i].getFeatureGroup() + ")";
215 overlaps.addItem(item);
220 overlaps.addItemListener(new java.awt.event.ItemListener()
223 public void itemStateChanged(java.awt.event.ItemEvent e)
225 int index = overlaps.getSelectedIndex();
228 featureIndex = index;
229 name.setText(features[index].getType());
230 description.setText(features[index].getDescription());
231 source.setText(features[index].getFeatureGroup());
232 start.setText(features[index].getBegin() + "");
233 end.setText(features[index].getEnd() + "");
235 SearchResults highlight = new SearchResults();
236 highlight.addResult(sequences[0], features[index].getBegin(),
237 features[index].getEnd());
239 ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
242 Object col = getFeatureStyle(name.getText());
245 col = new jalview.schemes.UserColourScheme()
246 .createColourFromName(name.getText());
249 colourPanel.updateColor(col);
256 // ////////////////////////////////////
260 tmp.add(new Label("Name: ", Label.RIGHT));
265 tmp.add(new Label("Group: ", Label.RIGHT));
270 tmp.add(new Label("Colour: ", Label.RIGHT));
271 tmp.add(colourPanel);
273 bigPanel.add(panel, BorderLayout.NORTH);
276 panel.add(new Label("Description: ", Label.RIGHT));
277 panel.add(new ScrollPane().add(description));
281 bigPanel.add(panel, BorderLayout.SOUTH);
284 panel.add(new Label(" Start:", Label.RIGHT));
286 panel.add(new Label(" End:", Label.RIGHT));
288 bigPanel.add(panel, BorderLayout.CENTER);
292 bigPanel.add(panel, BorderLayout.CENTER);
295 if (lastFeatureAdded == null)
297 if (features[0].type != null)
299 lastFeatureAdded = features[0].type;
303 lastFeatureAdded = "feature_1";
307 if (lastFeatureGroupAdded == null)
309 if (features[0].featureGroup != null)
311 lastFeatureGroupAdded = features[0].featureGroup;
315 lastFeatureAdded = "Jalview";
319 String title = newFeatures ? MessageManager
320 .getString("label.create_new_sequence_features")
321 : MessageManager.formatMessage("label.amend_delete_features",
322 new String[] { sequences[0].getName() });
324 final JVDialog dialog = new JVDialog(ap.alignFrame, title, true, 385,
327 dialog.setMainPanel(bigPanel);
331 name.setText(lastFeatureAdded);
332 source.setText(lastFeatureGroupAdded);
336 dialog.ok.setLabel(MessageManager.getString("label.amend"));
337 dialog.buttonPanel.add(deleteButton, 1);
338 deleteButton.addActionListener(new ActionListener()
341 public void actionPerformed(ActionEvent evt)
343 deleteFeature = true;
344 dialog.setVisible(false);
347 name.setText(features[0].getType());
348 source.setText(features[0].getFeatureGroup());
351 start.setText(features[0].getBegin() + "");
352 end.setText(features[0].getEnd() + "");
353 description.setText(features[0].getDescription());
354 Object fcol = getFeatureStyle(name.getText());
355 // simply display the feature color in a box
356 colourPanel.updateColor(fcol);
357 dialog.setResizable(true);
358 // TODO: render the graduated color in the box.
359 colourPanel.addMouseListener(new java.awt.event.MouseAdapter()
362 public void mousePressed(java.awt.event.MouseEvent evt)
364 if (!colourPanel.isGcol)
366 new UserDefinedColours(fr, ap.alignFrame);
370 FeatureColourChooser fcc = new FeatureColourChooser(
371 ap.alignFrame, name.getText());
372 dialog.transferFocus();
376 dialog.setVisible(true);
378 jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
382 // This ensures that the last sequence
383 // is refreshed and new features are rendered
385 lastFeatureAdded = name.getText().trim();
386 lastFeatureGroupAdded = source.getText().trim();
387 lastDescriptionAdded = description.getText().replace('\n', ' ');
390 if (lastFeatureGroupAdded != null && lastFeatureGroupAdded.length() < 1)
392 lastFeatureGroupAdded = null;
398 SequenceFeature sf = features[featureIndex];
401 sf.type = lastFeatureAdded;
402 sf.featureGroup = lastFeatureGroupAdded;
403 sf.description = lastDescriptionAdded;
404 if (!colourPanel.isGcol)
406 // update colour - otherwise its already done.
407 setColour(sf.type, colourPanel.getBackground());
411 sf.begin = Integer.parseInt(start.getText());
412 sf.end = Integer.parseInt(end.getText());
413 } catch (NumberFormatException ex)
417 ffile.parseDescriptionHTML(sf, false);
418 setVisible(lastFeatureAdded); // if user edited name then make sure new
423 sequences[0].deleteFeature(sf);
429 if (dialog.accept && name.getText().length() > 0)
431 for (int i = 0; i < sequences.length; i++)
433 features[i].type = lastFeatureAdded;
434 features[i].featureGroup = lastFeatureGroupAdded;
435 features[i].description = lastDescriptionAdded;
436 sequences[i].addSequenceFeature(features[i]);
437 ffile.parseDescriptionHTML(features[i], false);
440 Color newColour = colourPanel.getBackground();
441 // setColour(lastFeatureAdded, fcol);
443 if (lastFeatureGroupAdded != null)
445 setGroupVisibility(lastFeatureGroupAdded, true);
447 setColour(lastFeatureAdded, newColour); // was fcol
448 setVisible(lastFeatureAdded);
449 findAllFeatures(false); // different to original applet behaviour ?
450 // findAllFeatures();
454 // no update to the alignment
458 // refresh the alignment and the feature settings dialog
459 if (((jalview.appletgui.AlignViewport) av).featureSettings != null)
461 ((jalview.appletgui.AlignViewport) av).featureSettings.refreshTable();
463 // findAllFeatures();
465 ap.paintAlignment(true);