+/*\r
+* Jalview - A Sequence Alignment Editor and Viewer\r
+* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+*\r
+* This program is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU General Public License\r
+* as published by the Free Software Foundation; either version 2\r
+* of the License, or (at your option) any later version.\r
+*\r
+* This program is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with this program; if not, write to the Free Software\r
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+*/\r
+package jalview.gui;\r
+\r
+import javax.swing.*;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.BorderLayout;\r
+import java.awt.*;\r
+\r
+import jalview.schemes.*;\r
+\r
+public class AnnotationColourChooser\r
+ extends JPanel\r
+{\r
+ JInternalFrame frame;\r
+ AlignViewport av;\r
+ AlignmentPanel ap;\r
+ ColourSchemeI oldcs;\r
+\r
+ public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)\r
+ {\r
+ oldcs = av.getGlobalColourScheme();\r
+ this.av = av;\r
+ this.ap = ap;\r
+ frame = new JInternalFrame();\r
+ frame.setContentPane(this);\r
+ frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
+ Desktop.addInternalFrame(frame, "Colour by Annotation", 480, 110);\r
+\r
+ try{\r
+ jbInit();\r
+ }catch(Exception ex){}\r
+\r
+ if(av.alignment.getAlignmentAnnotation()==null)\r
+ return;\r
+\r
+ for(int i=0; i<av.alignment.getAlignmentAnnotation().length; i++)\r
+ {\r
+ annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label);\r
+ }\r
+\r
+ // if(av.getGlobalColourScheme() instanceof AnnotationColourGradient)\r
+ {\r
+ // minColour.\r
+ }\r
+ // else\r
+ {\r
+ minColour.setBackground(Color.orange);\r
+ maxColour.setBackground(Color.red);\r
+ }\r
+ }\r
+\r
+ public AnnotationColourChooser()\r
+ {\r
+ try\r
+ {\r
+ jbInit();\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ }\r
+\r
+ private void jbInit()\r
+ throws Exception\r
+ {\r
+ minColour.setBounds(new Rectangle(145, 5, 85, 25));\r
+ minColour.setToolTipText("");\r
+ minColour.setMargin(new Insets(2, 2, 2, 2));\r
+ minColour.setText("Min Colour");\r
+ minColour.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ minColour_actionPerformed(e);\r
+ }\r
+ });\r
+ maxColour.setBounds(new Rectangle(235, 5, 89, 25));\r
+ maxColour.setMargin(new Insets(2, 2, 2, 2));\r
+ maxColour.setText("Max Colour");\r
+ maxColour.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ maxColour_actionPerformed(e);\r
+ }\r
+ });\r
+ thresholdCheck.setOpaque(false);\r
+ thresholdCheck.setHorizontalTextPosition(SwingConstants.LEADING);\r
+ thresholdCheck.setSelectedIcon(null);\r
+ thresholdCheck.setText("Above Threshold");\r
+ thresholdCheck.setBounds(new Rectangle(329, 6, 109, 23));\r
+ apply.setOpaque(false);\r
+ apply.setSelectedIcon(null);\r
+ apply.setText("Apply");\r
+ apply.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ apply_actionPerformed(e);\r
+ }\r
+ });\r
+ ok.setOpaque(false);\r
+ ok.setText("OK");\r
+ ok.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ ok_actionPerformed(e);\r
+ }\r
+ });\r
+ cancel.setOpaque(false);\r
+ cancel.setText("Cancel");\r
+ cancel.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ cancel_actionPerformed(e);\r
+ }\r
+ });\r
+ this.setLayout(borderLayout1);\r
+ jPanel2.setLayout(null);\r
+ annotations.setBounds(new Rectangle(5, 7, 135, 21));\r
+ jPanel1.setBackground(Color.white);\r
+ jPanel2.setBackground(Color.white);\r
+ jPanel1.add(apply);\r
+ jPanel1.add(ok);\r
+ jPanel1.add(cancel);\r
+ jPanel2.add(annotations);\r
+ jPanel2.add(minColour);\r
+ jPanel2.add(maxColour);\r
+ jPanel2.add(thresholdCheck);\r
+ this.add(jPanel1, java.awt.BorderLayout.SOUTH);\r
+ this.add(jPanel2, java.awt.BorderLayout.CENTER);\r
+ }\r
+\r
+ JComboBox annotations = new JComboBox();\r
+ JButton minColour = new JButton();\r
+ JButton maxColour = new JButton();\r
+ JCheckBox thresholdCheck = new JCheckBox();\r
+ JButton apply = new JButton();\r
+ JButton ok = new JButton();\r
+ JButton cancel = new JButton();\r
+ JPanel jPanel1 = new JPanel();\r
+ JPanel jPanel2 = new JPanel();\r
+ BorderLayout borderLayout1 = new BorderLayout();\r
+ public void apply_actionPerformed(ActionEvent e)\r
+ {\r
+ changeColour();\r
+ }\r
+\r
+ public void minColour_actionPerformed(ActionEvent e)\r
+ {\r
+ Color col = JColorChooser.showDialog(this,\r
+ "Select Colour for Minimum Value",\r
+ minColour.getBackground());\r
+ if (col != null)\r
+ minColour.setBackground(col);\r
+ minColour.repaint();\r
+ }\r
+\r
+ public void maxColour_actionPerformed(ActionEvent e)\r
+ {\r
+ Color col = JColorChooser.showDialog(this,\r
+ "Select Colour for Maximum Value",\r
+ maxColour.getBackground());\r
+ if (col != null)\r
+ maxColour.setBackground(col);\r
+ maxColour.repaint();\r
+ }\r
+\r
+ void changeColour()\r
+ {\r
+ jalview.datamodel.AlignmentAnnotation aa = av.alignment.getAlignmentAnnotation()[annotations.getSelectedIndex()];\r
+\r
+ AnnotationColourGradient acg = new AnnotationColourGradient(aa,\r
+ minColour.getBackground(),\r
+ maxColour.getBackground(),\r
+ thresholdCheck.isSelected());\r
+\r
+ if(thresholdCheck.isSelected() && aa.graphLines==null)\r
+ {\r
+ aa.addGraphLine(new jalview.datamodel.GraphLine((aa.graphMax-aa.graphMin)/2f, "Threshold", Color.black));\r
+ }\r
+\r
+ av.setGlobalColourScheme(acg);\r
+ ap.repaint();\r
+\r
+ }\r
+\r
+ public void ok_actionPerformed(ActionEvent e)\r
+ {\r
+ changeColour();\r
+ try{\r
+ frame.setClosed(true);\r
+ }catch(Exception ex){}\r
+ }\r
+\r
+ public void cancel_actionPerformed(ActionEvent e)\r
+ {\r
+ av.setGlobalColourScheme(oldcs);\r
+ try{\r
+ frame.setClosed(true);\r
+ }catch(Exception ex){}\r
+ }\r
+\r
+}\r