From: amwaterhouse Date: Wed, 30 Aug 2006 16:08:36 +0000 (+0000) Subject: User colours are case sensitive X-Git-Tag: Release_2_1_1~26 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9e46fb6245b28f14f01cb84d46d03cf5453e7010;p=jalview.git User colours are case sensitive --- diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index e65f37d..be03a9c 100755 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -719,9 +719,21 @@ public class Jalview2XML for (int i = 0; i < colours.length; i++) { jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour(); + col.setName(ResidueProperties.aa[i]); col.setRGB(jalview.util.Format.getHexString(colours[i])); jbucs.addColour(col); } + if(ucs.getLowerCaseColours()!=null) + { + colours = ucs.getLowerCaseColours(); + for (int i = 0; i < colours.length; i++) + { + jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour(); + col.setName(ResidueProperties.aa[i].toLowerCase()); + col.setRGB(jalview.util.Format.getHexString(colours[i])); + jbucs.addColour(col); + } + } id = "ucs" + userColours.indexOf(ucs); uc.setId(id); @@ -748,16 +760,29 @@ public class Jalview2XML } } - int csize = colours.getUserColourScheme().getColourCount(); - java.awt.Color[] newColours = new java.awt.Color[csize]; + java.awt.Color[] newColours = new java.awt.Color[24]; - for (int i = 0; i < csize; i++) + for (int i = 0; i < 24; i++) { newColours[i] = new java.awt.Color(Integer.parseInt( colours.getUserColourScheme().getColour(i).getRGB(), 16)); } - return new jalview.schemes.UserColourScheme(newColours); + jalview.schemes.UserColourScheme ucs = + new jalview.schemes.UserColourScheme(newColours); + + if (colours.getUserColourScheme().getColourCount() > 24) + { + newColours = new java.awt.Color[23]; + for (int i = 0; i < 23; i++) + { + newColours[i] = new java.awt.Color(Integer.parseInt( + colours.getUserColourScheme().getColour(i+24).getRGB(), 16)); + } + ucs.setLowerCaseColours(newColours); + } + + return ucs; } /** diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index 8deec8e..2369049 100755 --- a/src/jalview/gui/UserDefinedColours.java +++ b/src/jalview/gui/UserDefinedColours.java @@ -53,6 +53,9 @@ public class UserDefinedColours extends GUserDefinedColours ColourSchemeI oldColourScheme; JInternalFrame frame; MCview.PDBCanvas pdbcanvas; + Vector upperCaseButtons; + Vector lowerCaseButtons; + /** * Creates a new UserDefinedColours object. @@ -63,63 +66,39 @@ public class UserDefinedColours extends GUserDefinedColours public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg) { super(); - frame = new JInternalFrame(); - frame.setContentPane(this); - Desktop.addInternalFrame(frame, "User Defined Colours", 720, 370, true); - - if (System.getProperty("os.name").startsWith("Mac")) - { - frame.setSize(760, 370); - } - - if (sg != null) - { - frame.setTitle(frame.getTitle() + " (" + sg.getName() + ")"); - } - - colorChooser.getSelectionModel().addChangeListener(this); + lcaseColour.setEnabled(false); this.ap = ap; seqGroup = sg; if (seqGroup != null) - { oldColourScheme = seqGroup.cs; - } else - { oldColourScheme = ap.av.getGlobalColourScheme(); - } if (oldColourScheme instanceof UserColourScheme) { - schemeName.setText( ( (UserColourScheme) oldColourScheme).getName()); - } - for (int i = 0; i < 20; i++) - { - makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) + - "", ResidueProperties.aa[i]); + schemeName.setText( ( (UserColourScheme) oldColourScheme).getName()); + if(( (UserColourScheme) oldColourScheme).getLowerCaseColours()!=null) + { + caseSensitive.setSelected(true); + lcaseColour.setEnabled(true); + resetButtonPanel(true); + } + else + resetButtonPanel(false); } + else + resetButtonPanel(false); - makeButton("B", "B"); - makeButton("Z", "Z"); - makeButton("X", "X"); - makeButton("Gap", "-"); + showFrame(); } public UserDefinedColours(MCview.PDBCanvas pdb, ColourSchemeI oldcs) { super(); - frame = new JInternalFrame(); - frame.setContentPane(this); - Desktop.addInternalFrame(frame, "User Defined Colours", 720, 370, true); pdbcanvas = pdb; - if (System.getProperty("os.name").startsWith("Mac")) - { - frame.setSize(760, 370); - } - colorChooser.getSelectionModel().addChangeListener(this); oldColourScheme = oldcs; @@ -128,16 +107,98 @@ public class UserDefinedColours extends GUserDefinedColours { schemeName.setText( ( (UserColourScheme) oldColourScheme).getName()); } - 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", "-"); + resetButtonPanel(false); + + showFrame(); + + } + + void showFrame() + { + colorChooser.getSelectionModel().addChangeListener(this); + frame = new JInternalFrame(); + frame.setContentPane(this); + Desktop.addInternalFrame(frame, "User Defined Colours", 720, 370, true); + + if (seqGroup != null) + frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")"); + + if (System.getProperty("os.name").startsWith("Mac")) + { + frame.setSize(760, 370); + } + } + + void resetButtonPanel(boolean caseSensitive) + { + buttonPanel.removeAll(); + + + if(upperCaseButtons==null) + upperCaseButtons = new Vector(); + + JButton button; + String label; + for (int i = 0; i < 20; i++) + { + if(caseSensitive) + label = ResidueProperties.aa[i]; + else + label = ResidueProperties.aa2Triplet.get + (ResidueProperties.aa[i]).toString(); + + button = makeButton(label, + ResidueProperties.aa[i], + upperCaseButtons, i); + + buttonPanel.add(button); + } + + buttonPanel.add(makeButton("B", "B", upperCaseButtons, 20)); + buttonPanel.add(makeButton("Z", "Z", upperCaseButtons, 21)); + buttonPanel.add(makeButton("X", "X", upperCaseButtons, 22)); + buttonPanel.add(makeButton("Gap", "-", upperCaseButtons, 23)); + + if(!caseSensitive) + { + gridLayout.setRows(6); + gridLayout.setColumns(4); + } + else + { + gridLayout.setRows(7); + int cols = 7; + gridLayout.setColumns(cols+1); + + if(lowerCaseButtons==null) + lowerCaseButtons = new Vector(); + + + for (int i = 0; i < 20; i++) + { + int row = i / cols + 1; + int index = (row * cols) + i; + button = makeButton( + ResidueProperties.aa[i].toLowerCase(), + ResidueProperties.aa[i].toLowerCase(), + lowerCaseButtons, + i); + + buttonPanel.add(button, index); + } + } + + + if(caseSensitive) + { + buttonPanel.add(makeButton("b", "b", lowerCaseButtons, 20)); + buttonPanel.add(makeButton("z", "z", lowerCaseButtons, 21)); + buttonPanel.add(makeButton("x", "x", lowerCaseButtons, 22)); + } + + buttonPanel.validate(); + validate(); } @@ -150,13 +211,22 @@ public class UserDefinedColours extends GUserDefinedColours { if (selectedButtons != null) { - JButton button; + JButton button=null; for(int i=0; iSave your colour scheme with a unique name and it will be added " + "to the Colour menu."); + caseSensitive.setText("Case Sensitive"); + caseSensitive.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + caseSensitive_actionPerformed(e); + } + }); + lcaseColour.setText("Lower Case Colour"); + lcaseColour.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + lcaseColour_actionPerformed(e); + } + }); - jPanel3.add(savebutton); - jPanel3.add(loadbutton); - jPanel1.add(applyButton); - jPanel1.add(okButton); - jPanel1.add(cancelButton); - jPanel2.add(jPanel3, java.awt.BorderLayout.NORTH); - jPanel2.add(jPanel1, java.awt.BorderLayout.SOUTH); + saveLoadPanel.add(savebutton); + saveLoadPanel.add(loadbutton); + okCancelPanel.add(applyButton); + okCancelPanel.add(okButton); + okCancelPanel.add(cancelButton); + lowerPanel.add(saveLoadPanel, java.awt.BorderLayout.NORTH); + lowerPanel.add(okCancelPanel, java.awt.BorderLayout.SOUTH); namePanel.add(schemeName, java.awt.BorderLayout.CENTER); namePanel.add(jLabel1, java.awt.BorderLayout.WEST); panel1.add(namePanel, null); panel1.add(buttonPanel, null); - panel1.add(jPanel2, null); + panel1.add(casePanel); + casePanel.add(caseSensitive); + casePanel.add(lcaseColour); + panel1.add(lowerPanel, null); panel1.add(label); jPanel4.add(panel1, java.awt.BorderLayout.CENTER); - jPanel4.add(jPanel6, java.awt.BorderLayout.NORTH); this.add(jPanel4, java.awt.BorderLayout.CENTER); this.add(colorChooser, java.awt.BorderLayout.EAST); } @@ -225,4 +240,14 @@ public class GUserDefinedColours extends JPanel protected void cancelButton_actionPerformed(ActionEvent e) { } + + public void caseSensitive_actionPerformed(ActionEvent e) + { + + } + + public void lcaseColour_actionPerformed(ActionEvent e) + { + + } } diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java index e5efb1a..95e9a32 100755 --- a/src/jalview/schemes/UserColourScheme.java +++ b/src/jalview/schemes/UserColourScheme.java @@ -24,6 +24,8 @@ import java.util.StringTokenizer; public class UserColourScheme extends ResidueColourScheme { + Color [] lowerCaseColours; + protected String schemeName; public UserColourScheme() @@ -54,6 +56,11 @@ public class UserColourScheme return colors; } + public Color[] getLowerCaseColours() + { + return lowerCaseColours; + } + public void setName(String name) { schemeName = name; @@ -127,7 +134,7 @@ public class UserColourScheme { StringTokenizer st = new StringTokenizer(paramValue, ";"); StringTokenizer st2; - String token=null, colour, residues; + String token=null, colour, residues, residue; try{ while (st.hasMoreElements()) { @@ -138,11 +145,32 @@ public class UserColourScheme st2 = new StringTokenizer(residues, " ,"); while (st2.hasMoreTokens()) { + token = st2.nextToken(); + if(token.equalsIgnoreCase("lowerCase")) + { + if (lowerCaseColours == null) + lowerCaseColours = new Color[23]; + for (int i = 0; i < 23; i++) + if (lowerCaseColours[i] == null) + lowerCaseColours[i] = getColourFromString(colour); + + continue; + } + int colIndex = ( (Integer) ResidueProperties.aaHash. - get(st2.nextToken())).intValue(); - - colors[colIndex] = getColourFromString(colour); + get(token)).intValue(); + + if(token.equals(token.toLowerCase())) + { + if(lowerCaseColours==null) + { + lowerCaseColours = new Color[23]; + } + lowerCaseColours[colIndex] = getColourFromString(colour); + } + else + colors[colIndex] = getColourFromString(colour); } } } @@ -154,4 +182,34 @@ public class UserColourScheme } + + + public Color findColour(String s, int j) + { + int index = ((Integer) (ResidueProperties.aaHash.get(s))).intValue(); + + if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j)) + { + if(lowerCaseColours!=null && 'a' <= s.charAt(0) && s.charAt(0) <= 'z') + currentColour = lowerCaseColours[index]; + else + currentColour = colors[index]; + } + else + { + currentColour = Color.white; + } + + if(conservationColouring) + applyConservation(j); + + + return currentColour; + } + + public void setLowerCaseColours(Color [] lcolours) + { + lowerCaseColours = lcolours; + } + }