2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.seqfeatures.FeaturesDisplayed;
39 public class FeatureRenderer extends jalview.renderer.seqfeatures.FeatureRenderer
42 // Holds web links for feature groups and feature types
43 // in the form label|link
44 Hashtable featureLinks = null;
47 * Creates a new FeatureRenderer object.
52 public FeatureRenderer(AlignViewport av)
57 setTransparencyAvailable(!System.getProperty("java.version").startsWith("1.1"));
60 static String lastFeatureAdded;
62 static String lastFeatureGroupAdded;
64 static String lastDescriptionAdded;
68 boolean deleteFeature = false;
70 FeatureColourPanel colourPanel;
72 class FeatureColourPanel extends Panel
78 private boolean isColourByLabel, isGcol;
81 * render a feature style in the amend feature dialog box
83 public void updateColor(Object newcol)
87 GraduatedColor gcol = null;
89 if (newcol instanceof Color)
95 else if (newcol instanceof GraduatedColor)
98 gcol = (GraduatedColor) newcol;
103 throw new Error(MessageManager.getString("error.invalid_colour_for_mycheckbox"));
107 setBackground(bg = col);
111 if (gcol.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
114 + ((gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD) ? "(>)"
117 if (isColourByLabel = gcol.isColourByLabel())
119 setBackground(bg = Color.white);
120 vlabel += " (by Label)";
124 setBackground(bg = gcol.getMinColor());
125 maxCol = gcol.getMaxColor();
138 public void paint(Graphics g)
140 Dimension d = getSize();
145 g.setColor(Color.white);
146 g.fillRect(d.width / 2, 0, d.width / 2, d.height);
147 g.setColor(Color.black);
148 Font f = new Font("Verdana", Font.PLAIN, 10);
150 g.drawString(MessageManager.getString("label.label"), 0, 0);
155 g.fillRect(d.width / 2, 0, d.width / 2, d.height);
163 boolean amendFeatures(final SequenceI[] sequences,
164 final SequenceFeature[] features, boolean newFeatures,
165 final AlignmentPanel ap)
167 Panel bigPanel = new Panel(new BorderLayout());
168 final TextField name = new TextField(16);
169 final TextField source = new TextField(16);
170 final TextArea description = new TextArea(3, 35);
171 final TextField start = new TextField(8);
172 final TextField end = new TextField(8);
173 final Choice overlaps;
174 Button deleteButton = new Button("Delete");
175 deleteFeature = false;
177 colourPanel = new FeatureColourPanel();
178 colourPanel.setSize(110, 15);
179 final FeatureRenderer fr = this;
181 Panel panel = new Panel(new GridLayout(3, 1));
183 featureIndex = 0; // feature to be amended.
186 // /////////////////////////////////////
187 // /MULTIPLE FEATURES AT SELECTED RESIDUE
188 if (!newFeatures && features.length > 1)
190 panel = new Panel(new GridLayout(4, 1));
192 tmp.add(new Label("Select Feature: "));
193 overlaps = new Choice();
194 for (int i = 0; i < features.length; i++)
196 String item = features[i].getType() + "/" + features[i].getBegin()
197 + "-" + features[i].getEnd();
199 if (features[i].getFeatureGroup() != null)
200 item += " (" + features[i].getFeatureGroup() + ")";
202 overlaps.addItem(item);
207 overlaps.addItemListener(new java.awt.event.ItemListener()
209 public void itemStateChanged(java.awt.event.ItemEvent e)
211 int index = overlaps.getSelectedIndex();
214 featureIndex = index;
215 name.setText(features[index].getType());
216 description.setText(features[index].getDescription());
217 source.setText(features[index].getFeatureGroup());
218 start.setText(features[index].getBegin() + "");
219 end.setText(features[index].getEnd() + "");
221 SearchResults highlight = new SearchResults();
222 highlight.addResult(sequences[0], features[index].getBegin(),
223 features[index].getEnd());
225 ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
228 Object col = getFeatureStyle(name.getText());
231 col = new jalview.schemes.UserColourScheme()
232 .createColourFromName(name.getText());
235 colourPanel.updateColor(col);
242 // ////////////////////////////////////
246 tmp.add(new Label("Name: ", Label.RIGHT));
251 tmp.add(new Label("Group: ", Label.RIGHT));
256 tmp.add(new Label("Colour: ", Label.RIGHT));
257 tmp.add(colourPanel);
259 bigPanel.add(panel, BorderLayout.NORTH);
262 panel.add(new Label("Description: ", Label.RIGHT));
263 panel.add(new ScrollPane().add(description));
267 bigPanel.add(panel, BorderLayout.SOUTH);
270 panel.add(new Label(" Start:", Label.RIGHT));
272 panel.add(new Label(" End:", Label.RIGHT));
274 bigPanel.add(panel, BorderLayout.CENTER);
278 bigPanel.add(panel, BorderLayout.CENTER);
281 if (lastFeatureAdded == null)
283 if (features[0].type != null)
285 lastFeatureAdded = features[0].type;
289 lastFeatureAdded = "feature_1";
293 if (lastFeatureGroupAdded == null)
295 if (features[0].featureGroup != null)
297 lastFeatureGroupAdded = features[0].featureGroup;
301 lastFeatureAdded = "Jalview";
305 String title = newFeatures ? MessageManager.getString("label.create_new_sequence_features")
306 : MessageManager.formatMessage("label.amend_delete_features", new String[]{sequences[0].getName()});
308 final JVDialog dialog = new JVDialog(ap.alignFrame, title, true, 385,
311 dialog.setMainPanel(bigPanel);
315 name.setText(lastFeatureAdded);
316 source.setText(lastFeatureGroupAdded);
320 dialog.ok.setLabel(MessageManager.getString("label.amend"));
321 dialog.buttonPanel.add(deleteButton, 1);
322 deleteButton.addActionListener(new ActionListener()
324 public void actionPerformed(ActionEvent evt)
326 deleteFeature = true;
327 dialog.setVisible(false);
330 name.setText(features[0].getType());
331 source.setText(features[0].getFeatureGroup());
334 start.setText(features[0].getBegin() + "");
335 end.setText(features[0].getEnd() + "");
336 description.setText(features[0].getDescription());
337 Color col = getColour(name.getText());
340 col = new jalview.schemes.UserColourScheme()
341 .createColourFromName(name.getText());
343 Object fcol = getFeatureStyle(name.getText());
344 // simply display the feature color in a box
345 colourPanel.updateColor(fcol);
346 dialog.setResizable(true);
347 // TODO: render the graduated color in the box.
348 colourPanel.addMouseListener(new java.awt.event.MouseAdapter()
350 public void mousePressed(java.awt.event.MouseEvent evt)
352 if (!colourPanel.isGcol)
354 new UserDefinedColours(fr, ap.alignFrame);
358 FeatureColourChooser fcc = new FeatureColourChooser(
359 ap.alignFrame, name.getText());
360 dialog.transferFocus();
364 dialog.setVisible(true);
366 jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
370 // This ensures that the last sequence
371 // is refreshed and new features are rendered
373 lastFeatureAdded = name.getText().trim();
374 lastFeatureGroupAdded = source.getText().trim();
375 lastDescriptionAdded = description.getText().replace('\n', ' ');
378 if (lastFeatureGroupAdded != null && lastFeatureGroupAdded.length() < 1)
379 lastFeatureGroupAdded = null;
384 SequenceFeature sf = features[featureIndex];
387 sf.type = lastFeatureAdded;
388 sf.featureGroup = lastFeatureGroupAdded;
389 sf.description = lastDescriptionAdded;
390 if (!colourPanel.isGcol)
392 // update colour - otherwise its already done.
393 setColour(sf.type, colourPanel.getBackground());
397 sf.begin = Integer.parseInt(start.getText());
398 sf.end = Integer.parseInt(end.getText());
399 } catch (NumberFormatException ex)
403 ffile.parseDescriptionHTML(sf, false);
404 setVisible(lastFeatureAdded); // if user edited name then make sure new type is visible
408 sequences[0].deleteFeature(sf);
414 if (dialog.accept && name.getText().length() > 0)
416 for (int i = 0; i < sequences.length; i++)
418 features[i].type = lastFeatureAdded;
419 features[i].featureGroup = lastFeatureGroupAdded;
420 features[i].description = lastDescriptionAdded;
421 sequences[i].addSequenceFeature(features[i]);
422 ffile.parseDescriptionHTML(features[i], false);
425 col = colourPanel.getBackground();
426 // setColour(lastFeatureAdded, fcol);
428 if (lastFeatureGroupAdded != null)
430 setGroupVisibility(lastFeatureGroupAdded, true);
432 setColour(lastFeatureAdded, fcol);
433 setVisible(lastFeatureAdded);
434 findAllFeatures(false); // different to original applet behaviour ?
435 // findAllFeatures();
439 // no update to the alignment
443 // refresh the alignment and the feature settings dialog
444 if (((jalview.appletgui.AlignViewport) av).featureSettings != null)
446 ((jalview.appletgui.AlignViewport) av).featureSettings.refreshTable();
448 // findAllFeatures();
450 ap.paintAlignment(true);