Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.gui

File JalviewColourChooser.java

 

Coverage histogram

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

Code metrics

2
11
4
2
81
52
5
0.45
2.75
2
1.25

Classes

Class Line # Actions
JalviewColourChooser 19 11 5 17
0.00%
JalviewColourChooser.ColourChooserListener 21 0 0 0
-1.0 -
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package jalview.gui;
2   
3    import jalview.gui.JalviewColourChooser.ColourChooserListener;
4   
5    import java.awt.Color;
6    import java.awt.Component;
7    import java.awt.event.ActionEvent;
8    import java.awt.event.ActionListener;
9   
10    import javax.swing.JColorChooser;
11    import javax.swing.JComponent;
12    import javax.swing.JDialog;
13    import javax.swing.JPanel;
14   
15    /**
16    * A helper class that shows a JColorChooser and passes the selected colour back
17    * to a listener
18    */
 
19    public class JalviewColourChooser
20    {
 
21    public interface ColourChooserListener
22    {
23    void colourSelected(Color c);
24    }
25   
26    /**
27    * Shows a colour chooser dialog with the given parent component, title, and
28    * (optionally) initially selected colour. The chosen colour is passed back to
29    * the listener. There is no action if the dialog is cancelled.
30    *
31    * @param parent
32    * @param title
33    * @param initialColour
34    * @param listener
35    */
 
36  0 toggle public static void showColourChooser(Component parent, String title,
37    Color initialColour, ColourChooserListener listener)
38    {
39  0 JColorChooser colorChooser = new JColorChooser();
40  0 if (initialColour != null)
41    {
42  0 colorChooser.setColor(initialColour);
43    }
44  0 ActionListener al = new ActionListener()
45    {
 
46  0 toggle @Override
47    public void actionPerformed(ActionEvent e)
48    {
49  0 listener.colourSelected(colorChooser.getColor());
50    };
51    };
52  0 JDialog dialog = JColorChooser.createDialog(parent, title, true,
53    colorChooser, al, null);
54  0 dialog.setVisible(true);
55    }
56   
57    /**
58    * A convenience method that shows a colour chooser, with initial colour the
59    * background of the given 'paintable', and updates its background colour and
60    * repaints it after a colour selection is made
61    *
62    * @param parent
63    * @param title
64    * @param paintable
65    */
 
66  0 toggle public static void showColourChooser(Component parent, String title,
67    JComponent paintable)
68    {
69  0 ColourChooserListener listener = new ColourChooserListener()
70    {
 
71  0 toggle @Override
72    public void colourSelected(Color c)
73    {
74  0 paintable.setBackground(c);
75  0 paintable.repaint();
76    }
77    };
78  0 JalviewColourChooser.showColourChooser(parent, title,
79    paintable.getBackground(), listener);
80    }
81    }