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)
67 setTransparencyAvailable(!System.getProperty("java.version")
71 static String lastFeatureAdded;
73 static String lastFeatureGroupAdded;
75 static String lastDescriptionAdded;
79 boolean deleteFeature = false;
81 FeatureColourPanel colourPanel;
83 class FeatureColourPanel extends Panel
89 private boolean isColourByLabel, isGcol;
92 * render a feature style in the amend feature dialog box
94 public void updateColor(Object newcol)
98 GraduatedColor gcol = null;
100 if (newcol instanceof Color)
103 col = (Color) newcol;
106 else if (newcol instanceof GraduatedColor)
109 gcol = (GraduatedColor) newcol;
116 .getString("error.invalid_colour_for_mycheckbox"));
120 setBackground(bg = col);
124 if (gcol.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
127 + ((gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD) ? "(>)"
130 if (isColourByLabel = gcol.isColourByLabel())
132 setBackground(bg = Color.white);
133 vlabel += " (by Label)";
137 setBackground(bg = gcol.getMinColor());
138 maxCol = gcol.getMaxColor();
152 public void paint(Graphics g)
154 Dimension d = getSize();
159 g.setColor(Color.white);
160 g.fillRect(d.width / 2, 0, d.width / 2, d.height);
161 g.setColor(Color.black);
162 Font f = new Font("Verdana", Font.PLAIN, 10);
164 g.drawString(MessageManager.getString("label.label"), 0, 0);
169 g.fillRect(d.width / 2, 0, d.width / 2, d.height);
177 boolean amendFeatures(final SequenceI[] sequences,
178 final SequenceFeature[] features, boolean newFeatures,
179 final AlignmentPanel ap)
181 Panel bigPanel = new Panel(new BorderLayout());
182 final TextField name = new TextField(16);
183 final TextField source = new TextField(16);
184 final TextArea description = new TextArea(3, 35);
185 final TextField start = new TextField(8);
186 final TextField end = new TextField(8);
187 final Choice overlaps;
188 Button deleteButton = new Button("Delete");
189 deleteFeature = false;
191 colourPanel = new FeatureColourPanel();
192 colourPanel.setSize(110, 15);
193 final FeatureRenderer fr = this;
195 Panel panel = new Panel(new GridLayout(3, 1));
197 featureIndex = 0; // feature to be amended.
200 // /////////////////////////////////////
201 // /MULTIPLE FEATURES AT SELECTED RESIDUE
202 if (!newFeatures && features.length > 1)
204 panel = new Panel(new GridLayout(4, 1));
206 tmp.add(new Label("Select Feature: "));
207 overlaps = new Choice();
208 for (int i = 0; i < features.length; i++)
210 String item = features[i].getType() + "/" + features[i].getBegin()
211 + "-" + features[i].getEnd();
213 if (features[i].getFeatureGroup() != null)
215 item += " (" + features[i].getFeatureGroup() + ")";
218 overlaps.addItem(item);
223 overlaps.addItemListener(new java.awt.event.ItemListener()
226 public void itemStateChanged(java.awt.event.ItemEvent e)
228 int index = overlaps.getSelectedIndex();
231 featureIndex = index;
232 name.setText(features[index].getType());
233 description.setText(features[index].getDescription());
234 source.setText(features[index].getFeatureGroup());
235 start.setText(features[index].getBegin() + "");
236 end.setText(features[index].getEnd() + "");
238 SearchResults highlight = new SearchResults();
239 highlight.addResult(sequences[0], features[index].getBegin(),
240 features[index].getEnd());
242 ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
245 Object col = getFeatureStyle(name.getText());
248 col = new jalview.schemes.UserColourScheme()
249 .createColourFromName(name.getText());
252 colourPanel.updateColor(col);
259 // ////////////////////////////////////
263 tmp.add(new Label("Name: ", Label.RIGHT));
268 tmp.add(new Label("Group: ", Label.RIGHT));
273 tmp.add(new Label("Colour: ", Label.RIGHT));
274 tmp.add(colourPanel);
276 bigPanel.add(panel, BorderLayout.NORTH);
279 panel.add(new Label("Description: ", Label.RIGHT));
280 panel.add(new ScrollPane().add(description));
284 bigPanel.add(panel, BorderLayout.SOUTH);
287 panel.add(new Label(" Start:", Label.RIGHT));
289 panel.add(new Label(" End:", Label.RIGHT));
291 bigPanel.add(panel, BorderLayout.CENTER);
295 bigPanel.add(panel, BorderLayout.CENTER);
298 if (lastFeatureAdded == null)
300 if (features[0].type != null)
302 lastFeatureAdded = features[0].type;
306 lastFeatureAdded = "feature_1";
310 if (lastFeatureGroupAdded == null)
312 if (features[0].featureGroup != null)
314 lastFeatureGroupAdded = features[0].featureGroup;
318 lastFeatureAdded = "Jalview";
322 String title = newFeatures ? MessageManager
323 .getString("label.create_new_sequence_features")
324 : MessageManager.formatMessage("label.amend_delete_features",
325 new String[] { sequences[0].getName() });
327 final JVDialog dialog = new JVDialog(ap.alignFrame, title, true, 385,
330 dialog.setMainPanel(bigPanel);
334 name.setText(lastFeatureAdded);
335 source.setText(lastFeatureGroupAdded);
339 dialog.ok.setLabel(MessageManager.getString("label.amend"));
340 dialog.buttonPanel.add(deleteButton, 1);
341 deleteButton.addActionListener(new ActionListener()
344 public void actionPerformed(ActionEvent evt)
346 deleteFeature = true;
347 dialog.setVisible(false);
350 name.setText(features[0].getType());
351 source.setText(features[0].getFeatureGroup());
354 start.setText(features[0].getBegin() + "");
355 end.setText(features[0].getEnd() + "");
356 description.setText(features[0].getDescription());
357 Color col = getColour(name.getText());
360 col = new jalview.schemes.UserColourScheme()
361 .createColourFromName(name.getText());
363 Object fcol = getFeatureStyle(name.getText());
364 // simply display the feature color in a box
365 colourPanel.updateColor(fcol);
366 dialog.setResizable(true);
367 // TODO: render the graduated color in the box.
368 colourPanel.addMouseListener(new java.awt.event.MouseAdapter()
371 public void mousePressed(java.awt.event.MouseEvent evt)
373 if (!colourPanel.isGcol)
375 new UserDefinedColours(fr, ap.alignFrame);
379 FeatureColourChooser fcc = new FeatureColourChooser(
380 ap.alignFrame, name.getText());
381 dialog.transferFocus();
385 dialog.setVisible(true);
387 jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
391 // This ensures that the last sequence
392 // is refreshed and new features are rendered
394 lastFeatureAdded = name.getText().trim();
395 lastFeatureGroupAdded = source.getText().trim();
396 lastDescriptionAdded = description.getText().replace('\n', ' ');
399 if (lastFeatureGroupAdded != null && lastFeatureGroupAdded.length() < 1)
401 lastFeatureGroupAdded = null;
407 SequenceFeature sf = features[featureIndex];
410 sf.type = lastFeatureAdded;
411 sf.featureGroup = lastFeatureGroupAdded;
412 sf.description = lastDescriptionAdded;
413 if (!colourPanel.isGcol)
415 // update colour - otherwise its already done.
416 setColour(sf.type, colourPanel.getBackground());
420 sf.begin = Integer.parseInt(start.getText());
421 sf.end = Integer.parseInt(end.getText());
422 } catch (NumberFormatException ex)
426 ffile.parseDescriptionHTML(sf, false);
427 setVisible(lastFeatureAdded); // if user edited name then make sure new
432 sequences[0].deleteFeature(sf);
438 if (dialog.accept && name.getText().length() > 0)
440 for (int i = 0; i < sequences.length; i++)
442 features[i].type = lastFeatureAdded;
443 features[i].featureGroup = lastFeatureGroupAdded;
444 features[i].description = lastDescriptionAdded;
445 sequences[i].addSequenceFeature(features[i]);
446 ffile.parseDescriptionHTML(features[i], false);
449 Color newColour = colourPanel.getBackground();
450 // setColour(lastFeatureAdded, fcol);
452 if (lastFeatureGroupAdded != null)
454 setGroupVisibility(lastFeatureGroupAdded, true);
456 setColour(lastFeatureAdded, newColour); // was fcol
457 setVisible(lastFeatureAdded);
458 findAllFeatures(false); // different to original applet behaviour ?
459 // findAllFeatures();
463 // no update to the alignment
467 // refresh the alignment and the feature settings dialog
468 if (((jalview.appletgui.AlignViewport) av).featureSettings != null)
470 ((jalview.appletgui.AlignViewport) av).featureSettings.refreshTable();
472 // findAllFeatures();
474 ap.paintAlignment(true);