Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 16:21:17 GMT
  2. Package jalview.appletgui

File UserDefinedColours.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
59% of files have more coverage

Code metrics

84
278
32
1
756
606
80
0.29
8.69
32
2.5

Classes

Class Line # Actions
UserDefinedColours 57 278 80
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.appletgui;
22   
23    import jalview.analysis.AAFrequency;
24    import jalview.api.FeatureColourI;
25    import jalview.datamodel.SequenceGroup;
26    import jalview.renderer.ResidueShader;
27    import jalview.schemes.Blosum62ColourScheme;
28    import jalview.schemes.ColourSchemeI;
29    import jalview.schemes.FeatureColour;
30    import jalview.schemes.PIDColourScheme;
31    import jalview.schemes.ResidueProperties;
32    import jalview.schemes.UserColourScheme;
33    import jalview.util.MessageManager;
34   
35    import java.awt.Button;
36    import java.awt.Color;
37    import java.awt.Component;
38    import java.awt.Container;
39    import java.awt.Dialog;
40    import java.awt.Font;
41    import java.awt.Frame;
42    import java.awt.GridLayout;
43    import java.awt.Label;
44    import java.awt.Panel;
45    import java.awt.Rectangle;
46    import java.awt.Scrollbar;
47    import java.awt.TextField;
48    import java.awt.event.ActionEvent;
49    import java.awt.event.ActionListener;
50    import java.awt.event.AdjustmentEvent;
51    import java.awt.event.AdjustmentListener;
52    import java.awt.event.FocusEvent;
53    import java.awt.event.FocusListener;
54    import java.awt.event.MouseEvent;
55    import java.util.Vector;
56   
 
57    public class UserDefinedColours extends Panel
58    implements ActionListener, AdjustmentListener, FocusListener
59    {
60   
61    AlignmentPanel ap;
62   
63    SequenceGroup seqGroup;
64   
65    Button selectedButton;
66   
67    Vector<Color> oldColours = new Vector<>();
68   
69    ColourSchemeI oldColourScheme;
70   
71    Frame frame;
72   
73    mc_view.AppletPDBCanvas pdbcanvas;
74   
75    AppletJmol jmol;
76   
77    Dialog dialog;
78   
79    Object caller;
80   
81    String originalLabel;
82   
83    FeatureColourI originalColour;
84   
85    int R = 0, G = 0, B = 0;
86   
 
87  0 toggle public ColourSchemeI loadDefaultColours()
88    {
89    // NOT IMPLEMENTED YET IN APPLET VERSION
90  0 return null;
91    }
92   
 
93  0 toggle public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
94    {
95  0 this.ap = ap;
96  0 seqGroup = sg;
97   
98  0 if (seqGroup != null)
99    {
100  0 oldColourScheme = seqGroup.getColourScheme();
101    }
102    else
103    {
104  0 oldColourScheme = ap.av.getGlobalColourScheme();
105    }
106   
107  0 init();
108    }
109   
 
110  0 toggle public UserDefinedColours(mc_view.AppletPDBCanvas pdb)
111    {
112  0 this.pdbcanvas = pdb;
113  0 init();
114    }
115   
 
116  0 toggle public UserDefinedColours(AppletJmol jmol)
117    {
118  0 this.jmol = jmol;
119  0 init();
120    }
121   
 
122  0 toggle public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
123    {
124  0 caller = fr;
125  0 originalColour = new FeatureColour(fr.colourPanel.getBackground());
126  0 originalLabel = "Feature Colour";
127  0 setForDialog("Select Feature Colour", alignframe);
128  0 setTargetColour(fr.colourPanel.getBackground());
129  0 dialog.setVisible(true);
130    }
131   
 
132  0 toggle public UserDefinedColours(Component caller, Color col1, Frame alignframe)
133    {
134  0 this(caller, col1, alignframe, "Select Colour");
135    }
136   
137    /**
138    * Makes a dialog to choose the colour
139    *
140    * @param caller
141    * - handles events
142    * @param col
143    * - original colour
144    * @param alignframe
145    * - the parent Frame for the dialog
146    * @param title
147    * - window title
148    */
 
149  0 toggle public UserDefinedColours(Component caller, Color col, Frame alignframe,
150    String title)
151    {
152  0 this.caller = caller;
153  0 originalColour = new FeatureColour(col);
154  0 originalLabel = title;
155  0 setForDialog(title, alignframe);
156  0 setTargetColour(col);
157  0 dialog.setVisible(true);
158    }
159   
160    /**
161    * feature colour chooser
162    *
163    * @param caller
164    * @param label
165    * @param colour
166    */
 
167  0 toggle public UserDefinedColours(Object caller, String label, Color colour)
168    {
169  0 this(caller, label, new FeatureColour(colour), colour);
170    }
171   
172    /**
173    * feature colour chooser when changing style to single color
174    *
175    * @param me
176    * @param type
177    * @param graduatedColor
178    */
 
179  0 toggle public UserDefinedColours(FeatureSettings me, String type,
180    FeatureColourI graduatedColor)
181    {
182  0 this(me, type, graduatedColor, graduatedColor.getMaxColour());
183    }
184   
 
185  0 toggle private UserDefinedColours(Object caller, String label,
186    FeatureColourI ocolour, Color colour)
187    {
188  0 this.caller = caller;
189  0 originalColour = ocolour;
190  0 originalLabel = label;
191  0 init();
192  0 remove(buttonPanel);
193   
194  0 setTargetColour(colour);
195   
196  0 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
197  0 frame.setTitle(MessageManager.getString("label.user_defined_colours")
198    + " - " + label);
199  0 frame.setSize(420, 200);
200    }
201   
 
202  0 toggle void setForDialog(String title, Container alignframe)
203    {
204  0 init();
205  0 frame.setVisible(false);
206  0 remove(buttonPanel);
207  0 if (alignframe instanceof Frame)
208    {
209  0 dialog = new Dialog((Frame) alignframe, title, true);
210    }
211    else
212    {
213    // if (alignframe instanceof JVDialog){
214    // // not 1.1 compatible!
215    // dialog = new Dialog(((JVDialog)alignframe), title, true);
216    // } else {
217  0 throw new Error(MessageManager.getString(
218    "label.error_unsupported_owwner_user_colour_scheme"));
219    }
220   
221  0 dialog.add(this);
222  0 this.setSize(400, 123);
223  0 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
224  0 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
225  0 int width = 400;
226   
227  0 dialog.setBounds(
228    alignframe.getBounds().x
229    + (alignframe.getSize().width - width) / 2,
230    alignframe.getBounds().y
231    + (alignframe.getSize().height - height) / 2,
232    width, height);
233   
234    }
235   
 
236  0 toggle @Override
237    public void actionPerformed(ActionEvent evt)
238    {
239  0 final Object source = evt.getSource();
240  0 if (source == okButton)
241    {
242  0 okButton_actionPerformed();
243    }
244  0 else if (source == applyButton)
245    {
246  0 applyButton_actionPerformed();
247    }
248  0 else if (source == cancelButton)
249    {
250  0 cancelButton_actionPerformed();
251    }
252  0 else if (source == rText)
253    {
254  0 rText_actionPerformed();
255    }
256  0 else if (source == gText)
257    {
258  0 gText_actionPerformed();
259    }
260  0 else if (source == bText)
261    {
262  0 bText_actionPerformed();
263    }
264    }
265   
 
266  0 toggle @Override
267    public void adjustmentValueChanged(AdjustmentEvent evt)
268    {
269  0 if (evt.getSource() == rScroller)
270    {
271  0 rScroller_adjustmentValueChanged();
272    }
273  0 else if (evt.getSource() == gScroller)
274    {
275  0 gScroller_adjustmentValueChanged();
276    }
277  0 else if (evt.getSource() == bScroller)
278    {
279  0 bScroller_adjustmentValueChanged();
280    }
281    }
282   
 
283  0 toggle void init()
284    {
285  0 try
286    {
287  0 jbInit();
288    } catch (Exception e)
289    {
290  0 e.printStackTrace();
291    }
292  0 frame = new Frame();
293  0 frame.add(this);
294  0 jalview.bin.JalviewLite.addFrame(frame,
295    MessageManager.getString("label.user_defined_colours"), 420,
296    345);
297   
298  0 if (seqGroup != null)
299    {
300  0 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
301    }
302   
303  0 for (int i = 0; i < 20; i++)
304    {
305  0 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
306    + "", ResidueProperties.aa[i]);
307    }
308   
309  0 makeButton("B", "B");
310  0 makeButton("Z", "Z");
311  0 makeButton("X", "X");
312  0 makeButton("Gap", "'.','-',' '");
313   
314  0 validate();
315    }
316   
 
317  0 toggle protected void rText_actionPerformed()
318    {
319  0 try
320    {
321  0 int i = Integer.parseInt(rText.getText());
322  0 rScroller.setValue(i);
323  0 rScroller_adjustmentValueChanged();
324    } catch (NumberFormatException ex)
325    {
326    }
327    }
328   
 
329  0 toggle protected void gText_actionPerformed()
330    {
331  0 try
332    {
333  0 int i = Integer.parseInt(gText.getText());
334  0 gScroller.setValue(i);
335  0 gScroller_adjustmentValueChanged();
336    } catch (NumberFormatException ex)
337    {
338    }
339   
340    }
341   
 
342  0 toggle protected void bText_actionPerformed()
343    {
344  0 try
345    {
346  0 int i = Integer.parseInt(bText.getText());
347  0 bScroller.setValue(i);
348  0 bScroller_adjustmentValueChanged();
349    } catch (NumberFormatException ex)
350    {
351    }
352   
353    }
354   
 
355  0 toggle protected void rScroller_adjustmentValueChanged()
356    {
357  0 R = rScroller.getValue();
358  0 rText.setText(R + "");
359  0 colourChanged();
360    }
361   
 
362  0 toggle protected void gScroller_adjustmentValueChanged()
363    {
364  0 G = gScroller.getValue();
365  0 gText.setText(G + "");
366  0 colourChanged();
367    }
368   
 
369  0 toggle protected void bScroller_adjustmentValueChanged()
370    {
371  0 B = bScroller.getValue();
372  0 bText.setText(B + "");
373  0 colourChanged();
374    }
375   
 
376  0 toggle public void colourChanged()
377    {
378  0 Color col = new Color(R, G, B);
379  0 target.setBackground(col);
380  0 target.repaint();
381   
382  0 if (selectedButton != null)
383    {
384  0 selectedButton.setBackground(col);
385  0 selectedButton.repaint();
386    }
387    }
388   
 
389  0 toggle void setTargetColour(Color col)
390    {
391  0 R = col.getRed();
392  0 G = col.getGreen();
393  0 B = col.getBlue();
394   
395  0 rScroller.setValue(R);
396  0 gScroller.setValue(G);
397  0 bScroller.setValue(B);
398  0 rText.setText(R + "");
399  0 gText.setText(G + "");
400  0 bText.setText(B + "");
401  0 colourChanged();
402    }
403   
 
404  0 toggle public void colourButtonPressed(MouseEvent e)
405    {
406  0 selectedButton = (Button) e.getSource();
407  0 setTargetColour(selectedButton.getBackground());
408    }
409   
 
410  0 toggle void makeButton(String label, String aa)
411    {
412  0 final Button button = new Button();
413  0 Color col = Color.white;
414  0 if (oldColourScheme != null && oldColourScheme.isSimple())
415    {
416  0 col = oldColourScheme.findColour(aa.charAt(0), 0, null, null, 0f);
417    }
418  0 button.setBackground(col);
419  0 oldColours.addElement(col);
420  0 button.setLabel(label);
421  0 button.setForeground(col.darker().darker().darker());
422  0 button.setFont(new java.awt.Font("Verdana", 1, 10));
423  0 button.addMouseListener(new java.awt.event.MouseAdapter()
424    {
 
425  0 toggle @Override
426    public void mousePressed(MouseEvent e)
427    {
428  0 colourButtonPressed(e);
429    }
430    });
431   
432  0 buttonPanel.add(button, null);
433    }
434   
 
435  0 toggle protected void okButton_actionPerformed()
436    {
437  0 applyButton_actionPerformed();
438  0 if (dialog != null)
439    {
440  0 dialog.setVisible(false);
441    }
442   
443  0 frame.setVisible(false);
444    }
445   
 
446  0 toggle public Color getColor()
447    {
448  0 return new Color(R, G, B);
449    }
450   
 
451  0 toggle protected void applyButton_actionPerformed()
452    {
453  0 if (caller != null)
454    {
455  0 if (caller instanceof FeatureSettings)
456    {
457  0 ((FeatureSettings) caller).setUserColour(originalLabel,
458    new FeatureColour(getColor()));
459    }
460  0 else if (caller instanceof AnnotationColourChooser)
461    {
462  0 if (originalLabel.equals("Min Colour"))
463    {
464  0 ((AnnotationColourChooser) caller)
465    .minColour_actionPerformed(getColor());
466    }
467    else
468    {
469  0 ((AnnotationColourChooser) caller)
470    .maxColour_actionPerformed(getColor());
471    }
472    }
473  0 else if (caller instanceof FeatureRenderer)
474    {
475  0 ((FeatureRenderer) caller).colourPanel
476    .updateColor(new FeatureColour(getColor()));
477    }
478  0 else if (caller instanceof FeatureColourChooser)
479    {
480  0 if (originalLabel.indexOf("inimum") > -1)
481    {
482  0 ((FeatureColourChooser) caller)
483    .minColour_actionPerformed(getColor());
484    }
485    else
486    {
487  0 ((FeatureColourChooser) caller)
488    .maxColour_actionPerformed(getColor());
489    }
490    }
491   
492  0 return;
493    }
494   
495  0 Color[] newColours = new Color[24];
496  0 for (int i = 0; i < 24; i++)
497    {
498  0 Button button = (Button) buttonPanel.getComponent(i);
499  0 newColours[i] = button.getBackground();
500    }
501   
502  0 UserColourScheme ucs = new UserColourScheme(newColours);
503    // if (ap != null)
504    // {
505    // ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
506    // }
507   
508  0 if (ap != null)
509    {
510  0 if (seqGroup != null)
511    {
512  0 seqGroup.cs = new ResidueShader(ucs);
513  0 seqGroup.getGroupColourScheme().setThreshold(0,
514    ap.av.isIgnoreGapsConsensus());
515    }
516    else
517    {
518  0 ap.av.setGlobalColourScheme(ucs);
519  0 ap.av.getResidueShading().setThreshold(0,
520    ap.av.isIgnoreGapsConsensus());
521    }
522  0 ap.seqPanel.seqCanvas.img = null;
523  0 ap.paintAlignment(true, true);
524    }
525  0 else if (jmol != null)
526    {
527  0 jmol.colourByJalviewColourScheme(ucs);
528    }
529  0 else if (pdbcanvas != null)
530    {
531  0 pdbcanvas.setColours(ucs);
532    }
533    }
534   
 
535  0 toggle protected void cancelButton_actionPerformed()
536    {
537  0 if (caller != null)
538    {
539  0 if (caller instanceof FeatureSettings)
540    {
541  0 ((FeatureSettings) caller).setUserColour(originalLabel,
542    originalColour);
543    }
544  0 else if (caller instanceof AnnotationColourChooser)
545    {
546  0 if (originalLabel.equals("Min Colour"))
547    {
548  0 ((AnnotationColourChooser) caller)
549    .minColour_actionPerformed(originalColour.getColour());
550    }
551    else
552    {
553  0 ((AnnotationColourChooser) caller)
554    .maxColour_actionPerformed(originalColour.getColour());
555    }
556    }
557  0 else if (caller instanceof FeatureRenderer)
558    {
559  0 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
560   
561    }
562   
563  0 else if (caller instanceof FeatureColourChooser)
564    {
565  0 if (originalLabel.indexOf("inimum") > -1)
566    {
567  0 ((FeatureColourChooser) caller)
568    .minColour_actionPerformed(originalColour.getColour());
569    }
570    else
571    {
572  0 ((FeatureColourChooser) caller)
573    .maxColour_actionPerformed(originalColour.getColour());
574    }
575    }
576  0 if (dialog != null)
577    {
578  0 dialog.setVisible(false);
579    }
580   
581  0 frame.setVisible(false);
582  0 return;
583    }
584   
585  0 if (ap != null)
586    {
587  0 if (seqGroup != null)
588    {
589  0 seqGroup.cs = new ResidueShader(oldColourScheme);
590  0 if (oldColourScheme instanceof PIDColourScheme
591    || oldColourScheme instanceof Blosum62ColourScheme)
592    {
593  0 seqGroup.cs.setConsensus(AAFrequency.calculate(
594    seqGroup.getSequences(ap.av.getHiddenRepSequences()), 0,
595    ap.av.getAlignment().getWidth()));
596    }
597    }
598    else
599    {
600  0 ap.av.setGlobalColourScheme(oldColourScheme);
601    }
602  0 ap.paintAlignment(true, true);
603    }
604   
605  0 frame.setVisible(false);
606    }
607   
608    protected Panel buttonPanel = new Panel();
609   
610    protected GridLayout gridLayout = new GridLayout();
611   
612    Panel okcancelPanel = new Panel();
613   
614    protected Button okButton = new Button();
615   
616    protected Button applyButton = new Button();
617   
618    protected Button cancelButton = new Button();
619   
620    protected Scrollbar rScroller = new Scrollbar();
621   
622    Label label1 = new Label();
623   
624    protected TextField rText = new TextField();
625   
626    Label label4 = new Label();
627   
628    protected Scrollbar gScroller = new Scrollbar();
629   
630    protected TextField gText = new TextField();
631   
632    Label label5 = new Label();
633   
634    protected Scrollbar bScroller = new Scrollbar();
635   
636    protected TextField bText = new TextField();
637   
638    protected Panel target = new Panel();
639   
 
640  0 toggle private void jbInit() throws Exception
641    {
642  0 this.setLayout(null);
643  0 buttonPanel.setLayout(gridLayout);
644  0 gridLayout.setColumns(6);
645  0 gridLayout.setRows(4);
646  0 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
647  0 okButton.setLabel(MessageManager.getString("action.ok"));
648  0 okButton.addActionListener(this);
649  0 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
650  0 applyButton.setLabel(MessageManager.getString("action.apply"));
651  0 applyButton.addActionListener(this);
652  0 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
653  0 cancelButton.setLabel(MessageManager.getString("action.cancel"));
654  0 cancelButton.addActionListener(this);
655  0 this.setBackground(new Color(212, 208, 223));
656  0 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
657  0 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
658  0 rScroller.setMaximum(256);
659  0 rScroller.setMinimum(0);
660  0 rScroller.setOrientation(0);
661  0 rScroller.setUnitIncrement(1);
662  0 rScroller.setVisibleAmount(1);
663  0 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
664  0 rScroller.addAdjustmentListener(this);
665  0 label1.setAlignment(Label.RIGHT);
666  0 label1.setText("R");
667  0 label1.setBounds(new Rectangle(19, 30, 16, 15));
668  0 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
669  0 rText.setText("0 ");
670  0 rText.setBounds(new Rectangle(156, 27, 53, 19));
671  0 rText.addActionListener(this);
672  0 rText.addFocusListener(this);
673  0 label4.setAlignment(Label.RIGHT);
674  0 label4.setText("G");
675  0 label4.setBounds(new Rectangle(15, 56, 20, 15));
676  0 gScroller.setMaximum(256);
677  0 gScroller.setMinimum(0);
678  0 gScroller.setOrientation(0);
679  0 gScroller.setUnitIncrement(1);
680  0 gScroller.setVisibleAmount(1);
681  0 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
682  0 gScroller.addAdjustmentListener(this);
683  0 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
684  0 gText.setText("0 ");
685  0 gText.setBounds(new Rectangle(156, 52, 53, 20));
686  0 gText.addActionListener(this);
687  0 gText.addFocusListener(this);
688  0 label5.setAlignment(Label.RIGHT);
689  0 label5.setText("B");
690  0 label5.setBounds(new Rectangle(14, 82, 20, 15));
691  0 bScroller.setMaximum(256);
692  0 bScroller.setMinimum(0);
693  0 bScroller.setOrientation(0);
694  0 bScroller.setUnitIncrement(1);
695  0 bScroller.setVisibleAmount(1);
696  0 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
697  0 bScroller.addAdjustmentListener(this);
698  0 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
699  0 bText.setText("0 ");
700  0 bText.setBounds(new Rectangle(157, 78, 52, 20));
701  0 bText.addActionListener(this);
702  0 bText.addFocusListener(this);
703  0 target.setBackground(Color.black);
704  0 target.setBounds(new Rectangle(229, 26, 134, 79));
705  0 this.add(okcancelPanel, null);
706  0 okcancelPanel.add(okButton, null);
707  0 okcancelPanel.add(applyButton, null);
708  0 okcancelPanel.add(cancelButton, null);
709  0 this.add(rText);
710  0 this.add(gText);
711  0 this.add(bText);
712  0 this.add(buttonPanel, null);
713  0 this.add(target, null);
714  0 this.add(gScroller);
715  0 this.add(rScroller);
716  0 this.add(bScroller);
717  0 this.add(label5);
718  0 this.add(label4);
719  0 this.add(label1);
720    }
721   
 
722  0 toggle @Override
723    public void focusGained(FocusEvent e)
724    {
725    // noop
726    }
727   
728    /**
729    * This method applies any change to an RGB value if the user tabs out of the
730    * field instead of pressing Enter
731    */
 
732  0 toggle @Override
733    public void focusLost(FocusEvent e)
734    {
735  0 Component c = e.getComponent();
736  0 if (c == rText)
737    {
738  0 rText_actionPerformed();
739    }
740    else
741    {
742  0 if (c == gText)
743    {
744  0 gText_actionPerformed();
745    }
746    else
747    {
748  0 if (c == bText)
749    {
750  0 bText_actionPerformed();
751    }
752    }
753    }
754    }
755   
756    }