/* * Jalview - A Sequence Alignment Editor and Viewer * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package jalview.appletgui; import java.io.*; import java.util.*; import java.awt.*; import java.awt.event.*; import jalview.datamodel.*; import jalview.jbappletgui.*; import jalview.schemes.*; public class UserDefinedColours extends GUserDefinedColours { AlignmentPanel ap; SequenceGroup seqGroup; Button selectedButton; Vector oldColours = new Vector(); ColourSchemeI oldColourScheme; Frame frame; int R = 0, G = 0, B = 0; public ColourSchemeI loadDefaultColours() { // NOT IMPLEMENTED YET IN APPLET VERSION return null; } public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg) { super(); frame = new Frame(); frame.add(this); jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420, 345); if (sg != null) { frame.setTitle(frame.getTitle() + " (" + sg.getName() + ")"); } this.ap = ap; seqGroup = sg; if (seqGroup != null) { oldColourScheme = seqGroup.cs; } else { oldColourScheme = ap.av.getGlobalColourScheme(); } for (int i = 0; i < 20; i++) { makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) + "", ResidueProperties.aa[i]); } makeButton("B", "B"); makeButton("Z", "Z"); makeButton("X", "X"); makeButton("Gap", "'.','-',' '"); } protected void rText_actionPerformed(ActionEvent e) { try { int i = Integer.parseInt(rText.getText()); rScroller.setValue(i); } catch (NumberFormatException ex) {} } protected void gText_actionPerformed(ActionEvent e) { try { int i = Integer.parseInt(gText.getText()); gScroller.setValue(i); } catch (NumberFormatException ex) {} } protected void bText_actionPerformed(ActionEvent e) { try { int i = Integer.parseInt(bText.getText()); bScroller.setValue(i); } catch (NumberFormatException ex) {} } protected void rScroller_adjustmentValueChanged(AdjustmentEvent e) { R = rScroller.getValue(); rText.setText(R + ""); colourChanged(); } protected void gScroller_adjustmentValueChanged(AdjustmentEvent e) { G = gScroller.getValue(); gText.setText(G + ""); colourChanged(); } protected void bScroller_adjustmentValueChanged(AdjustmentEvent e) { B = bScroller.getValue(); bText.setText(B + ""); colourChanged(); } public void colourChanged() { Color col = new Color(R, G, B); target.setBackground(col); if (selectedButton != null) { selectedButton.setBackground(col); } } public void colourButtonPressed(MouseEvent e) { selectedButton = (Button) e.getSource(); Color col = selectedButton.getBackground(); R = col.getRed(); G = col.getGreen(); B = col.getBlue(); rScroller.setValue(R); gScroller.setValue(G); bScroller.setValue(B); rText.setText(R + ""); gText.setText(G + ""); bText.setText(B + ""); colourChanged(); } void makeButton(String label, String aa) { final Button button = new Button(); Color col = Color.white; try { col = oldColourScheme.findColour(aa, -1); } catch (Exception ex) {} button.setBackground(col); oldColours.addElement(col); button.setLabel(label); button.setForeground(col.darker().darker().darker()); button.setFont(new java.awt.Font("Verdana", 1, 10)); button.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { colourButtonPressed(e); } }); buttonPanel.add(button, null); } protected void okButton_actionPerformed(ActionEvent e) { applyButton_actionPerformed(null); frame.setVisible(false); } protected void applyButton_actionPerformed(ActionEvent e) { Color[] newColours = new Color[24]; for (int i = 0; i < 24; i++) { Button button = (Button) buttonPanel.getComponent(i); newColours[i] = button.getBackground(); } UserColourScheme ucs = new UserColourScheme(newColours); ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus()); if (seqGroup != null) { seqGroup.cs = ucs; } else { ap.av.setGlobalColourScheme(ucs); } ap.repaint(); } protected void cancelButton_actionPerformed(ActionEvent e) { Color[] newColours = new Color[24]; for (int i = 0; i < 24; i++) { newColours[i] = (Color) oldColours.elementAt(i); buttonPanel.getComponent(i).setBackground(newColours[i]); } UserColourScheme ucs = new UserColourScheme(newColours); if (seqGroup != null) { seqGroup.cs = ucs; } else { ap.av.setGlobalColourScheme(ucs); } ap.repaint(); frame.setVisible(false); } }