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)
66 setTransparencyAvailable(!System.getProperty("java.version")
70 static String lastFeatureAdded;
72 static String lastFeatureGroupAdded;
74 static String lastDescriptionAdded;
78 boolean deleteFeature = false;
80 FeatureColourPanel colourPanel;
82 class FeatureColourPanel extends Panel
88 private boolean isColourByLabel, isGcol;
91 * render a feature style in the amend feature dialog box
93 public void updateColor(Object newcol)
97 GraduatedColor gcol = null;
99 if (newcol instanceof Color)
102 col = (Color) newcol;
105 else if (newcol instanceof GraduatedColor)
108 gcol = (GraduatedColor) newcol;
115 .getString("error.invalid_colour_for_mycheckbox"));
119 setBackground(bg = col);
123 if (gcol.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
126 + ((gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD) ? "(>)"
129 if (isColourByLabel = gcol.isColourByLabel())
131 setBackground(bg = Color.white);
132 vlabel += " (by Label)";
136 setBackground(bg = gcol.getMinColor());
137 maxCol = gcol.getMaxColor();
151 public void paint(Graphics g)
153 Dimension d = getSize();
158 g.setColor(Color.white);
159 g.fillRect(d.width / 2, 0, d.width / 2, d.height);
160 g.setColor(Color.black);
161 Font f = new Font("Verdana", Font.PLAIN, 10);
163 g.drawString(MessageManager.getString("label.label"), 0, 0);
168 g.fillRect(d.width / 2, 0, d.width / 2, d.height);
176 boolean amendFeatures(final SequenceI[] sequences,
177 final SequenceFeature[] features, boolean newFeatures,
178 final AlignmentPanel ap)
180 Panel bigPanel = new Panel(new BorderLayout());
181 final TextField name = new TextField(16);
182 final TextField source = new TextField(16);
183 final TextArea description = new TextArea(3, 35);
184 final TextField start = new TextField(8);
185 final TextField end = new TextField(8);
186 final Choice overlaps;
187 Button deleteButton = new Button("Delete");
188 deleteFeature = false;
190 colourPanel = new FeatureColourPanel();
191 colourPanel.setSize(110, 15);
192 final FeatureRenderer fr = this;
194 Panel panel = new Panel(new GridLayout(3, 1));
196 featureIndex = 0; // feature to be amended.
199 // /////////////////////////////////////
200 // /MULTIPLE FEATURES AT SELECTED RESIDUE
201 if (!newFeatures && features.length > 1)
203 panel = new Panel(new GridLayout(4, 1));
205 tmp.add(new Label("Select Feature: "));
206 overlaps = new Choice();
207 for (int i = 0; i < features.length; i++)
209 String item = features[i].getType() + "/" + features[i].getBegin()
210 + "-" + features[i].getEnd();
212 if (features[i].getFeatureGroup() != null)
214 item += " (" + features[i].getFeatureGroup() + ")";
217 overlaps.addItem(item);
222 overlaps.addItemListener(new java.awt.event.ItemListener()
225 public void itemStateChanged(java.awt.event.ItemEvent e)
227 int index = overlaps.getSelectedIndex();
230 featureIndex = index;
231 name.setText(features[index].getType());
232 description.setText(features[index].getDescription());
233 source.setText(features[index].getFeatureGroup());
234 start.setText(features[index].getBegin() + "");
235 end.setText(features[index].getEnd() + "");
237 SearchResults highlight = new SearchResults();
238 highlight.addResult(sequences[0], features[index].getBegin(),
239 features[index].getEnd());
241 ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
244 Object col = getFeatureStyle(name.getText());
247 col = new jalview.schemes.UserColourScheme()
248 .createColourFromName(name.getText());
251 colourPanel.updateColor(col);
258 // ////////////////////////////////////
262 tmp.add(new Label("Name: ", Label.RIGHT));
267 tmp.add(new Label("Group: ", Label.RIGHT));
272 tmp.add(new Label("Colour: ", Label.RIGHT));
273 tmp.add(colourPanel);
275 bigPanel.add(panel, BorderLayout.NORTH);
278 panel.add(new Label("Description: ", Label.RIGHT));
279 panel.add(new ScrollPane().add(description));
283 bigPanel.add(panel, BorderLayout.SOUTH);
286 panel.add(new Label(" Start:", Label.RIGHT));
288 panel.add(new Label(" End:", Label.RIGHT));
290 bigPanel.add(panel, BorderLayout.CENTER);
294 bigPanel.add(panel, BorderLayout.CENTER);
297 if (lastFeatureAdded == null)
299 if (features[0].type != null)
301 lastFeatureAdded = features[0].type;
305 lastFeatureAdded = "feature_1";
309 if (lastFeatureGroupAdded == null)
311 if (features[0].featureGroup != null)
313 lastFeatureGroupAdded = features[0].featureGroup;
317 lastFeatureAdded = "Jalview";
321 String title = newFeatures ? MessageManager
322 .getString("label.create_new_sequence_features")
323 : MessageManager.formatMessage("label.amend_delete_features",
324 new String[] { sequences[0].getName() });
326 final JVDialog dialog = new JVDialog(ap.alignFrame, title, true, 385,
329 dialog.setMainPanel(bigPanel);
333 name.setText(lastFeatureAdded);
334 source.setText(lastFeatureGroupAdded);
338 dialog.ok.setLabel(MessageManager.getString("label.amend"));
339 dialog.buttonPanel.add(deleteButton, 1);
340 deleteButton.addActionListener(new ActionListener()
343 public void actionPerformed(ActionEvent evt)
345 deleteFeature = true;
346 dialog.setVisible(false);
349 name.setText(features[0].getType());
350 source.setText(features[0].getFeatureGroup());
353 start.setText(features[0].getBegin() + "");
354 end.setText(features[0].getEnd() + "");
355 description.setText(features[0].getDescription());
356 Color col = getColour(name.getText());
359 col = new jalview.schemes.UserColourScheme()
360 .createColourFromName(name.getText());
362 Object fcol = getFeatureStyle(name.getText());
363 // simply display the feature color in a box
364 colourPanel.updateColor(fcol);
365 dialog.setResizable(true);
366 // TODO: render the graduated color in the box.
367 colourPanel.addMouseListener(new java.awt.event.MouseAdapter()
370 public void mousePressed(java.awt.event.MouseEvent evt)
372 if (!colourPanel.isGcol)
374 new UserDefinedColours(fr, ap.alignFrame);
378 FeatureColourChooser fcc = new FeatureColourChooser(
379 ap.alignFrame, name.getText());
380 dialog.transferFocus();
384 dialog.setVisible(true);
386 jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
390 // This ensures that the last sequence
391 // is refreshed and new features are rendered
393 lastFeatureAdded = name.getText().trim();
394 lastFeatureGroupAdded = source.getText().trim();
395 lastDescriptionAdded = description.getText().replace('\n', ' ');
398 if (lastFeatureGroupAdded != null && lastFeatureGroupAdded.length() < 1)
400 lastFeatureGroupAdded = null;
406 SequenceFeature sf = features[featureIndex];
409 sf.type = lastFeatureAdded;
410 sf.featureGroup = lastFeatureGroupAdded;
411 sf.description = lastDescriptionAdded;
412 if (!colourPanel.isGcol)
414 // update colour - otherwise its already done.
415 setColour(sf.type, colourPanel.getBackground());
419 sf.begin = Integer.parseInt(start.getText());
420 sf.end = Integer.parseInt(end.getText());
421 } catch (NumberFormatException ex)
425 ffile.parseDescriptionHTML(sf, false);
426 setVisible(lastFeatureAdded); // if user edited name then make sure new
431 sequences[0].deleteFeature(sf);
437 if (dialog.accept && name.getText().length() > 0)
439 for (int i = 0; i < sequences.length; i++)
441 features[i].type = lastFeatureAdded;
442 features[i].featureGroup = lastFeatureGroupAdded;
443 features[i].description = lastDescriptionAdded;
444 sequences[i].addSequenceFeature(features[i]);
445 ffile.parseDescriptionHTML(features[i], false);
448 Color newColour = colourPanel.getBackground();
449 // setColour(lastFeatureAdded, fcol);
451 if (lastFeatureGroupAdded != null)
453 setGroupVisibility(lastFeatureGroupAdded, true);
455 setColour(lastFeatureAdded, newColour); // was fcol
456 setVisible(lastFeatureAdded);
457 findAllFeatures(false); // different to original applet behaviour ?
458 // findAllFeatures();
462 // no update to the alignment
466 // refresh the alignment and the feature settings dialog
467 if (((jalview.appletgui.AlignViewport) av).featureSettings != null)
469 ((jalview.appletgui.AlignViewport) av).featureSettings.refreshTable();
471 // findAllFeatures();
473 ap.paintAlignment(true);