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;
25 import java.awt.event.*;
27 import jalview.datamodel.*;
28 import jalview.schemes.AnnotationColourGradient;
29 import jalview.schemes.GraduatedColor;
30 import jalview.util.MessageManager;
31 import jalview.viewmodel.AlignmentViewport;
32 import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
40 public class FeatureRenderer extends jalview.renderer.seqfeatures.FeatureRenderer
43 // Holds web links for feature groups and feature types
44 // in the form label|link
45 Hashtable featureLinks = null;
48 * Creates a new FeatureRenderer object.
53 public FeatureRenderer(AlignmentViewport av)
58 setTransparencyAvailable(!System.getProperty("java.version").startsWith("1.1"));
61 static String lastFeatureAdded;
63 static String lastFeatureGroupAdded;
65 static String lastDescriptionAdded;
69 boolean deleteFeature = false;
71 FeatureColourPanel colourPanel;
73 class FeatureColourPanel extends Panel
79 private boolean isColourByLabel, isGcol;
82 * render a feature style in the amend feature dialog box
84 public void updateColor(Object newcol)
88 GraduatedColor gcol = null;
90 if (newcol instanceof Color)
96 else if (newcol instanceof GraduatedColor)
99 gcol = (GraduatedColor) newcol;
104 throw new Error(MessageManager.getString("error.invalid_colour_for_mycheckbox"));
108 setBackground(bg = col);
112 if (gcol.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
115 + ((gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD) ? "(>)"
118 if (isColourByLabel = gcol.isColourByLabel())
120 setBackground(bg = Color.white);
121 vlabel += " (by Label)";
125 setBackground(bg = gcol.getMinColor());
126 maxCol = gcol.getMaxColor();
139 public void paint(Graphics g)
141 Dimension d = getSize();
146 g.setColor(Color.white);
147 g.fillRect(d.width / 2, 0, d.width / 2, d.height);
148 g.setColor(Color.black);
149 Font f = new Font("Verdana", Font.PLAIN, 10);
151 g.drawString(MessageManager.getString("label.label"), 0, 0);
156 g.fillRect(d.width / 2, 0, d.width / 2, d.height);
164 boolean amendFeatures(final SequenceI[] sequences,
165 final SequenceFeature[] features, boolean newFeatures,
166 final AlignmentPanel ap)
168 Panel bigPanel = new Panel(new BorderLayout());
169 final TextField name = new TextField(16);
170 final TextField source = new TextField(16);
171 final TextArea description = new TextArea(3, 35);
172 final TextField start = new TextField(8);
173 final TextField end = new TextField(8);
174 final Choice overlaps;
175 Button deleteButton = new Button("Delete");
176 deleteFeature = false;
178 colourPanel = new FeatureColourPanel();
179 colourPanel.setSize(110, 15);
180 final FeatureRenderer fr = this;
182 Panel panel = new Panel(new GridLayout(3, 1));
184 featureIndex = 0; // feature to be amended.
187 // /////////////////////////////////////
188 // /MULTIPLE FEATURES AT SELECTED RESIDUE
189 if (!newFeatures && features.length > 1)
191 panel = new Panel(new GridLayout(4, 1));
193 tmp.add(new Label("Select Feature: "));
194 overlaps = new Choice();
195 for (int i = 0; i < features.length; i++)
197 String item = features[i].getType() + "/" + features[i].getBegin()
198 + "-" + features[i].getEnd();
200 if (features[i].getFeatureGroup() != null)
201 item += " (" + features[i].getFeatureGroup() + ")";
203 overlaps.addItem(item);
208 overlaps.addItemListener(new java.awt.event.ItemListener()
210 public void itemStateChanged(java.awt.event.ItemEvent e)
212 int index = overlaps.getSelectedIndex();
215 featureIndex = index;
216 name.setText(features[index].getType());
217 description.setText(features[index].getDescription());
218 source.setText(features[index].getFeatureGroup());
219 start.setText(features[index].getBegin() + "");
220 end.setText(features[index].getEnd() + "");
222 SearchResults highlight = new SearchResults();
223 highlight.addResult(sequences[0], features[index].getBegin(),
224 features[index].getEnd());
226 ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
229 Object col = getFeatureStyle(name.getText());
232 col = new jalview.schemes.UserColourScheme()
233 .createColourFromName(name.getText());
236 colourPanel.updateColor(col);
243 // ////////////////////////////////////
247 tmp.add(new Label("Name: ", Label.RIGHT));
252 tmp.add(new Label("Group: ", Label.RIGHT));
257 tmp.add(new Label("Colour: ", Label.RIGHT));
258 tmp.add(colourPanel);
260 bigPanel.add(panel, BorderLayout.NORTH);
263 panel.add(new Label("Description: ", Label.RIGHT));
264 panel.add(new ScrollPane().add(description));
268 bigPanel.add(panel, BorderLayout.SOUTH);
271 panel.add(new Label(" Start:", Label.RIGHT));
273 panel.add(new Label(" End:", Label.RIGHT));
275 bigPanel.add(panel, BorderLayout.CENTER);
279 bigPanel.add(panel, BorderLayout.CENTER);
282 if (lastFeatureAdded == null)
284 if (features[0].type != null)
286 lastFeatureAdded = features[0].type;
290 lastFeatureAdded = "feature_1";
294 if (lastFeatureGroupAdded == null)
296 if (features[0].featureGroup != null)
298 lastFeatureGroupAdded = features[0].featureGroup;
302 lastFeatureAdded = "Jalview";
306 String title = newFeatures ? MessageManager.getString("label.create_new_sequence_features")
307 : MessageManager.formatMessage("label.amend_delete_features", new String[]{sequences[0].getName()});
309 final JVDialog dialog = new JVDialog(ap.alignFrame, title, true, 385,
312 dialog.setMainPanel(bigPanel);
316 name.setText(lastFeatureAdded);
317 source.setText(lastFeatureGroupAdded);
321 dialog.ok.setLabel(MessageManager.getString("label.amend"));
322 dialog.buttonPanel.add(deleteButton, 1);
323 deleteButton.addActionListener(new ActionListener()
325 public void actionPerformed(ActionEvent evt)
327 deleteFeature = true;
328 dialog.setVisible(false);
331 name.setText(features[0].getType());
332 source.setText(features[0].getFeatureGroup());
335 start.setText(features[0].getBegin() + "");
336 end.setText(features[0].getEnd() + "");
337 description.setText(features[0].getDescription());
338 Color col = getColour(name.getText());
341 col = new jalview.schemes.UserColourScheme()
342 .createColourFromName(name.getText());
344 Object fcol = getFeatureStyle(name.getText());
345 // simply display the feature color in a box
346 colourPanel.updateColor(fcol);
347 dialog.setResizable(true);
348 // TODO: render the graduated color in the box.
349 colourPanel.addMouseListener(new java.awt.event.MouseAdapter()
351 public void mousePressed(java.awt.event.MouseEvent evt)
353 if (!colourPanel.isGcol)
355 new UserDefinedColours(fr, ap.alignFrame);
359 FeatureColourChooser fcc = new FeatureColourChooser(
360 ap.alignFrame, name.getText());
361 dialog.transferFocus();
365 dialog.setVisible(true);
367 jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
371 // This ensures that the last sequence
372 // is refreshed and new features are rendered
374 lastFeatureAdded = name.getText().trim();
375 lastFeatureGroupAdded = source.getText().trim();
376 lastDescriptionAdded = description.getText().replace('\n', ' ');
379 if (lastFeatureGroupAdded != null && lastFeatureGroupAdded.length() < 1)
380 lastFeatureGroupAdded = null;
385 SequenceFeature sf = features[featureIndex];
388 sf.type = lastFeatureAdded;
389 sf.featureGroup = lastFeatureGroupAdded;
390 sf.description = lastDescriptionAdded;
391 if (!colourPanel.isGcol)
393 // update colour - otherwise its already done.
394 setColour(sf.type, colourPanel.getBackground());
398 sf.begin = Integer.parseInt(start.getText());
399 sf.end = Integer.parseInt(end.getText());
400 } catch (NumberFormatException ex)
404 ffile.parseDescriptionHTML(sf, false);
405 setVisible(lastFeatureAdded); // if user edited name then make sure new type is visible
409 sequences[0].deleteFeature(sf);
415 if (dialog.accept && name.getText().length() > 0)
417 for (int i = 0; i < sequences.length; i++)
419 features[i].type = lastFeatureAdded;
420 features[i].featureGroup = lastFeatureGroupAdded;
421 features[i].description = lastDescriptionAdded;
422 sequences[i].addSequenceFeature(features[i]);
423 ffile.parseDescriptionHTML(features[i], false);
426 col = colourPanel.getBackground();
427 // setColour(lastFeatureAdded, fcol);
429 if (lastFeatureGroupAdded != null)
431 setGroupVisibility(lastFeatureGroupAdded, true);
433 setColour(lastFeatureAdded, fcol);
434 setVisible(lastFeatureAdded);
435 findAllFeatures(false); // different to original applet behaviour ?
436 // findAllFeatures();
440 // no update to the alignment
444 // refresh the alignment and the feature settings dialog
445 if (((jalview.appletgui.AlignViewport) av).featureSettings != null)
447 ((jalview.appletgui.AlignViewport) av).featureSettings.refreshTable();
449 // findAllFeatures();
451 ap.paintAlignment(true);