X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FUserDefinedColours.java;h=80d91efdfcdbac60c4c1e7148c21b2c6f138fb1a;hb=11cfcb7281e45c5958b839e55da66cfbb9582fa7;hp=0c7e6854eb75aadafe780a7cd82ff2163fffb8c4;hpb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;p=jalview.git diff --git a/src/jalview/appletgui/UserDefinedColours.java b/src/jalview/appletgui/UserDefinedColours.java index 0c7e685..80d91ef 100755 --- a/src/jalview/appletgui/UserDefinedColours.java +++ b/src/jalview/appletgui/UserDefinedColours.java @@ -1,35 +1,36 @@ /* -* 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 -*/ + * 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 jalview.jbappletgui.GUserDefinedColours; -import jalview.datamodel.*; -import jalview.schemes.*; -import jalview.io.*; import java.io.*; +import java.util.*; + import java.awt.*; import java.awt.event.*; -import java.util.*; +import jalview.datamodel.*; +import jalview.jbappletgui.*; +import jalview.schemes.*; -public class UserDefinedColours extends GUserDefinedColours +public class UserDefinedColours + extends GUserDefinedColours { AlignmentPanel ap; @@ -52,98 +53,120 @@ public class UserDefinedColours extends GUserDefinedColours 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()+")"); + 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(); + } - 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]); + 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", "'.','-',' '"); + makeButton("B", "B"); + makeButton("Z", "Z"); + makeButton("X", "X"); + makeButton("Gap", "'.','-',' '"); } - protected void rText_actionPerformed(ActionEvent e) { - try{ + protected void rText_actionPerformed(ActionEvent e) + { + try + { int i = Integer.parseInt(rText.getText()); rScroller.setValue(i); - }catch(NumberFormatException ex){} + } + catch (NumberFormatException ex) + {} } - protected void gText_actionPerformed(ActionEvent e) { - try{ + protected void gText_actionPerformed(ActionEvent e) + { + try + { int i = Integer.parseInt(gText.getText()); gScroller.setValue(i); - }catch(NumberFormatException ex){} + } + catch (NumberFormatException ex) + {} } - protected void bText_actionPerformed(ActionEvent e) { - try{ + protected void bText_actionPerformed(ActionEvent e) + { + try + { int i = Integer.parseInt(bText.getText()); bScroller.setValue(i); - }catch(NumberFormatException ex){} + } + catch (NumberFormatException ex) + {} } - - protected void rScroller_adjustmentValueChanged(AdjustmentEvent e) { + protected void rScroller_adjustmentValueChanged(AdjustmentEvent e) + { R = rScroller.getValue(); - rText.setText(R+""); + rText.setText(R + ""); colourChanged(); } - protected void gScroller_adjustmentValueChanged(AdjustmentEvent e) { + protected void gScroller_adjustmentValueChanged(AdjustmentEvent e) + { G = gScroller.getValue(); - gText.setText(G+""); + gText.setText(G + ""); colourChanged(); } - protected void bScroller_adjustmentValueChanged(AdjustmentEvent e) { + protected void bScroller_adjustmentValueChanged(AdjustmentEvent e) + { B = bScroller.getValue(); - bText.setText(B+""); + bText.setText(B + ""); colourChanged(); } - public void colourChanged() - { - Color col = new Color(R,G,B); - target.setBackground( col ); + public void colourChanged() + { + Color col = new Color(R, G, B); + target.setBackground(col); - if(selectedButton!=null) - selectedButton.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(); + 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) @@ -151,15 +174,17 @@ public class UserDefinedColours extends GUserDefinedColours final Button button = new Button(); Color col = Color.white; - - try{ + try + { col = oldColourScheme.findColour(aa, -1); - }catch(Exception ex){} + } + catch (Exception ex) + {} - button.setBackground( col ); - oldColours.addElement( col ); - button.setLabel( label ); - button.setForeground( col.darker().darker().darker() ); + 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() { @@ -172,42 +197,44 @@ public class UserDefinedColours extends GUserDefinedColours buttonPanel.add(button, null); } - protected void okButton_actionPerformed(ActionEvent e) { applyButton_actionPerformed(null); - frame.setVisible(false); + frame.setVisible(false); } protected void applyButton_actionPerformed(ActionEvent e) { - Color [] newColours = new Color[24]; - for(int i=0; i<24; i++) + Color[] newColours = new Color[24]; + for (int i = 0; i < 24; i++) { - Button button = (Button)buttonPanel.getComponent(i); - newColours[i] = button.getBackground(); + Button button = (Button) buttonPanel.getComponent(i); + newColours[i] = button.getBackground(); } - UserColourScheme ucs = new UserColourScheme( newColours ); + UserColourScheme ucs = new UserColourScheme(newColours); ucs.setThreshold(0); - if(seqGroup!=null) + if (seqGroup != null) + { seqGroup.cs = ucs; + } else + { ap.av.setGlobalColourScheme(ucs); + } ap.repaint(); } - public static UserColourScheme loadDefaultColours(String file) { UserColourScheme ucs = null; try { BufferedReader in = new BufferedReader(new FileReader(file)); - Color [] newColours = new Color[24]; + Color[] newColours = new Color[24]; for (int i = 0; i < 24; i++) { newColours[i] = new Color(Integer.parseInt(in.readLine())); @@ -223,28 +250,30 @@ public class UserDefinedColours extends GUserDefinedColours return ucs; } - protected void cancelButton_actionPerformed(ActionEvent e) { - Color [] newColours = new Color[24]; - for(int i=0; i<24; i++) + Color[] newColours = new Color[24]; + for (int i = 0; i < 24; i++) { - newColours[i] = (Color)oldColours.elementAt(i); - buttonPanel.getComponent(i).setBackground(newColours[i]); + newColours[i] = (Color) oldColours.elementAt(i); + buttonPanel.getComponent(i).setBackground(newColours[i]); } - UserColourScheme ucs = new UserColourScheme( newColours ); + UserColourScheme ucs = new UserColourScheme(newColours); if (seqGroup != null) + { seqGroup.cs = ucs; + } else + { ap.av.setGlobalColourScheme(ucs); + } ap.repaint(); frame.setVisible(false); } - }