Merge branch 'develop' into features/JAL-2360colourSchemeApplicability
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 20 Jan 2017 09:47:20 +0000 (09:47 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 20 Jan 2017 09:47:20 +0000 (09:47 +0000)
Conflicts:
src/jalview/appletgui/APopupMenu.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/PopupMenu.java
src/jalview/jbgui/GAlignFrame.java

97 files changed:
examples/appletParameters.html
examples/groovy/colourSchemes.groovy [new file with mode: 0644]
help/html/colourSchemes/clustal.html
help/html/io/tcoffeescores.html
resources/lang/Messages.properties
resources/lang/Messages_es.properties
src/MCview/AppletPDBViewer.java
src/MCview/PDBViewer.java [deleted file]
src/jalview/analysis/AlignmentUtils.java
src/jalview/analysis/Conservation.java
src/jalview/appletgui/APopupMenu.java
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/AlignViewport.java
src/jalview/appletgui/AppletJmol.java
src/jalview/appletgui/FeatureRenderer.java
src/jalview/appletgui/SliderPanel.java
src/jalview/appletgui/TreeCanvas.java
src/jalview/bin/Cache.java
src/jalview/bin/Jalview.java
src/jalview/bin/JalviewLite.java
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/AlignmentI.java
src/jalview/datamodel/AnnotatedCollectionI.java
src/jalview/datamodel/SequenceGroup.java
src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/ext/rbvi/chimera/ChimeraCommands.java
src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java
src/jalview/gui/AppJmol.java
src/jalview/gui/ChimeraViewFrame.java
src/jalview/gui/ColourMenuHelper.java [new file with mode: 0644]
src/jalview/gui/FeatureRenderer.java
src/jalview/gui/Jalview2XML.java
src/jalview/gui/Jalview2XML_V1.java
src/jalview/gui/JalviewChimeraBindingModel.java
src/jalview/gui/PCAPanel.java
src/jalview/gui/PopupMenu.java
src/jalview/gui/Preferences.java
src/jalview/gui/SliderPanel.java
src/jalview/gui/StructureViewerBase.java
src/jalview/gui/TreeCanvas.java
src/jalview/gui/UserDefinedColours.java
src/jalview/io/AnnotationFile.java
src/jalview/io/FeaturesFile.java
src/jalview/io/JSONFile.java
src/jalview/io/TCoffeeScoreFile.java
src/jalview/jbgui/GAlignFrame.java
src/jalview/jbgui/GStructureViewer.java
src/jalview/jbgui/GUserDefinedColours.java
src/jalview/schemes/AnnotationColourGradient.java
src/jalview/schemes/Blosum62ColourScheme.java
src/jalview/schemes/BuriedColourScheme.java
src/jalview/schemes/ClustalxColourScheme.java
src/jalview/schemes/ColourSchemeI.java
src/jalview/schemes/ColourSchemeProperty.java
src/jalview/schemes/ColourSchemes.java [new file with mode: 0644]
src/jalview/schemes/CovariationColourScheme.java
src/jalview/schemes/FeatureColour.java
src/jalview/schemes/FollowerColourScheme.java
src/jalview/schemes/HelixColourScheme.java
src/jalview/schemes/HydrophobicColourScheme.java
src/jalview/schemes/JalviewColourScheme.java [new file with mode: 0644]
src/jalview/schemes/NucleotideColourScheme.java
src/jalview/schemes/PIDColourScheme.java
src/jalview/schemes/PurinePyrimidineColourScheme.java
src/jalview/schemes/RNAHelicesColour.java
src/jalview/schemes/RNAHelicesColourChooser.java
src/jalview/schemes/RNAInteractionColourScheme.java
src/jalview/schemes/ResidueColourScheme.java
src/jalview/schemes/ScoreColourScheme.java
src/jalview/schemes/StrandColourScheme.java
src/jalview/schemes/TCoffeeColourScheme.java
src/jalview/schemes/TaylorColourScheme.java
src/jalview/schemes/TurnColourScheme.java
src/jalview/schemes/UserColourScheme.java
src/jalview/schemes/ZappoColourScheme.java
src/jalview/structures/models/AAStructureBindingModel.java
src/jalview/util/ColorUtils.java
src/jalview/util/ParseHtmlBodyAndLinks.java
src/jalview/viewmodel/AlignmentViewport.java
src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java
src/jalview/ws/jws2/AADisorderClient.java
test/jalview/datamodel/AlignmentTest.java
test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java
test/jalview/gui/AlignViewportTest.java
test/jalview/gui/PopupMenuTest.java
test/jalview/io/Jalview2xmlTests.java
test/jalview/schemes/ClustalxColourSchemeTest.java [new file with mode: 0644]
test/jalview/schemes/ColourSchemePropertyTest.java [new file with mode: 0644]
test/jalview/schemes/ColourSchemesTest.java [new file with mode: 0644]
test/jalview/schemes/FeatureColourTest.java
test/jalview/schemes/JalviewColourSchemeTest.java [new file with mode: 0644]
test/jalview/schemes/ResidueColourSchemeTest.java
test/jalview/schemes/UserColourSchemeTest.java
test/jalview/structures/models/AAStructureBindingModelTest.java
test/jalview/util/ColorUtilsTest.java

index 277fd69..7959c3a 100644 (file)
@@ -115,7 +115,7 @@ the applet can be interacted with <em>via</em> its
             <td>defaultColour</td>
             <td> <em>One of: </em><br>
               Clustal, Blosum62, % Identity, Hydrophobic, Zappo, Taylor, Helix 
-              Propensity, Strand Propensity, Turn Propensity, Buried Index, Nucleotide, T-Coffee Scores, RNA Helices</td>
+              Propensity, Strand Propensity, Turn Propensity, Buried Index, Nucleotide, Purine/Pyrimidine, T-Coffee Scores, RNA Helices</td>
             <td>Default is no colour.</td>
           </tr>
           <tr> 
diff --git a/examples/groovy/colourSchemes.groovy b/examples/groovy/colourSchemes.groovy
new file mode 100644 (file)
index 0000000..84eabbf
--- /dev/null
@@ -0,0 +1,125 @@
+import java.awt.Color;
+import jalview.schemes.ResidueColourScheme;
+import jalview.schemes.ColourSchemes;
+import jalview.datamodel.AnnotatedCollectionI;
+import java.util.Map;
+import jalview.datamodel.SequenceI;
+
+/*
+ * Example script that registers two new alignment colour schemes
+ */
+
+/*
+ * Class that defines a colour scheme where odd columns are red,
+ * even numbered columns are blue, and gaps are yellow  
+ */
+class Stripy extends ResidueColourScheme {
+    Stripy() { }
+    String getSchemeName() { "stripy" }
+    Stripy getInstance(AnnotatedCollectionI coll, Map map) { new Stripy() }
+    Color findColour(char res, int col, SequenceI seq) {
+      // determine the colour
+      Color colour = findColour(res, col)
+      // let Jalview apply conservation or consensus shading
+      adjustColour(res, col, colour);
+    }
+    Color findColour(char res, int col) {
+        if (res == ' ' || res == '-' || res == '.') 
+        {
+            Color.yellow
+         } else if (col % 2 == 0) 
+         {
+            Color.blue
+         } else 
+         {
+            Color.red
+         }
+    }
+}
+
+/*
+ * Class that defines a colour scheme graduated 
+ * (approximately) by amino acid weight  
+ */
+class ByWeight extends ResidueColourScheme {
+    int min = 75
+    int max = 204
+    ByWeight() { }
+    boolean isPeptideSpecific() {true}
+    String getSchemeName() { "By Weight" }
+    ByWeight getInstance(AnnotatedCollectionI coll, Map map) { new ByWeight() }
+    Color makeColour(int weight) {
+      int i = 255 * (weight - min) / (max - min);
+      new Color(i, 0, i);
+    }
+    Color findColour(char res, int col, SequenceI seq) {
+      // determine the colour
+      Color colour = findColour(res, col)
+      // let Jalview apply any conservation or consensus shading
+      adjustColour(res, col, colour);
+    }
+    Color findColour(char res, int col) {
+        switch (res) {
+          case ' ':
+          case '-':
+          case '.':
+            Color.white
+             break
+          case 'A':
+            makeColour(89)
+            break
+          case 'R':
+            makeColour(174)
+            break
+          case 'N':
+          case 'D':
+          case 'B':
+          case 'I':
+          case 'L':
+            makeColour(132)
+            break
+          case 'C':
+            makeColour(121)
+            break
+          case 'Q':
+          case 'E':
+          case 'Z':
+          case 'K':
+          case 'M':
+            makeColour(146)
+            break
+          case 'G':
+            makeColour(75)
+            break
+          case 'H':
+            makeColour(155)
+            break
+          case 'F':
+            makeColour(165)
+            break
+          case 'P':
+            makeColour(115)
+            break
+          case 'S':
+            makeColour(105)
+            break
+          case 'T':
+            makeColour(119)
+            break
+          case 'W':
+            makeColour(204)
+            break
+          case 'Y':
+            makeColour(181)
+            break
+          case 'V':
+            makeColour(117)
+            break
+          default:
+            makeColour(150)
+        }
+      }
+}
+
+ColourSchemes.instance.registerColourScheme(new Stripy())
+ColourSchemes.instance.registerColourScheme(new ByWeight())
index 7b68c84..9ed6139 100755 (executable)
@@ -40,9 +40,10 @@ td {
     is assigned a colour if the amino acid profile of the alignment at
     that position meets some minimum criteria specific for the residue
     type.</p>
-  <p>The table below gives these criteria as clauses: {+X%,xx,y},
-    where X is the minimum percentage presence for any of the xx (or y)
-    residue types.</p>
+  <p>The table below gives these criteria as clauses: {&gt;X%,xx,y},
+    where X is the threshold percentage presence for any of the xx (or y)
+    residue types.
+    <br>For example, K or R is coloured red if the column includes more than 60% K or R (combined), or more than 80% of either K or R or Q (individually).</p>
   <div align="center">
     <p>&nbsp;</p>
     <table border="1">
@@ -52,70 +53,81 @@ td {
       <tr>
         <td><table border="1">
             <tr>
+              <th>Category</th>
+              <th>Colour</th>
               <th>Residue at position</th>
-              <th>Applied Colour</th>
-              <th>{ Threshhold, Residue group }</th>
+              <th>{ Threshold, Residue group }</th>
             </tr>
             <tr>
+              <td rowspan="2">Hydrophobic</td>
+              <td rowspan="2" bgcolor="#80a0f0">BLUE</td>
               <td>A,I,L,M,F,W,V</td>
-              <td bgcolor="#80a0f0">BLUE</td>
-              <td>{+60%, WLVIMAFCHP}</td>
+              <td>{&gt;60%, WLVIMAFCHP}</td>
             </tr>
             <tr>
-              <td>R,K</td>
+              <td>C</td>
+              <td>{&gt;60%, WLVIMAFCHP}</td>
+            </tr>
+            <tr>
+              <td>Positive charge</td>
               <td bgcolor="#f01505">RED</td>
-              <td>{+60%,KR},{+80%, K,R,Q}</td>
+              <td>K,R</td>
+              <td>{&gt;60%,KR},{&gt;80%, K,R,Q}</td>
             </tr>
             <tr>
-              <td>N</td>
-              <td bgcolor="#15c015">GREEN</td>
-              <td>{+50%, N}, {+85%, N,Y}</td>
+              <td rowspan="2">Negative charge</td>
+              <td rowspan="2" bgcolor="#c048c0">MAGENTA</td>
+              <td>E</td>
+              <td>{&gt;60%,KR},{&gt;50%,QE},{&gt;85%,E,Q,D}</td>
             </tr>
             <tr>
-              <td>C</td>
-              <td bgcolor="#80a0f0">BLUE</td>
-              <td>{+60%, WLVIMAFCHP}</td>
+              <td>D</td>
+              <td>{&gt;60%,KR}, {&gt;85%, K,R,Q}, {&gt;50%,ED}</td>
             </tr>
             <tr>
-              <td>C</td>
-              <td bgcolor="#f08080">PINK</td>
-              <td>{100%, C}</td>
+              <td rowspan="3">Polar</td>
+              <td rowspan="3" bgcolor="#15c015">GREEN</td>
+              <td>N</td>
+              <td>{&gt;50%, N}, {&gt;85%, N,Y}</td>
             </tr>
             <tr>
               <td>Q</td>
-              <td bgcolor="#15c015">GREEN</td>
-              <td>{+60%,KR},{+50%,QE},{+85%,Q,E,K,R}</td>
+              <td>{&gt;60%,KR},{&gt;50%,QE},{&gt;85%,Q,E,K,R}</td>
             </tr>
             <tr>
-              <td>E</td>
-              <td bgcolor="#c048c0">MAGENTA</td>
-              <td>{+60%,KR},{+50%,QE},{+85%,E,Q,D}</td>
+              <td>S,T</td>
+              <td>{&gt;60%, WLVIMAFCHP}, {&gt;50%, TS}, {&gt;85%,S,T}</td>
             </tr>
             <tr>
-              <td>D</td>
-              <td bgcolor="#c048c0">MAGENTA</td>
-              <td>{+60%,KR}, {+85%, K,R,Q}, {+50%,ED}</td>
+              <td>Cysteines</td>
+              <td bgcolor="#f08080">PINK</td>
+              <td>C</td>
+              <td>{100%, C}</td>
             </tr>
             <tr>
-              <td>G</td>
+              <td>Glycines</td>
               <td bgcolor="#f09048">ORANGE</td>
-              <td>{+0%, G}</td>
+              <td>G</td>
+              <td>{&gt;0%, G}</td>
             </tr>
             <tr>
-              <td>H,Y</td>
-              <td bgcolor="#15a4a4">CYAN</td>
-              <td>{+60%, WLVIMAFCHP}, {+85%,
-                W,Y,A,C,P,Q,F,H,I,L,M,V}</td>
+              <td>Prolines</td>
+              <td bgcolor="#c0c000">YELLOW</td>
+              <td>P</td>
+              <td>{&gt;0%, P}</td>
             </tr>
             <tr>
-              <td>P</td>
-              <td bgcolor="#c0c000">YELLOW</td>
-              <td>{+0%, P}</td>
+              <td>Aromatic</td>
+              <td bgcolor="#15a4a4">CYAN</td>
+              <td>H,Y</td>
+              <td>{&gt;60%, WLVIMAFCHP}, {&gt;85%,
+                W,Y,A,C,P,Q,F,H,I,L,M,V}</td>
             </tr>
             <tr>
-              <td>S,T</td>
-              <td bgcolor="#15c015">GREEN</td>
-              <td>{+60%, WLVIMAFCHP}, {+50%, TS}, {+85%,S,T}</td>
+              <td>Unconserved</td>
+              <td>WHITE</td>
+              <td>any / gap</td>
+              <td>If none of the above criteria are met</td>
             </tr>
           </table></td>
       </tr>
index 08d1889..e67e3af 100644 (file)
@@ -79,6 +79,20 @@ cons   999999999999999999999999999851000110321100001134
 1QCF   ----------6878742356789999999999889
 cons   00100000006877641356789999999999889
 </pre>
-
+<table border="1">
+<tr><th>Score</th><th>0</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>9</th></tr>
+<tr>
+<td>RGB colour</td>
+<td bgcolor="#6666FF">102, 102, 255</td>
+<td bgcolor="#00FF00">0, 255, 0</td>
+<td bgcolor="#66FF00">102, 255, 0</td>
+<td bgcolor="#CCFF00">204, 255, 0</td>
+<td bgcolor="#FFFF00">255, 255, 0</td>
+<td bgcolor="#FFCC00">255, 204, 0</td>
+<td bgcolor="#FF9900">255, 153, 0</td>
+<td bgcolor="#FF6600">255, 102, 0</td>
+<td bgcolor="#FF3300">255, 51, 0</td>
+<td bgcolor="#FF2000">255, 34, 0</td></tr>
+</table>
 </body>
 </html>
index a86154c..c451f07 100644 (file)
@@ -61,7 +61,6 @@ action.set_as_reference = Set as Reference
 action.remove = Remove
 action.remove_redundancy = Remove Redundancy...
 action.pairwise_alignment = Pairwise Alignment
-action.by_rna_helixes = By RNA Helices
 action.user_defined = User Defined...
 action.by_conservation = By Conservation
 action.wrap = Wrap
@@ -179,27 +178,30 @@ label.score_model_conservation = Physicochemical property conservation
 label.score_model_enhconservation = Physicochemical property conservation
 label.status_bar = Status bar
 label.out_to_textbox = Output to Textbox
-label.clustalx = Clustalx
+# delete Clustal - use FileFormat name instead
 label.clustal = Clustal
-label.zappo = Zappo
-label.taylor = Taylor
+# label.colourScheme_<schemeName> as in JalviewColourScheme
+label.colourScheme_clustal = Clustalx
+label.colourScheme_blosum62 = BLOSUM62 Score
+label.colourScheme_%_identity = Percentage Identity
+label.colourScheme_zappo = Zappo
+label.colourScheme_taylor = Taylor
+label.colourScheme_hydrophobic = Hydrophobicity
+label.colourScheme_helix_propensity = Helix Propensity
+label.colourScheme_strand_propensity = Strand Propensity
+label.colourScheme_turn_propensity = Turn Propensity
+label.colourScheme_buried_index = Buried Index
+label.colourScheme_purine/pyrimidine = Purine/Pyrimidine
+label.colourScheme_nucleotide = Nucleotide
+label.colourScheme_t-coffee_scores = T-Coffee Scores
+label.colourScheme_rna_helices = By RNA Helices
 label.blc = BLC
 label.fasta = Fasta
 label.msf = MSF
 label.pfam = PFAM
 label.pileup = Pileup
 label.pir = PIR
-label.hydrophobicity = Hydrophobicity
-label.helix_propensity = Helix Propensity
-label.strand_propensity = Strand Propensity
-label.turn_propensity = Turn Propensity
-label.buried_index = Buried Index
-label.purine_pyrimidine = Purine/Pyrimidine
-label.percentage_identity = Percentage Identity
-label.blosum62 = BLOSUM62
-label.blosum62_score = BLOSUM62 Score
-label.tcoffee_scores = T-Coffee Scores
-label.average_distance_bloslum62 = Average Distance Using BLOSUM62
+label.average_distance_blosum62 = Average Distance Using BLOSUM62
 label.neighbour_blosum62 = Neighbour Joining Using BLOSUM62
 label.show_annotations = Show annotations
 label.hide_annotations = Hide annotations
@@ -211,7 +213,7 @@ label.hide_all = Hide all
 label.add_reference_annotations = Add reference annotations
 label.find_tip = Search alignment, selection or sequence ids for a subsequence (ignoring gaps).<br>Accepts regular expressions - search Help for 'regex' for details.
 label.colour_text = Colour Text
-label.show_non_conversed = Show nonconserved
+label.show_non_conserved = Show nonconserved
 label.overview_window = Overview Window
 label.none = None
 label.above_identity_threshold = Above Identity Threshold
@@ -323,7 +325,7 @@ label.size = Size:
 label.style = Style:
 label.calculating = Calculating....
 label.modify_conservation_visibility = Modify conservation visibility
-label.colour_residues_above_occurence = Colour residues above % occurrence
+label.colour_residues_above_occurrence = Colour residues above % occurrence
 label.set_this_label_text = set this label text
 label.sequences_from = Sequences from {0}
 label.successfully_loaded_file  = Successfully loaded file {0}
@@ -670,8 +672,6 @@ action.set_text_colour = Text Colour...
 label.structure = Structure
 label.show_pdbstruct_dialog = 3D Structure Data...
 label.view_rna_structure = VARNA 2D Structure
-label.clustalx_colours = Clustalx colours
-label.above_identity_percentage = Above % Identity
 label.create_sequence_details_report_annotation_for = Annotation for {0}
 label.sequence_details_for = Sequence Details for {0}
 label.sequence_name = Sequence Name
@@ -770,7 +770,7 @@ label.original_data_for_params = Original Data for {0}
 label.points_for_params = Points for {0}
 label.transformed_points_for_params = Transformed points for {0}
 label.graduated_color_for_params = Graduated Feature Colour for {0}
-label.select_backgroud_colour = Select Background Colour
+label.select_background_colour = Select Background Colour
 label.invalid_font = Invalid Font
 label.separate_multiple_accession_ids = Enter one or more accession IDs separated by a semi-colon ";"
 label.separate_multiple_query_values = Enter one or more {0}s separated by a semi-colon ";"
@@ -960,7 +960,6 @@ error.implementation_error_maplist_is_null = Implementation error. MapList is nu
 error.implementation_error_cannot_have_null_alignment = Implementation error: Cannot have null alignment property key
 error.implementation_error_null_fileparse = Implementation error. Null FileParse in copy constructor
 error.implementation_error_cannot_map_alignment_sequences = IMPLEMENTATION ERROR: Cannot map an alignment of sequences from different datasets into a single alignment in the vamsas document.
-error.implementation_error_cannot_duplicate_colour_scheme = Serious implementation error: cannot duplicate colourscheme {0}
 error.implementation_error_structure_selection_manager_null = Implementation error. Structure selection manager's context is 'null'
 exception.ssm_context_is_null = SSM context is null
 error.idstring_seqstrings_only_one_per_sequence = idstrings and seqstrings contain one string each per sequence
@@ -1025,7 +1024,6 @@ exception.replace_null_regex_pointer = Replacer has null Regex pointer
 exception.bad_pattern_to_regex_perl_code = bad pattern to Regex.perlCode: {0}
 exception.no_stub_implementation_for_interface = There is no stub implementation for the interface: {0}
 exception.cannot_set_endpoint_address_unknown_port = Cannot set Endpoint Address for Unknown Port {0}
-exception.querying_matching_opening_parenthesis_for_non_closing_parenthesis = Querying matching opening parenthesis for non-closing parenthesis character {0}
 exception.mismatched_unseen_closing_char = Mismatched (unseen) closing character {0}
 exception.mismatched_closing_char = Mismatched closing character {0}
 exception.mismatched_opening_char = Mismatched opening character {0} at {1}
@@ -1036,7 +1034,6 @@ exception.couldnt_parse_responde_from_annotated3d_server = Couldn't parse respon
 exception.application_test_npe = Application test: throwing an NullPointerException It should arrive at the console
 exception.overwriting_vamsas_id_binding = Overwriting vamsas id binding
 exception.overwriting_jalview_id_binding = Overwriting jalview id binding
-error.implementation_error_unknown_file_format_string = Implementation error: Unknown file format string
 exception.failed_to_resolve_gzip_stream = Failed to resolve GZIP stream
 exception.problem_opening_file_also_tried = Problem opening {0} (also tried {1}) : {2}
 exception.problem_opening_file = Problem opening {0} : {1}
@@ -1232,7 +1229,6 @@ action.export_hidden_columns = Export Hidden Columns
 action.export_hidden_sequences = Export Hidden Sequences
 action.export_features = Export Features
 label.export_settings = Export Settings
-label.save_as_biojs_html = Save as BioJs HTML
 label.pdb_web-service_error = PDB Web-service Error
 label.structure_chooser_manual_association = Structure Chooser - Manual association
 label.structure_chooser_filter_time = Structure Chooser - Filter time ({0})
index 8cdcd52..72461e2 100644 (file)
@@ -59,7 +59,6 @@ action.by_group = Por grupo
 action.remove = Eliminar
 action.remove_redundancy = Eliminar redundancia...
 action.pairwise_alignment = Alineamiento de pares...
-action.by_rna_helixes = Por hélices de RNA
 action.user_defined = Definido por el usuario...
 action.by_conservation = Por conservación
 action.wrap = Envolver
@@ -176,31 +175,33 @@ label.score_model_conservation = Conservaci
 label.score_model_enhconservation = Conservación de las propiedades físico-químicas
 label.status_bar = Barra de estado
 label.out_to_textbox = Generar cuadro de texto
-label.clustalx = Clustalx
 label.clustal = Clustal
-label.zappo = Zappo
-label.taylor = Taylor
+# label.colourScheme_<schemeName> as in JalviewColourScheme
+label.colourScheme_clustal = Clustalx
+label.colourScheme_blosum62 = Puntuación del BLOSUM62
+label.colourScheme_%_identity = Porcentaje de identidad
+label.colourScheme_zappo = Zappo
+label.colourScheme_taylor = Taylor
+label.colourScheme_hydrophobic = Hidrofobicidad
+label.colourScheme_helix_propensity = Tendencia de la hélice
+label.colourScheme_strand_propensity = Tendencia de la hebra
+label.colourScheme_turn_propensity = Tendencia de giro
+label.colourScheme_buried_index = Índice de encubrimiento
+label.colourScheme_purine/pyrimidine = Purina/Pirimidina
+label.colourScheme_nucleotide = Nucleótido
+label.colourScheme_t-coffee_scores = Puntuación del T-Coffee
+label.colourScheme_rna_helices = Por hélices de RNA
 label.blc = BLC
 label.fasta = Fasta
 label.msf = MSF
 label.pfam = PFAM
 label.pileup = Pileup
 label.pir = PIR
-label.hydrophobicity = Hidrofobicidad
-label.helix_propensity = Tendencia de la hélice
-label.strand_propensity = Tendencia de la hebra
-label.turn_propensity = Tendencia de giro
-label.buried_index = Índice de encubrimiento
-label.purine_pyrimidine = Purina/Pirimidina
-label.percentage_identity = Porcentaje de identidad
-label.blosum62 = BLOSUM62
-label.blosum62_score = Puntuación del BLOSUM62 
-label.tcoffee_scores = Puntuación del T-Coffee
-label.average_distance_bloslum62 = Distancia Media Usando BLOSUM62
+label.average_distance_blosum62 = Distancia Media Usando BLOSUM62
 label.neighbour_blosum62 = Neighbour Joining usando BLOSUM62
 label.show_annotations = Mostrar anotaciones
 label.colour_text = Color del texto
-label.show_non_conversed = Mostrar no conservadas
+label.show_non_conserved = Mostrar no conservadas
 label.overview_window = Ventana resumen
 label.none = Ninguno
 label.above_identity_threshold = Por encima del umbral de identidad
@@ -622,8 +623,6 @@ label.from_file = desde fichero
 label.enter_pdb_id = Introducir PDB Id
 label.text_colour = Color del texto
 label.structure = Estructura
-label.clustalx_colours = Colores de Clustalx
-label.above_identity_percentage = Sobre % identidad
 label.create_sequence_details_report_annotation_for = Anotación para {0}
 label.sequence_details_for = Detalles de la secuencia para {0}
 label.sequence_name = Nombre de la secuencia
@@ -707,7 +706,7 @@ label.original_data_for_params = Datos originales de {0}
 label.points_for_params = Puntos de {0}
 label.transformed_points_for_params = Puntos transformados de {0}
 label.graduated_color_for_params = Color graduado para la característica de {0}
-label.select_backgroud_colour = Seleccionar color de fondo
+label.select_background_colour = Seleccionar color de fondo
 label.invalid_font = Fuente no válida
 label.separate_multiple_accession_ids = Separar los accession id con un punto y coma ";"
 label.replace_commas_semicolons = Cambiar comas por puntos y comas
@@ -893,7 +892,6 @@ error.implementation_error_maplist_is_null = Error de implementaci
 error.implementation_error_cannot_have_null_alignment = Error de implementación: no es posible tener una clave nula en el alineamiento
 error.implementation_error_null_fileparse = Error de implementación. FileParse nulo en el construictor de copia
 error.implementation_error_cannot_map_alignment_sequences = Error de implementación: no es posible maper un alineamiento de secuencias desde distintos conjuntos de datos en un único alineamiento en el documento VAMSAS.
-error.implementation_error_cannot_duplicate_colour_scheme = Error grave de implementación: no es posible duplicar el esquema cromático {0}
 error.implementation_error_structure_selection_manager_null = Error de implementación. El contexto structure selection manager's es nulo
 exception.ssm_context_is_null = El contexto SSM es nulo
 error.idstring_seqstrings_only_one_per_sequence = idstrings y seqstrings contienen una cadena por cada secuencia
@@ -958,7 +956,6 @@ exception.replace_null_regex_pointer = Reemplazador tiene un puntero Regex nulo
 exception.bad_pattern_to_regex_perl_code = patrón erróneo en Regex.perlCode: {0}
 exception.no_stub_implementation_for_interface = No existe una implementación del stub para la interfaz: {0}
 exception.cannot_set_endpoint_address_unknown_port = No es posible estabelcer la dirección de punto final para el puerto desconocido {0}
-exception.querying_matching_opening_parenthesis_for_non_closing_parenthesis = Consultando la coincidencia de apertura de paréntesis para paréntesis sin cerrar (?)
 exception.mismatched_unseen_closing_char = Discordancia (no vista) en el carácter de cierre {0}
 exception.mismatched_closing_char = Carácter de cierre discordante {0}
 exception.mismatched_opening_char = Carácter de apertura discordante {0} en {1}
@@ -969,7 +966,6 @@ exception.couldnt_parse_responde_from_annotated3d_server = No es posible parsear
 exception.application_test_npe = Prueba de aplicación: lanzando un NullPointerException que debe aparecer en la consola
 exception.overwriting_vamsas_id_binding = Sobreescribiendo la asociación al VAMSAS id
 exception.overwriting_jalview_id_binding = Sobreescribiendo la asociación al Jalview id
-error.implementation_error_unknown_file_format_string = Error de implementación: cadena de formato de fichero desconocido
 exception.failed_to_resolve_gzip_stream = Fallo al resolver el flujo GZIP 
 exception.problem_opening_file_also_tried = Problema abriendo {0} (también se intentó {1}) : {2}
 exception.problem_opening_file = Problema abriendo {0} : {1}
@@ -1233,7 +1229,6 @@ tooltip.aacon_calculations=Actualizar c
 info.select_filter_option=Escoger Opción de Filtro / Entrada Manual
 info.invalid_msa_input_mininfo=Necesita por lo menos dos secuencias con al menos 3 residuos cada una, sin regiones ocultas entre ellas.
 label.chimera_missing=Visualizador de estructura Chimera no encontrado.<br/>Por favor, introduzca la ruta de Chimera,<br/>o descargar e instalar la UCSF Chimera.
-label.save_as_biojs_html=Guardar como HTML BioJs
 exception.fts_server_unreachable=Jalview no puede conectar con el servidor {0}. \nPor favor asegúrese de que está conectado a Internet y vuelva a intentarlo.
 exception.outofmemory_loading_mmcif_file=Sin memoria al cargar el fichero mmCIF
 label.hide_columns_not_containing=Ocultar las columnas que no contengan
index 76ee4b0..133565c 100644 (file)
@@ -185,7 +185,8 @@ public class AppletPDBViewer extends EmbmenuFrame implements
     zbuffer.addItemListener(this);
     charge.setLabel(MessageManager.getString("label.charge_cysteine"));
     charge.addActionListener(this);
-    hydro.setLabel(MessageManager.getString("label.hydrophobicity"));
+    hydro.setLabel(MessageManager
+            .getString("label.colourScheme_hydrophobic"));
     hydro.addActionListener(this);
     chain.setLabel(MessageManager.getString("action.by_chain"));
     chain.addActionListener(this);
@@ -195,17 +196,21 @@ public class AppletPDBViewer extends EmbmenuFrame implements
             .setLabel(MessageManager.getString("label.all_chains_visible"));
     allchains.addItemListener(this);
     viewMenu.setLabel(MessageManager.getString("action.view"));
-    zappo.setLabel(MessageManager.getString("label.zappo"));
+    zappo.setLabel(MessageManager.getString("label.colourScheme_zappo"));
     zappo.addActionListener(this);
-    taylor.setLabel(MessageManager.getString("label.taylor"));
+    taylor.setLabel(MessageManager.getString("label.colourScheme_taylor"));
     taylor.addActionListener(this);
-    helix.setLabel(MessageManager.getString("label.helix_propensity"));
+    helix.setLabel(MessageManager
+            .getString("label.colourScheme_helix_propensity"));
     helix.addActionListener(this);
-    strand.setLabel(MessageManager.getString("label.strand_propensity"));
+    strand.setLabel(MessageManager
+            .getString("label.colourScheme_strand_propensity"));
     strand.addActionListener(this);
-    turn.setLabel(MessageManager.getString("label.turn_propensity"));
+    turn.setLabel(MessageManager
+            .getString("label.colourScheme_turn_propensity"));
     turn.addActionListener(this);
-    buried.setLabel(MessageManager.getString("label.buried_index"));
+    buried.setLabel(MessageManager
+            .getString("label.colourScheme_buried_index"));
     buried.addActionListener(this);
     user.setLabel(MessageManager.getString("action.user_defined"));
     user.addActionListener(this);
diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java
deleted file mode 100755 (executable)
index f108fc2..0000000
+++ /dev/null
@@ -1,784 +0,0 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
- * 
- * This file is part of Jalview.
- * 
- * Jalview 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 3
- * of the License, or (at your option) any later version.
- *  
- * Jalview 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 Jalview.  If not, see <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package MCview;
-
-import jalview.datamodel.PDBEntry;
-import jalview.datamodel.SequenceI;
-import jalview.gui.AlignmentPanel;
-import jalview.gui.Desktop;
-import jalview.gui.JvOptionPane;
-import jalview.gui.OOMWarning;
-import jalview.gui.UserDefinedColours;
-import jalview.io.DataSourceType;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.StrandColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.UserColourScheme;
-import jalview.schemes.ZappoColourScheme;
-import jalview.util.MessageManager;
-import jalview.ws.ebi.EBIFetchClient;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.PrintWriter;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JColorChooser;
-import javax.swing.JInternalFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JMenuItem;
-import javax.swing.JRadioButtonMenuItem;
-
-public class PDBViewer extends JInternalFrame implements Runnable
-{
-
-  /**
-   * The associated sequence in an alignment
-   */
-  PDBCanvas pdbcanvas;
-
-  PDBEntry pdbentry;
-
-  SequenceI[] seq;
-
-  String[] chains;
-
-  AlignmentPanel ap;
-
-  DataSourceType protocol;
-
-  String tmpPDBFile;
-
-  public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
-          AlignmentPanel ap, DataSourceType protocol)
-  {
-    this.pdbentry = pdbentry;
-    this.seq = seq;
-    this.chains = chains;
-    this.ap = ap;
-    this.protocol = protocol;
-
-    try
-    {
-      jbInit();
-    } catch (Exception ex)
-    {
-      ex.printStackTrace();
-    }
-
-    StringBuffer title = new StringBuffer(seq[0].getName() + ":"
-            + pdbentry.getFile());
-
-    pdbcanvas = new PDBCanvas();
-
-    setContentPane(pdbcanvas);
-
-    if (pdbentry.getFile() != null)
-    {
-      try
-      {
-        tmpPDBFile = pdbentry.getFile();
-        PDBfile pdbfile = new PDBfile(false, false, false, tmpPDBFile,
-                DataSourceType.FILE);
-
-        pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
-
-      } catch (java.io.IOException ex)
-      {
-        ex.printStackTrace();
-      }
-    }
-    else
-    {
-      Thread worker = new Thread(this);
-      worker.start();
-    }
-
-    String method = (String) pdbentry.getProperty("method");
-    if (method != null)
-    {
-      title.append(" Method: ");
-      title.append(method);
-    }
-    String ch = (String) pdbentry.getProperty("chains");
-    if (ch != null)
-    {
-      title.append(" Chain:");
-      title.append(ch);
-    }
-    Desktop.addInternalFrame(this, title.toString(), 400, 400);
-  }
-
-  @Override
-  public void run()
-  {
-    try
-    {
-      EBIFetchClient ebi = new EBIFetchClient();
-      String query = "pdb:" + pdbentry.getId();
-      pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "xml")
-              .getAbsolutePath());
-
-      if (pdbentry.getFile() != null)
-      {
-        pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
-      }
-    } catch (Exception ex)
-    {
-      pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
-      ex.printStackTrace();
-    }
-  }
-
-  private void jbInit() throws Exception
-  {
-    this.addKeyListener(new KeyAdapter()
-    {
-      @Override
-      public void keyPressed(KeyEvent evt)
-      {
-        pdbcanvas.keyPressed(evt);
-      }
-    });
-
-    this.setJMenuBar(jMenuBar1);
-    fileMenu.setText(MessageManager.getString("action.file"));
-    coloursMenu.setText(MessageManager.getString("label.colours"));
-    saveMenu.setActionCommand(MessageManager.getString("action.save_image"));
-    saveMenu.setText(MessageManager.getString("action.save_as"));
-    png.setText("PNG");
-    png.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        png_actionPerformed(e);
-      }
-    });
-    eps.setText("EPS");
-    eps.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        eps_actionPerformed(e);
-      }
-    });
-    mapping.setText(MessageManager.getString("label.view_mapping"));
-    mapping.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        mapping_actionPerformed(e);
-      }
-    });
-    wire.setText(MessageManager.getString("label.wireframe"));
-    wire.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        wire_actionPerformed(e);
-      }
-    });
-    depth.setSelected(true);
-    depth.setText(MessageManager.getString("label.depthcue"));
-    depth.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        depth_actionPerformed(e);
-      }
-    });
-    zbuffer.setSelected(true);
-    zbuffer.setText(MessageManager.getString("label.z_buffering"));
-    zbuffer.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        zbuffer_actionPerformed(e);
-      }
-    });
-    charge.setText(MessageManager.getString("label.charge_cysteine"));
-    charge.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        charge_actionPerformed(e);
-      }
-    });
-    chain.setText(MessageManager.getString("action.by_chain"));
-    chain.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        chain_actionPerformed(e);
-      }
-    });
-    seqButton.setSelected(true);
-    seqButton.setText(MessageManager.getString("action.by_sequence"));
-    seqButton.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        seqButton_actionPerformed(e);
-      }
-    });
-    allchains.setSelected(true);
-    allchains.setText(MessageManager.getString("label.show_all_chains"));
-    allchains.addItemListener(new ItemListener()
-    {
-      @Override
-      public void itemStateChanged(ItemEvent e)
-      {
-        allchains_itemStateChanged(e);
-      }
-    });
-    zappo.setText(MessageManager.getString("label.zappo"));
-    zappo.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        zappo_actionPerformed(e);
-      }
-    });
-    taylor.setText(MessageManager.getString("label.taylor"));
-    taylor.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        taylor_actionPerformed(e);
-      }
-    });
-    hydro.setText(MessageManager.getString("label.hydrophobicity"));
-    hydro.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        hydro_actionPerformed(e);
-      }
-    });
-    helix.setText(MessageManager.getString("label.helix_propensity"));
-    helix.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        helix_actionPerformed(e);
-      }
-    });
-    strand.setText(MessageManager.getString("label.strand_propensity"));
-    strand.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        strand_actionPerformed(e);
-      }
-    });
-    turn.setText(MessageManager.getString("label.turn_propensity"));
-    turn.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        turn_actionPerformed(e);
-      }
-    });
-    buried.setText(MessageManager.getString("label.buried_index"));
-    buried.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        buried_actionPerformed(e);
-      }
-    });
-    user.setText(MessageManager.getString("action.user_defined"));
-    user.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        user_actionPerformed(e);
-      }
-    });
-    viewMenu.setText(MessageManager.getString("action.view"));
-    background
-            .setText(MessageManager.getString("action.background_colour"));
-    background.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        background_actionPerformed(e);
-      }
-    });
-    savePDB.setText(MessageManager.getString("label.pdb_file"));
-    savePDB.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        savePDB_actionPerformed(e);
-      }
-    });
-    jMenuBar1.add(fileMenu);
-    jMenuBar1.add(coloursMenu);
-    jMenuBar1.add(viewMenu);
-    fileMenu.add(saveMenu);
-    fileMenu.add(mapping);
-    saveMenu.add(savePDB);
-    saveMenu.add(png);
-    saveMenu.add(eps);
-    coloursMenu.add(seqButton);
-    coloursMenu.add(chain);
-    coloursMenu.add(charge);
-    coloursMenu.add(zappo);
-    coloursMenu.add(taylor);
-    coloursMenu.add(hydro);
-    coloursMenu.add(helix);
-    coloursMenu.add(strand);
-    coloursMenu.add(turn);
-    coloursMenu.add(buried);
-    coloursMenu.add(user);
-    coloursMenu.add(background);
-    ButtonGroup bg = new ButtonGroup();
-    bg.add(seqButton);
-    bg.add(chain);
-    bg.add(charge);
-    bg.add(zappo);
-    bg.add(taylor);
-    bg.add(hydro);
-    bg.add(helix);
-    bg.add(strand);
-    bg.add(turn);
-    bg.add(buried);
-    bg.add(user);
-
-    if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
-    {
-      java.util.Enumeration userColours = jalview.gui.UserDefinedColours
-              .getUserColourSchemes().keys();
-
-      while (userColours.hasMoreElements())
-      {
-        final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
-                userColours.nextElement().toString());
-        radioItem.setName("USER_DEFINED");
-        radioItem.addMouseListener(new MouseAdapter()
-        {
-          @Override
-          public void mousePressed(MouseEvent evt)
-          {
-            if (evt.isPopupTrigger()) // Mac
-            {
-              offerRemoval(radioItem);
-            }
-          }
-
-          @Override
-          public void mouseReleased(MouseEvent evt)
-          {
-            if (evt.isPopupTrigger()) // Windows
-            {
-              offerRemoval(radioItem);
-            }
-          }
-
-          /**
-           * @param radioItem
-           */
-          void offerRemoval(final JRadioButtonMenuItem radioItem)
-          {
-            radioItem.removeActionListener(radioItem.getActionListeners()[0]);
-
-            int option = JvOptionPane.showInternalConfirmDialog(
-                    jalview.gui.Desktop.desktop, MessageManager
-                            .getString("label.remove_from_default_list"),
-                    MessageManager
-                            .getString("label.remove_user_defined_colour"),
-                    JvOptionPane.YES_NO_OPTION);
-            if (option == JvOptionPane.YES_OPTION)
-            {
-              jalview.gui.UserDefinedColours
-                      .removeColourFromDefaults(radioItem.getText());
-              coloursMenu.remove(radioItem);
-            }
-            else
-            {
-              radioItem.addActionListener(new ActionListener()
-              {
-                @Override
-                public void actionPerformed(ActionEvent evt)
-                {
-                  user_actionPerformed(evt);
-                }
-              });
-            }
-          }
-        });
-        radioItem.addActionListener(new ActionListener()
-        {
-          @Override
-          public void actionPerformed(ActionEvent evt)
-          {
-            user_actionPerformed(evt);
-          }
-        });
-        coloursMenu.add(radioItem);
-        bg.add(radioItem);
-      }
-    }
-
-    viewMenu.add(wire);
-    viewMenu.add(depth);
-    viewMenu.add(zbuffer);
-    viewMenu.add(allchains);
-  }
-
-  JMenuBar jMenuBar1 = new JMenuBar();
-
-  JMenu fileMenu = new JMenu();
-
-  JMenu coloursMenu = new JMenu();
-
-  JMenu saveMenu = new JMenu();
-
-  JMenuItem png = new JMenuItem();
-
-  JMenuItem eps = new JMenuItem();
-
-  JMenuItem mapping = new JMenuItem();
-
-  JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
-
-  JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
-
-  JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
-
-  JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
-
-  JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
-
-  JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
-
-  JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
-
-  JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
-
-  JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
-
-  JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
-
-  JRadioButtonMenuItem user = new JRadioButtonMenuItem();
-
-  JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
-
-  JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
-
-  JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
-
-  JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
-
-  JMenu viewMenu = new JMenu();
-
-  JMenuItem background = new JMenuItem();
-
-  JMenuItem savePDB = new JMenuItem();
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  public void eps_actionPerformed(ActionEvent e)
-  {
-    makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  public void png_actionPerformed(ActionEvent e)
-  {
-    makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
-  }
-
-  void makePDBImage(jalview.util.ImageMaker.TYPE type)
-  {
-    int width = pdbcanvas.getWidth();
-    int height = pdbcanvas.getHeight();
-
-    jalview.util.ImageMaker im;
-
-    if (type == jalview.util.ImageMaker.TYPE.PNG)
-    {
-      im = new jalview.util.ImageMaker(this,
-              jalview.util.ImageMaker.TYPE.PNG, "Make PNG image from view",
-              width, height, null, null, null, 0, false);
-    }
-    else if (type == jalview.util.ImageMaker.TYPE.EPS)
-    {
-      im = new jalview.util.ImageMaker(this,
-              jalview.util.ImageMaker.TYPE.EPS, "Make EPS file from view",
-              width, height, null, this.getTitle(), null, 0, false);
-    }
-    else
-    {
-
-      im = new jalview.util.ImageMaker(this,
-              jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
-              width, height, null, this.getTitle(), null, 0, false);
-    }
-
-    if (im.getGraphics() != null)
-    {
-      pdbcanvas.drawAll(im.getGraphics(), width, height);
-      im.writeImage();
-    }
-  }
-
-  public void charge_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.bysequence = false;
-    pdbcanvas.pdb.setChargeColours();
-    pdbcanvas.redrawneeded = true;
-    pdbcanvas.repaint();
-  }
-
-  public void hydro_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.bysequence = false;
-    pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
-    pdbcanvas.redrawneeded = true;
-    pdbcanvas.repaint();
-  }
-
-  public void chain_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.bysequence = false;
-    pdbcanvas.pdb.setChainColours();
-    pdbcanvas.redrawneeded = true;
-    pdbcanvas.repaint();
-  }
-
-  public void zbuffer_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
-    pdbcanvas.redrawneeded = true;
-    pdbcanvas.repaint();
-  }
-
-  public void molecule_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
-    pdbcanvas.redrawneeded = true;
-    pdbcanvas.repaint();
-  }
-
-  public void depth_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.depthcue = !pdbcanvas.depthcue;
-    pdbcanvas.redrawneeded = true;
-    pdbcanvas.repaint();
-  }
-
-  public void wire_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.wire = !pdbcanvas.wire;
-    pdbcanvas.redrawneeded = true;
-    pdbcanvas.repaint();
-  }
-
-  public void seqButton_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.bysequence = true;
-    pdbcanvas.updateSeqColours();
-  }
-
-  public void mapping_actionPerformed(ActionEvent e)
-  {
-    jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
-    try
-    {
-      cap.setText(pdbcanvas.mappingDetails.toString());
-      Desktop.addInternalFrame(cap,
-              MessageManager.getString("label.pdb_sequence_mapping"), 550,
-              600);
-    } catch (OutOfMemoryError oom)
-    {
-      new OOMWarning("Opening sequence to structure mapping report", oom);
-      cap.dispose();
-    }
-  }
-
-  public void allchains_itemStateChanged(ItemEvent e)
-  {
-    pdbcanvas.setAllchainsVisible(allchains.getState());
-  }
-
-  public void zappo_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.bysequence = false;
-    pdbcanvas.pdb.setColours(new ZappoColourScheme());
-    pdbcanvas.redrawneeded = true;
-    pdbcanvas.repaint();
-  }
-
-  public void taylor_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.bysequence = false;
-    pdbcanvas.pdb.setColours(new TaylorColourScheme());
-    pdbcanvas.redrawneeded = true;
-    pdbcanvas.repaint();
-  }
-
-  public void helix_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.bysequence = false;
-    pdbcanvas.pdb.setColours(new HelixColourScheme());
-    pdbcanvas.redrawneeded = true;
-    pdbcanvas.repaint();
-  }
-
-  public void strand_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.bysequence = false;
-    pdbcanvas.pdb.setColours(new StrandColourScheme());
-    pdbcanvas.redrawneeded = true;
-    pdbcanvas.repaint();
-  }
-
-  public void turn_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.bysequence = false;
-    pdbcanvas.pdb.setColours(new TurnColourScheme());
-    pdbcanvas.redrawneeded = true;
-    pdbcanvas.repaint();
-  }
-
-  public void buried_actionPerformed(ActionEvent e)
-  {
-    pdbcanvas.bysequence = false;
-    pdbcanvas.pdb.setColours(new BuriedColourScheme());
-    pdbcanvas.redrawneeded = true;
-    pdbcanvas.repaint();
-  }
-
-  public void user_actionPerformed(ActionEvent e)
-  {
-    if (e.getActionCommand().equals(
-            MessageManager.getString("action.user_defined")))
-    {
-      // new UserDefinedColours(pdbcanvas, null);
-    }
-    else
-    {
-      UserColourScheme udc = (UserColourScheme) UserDefinedColours
-              .getUserColourSchemes().get(e.getActionCommand());
-
-      pdbcanvas.pdb.setColours(udc);
-      pdbcanvas.redrawneeded = true;
-      pdbcanvas.repaint();
-    }
-  }
-
-  public void background_actionPerformed(ActionEvent e)
-  {
-    java.awt.Color col = JColorChooser.showDialog(this,
-            MessageManager.getString("label.select_backgroud_colour"),
-            pdbcanvas.backgroundColour);
-
-    if (col != null)
-    {
-      pdbcanvas.backgroundColour = col;
-      pdbcanvas.redrawneeded = true;
-      pdbcanvas.repaint();
-    }
-  }
-
-  public void savePDB_actionPerformed(ActionEvent e)
-  {
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
-
-    chooser.setFileView(new JalviewFileView());
-    chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
-    chooser.setToolTipText(MessageManager.getString("action.save"));
-
-    int value = chooser.showSaveDialog(this);
-
-    if (value == JalviewFileChooser.APPROVE_OPTION)
-    {
-      try
-      {
-        BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
-        File outFile = chooser.getSelectedFile();
-
-        PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
-        String data;
-        while ((data = in.readLine()) != null)
-        {
-          if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
-          {
-            out.println(data);
-          }
-        }
-        out.close();
-        in.close();
-      } catch (Exception ex)
-      {
-        ex.printStackTrace();
-      }
-    }
-  }
-}
index 34fe221..ea96b3b 100644 (file)
@@ -60,6 +60,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.NoSuchElementException;
 import java.util.Set;
+import java.util.SortedMap;
 import java.util.TreeMap;
 
 /**
@@ -2840,7 +2841,7 @@ public class AlignmentUtils
    * @param unmapped
    * @return
    */
-  static Map<Integer, Map<SequenceI, Character>> buildMappedColumnsMap(
+  static SortedMap<Integer, Map<SequenceI, Character>> buildMappedColumnsMap(
           AlignmentI unaligned, AlignmentI aligned, List<SequenceI> unmapped)
   {
     /*
@@ -2848,7 +2849,7 @@ public class AlignmentUtils
      * {unalignedSequence, characterPerSequence} at that position.
      * TreeMap keeps the entries in ascending column order. 
      */
-    Map<Integer, Map<SequenceI, Character>> map = new TreeMap<Integer, Map<SequenceI, Character>>();
+    SortedMap<Integer, Map<SequenceI, Character>> map = new TreeMap<Integer, Map<SequenceI, Character>>();
 
     /*
      * record any sequences that have no mapping so can't be realigned
index 7b9da46..5e5f716 100755 (executable)
@@ -33,6 +33,7 @@ import java.awt.Color;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.Vector;
 
@@ -243,7 +244,7 @@ public class Conservation
        * or not conserved (-1)
        * Using TreeMap means properties are displayed in alphabetical order
        */
-      Map<String, Integer> resultHash = new TreeMap<String, Integer>();
+      SortedMap<String, Integer> resultHash = new TreeMap<String, Integer>();
       SymbolCounts symbolCounts = values.getSymbolCounts();
       char[] symbols = symbolCounts.symbols;
       int[] counts = symbolCounts.values;
index 209ca22..1f3d318 100644 (file)
@@ -42,10 +42,13 @@ import jalview.io.SequenceAnnotationReport;
 import jalview.schemes.Blosum62ColourScheme;
 import jalview.schemes.BuriedColourScheme;
 import jalview.schemes.ClustalxColourScheme;
+import jalview.schemes.ColourSchemeI;
 import jalview.schemes.HelixColourScheme;
 import jalview.schemes.HydrophobicColourScheme;
+import jalview.schemes.JalviewColourScheme;
 import jalview.schemes.NucleotideColourScheme;
 import jalview.schemes.PIDColourScheme;
+import jalview.schemes.PurinePyrimidineColourScheme;
 import jalview.schemes.StrandColourScheme;
 import jalview.schemes.TaylorColourScheme;
 import jalview.schemes.TurnColourScheme;
@@ -67,6 +70,7 @@ import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.Vector;
 
@@ -77,46 +81,50 @@ public class APopupMenu extends java.awt.PopupMenu implements
 
   MenuItem editGroupName = new MenuItem();
 
-  protected MenuItem clustalColour = new MenuItem();
+  CheckboxMenuItem noColour = new CheckboxMenuItem();
 
-  protected MenuItem zappoColour = new MenuItem();
+  protected CheckboxMenuItem clustalColour = new CheckboxMenuItem();
 
-  protected MenuItem taylorColour = new MenuItem();
+  protected CheckboxMenuItem zappoColour = new CheckboxMenuItem();
 
-  protected MenuItem hydrophobicityColour = new MenuItem();
+  protected CheckboxMenuItem taylorColour = new CheckboxMenuItem();
 
-  protected MenuItem helixColour = new MenuItem();
+  protected CheckboxMenuItem hydrophobicityColour = new CheckboxMenuItem();
 
-  protected MenuItem strandColour = new MenuItem();
+  protected CheckboxMenuItem helixColour = new CheckboxMenuItem();
 
-  protected MenuItem turnColour = new MenuItem();
+  protected CheckboxMenuItem strandColour = new CheckboxMenuItem();
 
-  protected MenuItem buriedColour = new MenuItem();
+  protected CheckboxMenuItem turnColour = new CheckboxMenuItem();
 
-  protected MenuItem userDefinedColour = new MenuItem();
+  protected CheckboxMenuItem buriedColour = new CheckboxMenuItem();
 
-  protected MenuItem PIDColour = new MenuItem();
+  protected CheckboxMenuItem PIDColour = new CheckboxMenuItem();
 
-  protected MenuItem BLOSUM62Colour = new MenuItem();
+  protected CheckboxMenuItem BLOSUM62Colour = new CheckboxMenuItem();
 
-  MenuItem noColourmenuItem = new MenuItem();
+  CheckboxMenuItem nucleotideColour = new CheckboxMenuItem();
+
+  CheckboxMenuItem purinePyrimidineColour = new CheckboxMenuItem();
+
+  protected MenuItem userDefinedColour = new MenuItem();
 
   protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
 
   MenuItem modifyPID = new MenuItem();
 
-  protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
+  protected CheckboxMenuItem conservationColour = new CheckboxMenuItem();
 
   MenuItem modifyConservation = new MenuItem();
 
+  MenuItem noColourmenuItem = new MenuItem();
+
   final AlignmentPanel ap;
 
   MenuItem unGroupMenuItem = new MenuItem();
 
   MenuItem createGroupMenuItem = new MenuItem();
 
-  MenuItem nucleotideMenuItem = new MenuItem();
-
   Menu colourMenu = new Menu();
 
   CheckboxMenuItem showBoxes = new CheckboxMenuItem();
@@ -252,11 +260,12 @@ public class APopupMenu extends java.awt.PopupMenu implements
         if (sg.cs != null)
         {
           abovePIDColour.setState(sg.cs.getThreshold() > 0);
+          conservationColour.setState(sg.cs.conservationApplied());
           modifyPID.setEnabled(abovePIDColour.getState());
-          conservationMenuItem.setState(sg.cs.conservationApplied());
-          modifyConservation.setEnabled(conservationMenuItem.getState());
+          modifyConservation.setEnabled(conservationColour.getState());
         }
       }
+      setSelectedColour(sg.cs);
     }
     else
     {
@@ -314,6 +323,35 @@ public class APopupMenu extends java.awt.PopupMenu implements
   }
 
   /**
+   * Select the menu item (if any) matching the current colour scheme. This
+   * works by matching the menu item name (not display text) to the canonical
+   * name of the colour scheme.
+   * 
+   * @param cs
+   */
+  protected void setSelectedColour(ColourSchemeI cs)
+  {
+    if (cs == null)
+    {
+      noColour.setState(true);
+    }
+    else
+    {
+      for (int i = 0; i < colourMenu.getItemCount(); i++)
+      {
+        MenuItem item = colourMenu.getItem(i);
+        if (item instanceof CheckboxMenuItem)
+        {
+          if (cs.getSchemeName().equals(item.getName()))
+          {
+            ((CheckboxMenuItem) item).setState(true);
+          }
+        }
+      }
+    }
+  }
+
+  /**
    * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
    * 
    * @param seq
@@ -423,7 +461,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
      * Temporary store to hold distinct calcId / type pairs for the tooltip.
      * Using TreeMap means calcIds are shown in alphabetical order.
      */
-    Map<String, String> tipEntries = new TreeMap<String, String>();
+    SortedMap<String, String> tipEntries = new TreeMap<String, String>();
     final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
     AlignmentI al = this.ap.av.getAlignment();
     AlignmentUtils.findAddableReferenceAnnotations(forSequences,
@@ -508,43 +546,28 @@ public class APopupMenu extends java.awt.PopupMenu implements
     linkMenu.add(item);
   }
 
+  /**
+   * Actions on selecting / unselecting a checkbox menu item
+   */
   @Override
   public void itemStateChanged(ItemEvent evt)
   {
     Object source = evt.getSource();
-    if (source == abovePIDColour)
-    {
-      abovePIDColour_itemStateChanged();
-    }
-    else if (source == conservationMenuItem)
-    {
-      conservationMenuItem_itemStateChanged();
-    }
-    else if (source == showColourText)
-    {
-      showColourText_itemStateChanged();
-    }
-    else if (source == showText)
+    if (source == noColour)
     {
-      showText_itemStateChanged();
+      noColourmenuItem_actionPerformed();
     }
-    else if (source == showBoxes)
+    else if (source == clustalColour)
     {
-      showBoxes_itemStateChanged();
+      clustalColour_actionPerformed();
     }
-    else if (source == displayNonconserved)
+    else if (source == BLOSUM62Colour)
     {
-      this.showNonconserved_itemStateChanged();
+      BLOSUM62Colour_actionPerformed();
     }
-  }
-
-  @Override
-  public void actionPerformed(ActionEvent evt)
-  {
-    Object source = evt.getSource();
-    if (source == clustalColour)
+    else if (source == PIDColour)
     {
-      clustalColour_actionPerformed();
+      PIDColour_actionPerformed();
     }
     else if (source == zappoColour)
     {
@@ -574,26 +597,50 @@ public class APopupMenu extends java.awt.PopupMenu implements
     {
       buriedColour_actionPerformed();
     }
-    else if (source == nucleotideMenuItem)
+    else if (source == nucleotideColour)
     {
       nucleotideMenuItem_actionPerformed();
     }
-
-    else if (source == userDefinedColour)
+    else if (source == purinePyrimidineColour)
     {
-      userDefinedColour_actionPerformed();
+      purinePyrimidineColour_actionPerformed();
     }
-    else if (source == PIDColour)
+    else if (source == abovePIDColour)
     {
-      PIDColour_actionPerformed();
+      abovePIDColour_itemStateChanged();
     }
-    else if (source == BLOSUM62Colour)
+    else if (source == conservationColour)
     {
-      BLOSUM62Colour_actionPerformed();
+      conservationMenuItem_itemStateChanged();
     }
-    else if (source == noColourmenuItem)
+    else if (source == showColourText)
     {
-      noColourmenuItem_actionPerformed();
+      showColourText_itemStateChanged();
+    }
+    else if (source == showText)
+    {
+      showText_itemStateChanged();
+    }
+    else if (source == showBoxes)
+    {
+      showBoxes_itemStateChanged();
+    }
+    else if (source == displayNonconserved)
+    {
+      this.showNonconserved_itemStateChanged();
+    }
+  }
+
+  /**
+   * Actions on clicking a menu item
+   */
+  @Override
+  public void actionPerformed(ActionEvent evt)
+  {
+    Object source = evt.getSource();
+    if (source == userDefinedColour)
+    {
+      userDefinedColour_actionPerformed();
     }
     else if (source == modifyConservation)
     {
@@ -868,14 +915,14 @@ public class APopupMenu extends java.awt.PopupMenu implements
   void addPDB()
   {
     Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
-    if (pdbs != null&& !pdbs.isEmpty())
+    if (pdbs != null && !pdbs.isEmpty())
     {
       PDBEntry entry = pdbs.firstElement();
 
       if (ap.av.applet.jmolAvailable)
       {
-        new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
-                null, ap, DataSourceType.URL);
+        new AppletJmol(entry, new SequenceI[] { seq }, null, ap,
+                DataSourceType.URL);
       }
       else
       {
@@ -891,7 +938,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
       cap.setPDBImport(seq);
       Frame frame = new Frame();
       frame.add(cap);
-      jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
+      JalviewLite.addFrame(frame, MessageManager.formatMessage(
               "label.paste_pdb_file_for_sequence",
               new Object[] { seq.getName() }), 400, 300);
     }
@@ -911,19 +958,6 @@ public class APopupMenu extends java.awt.PopupMenu implements
             .getString("action.create_group"));
     createGroupMenuItem.addActionListener(this);
 
-    nucleotideMenuItem.setLabel(MessageManager
-            .getString("label.nucleotide"));
-    nucleotideMenuItem.addActionListener(this);
-    conservationMenuItem.addItemListener(this);
-    abovePIDColour.addItemListener(this);
-    modifyPID.setLabel(MessageManager
-            .getString("label.modify_identity_threshold"));
-    modifyPID.addActionListener(this);
-    modifyConservation.setLabel(MessageManager
-            .getString("label.modify_conservation_threshold"));
-    modifyPID.setEnabled(abovePIDColour.getState());
-    modifyConservation.setEnabled(conservationMenuItem.getState());
-    modifyConservation.addActionListener(this);
     colourMenu.setLabel(MessageManager.getString("label.group_colour"));
     showBoxes.setLabel(MessageManager.getString("action.boxes"));
     showBoxes.setState(true);
@@ -932,7 +966,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
     sequenceDetails.addActionListener(this);
     selSeqDetails.addActionListener(this);
     displayNonconserved.setLabel(MessageManager
-            .getString("label.show_non_conversed"));
+            .getString("label.show_non_conserved"));
     displayNonconserved.setState(false);
     displayNonconserved.addItemListener(this);
     showText.setLabel(MessageManager.getString("action.text"));
@@ -964,7 +998,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
     groupMenu.add(unGroupMenuItem);
     groupMenu.add(menu1);
 
-    colourMenu.add(noColourmenuItem);
+    colourMenu.add(noColour);
     colourMenu.add(clustalColour);
     colourMenu.add(BLOSUM62Colour);
     colourMenu.add(PIDColour);
@@ -975,50 +1009,88 @@ public class APopupMenu extends java.awt.PopupMenu implements
     colourMenu.add(strandColour);
     colourMenu.add(turnColour);
     colourMenu.add(buriedColour);
-    colourMenu.add(nucleotideMenuItem);
+    colourMenu.add(nucleotideColour);
+    colourMenu.add(purinePyrimidineColour);
     colourMenu.add(userDefinedColour);
     colourMenu.addSeparator();
+    colourMenu.add(conservationColour);
+    colourMenu.add(modifyConservation);
     colourMenu.add(abovePIDColour);
     colourMenu.add(modifyPID);
-    colourMenu.add(conservationMenuItem);
-    colourMenu.add(modifyConservation);
 
-    noColourmenuItem.setLabel(MessageManager.getString("label.none"));
-    noColourmenuItem.addActionListener(this);
+    noColour.setLabel(MessageManager.getString("label.none"));
+    noColour.addItemListener(this);
 
+    /*
+     * setName allows setSelectedColour to do its thing
+     */
     clustalColour.setLabel(MessageManager
-            .getString("label.clustalx_colours"));
-    clustalColour.addActionListener(this);
-    zappoColour.setLabel(MessageManager.getString("label.zappo"));
-    zappoColour.addActionListener(this);
-    taylorColour.setLabel(MessageManager.getString("label.taylor"));
-    taylorColour.addActionListener(this);
+            .getString("label.colourScheme_clustal"));
+    clustalColour.setName(JalviewColourScheme.Clustal.toString());
+    clustalColour.addItemListener(this);
+    BLOSUM62Colour.setLabel(MessageManager
+            .getString("label.colourScheme_blosum62"));
+    BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
+    BLOSUM62Colour.addItemListener(this);
+    PIDColour.setLabel(MessageManager
+            .getString("label.colourScheme_%_identity"));
+    PIDColour.setName(JalviewColourScheme.PID.toString());
+    PIDColour.addItemListener(this);
+    zappoColour.setLabel(MessageManager
+            .getString("label.colourScheme_zappo"));
+    zappoColour.setName(JalviewColourScheme.Zappo.toString());
+    zappoColour.addItemListener(this);
+    taylorColour.setLabel(MessageManager
+            .getString("label.colourScheme_taylor"));
+    taylorColour.setName(JalviewColourScheme.Taylor.toString());
+    taylorColour.addItemListener(this);
     hydrophobicityColour.setLabel(MessageManager
-            .getString("label.hydrophobicity"));
-    hydrophobicityColour.addActionListener(this);
-    helixColour
-            .setLabel(MessageManager.getString("label.helix_propensity"));
-    helixColour.addActionListener(this);
+            .getString("label.colourScheme_hydrophobic"));
+    hydrophobicityColour
+            .setName(JalviewColourScheme.Hydrophobic.toString());
+    hydrophobicityColour.addItemListener(this);
+    helixColour.setLabel(MessageManager
+            .getString("label.colourScheme_helix_propensity"));
+    helixColour.setName(JalviewColourScheme.Helix.toString());
+    helixColour.addItemListener(this);
     strandColour.setLabel(MessageManager
-            .getString("label.strand_propensity"));
-    strandColour.addActionListener(this);
-    turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
-    turnColour.addActionListener(this);
-    buriedColour.setLabel(MessageManager.getString("label.buried_index"));
-    buriedColour.addActionListener(this);
-    abovePIDColour.setLabel(MessageManager
-            .getString("label.above_identity_percentage"));
+            .getString("label.colourScheme_strand_propensity"));
+    strandColour.setName(JalviewColourScheme.Strand.toString());
+    strandColour.addItemListener(this);
+    turnColour.setLabel(MessageManager
+            .getString("label.colourScheme_turn_propensity"));
+    turnColour.setName(JalviewColourScheme.Turn.toString());
+    turnColour.addItemListener(this);
+    buriedColour.setLabel(MessageManager
+            .getString("label.colourScheme_buried_index"));
+    buriedColour.setName(JalviewColourScheme.Buried.toString());
+    buriedColour.addItemListener(this);
+    nucleotideColour.setLabel(MessageManager
+            .getString("label.colourScheme_nucleotide"));
+    nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
+    nucleotideColour.addItemListener(this);
+    purinePyrimidineColour.setLabel(MessageManager
+            .getString("label.colourScheme_purine/pyrimidine"));
+    purinePyrimidineColour.setName(JalviewColourScheme.PurinePyrimidine
+            .toString());
+    purinePyrimidineColour.addItemListener(this);
 
     userDefinedColour.setLabel(MessageManager
             .getString("action.user_defined"));
     userDefinedColour.addActionListener(this);
-    PIDColour.setLabel(MessageManager
-            .getString("label.percentage_identity"));
-    PIDColour.addActionListener(this);
-    BLOSUM62Colour.setLabel("BLOSUM62");
-    BLOSUM62Colour.addActionListener(this);
-    conservationMenuItem.setLabel(MessageManager
-            .getString("label.conservation"));
+
+    abovePIDColour.setLabel(MessageManager
+            .getString("label.above_identity_threshold"));
+    abovePIDColour.addItemListener(this);
+    modifyPID.setLabel(MessageManager
+            .getString("label.modify_identity_threshold"));
+    modifyPID.addActionListener(this);
+    conservationColour.setLabel(MessageManager
+            .getString("action.by_conservation"));
+    conservationColour.addItemListener(this);
+    modifyConservation.setLabel(MessageManager
+            .getString("label.modify_conservation_threshold"));
+    modifyConservation.addActionListener(this);
 
     editMenu.add(copy);
     copy.addActionListener(this);
@@ -1120,6 +1192,12 @@ public class APopupMenu extends java.awt.PopupMenu implements
     refresh();
   }
 
+  public void purinePyrimidineColour_actionPerformed()
+  {
+    getGroup().cs = new PurinePyrimidineColourScheme();
+    refresh();
+  }
+
   protected void abovePIDColour_itemStateChanged()
   {
     SequenceGroup sg = getGroup();
@@ -1190,7 +1268,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
       return;
     }
 
-    if (conservationMenuItem.getState())
+    if (conservationColour.getState())
     {
       sg.cs.setConservation(Conservation.calculateConservation("Group", sg
               .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
@@ -1205,7 +1283,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
       SliderPanel.hideConservationSlider();
       sg.cs.setConservation(null);
     }
-    modifyConservation.setEnabled(conservationMenuItem.getState());
+    modifyConservation.setEnabled(conservationColour.getState());
     refresh();
   }
 
index 2287979..cfd3d00 100644 (file)
@@ -64,6 +64,7 @@ import jalview.schemes.HydrophobicColourScheme;
 import jalview.schemes.NucleotideColourScheme;
 import jalview.schemes.PIDColourScheme;
 import jalview.schemes.PurinePyrimidineColourScheme;
+import jalview.schemes.RNAHelicesColour;
 import jalview.schemes.RNAHelicesColourChooser;
 import jalview.schemes.StrandColourScheme;
 import jalview.schemes.TCoffeeColourScheme;
@@ -298,6 +299,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
       RNAHelixColour.setEnabled(false);
       purinePyrimidineColour.setEnabled(false);
+      nucleotideColour.setEnabled(false);
     }
     // Some JVMS send keyevents to Top frame or lowest panel,
     // Havent worked out why yet. So add to both this frame and seqCanvas for
@@ -1257,7 +1259,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     // }
     else if (source == RNAHelixColour)
     {
-      new RNAHelicesColourChooser(viewport, alignPanel);
+      changeColour(new RNAHelicesColour(viewport.getAlignment()));
+      // new RNAHelicesColourChooser(viewport, alignPanel);
     }
     else if (source == modifyPID)
     {
@@ -3459,7 +3462,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
             .getString("label.colour_text"));
     colourTextMenuItem.addItemListener(this);
     displayNonconservedMenuItem.setLabel(MessageManager
-            .getString("label.show_non_conversed"));
+            .getString("label.show_non_conserved"));
     displayNonconservedMenuItem.addItemListener(this);
     wrapMenuItem.setLabel(MessageManager.getString("action.wrap"));
     wrapMenuItem.addItemListener(this);
@@ -3482,45 +3485,50 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
             .getString("label.apply_colour_to_all_groups"));
     applyToAllGroups.setState(true);
     applyToAllGroups.addItemListener(this);
-    clustalColour.setLabel(MessageManager.getString("label.clustalx"));
+    clustalColour.setLabel(MessageManager
+            .getString("label.colourScheme_clustal"));
     clustalColour.addActionListener(this);
-    zappoColour.setLabel(MessageManager.getString("label.zappo"));
+    zappoColour.setLabel(MessageManager
+            .getString("label.colourScheme_zappo"));
     zappoColour.addActionListener(this);
-    taylorColour.setLabel(MessageManager.getString("label.taylor"));
+    taylorColour.setLabel(MessageManager
+            .getString("label.colourScheme_taylor"));
     taylorColour.addActionListener(this);
     hydrophobicityColour.setLabel(MessageManager
-            .getString("label.hydrophobicity"));
+            .getString("label.colourScheme_hydrophobic"));
     hydrophobicityColour.addActionListener(this);
-    helixColour
-            .setLabel(MessageManager.getString("label.helix_propensity"));
+    helixColour.setLabel(MessageManager
+            .getString("label.colourScheme_helix_propensity"));
     helixColour.addActionListener(this);
     strandColour.setLabel(MessageManager
-            .getString("label.strand_propensity"));
+            .getString("label.colourScheme_strand_propensity"));
     strandColour.addActionListener(this);
-    turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
+    turnColour.setLabel(MessageManager
+            .getString("label.colourScheme_turn_propensity"));
     turnColour.addActionListener(this);
-    buriedColour.setLabel(MessageManager.getString("label.buried_index"));
+    buriedColour.setLabel(MessageManager
+            .getString("label.colourScheme_buried_index"));
     buriedColour.addActionListener(this);
     purinePyrimidineColour.setLabel(MessageManager
-            .getString("label.purine_pyrimidine"));
+            .getString("label.colourScheme_purine/pyrimidine"));
     purinePyrimidineColour.addActionListener(this);
     // RNAInteractionColour.setLabel(MessageManager
     // .getString("label.rna_interaction"));
     // RNAInteractionColour.addActionListener(this);
     RNAHelixColour.setLabel(MessageManager
-            .getString("action.by_rna_helixes"));
+            .getString("label.colourScheme_rna_helices"));
     RNAHelixColour.addActionListener(this);
     userDefinedColour.setLabel(MessageManager
             .getString("action.user_defined"));
     userDefinedColour.addActionListener(this);
     PIDColour.setLabel(MessageManager
-            .getString("label.percentage_identity"));
+            .getString("label.colourScheme_%_identity"));
     PIDColour.addActionListener(this);
     BLOSUM62Colour.setLabel(MessageManager
-            .getString("label.blosum62_score"));
+            .getString("label.colourScheme_blosum62"));
     BLOSUM62Colour.addActionListener(this);
-    tcoffeeColour
-            .setLabel(MessageManager.getString("label.tcoffee_scores"));
+    tcoffeeColour.setLabel(MessageManager
+            .getString("label.colourScheme_t-coffee_scores"));
     // it will be enabled only if a score file is provided
     tcoffeeColour.setEnabled(false);
     tcoffeeColour.addActionListener(this);
@@ -3532,7 +3540,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     abovePIDThreshold.setLabel(MessageManager
             .getString("label.above_identity_threshold"));
     abovePIDThreshold.addItemListener(this);
-    nucleotideColour.setLabel(MessageManager.getString("label.nucleotide"));
+    nucleotideColour.setLabel(MessageManager
+            .getString("label.colourScheme_nucleotide"));
     nucleotideColour.addActionListener(this);
     modifyPID.setLabel(MessageManager
             .getString("label.modify_identity_threshold"));
@@ -3574,7 +3583,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
             .getString("label.neighbour_joining_identity"));
     neighbourTreeMenuItem.addActionListener(this);
     avDistanceTreeBlosumMenuItem.setLabel(MessageManager
-            .getString("label.average_distance_bloslum62"));
+            .getString("label.average_distance_blosum62"));
     avDistanceTreeBlosumMenuItem.addActionListener(this);
     njTreeBlosumMenuItem.setLabel(MessageManager
             .getString("label.neighbour_blosum62"));
index 4bd77b6..9e82ae5 100644 (file)
@@ -208,8 +208,8 @@ public class AlignViewport extends AlignmentViewport implements
 
       if (colour != null)
       {
-        globalColourScheme = ColourSchemeProperty.getColour(alignment,
-                colour);
+        globalColourScheme = ColourSchemeProperty.getColourScheme(
+                alignment, colour);
         if (globalColourScheme != null)
         {
           globalColourScheme.setConsensus(hconsensus);
@@ -218,8 +218,8 @@ public class AlignViewport extends AlignmentViewport implements
 
       if (applet.getParameter("userDefinedColour") != null)
       {
-        ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
-                .getParameter("userDefinedColour"));
+        globalColourScheme = new UserColourScheme(
+                applet.getParameter("userDefinedColour"));
       }
     }
     initAutoAnnotation();
index 9d4779c..c0b4ff0 100644 (file)
@@ -24,8 +24,8 @@ import jalview.bin.JalviewLite;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
-import jalview.io.FileParse;
 import jalview.io.DataSourceType;
+import jalview.io.FileParse;
 import jalview.io.StructureFile;
 import jalview.schemes.BuriedColourScheme;
 import jalview.schemes.HelixColourScheme;
@@ -93,27 +93,29 @@ public class AppletJmol extends EmbmenuFrame implements
   MenuItem charge = new MenuItem(
           MessageManager.getString("label.charge_cysteine"));
 
-  MenuItem zappo = new MenuItem(MessageManager.getString("label.zappo"));
+  MenuItem zappo = new MenuItem(
+          MessageManager.getString("label.colourScheme_zappo"));
 
-  MenuItem taylor = new MenuItem(MessageManager.getString("label.taylor"));
+  MenuItem taylor = new MenuItem(
+          MessageManager.getString("label.colourScheme_taylor"));
 
   MenuItem hydro = new MenuItem(
-          MessageManager.getString("label.hydrophobicity"));
+          MessageManager.getString("label.colourScheme_hydrophobic"));
 
   MenuItem helix = new MenuItem(
-          MessageManager.getString("label.helix_propensity"));
+          MessageManager.getString("label.colourScheme_helix_propensity"));
 
   MenuItem strand = new MenuItem(
-          MessageManager.getString("label.strand_propensity"));
+          MessageManager.getString("label.colourScheme_strand_propensity"));
 
   MenuItem turn = new MenuItem(
-          MessageManager.getString("label.turn_propensity"));
+          MessageManager.getString("label.colourScheme_turn_propensity"));
 
   MenuItem buried = new MenuItem(
-          MessageManager.getString("label.buried_index"));
+          MessageManager.getString("label.colourScheme_buried_index"));
 
   MenuItem purinepyrimidine = new MenuItem(
-          MessageManager.getString("label.purine_pyrimidine"));
+          MessageManager.getString("label.colourScheme_purine/pyrimidine"));
 
   MenuItem user = new MenuItem(
           MessageManager.getString("label.user_defined_colours"));
@@ -584,7 +586,7 @@ public class AppletJmol extends EmbmenuFrame implements
 
   public void updateTitleAndMenus()
   {
-    if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
+    if (jmb.hasFileLoadingError())
     {
       repaint();
       return;
index 2fca07d..67ca8e9 100644 (file)
@@ -27,7 +27,7 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.io.FeaturesFile;
 import jalview.schemes.FeatureColour;
-import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 
@@ -236,7 +236,7 @@ public class FeatureRenderer extends
           FeatureColourI col = getFeatureStyle(name.getText());
           if (col == null)
           {
-            Color generatedColour = UserColourScheme
+            Color generatedColour = ColorUtils
                     .createColourFromName(name.getText());
             col = new FeatureColour(generatedColour);
           }
index 5ee665a..5179eb0 100644 (file)
@@ -125,7 +125,7 @@ public class SliderPanel extends Panel implements ActionListener,
     SliderPanel pid = null;
     if (PIDSlider == null)
     {
-      pid = new SliderPanel(ap, 50, false, cs);
+      pid = new SliderPanel(ap, cs.getThreshold(), false, cs);
       PIDSlider = new Frame();
       PIDSlider.add(pid);
     }
@@ -178,15 +178,27 @@ public class SliderPanel extends Panel implements ActionListener,
 
   }
 
+  /**
+   * Hides the PID slider panel if it is shown
+   */
   public static void hidePIDSlider()
   {
-    PIDSlider.setVisible(false);
+    if (PIDSlider != null)
+    {
+      PIDSlider.setVisible(false);
+    }
     PIDSlider = null;
   }
 
+  /**
+   * Hides the Conservation slider panel if it is shown
+   */
   public static void hideConservationSlider()
   {
-    conservationSlider.setVisible(false);
+    if (conservationSlider != null)
+    {
+      conservationSlider.setVisible(false);
+    }
     conservationSlider = null;
   }
   public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
index 8292a5a..ca9f2d8 100755 (executable)
@@ -656,8 +656,9 @@ public class TreeCanvas extends Panel implements MouseListener,
         }
         else
         {
-          cs = ColourSchemeProperty.getColour(sg, ColourSchemeProperty
-                  .getColourName(av.getGlobalColourScheme()));
+          cs = ColourSchemeProperty.getColourScheme(sg,
+                  ColourSchemeProperty.getColourName(av
+                          .getGlobalColourScheme()));
         }
         // cs is null if shading is an annotationColourGradient
         if (cs != null)
index 8412dab..9363c23 100755 (executable)
 package jalview.bin;
 
 import jalview.datamodel.PDBEntry;
+import jalview.gui.UserDefinedColours;
+import jalview.schemes.ColourSchemes;
+import jalview.schemes.UserColourScheme;
 import jalview.structure.StructureImportSettings;
+import jalview.util.ColorUtils;
 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
 import jalview.ws.dbsources.das.datamodel.DasSourceRegistry;
 import jalview.ws.sifts.SiftsSettings;
@@ -40,6 +44,7 @@ import java.util.Date;
 import java.util.Enumeration;
 import java.util.Locale;
 import java.util.Properties;
+import java.util.StringTokenizer;
 import java.util.TreeSet;
 
 import org.apache.log4j.ConsoleAppender;
@@ -526,7 +531,7 @@ public class Cache
     setProperty("VERSION", codeVersion);
 
     // LOAD USERDEFINED COLOURS
-    jalview.gui.UserDefinedColours
+    jalview.bin.Cache
             .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
     jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
             false);
@@ -868,19 +873,11 @@ public class Cache
     {
       return defcolour;
     }
-    Color col = jalview.schemes.ColourSchemeProperty
-            .getAWTColorFromName(colprop);
+    Color col = ColorUtils.parseColourString(colprop);
     if (col == null)
     {
-      try
-      {
-        col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
-      } catch (Exception ex)
-      {
-        log.warn("Couldn't parse '" + colprop + "' as a colour for "
-                + property);
-        col = null;
-      }
+      log.warn("Couldn't parse '" + colprop + "' as a colour for "
+              + property);
     }
     return (col == null) ? defcolour : col;
   }
@@ -997,4 +994,54 @@ public class Cache
       Cache.applicationProperties.setProperty(propName, value);
     }
   }
+
+  /**
+   * Loads in user colour schemes from files.
+   * 
+   * @param files
+   *          a '|'-delimited list of file paths
+   */
+  public static void initUserColourSchemes(String files)
+  {
+    if (files == null || files.length() == 0)
+    {
+      return;
+    }
+  
+    // In case colours can't be loaded, we'll remove them
+    // from the default list here.
+    StringBuffer coloursFound = new StringBuffer();
+    StringTokenizer st = new StringTokenizer(files, "|");
+    while (st.hasMoreElements())
+    {
+      String file = st.nextToken();
+      try
+      {
+        UserColourScheme ucs = ColourSchemes.loadColourScheme(file);
+        if (ucs != null)
+        {
+          if (coloursFound.length() > 0)
+          {
+            coloursFound.append("|");
+          }
+          coloursFound.append(file);
+          ColourSchemes.getInstance().registerColourScheme(ucs);
+        }
+      } catch (Exception ex)
+      {
+        System.out.println("Error loading User ColourFile\n" + ex);
+      }
+    }
+    if (!files.equals(coloursFound.toString()))
+    {
+      if (coloursFound.toString().length() > 1)
+      {
+        setProperty(UserDefinedColours.USER_DEFINED_COLOURS, coloursFound.toString());
+      }
+      else
+      {
+        applicationProperties.remove(UserDefinedColours.USER_DEFINED_COLOURS);
+      }
+    }
+  }
 }
index 39c0a5b..966e952 100755 (executable)
@@ -40,7 +40,6 @@ import jalview.io.NewickFile;
 import jalview.io.gff.SequenceOntologyFactory;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.UserColourScheme;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.jws2.Jws2Discoverer;
@@ -511,16 +510,10 @@ public class Jalview
         {
           data.replaceAll("%20", " ");
 
-          ColourSchemeI cs = ColourSchemeProperty.getColour(af
+          ColourSchemeI cs = ColourSchemeProperty.getColourScheme(af
                   .getViewport().getAlignment(), data);
 
-          if (cs == null)
-          {
-            UserColourScheme ucs = new UserColourScheme("white");
-            ucs.parseAppletParameter(data);
-            cs = ucs;
-          }
-          else
+          if (cs != null)
           {
             System.out.println("CMD [-color " + data
                     + "] executed successfully!");
index d7b064a..7fa5147 100644 (file)
@@ -51,6 +51,7 @@ import jalview.javascript.JsCallBack;
 import jalview.javascript.MouseOverStructureListener;
 import jalview.structure.SelectionListener;
 import jalview.structure.StructureSelectionManager;
+import jalview.util.ColorUtils;
 import jalview.util.HttpUtils;
 import jalview.util.MessageManager;
 
@@ -2888,22 +2889,13 @@ public class JalviewLite extends Applet implements
     {
       return defcolour;
     }
-    Color col = jalview.schemes.ColourSchemeProperty
-            .getAWTColorFromName(colprop);
+    Color col = ColorUtils.parseColourString(colprop);
     if (col == null)
     {
-      try
-      {
-        col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
-      } catch (Exception ex)
-      {
-        System.err.println("Couldn't parse '" + colprop
-                + "' as a colour for " + colparam);
-        col = null;
-      }
+      System.err.println("Couldn't parse '" + colprop
+              + "' as a colour for " + colparam);
     }
     return (col == null) ? defcolour : col;
-
   }
 
   public void openJalviewHelpUrl()
index 90bdcae..a6f2bf4 100755 (executable)
@@ -54,11 +54,7 @@ public class Alignment implements AlignmentI
 
   protected char gapCharacter = '-';
 
-  protected int type = NUCLEOTIDE;
-
-  public static final int PROTEIN = 0;
-
-  public static final int NUCLEOTIDE = 1;
+  private boolean nucleotide = true;
 
   public boolean hasRNAStructure = false;
 
@@ -76,14 +72,7 @@ public class Alignment implements AlignmentI
     hiddenSequences = new HiddenSequences(this);
     codonFrameList = new ArrayList<AlignedCodonFrame>();
 
-    if (Comparison.isNucleotide(seqs))
-    {
-      type = NUCLEOTIDE;
-    }
-    else
-    {
-      type = PROTEIN;
-    }
+    nucleotide = Comparison.isNucleotide(seqs);
 
     sequences = Collections.synchronizedList(new ArrayList<SequenceI>());
 
@@ -218,7 +207,9 @@ public class Alignment implements AlignmentI
   }
 
   /**
-   * Adds a sequence to the alignment. Recalculates maxLength and size.
+   * Adds a sequence to the alignment. Recalculates maxLength and size. Note
+   * this currently does not recalculate whether or not the alignment is
+   * nucleotide, so mixed alignments may have undefined behaviour.
    * 
    * @param snew
    */
@@ -978,29 +969,9 @@ public class Alignment implements AlignmentI
   }
 
   @Override
-  public void setNucleotide(boolean b)
-  {
-    if (b)
-    {
-      type = NUCLEOTIDE;
-    }
-    else
-    {
-      type = PROTEIN;
-    }
-  }
-
-  @Override
   public boolean isNucleotide()
   {
-    if (type == NUCLEOTIDE)
-    {
-      return true;
-    }
-    else
-    {
-      return false;
-    }
+    return nucleotide;
   }
 
   @Override
@@ -1591,7 +1562,6 @@ public class Alignment implements AlignmentI
           String calcId, boolean autoCalc, SequenceI seqRef,
           SequenceGroup groupRef)
   {
-    assert (name != null);
     if (annotations != null)
     {
       for (AlignmentAnnotation annot : getAlignmentAnnotation())
@@ -1623,14 +1593,18 @@ public class Alignment implements AlignmentI
   @Override
   public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
   {
-    ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
-    for (AlignmentAnnotation a : getAlignmentAnnotation())
+    List<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+    AlignmentAnnotation[] alignmentAnnotation = getAlignmentAnnotation();
+    if (alignmentAnnotation != null)
     {
-      if (a.getCalcId() == calcId
-              || (a.getCalcId() != null && calcId != null && a.getCalcId()
-                      .equals(calcId)))
+      for (AlignmentAnnotation a : alignmentAnnotation)
       {
-        aa.add(a);
+        if (a.getCalcId() == calcId
+                || (a.getCalcId() != null && calcId != null && a
+                        .getCalcId().equals(calcId)))
+        {
+          aa.add(a);
+        }
       }
     }
     return aa;
index 2df099a..a0b3ff1 100755 (executable)
@@ -299,12 +299,6 @@ public interface AlignmentI extends AnnotatedCollectionI
   boolean hasRNAStructure();
 
   /**
-   * Set alignment to be a nucleotide sequence
-   * 
-   */
-  void setNucleotide(boolean b);
-
-  /**
    * Get the associated dataset for the alignment.
    * 
    * @return Alignment containing dataset sequences or null of this is a
index 74568e4..3f6c515 100644 (file)
@@ -31,6 +31,13 @@ public interface AnnotatedCollectionI extends SequenceCollectionI
    */
   AlignmentAnnotation[] getAlignmentAnnotation();
 
+  /**
+   * Returns a list of annotations matching the given calc id, or an empty list
+   * if calcId is null
+   * 
+   * @param calcId
+   * @return
+   */
   Iterable<AlignmentAnnotation> findAnnotation(String calcId);
 
   Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
index 9245761..da47a89 100755 (executable)
@@ -1269,10 +1269,14 @@ public class SequenceGroup implements AnnotatedCollectionI
   @Override
   public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
   {
-    ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+    List<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+    if (calcId == null)
+    {
+      return aa;
+    }
     for (AlignmentAnnotation a : getAlignmentAnnotation())
     {
-      if (a.getCalcId() == calcId)
+      if (calcId.equals(a.getCalcId()))
       {
         aa.add(a);
       }
index 2d2d10e..b4586ca 100644 (file)
@@ -20,7 +20,6 @@
  */
 package jalview.ext.jmol;
 
-import jalview.api.AlignmentViewPanel;
 import jalview.api.FeatureRenderer;
 import jalview.api.SequenceRenderer;
 import jalview.datamodel.AlignmentI;
@@ -76,8 +75,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
   Hashtable<String, String> chainFile;
 
-  public String fileLoadingError;
-
   /*
    * the default or current model displayed if the model cannot be identified
    * from the selection message
@@ -241,6 +238,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
    * @param _hiddenCols
    *          an array of corresponding hidden columns for each alignment
    */
+  @Override
   public void superposeStructures(AlignmentI[] _alignment,
           int[] _refStructure, ColumnSelection[] _hiddenCols)
   {
@@ -487,35 +485,15 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
   }
 
   /**
-   * colour any structures associated with sequences in the given alignment
-   * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
-   * if colourBySequence is enabled.
+   * Sends a set of colour commands to the structure viewer
+   * 
+   * @param colourBySequenceCommands
    */
-  public void colourBySequence(AlignmentViewPanel alignmentv)
+  @Override
+  protected void colourBySequence(
+          StructureMappingcommandSet[] colourBySequenceCommands)
   {
-    boolean showFeatures = alignmentv.getAlignViewport()
-            .isShowSequenceFeatures();
-    if (!colourBySequence || !isLoadingFinished())
-    {
-      return;
-    }
-    if (getSsm() == null)
-    {
-      return;
-    }
-    String[] files = getPdbFile();
-
-    SequenceRenderer sr = getSequenceRenderer(alignmentv);
-
-    FeatureRenderer fr = null;
-    if (showFeatures)
-    {
-      fr = getFeatureRenderer(alignmentv);
-    }
-    AlignmentI alignment = alignmentv.getAlignment();
-
-    for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(
-            files, sr, fr, alignment))
+    for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
     {
       for (String cbyseq : cpdbbyseq.commands)
       {
@@ -531,6 +509,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
    * @param alignment
    * @return
    */
+  @Override
   protected StructureMappingcommandSet[] getColourBySequenceCommands(
           String[] files, SequenceRenderer sr, FeatureRenderer fr,
           AlignmentI alignment)
@@ -598,17 +577,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
   }
 
   /**
-   * returns the current featureRenderer that should be used to colour the
-   * structures
-   * 
-   * @param alignment
-   * 
-   * @return
-   */
-  public abstract FeatureRenderer getFeatureRenderer(
-          AlignmentViewPanel alignment);
-
-  /**
    * instruct the Jalview binding to update the pdbentries vector if necessary
    * prior to matching the jmol view's contents to the list of structure files
    * Jalview knows about.
@@ -717,16 +685,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
     return null;
   }
 
-  /**
-   * returns the current sequenceRenderer that should be used to colour the
-   * structures
-   * 
-   * @param alignment
-   * 
-   * @return
-   */
-  public abstract SequenceRenderer getSequenceRenderer(
-          AlignmentViewPanel alignment);
+  
 
   // ///////////////////////////////
   // JmolStatusListener
@@ -1286,6 +1245,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
   }
 
+  @Override
   public void setJalviewColourScheme(ColourSchemeI cs)
   {
     colourBySequence = false;
@@ -1300,10 +1260,12 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
     command.append("select *;color white;");
     List<String> residueSet = ResidueProperties.getResidues(isNucleotide(),
             false);
-    for (String res : residueSet)
+    for (String resName : residueSet)
     {
-      Color col = cs.findColour(res.charAt(0));
-      command.append("select " + res + ";color[" + col.getRed() + ","
+      char res = resName.length() == 3 ? ResidueProperties
+              .getSingleCharacterCode(resName) : resName.charAt(0);
+      Color col = cs.findColour(res);
+      command.append("select " + resName + ";color[" + col.getRed() + ","
               + col.getGreen() + "," + col.getBlue() + "];");
     }
 
@@ -1400,6 +1362,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
   protected org.jmol.api.JmolAppConsoleInterface console = null;
 
+  @Override
   public void setBackgroundColour(java.awt.Color col)
   {
     jmolHistory(false);
index a551ca2..8f6b2f1 100644 (file)
@@ -35,6 +35,7 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.SortedMap;
 import java.util.TreeMap;
 
 /**
@@ -58,7 +59,7 @@ public class ChimeraCommands
           SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,
           AlignmentI alignment)
   {
-    Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap = buildColoursMap(
+    Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> colourMap = buildColoursMap(
             ssm, files, sequence, sr, fr, alignment);
 
     List<String> colourCommands = buildColourCommands(colourMap);
@@ -86,7 +87,7 @@ public class ChimeraCommands
    * @return
    */
   protected static List<String> buildColourCommands(
-          Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap)
+          Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> colourMap)
   {
     /*
      * This version concatenates all commands into a single String (semi-colon
@@ -161,12 +162,12 @@ public class ChimeraCommands
    * Ordering is by order of addition (for colours and positions), natural ordering (for models and chains)
    * </pre>
    */
-  protected static Map<Color, Map<Integer, Map<String, List<int[]>>>> buildColoursMap(
+  protected static Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> buildColoursMap(
           StructureSelectionManager ssm, String[] files,
           SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,
           AlignmentI alignment)
   {
-    Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap = new LinkedHashMap<Color, Map<Integer, Map<String, List<int[]>>>>();
+    Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> colourMap = new LinkedHashMap<Color, SortedMap<Integer, Map<String, List<int[]>>>>();
     Color lastColour = null;
     for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
     {
@@ -251,13 +252,13 @@ public class ChimeraCommands
    * @param chain
    */
   protected static void addColourRange(
-          Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap,
+          Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> colourMap,
           Color colour, int model, int startPos, int endPos, String chain)
   {
     /*
      * Get/initialize map of data for the colour
      */
-    Map<Integer, Map<String, List<int[]>>> colourData = colourMap
+    SortedMap<Integer, Map<String, List<int[]>>> colourData = colourMap
             .get(colour);
     if (colourData == null)
     {
index 262b8a2..2171815 100644 (file)
@@ -93,8 +93,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    */
   private boolean loadingFinished = true;
 
-  public String fileLoadingError;
-
   /*
    * Map of ChimeraModel objects keyed by PDB full local file name
    */
@@ -254,18 +252,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   }
 
   /**
-   * Construct a title string for the viewer window based on the data Jalview
-   * knows about
-   * 
-   * @param verbose
-   * @return
-   */
-  public String getViewerTitle(boolean verbose)
-  {
-    return getViewerTitle("Chimera", verbose);
-  }
-
-  /**
    * Tells Chimera to display only the specified chains
    * 
    * @param toshow
@@ -328,6 +314,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
     releaseUIResources();
   }
 
+  @Override
   public void colourByChain()
   {
     colourBySequence = false;
@@ -343,6 +330,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    * <li>all others - white</li>
    * </ul>
    */
+  @Override
   public void colourByCharge()
   {
     colourBySequence = false;
@@ -364,6 +352,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    * @param _hiddenCols
    *          an array of corresponding hidden columns for each alignment
    */
+  @Override
   public void superposeStructures(AlignmentI[] _alignment,
           int[] _refStructure, ColumnSelection[] _hiddenCols)
   {
@@ -680,34 +669,15 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
           String progressMsg);
 
   /**
-   * colour any structures associated with sequences in the given alignment
-   * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
-   * if colourBySequence is enabled.
+   * Sends a set of colour commands to the structure viewer
+   * 
+   * @param colourBySequenceCommands
    */
-  public void colourBySequence(boolean showFeatures,
-          jalview.api.AlignmentViewPanel alignmentv)
+  @Override
+  protected void colourBySequence(
+          StructureMappingcommandSet[] colourBySequenceCommands)
   {
-    if (!colourBySequence || !loadingFinished)
-    {
-      return;
-    }
-    if (getSsm() == null)
-    {
-      return;
-    }
-    String[] files = getPdbFile();
-
-    SequenceRenderer sr = getSequenceRenderer(alignmentv);
-
-    FeatureRenderer fr = null;
-    if (showFeatures)
-    {
-      fr = getFeatureRenderer(alignmentv);
-    }
-    AlignmentI alignment = alignmentv.getAlignment();
-
-    for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(
-            files, sr, fr, alignment))
+    for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
     {
       for (String command : cpdbbyseq.commands)
       {
@@ -723,6 +693,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    * @param alignment
    * @return
    */
+  @Override
   protected StructureMappingcommandSet[] getColourBySequenceCommands(
           String[] files, SequenceRenderer sr, FeatureRenderer fr,
           AlignmentI alignment)
@@ -758,40 +729,12 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   // //////////////////////////
 
   /**
-   * returns the current featureRenderer that should be used to colour the
-   * structures
-   * 
-   * @param alignment
-   * 
-   * @return
-   */
-  public abstract FeatureRenderer getFeatureRenderer(
-          AlignmentViewPanel alignment);
-
-  /**
    * instruct the Jalview binding to update the pdbentries vector if necessary
    * prior to matching the viewer's contents to the list of structure files
    * Jalview knows about.
    */
   public abstract void refreshPdbEntries();
 
-  private int getModelNum(String modelFileName)
-  {
-    String[] mfn = getPdbFile();
-    if (mfn == null)
-    {
-      return -1;
-    }
-    for (int i = 0; i < mfn.length; i++)
-    {
-      if (mfn[i].equalsIgnoreCase(modelFileName))
-      {
-        return i;
-      }
-    }
-    return -1;
-  }
-
   /**
    * map between index of model filename returned from getPdbFile and the first
    * index of models from this file in the viewer. Note - this is not trimmed -
@@ -814,17 +757,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   }
 
   /**
-   * returns the current sequenceRenderer that should be used to colour the
-   * structures
-   * 
-   * @param alignment
-   * 
-   * @return
-   */
-  public abstract SequenceRenderer getSequenceRenderer(
-          AlignmentViewPanel alignment);
-
-  /**
    * Construct and send a command to highlight zero, one or more atoms. We do
    * this by sending an "rlabel" command to show the residue label at that
    * position.
@@ -976,6 +908,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
     return loadNotifiesHandled;
   }
 
+  @Override
   public void setJalviewColourScheme(ColourSchemeI cs)
   {
     colourBySequence = false;
@@ -992,12 +925,14 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
 
     List<String> residueSet = ResidueProperties.getResidues(isNucleotide(),
             false);
-    for (String res : residueSet)
+    for (String resName : residueSet)
     {
-      Color col = cs.findColour(res.charAt(0));
+      char res = resName.length() == 3 ? ResidueProperties
+              .getSingleCharacterCode(resName) : resName.charAt(0);
+      Color col = cs.findColour(res);
       command.append("color " + col.getRed() / normalise + ","
               + col.getGreen() / normalise + "," + col.getBlue()
-              / normalise + " ::" + res + ";");
+              / normalise + " ::" + resName + ";");
     }
 
     sendAsynchronousCommand(command.toString(), COLOURING_CHIMERA);
@@ -1048,6 +983,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    *      .html
    * @param col
    */
+  @Override
   public void setBackgroundColour(Color col)
   {
     viewerCommandHistory(false);
index 44a2318..40ab6bb 100644 (file)
@@ -59,6 +59,7 @@ import jalview.datamodel.SeqCigar;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.gui.ColourMenuHelper.ColourChangeListener;
 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
 import jalview.io.AlignmentProperties;
 import jalview.io.AnnotationFile;
@@ -78,24 +79,11 @@ import jalview.io.JnetAnnotationMaker;
 import jalview.io.NewickFile;
 import jalview.io.TCoffeeScoreFile;
 import jalview.jbgui.GAlignFrame;
-import jalview.schemes.Blosum62ColourScheme;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.ClustalxColourScheme;
 import jalview.schemes.ColourSchemeI;
-import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.NucleotideColourScheme;
-import jalview.schemes.PIDColourScheme;
-import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.RNAHelicesColourChooser;
+import jalview.schemes.ColourSchemes;
+import jalview.schemes.ResidueColourScheme;
 import jalview.schemes.ResidueProperties;
-import jalview.schemes.StrandColourScheme;
 import jalview.schemes.TCoffeeColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.UserColourScheme;
-import jalview.schemes.ZappoColourScheme;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.DBRefFetcher;
@@ -126,7 +114,6 @@ import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.awt.event.KeyAdapter;
 import java.awt.event.KeyEvent;
-import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.awt.print.PageFormat;
 import java.awt.print.PrinterJob;
@@ -149,7 +136,6 @@ import javax.swing.JInternalFrame;
 import javax.swing.JLayeredPane;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
-import javax.swing.JRadioButtonMenuItem;
 import javax.swing.JScrollPane;
 import javax.swing.SwingUtilities;
 
@@ -160,7 +146,7 @@ import javax.swing.SwingUtilities;
  * @version $Revision$
  */
 public class AlignFrame extends GAlignFrame implements DropTargetListener,
-        IProgressIndicator, AlignViewControllerGuiI
+        IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
 {
 
   public static final int DEFAULT_WIDTH = 700;
@@ -349,7 +335,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             alignPanel);
     if (viewport.getAlignmentConservationAnnotation() == null)
     {
-      BLOSUM62Colour.setEnabled(false);
+      // BLOSUM62Colour.setEnabled(false);
       conservationMenuItem.setEnabled(false);
       modifyConservation.setEnabled(false);
       // PIDColour.setEnabled(false);
@@ -369,19 +355,20 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       sortPairwiseMenuItem_actionPerformed(null);
     }
 
-    if (Desktop.desktop != null)
-    {
-      this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
-      addServiceListeners();
-      setGUINucleotide(viewport.getAlignment().isNucleotide());
-    }
-
     this.alignPanel.av
             .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
 
     setMenusFromViewport(viewport);
     buildSortByAnnotationScoresMenu();
     buildTreeMenu();
+    buildColourMenu();
+
+    if (Desktop.desktop != null)
+    {
+      this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
+      addServiceListeners();
+      setGUINucleotide();
+    }
 
     if (viewport.getWrapAlignment())
     {
@@ -848,27 +835,23 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * Configure menu items that vary according to whether the alignment is
    * nucleotide or protein
-   * 
-   * @param nucleotide
    */
-  public void setGUINucleotide(boolean nucleotide)
+  public void setGUINucleotide()
   {
+    AlignmentI al = getViewport().getAlignment();
+    boolean nucleotide = al.isNucleotide();
+
     showTranslation.setVisible(nucleotide);
     showReverse.setVisible(nucleotide);
     showReverseComplement.setVisible(nucleotide);
     conservationMenuItem.setEnabled(!nucleotide);
-    modifyConservation.setEnabled(!nucleotide);
+    modifyConservation.setEnabled(!nucleotide
+            && conservationMenuItem.isSelected());
     showGroupConservation.setEnabled(!nucleotide);
-    rnahelicesColour.setEnabled(nucleotide);
-    nucleotideColour.setEnabled(nucleotide);
-    purinePyrimidineColour.setEnabled(nucleotide);
-    RNAInteractionColour.setEnabled(nucleotide);
+
     showComplementMenuItem.setText(nucleotide ? MessageManager
             .getString("label.protein") : MessageManager
             .getString("label.nucleotide"));
-    setColourSelected(jalview.bin.Cache.getDefault(
-            nucleotide ? Preferences.DEFAULT_COLOUR_NUC
-                    : Preferences.DEFAULT_COLOUR_PROT, "None"));
   }
 
   /**
@@ -922,8 +905,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     showSequenceLogo.setSelected(av.isShowSequenceLogo());
     normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
 
-    setColourSelected(ColourSchemeProperty.getColourName(av
-            .getGlobalColourScheme()));
+    ColourMenuHelper.setColourSelected(colourMenu,
+            av.getGlobalColourScheme());
 
     showSeqFeatures.setSelected(av.isShowSequenceFeatures());
     hiddenMarkers.setState(av.getShowHiddenMarkers());
@@ -933,9 +916,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     autoCalculate.setSelected(av.autoCalculateConsensus);
     sortByTree.setSelected(av.sortByTree);
     listenToViewSelections.setSelected(av.followSelection);
-    rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
-    rnahelicesColour
-            .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
 
     showProducts.setEnabled(canShowProducts());
     setGroovyEnabled(Desktop.getGroovyConsole() != null);
@@ -3292,146 +3272,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   @Override
-  public void textColour_actionPerformed(ActionEvent e)
+  public void textColour_actionPerformed()
   {
     new TextColourChooser().chooseColour(alignPanel, null);
   }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  protected void noColourmenuItem_actionPerformed(ActionEvent e)
-  {
-    changeColour(null);
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  public void clustalColour_actionPerformed(ActionEvent e)
-  {
-    changeColour(new ClustalxColourScheme(viewport.getAlignment(),
-            viewport.getHiddenRepSequences()));
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  public void zappoColour_actionPerformed(ActionEvent e)
-  {
-    changeColour(new ZappoColourScheme());
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  public void taylorColour_actionPerformed(ActionEvent e)
-  {
-    changeColour(new TaylorColourScheme());
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  public void hydrophobicityColour_actionPerformed(ActionEvent e)
-  {
-    changeColour(new HydrophobicColourScheme());
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  public void helixColour_actionPerformed(ActionEvent e)
-  {
-    changeColour(new HelixColourScheme());
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  public void strandColour_actionPerformed(ActionEvent e)
-  {
-    changeColour(new StrandColourScheme());
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  public void turnColour_actionPerformed(ActionEvent e)
-  {
-    changeColour(new TurnColourScheme());
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  public void buriedColour_actionPerformed(ActionEvent e)
-  {
-    changeColour(new BuriedColourScheme());
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  public void nucleotideColour_actionPerformed(ActionEvent e)
-  {
-    changeColour(new NucleotideColourScheme());
-  }
-
-  @Override
-  public void purinePyrimidineColour_actionPerformed(ActionEvent e)
-  {
-    changeColour(new PurinePyrimidineColourScheme());
-  }
-
   /*
-   * public void covariationColour_actionPerformed(ActionEvent e) {
+   * public void covariationColour_actionPerformed() {
    * changeColour(new
    * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
    * ()[0])); }
    */
   @Override
-  public void annotationColour_actionPerformed(ActionEvent e)
+  public void annotationColour_actionPerformed()
   {
     new AnnotationColourChooser(viewport, alignPanel);
   }
@@ -3442,37 +3295,57 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     new AnnotationColumnChooser(viewport, alignPanel);
   }
 
+  /**
+   * Action on the user checking or unchecking the option to apply the selected
+   * colour scheme to all groups. If unchecked, groups may have their own
+   * independent colour schemes.
+   * 
+   */
   @Override
-  public void rnahelicesColour_actionPerformed(ActionEvent e)
+  protected void applyToAllGroups_actionPerformed()
   {
-    new RNAHelicesColourChooser(viewport, alignPanel);
+    viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
   }
 
   /**
-   * DOCUMENT ME!
+   * Action on user selecting a colour from the colour menu
    * 
-   * @param e
-   *          DOCUMENT ME!
+   * @param name
+   *          the name (not the menu item label!) of the colour scheme
    */
   @Override
-  protected void applyToAllGroups_actionPerformed(ActionEvent e)
+  public void changeColour_actionPerformed(String name)
   {
-    viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
+    /*
+     * 'User Defined' opens a panel to configure or load a
+     * user-defined colour scheme
+     */
+    if (ResidueColourScheme.USER_DEFINED.equals(name))
+    {
+      new UserDefinedColours(alignPanel, null);
+      return;
+    }
+
+    /*
+     * otherwise set the chosen colour scheme (or null for 'None')
+     */
+    ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
+            viewport.getAlignment(), viewport.getHiddenRepSequences());
+    changeColour(cs);
   }
 
   /**
-   * DOCUMENT ME!
+   * Actions on setting or changing the alignment colour scheme
    * 
    * @param cs
-   *          DOCUMENT ME!
    */
   @Override
   public void changeColour(ColourSchemeI cs)
   {
     // TODO: pull up to controller method
-
     if (cs != null)
     {
+      ColourMenuHelper.setColourSelected(colourMenu, cs.getSchemeName());
       // Make sure viewport is up to date w.r.t. any sliders
       if (viewport.getAbovePIDThreshold())
       {
@@ -3486,11 +3359,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
                 cs, "Background"));
       }
-      if (cs instanceof TCoffeeColourScheme)
-      {
-        tcoffeeColour.setEnabled(true);
-        tcoffeeColour.setSelected(true);
-      }
     }
 
     viewport.setGlobalColourScheme(cs);
@@ -3500,6 +3368,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
   /**
    * DOCUMENT ME!
+   * 
+   * @param e
+   *          DOCUMENT ME!
    */
   @Override
   protected void modifyPID_actionPerformed()
@@ -3515,6 +3386,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
   /**
    * DOCUMENT ME!
+   * 
+   * @param e
+   *          DOCUMENT ME!
    */
   @Override
   protected void modifyConservation_actionPerformed()
@@ -3577,144 +3451,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    *          DOCUMENT ME!
    */
   @Override
-  public void userDefinedColour_actionPerformed(ActionEvent e)
-  {
-    if (e.getActionCommand().equals(
-            MessageManager.getString("action.user_defined")))
-    {
-      new UserDefinedColours(alignPanel, null);
-    }
-    else
-    {
-      UserColourScheme udc = (UserColourScheme) UserDefinedColours
-              .getUserColourSchemes().get(e.getActionCommand());
-
-      changeColour(udc);
-    }
-  }
-
-  public void updateUserColourMenu()
-  {
-
-    Component[] menuItems = colourMenu.getMenuComponents();
-    int iSize = menuItems.length;
-    for (int i = 0; i < iSize; i++)
-    {
-      if (menuItems[i].getName() != null
-              && menuItems[i].getName().equals("USER_DEFINED"))
-      {
-        colourMenu.remove(menuItems[i]);
-        iSize--;
-      }
-    }
-    if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
-    {
-      java.util.Enumeration userColours = jalview.gui.UserDefinedColours
-              .getUserColourSchemes().keys();
-
-      while (userColours.hasMoreElements())
-      {
-        final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
-                userColours.nextElement().toString());
-        radioItem.setName("USER_DEFINED");
-        radioItem.addMouseListener(new MouseAdapter()
-        {
-          @Override
-          public void mousePressed(MouseEvent evt)
-          {
-            if (evt.isPopupTrigger()) // Mac
-            {
-              offerRemoval(radioItem);
-            }
-          }
-
-          @Override
-          public void mouseReleased(MouseEvent evt)
-          {
-            if (evt.isPopupTrigger()) // Windows
-            {
-              offerRemoval(radioItem);
-            }
-          }
-
-          /**
-           * @param radioItem
-           */
-          void offerRemoval(final JRadioButtonMenuItem radioItem)
-          {
-            radioItem.removeActionListener(radioItem.getActionListeners()[0]);
-
-            int option = JvOptionPane.showInternalConfirmDialog(
-                    jalview.gui.Desktop.desktop, MessageManager
-                            .getString("label.remove_from_default_list"),
-                    MessageManager
-                            .getString("label.remove_user_defined_colour"),
-                    JvOptionPane.YES_NO_OPTION);
-            if (option == JvOptionPane.YES_OPTION)
-            {
-              jalview.gui.UserDefinedColours
-                      .removeColourFromDefaults(radioItem.getText());
-              colourMenu.remove(radioItem);
-            }
-            else
-            {
-              radioItem.addActionListener(new ActionListener()
-              {
-                @Override
-                public void actionPerformed(ActionEvent evt)
-                {
-                  userDefinedColour_actionPerformed(evt);
-                }
-              });
-            }
-          }
-        });
-        radioItem.addActionListener(new ActionListener()
-        {
-          @Override
-          public void actionPerformed(ActionEvent evt)
-          {
-            userDefinedColour_actionPerformed(evt);
-          }
-        });
-
-        colourMenu.insert(radioItem, 15);
-        colours.add(radioItem);
-      }
-    }
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  public void PIDColour_actionPerformed(ActionEvent e)
-  {
-    changeColour(new PIDColourScheme());
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
-  public void BLOSUM62Colour_actionPerformed(ActionEvent e)
-  {
-    changeColour(new Blosum62ColourScheme());
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  @Override
   public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
   {
     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
@@ -4342,12 +4078,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
   }
 
-  @Override
-  protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
-  {
-    changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
-  }
-
   public TreePanel ShowNewickTree(NewickFile nf, String title)
   {
     return ShowNewickTree(nf, title, 600, 500, 4, 5);
@@ -5013,8 +4743,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           {
             if (tcf.annotateAlignment(viewport.getAlignment(), true))
             {
-              tcoffeeColour.setEnabled(true);
-              tcoffeeColour.setSelected(true);
+              buildColourMenu();
               changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
               isAnnotation = true;
               statusBar
@@ -5828,7 +5557,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
     AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
             .size()]));
-    AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
+    GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
             AlignFrame.DEFAULT_HEIGHT);
     cdna.alignAs(alignment);
     String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
@@ -5944,6 +5673,41 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             true,
             (actionEvent.getModifiers() & (ActionEvent.META_MASK | ActionEvent.CTRL_MASK)) != 0);
   }
+
+  /**
+   * Rebuilds the Colour menu, including any user-defined colours which have
+   * been loaded either on startup or during the session
+   */
+  public void buildColourMenu()
+  {
+    colourMenu.removeAll();
+
+    colourMenu.add(applyToAllGroups);
+    colourMenu.add(textColour);
+    colourMenu.addSeparator();
+
+    ColourMenuHelper.addMenuItems(colourMenu, this,
+            viewport.getAlignment(), false);
+
+    colourMenu.addSeparator();
+    colourMenu.add(conservationMenuItem);
+    colourMenu.add(modifyConservation);
+    colourMenu.add(abovePIDThreshold);
+    colourMenu.add(modifyPID);
+    colourMenu.add(annotationColour);
+
+    /*
+     * select the default colour for the alignment (this may be
+     * overridden later)
+     */
+    boolean nucleotide = viewport.getAlignment().isNucleotide();
+    String defaultColourScheme = Cache.getDefault(
+            nucleotide ? Preferences.DEFAULT_COLOUR_NUC
+                    : Preferences.DEFAULT_COLOUR_PROT,
+            ResidueColourScheme.NONE);
+
+    ColourMenuHelper.setColourSelected(colourMenu, defaultColourScheme);
+  }
 }
 
 class PrintThread extends Thread
index 53d118b..2115617 100644 (file)
@@ -292,7 +292,7 @@ public class AlignViewport extends AlignmentViewport implements
     }
     if (propertyValue != null)
     {
-      globalColourScheme = ColourSchemeProperty.getColour(alignment,
+      globalColourScheme = ColourSchemeProperty.getColourScheme(alignment,
               propertyValue);
 
       if (globalColourScheme instanceof UserColourScheme)
index e2e54aa..ffb9639 100644 (file)
 package jalview.gui;
 
 import jalview.bin.Cache;
-import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
-import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.gui.StructureViewer.ViewerType;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.StrandColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.ZappoColourScheme;
 import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.BrowserLauncher;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.dbsources.Pdb;
@@ -50,30 +38,19 @@ import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JColorChooser;
 import javax.swing.JInternalFrame;
 import javax.swing.JMenu;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JSplitPane;
 import javax.swing.SwingUtilities;
 import javax.swing.event.InternalFrameAdapter;
 import javax.swing.event.InternalFrameEvent;
-import javax.swing.event.MenuEvent;
-import javax.swing.event.MenuListener;
 
 public class AppJmol extends StructureViewerBase
 {
@@ -92,8 +69,6 @@ public class AppJmol extends StructureViewerBase
 
   RenderPanel renderPanel;
 
-  ViewSelectionMenu seqColourBy;
-
   /**
    * 
    * @param files
@@ -137,6 +112,7 @@ public class AppJmol extends StructureViewerBase
     {
       useAlignmentPanelForSuperposition(ap);
     }
+    initMenus();
     if (leaveColouringToJmol || !usetoColour)
     {
       jmb.setColourBySequence(false);
@@ -151,7 +127,6 @@ public class AppJmol extends StructureViewerBase
       viewerColour.setSelected(false);
     }
     this.setBounds(bounds);
-    initMenus();
     setViewId(viewid);
     // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
     // bounds.width,bounds.height);
@@ -165,84 +140,19 @@ public class AppJmol extends StructureViewerBase
       }
     });
     initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
-
   }
 
-  private void initMenus()
+  @Override
+  protected void initMenus()
   {
-    seqColour.setSelected(jmb.isColourBySequence());
-    viewerColour.setSelected(!jmb.isColourBySequence());
-    if (_colourwith == null)
-    {
-      _colourwith = new Vector<AlignmentPanel>();
-    }
-    if (_alignwith == null)
-    {
-      _alignwith = new Vector<AlignmentPanel>();
-    }
-
-    seqColourBy = new ViewSelectionMenu(
-            MessageManager.getString("label.colour_by"), this, _colourwith,
-            new ItemListener()
-            {
-
-              @Override
-              public void itemStateChanged(ItemEvent e)
-              {
-                if (!seqColour.isSelected())
-                {
-                  seqColour.doClick();
-                }
-                else
-                {
-                  // update the jmol display now.
-                  seqColour_actionPerformed(null);
-                }
-              }
-            });
-    viewMenu.add(seqColourBy);
-    final ItemListener handler;
-    JMenu alpanels = new ViewSelectionMenu(
-            MessageManager.getString("label.superpose_with"), this,
-            _alignwith, handler = new ItemListener()
-            {
-
-              @Override
-              public void itemStateChanged(ItemEvent e)
-              {
-                alignStructs.setEnabled(_alignwith.size() > 0);
-                alignStructs.setToolTipText(MessageManager
-                        .formatMessage(
-                                "label.align_structures_using_linked_alignment_views",
-                                new String[] { new Integer(_alignwith
-                                        .size()).toString() }));
-              }
-            });
-    handler.itemStateChanged(null);
-    viewerActionMenu.add(alpanels);
-    viewerActionMenu.addMenuListener(new MenuListener()
-    {
-
-      @Override
-      public void menuSelected(MenuEvent e)
-      {
-        handler.itemStateChanged(null);
-      }
-
-      @Override
-      public void menuDeselected(MenuEvent e)
-      {
-        // TODO Auto-generated method stub
+    super.initMenus();
 
-      }
+    viewerActionMenu = new JMenu(MessageManager.getString("label.jmol"));
 
-      @Override
-      public void menuCanceled(MenuEvent e)
-      {
-        // TODO Auto-generated method stub
-
-      }
-    });
+    viewerColour
+            .setText(MessageManager.getString("label.colour_with_jmol"));
+    viewerColour.setToolTipText(MessageManager
+            .getString("label.let_jmol_manage_structure_colours"));
   }
 
   IProgressIndicator progressBar = null;
@@ -285,15 +195,6 @@ public class AppJmol extends StructureViewerBase
     openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq });
   }
 
-  /**
-   * Answers true if this viewer already involves the given PDB ID
-   */
-  @Override
-  protected boolean hasPdbId(String pdbId)
-  {
-    return jmb.hasPdbId(pdbId);
-  }
-
   private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
           SequenceI[][] seqs)
   {
@@ -302,6 +203,7 @@ public class AppJmol extends StructureViewerBase
             pdbentrys, seqs, null);
     addAlignmentPanel(ap);
     useAlignmentPanelForColourbyseq(ap);
+
     if (pdbentrys.length > 1)
     {
       alignAddedStructures = true;
@@ -685,76 +587,6 @@ public class AppJmol extends StructureViewerBase
   }
 
   @Override
-  public void pdbFile_actionPerformed(ActionEvent actionEvent)
-  {
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
-
-    chooser.setFileView(new JalviewFileView());
-    chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
-    chooser.setToolTipText(MessageManager.getString("action.save"));
-
-    int value = chooser.showSaveDialog(this);
-
-    if (value == JalviewFileChooser.APPROVE_OPTION)
-    {
-      BufferedReader in = null;
-      try
-      {
-        // TODO: cope with multiple PDB files in view
-        in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
-        File outFile = chooser.getSelectedFile();
-
-        PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
-        String data;
-        while ((data = in.readLine()) != null)
-        {
-          if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
-          {
-            out.println(data);
-          }
-        }
-        out.close();
-      } catch (Exception ex)
-      {
-        ex.printStackTrace();
-      } finally
-      {
-        if (in != null)
-        {
-          try
-          {
-            in.close();
-          } catch (IOException e)
-          {
-            // ignore
-          }
-        }
-      }
-    }
-  }
-
-  @Override
-  public void viewMapping_actionPerformed(ActionEvent actionEvent)
-  {
-    jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
-    try
-    {
-      cap.appendText(jmb.printMappings());
-    } catch (OutOfMemoryError e)
-    {
-      new OOMWarning(
-              "composing sequence-structure alignments for display in text box.",
-              e);
-      cap.dispose();
-      return;
-    }
-    jalview.gui.Desktop.addInternalFrame(cap,
-            MessageManager.getString("label.pdb_sequence_mapping"), 550,
-            600);
-  }
-
-  @Override
   public void eps_actionPerformed(ActionEvent e)
   {
     makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
@@ -801,135 +633,11 @@ public class AppJmol extends StructureViewerBase
   }
 
   @Override
-  public void viewerColour_actionPerformed(ActionEvent actionEvent)
-  {
-    if (viewerColour.isSelected())
-    {
-      // disable automatic sequence colouring.
-      jmb.setColourBySequence(false);
-    }
-  }
-
-  @Override
-  public void seqColour_actionPerformed(ActionEvent actionEvent)
-  {
-    jmb.setColourBySequence(seqColour.isSelected());
-    if (_colourwith == null)
-    {
-      _colourwith = new Vector<AlignmentPanel>();
-    }
-    if (jmb.isColourBySequence())
-    {
-      if (!jmb.isLoadingFromArchive())
-      {
-        if (_colourwith.size() == 0 && getAlignmentPanel() != null)
-        {
-          // Make the currently displayed alignment panel the associated view
-          _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
-        }
-      }
-      // Set the colour using the current view for the associated alignframe
-      for (AlignmentPanel ap : _colourwith)
-      {
-        jmb.colourBySequence(ap);
-      }
-    }
-  }
-
-  @Override
-  public void chainColour_actionPerformed(ActionEvent actionEvent)
-  {
-    chainColour.setSelected(true);
-    jmb.colourByChain();
-  }
-
-  @Override
-  public void chargeColour_actionPerformed(ActionEvent actionEvent)
-  {
-    chargeColour.setSelected(true);
-    jmb.colourByCharge();
-  }
-
-  @Override
-  public void zappoColour_actionPerformed(ActionEvent actionEvent)
-  {
-    zappoColour.setSelected(true);
-    jmb.setJalviewColourScheme(new ZappoColourScheme());
-  }
-
-  @Override
-  public void taylorColour_actionPerformed(ActionEvent actionEvent)
-  {
-    taylorColour.setSelected(true);
-    jmb.setJalviewColourScheme(new TaylorColourScheme());
-  }
-
-  @Override
-  public void hydroColour_actionPerformed(ActionEvent actionEvent)
-  {
-    hydroColour.setSelected(true);
-    jmb.setJalviewColourScheme(new HydrophobicColourScheme());
-  }
-
-  @Override
-  public void helixColour_actionPerformed(ActionEvent actionEvent)
-  {
-    helixColour.setSelected(true);
-    jmb.setJalviewColourScheme(new HelixColourScheme());
-  }
-
-  @Override
-  public void strandColour_actionPerformed(ActionEvent actionEvent)
-  {
-    strandColour.setSelected(true);
-    jmb.setJalviewColourScheme(new StrandColourScheme());
-  }
-
-  @Override
-  public void turnColour_actionPerformed(ActionEvent actionEvent)
-  {
-    turnColour.setSelected(true);
-    jmb.setJalviewColourScheme(new TurnColourScheme());
-  }
-
-  @Override
-  public void buriedColour_actionPerformed(ActionEvent actionEvent)
-  {
-    buriedColour.setSelected(true);
-    jmb.setJalviewColourScheme(new BuriedColourScheme());
-  }
-
-  @Override
-  public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
-  {
-    setJalviewColourScheme(new PurinePyrimidineColourScheme());
-  }
-
-  @Override
-  public void userColour_actionPerformed(ActionEvent actionEvent)
-  {
-    userColour.setSelected(true);
-    new UserDefinedColours(this, null);
-  }
-
-  @Override
-  public void backGround_actionPerformed(ActionEvent actionEvent)
-  {
-    java.awt.Color col = JColorChooser
-            .showDialog(this, MessageManager
-                    .getString("label.select_backgroud_colour"), null);
-    if (col != null)
-    {
-      jmb.setBackgroundColour(col);
-    }
-  }
-
-  @Override
   public void showHelp_actionPerformed(ActionEvent actionEvent)
   {
     try
     {
-      jalview.util.BrowserLauncher
+      BrowserLauncher
               .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
     } catch (Exception ex)
     {
@@ -978,7 +686,7 @@ public class AppJmol extends StructureViewerBase
     {
       getSize(currentSize);
 
-      if (jmb != null && jmb.fileLoadingError != null)
+      if (jmb != null && jmb.hasFileLoadingError())
       {
         g.setColor(Color.black);
         g.fillRect(0, 0, currentSize.width, currentSize.height);
@@ -1021,104 +729,6 @@ public class AppJmol extends StructureViewerBase
     }
   }
 
-  public void updateTitleAndMenus()
-  {
-    if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
-    {
-      repaint();
-      return;
-    }
-    setChainMenuItems(jmb.getChainNames());
-
-    this.setTitle(jmb.getViewerTitle());
-    if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
-    {
-      viewerActionMenu.setVisible(true);
-    }
-    if (!jmb.isLoadingFromArchive())
-    {
-      seqColour_actionPerformed(null);
-    }
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
-   * @see
-   * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
-   * .ActionEvent)
-   */
-  @Override
-  protected void alignStructs_actionPerformed(ActionEvent actionEvent)
-  {
-    alignStructs_withAllAlignPanels();
-  }
-
-  private void alignStructs_withAllAlignPanels()
-  {
-    if (getAlignmentPanel() == null)
-    {
-      return;
-    }
-    ;
-    if (_alignwith.size() == 0)
-    {
-      _alignwith.add(getAlignmentPanel());
-    }
-    ;
-    try
-    {
-      AlignmentI[] als = new Alignment[_alignwith.size()];
-      ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
-      int[] alm = new int[_alignwith.size()];
-      int a = 0;
-
-      for (AlignmentPanel ap : _alignwith)
-      {
-        als[a] = ap.av.getAlignment();
-        alm[a] = -1;
-        alc[a++] = ap.av.getColumnSelection();
-      }
-      jmb.superposeStructures(als, alm, alc);
-    } catch (Exception e)
-    {
-      StringBuffer sp = new StringBuffer();
-      for (AlignmentPanel ap : _alignwith)
-      {
-        sp.append("'" + ap.alignFrame.getTitle() + "' ");
-      }
-      Cache.log.info("Couldn't align structures with the " + sp.toString()
-              + "associated alignment panels.", e);
-
-    }
-
-  }
-
-  @Override
-  public void setJalviewColourScheme(ColourSchemeI ucs)
-  {
-    jmb.setJalviewColourScheme(ucs);
-
-  }
-
-  /**
-   * 
-   * @param alignment
-   * @return first alignment panel displaying given alignment, or the default
-   *         alignment panel
-   */
-  public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
-  {
-    for (AlignmentPanel ap : getAllAlignmentPanels())
-    {
-      if (ap.av.getAlignment() == alignment)
-      {
-        return ap;
-      }
-    }
-    return getAlignmentPanel();
-  }
-
   @Override
   public AAStructureBindingModel getBinding()
   {
@@ -1138,9 +748,8 @@ public class AppJmol extends StructureViewerBase
   }
 
   @Override
-  protected AAStructureBindingModel getBindingModel()
+  protected String getViewerName()
   {
-    return jmb;
+    return "Jmol";
   }
-
 }
index b82eef3..530f4fe 100644 (file)
 package jalview.gui;
 
 import jalview.bin.Cache;
-import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
-import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
 import jalview.gui.StructureViewer.ViewerType;
 import jalview.io.DataSourceType;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
 import jalview.io.StructureFile;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.StrandColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.ZappoColourScheme;
 import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.BrowserLauncher;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.dbsources.Pdb;
 
 import java.awt.event.ActionEvent;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Random;
-import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JColorChooser;
 import javax.swing.JInternalFrame;
-import javax.swing.JMenu;
-import javax.swing.JOptionPane;
 import javax.swing.event.InternalFrameAdapter;
 import javax.swing.event.InternalFrameEvent;
-import javax.swing.event.MenuEvent;
-import javax.swing.event.MenuListener;
 
 /**
  * GUI elements for handling an external chimera display
@@ -98,88 +74,21 @@ public class ChimeraViewFrame extends StructureViewerBase
   /**
    * Initialise menu options.
    */
-  private void initMenus()
+  @Override
+  protected void initMenus()
   {
+    super.initMenus();
+
     viewerActionMenu.setText(MessageManager.getString("label.chimera"));
+
     viewerColour.setText(MessageManager
             .getString("label.colour_with_chimera"));
     viewerColour.setToolTipText(MessageManager
             .getString("label.let_chimera_manage_structure_colours"));
-    helpItem.setText(MessageManager.getString("label.chimera_help"));
-    seqColour.setSelected(jmb.isColourBySequence());
-    viewerColour.setSelected(!jmb.isColourBySequence());
-    if (_colourwith == null)
-    {
-      _colourwith = new Vector<AlignmentPanel>();
-    }
-    if (_alignwith == null)
-    {
-      _alignwith = new Vector<AlignmentPanel>();
-    }
-
-    // save As not yet implemented
-    savemenu.setVisible(false);
 
-    ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
-            MessageManager.getString("label.colour_by"), this, _colourwith,
-            new ItemListener()
-            {
-              @Override
-              public void itemStateChanged(ItemEvent e)
-              {
-                if (!seqColour.isSelected())
-                {
-                  seqColour.doClick();
-                }
-                else
-                {
-                  // update the Chimera display now.
-                  seqColour_actionPerformed(null);
-                }
-              }
-            });
-    viewMenu.add(seqColourBy);
+    helpItem.setText(MessageManager.getString("label.chimera_help"));
+    savemenu.setVisible(false); // not yet implemented
     viewMenu.add(fitToWindow);
-
-    final ItemListener handler;
-    JMenu alpanels = new ViewSelectionMenu(
-            MessageManager.getString("label.superpose_with"), this,
-            _alignwith, handler = new ItemListener()
-            {
-              @Override
-              public void itemStateChanged(ItemEvent e)
-              {
-                alignStructs.setEnabled(_alignwith.size() > 0);
-                alignStructs.setToolTipText(MessageManager
-                        .formatMessage(
-                                "label.align_structures_using_linked_alignment_views",
-                                new Object[] { new Integer(_alignwith
-                                        .size()).toString() }));
-              }
-            });
-    handler.itemStateChanged(null);
-    viewerActionMenu.add(alpanels);
-    viewerActionMenu.addMenuListener(new MenuListener()
-    {
-
-      @Override
-      public void menuSelected(MenuEvent e)
-      {
-        handler.itemStateChanged(null);
-      }
-
-      @Override
-      public void menuDeselected(MenuEvent e)
-      {
-        // TODO Auto-generated method stub
-      }
-
-      @Override
-      public void menuCanceled(MenuEvent e)
-      {
-        // TODO Auto-generated method stub
-      }
-    });
   }
 
   /**
@@ -233,15 +142,6 @@ public class ChimeraViewFrame extends StructureViewerBase
     }
   }
 
-  /**
-   * Answers true if this viewer already involves the given PDB ID
-   */
-  @Override
-  protected boolean hasPdbId(String pdbId)
-  {
-    return jmb.hasPdbId(pdbId);
-  }
-
   private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
           SequenceI[][] seqs)
   {
@@ -251,6 +151,7 @@ public class ChimeraViewFrame extends StructureViewerBase
             ap.getStructureSelectionManager(), pdbentrys, seqs, null);
     addAlignmentPanel(ap);
     useAlignmentPanelForColourbyseq(ap);
+
     if (pdbentrys.length > 1)
     {
       alignAddedStructures = true;
@@ -275,8 +176,6 @@ public class ChimeraViewFrame extends StructureViewerBase
 
   }
 
-
-
   /**
    * Create a new viewer from saved session state data including Chimera session
    * file
@@ -372,7 +271,7 @@ public class ChimeraViewFrame extends StructureViewerBase
   {
     jmb.setFinishedInit(false);
     jalview.gui.Desktop.addInternalFrame(this,
-            jmb.getViewerTitle("Chimera", true), getBounds().width,
+            jmb.getViewerTitle(getViewerName(), true), getBounds().width,
             getBounds().height);
 
     if (!jmb.launchChimera())
@@ -439,7 +338,8 @@ public class ChimeraViewFrame extends StructureViewerBase
       {
         String prompt = MessageManager.formatMessage(
                 "label.confirm_close_chimera",
-                new Object[] { jmb.getViewerTitle("Chimera", false) });
+                        new Object[] { jmb.getViewerTitle(getViewerName(),
+                                false) });
         prompt = JvSwingUtils.wrapTooltip(true, prompt);
         int confirm = JvOptionPane.showConfirmDialog(this, prompt,
                 MessageManager.getString("label.close_viewer"),
@@ -569,7 +469,7 @@ public class ChimeraViewFrame extends StructureViewerBase
           try
           {
             int pos = filePDBpos.get(num).intValue();
-            long startTime = startProgressBar("Chimera "
+            long startTime = startProgressBar(getViewerName() + " "
                     + MessageManager.getString("status.opening_file_for")
                     + " " + pe.getId());
             jmb.openFile(pe);
@@ -734,76 +634,6 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   @Override
-  public void pdbFile_actionPerformed(ActionEvent actionEvent)
-  {
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
-
-    chooser.setFileView(new JalviewFileView());
-    chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
-    chooser.setToolTipText(MessageManager.getString("action.save"));
-
-    int value = chooser.showSaveDialog(this);
-
-    if (value == JalviewFileChooser.APPROVE_OPTION)
-    {
-      BufferedReader in = null;
-      try
-      {
-        // TODO: cope with multiple PDB files in view
-        in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
-        File outFile = chooser.getSelectedFile();
-
-        PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
-        String data;
-        while ((data = in.readLine()) != null)
-        {
-          if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
-          {
-            out.println(data);
-          }
-        }
-        out.close();
-      } catch (Exception ex)
-      {
-        ex.printStackTrace();
-      } finally
-      {
-        if (in != null)
-        {
-          try
-          {
-            in.close();
-          } catch (IOException e)
-          {
-            e.printStackTrace();
-          }
-        }
-      }
-    }
-  }
-
-  @Override
-  public void viewMapping_actionPerformed(ActionEvent actionEvent)
-  {
-    jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
-    try
-    {
-      cap.appendText(jmb.printMappings());
-    } catch (OutOfMemoryError e)
-    {
-      new OOMWarning(
-              "composing sequence-structure alignments for display in text box.",
-              e);
-      cap.dispose();
-      return;
-    }
-    jalview.gui.Desktop.addInternalFrame(cap,
-            MessageManager.getString("label.pdb_sequence_mapping"), 550,
-            600);
-  }
-
-  @Override
   public void eps_actionPerformed(ActionEvent e)
   {
     throw new Error(
@@ -820,237 +650,17 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   @Override
-  public void viewerColour_actionPerformed(ActionEvent actionEvent)
-  {
-    if (viewerColour.isSelected())
-    {
-      // disable automatic sequence colouring.
-      jmb.setColourBySequence(false);
-    }
-  }
-
-  @Override
-  public void seqColour_actionPerformed(ActionEvent actionEvent)
-  {
-    jmb.setColourBySequence(seqColour.isSelected());
-    if (_colourwith == null)
-    {
-      _colourwith = new Vector<AlignmentPanel>();
-    }
-    if (jmb.isColourBySequence())
-    {
-      if (!jmb.isLoadingFromArchive())
-      {
-        if (_colourwith.size() == 0 && getAlignmentPanel() != null)
-        {
-          // Make the currently displayed alignment panel the associated view
-          _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
-        }
-      }
-      // Set the colour using the current view for the associated alignframe
-      for (AlignmentPanel ap : _colourwith)
-      {
-        jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
-      }
-    }
-  }
-
-  @Override
-  public void chainColour_actionPerformed(ActionEvent actionEvent)
-  {
-    chainColour.setSelected(true);
-    jmb.colourByChain();
-  }
-
-  @Override
-  public void chargeColour_actionPerformed(ActionEvent actionEvent)
-  {
-    chargeColour.setSelected(true);
-    jmb.colourByCharge();
-  }
-
-  @Override
-  public void zappoColour_actionPerformed(ActionEvent actionEvent)
-  {
-    zappoColour.setSelected(true);
-    jmb.setJalviewColourScheme(new ZappoColourScheme());
-  }
-
-  @Override
-  public void taylorColour_actionPerformed(ActionEvent actionEvent)
-  {
-    taylorColour.setSelected(true);
-    jmb.setJalviewColourScheme(new TaylorColourScheme());
-  }
-
-  @Override
-  public void hydroColour_actionPerformed(ActionEvent actionEvent)
-  {
-    hydroColour.setSelected(true);
-    jmb.setJalviewColourScheme(new HydrophobicColourScheme());
-  }
-
-  @Override
-  public void helixColour_actionPerformed(ActionEvent actionEvent)
-  {
-    helixColour.setSelected(true);
-    jmb.setJalviewColourScheme(new HelixColourScheme());
-  }
-
-  @Override
-  public void strandColour_actionPerformed(ActionEvent actionEvent)
-  {
-    strandColour.setSelected(true);
-    jmb.setJalviewColourScheme(new StrandColourScheme());
-  }
-
-  @Override
-  public void turnColour_actionPerformed(ActionEvent actionEvent)
-  {
-    turnColour.setSelected(true);
-    jmb.setJalviewColourScheme(new TurnColourScheme());
-  }
-
-  @Override
-  public void buriedColour_actionPerformed(ActionEvent actionEvent)
-  {
-    buriedColour.setSelected(true);
-    jmb.setJalviewColourScheme(new BuriedColourScheme());
-  }
-
-  @Override
-  public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
-  {
-    setJalviewColourScheme(new PurinePyrimidineColourScheme());
-  }
-
-  @Override
-  public void userColour_actionPerformed(ActionEvent actionEvent)
-  {
-    userColour.setSelected(true);
-    new UserDefinedColours(this, null);
-  }
-
-  @Override
-  public void backGround_actionPerformed(ActionEvent actionEvent)
-  {
-    java.awt.Color col = JColorChooser
-            .showDialog(this, MessageManager
-                    .getString("label.select_backgroud_colour"), null);
-    if (col != null)
-    {
-      jmb.setBackgroundColour(col);
-    }
-  }
-
-  @Override
   public void showHelp_actionPerformed(ActionEvent actionEvent)
   {
     try
     {
-      jalview.util.BrowserLauncher
+      BrowserLauncher
               .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
     } catch (Exception ex)
     {
     }
   }
 
-  public void updateTitleAndMenus()
-  {
-    if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
-    {
-      repaint();
-      return;
-    }
-    setChainMenuItems(jmb.getChainNames());
-
-    this.setTitle(jmb.getViewerTitle("Chimera", true));
-    if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
-    {
-      viewerActionMenu.setVisible(true);
-    }
-    if (!jmb.isLoadingFromArchive())
-    {
-      seqColour_actionPerformed(null);
-    }
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
-   * @see
-   * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
-   * .ActionEvent)
-   */
-  @Override
-  protected void alignStructs_actionPerformed(ActionEvent actionEvent)
-  {
-    alignStructs_withAllAlignPanels();
-  }
-
-  private void alignStructs_withAllAlignPanels()
-  {
-    if (getAlignmentPanel() == null)
-    {
-      return;
-    }
-
-    if (_alignwith.size() == 0)
-    {
-      _alignwith.add(getAlignmentPanel());
-    }
-
-    try
-    {
-      AlignmentI[] als = new Alignment[_alignwith.size()];
-      ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
-      int[] alm = new int[_alignwith.size()];
-      int a = 0;
-
-      for (AlignmentPanel ap : _alignwith)
-      {
-        als[a] = ap.av.getAlignment();
-        alm[a] = -1;
-        alc[a++] = ap.av.getColumnSelection();
-      }
-      jmb.superposeStructures(als, alm, alc);
-    } catch (Exception e)
-    {
-      StringBuffer sp = new StringBuffer();
-      for (AlignmentPanel ap : _alignwith)
-      {
-        sp.append("'" + ap.alignFrame.getTitle() + "' ");
-      }
-      Cache.log.info("Couldn't align structures with the " + sp.toString()
-              + "associated alignment panels.", e);
-    }
-  }
-
-  @Override
-  public void setJalviewColourScheme(ColourSchemeI ucs)
-  {
-    jmb.setJalviewColourScheme(ucs);
-
-  }
-
-  /**
-   * 
-   * @param alignment
-   * @return first alignment panel displaying given alignment, or the default
-   *         alignment panel
-   */
-  public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
-  {
-    for (AlignmentPanel ap : getAllAlignmentPanels())
-    {
-      if (ap.av.getAlignment() == alignment)
-      {
-        return ap;
-      }
-    }
-    return getAlignmentPanel();
-  }
-
   @Override
   public AAStructureBindingModel getBinding()
   {
@@ -1140,8 +750,8 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   @Override
-  protected AAStructureBindingModel getBindingModel()
+  protected String getViewerName()
   {
-    return jmb;
+    return "Chimera";
   }
 }
diff --git a/src/jalview/gui/ColourMenuHelper.java b/src/jalview/gui/ColourMenuHelper.java
new file mode 100644 (file)
index 0000000..52abfe1
--- /dev/null
@@ -0,0 +1,286 @@
+package jalview.gui;
+
+import jalview.bin.Cache;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
+import jalview.schemes.ResidueColourScheme;
+import jalview.schemes.UserColourScheme;
+import jalview.util.MessageManager;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JMenu;
+import javax.swing.JRadioButtonMenuItem;
+
+public class ColourMenuHelper
+{
+  public interface ColourChangeListener
+  {
+    void changeColour_actionPerformed(String name);
+  }
+
+  /**
+   * Adds items to the colour menu, as mutually exclusive members of a button
+   * group. The callback handler is responsible for the action on selecting any
+   * of these options. The callback method receives the name of the selected
+   * colour, or "None" or "User Defined". This method returns the ButtonGroup to
+   * which items were added.
+   * <ul>
+   * <li>None</li>
+   * <li>Clustal</li>
+   * <li>...other 'built-in' colours</li>
+   * <li>...any user-defined colours</li>
+   * <li>User Defined..</li>
+   * </ul>
+   * 
+   * @param colourMenu
+   *          the menu to attach items to
+   * @param client
+   *          a callback to handle menu selection
+   * @param coll
+   *          the data the menu is being built for
+   * @param simpleOnly
+   *          if true, only simple per-residue colour schemes are included
+   */
+  public static ButtonGroup addMenuItems(final JMenu colourMenu,
+          final ColourChangeListener client, AnnotatedCollectionI coll,
+          boolean simpleOnly)
+  {
+    /*
+     * ButtonGroup groups those items whose 
+     * selection is mutually exclusive
+     */
+    ButtonGroup colours = new ButtonGroup();
+
+    if (!simpleOnly)
+    {
+      JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem(
+              MessageManager.getString("label.none"));
+      noColourmenuItem.setName(ResidueColourScheme.NONE);
+      noColourmenuItem.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          client.changeColour_actionPerformed(ResidueColourScheme.NONE);
+        }
+      });
+      colourMenu.add(noColourmenuItem);
+      colours.add(noColourmenuItem);
+    }
+
+    /*
+     * scan registered colour schemes (built-in or user-defined
+     * and add them to the menu (in the order they were added)
+     */
+    Iterable<ColourSchemeI> colourSchemes = ColourSchemes.getInstance()
+            .getColourSchemes();
+    for (ColourSchemeI scheme : colourSchemes)
+    {
+      if (simpleOnly && !scheme.isSimple())
+      {
+        continue;
+      }
+
+      /*
+       * button text is i18n'd but the name is the canonical name of
+       * the colour scheme (inspected in setColourSelected())
+       */
+      final String name = scheme.getSchemeName();
+      String label = MessageManager.getStringOrReturn("label.colourScheme_"
+              + name.toLowerCase().replace(" ", "_"), name);
+      final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(label);
+      radioItem.setName(name);
+      radioItem.setEnabled(scheme.isApplicableTo(coll));
+      if (scheme instanceof UserColourScheme)
+      {
+        /*
+         * user-defined colour scheme loaded on startup or during the
+         * Jalview session; right-click on this offers the option to
+         * remove it as a colour choice
+         */
+        radioItem.addMouseListener(new MouseAdapter()
+        {
+          @Override
+          public void mousePressed(MouseEvent evt)
+          {
+            if (evt.isPopupTrigger()) // Mac
+            {
+              offerRemoval();
+            }
+          }
+
+          @Override
+          public void mouseReleased(MouseEvent evt)
+          {
+            if (evt.isPopupTrigger()) // Windows
+            {
+              offerRemoval();
+            }
+          }
+
+          void offerRemoval()
+          {
+            ActionListener al = radioItem.getActionListeners()[0];
+            radioItem.removeActionListener(al);
+            int option = JvOptionPane.showInternalConfirmDialog(
+                    Desktop.desktop, MessageManager
+                            .getString("label.remove_from_default_list"),
+                    MessageManager
+                            .getString("label.remove_user_defined_colour"),
+                    JvOptionPane.YES_NO_OPTION);
+            if (option == JvOptionPane.YES_OPTION)
+            {
+              ColourSchemes.getInstance().removeColourScheme(
+                      radioItem.getName());
+              colourMenu.remove(radioItem);
+              updatePreferences();
+            }
+            else
+            {
+              radioItem.addActionListener(al);
+            }
+          }
+        });
+      }
+      radioItem.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent evt)
+        {
+          client.changeColour_actionPerformed(name);
+        }
+      });
+      colourMenu.add(radioItem);
+      colours.add(radioItem);
+    }
+
+    /*
+     * only add the option to load/configure a user-defined colour
+     * to the AlignFrame colour menu
+     */
+    if (client instanceof AlignFrame)
+    {
+      final String label = MessageManager.getString("action.user_defined");
+      JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem(
+              label);
+      userDefinedColour.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          client.changeColour_actionPerformed(ResidueColourScheme.USER_DEFINED);
+        }
+      });
+      colourMenu.add(userDefinedColour);
+      colours.add(userDefinedColour);
+    }
+
+    return colours;
+  }
+
+  /**
+   * Marks as selected the colour menu item matching the given name, or the
+   * first item ('None') if no match is found
+   * 
+   * @param colourMenu
+   * @param colourName
+   */
+  public static void setColourSelected(JMenu colourMenu, String colourName)
+  {
+    if (colourName == null)
+    {
+      return;
+    }
+
+    JRadioButtonMenuItem none = null;
+
+    /*
+     * select the radio button whose name matches the colour name
+     * (not the button text, as it may be internationalised)
+     */
+    for (Component menuItem : colourMenu.getMenuComponents())
+    {
+      if (menuItem instanceof JRadioButtonMenuItem)
+      {
+        String buttonName = ((JRadioButtonMenuItem) menuItem).getName();
+        if (colourName.equals(buttonName))
+        {
+          ((JRadioButtonMenuItem) menuItem).setSelected(true);
+          return;
+        }
+        if (ResidueColourScheme.NONE.equals(buttonName))
+        {
+          none = (JRadioButtonMenuItem) menuItem;
+        }
+      }
+    }
+    if (none != null)
+    {
+      none.setSelected(true);
+    }
+  }
+
+  /**
+   * Marks as selected the colour menu item matching the given colour scheme, or
+   * the first item ('None') if no match is found
+   * 
+   * @param colourMenu
+   * @param cs
+   */
+  public static void setColourSelected(JMenu colourMenu, ColourSchemeI cs)
+  {
+    setColourSelected(colourMenu, cs == null ? ResidueColourScheme.NONE
+            : cs.getSchemeName());
+  }
+
+  /**
+   * Updates the USER_DEFINE_COLOURS preference to remove any de-registered
+   * colour scheme
+   */
+  static void updatePreferences()
+  {
+    StringBuilder coloursFound = new StringBuilder();
+    String[] files = Cache.getProperty("USER_DEFINED_COLOURS").split("\\|");
+
+    /*
+     * the property does not include the scheme name, it is in the file;
+     * so just load the colour schemes and discard any whose name is not
+     * registered
+     */
+    for (String file : files)
+    {
+      try
+      {
+        UserColourScheme ucs = ColourSchemes.loadColourScheme(file);
+        if (ucs != null
+                && ColourSchemes.getInstance().nameExists(ucs.getName()))
+        {
+          if (coloursFound.length() > 0)
+          {
+            coloursFound.append("|");
+          }
+          coloursFound.append(file);
+        }
+      } catch (Exception ex)
+      {
+        System.out.println("Error loading User ColourFile\n" + ex);
+      }
+    }
+
+    if (coloursFound.toString().length() > 1)
+    {
+      Cache.setProperty("USER_DEFINED_COLOURS", coloursFound.toString());
+    }
+    else
+    {
+      Cache.applicationProperties.remove("USER_DEFINED_COLOURS");
+    }
+  }
+}
index ae911ed..ed6a3c5 100644 (file)
@@ -26,7 +26,7 @@ import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.schemes.FeatureColour;
-import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -211,7 +211,7 @@ public class FeatureRenderer extends
           FeatureColourI col = getFeatureStyle(name.getText());
           if (col == null)
           {
-            col = new FeatureColour(UserColourScheme
+            col = new FeatureColour(ColorUtils
                     .createColourFromName(name.getText()));
           }
           oldcol = fcol = col;
index d8537bb..7057c2a 100644 (file)
@@ -1186,7 +1186,7 @@ public class Jalview2XML
             }
             else
             {
-              jGroup.setColour(ColourSchemeProperty.getColourName(sg.cs));
+              jGroup.setColour(sg.cs.getSchemeName());
             }
           }
           else if (sg.cs instanceof jalview.schemes.AnnotationColourGradient)
@@ -1202,7 +1202,7 @@ public class Jalview2XML
           }
           else
           {
-            jGroup.setColour(ColourSchemeProperty.getColourName(sg.cs));
+            jGroup.setColour(sg.cs.getSchemeName());
           }
 
           jGroup.setPidThreshold(sg.cs.getThreshold());
@@ -1723,8 +1723,7 @@ public class Jalview2XML
     }
     else
     {
-      ac.setColourScheme(ColourSchemeProperty.getColourName(acg
-              .getBaseColour()));
+      ac.setColourScheme(ColourSchemeProperty.getColourName(acg.getBaseColour()));
     }
 
     ac.setMaxColour(acg.getMaxColour().getRGB());
@@ -3345,7 +3344,7 @@ public class Jalview2XML
           }
           else
           {
-            cs = ColourSchemeProperty.getColour(al, jGroup.getColour());
+            cs = ColourSchemeProperty.getColourScheme(al, jGroup.getColour());
           }
 
           if (cs != null)
@@ -4471,7 +4470,7 @@ public class Jalview2XML
       }
       else
       {
-        cs = ColourSchemeProperty.getColour(al, view.getBgColour());
+        cs = ColourSchemeProperty.getColourScheme(al, view.getBgColour());
       }
 
       if (cs != null)
@@ -4730,7 +4729,8 @@ public class Jalview2XML
                     );
           }
 
-          if (viewAnnColour.getColourScheme().equals("None"))
+          if (viewAnnColour.getColourScheme().equals(
+                  ResidueColourScheme.NONE))
           {
             cs = new AnnotationColourGradient(
                     annAlignment.getAlignmentAnnotation()[i],
@@ -4750,7 +4750,7 @@ public class Jalview2XML
           {
             cs = new AnnotationColourGradient(
                     annAlignment.getAlignmentAnnotation()[i],
-                    ColourSchemeProperty.getColour(al,
+                    ColourSchemeProperty.getColourScheme(al,
                             viewAnnColour.getColourScheme()),
                     viewAnnColour.getAboveThreshold());
           }
@@ -4778,7 +4778,7 @@ public class Jalview2XML
               }
 
               /*
-               * if (viewAnnColour.getColourScheme().equals("None" )) { sg.cs =
+               * if (viewAnnColour.getColourScheme().equals(ResidueColourScheme.NONE)) { sg.cs =
                * new AnnotationColourGradient(
                * annAlignment.getAlignmentAnnotation()[i], new
                * java.awt.Color(viewAnnColour. getMinColour()), new
index 52f61b1..aefc233 100755 (executable)
@@ -333,7 +333,7 @@ public class Jalview2XML_V1
           }
           else
           {
-            cs = ColourSchemeProperty.getColour(al, groups[i].getColour());
+            cs = ColourSchemeProperty.getColourScheme(al, groups[i].getColour());
           }
 
           if (cs != null)
@@ -401,7 +401,7 @@ public class Jalview2XML_V1
       }
       else
       {
-        cs = ColourSchemeProperty.getColour(al, view.getBgColour());
+        cs = ColourSchemeProperty.getColourScheme(al, view.getBgColour());
       }
 
       if (cs != null)
index 801b285..a797872 100644 (file)
@@ -95,7 +95,7 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding
     }
     if (!isLoadingFromArchive())
     {
-      colourBySequence(ap.av.isShowSequenceFeatures(), ap);
+      colourBySequence(ap);
     }
   }
 
index aa01bf5..58ed008 100644 (file)
@@ -193,7 +193,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
   public void bgcolour_actionPerformed(ActionEvent e)
   {
     Color col = JColorChooser.showDialog(this,
-            MessageManager.getString("label.select_backgroud_colour"),
+            MessageManager.getString("label.select_background_colour"),
             rc.bgColour);
 
     if (col != null)
index 3a99f9e..310266e 100644 (file)
@@ -38,24 +38,16 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.gui.ColourMenuHelper.ColourChangeListener;
 import jalview.io.FileFormatI;
 import jalview.io.FileFormats;
 import jalview.io.FormatAdapter;
 import jalview.io.SequenceAnnotationReport;
 import jalview.schemes.AnnotationColourGradient;
 import jalview.schemes.Blosum62ColourScheme;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.ClustalxColourScheme;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.NucleotideColourScheme;
+import jalview.schemes.ColourSchemes;
 import jalview.schemes.PIDColourScheme;
-import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.StrandColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.UserColourScheme;
-import jalview.schemes.ZappoColourScheme;
+import jalview.schemes.ResidueColourScheme;
 import jalview.util.GroupUrlLink;
 import jalview.util.GroupUrlLink.UrlStringTooLongException;
 import jalview.util.MessageManager;
@@ -71,16 +63,15 @@ import java.util.Hashtable;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.Vector;
 
-import javax.swing.ButtonGroup;
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JColorChooser;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JPopupMenu;
-import javax.swing.JRadioButtonMenuItem;
 
 /**
  * DOCUMENT ME!
@@ -88,40 +79,12 @@ import javax.swing.JRadioButtonMenuItem;
  * @author $author$
  * @version $Revision: 1.118 $
  */
-public class PopupMenu extends JPopupMenu
+public class PopupMenu extends JPopupMenu implements ColourChangeListener
 {
   JMenu groupMenu = new JMenu();
 
   JMenuItem groupName = new JMenuItem();
 
-  protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
-
-  JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
-
   protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
 
   protected JMenuItem modifyPID = new JMenuItem();
@@ -152,8 +115,6 @@ public class PopupMenu extends JPopupMenu
 
   JMenuItem outline = new JMenuItem();
 
-  JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
-
   JMenu colourMenu = new JMenu();
 
   JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
@@ -242,22 +203,6 @@ public class PopupMenu extends JPopupMenu
     this.ap = ap;
     sequence = seq;
 
-    ButtonGroup colours = new ButtonGroup();
-    colours.add(noColourmenuItem);
-    colours.add(clustalColour);
-    colours.add(zappoColour);
-    colours.add(taylorColour);
-    colours.add(hydrophobicityColour);
-    colours.add(helixColour);
-    colours.add(strandColour);
-    colours.add(turnColour);
-    colours.add(buriedColour);
-    colours.add(userDefinedColour);
-    colours.add(PIDColour);
-    colours.add(BLOSUM62Colour);
-    colours.add(purinePyrimidineColour);
-    colours.add(RNAInteractionColour);
-
     for (String ff : FileFormats.getInstance().getWritableFormats(true))
     {
       JMenuItem item = new JMenuItem(ff);
@@ -480,63 +425,7 @@ public class PopupMenu extends JPopupMenu
       groupName.setText(MessageManager
               .getString("label.edit_name_and_description_current_group"));
 
-      if (sg.cs instanceof ZappoColourScheme)
-      {
-        zappoColour.setSelected(true);
-      }
-      else if (sg.cs instanceof TaylorColourScheme)
-      {
-        taylorColour.setSelected(true);
-      }
-      else if (sg.cs instanceof PIDColourScheme)
-      {
-        PIDColour.setSelected(true);
-      }
-      else if (sg.cs instanceof Blosum62ColourScheme)
-      {
-        BLOSUM62Colour.setSelected(true);
-      }
-      else if (sg.cs instanceof UserColourScheme)
-      {
-        userDefinedColour.setSelected(true);
-      }
-      else if (sg.cs instanceof HydrophobicColourScheme)
-      {
-        hydrophobicityColour.setSelected(true);
-      }
-      else if (sg.cs instanceof HelixColourScheme)
-      {
-        helixColour.setSelected(true);
-      }
-      else if (sg.cs instanceof StrandColourScheme)
-      {
-        strandColour.setSelected(true);
-      }
-      else if (sg.cs instanceof TurnColourScheme)
-      {
-        turnColour.setSelected(true);
-      }
-      else if (sg.cs instanceof BuriedColourScheme)
-      {
-        buriedColour.setSelected(true);
-      }
-      else if (sg.cs instanceof ClustalxColourScheme)
-      {
-        clustalColour.setSelected(true);
-      }
-      else if (sg.cs instanceof PurinePyrimidineColourScheme)
-      {
-        purinePyrimidineColour.setSelected(true);
-      }
-
-      /*
-       * else if (sg.cs instanceof CovariationColourScheme) {
-       * covariationColour.setSelected(true); }
-       */
-      else
-      {
-        noColourmenuItem.setSelected(true);
-      }
+      ColourMenuHelper.setColourSelected(colourMenu, sg.cs);
 
       if (sg.cs != null)
       {
@@ -1097,7 +986,7 @@ public class PopupMenu extends JPopupMenu
         sequenceSelectionDetails_actionPerformed();
       }
     });
-    PIDColour.setFocusPainted(false);
+
     unGroupMenuItem
             .setText(MessageManager.getString("action.remove_group"));
     unGroupMenuItem.addActionListener(new ActionListener()
@@ -1128,17 +1017,6 @@ public class PopupMenu extends JPopupMenu
         outline_actionPerformed();
       }
     });
-    nucleotideMenuItem
-            .setText(MessageManager.getString("label.nucleotide"));
-    nucleotideMenuItem.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        nucleotideMenuItem_actionPerformed();
-      }
-    });
-    colourMenu.setText(MessageManager.getString("label.group_colour"));
     showBoxes.setText(MessageManager.getString("action.boxes"));
     showBoxes.setState(true);
     showBoxes.addActionListener(new ActionListener()
@@ -1169,7 +1047,7 @@ public class PopupMenu extends JPopupMenu
       }
     });
     displayNonconserved.setText(MessageManager
-            .getString("label.show_non_conversed"));
+            .getString("label.show_non_conserved"));
     displayNonconserved.setState(true);
     displayNonconserved.addActionListener(new ActionListener()
     {
@@ -1245,15 +1123,6 @@ public class PopupMenu extends JPopupMenu
         sequenceFeature_actionPerformed();
       }
     });
-    textColour.setText(MessageManager.getString("label.text_colour"));
-    textColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        textColour_actionPerformed();
-      }
-    });
     jMenu1.setText(MessageManager.getString("label.group"));
     pdbStructureDialog.setText(MessageManager
             .getString("label.show_pdbstruct_dialog"));
@@ -1345,51 +1214,10 @@ public class PopupMenu extends JPopupMenu
     sequenceMenu.add(sequenceName);
     sequenceMenu.add(sequenceDetails);
     sequenceMenu.add(makeReferenceSeq);
-    colourMenu.add(textColour);
-    colourMenu.add(noColourmenuItem);
-    colourMenu.add(clustalColour);
-    colourMenu.add(BLOSUM62Colour);
-    colourMenu.add(PIDColour);
-    colourMenu.add(zappoColour);
-    colourMenu.add(taylorColour);
-    colourMenu.add(hydrophobicityColour);
-    colourMenu.add(helixColour);
-    colourMenu.add(strandColour);
-    colourMenu.add(turnColour);
-    colourMenu.add(buriedColour);
-    colourMenu.add(nucleotideMenuItem);
-    if (ap.getAlignment().isNucleotide())
-    {
-      // JBPNote - commented since the colourscheme isn't functional
-      colourMenu.add(purinePyrimidineColour);
-    }
-    colourMenu.add(userDefinedColour);
-
-    if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
-    {
-      java.util.Enumeration userColours = jalview.gui.UserDefinedColours
-              .getUserColourSchemes().keys();
 
-      while (userColours.hasMoreElements())
-      {
-        JMenuItem item = new JMenuItem(userColours.nextElement().toString());
-        item.addActionListener(new ActionListener()
-        {
-          @Override
-          public void actionPerformed(ActionEvent evt)
-          {
-            userDefinedColour_actionPerformed(evt);
-          }
-        });
-        colourMenu.add(item);
-      }
-    }
+    initColourMenu();
+    buildColourMenu();
 
-    colourMenu.addSeparator();
-    colourMenu.add(abovePIDColour);
-    colourMenu.add(modifyPID);
-    colourMenu.add(conservationMenuItem);
-    colourMenu.add(modifyConservation);
     editMenu.add(copy);
     editMenu.add(cut);
     editMenu.add(editSequence);
@@ -1407,138 +1235,26 @@ public class PopupMenu extends JPopupMenu
     jMenu1.add(showColourText);
     jMenu1.add(outline);
     jMenu1.add(displayNonconserved);
-    noColourmenuItem.setText(MessageManager.getString("label.none"));
-    noColourmenuItem.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        noColourmenuItem_actionPerformed();
-      }
-    });
-
-    clustalColour.setText(MessageManager
-            .getString("label.clustalx_colours"));
-    clustalColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        clustalColour_actionPerformed();
-      }
-    });
-    zappoColour.setText(MessageManager.getString("label.zappo"));
-    zappoColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        zappoColour_actionPerformed();
-      }
-    });
-    taylorColour.setText(MessageManager.getString("label.taylor"));
-    taylorColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        taylorColour_actionPerformed();
-      }
-    });
-    hydrophobicityColour.setText(MessageManager
-            .getString("label.hydrophobicity"));
-    hydrophobicityColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        hydrophobicityColour_actionPerformed();
-      }
-    });
-    helixColour.setText(MessageManager.getString("label.helix_propensity"));
-    helixColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        helixColour_actionPerformed();
-      }
-    });
-    strandColour.setText(MessageManager
-            .getString("label.strand_propensity"));
-    strandColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        strandColour_actionPerformed();
-      }
-    });
-    turnColour.setText(MessageManager.getString("label.turn_propensity"));
-    turnColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        turnColour_actionPerformed();
-      }
-    });
-    buriedColour.setText(MessageManager.getString("label.buried_index"));
-    buriedColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        buriedColour_actionPerformed();
-      }
-    });
-    userDefinedColour.setText(MessageManager
-            .getString("action.user_defined"));
-    userDefinedColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        userDefinedColour_actionPerformed(e);
-      }
-    });
-    PIDColour
-            .setText(MessageManager.getString("label.percentage_identity"));
-    PIDColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        PIDColour_actionPerformed();
-      }
-    });
-    BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
-    BLOSUM62Colour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        BLOSUM62Colour_actionPerformed();
-      }
-    });
-    purinePyrimidineColour.setText(MessageManager
-            .getString("label.purine_pyrimidine"));
-    purinePyrimidineColour.addActionListener(new ActionListener()
+  }
+  
+  /**
+   * Constructs the entries for the colour menu
+   */
+  protected void initColourMenu()
+  {
+    colourMenu.setText(MessageManager.getString("label.group_colour"));
+    textColour.setText(MessageManager.getString("label.text_colour"));
+    textColour.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        purinePyrimidineColour_actionPerformed();
+        textColour_actionPerformed();
       }
     });
 
-    /*
-     * covariationColour.addActionListener(new ActionListener() {
-     * public void actionPerformed(ActionEvent e) {
-     * covariationColour_actionPerformed(); } });
-     */
     abovePIDColour.setText(MessageManager
-            .getString("label.above_identity_percentage"));
+            .getString("label.above_identity_threshold"));
     abovePIDColour.addActionListener(new ActionListener()
     {
       @Override
@@ -1560,7 +1276,7 @@ public class PopupMenu extends JPopupMenu
     });
 
     conservationMenuItem.setText(MessageManager
-            .getString("label.conservation"));
+            .getString("action.by_conservation"));
     conservationMenuItem.addActionListener(new ActionListener()
     {
       @Override
@@ -1582,6 +1298,33 @@ public class PopupMenu extends JPopupMenu
     });
   }
 
+  /**
+   * Builds the group colour sub-menu, including any user-defined colours which
+   * were loaded at startup or during the Jalview session
+   */
+  protected void buildColourMenu()
+  {
+    SequenceGroup sg = ap.av.getSelectionGroup();
+    if (sg == null)
+    {
+      /*
+       * popup menu with no sequence group scope
+       */
+      return;
+    }
+    colourMenu.removeAll();
+    colourMenu.add(textColour);
+    colourMenu.addSeparator();
+
+    ColourMenuHelper.addMenuItems(colourMenu, this, sg, false);
+
+    colourMenu.addSeparator();
+    colourMenu.add(conservationMenuItem);
+    colourMenu.add(modifyConservation);
+    colourMenu.add(abovePIDColour);
+    colourMenu.add(modifyPID);
+  }
+
   protected void modifyConservation_actionPerformed()
   {
     SequenceGroup sg = getGroup();
@@ -1628,7 +1371,7 @@ public class PopupMenu extends JPopupMenu
      * Temporary store to hold distinct calcId / type pairs for the tooltip.
      * Using TreeMap means calcIds are shown in alphabetical order.
      */
-    Map<String, String> tipEntries = new TreeMap<String, String>();
+    SortedMap<String, String> tipEntries = new TreeMap<String, String>();
     final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
     AlignmentI al = this.ap.av.getAlignment();
     AlignmentUtils.findAddableReferenceAnnotations(forSequences,
@@ -1777,121 +1520,6 @@ public class PopupMenu extends JPopupMenu
     PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
   }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  protected void clustalColour_actionPerformed()
-  {
-    SequenceGroup sg = getGroup();
-    sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
-    refresh();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  protected void zappoColour_actionPerformed()
-  {
-    getGroup().cs = new ZappoColourScheme();
-    refresh();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  protected void taylorColour_actionPerformed()
-  {
-    getGroup().cs = new TaylorColourScheme();
-    refresh();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  protected void hydrophobicityColour_actionPerformed()
-  {
-    getGroup().cs = new HydrophobicColourScheme();
-    refresh();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  protected void helixColour_actionPerformed()
-  {
-    getGroup().cs = new HelixColourScheme();
-    refresh();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  protected void strandColour_actionPerformed()
-  {
-    getGroup().cs = new StrandColourScheme();
-    refresh();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  protected void turnColour_actionPerformed()
-  {
-    getGroup().cs = new TurnColourScheme();
-    refresh();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  protected void buriedColour_actionPerformed()
-  {
-    getGroup().cs = new BuriedColourScheme();
-    refresh();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  public void nucleotideMenuItem_actionPerformed()
-  {
-    getGroup().cs = new NucleotideColourScheme();
-    refresh();
-  }
-
-  protected void purinePyrimidineColour_actionPerformed()
-  {
-    getGroup().cs = new PurinePyrimidineColourScheme();
-    refresh();
-  }
-
   /*
    * protected void covariationColour_actionPerformed() { getGroup().cs = new
    * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
@@ -1936,30 +1564,6 @@ public class PopupMenu extends JPopupMenu
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  protected void userDefinedColour_actionPerformed(ActionEvent e)
-  {
-    SequenceGroup sg = getGroup();
-
-    if (e.getSource().equals(userDefinedColour))
-    {
-      new UserDefinedColours(ap, sg);
-    }
-    else
-    {
-      UserColourScheme udc = (UserColourScheme) UserDefinedColours
-              .getUserColourSchemes().get(e.getActionCommand());
-
-      sg.cs = udc;
-    }
-    refresh();
-  }
-
-  /**
    * Open a panel where the user can choose which types of sequence annotation
    * to show or hide.
    * 
@@ -1977,53 +1581,6 @@ public class PopupMenu extends JPopupMenu
    * @param e
    *          DOCUMENT ME!
    */
-  protected void PIDColour_actionPerformed()
-  {
-    SequenceGroup sg = getGroup();
-    sg.cs = new PIDColourScheme();
-    sg.cs.setConsensus(AAFrequency.calculate(
-            sg.getSequences(ap.av.getHiddenRepSequences()),
-            sg.getStartRes(), sg.getEndRes() + 1));
-    refresh();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  protected void BLOSUM62Colour_actionPerformed()
-  {
-    SequenceGroup sg = getGroup();
-
-    sg.cs = new Blosum62ColourScheme();
-
-    sg.cs.setConsensus(AAFrequency.calculate(
-            sg.getSequences(ap.av.getHiddenRepSequences()),
-            sg.getStartRes(), sg.getEndRes() + 1));
-
-    refresh();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
-  protected void noColourmenuItem_actionPerformed()
-  {
-    getGroup().cs = null;
-    refresh();
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
-   */
   protected void conservationMenuItem_actionPerformed()
   {
     SequenceGroup sg = getGroup();
@@ -2332,8 +1889,7 @@ public class PopupMenu extends JPopupMenu
     // or we simply trust the user wants
     // wysiwig behaviour
 
-    FileFormatI fileFormat = FileFormats.getInstance().forName(
-            e.getActionCommand());
+    FileFormatI fileFormat = FileFormats.getInstance().forName(e.getActionCommand());
     cap.setText(new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
   }
 
@@ -2438,4 +1994,38 @@ public class PopupMenu extends JPopupMenu
     }
   }
 
+  /**
+   * Action on user selecting an item from the colour menu (that does not have
+   * its bespoke action handler)
+   */
+  @Override
+  public void changeColour_actionPerformed(String colourSchemeName)
+  {
+    SequenceGroup sg = getGroup();
+    if (ResidueColourScheme.USER_DEFINED.equals(colourSchemeName))
+    {
+      /*
+       * open a panel to load or configure a user-defined colour scheme
+       */
+      new UserDefinedColours(ap, sg);
+    }
+    else
+    {
+      /*
+       * switch to the chosen colour scheme (or null for None)
+       */
+      sg.cs = ColourSchemes.getInstance().getColourScheme(colourSchemeName,
+              sg, ap.av.getHiddenRepSequences());
+      if (sg.cs instanceof Blosum62ColourScheme
+              || sg.cs instanceof PIDColourScheme)
+      {
+        sg.cs.setConsensus(AAFrequency.calculate(
+                sg.getSequences(ap.av.getHiddenRepSequences()),
+                sg.getStartRes(), sg.getEndRes() + 1));
+      }
+    }
+
+    refresh();
+  }
+
 }
index 422745a..d32ff46 100755 (executable)
@@ -34,7 +34,9 @@ import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
 import jalview.jbgui.GPreferences;
 import jalview.jbgui.GSequenceLink;
-import jalview.schemes.ColourSchemeProperty;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
+import jalview.schemes.ResidueColourScheme;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.sifts.SiftsSettings;
@@ -290,12 +292,16 @@ public class Preferences extends GPreferences
     /*
      * Set Colours tab defaults
      */
-    for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++)
+    protColour.addItem(ResidueColourScheme.NONE);
+    nucColour.addItem(ResidueColourScheme.NONE);
+    for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
     {
-      protColour.addItem(ColourSchemeProperty.getColourName(i));
-      nucColour.addItem(ColourSchemeProperty.getColourName(i));
+      String name = cs.getSchemeName();
+      protColour.addItem(name);
+      nucColour.addItem(name);
     }
-    String oldProp = Cache.getDefault(DEFAULT_COLOUR, "None");
+    String oldProp = Cache.getDefault(DEFAULT_COLOUR,
+            ResidueColourScheme.NONE);
     String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
     protColour.setSelectedItem(newProp != null ? newProp : oldProp);
     newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
index af77c48..83193dc 100755 (executable)
@@ -159,25 +159,37 @@ public class SliderPanel extends GSliderPanel
     return sp.getValue();
   }
 
+  /**
+   * Hides the PID slider panel if it is shown
+   */
   public static void hidePIDSlider()
   {
-    try
-    {
-      PIDSlider.setClosed(true);
-      PIDSlider = null;
-    } catch (PropertyVetoException ex)
+    if (PIDSlider != null)
     {
+      try
+      {
+        PIDSlider.setClosed(true);
+        PIDSlider = null;
+      } catch (PropertyVetoException ex)
+      {
+      }
     }
   }
 
+  /**
+   * Hides the conservation slider panel if it is shown
+   */
   public static void hideConservationSlider()
   {
-    try
-    {
-      conservationSlider.setClosed(true);
-      conservationSlider = null;
-    } catch (PropertyVetoException ex)
+    if (conservationSlider != null)
     {
+      try
+      {
+        conservationSlider.setClosed(true);
+        conservationSlider = null;
+      } catch (PropertyVetoException ex)
+      {
+      }
     }
   }
 
index 91d7130..34ad659 100644 (file)
  */
 package jalview.gui;
 
+import jalview.bin.Cache;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.gui.StructureViewer.ViewerType;
 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
 import jalview.io.DataSourceType;
+import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
 import jalview.jbgui.GStructureViewer;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.MessageManager;
 
+import java.awt.Color;
 import java.awt.Component;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Vector;
 
+import javax.swing.ButtonGroup;
 import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JColorChooser;
+import javax.swing.JMenu;
 import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
 
 /**
  * Base class with common functionality for JMol, Chimera or other structure
@@ -52,6 +72,13 @@ import javax.swing.JOptionPane;
 public abstract class StructureViewerBase extends GStructureViewer
         implements Runnable, ViewSetProvider
 {
+  /*
+   * names for colour options (additional to Jalview colour schemes)
+   */
+  enum ViewerColour
+  {
+    BySequence, ByChain, ChargeCysteine, ByViewer
+  }
 
   /**
    * list of sequenceSet ids associated with the view
@@ -84,6 +111,13 @@ public abstract class StructureViewerBase extends GStructureViewer
   protected boolean allChainsSelected = false;
 
   /**
+   * Default constructor
+   */
+  public StructureViewerBase()
+  {
+    super();
+  }
+  /**
    * 
    * @param ap2
    * @return true if this Jmol instance is linked with the given alignPanel
@@ -273,8 +307,6 @@ public abstract class StructureViewerBase extends GStructureViewer
 
   public abstract ViewerType getViewerType();
 
-  protected abstract AAStructureBindingModel getBindingModel();
-
   /**
    * add a new structure (with associated sequences and chains) to this viewer,
    * retrieving it if necessary first.
@@ -320,7 +352,7 @@ public abstract class StructureViewerBase extends GStructureViewer
       }
     }
     // otherwise, start adding the structure.
-    getBindingModel().addSequenceAndChain(new PDBEntry[] { pdbentry },
+    getBinding().addSequenceAndChain(new PDBEntry[] { pdbentry },
             new SequenceI[][] { seqs }, new String[][] { chains });
     addingStructures = true;
     _started = false;
@@ -350,7 +382,10 @@ public abstract class StructureViewerBase extends GStructureViewer
     return option;
   }
 
-  protected abstract boolean hasPdbId(String pdbId);
+  protected boolean hasPdbId(String pdbId)
+  {
+    return getBinding().hasPdbId(pdbId);
+  }
 
   protected abstract List<StructureViewerBase> getViewersFor(
           AlignmentPanel alp);
@@ -438,7 +473,7 @@ public abstract class StructureViewerBase extends GStructureViewer
     // JBPNOTE: this looks like a binding routine, rather than a gui routine
     for (StructureViewerBase viewer : getViewersFor(null))
     {
-      AAStructureBindingModel bindingModel = viewer.getBindingModel();
+      AAStructureBindingModel bindingModel = viewer.getBinding();
       for (int pe = 0; pe < bindingModel.getPdbCount(); pe++)
       {
         if (bindingModel.getPdbEntry(pe).getFile().equals(pdbFilename))
@@ -552,4 +587,389 @@ public abstract class StructureViewerBase extends GStructureViewer
 
   abstract void showSelectedChains();
 
+  /**
+   * Action on selecting one of Jalview's registered colour schemes
+   */
+  @Override
+  public void changeColour_actionPerformed(String colourSchemeName)
+  {
+    AlignmentI al = getAlignmentPanel().av.getAlignment();
+    ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(
+            colourSchemeName, al, null);
+    getBinding().setJalviewColourScheme(cs);
+  }
+
+  /**
+   * Builds the colour menu
+   */
+  protected void buildColourMenu()
+  {
+    colourMenu.removeAll();
+    AlignmentI al = getAlignmentPanel().av.getAlignment();
+
+    /*
+     * add colour by sequence, by chain, by charge and cysteine
+     */
+    colourMenu.add(seqColour);
+    colourMenu.add(chainColour);
+    colourMenu.add(chargeColour);
+    chargeColour.setEnabled(!al.isNucleotide());
+
+    /*
+     * add all 'simple' (per-residue) colour schemes registered to Jalview
+     */
+    ButtonGroup itemGroup = ColourMenuHelper.addMenuItems(colourMenu, this,
+            al, true);
+
+    /*
+     * add 'colour by viewer' (menu item text is set in subclasses)
+     */
+    viewerColour.setSelected(false);
+    viewerColour.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        viewerColour_actionPerformed(actionEvent);
+      }
+    });
+    colourMenu.add(viewerColour);
+
+    /*
+     * add 'set background colour'
+     */
+    JMenuItem backGround = new JMenuItem();
+    backGround
+            .setText(MessageManager.getString("action.background_colour"));
+    backGround.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        background_actionPerformed(actionEvent);
+      }
+    });
+    colourMenu.add(backGround);
+
+    /*
+     * add colour buttons to a group so their selection is
+     * mutually exclusive (background colour is a separate option)
+     */
+    itemGroup.add(seqColour);
+    itemGroup.add(chainColour);
+    itemGroup.add(chargeColour);
+    itemGroup.add(viewerColour);
+  }
+
+  /**
+   * Construct menu items
+   */
+  protected void initMenus()
+  {
+    AAStructureBindingModel binding = getBinding();
+
+    seqColour = new JRadioButtonMenuItem();
+    seqColour.setText(MessageManager.getString("action.by_sequence"));
+    seqColour.setName(ViewerColour.BySequence.name());
+    seqColour.setSelected(binding.isColourBySequence());
+    seqColour.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        seqColour_actionPerformed(actionEvent);
+      }
+    });
+
+    chainColour = new JRadioButtonMenuItem();
+    chainColour.setText(MessageManager.getString("action.by_chain"));
+    chainColour.setName(ViewerColour.ByChain.name());
+    chainColour.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        chainColour_actionPerformed(actionEvent);
+      }
+    });
+
+    chargeColour = new JRadioButtonMenuItem();
+    chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
+    chargeColour.setName(ViewerColour.ChargeCysteine.name());
+    chargeColour.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        chargeColour_actionPerformed(actionEvent);
+      }
+    });
+
+    viewerColour = new JRadioButtonMenuItem();
+    // text is set in overrides of this method
+    viewerColour.setName(ViewerColour.ByViewer.name());
+    viewerColour.setSelected(!binding.isColourBySequence());
+
+    if (_colourwith == null)
+    {
+      _colourwith = new Vector<AlignmentPanel>();
+    }
+    if (_alignwith == null)
+    {
+      _alignwith = new Vector<AlignmentPanel>();
+    }
+
+    ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
+            MessageManager.getString("label.colour_by"), this, _colourwith,
+            new ItemListener()
+            {
+              @Override
+              public void itemStateChanged(ItemEvent e)
+              {
+                if (!seqColour.isSelected())
+                {
+                  seqColour.doClick();
+                }
+                else
+                {
+                  // update the Chimera display now.
+                  seqColour_actionPerformed(null);
+                }
+              }
+            });
+    viewMenu.add(seqColourBy);
+
+    final ItemListener handler = new ItemListener()
+    {
+      @Override
+      public void itemStateChanged(ItemEvent e)
+      {
+        alignStructs.setEnabled(_alignwith.size() > 0);
+        alignStructs.setToolTipText(MessageManager.formatMessage(
+                "label.align_structures_using_linked_alignment_views",
+                new String[] { String.valueOf(_alignwith.size()) }));
+      }
+    };
+    JMenu alpanels = new ViewSelectionMenu(
+            MessageManager.getString("label.superpose_with"), this,
+            _alignwith, handler);
+    handler.itemStateChanged(null);
+    viewerActionMenu.add(alpanels);
+    viewerActionMenu.addMenuListener(new MenuListener()
+    {
+      @Override
+      public void menuSelected(MenuEvent e)
+      {
+        handler.itemStateChanged(null);
+      }
+
+      @Override
+      public void menuDeselected(MenuEvent e)
+      {
+      }
+
+      @Override
+      public void menuCanceled(MenuEvent e)
+      {
+      }
+    });
+
+    buildColourMenu();
+  }
+
+  @Override
+  public void setJalviewColourScheme(ColourSchemeI cs) {
+    getBinding().setJalviewColourScheme(cs);
+  }
+  @Override
+  protected void alignStructs_actionPerformed(ActionEvent actionEvent)
+  {
+    alignStructs_withAllAlignPanels();
+  }
+  protected void alignStructs_withAllAlignPanels()
+  {
+    if (getAlignmentPanel() == null)
+    {
+      return;
+    }
+  
+    if (_alignwith.size() == 0)
+    {
+      _alignwith.add(getAlignmentPanel());
+    }
+  
+    try
+    {
+      AlignmentI[] als = new Alignment[_alignwith.size()];
+      ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
+      int[] alm = new int[_alignwith.size()];
+      int a = 0;
+  
+      for (AlignmentPanel ap : _alignwith)
+      {
+        als[a] = ap.av.getAlignment();
+        alm[a] = -1;
+        alc[a++] = ap.av.getColumnSelection();
+      }
+      getBinding().superposeStructures(als, alm, alc);
+    } catch (Exception e)
+    {
+      StringBuffer sp = new StringBuffer();
+      for (AlignmentPanel ap : _alignwith)
+      {
+        sp.append("'" + ap.alignFrame.getTitle() + "' ");
+      }
+      Cache.log.info("Couldn't align structures with the " + sp.toString()
+              + "associated alignment panels.", e);
+    }
+  }
+  @Override
+  public void background_actionPerformed(ActionEvent actionEvent)
+  {
+    Color col = JColorChooser.showDialog(this,
+            MessageManager.getString("label.select_background_colour"),
+            null);
+    if (col != null)
+    {
+      getBinding().setBackgroundColour(col);
+    }
+  }
+  @Override
+  public void viewerColour_actionPerformed(ActionEvent actionEvent)
+  {
+    if (viewerColour.isSelected())
+    {
+      // disable automatic sequence colouring.
+      getBinding().setColourBySequence(false);
+    }
+  }
+  @Override
+  public void chainColour_actionPerformed(ActionEvent actionEvent)
+  {
+    chainColour.setSelected(true);
+    getBinding().colourByChain();
+  }
+  @Override
+  public void chargeColour_actionPerformed(ActionEvent actionEvent)
+  {
+    chargeColour.setSelected(true);
+    getBinding().colourByCharge();
+  }
+  @Override
+  public void seqColour_actionPerformed(ActionEvent actionEvent)
+  {
+    AAStructureBindingModel binding = getBinding();
+    binding.setColourBySequence(seqColour.isSelected());
+    if (_colourwith == null)
+    {
+      _colourwith = new Vector<AlignmentPanel>();
+    }
+    if (binding.isColourBySequence())
+    {
+      if (!binding.isLoadingFromArchive())
+      {
+        if (_colourwith.size() == 0 && getAlignmentPanel() != null)
+        {
+          // Make the currently displayed alignment panel the associated view
+          _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
+        }
+      }
+      // Set the colour using the current view for the associated alignframe
+      for (AlignmentPanel ap : _colourwith)
+      {
+        binding.colourBySequence(ap);
+      }
+    }
+  }
+  @Override
+  public void pdbFile_actionPerformed(ActionEvent actionEvent)
+  {
+    JalviewFileChooser chooser = new JalviewFileChooser(
+            Cache.getProperty("LAST_DIRECTORY"));
+  
+    chooser.setFileView(new JalviewFileView());
+    chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
+    chooser.setToolTipText(MessageManager.getString("action.save"));
+  
+    int value = chooser.showSaveDialog(this);
+  
+    if (value == JalviewFileChooser.APPROVE_OPTION)
+    {
+      BufferedReader in = null;
+      try
+      {
+        // TODO: cope with multiple PDB files in view
+        in = new BufferedReader(
+                new FileReader(getBinding().getPdbFile()[0]));
+        File outFile = chooser.getSelectedFile();
+  
+        PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
+        String data;
+        while ((data = in.readLine()) != null)
+        {
+          if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
+          {
+            out.println(data);
+          }
+        }
+        out.close();
+      } catch (Exception ex)
+      {
+        ex.printStackTrace();
+      } finally
+      {
+        if (in != null)
+        {
+          try
+          {
+            in.close();
+          } catch (IOException e)
+          {
+            // ignore
+          }
+        }
+      }
+    }
+  }
+  @Override
+  public void viewMapping_actionPerformed(ActionEvent actionEvent)
+  {
+    CutAndPasteTransfer cap = new CutAndPasteTransfer();
+    try
+    {
+      cap.appendText(getBinding().printMappings());
+    } catch (OutOfMemoryError e)
+    {
+      new OOMWarning(
+              "composing sequence-structure alignments for display in text box.",
+              e);
+      cap.dispose();
+      return;
+    }
+    Desktop.addInternalFrame(cap,
+            MessageManager.getString("label.pdb_sequence_mapping"), 550,
+            600);
+  }
+
+  protected abstract String getViewerName();
+  public void updateTitleAndMenus()
+  {
+    AAStructureBindingModel binding = getBinding();
+    if (binding.hasFileLoadingError())
+    {
+      repaint();
+      return;
+    }
+    setChainMenuItems(binding.getChainNames());
+  
+    this.setTitle(binding.getViewerTitle(getViewerName(), true));
+    if (binding.getPdbFile().length > 1 && binding.getSequence().length > 1)
+    {
+      viewerActionMenu.setVisible(true);
+    }
+    if (!binding.isLoadingFromArchive())
+    {
+      seqColour_actionPerformed(null);
+    }
+  }
 }
index 84fd82f..8ad5699 100755 (executable)
@@ -997,8 +997,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         }
         else
         {
-          cs = ColourSchemeProperty.getColour(sg, ColourSchemeProperty
-                  .getColourName(av.getGlobalColourScheme()));
+          cs = ColourSchemeProperty.getColourScheme(sg,
+                  ColourSchemeProperty.getColourName(av
+                          .getGlobalColourScheme()));
         }
         // cs is null if shading is an annotationColourGradient
         if (cs != null)
index 0df23e0..012edb6 100755 (executable)
@@ -26,25 +26,28 @@ import jalview.datamodel.SequenceGroup;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
 import jalview.jbgui.GUserDefinedColours;
+import jalview.schemabinding.version2.Colour;
+import jalview.schemabinding.version2.JalviewUserColours;
 import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
 import jalview.schemes.ResidueProperties;
 import jalview.schemes.UserColourScheme;
 import jalview.util.ColorUtils;
+import jalview.util.Format;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
 import java.awt.Font;
+import java.awt.Insets;
 import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.StringTokenizer;
+import java.util.List;
 
 import javax.swing.JButton;
 import javax.swing.JInternalFrame;
@@ -61,6 +64,12 @@ import javax.swing.event.ChangeListener;
 public class UserDefinedColours extends GUserDefinedColours implements
         ChangeListener
 {
+  private static final Font VERDANA_BOLD_10 = new Font("Verdana", Font.BOLD, 10);
+
+  public static final String USER_DEFINED_COLOURS = "USER_DEFINED_COLOURS";
+
+  private static final String LAST_DIRECTORY = "LAST_DIRECTORY";
+
   private static final int MY_FRAME_HEIGHT = 420;
 
   private static final int MY_FRAME_WIDTH = 810;
@@ -71,25 +80,23 @@ public class UserDefinedColours extends GUserDefinedColours implements
 
   SequenceGroup seqGroup;
 
-  ArrayList<JButton> selectedButtons;
+  List<JButton> selectedButtons;
 
   ColourSchemeI oldColourScheme;
 
   JInternalFrame frame;
 
-  JalviewStructureDisplayI jmol;
+  JalviewStructureDisplayI structureViewer;
 
-  ArrayList<JButton> upperCaseButtons;
+  List<JButton> upperCaseButtons;
 
-  ArrayList<JButton> lowerCaseButtons;
+  List<JButton> lowerCaseButtons;
 
   /**
    * Creates a new UserDefinedColours object.
    * 
    * @param ap
-   *          DOCUMENT ME!
    * @param sg
-   *          DOCUMENT ME!
    */
   public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
   {
@@ -111,7 +118,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
 
     if (oldColourScheme instanceof UserColourScheme)
     {
-      schemeName.setText(((UserColourScheme) oldColourScheme).getName());
+      schemeName.setText(oldColourScheme.getSchemeName());
       if (((UserColourScheme) oldColourScheme).getLowerCaseColours() != null)
       {
         caseSensitive.setSelected(true);
@@ -131,11 +138,11 @@ public class UserDefinedColours extends GUserDefinedColours implements
     showFrame();
   }
 
-  public UserDefinedColours(JalviewStructureDisplayI jmol,
+  public UserDefinedColours(JalviewStructureDisplayI viewer,
           ColourSchemeI oldcs)
   {
     super();
-    this.jmol = jmol;
+    this.structureViewer = viewer;
 
     colorChooser.getSelectionModel().addChangeListener(this);
 
@@ -143,7 +150,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
 
     if (oldColourScheme instanceof UserColourScheme)
     {
-      schemeName.setText(((UserColourScheme) oldColourScheme).getName());
+      schemeName.setText(((UserColourScheme) oldColourScheme).getSchemeName());
     }
 
     resetButtonPanel(false);
@@ -167,7 +174,15 @@ public class UserDefinedColours extends GUserDefinedColours implements
     }
   }
 
-  void resetButtonPanel(boolean caseSensitive)
+  /**
+   * Rebuilds the panel with coloured buttons for residues. If not case
+   * sensitive colours, show 3-letter amino acid code as button text. If case
+   * sensitive, just show the single letter code, in order to make space for the
+   * additional buttons.
+   * 
+   * @param isCaseSensitive
+   */
+  void resetButtonPanel(boolean isCaseSensitive)
   {
     buttonPanel.removeAll();
 
@@ -176,23 +191,13 @@ public class UserDefinedColours extends GUserDefinedColours implements
       upperCaseButtons = new ArrayList<JButton>();
     }
 
-    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);
-
+      String label = isCaseSensitive ? ResidueProperties.aa[i]
+              : ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
+                      .toString();
+      JButton button = makeButton(label, ResidueProperties.aa[i],
+              upperCaseButtons, i);
       buttonPanel.add(button);
     }
 
@@ -201,7 +206,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
     buttonPanel.add(makeButton("X", "X", upperCaseButtons, 22));
     buttonPanel.add(makeButton("Gap", "-", upperCaseButtons, 23));
 
-    if (!caseSensitive)
+    if (!isCaseSensitive)
     {
       gridLayout.setRows(6);
       gridLayout.setColumns(4);
@@ -221,14 +226,14 @@ public class UserDefinedColours extends GUserDefinedColours implements
       {
         int row = i / cols + 1;
         int index = (row * cols) + i;
-        button = makeButton(ResidueProperties.aa[i].toLowerCase(),
+        JButton button = makeButton(ResidueProperties.aa[i].toLowerCase(),
                 ResidueProperties.aa[i].toLowerCase(), lowerCaseButtons, i);
 
         buttonPanel.add(button, index);
       }
     }
 
-    if (caseSensitive)
+    if (isCaseSensitive)
     {
       buttonPanel.add(makeButton("b", "b", lowerCaseButtons, 20));
       buttonPanel.add(makeButton("z", "z", lowerCaseButtons, 21));
@@ -239,7 +244,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
     // codes
     if (this.frame != null)
     {
-      int newWidth = caseSensitive ? MY_FRAME_WIDTH_CASE_SENSITIVE
+      int newWidth = isCaseSensitive ? MY_FRAME_WIDTH_CASE_SENSITIVE
               : MY_FRAME_WIDTH;
       this.frame.setSize(newWidth, this.frame.getHeight());
     }
@@ -384,28 +389,35 @@ public class UserDefinedColours extends GUserDefinedColours implements
   }
 
   /**
-   * DOCUMENT ME!
+   * A helper method to update or make a colour button, whose background colour
+   * is the associated colour, and text colour a darker shade of the same. If
+   * the button is already in the list, then its text and margins are updated,
+   * if not then it is created and added. This method supports toggling between
+   * case-sensitive and case-insensitive button panels. The case-sensitive
+   * version has abbreviated button text in order to fit in more buttons.
    * 
    * @param label
-   *          DOCUMENT ME!
-   * @param aa
-   *          DOCUMENT ME!
+   * @param residue
+   * @param the
+   *          list of buttons
+   * @param buttonIndex
+   *          the button's position in the list
    */
-  JButton makeButton(String label, String aa,
-          ArrayList<JButton> caseSensitiveButtons, int buttonIndex)
+  JButton makeButton(String label, String residue,
+          List<JButton> buttons, int buttonIndex)
   {
     final JButton button;
     Color col;
 
-    if (buttonIndex < caseSensitiveButtons.size())
+    if (buttonIndex < buttons.size())
     {
-      button = caseSensitiveButtons.get(buttonIndex);
+      button = buttons.get(buttonIndex);
       col = button.getBackground();
     }
     else
     {
       button = new JButton();
-      button.addMouseListener(new java.awt.event.MouseAdapter()
+      button.addMouseListener(new MouseAdapter()
       {
         @Override
         public void mouseClicked(MouseEvent e)
@@ -414,46 +426,44 @@ public class UserDefinedColours extends GUserDefinedColours implements
         }
       });
 
-      caseSensitiveButtons.add(button);
+      buttons.add(button);
 
+      /*
+       * make initial button colour that of the current colour scheme,
+       * if it is a simple per-residue colouring, else white
+       */
       col = Color.white;
-      if (oldColourScheme != null)
+      if (oldColourScheme != null && oldColourScheme.isSimple())
       {
-        try
-        {
-          col = oldColourScheme.findColour(aa.charAt(0), -1, null);
-        } catch (Exception ex)
-        {
-        }
+        col = oldColourScheme.findColour(residue.charAt(0));
       }
     }
 
     if (caseSensitive.isSelected())
     {
-      button.setMargin(new java.awt.Insets(2, 2, 2, 2));
+      button.setMargin(new Insets(2, 2, 2, 2));
     }
     else
     {
-      button.setMargin(new java.awt.Insets(2, 14, 2, 14));
+      button.setMargin(new Insets(2, 14, 2, 14));
     }
 
     button.setOpaque(true); // required for the next line to have effect
     button.setBackground(col);
     button.setText(label);
     button.setForeground(ColorUtils.darkerThan(col));
-    button.setFont(new java.awt.Font("Verdana", Font.BOLD, 10));
+    button.setFont(VERDANA_BOLD_10);
 
     return button;
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
+   * On 'OK', check that at least one colour has been assigned to a residue (and
+   * if not issue a warning), and apply the chosen colour scheme and close the
+   * panel.
    */
   @Override
-  protected void okButton_actionPerformed(ActionEvent e)
+  protected void okButton_actionPerformed()
   {
     if (isNoSelectionMade())
     {
@@ -464,7 +474,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
     }
     else
     {
-      applyButton_actionPerformed(null);
+      applyButton_actionPerformed();
 
       try
       {
@@ -493,13 +503,11 @@ public class UserDefinedColours extends GUserDefinedColours implements
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
+   * Applies the current colour scheme to the alignment, sequence group or
+   * structure view.
    */
   @Override
-  protected void applyButton_actionPerformed(ActionEvent e)
+  protected void applyButton_actionPerformed()
   {
     if (isNoSelectionMade())
     {
@@ -510,7 +518,6 @@ public class UserDefinedColours extends GUserDefinedColours implements
 
     }
     UserColourScheme ucs = getSchemeFromButtons();
-    ucs.setName(schemeName.getText());
 
     if (seqGroup != null)
     {
@@ -521,9 +528,9 @@ public class UserDefinedColours extends GUserDefinedColours implements
     {
       ap.alignFrame.changeColour(ucs);
     }
-    else if (jmol != null)
+    else if (structureViewer != null)
     {
-      jmol.setJalviewColourScheme(ucs);
+      structureViewer.setJalviewColourScheme(ucs);
     }
   }
 
@@ -552,6 +559,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
     }
 
     UserColourScheme ucs = new UserColourScheme(newColours);
+    ucs.setName(schemeName.getText());
 
     if (caseSensitive.isSelected())
     {
@@ -598,8 +606,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
     lowerCaseButtons = new ArrayList<JButton>();
 
     JalviewFileChooser chooser = new JalviewFileChooser(
-            Cache.getProperty("LAST_DIRECTORY"), "jc",
-            "Jalview User Colours");
+            Cache.getProperty(LAST_DIRECTORY), "jc", "Jalview User Colours");
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
             .getString("label.load_colour_scheme"));
@@ -607,80 +614,67 @@ public class UserDefinedColours extends GUserDefinedColours implements
 
     int value = chooser.showOpenDialog(this);
 
-    if (value == JalviewFileChooser.APPROVE_OPTION)
+    if (value != JalviewFileChooser.APPROVE_OPTION)
     {
-      File choice = chooser.getSelectedFile();
-      jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
-      String defaultColours = jalview.bin.Cache.getDefault(
-              "USER_DEFINED_COLOURS", choice.getPath());
-      if (defaultColours.indexOf(choice.getPath()) == -1)
-      {
-        defaultColours = defaultColours.concat("|")
-                .concat(choice.getPath());
-      }
-
-      jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", defaultColours);
-
-      UserColourScheme ucs = loadColours(choice.getAbsolutePath());
-      Color[] colors = ucs.getColours();
-      schemeName.setText(ucs.getName());
-
-      if (ucs.getLowerCaseColours() != null)
-      {
-        caseSensitive.setSelected(true);
-        lcaseColour.setEnabled(true);
-        resetButtonPanel(true);
-        for (int i = 0; i < lowerCaseButtons.size(); i++)
-        {
-          JButton button = lowerCaseButtons.get(i);
-          button.setBackground(ucs.getLowerCaseColours()[i]);
-        }
+      return;
+    }
+    File choice = chooser.getSelectedFile();
+    Cache.setProperty(LAST_DIRECTORY, choice.getParent());
 
-      }
-      else
-      {
-        caseSensitive.setSelected(false);
-        lcaseColour.setEnabled(false);
-        resetButtonPanel(false);
-      }
+    UserColourScheme ucs = ColourSchemes.loadColourScheme(choice.getAbsolutePath());
+    Color[] colors = ucs.getColours();
+    schemeName.setText(ucs.getSchemeName());
 
-      for (int i = 0; i < upperCaseButtons.size(); i++)
+    if (ucs.getLowerCaseColours() != null)
+    {
+      caseSensitive.setSelected(true);
+      lcaseColour.setEnabled(true);
+      resetButtonPanel(true);
+      for (int i = 0; i < lowerCaseButtons.size(); i++)
       {
-        JButton button = upperCaseButtons.get(i);
-        button.setBackground(colors[i]);
+        JButton button = lowerCaseButtons.get(i);
+        button.setBackground(ucs.getLowerCaseColours()[i]);
       }
+    }
+    else
+    {
+      caseSensitive.setSelected(false);
+      lcaseColour.setEnabled(false);
+      resetButtonPanel(false);
+    }
 
+    for (int i = 0; i < upperCaseButtons.size(); i++)
+    {
+      JButton button = upperCaseButtons.get(i);
+      button.setBackground(colors[i]);
     }
+
+    addNewColourScheme(choice.getPath());
   }
 
   /**
-   * DOCUMENT ME!
+   * Loads the user-defined colour scheme from the first file listed in property
+   * "USER_DEFINED_COLOURS". If this fails, returns an all-white colour scheme.
    * 
-   * @return DOCUMENT ME!
+   * @return
    */
   public static UserColourScheme loadDefaultColours()
   {
     UserColourScheme ret = null;
 
-    String colours = jalview.bin.Cache.getProperty("USER_DEFINED_COLOURS");
+    String colours = Cache.getProperty(USER_DEFINED_COLOURS);
     if (colours != null)
     {
       if (colours.indexOf("|") > -1)
       {
         colours = colours.substring(0, colours.indexOf("|"));
       }
-
-      ret = loadColours(colours);
+      ret = ColourSchemes.loadColourScheme(colours);
     }
 
     if (ret == null)
     {
-      Color[] newColours = new Color[24];
-      for (int i = 0; i < 24; i++)
-      {
-        newColours[i] = Color.white;
-      }
-      ret = new UserColourScheme(newColours);
+      ret = new UserColourScheme("white");
     }
 
     return ret;
@@ -689,125 +683,14 @@ public class UserDefinedColours extends GUserDefinedColours implements
   /**
    * DOCUMENT ME!
    * 
-   * @param file
-   *          DOCUMENT ME!
-   * 
-   * @return DOCUMENT ME!
-   */
-  static UserColourScheme loadColours(String file)
-  {
-    UserColourScheme ucs = null;
-    Color[] newColours = null;
-    try
-    {
-      InputStreamReader in = new InputStreamReader(
-              new FileInputStream(file), "UTF-8");
-
-      jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours();
-
-      org.exolab.castor.xml.Unmarshaller unmar = new org.exolab.castor.xml.Unmarshaller(
-              jucs);
-      jucs = (jalview.schemabinding.version2.JalviewUserColours) unmar
-              .unmarshal(in);
-
-      newColours = new Color[24];
-
-      Color[] lowerCase = null;
-      boolean caseSensitive = false;
-
-      String name;
-      int index;
-      for (int i = 0; i < jucs.getColourCount(); i++)
-      {
-        name = jucs.getColour(i).getName();
-        if (ResidueProperties.aa3Hash.containsKey(name))
-        {
-          index = ResidueProperties.aa3Hash.get(name).intValue();
-        }
-        else
-        {
-          index = ResidueProperties.aaIndex[name.charAt(0)];
-        }
-        if (index == -1)
-        {
-          continue;
-        }
-
-        if (name.toLowerCase().equals(name))
-        {
-          if (lowerCase == null)
-          {
-            lowerCase = new Color[23];
-          }
-          caseSensitive = true;
-          lowerCase[index] = new Color(Integer.parseInt(jucs.getColour(i)
-                  .getRGB(), 16));
-        }
-        else
-        {
-          newColours[index] = new Color(Integer.parseInt(jucs.getColour(i)
-                  .getRGB(), 16));
-        }
-      }
-
-      if (newColours != null)
-      {
-        ucs = new UserColourScheme(newColours);
-        ucs.setName(jucs.getSchemeName());
-        if (caseSensitive)
-        {
-          ucs.setLowerCaseColours(lowerCase);
-        }
-      }
-
-    } catch (Exception ex)
-    {
-      // Could be Archive Jalview format
-      try
-      {
-        InputStreamReader in = new InputStreamReader(new FileInputStream(
-                file), "UTF-8");
-
-        jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();
-
-        jucs = jucs.unmarshal(in);
-
-        newColours = new Color[jucs.getColourCount()];
-
-        for (int i = 0; i < 24; i++)
-        {
-          newColours[i] = new Color(Integer.parseInt(jucs.getColour(i)
-                  .getRGB(), 16));
-        }
-        if (newColours != null)
-        {
-          ucs = new UserColourScheme(newColours);
-          ucs.setName(jucs.getSchemeName());
-        }
-      } catch (Exception ex2)
-      {
-        ex2.printStackTrace();
-      }
-
-      if (newColours == null)
-      {
-        System.out.println("Error loading User ColourFile\n" + ex);
-      }
-    }
-
-    return ucs;
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
    * @param e
    *          DOCUMENT ME!
    */
   @Override
   protected void savebutton_actionPerformed(ActionEvent e)
   {
-    if (schemeName.getText().trim().length() < 1)
+    String name = schemeName.getText().trim();
+    if (name.length() < 1)
     {
       JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
               .getString("label.user_colour_scheme_must_have_name"),
@@ -816,27 +699,26 @@ public class UserDefinedColours extends GUserDefinedColours implements
       return;
     }
 
-    if (userColourSchemes != null
-            && userColourSchemes.containsKey(schemeName.getText()))
+    if (ColourSchemes.getInstance().nameExists(name))
     {
       int reply = JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
               MessageManager.formatMessage(
                       "label.colour_scheme_exists_overwrite", new Object[] {
-                          schemeName.getText(), schemeName.getText() }),
+                          name, name }),
               MessageManager.getString("label.duplicate_scheme_name"),
               JvOptionPane.YES_NO_OPTION);
       if (reply != JvOptionPane.YES_OPTION)
       {
         return;
       }
-
-      userColourSchemes.remove(schemeName.getText());
+      ColourSchemes.getInstance().removeColourScheme(name);
     }
     JalviewFileChooser chooser = new JalviewFileChooser(
-            Cache.getProperty("LAST_DIRECTORY"), "jc",
+            Cache.getProperty(LAST_DIRECTORY), "jc",
             "Jalview User Colours");
 
-    chooser.setFileView(new JalviewFileView());
+    JalviewFileView fileView = new JalviewFileView();
+    chooser.setFileView(fileView);
     chooser.setDialogTitle(MessageManager
             .getString("label.save_colour_scheme"));
     chooser.setToolTipText(MessageManager.getString("action.save"));
@@ -845,56 +727,91 @@ public class UserDefinedColours extends GUserDefinedColours implements
 
     if (value == JalviewFileChooser.APPROVE_OPTION)
     {
-      String choice = chooser.getSelectedFile().getPath();
-      String defaultColours = jalview.bin.Cache.getDefault(
-              "USER_DEFINED_COLOURS", choice);
-      if (defaultColours.indexOf(choice) == -1)
+      File file = chooser.getSelectedFile();
+      addNewColourScheme(file.getPath());
+      saveToFile(file);
+    }
+  }
+
+  /**
+   * Adds the current colour scheme to the Jalview properties file so it is
+   * loaded on next startup, and updates the Colour menu in the parent
+   * AlignFrame (if there is one). Note this action does not including applying
+   * the colour scheme.
+   * 
+   * @param filePath
+   */
+  protected void addNewColourScheme(String filePath)
+  {
+    /*
+     * update the delimited list of user defined colour files in
+     * Jalview property USER_DEFINED_COLOURS
+     */
+    String defaultColours = Cache
+            .getDefault(USER_DEFINED_COLOURS, filePath);
+    if (defaultColours.indexOf(filePath) == -1)
+    {
+      if (defaultColours.length() > 0)
       {
-        if (defaultColours.length() > 0)
-        {
-          defaultColours = defaultColours.concat("|");
-        }
-        defaultColours = defaultColours.concat(choice);
+        defaultColours = defaultColours.concat("|");
       }
+      defaultColours = defaultColours.concat(filePath);
+    }
+    Cache.setProperty(USER_DEFINED_COLOURS, defaultColours);
 
-      userColourSchemes.put(schemeName.getText(), getSchemeFromButtons());
-
-      ap.alignFrame.updateUserColourMenu();
-
-      jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", defaultColours);
-
-      jalview.schemabinding.version2.JalviewUserColours ucs = new jalview.schemabinding.version2.JalviewUserColours();
+    /*
+     * construct and register the colour scheme
+     */
+    UserColourScheme ucs = getSchemeFromButtons();
+    ColourSchemes.getInstance().registerColourScheme(ucs);
 
-      ucs.setSchemeName(schemeName.getText());
-      try
-      {
-        PrintWriter out = new PrintWriter(new OutputStreamWriter(
-                new FileOutputStream(choice), "UTF-8"));
+    /*
+     * update the Colour menu items
+     */
+    if (ap != null)
+    {
+      ap.alignFrame.buildColourMenu();
+    }
+  }
 
-        for (int i = 0; i < buttonPanel.getComponentCount(); i++)
-        {
-          JButton button = (JButton) buttonPanel.getComponent(i);
-          jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
-          col.setName(button.getText());
-          col.setRGB(jalview.util.Format.getHexString(button
-                  .getBackground()));
-          ucs.addColour(col);
-        }
+  /**
+   * Saves the colour scheme to file in XML format
+   * 
+   * @param path
+   */
+  protected void saveToFile(File toFile)
+  {
+    /*
+     * build a Java model of colour scheme as XML, and 
+     * marshal to file
+     */
+    JalviewUserColours ucs = new JalviewUserColours();
+    ucs.setSchemeName(schemeName.getText());
+    try
+    {
+      PrintWriter out = new PrintWriter(new OutputStreamWriter(
+              new FileOutputStream(toFile), "UTF-8"));
 
-        ucs.marshal(out);
-        out.close();
-      } catch (Exception ex)
+      for (int i = 0; i < buttonPanel.getComponentCount(); i++)
       {
-        ex.printStackTrace();
+        JButton button = (JButton) buttonPanel.getComponent(i);
+        Colour col = new Colour();
+        col.setName(button.getText());
+        col.setRGB(Format.getHexString(button.getBackground()));
+        ucs.addColour(col);
       }
+      ucs.marshal(out);
+      out.close();
+    } catch (Exception ex)
+    {
+      ex.printStackTrace();
     }
   }
 
   /**
-   * DOCUMENT ME!
+   * On cancel, restores the colour scheme before the dialogue was opened
    * 
    * @param e
-   *          DOCUMENT ME!
    */
   @Override
   protected void cancelButton_actionPerformed(ActionEvent e)
@@ -905,16 +822,16 @@ public class UserDefinedColours extends GUserDefinedColours implements
       {
         seqGroup.cs = oldColourScheme;
       }
-      else if (ap != null)
+      else
       {
-        ap.av.setGlobalColourScheme(oldColourScheme);
+        ap.alignFrame.changeColour(oldColourScheme);
       }
       ap.paintAlignment(true);
     }
 
-    if (jmol != null)
+    if (structureViewer != null)
     {
-      jmol.setJalviewColourScheme(oldColourScheme);
+      structureViewer.setJalviewColourScheme(oldColourScheme);
     }
 
     try
@@ -925,107 +842,6 @@ public class UserDefinedColours extends GUserDefinedColours implements
     }
   }
 
-  static Hashtable userColourSchemes;
-
-  public static Hashtable getUserColourSchemes()
-  {
-    return userColourSchemes;
-  }
-
-  public static void initUserColourSchemes(String files)
-  {
-    userColourSchemes = new Hashtable();
-
-    if (files == null || files.length() == 0)
-    {
-      return;
-    }
-
-    // In case colours can't be loaded, we'll remove them
-    // from the default list here.
-    StringBuffer coloursFound = new StringBuffer();
-    StringTokenizer st = new StringTokenizer(files, "|");
-    while (st.hasMoreElements())
-    {
-      String file = st.nextToken();
-      try
-      {
-        UserColourScheme ucs = loadColours(file);
-        if (ucs != null)
-        {
-          if (coloursFound.length() > 0)
-          {
-            coloursFound.append("|");
-          }
-          coloursFound.append(file);
-          userColourSchemes.put(ucs.getName(), ucs);
-        }
-      } catch (Exception ex)
-      {
-        System.out.println("Error loading User ColourFile\n" + ex);
-      }
-    }
-    if (!files.equals(coloursFound.toString()))
-    {
-      if (coloursFound.toString().length() > 1)
-      {
-        jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS",
-                coloursFound.toString());
-      }
-      else
-      {
-        jalview.bin.Cache.applicationProperties
-                .remove("USER_DEFINED_COLOURS");
-      }
-    }
-  }
-
-  public static void removeColourFromDefaults(String target)
-  {
-    // The only way to find colours by name is to load them in
-    // In case colours can't be loaded, we'll remove them
-    // from the default list here.
-
-    userColourSchemes = new Hashtable();
-
-    StringBuffer coloursFound = new StringBuffer();
-    StringTokenizer st = new StringTokenizer(
-            jalview.bin.Cache.getProperty("USER_DEFINED_COLOURS"), "|");
-
-    while (st.hasMoreElements())
-    {
-      String file = st.nextToken();
-      try
-      {
-        UserColourScheme ucs = loadColours(file);
-        if (ucs != null && !ucs.getName().equals(target))
-        {
-          if (coloursFound.length() > 0)
-          {
-            coloursFound.append("|");
-          }
-          coloursFound.append(file);
-          userColourSchemes.put(ucs.getName(), ucs);
-        }
-      } catch (Exception ex)
-      {
-        System.out.println("Error loading User ColourFile\n" + ex);
-      }
-    }
-
-    if (coloursFound.toString().length() > 1)
-    {
-      jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS",
-              coloursFound.toString());
-    }
-    else
-    {
-      jalview.bin.Cache.applicationProperties
-              .remove("USER_DEFINED_COLOURS");
-    }
-
-  }
-
   @Override
   public void caseSensitive_actionPerformed(ActionEvent e)
   {
index 82e71b5..ae34f6b 100755 (executable)
@@ -32,8 +32,9 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
 
+import java.awt.Color;
 import java.io.BufferedReader;
 import java.io.FileReader;
 import java.io.InputStreamReader;
@@ -581,7 +582,7 @@ public class AnnotationFile
       if (sg.cs != null)
       {
         text.append("colour=");
-        text.append(ColourSchemeProperty.getColourName(sg.cs));
+        text.append(sg.cs.toString());
         text.append("\t");
         if (sg.cs.getThreshold() != 0)
         {
@@ -1223,29 +1224,21 @@ public class AnnotationFile
 
   Annotation parseAnnotation(String string, int graphStyle)
   {
-    boolean hasSymbols = (graphStyle == AlignmentAnnotation.NO_GRAPH); // don't
-    // do the
-    // glyph
-    // test
-    // if we
-    // don't
-    // want
-    // secondary
-    // structure
+    // don't do the glyph test if we don't want secondary structure
+    boolean hasSymbols = (graphStyle == AlignmentAnnotation.NO_GRAPH);
     String desc = null, displayChar = null;
     char ss = ' '; // secondaryStructure
     float value = 0;
     boolean parsedValue = false, dcset = false;
 
     // find colour here
-    java.awt.Color colour = null;
+    Color colour = null;
     int i = string.indexOf("[");
     int j = string.indexOf("]");
     if (i > -1 && j > -1)
     {
-      UserColourScheme ucs = new UserColourScheme();
-
-      colour = ucs.getColourFromString(string.substring(i + 1, j));
+      colour = ColorUtils.parseColourString(string.substring(i + 1,
+              j));
       if (i > 0 && string.charAt(i - 1) == ',')
       {
         // clip the preceding comma as well
@@ -1347,7 +1340,7 @@ public class AnnotationFile
 
   void colourAnnotations(AlignmentI al, String label, String colour)
   {
-    UserColourScheme ucs = new UserColourScheme(colour);
+    Color awtColour = ColorUtils.parseColourString(colour);
     Annotation[] annotations;
     for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
     {
@@ -1358,7 +1351,7 @@ public class AnnotationFile
         {
           if (annotations[j] != null)
           {
-            annotations[j].colour = ucs.findColour('A');
+            annotations[j].colour = awtColour;
           }
         }
       }
@@ -1428,15 +1421,22 @@ public class AnnotationFile
           SequenceGroup groupRef)
   {
     String group = st.nextToken();
-    AlignmentAnnotation annotation = null, alannot[] = al
-            .getAlignmentAnnotation();
-    float value = new Float(st.nextToken()).floatValue();
+    AlignmentAnnotation[] alannot = al.getAlignmentAnnotation();
+    String nextToken = st.nextToken();
+    float value = 0f;
+    try
+    {
+      value = Float.valueOf(nextToken);
+    } catch (NumberFormatException e)
+    {
+      System.err.println("line " + nlinesread + ": Threshold '" + nextToken
+              + "' invalid, setting to zero");
+    }
     String label = st.hasMoreTokens() ? st.nextToken() : null;
-    java.awt.Color colour = null;
+    Color colour = null;
     if (st.hasMoreTokens())
     {
-      UserColourScheme ucs = new UserColourScheme(st.nextToken());
-      colour = ucs.findColour('A');
+      colour = ColorUtils.parseColourString(st.nextToken());
     }
     if (alannot != null)
     {
@@ -1450,10 +1450,6 @@ public class AnnotationFile
         }
       }
     }
-    if (annotation == null)
-    {
-      return;
-    }
   }
 
   void addGroup(AlignmentI al, StringTokenizer st)
@@ -1627,7 +1623,7 @@ public class AnnotationFile
         }
         else if (key.equalsIgnoreCase("colour"))
         {
-          sg.cs = ColourSchemeProperty.getColour(al, value);
+          sg.cs = ColourSchemeProperty.getColourScheme(al, value);
         }
         else if (key.equalsIgnoreCase("pidThreshold"))
         {
@@ -1648,7 +1644,7 @@ public class AnnotationFile
         }
         else if (key.equalsIgnoreCase("outlineColour"))
         {
-          sg.setOutlineColour(new UserColourScheme(value).findColour('A'));
+          sg.setOutlineColour(ColorUtils.parseColourString(value));
         }
         else if (key.equalsIgnoreCase("displayBoxes"))
         {
@@ -1668,11 +1664,11 @@ public class AnnotationFile
         }
         else if (key.equalsIgnoreCase("textCol1"))
         {
-          sg.textColour = new UserColourScheme(value).findColour('A');
+          sg.textColour = ColorUtils.parseColourString(value);
         }
         else if (key.equalsIgnoreCase("textCol2"))
         {
-          sg.textColour2 = new UserColourScheme(value).findColour('A');
+          sg.textColour2 = ColorUtils.parseColourString(value);
         }
         else if (key.equalsIgnoreCase("textColThreshold"))
         {
@@ -1680,9 +1676,8 @@ public class AnnotationFile
         }
         else if (key.equalsIgnoreCase("idColour"))
         {
-          // consider warning if colour doesn't resolve to a real colour
-          sg.setIdColour((def = new UserColourScheme(value))
-                  .findColour('A'));
+          Color idColour = ColorUtils.parseColourString(value);
+          sg.setIdColour(idColour == null ? Color.black : idColour);
         }
         else if (key.equalsIgnoreCase("hide"))
         {
index 6af0cdf..48eeee3 100755 (executable)
@@ -35,11 +35,12 @@ import jalview.io.gff.GffHelperBase;
 import jalview.io.gff.GffHelperFactory;
 import jalview.io.gff.GffHelperI;
 import jalview.schemes.FeatureColour;
-import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
 import jalview.util.MapList;
 import jalview.util.ParseHtmlBodyAndLinks;
 import jalview.util.StringUtils;
 
+import java.awt.Color;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -355,8 +356,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
        * Perhaps an old style groups file with no colours -
        * synthesize a colour from the feature type
        */
-      UserColourScheme ucs = new UserColourScheme(ft);
-      featureColours.put(ft, new FeatureColour(ucs.findColour('A')));
+      Color colour = ColorUtils.createColourFromName(ft);
+      featureColours.put(ft, new FeatureColour(colour));
     }
     SequenceFeature sf = new SequenceFeature(ft, desc, "", startPos,
             endPos, featureGroup);
index 7a12076..bdd2dcb 100644 (file)
@@ -46,8 +46,9 @@ import jalview.json.binding.biojson.v1.ColourSchemeMapper;
 import jalview.json.binding.biojson.v1.SequenceFeaturesPojo;
 import jalview.json.binding.biojson.v1.SequenceGrpPojo;
 import jalview.json.binding.biojson.v1.SequencePojo;
-import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.UserColourScheme;
+import jalview.schemes.JalviewColourScheme;
+import jalview.schemes.ResidueColourScheme;
+import jalview.util.ColorUtils;
 import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
 
 import java.awt.Color;
@@ -215,10 +216,13 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
       {
         // These color schemes require annotation, disable them if annotations
         // are not exported
-        if (globalColourScheme.equalsIgnoreCase("RNA Helices")
-                || globalColourScheme.equalsIgnoreCase("T-COFFEE SCORES"))
+        if (globalColourScheme
+                .equalsIgnoreCase(JalviewColourScheme.RNAHelices.toString())
+                || globalColourScheme
+                        .equalsIgnoreCase(JalviewColourScheme.TCoffee
+                                .toString()))
         {
-          jsonAlignmentPojo.setGlobalColorScheme("None");
+          jsonAlignmentPojo.setGlobalColorScheme(ResidueColourScheme.NONE);
         }
       }
 
@@ -235,8 +239,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
         {
           SequenceGrpPojo seqGrpPojo = new SequenceGrpPojo();
           seqGrpPojo.setGroupName(seqGrp.getName());
-          seqGrpPojo.setColourScheme(ColourSchemeProperty
-                  .getColourName(seqGrp.cs));
+          seqGrpPojo.setColourScheme(seqGrp.cs.getSchemeName());
           seqGrpPojo.setColourText(seqGrp.getColourText());
           seqGrpPojo.setDescription(seqGrp.getDescription());
           seqGrpPojo.setDisplayBoxes(seqGrp.getDisplayBoxes());
@@ -563,7 +566,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
             annotations[count] = new Annotation(displayChar, desc, ss, val);
             if (annot.get("colour") != null)
             {
-              Color color = UserColourScheme.getColourFromString(annot.get(
+              Color color = ColorUtils.parseColourString(annot.get(
                       "colour").toString());
               annotations[count].colour = color;
             }
@@ -760,8 +763,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
         }
       }
     }
-    globalColourScheme = ColourSchemeProperty.getColourName(viewport
-            .getGlobalColourScheme());
+    globalColourScheme = viewport.getGlobalColourScheme().getSchemeName();
     setDisplayedFeatures(viewport.getFeaturesDisplayed());
     showSeqFeatures = viewport.isShowSequenceFeatures();
 
index c3ec951..648954f 100644 (file)
@@ -37,10 +37,10 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 /**
- * A file parse for T-Coffee score ascii format. This file contains the
- * alignment consensus for each resude in any sequence.
+ * A file parser for T-Coffee score ascii format. This file contains the
+ * alignment consensus for each residue in any sequence.
  * <p>
- * This file is procuded by <code>t_coffee</code> providing the option
+ * This file is produced by <code>t_coffee</code> providing the option
  * <code>-output=score_ascii </code> to the program command line
  * 
  * An example file is the following
@@ -91,17 +91,26 @@ import java.util.regex.Pattern;
  */
 public class TCoffeeScoreFile extends AlignFile
 {
-  public TCoffeeScoreFile(String inFile, DataSourceType fileSourceType)
-          throws IOException
-  {
-    super(inFile, fileSourceType);
 
-  }
+  /**
+   * TCOFFEE score colourscheme
+   */
+  static final Color[] colors = { new Color(102, 102, 255), // 0: lilac #6666FF
+      new Color(0, 255, 0), // 1: green #00FF00
+      new Color(102, 255, 0), // 2: lime green #66FF00
+      new Color(204, 255, 0), // 3: greeny yellow #CCFF00
+      new Color(255, 255, 0), // 4: yellow #FFFF00
+      new Color(255, 204, 0), // 5: orange #FFCC00
+      new Color(255, 153, 0), // 6: deep orange #FF9900
+      new Color(255, 102, 0), // 7: ochre #FF6600
+      new Color(255, 51, 0), // 8: red #FF3300
+      new Color(255, 34, 0) // 9: redder #FF2000
+  };
 
-  public TCoffeeScoreFile(FileParse source) throws IOException
-  {
-    super(source);
-  }
+  public final static String TCOFFEE_SCORE = "TCoffeeScore";
+
+  static Pattern SCORES_WITH_RESIDUE_NUMS = Pattern
+          .compile("^\\d+\\s([^\\s]+)\\s+\\d+$");
 
   /** The {@link Header} structure holder */
   Header header;
@@ -114,6 +123,18 @@ public class TCoffeeScoreFile extends AlignFile
 
   Integer fWidth;
 
+  public TCoffeeScoreFile(String inFile, DataSourceType fileSourceType)
+          throws IOException
+  {
+    super(inFile, fileSourceType);
+
+  }
+
+  public TCoffeeScoreFile(FileParse source) throws IOException
+  {
+    super(source);
+  }
+
   /**
    * Parse the provided reader for the T-Coffee scores file format
    * 
@@ -399,9 +420,6 @@ public class TCoffeeScoreFile extends AlignFile
     }
   }
 
-  static Pattern SCORES_WITH_RESIDUE_NUMS = Pattern
-          .compile("^\\d+\\s([^\\s]+)\\s+\\d+$");
-
   /**
    * Read a scores block ihe provided stream.
    * 
@@ -525,23 +543,6 @@ public class TCoffeeScoreFile extends AlignFile
   }
 
   /**
-   * TCOFFEE score colourscheme
-   */
-  static final Color[] colors = { new Color(102, 102, 255), // #6666FF
-      new Color(0, 255, 0), // #00FF00
-      new Color(102, 255, 0), // #66FF00
-      new Color(204, 255, 0), // #CCFF00
-      new Color(255, 255, 0), // #FFFF00
-      new Color(255, 204, 0), // #FFCC00
-      new Color(255, 153, 0), // #FF9900
-      new Color(255, 102, 0), // #FF6600
-      new Color(255, 51, 0), // #FF3300
-      new Color(255, 34, 0) // #FF2000
-  };
-
-  public final static String TCOFFEE_SCORE = "TCoffeeScore";
-
-  /**
    * generate annotation for this TCoffee score set on the given alignment
    * 
    * @param al
index 6530d3d..c8aa94f 100755 (executable)
@@ -23,12 +23,11 @@ package jalview.jbgui;
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.api.SplitContainerI;
 import jalview.bin.Cache;
-import jalview.gui.JvOptionPane;
 import jalview.gui.JvSwingUtils;
 import jalview.gui.Preferences;
 import jalview.io.FileFormats;
-import jalview.schemes.ColourSchemeProperty;
 import jalview.util.MessageManager;
+import jalview.util.Platform;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -66,15 +65,13 @@ public class GAlignFrame extends JInternalFrame
 
   protected JMenuItem closeMenuItem = new JMenuItem();
 
-  protected JMenu colourMenu = new JMenu();
-
   protected JMenu webService = new JMenu();
 
   protected JMenuItem webServiceNoServices;
 
-  public JCheckBoxMenuItem viewBoxesMenuItem = new JCheckBoxMenuItem();
+  protected JCheckBoxMenuItem viewBoxesMenuItem = new JCheckBoxMenuItem();
 
-  public JCheckBoxMenuItem viewTextMenuItem = new JCheckBoxMenuItem();
+  protected JCheckBoxMenuItem viewTextMenuItem = new JCheckBoxMenuItem();
 
   protected JMenu sortByAnnotScore = new JMenu();
 
@@ -82,58 +79,19 @@ public class GAlignFrame extends JInternalFrame
 
   protected JMenu outputTextboxMenu = new JMenu();
 
-  protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem nucleotideColour = new JRadioButtonMenuItem();
+  protected JCheckBoxMenuItem annotationPanelMenuItem = new JCheckBoxMenuItem();
 
-  protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
+  protected JCheckBoxMenuItem colourTextMenuItem = new JCheckBoxMenuItem();
 
-  protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
-
-  // protected JRadioButtonMenuItem covariationColour = new
-  // JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem tcoffeeColour = new JRadioButtonMenuItem();
-
-  public JCheckBoxMenuItem annotationPanelMenuItem = new JCheckBoxMenuItem();
-
-  public JCheckBoxMenuItem colourTextMenuItem = new JCheckBoxMenuItem();
-
-  public JCheckBoxMenuItem showNonconservedMenuItem = new JCheckBoxMenuItem();
+  protected JCheckBoxMenuItem showNonconservedMenuItem = new JCheckBoxMenuItem();
 
   protected JMenuItem undoMenuItem = new JMenuItem();
 
   protected JMenuItem redoMenuItem = new JMenuItem();
 
-  public JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
-
-  JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
+  protected JCheckBoxMenuItem wrapMenuItem = new JCheckBoxMenuItem();
 
-  public JCheckBoxMenuItem wrapMenuItem = new JCheckBoxMenuItem();
-
-  public JCheckBoxMenuItem renderGapsMenuItem = new JCheckBoxMenuItem();
-
-  public JCheckBoxMenuItem abovePIDThreshold = new JCheckBoxMenuItem();
+  protected JCheckBoxMenuItem renderGapsMenuItem = new JCheckBoxMenuItem();
 
   public JCheckBoxMenuItem showSeqFeatures = new JCheckBoxMenuItem();
 
@@ -143,19 +101,29 @@ public class GAlignFrame extends JInternalFrame
 
   JMenu pasteMenu = new JMenu();
 
-  public JCheckBoxMenuItem applyToAllGroups = new JCheckBoxMenuItem();
+  protected JCheckBoxMenuItem seqLimits = new JCheckBoxMenuItem();
+
+  protected JCheckBoxMenuItem scaleAbove = new JCheckBoxMenuItem();
 
-  public JCheckBoxMenuItem seqLimits = new JCheckBoxMenuItem();
+  protected JCheckBoxMenuItem scaleLeft = new JCheckBoxMenuItem();
 
-  public JCheckBoxMenuItem scaleAbove = new JCheckBoxMenuItem();
+  protected JCheckBoxMenuItem scaleRight = new JCheckBoxMenuItem();
+
+  protected JCheckBoxMenuItem applyToAllGroups;
+
+  protected JMenu colourMenu = new JMenu();
 
-  public JCheckBoxMenuItem scaleLeft = new JCheckBoxMenuItem();
+  protected JRadioButtonMenuItem textColour;
 
-  public JCheckBoxMenuItem scaleRight = new JCheckBoxMenuItem();
+  protected JCheckBoxMenuItem conservationMenuItem;
 
-  protected JMenuItem modifyConservation = new JMenuItem();
+  protected JMenuItem modifyConservation;
 
-  protected JMenuItem modifyPID = new JMenuItem();
+  protected JCheckBoxMenuItem abovePIDThreshold;
+
+  protected JMenuItem modifyPID;
+
+  protected JMenuItem annotationColour;
 
   protected JMenu sortByTreeMenu = new JMenu();
 
@@ -169,8 +137,6 @@ public class GAlignFrame extends JInternalFrame
 
   protected JCheckBoxMenuItem showDbRefsMenuitem = new JCheckBoxMenuItem();
 
-  protected ButtonGroup colours = new ButtonGroup();
-
   protected JMenuItem showTranslation = new JMenuItem();
 
   protected JMenuItem showReverse = new JMenuItem();
@@ -181,8 +147,6 @@ public class GAlignFrame extends JInternalFrame
 
   protected JMenuItem runGroovy = new JMenuItem();
 
-  protected JMenuItem rnahelicesColour = new JMenuItem();
-
   protected JCheckBoxMenuItem autoCalculate = new JCheckBoxMenuItem();
 
   protected JCheckBoxMenuItem sortByTree = new JCheckBoxMenuItem();
@@ -267,7 +231,7 @@ public class GAlignFrame extends JInternalFrame
       System.err.println(e.toString());
     }
 
-    if (!jalview.util.Platform.isAMac())
+    if (!Platform.isAMac())
     {
       closeMenuItem.setMnemonic('C');
       outputTextboxMenu.setMnemonic('T');
@@ -278,201 +242,12 @@ public class GAlignFrame extends JInternalFrame
       pasteMenu.setMnemonic('P');
       reload.setMnemonic('R');
     }
-
-    if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
-    {
-      java.util.Enumeration userColours = jalview.gui.UserDefinedColours
-              .getUserColourSchemes().keys();
-
-      while (userColours.hasMoreElements())
-      {
-        final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
-                userColours.nextElement().toString());
-        radioItem.setName("USER_DEFINED");
-        radioItem.addMouseListener(new MouseAdapter()
-        {
-          @Override
-          public void mousePressed(MouseEvent evt)
-          {
-            if (evt.isPopupTrigger()) // Mac
-            {
-              offerRemoval(radioItem);
-            }
-          }
-
-          @Override
-          public void mouseReleased(MouseEvent evt)
-          {
-            if (evt.isPopupTrigger()) // Windows
-            {
-              offerRemoval(radioItem);
-            }
-          }
-
-          /**
-           * @param radioItem
-           */
-          void offerRemoval(final JRadioButtonMenuItem radioItem)
-          {
-            radioItem.removeActionListener(radioItem.getActionListeners()[0]);
-
-            int option = JvOptionPane.showInternalConfirmDialog(
-                    jalview.gui.Desktop.desktop, MessageManager
-                            .getString("label.remove_from_default_list"),
-                    MessageManager
-                            .getString("label.remove_user_defined_colour"),
-                    JvOptionPane.YES_NO_OPTION);
-            if (option == JvOptionPane.YES_OPTION)
-            {
-              jalview.gui.UserDefinedColours
-                      .removeColourFromDefaults(radioItem.getText());
-              colourMenu.remove(radioItem);
-            }
-            else
-            {
-              radioItem.addActionListener(new ActionListener()
-              {
-                @Override
-                public void actionPerformed(ActionEvent evt)
-                {
-                  userDefinedColour_actionPerformed(evt);
-                }
-              });
-            }
-          }
-        });
-        radioItem.addActionListener(new ActionListener()
-        {
-          @Override
-          public void actionPerformed(ActionEvent evt)
-          {
-            userDefinedColour_actionPerformed(evt);
-          }
-        });
-        colourMenu.insert(radioItem, 15);
-        colours.add(radioItem);
-      }
-    }
-    colours.add(noColourmenuItem);
-    colours.add(clustalColour);
-    colours.add(zappoColour);
-    colours.add(taylorColour);
-    colours.add(hydrophobicityColour);
-    colours.add(helixColour);
-    colours.add(strandColour);
-    colours.add(turnColour);
-    colours.add(buriedColour);
-    colours.add(userDefinedColour);
-    colours.add(PIDColour);
-    colours.add(BLOSUM62Colour);
-    colours.add(nucleotideColour);
-    colours.add(purinePyrimidineColour);
-    // colours.add(covariationColour);
-    colours.add(tcoffeeColour);
-    colours.add(RNAInteractionColour);
-    setColourSelected(jalview.bin.Cache.getDefault(
-            Preferences.DEFAULT_COLOUR, "None"));
-  }
-
-  public void setColourSelected(String defaultColour)
-  {
-
-    if (defaultColour != null)
-    {
-      int index = ColourSchemeProperty
-              .getColourIndexFromName(defaultColour);
-
-      switch (index)
-      {
-      case ColourSchemeProperty.CLUSTAL:
-        clustalColour.setSelected(true);
-
-        break;
-
-      case ColourSchemeProperty.BLOSUM:
-        BLOSUM62Colour.setSelected(true);
-
-        break;
-
-      case ColourSchemeProperty.PID:
-        PIDColour.setSelected(true);
-
-        break;
-
-      case ColourSchemeProperty.ZAPPO:
-        zappoColour.setSelected(true);
-
-        break;
-
-      case ColourSchemeProperty.TAYLOR:
-        taylorColour.setSelected(true);
-        break;
-
-      case ColourSchemeProperty.HYDROPHOBIC:
-        hydrophobicityColour.setSelected(true);
-
-        break;
-
-      case ColourSchemeProperty.HELIX:
-        helixColour.setSelected(true);
-
-        break;
-
-      case ColourSchemeProperty.STRAND:
-        strandColour.setSelected(true);
-
-        break;
-
-      case ColourSchemeProperty.TURN:
-        turnColour.setSelected(true);
-
-        break;
-
-      case ColourSchemeProperty.BURIED:
-        buriedColour.setSelected(true);
-
-        break;
-
-      case ColourSchemeProperty.NUCLEOTIDE:
-        nucleotideColour.setSelected(true);
-
-        break;
-
-      case ColourSchemeProperty.TCOFFEE:
-        tcoffeeColour.setSelected(true);
-        break;
-
-      case ColourSchemeProperty.PURINEPYRIMIDINE:
-        purinePyrimidineColour.setSelected(true);
-
-        break;
-
-      case ColourSchemeProperty.RNAINTERACTION:
-        RNAInteractionColour.setSelected(true);
-
-        break;
-      /*
-       * case ColourSchemeProperty.COVARIATION:
-       * covariationColour.setSelected(true);
-       * 
-       * break;
-       */
-      case ColourSchemeProperty.USER_DEFINED:
-        userDefinedColour.setSelected(true);
-
-        break;
-      case ColourSchemeProperty.NONE:
-      default:
-        noColourmenuItem.setSelected(true);
-        break;
-
-      }
-    }
-
   }
 
   private void jbInit() throws Exception
   {
+    initColourMenu();
+
     JMenuItem saveAs = new JMenuItem(
             MessageManager.getString("action.save_as"));
     ActionListener al = new ActionListener()
@@ -483,6 +258,8 @@ public class GAlignFrame extends JInternalFrame
         saveAs_actionPerformed(e);
       }
     };
+
+    // FIXME getDefaultToolkit throws an exception in Headless mode
     KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit
             .getDefaultToolkit().getMenuShortcutKeyMask()
             | KeyEvent.SHIFT_MASK, false);
@@ -671,7 +448,7 @@ public class GAlignFrame extends JInternalFrame
       }
     });
     showNonconservedMenuItem.setText(MessageManager
-            .getString("label.show_non_conversed"));
+            .getString("label.show_non_conserved"));
     showNonconservedMenuItem.setState(false);
     showNonconservedMenuItem.addActionListener(new ActionListener()
     {
@@ -785,149 +562,10 @@ public class GAlignFrame extends JInternalFrame
     statusBar.setText(MessageManager.getString("label.status_bar"));
     outputTextboxMenu.setText(MessageManager
             .getString("label.out_to_textbox"));
-    clustalColour.setText(MessageManager.getString("label.clustalx"));
-    clustalColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        clustalColour_actionPerformed(e);
-      }
-    });
-    zappoColour.setText(MessageManager.getString("label.zappo"));
-    zappoColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        zappoColour_actionPerformed(e);
-      }
-    });
-    taylorColour.setText(MessageManager.getString("label.taylor"));
-    taylorColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        taylorColour_actionPerformed(e);
-      }
-    });
-    hydrophobicityColour.setText(MessageManager
-            .getString("label.hydrophobicity"));
-    hydrophobicityColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        hydrophobicityColour_actionPerformed(e);
-      }
-    });
-    helixColour.setText(MessageManager.getString("label.helix_propensity"));
-    helixColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        helixColour_actionPerformed(e);
-      }
-    });
-    strandColour.setText(MessageManager
-            .getString("label.strand_propensity"));
-    strandColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        strandColour_actionPerformed(e);
-      }
-    });
-    turnColour.setText(MessageManager.getString("label.turn_propensity"));
-    turnColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        turnColour_actionPerformed(e);
-      }
-    });
-    buriedColour.setText(MessageManager.getString("label.buried_index"));
-    buriedColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        buriedColour_actionPerformed(e);
-      }
-    });
-    userDefinedColour.setText(MessageManager
-            .getString("action.user_defined"));
-    userDefinedColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        userDefinedColour_actionPerformed(e);
-      }
-    });
-    PIDColour
-            .setText(MessageManager.getString("label.percentage_identity"));
-    PIDColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        PIDColour_actionPerformed(e);
-      }
-    });
-    BLOSUM62Colour
-            .setText(MessageManager.getString("label.blosum62_score"));
-    BLOSUM62Colour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        BLOSUM62Colour_actionPerformed(e);
-      }
-    });
-    nucleotideColour.setText(MessageManager.getString("label.nucleotide"));
-    nucleotideColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        nucleotideColour_actionPerformed(e);
-      }
-    });
-
-    purinePyrimidineColour.setText(MessageManager
-            .getString("label.purine_pyrimidine"));
-    purinePyrimidineColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        purinePyrimidineColour_actionPerformed(e);
-      }
-    });
 
-    RNAInteractionColour.setText("RNA Interaction type");
-    RNAInteractionColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        RNAInteractionColour_actionPerformed(e);
-      }
-    });
-    /*
-     * covariationColour.setText("Covariation");
-     * covariationColour.addActionListener(new ActionListener() { public void
-     * actionPerformed(ActionEvent e) { covariationColour_actionPerformed(e); }
-     * });
-     */
 
     JMenuItem avDistanceTreeBlosumMenuItem = new JMenuItem(
-            MessageManager.getString("label.average_distance_bloslum62"));
+            MessageManager.getString("label.average_distance_blosum62"));
     avDistanceTreeBlosumMenuItem.addActionListener(new ActionListener()
     {
       @Override
@@ -1041,7 +679,8 @@ public class GAlignFrame extends JInternalFrame
         sortAnnotations_actionPerformed();
       }
     });
-    colourTextMenuItem.setText(MessageManager
+    colourTextMenuItem = new JCheckBoxMenuItem(
+            MessageManager
             .getString("label.colour_text"));
     colourTextMenuItem.addActionListener(new ActionListener()
     {
@@ -1123,15 +762,7 @@ public class GAlignFrame extends JInternalFrame
         conservationMenuItem_actionPerformed();
       }
     });
-    noColourmenuItem.setText(MessageManager.getString("label.none"));
-    noColourmenuItem.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        noColourmenuItem_actionPerformed(e);
-      }
-    });
+
     wrapMenuItem.setText(MessageManager.getString("label.wrap"));
     wrapMenuItem.addActionListener(new ActionListener()
     {
@@ -1194,6 +825,7 @@ public class GAlignFrame extends JInternalFrame
         abovePIDThreshold_actionPerformed();
       }
     });
+
     showSeqFeatures.setText(MessageManager
             .getString("label.show_sequence_features"));
     showSeqFeatures.addActionListener(new ActionListener()
@@ -1339,28 +971,6 @@ public class GAlignFrame extends JInternalFrame
       }
     });
 
-    nucleotideColour.setText(MessageManager.getString("label.nucleotide"));
-    nucleotideColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        nucleotideColour_actionPerformed(e);
-      }
-    });
-
-    tcoffeeColour.setText(MessageManager.getString("label.tcoffee_scores"));
-    tcoffeeColour.setEnabled(false);
-    tcoffeeColour.addActionListener(new ActionListener()
-    {
-
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        tcoffeeColorScheme_actionPerformed(e);
-      }
-    });
-
     JMenuItem deleteGroups = new JMenuItem(
             MessageManager.getString("action.undefine_groups"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_U, Toolkit
@@ -1375,6 +985,17 @@ public class GAlignFrame extends JInternalFrame
     };
     addMenuActionAndAccelerator(keyStroke, deleteGroups, al);
 
+    JMenuItem annotationColumn = new JMenuItem(
+            MessageManager.getString("action.select_by_annotation"));
+    annotationColumn.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        annotationColumn_actionPerformed(e);
+      }
+    });
+
     JMenuItem createGroup = new JMenuItem(
             MessageManager.getString("action.create_groups"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit
@@ -1472,16 +1093,6 @@ public class GAlignFrame extends JInternalFrame
     };
     addMenuActionAndAccelerator(keyStroke, pasteThis, al);
 
-    applyToAllGroups.setText(MessageManager
-            .getString("label.apply_colour_to_all_groups"));
-    applyToAllGroups.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        applyToAllGroups_actionPerformed(e);
-      }
-    });
     JMenuItem createPNG = new JMenuItem("PNG");
     createPNG.addActionListener(new ActionListener()
     {
@@ -1626,6 +1237,7 @@ public class GAlignFrame extends JInternalFrame
         modifyConservation_actionPerformed();
       }
     });
+
     sortByTreeMenu
             .setText(MessageManager.getString("action.by_tree_order"));
     sort.setText(MessageManager.getString("action.sort"));
@@ -1775,39 +1387,6 @@ public class GAlignFrame extends JInternalFrame
       }
     });
 
-    JMenuItem annotationColour = new JMenuItem(
-            MessageManager.getString("action.by_annotation"));
-    annotationColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        annotationColour_actionPerformed(e);
-      }
-    });
-
-    JMenuItem annotationColumn = new JMenuItem(
-            MessageManager.getString("action.select_by_annotation"));
-    annotationColumn.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        annotationColumn_actionPerformed(e);
-      }
-    });
-
-    rnahelicesColour.setText(MessageManager
-            .getString("action.by_rna_helixes"));
-    rnahelicesColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        rnahelicesColour_actionPerformed(e);
-      }
-    });
-
     JMenuItem associatedData = new JMenuItem(
             MessageManager.getString("label.load_features_annotations"));
     associatedData.addActionListener(new ActionListener()
@@ -2114,16 +1693,7 @@ public class GAlignFrame extends JInternalFrame
     tabbedPane.setToolTipText("<html><i>"
             + MessageManager.getString("label.rename_tab_eXpand_reGroup")
             + "</i></html>");
-    JMenuItem textColour = new JMenuItem(
-            MessageManager.getString("action.set_text_colour"));
-    textColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        textColour_actionPerformed(e);
-      }
-    });
+
     formatMenu.setText(MessageManager.getString("action.format"));
     JMenu selectMenu = new JMenu(MessageManager.getString("action.select"));
     idRightAlign.setText(MessageManager
@@ -2305,33 +1875,6 @@ public class GAlignFrame extends JInternalFrame
     autoAnnMenu.add(showGroupConsensus);
     annotationsMenu.add(autoAnnMenu);
 
-    colourMenu.add(applyToAllGroups);
-    colourMenu.add(textColour);
-    colourMenu.addSeparator();
-    colourMenu.add(noColourmenuItem);
-    colourMenu.add(clustalColour);
-    colourMenu.add(BLOSUM62Colour);
-    colourMenu.add(PIDColour);
-    colourMenu.add(zappoColour);
-    colourMenu.add(taylorColour);
-    colourMenu.add(hydrophobicityColour);
-    colourMenu.add(helixColour);
-    colourMenu.add(strandColour);
-    colourMenu.add(turnColour);
-    colourMenu.add(buriedColour);
-    colourMenu.add(nucleotideColour);
-    colourMenu.add(purinePyrimidineColour);
-    // colourMenu.add(RNAInteractionColour);
-    // colourMenu.add(covariationColour);
-    colourMenu.add(tcoffeeColour);
-    colourMenu.add(userDefinedColour);
-    colourMenu.addSeparator();
-    colourMenu.add(conservationMenuItem);
-    colourMenu.add(modifyConservation);
-    colourMenu.add(abovePIDThreshold);
-    colourMenu.add(modifyPID);
-    colourMenu.add(annotationColour);
-    colourMenu.add(rnahelicesColour);
 
     sort.add(sortIDMenuItem);
     sort.add(sortLengthMenuItem);
@@ -2404,6 +1947,89 @@ public class GAlignFrame extends JInternalFrame
     // selectMenu.add(listenToViewSelections);
   }
 
+  /**
+   * Constructs the entries on the Colour menu (but does not add them to the
+   * menu).
+   */
+  protected void initColourMenu()
+  {
+    applyToAllGroups = new JCheckBoxMenuItem(
+            MessageManager.getString("label.apply_colour_to_all_groups"));
+    applyToAllGroups.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        applyToAllGroups_actionPerformed();
+      }
+    });
+
+    textColour = new JRadioButtonMenuItem(
+            MessageManager.getString("action.set_text_colour"));
+    textColour.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        textColour_actionPerformed();
+      }
+    });
+
+    conservationMenuItem = new JCheckBoxMenuItem(
+            MessageManager.getString("action.by_conservation"));
+    conservationMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        conservationMenuItem_actionPerformed();
+      }
+    });
+
+    abovePIDThreshold = new JCheckBoxMenuItem(
+            MessageManager.getString("label.above_identity_threshold"));
+    abovePIDThreshold.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        abovePIDThreshold_actionPerformed();
+      }
+    });
+    modifyPID = new JMenuItem(
+            MessageManager.getString("label.modify_identity_threshold"));
+    modifyPID.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        modifyPID_actionPerformed();
+      }
+    });
+    modifyConservation = new JMenuItem(
+            MessageManager
+            .getString("label.modify_conservation_threshold"));
+    modifyConservation.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        modifyConservation_actionPerformed();
+      }
+    });
+
+    annotationColour = new JMenuItem(
+            MessageManager.getString("action.by_annotation"));
+    annotationColour.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        annotationColour_actionPerformed();
+      }
+    });
+  }
+
   protected void selectHighlightedColumns_actionPerformed(
           ActionEvent actionEvent)
   {
@@ -2759,66 +2385,6 @@ public class GAlignFrame extends JInternalFrame
   {
   }
 
-  protected void clustalColour_actionPerformed(ActionEvent e)
-  {
-  }
-
-  protected void zappoColour_actionPerformed(ActionEvent e)
-  {
-  }
-
-  protected void taylorColour_actionPerformed(ActionEvent e)
-  {
-  }
-
-  protected void hydrophobicityColour_actionPerformed(ActionEvent e)
-  {
-  }
-
-  protected void helixColour_actionPerformed(ActionEvent e)
-  {
-  }
-
-  protected void strandColour_actionPerformed(ActionEvent e)
-  {
-  }
-
-  protected void turnColour_actionPerformed(ActionEvent e)
-  {
-  }
-
-  protected void buriedColour_actionPerformed(ActionEvent e)
-  {
-  }
-
-  protected void userDefinedColour_actionPerformed(ActionEvent e)
-  {
-  }
-
-  protected void PIDColour_actionPerformed(ActionEvent e)
-  {
-  }
-
-  protected void BLOSUM62Colour_actionPerformed(ActionEvent e)
-  {
-  }
-
-  protected void purinePyrimidineColour_actionPerformed(ActionEvent e)
-  {
-  }
-
-  protected void RNAInteractionColour_actionPerformed(ActionEvent e)
-  {
-  }
-
-  /*
-   * protected void covariationColour_actionPerformed(ActionEvent e) { }
-   */
-
-  protected void noColourmenuItem_actionPerformed(ActionEvent e)
-  {
-  }
-
   protected void conservationMenuItem_actionPerformed()
   {
   }
@@ -2843,10 +2409,6 @@ public class GAlignFrame extends JInternalFrame
   {
   }
 
-  protected void nucleotideColour_actionPerformed(ActionEvent e)
-  {
-  }
-
   protected void deleteGroups_actionPerformed(ActionEvent e)
   {
   }
@@ -2879,7 +2441,7 @@ public class GAlignFrame extends JInternalFrame
   {
   }
 
-  protected void applyToAllGroups_actionPerformed(ActionEvent e)
+  protected void applyToAllGroups_actionPerformed()
   {
   }
 
@@ -2927,19 +2489,6 @@ public class GAlignFrame extends JInternalFrame
 
   }
 
-  /**
-   * Template method to handle the 'Color T-Coffee scores' menu event.
-   * <p>
-   * Subclasses override this method to provide a custom action.
-   * 
-   * @param event
-   *          The raised event
-   */
-  protected void tcoffeeColorScheme_actionPerformed(ActionEvent event)
-  {
-
-  }
-
   protected void jpred_actionPerformed(ActionEvent e)
   {
   }
@@ -3002,19 +2551,12 @@ public class GAlignFrame extends JInternalFrame
 
   }
 
-  public void annotationColour_actionPerformed(ActionEvent e)
+  public void annotationColour_actionPerformed()
   {
-
   }
 
   public void annotationColumn_actionPerformed(ActionEvent e)
   {
-
-  }
-
-  public void rnahelicesColour_actionPerformed(ActionEvent e)
-  {
-
   }
 
   public void associatedData_actionPerformed(ActionEvent e)
@@ -3107,7 +2649,7 @@ public class GAlignFrame extends JInternalFrame
 
   }
 
-  public void textColour_actionPerformed(ActionEvent e)
+  public void textColour_actionPerformed()
   {
 
   }
index bd0f1de..6b89ab4 100644 (file)
 package jalview.jbgui;
 
 import jalview.api.structures.JalviewStructureDisplayI;
+import jalview.gui.ColourMenuHelper.ColourChangeListener;
 import jalview.util.MessageManager;
 
+import java.awt.BorderLayout;
 import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 
-import javax.swing.ButtonGroup;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenu;
@@ -37,53 +38,37 @@ import javax.swing.JPanel;
 import javax.swing.JRadioButtonMenuItem;
 
 public abstract class GStructureViewer extends JInternalFrame implements
-        JalviewStructureDisplayI
+        JalviewStructureDisplayI, ColourChangeListener
 {
   // private AAStructureBindingModel bindingModel;
 
-  protected JMenu savemenu = new JMenu();
+  protected JMenu savemenu;
 
-  protected JMenu viewMenu = new JMenu();
+  protected JMenu viewMenu;
 
-  protected JMenu chainMenu = new JMenu();
+  protected JMenu colourMenu;
 
-  protected JMenu viewerActionMenu = new JMenu();
+  protected JMenu chainMenu;
 
-  protected JMenuItem alignStructs = new JMenuItem();
+  protected JMenu viewerActionMenu;
 
-  protected JMenuItem fitToWindow = new JMenuItem();
+  protected JMenuItem alignStructs;
 
-  protected JRadioButtonMenuItem seqColour = new JRadioButtonMenuItem();
+  protected JMenuItem fitToWindow;
 
-  protected JRadioButtonMenuItem chainColour = new JRadioButtonMenuItem();
+  protected JRadioButtonMenuItem seqColour;
 
-  protected JRadioButtonMenuItem chargeColour = new JRadioButtonMenuItem();
+  protected JRadioButtonMenuItem chainColour;
 
-  protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
+  protected JRadioButtonMenuItem chargeColour;
 
-  protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
+  protected JRadioButtonMenuItem viewerColour;
 
-  protected JRadioButtonMenuItem hydroColour = new JRadioButtonMenuItem();
+  protected JMenuItem helpItem;
 
-  protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
+  protected JLabel statusBar;
 
-  protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem userColour = new JRadioButtonMenuItem();
-
-  protected JRadioButtonMenuItem viewerColour = new JRadioButtonMenuItem();
-
-  protected JMenuItem helpItem = new JMenuItem();
-
-  protected JLabel statusBar = new JLabel();
-
-  protected JPanel statusPanel = new JPanel();
+  protected JPanel statusPanel;
 
   /**
    * Constructor
@@ -107,6 +92,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
     JMenu fileMenu = new JMenu();
     fileMenu.setText(MessageManager.getString("action.file"));
 
+    savemenu = new JMenu();
     savemenu.setActionCommand(MessageManager.getString("action.save_image"));
     savemenu.setText(MessageManager.getString("action.save_as"));
 
@@ -153,10 +139,14 @@ public abstract class GStructureViewer extends JInternalFrame implements
         viewMapping_actionPerformed(actionEvent);
       }
     });
+
+    viewMenu = new JMenu();
     viewMenu.setText(MessageManager.getString("action.view"));
 
+    chainMenu = new JMenu();
     chainMenu.setText(MessageManager.getString("action.show_chain"));
 
+    fitToWindow = new JMenuItem();
     fitToWindow.setText(MessageManager.getString("label.fit_to_window"));
     fitToWindow.addActionListener(new ActionListener()
     {
@@ -167,148 +157,9 @@ public abstract class GStructureViewer extends JInternalFrame implements
       }
     });
 
-    JMenu colourMenu = new JMenu();
-    colourMenu.setText(MessageManager.getString("label.colours"));
-
-    JMenuItem backGround = new JMenuItem();
-    backGround
-            .setText(MessageManager.getString("action.background_colour"));
-    backGround.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        backGround_actionPerformed(actionEvent);
-      }
-    });
-    seqColour.setSelected(false);
-    seqColour.setText(MessageManager.getString("action.by_sequence"));
-    seqColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        seqColour_actionPerformed(actionEvent);
-      }
-    });
-    chainColour.setText(MessageManager.getString("action.by_chain"));
-    chainColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        chainColour_actionPerformed(actionEvent);
-      }
-    });
-    chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
-    chargeColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        chargeColour_actionPerformed(actionEvent);
-      }
-    });
-    zappoColour.setText(MessageManager.getString("label.zappo"));
-    zappoColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        zappoColour_actionPerformed(actionEvent);
-      }
-    });
-    taylorColour.setText(MessageManager.getString("label.taylor"));
-    taylorColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        taylorColour_actionPerformed(actionEvent);
-      }
-    });
-    hydroColour.setText(MessageManager.getString("label.hydrophobicity"));
-    hydroColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        hydroColour_actionPerformed(actionEvent);
-      }
-    });
-    strandColour.setText(MessageManager
-            .getString("label.strand_propensity"));
-    strandColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        strandColour_actionPerformed(actionEvent);
-      }
-    });
-    helixColour.setText(MessageManager.getString("label.helix_propensity"));
-    helixColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        helixColour_actionPerformed(actionEvent);
-      }
-    });
-    turnColour.setText(MessageManager.getString("label.turn_propensity"));
-    turnColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        turnColour_actionPerformed(actionEvent);
-      }
-    });
-    buriedColour.setText(MessageManager.getString("label.buried_index"));
-    buriedColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        buriedColour_actionPerformed(actionEvent);
-      }
-    });
-    purinePyrimidineColour.setText(MessageManager
-            .getString("label.purine_pyrimidine"));
-    purinePyrimidineColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        purinePyrimidineColour_actionPerformed(actionEvent);
-      }
-    });
-
-    userColour.setText(MessageManager.getString("action.user_defined"));
-    userColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        userColour_actionPerformed(actionEvent);
-      }
-    });
-    viewerColour.setSelected(false);
-    viewerColour
-            .setText(MessageManager.getString("label.colour_with_jmol"));
-    viewerColour.setToolTipText(MessageManager
-            .getString("label.let_jmol_manage_structure_colours"));
-    viewerColour.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        viewerColour_actionPerformed(actionEvent);
-      }
-    });
-
     JMenu helpMenu = new JMenu();
     helpMenu.setText(MessageManager.getString("action.help"));
+    helpItem = new JMenuItem();
     helpItem.setText(MessageManager.getString("label.jmol_help"));
     helpItem.addActionListener(new ActionListener()
     {
@@ -318,6 +169,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
         showHelp_actionPerformed(actionEvent);
       }
     });
+    alignStructs = new JMenuItem();
     alignStructs
             .setText(MessageManager.getString("label.align_structures"));
     alignStructs.addActionListener(new ActionListener()
@@ -328,56 +180,30 @@ public abstract class GStructureViewer extends JInternalFrame implements
         alignStructs_actionPerformed(actionEvent);
       }
     });
-    viewerActionMenu.setText(MessageManager.getString("label.jmol"));
-    menuBar.add(fileMenu);
-    menuBar.add(viewMenu);
-    menuBar.add(colourMenu);
-    menuBar.add(viewerActionMenu);
+
+    viewerActionMenu = new JMenu();
     viewerActionMenu.setVisible(false);
-    menuBar.add(helpMenu);
+    viewerActionMenu.add(alignStructs);
+    colourMenu = new JMenu();
+    colourMenu.setText(MessageManager.getString("label.colours"));
     fileMenu.add(savemenu);
     fileMenu.add(viewMapping);
     savemenu.add(pdbFile);
     savemenu.add(png);
     savemenu.add(eps);
     viewMenu.add(chainMenu);
-
-    colourMenu.add(seqColour);
-    colourMenu.add(chainColour);
-    colourMenu.add(chargeColour);
-    colourMenu.add(zappoColour);
-    colourMenu.add(taylorColour);
-    colourMenu.add(hydroColour);
-    colourMenu.add(helixColour);
-    colourMenu.add(strandColour);
-    colourMenu.add(turnColour);
-    colourMenu.add(buriedColour);
-    colourMenu.add(purinePyrimidineColour);
-    colourMenu.add(userColour);
-    colourMenu.add(viewerColour);
-    colourMenu.add(backGround);
-
-    ButtonGroup colourButtons = new ButtonGroup();
-
-    colourButtons.add(seqColour);
-    colourButtons.add(chainColour);
-    colourButtons.add(chargeColour);
-    colourButtons.add(zappoColour);
-    colourButtons.add(taylorColour);
-    colourButtons.add(hydroColour);
-    colourButtons.add(helixColour);
-    colourButtons.add(strandColour);
-    colourButtons.add(turnColour);
-    colourButtons.add(buriedColour);
-    colourButtons.add(purinePyrimidineColour);
-    colourButtons.add(userColour);
-    colourButtons.add(viewerColour);
-
     helpMenu.add(helpItem);
-    viewerActionMenu.add(alignStructs);
 
+    menuBar.add(fileMenu);
+    menuBar.add(viewMenu);
+    menuBar.add(colourMenu);
+    menuBar.add(viewerActionMenu);
+    menuBar.add(helpMenu);
+
+    statusPanel = new JPanel();
     statusPanel.setLayout(new GridLayout());
-    this.getContentPane().add(statusPanel, java.awt.BorderLayout.SOUTH);
+    this.getContentPane().add(statusPanel, BorderLayout.SOUTH);
+    statusBar = new JLabel();
     statusPanel.add(statusBar, null);
   }
 
@@ -432,52 +258,7 @@ public abstract class GStructureViewer extends JInternalFrame implements
 
   }
 
-  public void zappoColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void taylorColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void hydroColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void helixColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void strandColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void turnColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void buriedColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void userColour_actionPerformed(ActionEvent actionEvent)
-  {
-
-  }
-
-  public void backGround_actionPerformed(ActionEvent actionEvent)
+  public void background_actionPerformed(ActionEvent actionEvent)
   {
 
   }
@@ -486,14 +267,4 @@ public abstract class GStructureViewer extends JInternalFrame implements
   {
 
   }
-
-  // {
-  // return bindingModel;
-  // }
-
-  // public void setBindingModel(AAStructureBindingModel bindingModel)
-  // {
-  // this.bindingModel = bindingModel;
-  // }
-
 }
index b5695b2..65deb5e 100755 (executable)
@@ -135,24 +135,27 @@ public class GUserDefinedColours extends JPanel
     okButton.setText(MessageManager.getString("action.ok"));
     okButton.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
-        okButton_actionPerformed(e);
+        okButton_actionPerformed();
       }
     });
     applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
     applyButton.setText(MessageManager.getString("action.apply"));
-    applyButton.addActionListener(new java.awt.event.ActionListener()
+    applyButton.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
-        applyButton_actionPerformed(e);
+        applyButton_actionPerformed();
       }
     });
     loadbutton.setFont(new java.awt.Font("Verdana", 0, 11));
     loadbutton.setText(MessageManager.getString("action.load_scheme"));
     loadbutton.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         loadbutton_actionPerformed(e);
@@ -162,6 +165,7 @@ public class GUserDefinedColours extends JPanel
     savebutton.setText(MessageManager.getString("action.save_scheme"));
     savebutton.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         savebutton_actionPerformed(e);
@@ -171,6 +175,7 @@ public class GUserDefinedColours extends JPanel
     cancelButton.setText(MessageManager.getString("action.cancel"));
     cancelButton.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         cancelButton_actionPerformed(e);
@@ -206,6 +211,7 @@ public class GUserDefinedColours extends JPanel
     caseSensitive.setText(MessageManager.getString("label.case_sensitive"));
     caseSensitive.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         caseSensitive_actionPerformed(e);
@@ -215,6 +221,7 @@ public class GUserDefinedColours extends JPanel
             .setText(MessageManager.getString("label.lower_case_colour"));
     lcaseColour.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         lcaseColour_actionPerformed(e);
@@ -257,21 +264,15 @@ public class GUserDefinedColours extends JPanel
 
   /**
    * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
    */
-  protected void okButton_actionPerformed(ActionEvent e)
+  protected void okButton_actionPerformed()
   {
   }
 
   /**
    * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
    */
-  protected void applyButton_actionPerformed(ActionEvent e)
+  protected void applyButton_actionPerformed()
   {
   }
 
index 89b8f07..fb1443d 100755 (executable)
@@ -64,7 +64,7 @@ public class AnnotationColourGradient extends FollowerColourScheme
   IdentityHashMap<SequenceI, AlignmentAnnotation> seqannot = null;
 
   @Override
-  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+  public ColourSchemeI getInstance(AnnotatedCollectionI sg,
           Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
   {
     AnnotationColourGradient acg = new AnnotationColourGradient(annotation,
@@ -250,6 +250,7 @@ public class AnnotationColourGradient extends FollowerColourScheme
    * 
    * @return DOCUMENT ME!
    */
+  @Override
   public Color findColour(char c)
   {
     return Color.red;
@@ -419,4 +420,16 @@ public class AnnotationColourGradient extends FollowerColourScheme
   {
     seqAssociated = sassoc;
   }
+
+  @Override
+  public String getSchemeName()
+  {
+    return "Annotation";
+  }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
 }
index c47f171..be77e00 100755 (executable)
@@ -38,6 +38,17 @@ public class Blosum62ColourScheme extends ResidueColourScheme
     super();
   }
 
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new Blosum62ColourScheme();
+  }
+
   @Override
   public Color findColour(char res, int j, SequenceI seq)
   {
@@ -101,10 +112,20 @@ public class Blosum62ColourScheme extends ResidueColourScheme
   }
 
   @Override
-  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
-          Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  public boolean isPeptideSpecific()
+  {
+    return true;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.Blosum62.toString();
+  }
+
+  @Override
+  public boolean isSimple()
   {
-    ColourSchemeI newcs = super.applyTo(sg, hiddenRepSequences);
-    return newcs;
+    return false;
   }
 }
index 3c68da0..a3b85b9 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
 import java.awt.Color;
+import java.util.Map;
 
 /**
  * DOCUMENT ME!
@@ -47,8 +52,32 @@ public class BuriedColourScheme extends ScoreColourScheme
    * 
    * @return DOCUMENT ME!
    */
+  @Override
   public Color makeColour(float c)
   {
     return new Color(0, (float) (1.0 - c), c);
   }
+
+  @Override
+  public boolean isPeptideSpecific()
+  {
+    return true;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.Buried.toString();
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new BuriedColourScheme();
+  }
 }
index ca4316f..9c0b953 100755 (executable)
@@ -25,7 +25,6 @@ import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
 
 import java.awt.Color;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -39,10 +38,32 @@ public class ClustalxColourScheme extends ResidueColourScheme
 
   private static final int SIXTY = 60;
 
-  /*
-   * Map from conventional colour names to Clustal version of the same
-   */
-  private static Map<Color, Color> colhash = new HashMap<Color, Color>();
+  enum ClustalColour
+  {
+    RED(0.9f, 0.2f, 0.1f), BLUE(0.5f, 0.7f, 0.9f), GREEN(0.1f, 0.8f, 0.1f),
+    ORANGE(0.9f, 0.6f, 0.3f), CYAN(0.1f, 0.7f, 0.7f),
+    PINK(0.9f, 0.5f, 0.5f), MAGENTA(0.8f, 0.3f, 0.8f), YELLOW(0.8f, 0.8f,
+            0.0f);
+
+    final Color colour;
+
+    ClustalColour(float r, float g, float b)
+    {
+      colour = new Color(r, g, b);
+    }
+  }
+  private class ConsensusColour
+  {
+    Consensus[] cons;
+
+    Color c;
+
+    public ConsensusColour(ClustalColour col, Consensus[] conses)
+    {
+      this.cons = conses;
+      this.c = col.colour;
+    }
+  }
 
   private int[][] cons2;
 
@@ -56,16 +77,12 @@ public class ClustalxColourScheme extends ResidueColourScheme
 
   private boolean includeGaps = true;
 
-  static
+  /**
+   * Default constructor (required for Class.newInstance())
+   */
+  public ClustalxColourScheme()
   {
-    colhash.put(Color.RED, new Color(0.9f, 0.2f, 0.1f));
-    colhash.put(Color.BLUE, new Color(0.5f, 0.7f, 0.9f));
-    colhash.put(Color.GREEN, new Color(0.1f, 0.8f, 0.1f));
-    colhash.put(Color.ORANGE, new Color(0.9f, 0.6f, 0.3f));
-    colhash.put(Color.CYAN, new Color(0.1f, 0.7f, 0.7f));
-    colhash.put(Color.PINK, new Color(0.9f, 0.5f, 0.5f));
-    colhash.put(Color.MAGENTA, new Color(0.8f, 0.3f, 0.8f));
-    colhash.put(Color.YELLOW, new Color(0.8f, 0.8f, 0.0f));
+
   }
 
   public ClustalxColourScheme(AnnotatedCollectionI alignment,
@@ -74,6 +91,7 @@ public class ClustalxColourScheme extends ResidueColourScheme
     alignmentChanged(alignment, hiddenReps);
   }
 
+  @Override
   public void alignmentChanged(AnnotatedCollectionI alignment,
           Map<SequenceI, SequenceCollectionI> hiddenReps)
   {
@@ -83,29 +101,15 @@ public class ClustalxColourScheme extends ResidueColourScheme
     includeGaps = isIncludeGaps(); // does nothing - TODO replace with call to
     // get the current setting of the
     // includeGaps param.
-    int start = 0;
-
-    // Initialize the array
-    for (int j = 0; j < 24; j++)
-    {
-      for (int i = 0; i < maxWidth; i++)
-      {
-        cons2[i][j] = 0;
-      }
-    }
-
-    int res;
-    int i;
-    int j = 0;
-    char[] seq;
+    int res = 0;
 
     for (SequenceI sq : seqs)
     {
-      seq = sq.getSequence();
+      char[] seq = sq.getSequence();
 
       int end_j = seq.length - 1;
 
-      for (i = start; i <= end_j; i++)
+      for (int i = 0; i <= end_j; i++)
       {
         if ((seq.length - 1) < i)
         {
@@ -115,18 +119,15 @@ public class ClustalxColourScheme extends ResidueColourScheme
         {
           res = ResidueProperties.aaIndex[seq[i]];
         }
-
         cons2[i][res]++;
       }
-
-      j++;
     }
 
     this.size = seqs.size();
     makeColours();
   }
 
-  public void makeColours()
+  void makeColours()
   {
     conses[0] = new Consensus("WLVIMAFCYHP", SIXTY);
     conses[1] = new Consensus("WLVIMAFCYHP", EIGHTY);
@@ -167,15 +168,15 @@ public class ClustalxColourScheme extends ResidueColourScheme
 
     Consensus[] tmp8 = new Consensus[1];
     tmp8[0] = conses[30]; // G
-    colours[7] = new ConsensusColour(colhash.get(Color.ORANGE), tmp8);
+    colours[7] = new ConsensusColour(ClustalColour.ORANGE, tmp8);
 
     Consensus[] tmp9 = new Consensus[1];
     tmp9[0] = conses[31]; // P
-    colours[8] = new ConsensusColour(colhash.get(Color.YELLOW), tmp9);
+    colours[8] = new ConsensusColour(ClustalColour.YELLOW, tmp9);
 
     Consensus[] tmp10 = new Consensus[1];
     tmp10[0] = conses[27]; // C
-    colours[9] = new ConsensusColour(colhash.get(Color.PINK), tmp8);
+    colours[9] = new ConsensusColour(ClustalColour.PINK, tmp8);
 
     Consensus[] tmp1 = new Consensus[14];
     tmp1[0] = conses[0]; // %
@@ -192,9 +193,9 @@ public class ClustalxColourScheme extends ResidueColourScheme
     tmp1[11] = conses[25]; // Y
     tmp1[12] = conses[18]; // P
     tmp1[13] = conses[19]; // p
-    colours[0] = new ConsensusColour(colhash.get(Color.BLUE), tmp1);
+    colours[0] = new ConsensusColour(ClustalColour.BLUE, tmp1);
 
-    colours[10] = new ConsensusColour(colhash.get(Color.CYAN), tmp1);
+    colours[10] = new ConsensusColour(ClustalColour.CYAN, tmp1);
 
     Consensus[] tmp2 = new Consensus[5];
     tmp2[0] = conses[8]; // t
@@ -202,14 +203,14 @@ public class ClustalxColourScheme extends ResidueColourScheme
     tmp2[2] = conses[22]; // T
     tmp2[3] = conses[0]; // %
     tmp2[4] = conses[1]; // #
-    colours[1] = new ConsensusColour(colhash.get(Color.GREEN), tmp2);
+    colours[1] = new ConsensusColour(ClustalColour.GREEN, tmp2);
 
     Consensus[] tmp3 = new Consensus[3];
 
     tmp3[0] = conses[17]; // N
     tmp3[1] = conses[29]; // D
     tmp3[2] = conses[5]; // n
-    colours[2] = new ConsensusColour(colhash.get(Color.GREEN), tmp3);
+    colours[2] = new ConsensusColour(ClustalColour.GREEN, tmp3);
 
     Consensus[] tmp4 = new Consensus[6];
     tmp4[0] = conses[6]; // q = QE
@@ -218,14 +219,14 @@ public class ClustalxColourScheme extends ResidueColourScheme
     tmp4[3] = conses[3]; // +
     tmp4[4] = conses[28]; // K
     tmp4[5] = conses[20]; // R
-    colours[3] = new ConsensusColour(colhash.get(Color.GREEN), tmp4);
+    colours[3] = new ConsensusColour(ClustalColour.GREEN, tmp4);
 
     Consensus[] tmp5 = new Consensus[4];
     tmp5[0] = conses[3]; // +
     tmp5[1] = conses[28]; // K
     tmp5[2] = conses[20]; // R
     tmp5[3] = conses[19]; // Q
-    colours[4] = new ConsensusColour(colhash.get(Color.RED), tmp5);
+    colours[4] = new ConsensusColour(ClustalColour.RED, tmp5);
 
     Consensus[] tmp6 = new Consensus[6];
     tmp6[0] = conses[3]; // -
@@ -234,7 +235,7 @@ public class ClustalxColourScheme extends ResidueColourScheme
     tmp6[3] = conses[6]; // QE
     tmp6[4] = conses[19]; // Q
     tmp6[5] = conses[2]; // DE
-    colours[5] = new ConsensusColour(colhash.get(Color.MAGENTA), tmp6);
+    colours[5] = new ConsensusColour(ClustalColour.MAGENTA, tmp6);
 
     Consensus[] tmp7 = new Consensus[5];
     tmp7[0] = conses[3]; // -
@@ -242,7 +243,7 @@ public class ClustalxColourScheme extends ResidueColourScheme
     tmp7[2] = conses[10]; // E
     tmp7[3] = conses[17]; // N
     tmp7[4] = conses[2]; // DE
-    colours[6] = new ConsensusColour(colhash.get(Color.MAGENTA), tmp7);
+    colours[6] = new ConsensusColour(ClustalColour.MAGENTA, tmp7);
 
     // Now attach the ConsensusColours to the residue letters
     residueColour = new ConsensusColour[20];
@@ -294,9 +295,9 @@ public class ClustalxColourScheme extends ResidueColourScheme
       return currentColour;
     }
 
-    for (int k = 0; k < residueColour[i].conses.length; k++)
+    for (int k = 0; k < residueColour[i].cons.length; k++)
     {
-      if (residueColour[i].conses[k].isConserved(cons2, j, size,
+      if (residueColour[i].cons[k].isConserved(cons2, j, size,
               includeGaps))
       {
         currentColour = residueColour[i].c;
@@ -305,9 +306,12 @@ public class ClustalxColourScheme extends ResidueColourScheme
 
     if (i == 4)
     {
+      /*
+       * override to colour C pink if 100% conserved
+       */
       if (conses[27].isConserved(cons2, j, size, includeGaps))
       {
-        currentColour = colhash.get(Color.PINK);
+        currentColour = ClustalColour.PINK.colour;
       }
     }
 
@@ -337,7 +341,7 @@ public class ClustalxColourScheme extends ResidueColourScheme
   }
 
   @Override
-  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+  public ColourSchemeI getInstance(AnnotatedCollectionI sg,
           Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
   {
     ClustalxColourScheme css = new ClustalxColourScheme(sg,
@@ -345,19 +349,22 @@ public class ClustalxColourScheme extends ResidueColourScheme
     css.includeGaps = includeGaps;
     return css;
   }
-}
 
-class ConsensusColour
-{
-  Consensus[] conses;
-
-  Color c;
+  @Override
+  public boolean isPeptideSpecific()
+  {
+    return true;
+  }
 
-  public ConsensusColour(Color c, Consensus[] conses)
+  @Override
+  public String getSchemeName()
   {
-    this.conses = conses;
+    return JalviewColourScheme.Clustal.toString();
+  }
 
-    // this.list = list;
-    this.c = c;
+  @Override
+  public boolean isSimple()
+  {
+    return false;
   }
 }
index da99a4a..64248c5 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.schemes;
 
+import jalview.analysis.Conservation;
 import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.ProfilesI;
 import jalview.datamodel.SequenceCollectionI;
@@ -31,99 +32,134 @@ import java.util.Map;
 public interface ColourSchemeI
 {
   /**
+   * Returns the colour for the given character. For use when the colour depends
+   * only on the symbol.
    * 
    * @param c
-   * @return the colour for the given character
+   * @return
    */
-  public Color findColour(char c);
+  Color findColour(char c);
 
   /**
+   * Returns the possibly context dependent colour for the given symbol at the
+   * aligned position in the given sequence. For example, the colour may depend
+   * on the symbol's relationship to the consensus residue for the column.
    * 
-   * @param c
-   *          - sequence symbol or gap
-   * @param j
-   *          - position in seq
+   * @param symbol
+   * @param position
    * @param seq
-   *          - sequence being coloured
-   * @return context dependent colour for the given symbol at the position in
-   *         the given sequence
+   * @return
    */
-  public Color findColour(char c, int j, SequenceI seq);
+  Color findColour(char symbol, int position, SequenceI seq);
 
   /**
-   * assign the given consensus profile for the colourscheme
+   * Assigns the given consensus profile for the colourscheme
    */
-  public void setConsensus(ProfilesI hconsensus);
+  void setConsensus(ProfilesI hconsensus);
 
   /**
-   * assign the given conservation to the colourscheme
+   * Assigns the given conservation to the colourscheme
    * 
    * @param c
    */
-  public void setConservation(jalview.analysis.Conservation c);
+  void setConservation(Conservation c);
 
   /**
-   * enable or disable conservation shading for this colourscheme
+   * Enable or disable conservation shading for this colourscheme
    * 
    * @param conservationApplied
    */
-  public void setConservationApplied(boolean conservationApplied);
+  void setConservationApplied(boolean conservationApplied);
 
   /**
+   * Answers true if conservation shading is enabled for this colourscheme
    * 
-   * @return true if conservation shading is enabled for this colourscheme
+   * @return
    */
-  public boolean conservationApplied();
+  boolean conservationApplied();
 
   /**
-   * set scale factor for bleaching of colour in unconserved regions
+   * Sets the scale factor for bleaching of colour in unconserved regions
    * 
    * @param i
    */
-  public void setConservationInc(int i);
+  void setConservationInc(int i);
 
   /**
+   * Returns the scale factor for bleaching colour in unconserved regions
    * 
-   * @return scale factor for bleaching colour in unconserved regions
+   * @return
    */
-  public int getConservationInc();
+  int getConservationInc();
 
   /**
+   * Returns the percentage identity threshold for applying colourscheme
    * 
-   * @return percentage identity threshold for applying colourscheme
+   * @return
    */
-  public int getThreshold();
+  int getThreshold();
 
   /**
-   * set percentage identity threshold and type of %age identity calculation for
-   * shading
+   * Sets the percentage identity threshold and type of %age identity
+   * calculation for shading
    * 
-   * @param ct
+   * @param pct
    *          0..100 percentage identity for applying this colourscheme
    * @param ignoreGaps
    *          when true, calculate PID without including gapped positions
    */
-  public void setThreshold(int ct, boolean ignoreGaps);
+  void setThreshold(int pct, boolean ignoreGaps);
 
   /**
-   * recalculate dependent data using the given sequence collection, taking
+   * Recalculate dependent data using the given sequence collection, taking
    * account of hidden rows
    * 
    * @param alignment
    * @param hiddenReps
    */
-  public void alignmentChanged(AnnotatedCollectionI alignment,
+  void alignmentChanged(AnnotatedCollectionI alignment,
           Map<SequenceI, SequenceCollectionI> hiddenReps);
 
   /**
-   * create a new instance of the colourscheme configured to colour the given
-   * connection
+   * Creates and returns a new instance of the colourscheme configured to colour
+   * the given collection. Note that even simple colour schemes should return a
+   * new instance for each call to this method, as different instances may have
+   * differing shading by consensus or percentage identity applied.
    * 
    * @param sg
    * @param hiddenRepSequences
-   * @return copy of current scheme with any inherited settings transfered
+   * @return copy of current scheme with any inherited settings transferred
    */
-  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+  ColourSchemeI getInstance(AnnotatedCollectionI sg,
           Map<SequenceI, SequenceCollectionI> hiddenRepSequences);
 
+  /**
+   * Answers true if the colour scheme is suitable for the given data, else
+   * false. For example, some colour schemes are specific to either peptide or
+   * nucleotide, or only apply if certain kinds of annotation are present.
+   * 
+   * @param ac
+   * @return
+   */
+  // TODO can make this method static in Java 8
+  boolean isApplicableTo(AnnotatedCollectionI ac);
+
+  /**
+   * Answers the 'official' name of the colour scheme (as used, for example, as
+   * a Jalview startup parameter)
+   * 
+   * @return
+   */
+  String getSchemeName();
+
+  /**
+   * Answers true if the colour scheme depends only on the sequence symbol, and
+   * not on other information such as alignment consensus or annotation. (Note
+   * that simple colour schemes may have a fading by percentage identity or
+   * conservation overlaid.) Simple colour schemes can be propagated to
+   * structure viewers.
+   * 
+   * @return
+   */
+  boolean isSimple();
 }
index 0d9c39d..5190c72 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.schemes;
 
 import jalview.datamodel.AnnotatedCollectionI;
+import jalview.util.ColorUtils;
 
 import java.awt.Color;
 
@@ -38,564 +39,66 @@ import java.awt.Color;
  */
 public class ColourSchemeProperty
 {
-  /** Undefined Colourscheme Index */
-  public static final int UNDEFINED = -1;
-
-  /** for schemes defined on the fly */
-  public static final int USER_DEFINED = 0;
-
-  /** No Colourscheme Index */
-  public static final int NONE = 1;
-
-  /** DOCUMENT ME!! */
-  public static final int CLUSTAL = 2;
-
-  /** DOCUMENT ME!! */
-  public static final int BLOSUM = 3;
-
-  /** DOCUMENT ME!! */
-  public static final int PID = 4;
-
-  /** DOCUMENT ME!! */
-  public static final int ZAPPO = 5;
-
-  /** DOCUMENT ME!! */
-  public static final int TAYLOR = 6;
-
-  /** DOCUMENT ME!! */
-  public static final int HYDROPHOBIC = 7;
-
-  /** DOCUMENT ME!! */
-  public static final int HELIX = 8;
-
-  /** DOCUMENT ME!! */
-  public static final int STRAND = 9;
-
-  /** DOCUMENT ME!! */
-  public static final int TURN = 10;
-
-  /** DOCUMENT ME!! */
-  public static final int BURIED = 11;
-
-  /** DOCUMENT ME!! */
-  public static final int NUCLEOTIDE = 12;
 
   /**
-   * purine/pyrimidine
-   */
-  public static final int PURINEPYRIMIDINE = 13;
-
-  public static final int COVARIATION = 14;
-
-  public static final int TCOFFEE = 15;
-
-  public static final int RNAHELIX = 16;
-
-  public static final int RNAINTERACTION = 17;
-
-  /**
-   * index of first colourscheme (includes 'None')
-   */
-  public static final int FIRST_COLOUR = NONE;
-
-  public static final int LAST_COLOUR = RNAINTERACTION;
-
-  /**
-   * DOCUMENT ME!
+   * Returns a colour scheme for the given name, with which the given data may
+   * be coloured. The name is not case-sensitive, and may be one of
+   * <ul>
+   * <li>Clustal</li>
+   * <li>Blosum62</li>
+   * <li>% Identity</li>
+   * <li>Hydrophobic</li>
+   * <li>Zappo</li>
+   * <li>Taylor</li>
+   * <li>Helix Propensity</li>
+   * <li>Strand Propensity</li>
+   * <li>Turn Propensity</li>
+   * <li>Buried Index</li>
+   * <li>Nucleotide</li>
+   * <li>Purine/Pyrimidine</li>
+   * <li>T-Coffee Scores</li>
+   * <li>RNA Helices</li>
+   * <li>User Defined</li>
+   * <li>an AWT colour name e.g. red</li>
+   * <li>an AWT hex rgb colour e.g. ff2288</li>
+   * <li>residue colours list e.g. D,E=red;K,R,H=0022FF;c=yellow</li>
+   * </ul>
+   * If none of these formats is matched, the string is converted to a colour
+   * using a hashing algorithm. For name "None", returns null.
    * 
+   * @param forData
    * @param name
-   *          DOCUMENT ME!
-   * 
-   * @return DOCUMENT ME!
+   * @return
    */
-  public static int getColourIndexFromName(String name)
+  public static ColourSchemeI getColourScheme(AnnotatedCollectionI forData,
+          String name)
   {
-    int ret = UNDEFINED;
-
-    if (name.equalsIgnoreCase("Clustal"))
-    {
-      ret = CLUSTAL;
-    }
-    else if (name.equalsIgnoreCase("Blosum62"))
+    if (ResidueColourScheme.NONE.equalsIgnoreCase(name))
     {
-      ret = BLOSUM;
-    }
-    else if (name.equalsIgnoreCase("% Identity"))
-    {
-      ret = PID;
-    }
-    else if (name.equalsIgnoreCase("Zappo"))
-    {
-      ret = ZAPPO;
-    }
-    else if (name.equalsIgnoreCase("Taylor"))
-    {
-      ret = TAYLOR;
-    }
-    else if (name.equalsIgnoreCase("Hydrophobic"))
-    {
-      ret = HYDROPHOBIC;
-    }
-    else if (name.equalsIgnoreCase("Helix Propensity"))
-    {
-      ret = HELIX;
-    }
-    else if (name.equalsIgnoreCase("Strand Propensity"))
-    {
-      ret = STRAND;
-    }
-    else if (name.equalsIgnoreCase("Turn Propensity"))
-    {
-      ret = TURN;
-    }
-    else if (name.equalsIgnoreCase("Buried Index"))
-    {
-      ret = BURIED;
-    }
-    else if (name.equalsIgnoreCase("Nucleotide"))
-    {
-      ret = NUCLEOTIDE;
-    }
-    else if (name.equalsIgnoreCase("T-Coffee Scores"))
-    {
-      ret = TCOFFEE;
-    }
+      return null;
 
-    else if (name.equalsIgnoreCase("User Defined"))
-    {
-      ret = USER_DEFINED;
-    }
-    else if (name.equalsIgnoreCase("None"))
-    {
-      ret = NONE;
-    }
-    else if (name.equalsIgnoreCase("Purine/Pyrimidine"))
-    {
-      ret = PURINEPYRIMIDINE;
-    }
-    else if (name.equalsIgnoreCase("RNA Interaction type"))
-    {
-      ret = RNAINTERACTION;
     }
-    else if (name.equalsIgnoreCase("RNA Helices"))
-    {
-      ret = RNAHELIX;
-    }
-    // else if (name.equalsIgnoreCase("Covariation"))
-    // {
-    // ret = COVARIATION;
-    // }
-
-    return ret;
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param cs
-   *          DOCUMENT ME!
-   * 
-   * @return DOCUMENT ME!
-   */
-  public static String getColourName(ColourSchemeI cs)
-  {
-
-    int index = NONE;
 
-    if (cs instanceof ClustalxColourScheme)
-    {
-      index = CLUSTAL;
-    }
-    else if (cs instanceof Blosum62ColourScheme)
-    {
-      index = BLOSUM;
-    }
-    else if (cs instanceof PIDColourScheme)
-    {
-      index = PID;
-    }
-    else if (cs instanceof ZappoColourScheme)
-    {
-      index = ZAPPO;
-    }
-    else if (cs instanceof TaylorColourScheme)
-    {
-      index = TAYLOR;
-    }
-    else if (cs instanceof HydrophobicColourScheme)
-    {
-      index = HYDROPHOBIC;
-    }
-    else if (cs instanceof HelixColourScheme)
-    {
-      index = HELIX;
-    }
-    else if (cs instanceof StrandColourScheme)
-    {
-      index = STRAND;
-    }
-    else if (cs instanceof TurnColourScheme)
-    {
-      index = TURN;
-    }
-    else if (cs instanceof BuriedColourScheme)
-    {
-      index = BURIED;
-    }
-    else if (cs instanceof NucleotideColourScheme)
-    {
-      index = NUCLEOTIDE;
-    }
-    else if (cs instanceof PurinePyrimidineColourScheme)
-    {
-      index = PURINEPYRIMIDINE;
-    }
-    else if (cs instanceof TCoffeeColourScheme)
-    {
-      index = TCOFFEE;
-    }
-    else if (cs instanceof RNAHelicesColour)
-    {
-      index = RNAHELIX;
-    }
     /*
-     * else if (cs instanceof CovariationColourScheme) { index = COVARIATION; }
+     * if this is the name of a registered colour scheme, just
+     * create a new instance of it
      */
-    else if (cs instanceof UserColourScheme)
+    ColourSchemeI scheme = ColourSchemes.getInstance().getColourScheme(
+            name, forData, null);
+    if (scheme != null)
     {
-      if ((((UserColourScheme) cs).getName() != null)
-              && (((UserColourScheme) cs).getName().length() > 0))
-      {
-        return ((UserColourScheme) cs).getName();
-      }
-      // get default colourscheme name
-      index = USER_DEFINED;
+      return scheme;
     }
 
-    return getColourName(index);
-  }
-
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param index
-   *          DOCUMENT ME!
-   * 
-   * @return DOCUMENT ME!
-   */
-  public static String getColourName(int index)
-  {
-    String ret = null;
-
-    switch (index)
-    {
-    case CLUSTAL:
-      ret = "Clustal";
-
-      break;
-
-    case BLOSUM:
-      ret = "Blosum62";
-
-      break;
-
-    case PID:
-      ret = "% Identity";
-
-      break;
-
-    case ZAPPO:
-      ret = "Zappo";
-
-      break;
-
-    case TAYLOR:
-      ret = "Taylor";
-      break;
-
-    case HYDROPHOBIC:
-      ret = "Hydrophobic";
-
-      break;
-
-    case HELIX:
-      ret = "Helix Propensity";
-
-      break;
-
-    case STRAND:
-      ret = "Strand Propensity";
-
-      break;
-
-    case TURN:
-      ret = "Turn Propensity";
-
-      break;
-
-    case BURIED:
-      ret = "Buried Index";
-
-      break;
-
-    case NUCLEOTIDE:
-      ret = "Nucleotide";
-
-      break;
-
-    case PURINEPYRIMIDINE:
-      ret = "Purine/Pyrimidine";
-
-      break;
-
-    case TCOFFEE:
-      ret = "T-Coffee Scores";
-
-      break;
-
-    case RNAINTERACTION:
-      ret = "RNA Interaction type";
-
-      break;
-    case RNAHELIX:
-      ret = "RNA Helices";
-
-      break;
     /*
-     * case COVARIATION: ret = "Covariation";
-     * 
-     * break;
+     * try to parse the string as a residues colour scheme
+     * e.g. A=red;T,G=blue etc
+     * else parse the name as a colour specification
+     * e.g. "red" or "ff00ed",
+     * or failing that hash the name to a colour
      */
-    case USER_DEFINED:
-      ret = "User Defined";
-
-      break;
-
-    default:
-      ret = "None";
-
-      break;
-    }
-
-    return ret;
-  }
-
-  /**
-   * retrieve or create colourscheme associated with name
-   * 
-   * @param seqs
-   *          sequences to colour
-   * @param width
-   *          range of sequences to colour
-   * @param name
-   *          colourscheme name, applet colour parameter specification, or
-   *          string to parse as colour for new coloursheme
-   * @return Valid Colourscheme
-   */
-  public static ColourSchemeI getColour(AnnotatedCollectionI alignment,
-          String name)
-  {
-    int colindex = getColourIndexFromName(name);
-    if (colindex == UNDEFINED)
-    {
-      if (name.indexOf('=') == -1)
-      {
-        // try to build a colour from the string directly
-        try
-        {
-          return new UserColourScheme(name);
-        } catch (Exception e)
-        {
-          // System.err.println("Ignoring unknown colourscheme name");
-        }
-      }
-      else
-      {
-        // try to parse the string as a residue colourscheme
-        try
-        {
-          // fix the launchApp user defined coloursheme transfer bug
-          jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
-                  "white");
-          ucs.parseAppletParameter(name);
-
-        } catch (Exception e)
-        {
-          // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
-        }
-      }
-    }
-    return getColour(alignment, getColourIndexFromName(name));
-  }
-
-  /**
-   * Construct an instance of ColourSchemeI corresponding to the given
-   * colourscheme index
-   * 
-   * @param seqs
-   *          sequences to be coloured by colourscheme
-   * @param width
-   *          geometry of alignment
-   * @param index
-   *          colourscheme number
-   * 
-   * @return null or an instance of the colourscheme configured to colour given
-   *         sequence set
-   */
-  public static ColourSchemeI getColour(
-          jalview.datamodel.AnnotatedCollectionI coll, int index)
-  {
-    // TODO 3.0 2.8 refactor signature to take an alignmentI like container so
-    // colourschemes based on annotation can be initialised
-    ColourSchemeI cs = null;
-
-    switch (index)
-    {
-    case CLUSTAL:
-      cs = new ClustalxColourScheme(coll, null);
-
-      break;
-
-    case BLOSUM:
-      cs = new Blosum62ColourScheme();
-
-      break;
-
-    case PID:
-      cs = new PIDColourScheme();
-
-      break;
-
-    case ZAPPO:
-      cs = new ZappoColourScheme();
-
-      break;
-
-    case TAYLOR:
-      cs = new TaylorColourScheme();
-      break;
-
-    case HYDROPHOBIC:
-      cs = new HydrophobicColourScheme();
-
-      break;
-
-    case HELIX:
-      cs = new HelixColourScheme();
-
-      break;
-
-    case STRAND:
-      cs = new StrandColourScheme();
-
-      break;
-
-    case TURN:
-      cs = new TurnColourScheme();
-
-      break;
-
-    case BURIED:
-      cs = new BuriedColourScheme();
-
-      break;
-
-    case NUCLEOTIDE:
-      cs = new NucleotideColourScheme();
-
-      break;
-
-    case PURINEPYRIMIDINE:
-      cs = new PurinePyrimidineColourScheme();
-
-      break;
-
-    case TCOFFEE:
-      cs = new TCoffeeColourScheme(coll);
-      break;
-
-    case RNAHELIX:
-      cs = new RNAHelicesColour(coll);
-      break;
-
-    // case COVARIATION:
-    // cs = new CovariationColourScheme(annotation);
-    // break;
-
-    case USER_DEFINED:
-      Color[] col = new Color[24];
-      for (int i = 0; i < 24; i++)
-      {
-        col[i] = Color.white;
-      }
-      cs = new UserColourScheme(col);
-      break;
-
-    default:
-      break;
-    }
-
-    return cs;
-  }
-
-  public static Color getAWTColorFromName(String name)
-  {
-    Color col = null;
-    name = name.toLowerCase();
-    if (name.equals("black"))
-    {
-      col = Color.black;
-    }
-    else if (name.equals("blue"))
-    {
-      col = Color.blue;
-    }
-    else if (name.equals("cyan"))
-    {
-      col = Color.cyan;
-    }
-    else if (name.equals("darkGray"))
-    {
-      col = Color.darkGray;
-    }
-    else if (name.equals("gray"))
-    {
-      col = Color.gray;
-    }
-    else if (name.equals("green"))
-    {
-      col = Color.green;
-    }
-    else if (name.equals("lightGray"))
-    {
-      col = Color.lightGray;
-    }
-    else if (name.equals("magenta"))
-    {
-      col = Color.magenta;
-    }
-    else if (name.equals("orange"))
-    {
-      col = Color.orange;
-    }
-    else if (name.equals("pink"))
-    {
-      col = Color.pink;
-    }
-    else if (name.equals("red"))
-    {
-      col = Color.red;
-    }
-    else if (name.equals("white"))
-    {
-      col = Color.white;
-    }
-    else if (name.equals("yellow"))
-    {
-      col = Color.yellow;
-    }
-
-    return col;
+    UserColourScheme ucs = new UserColourScheme(name);
+    return ucs;
   }
 
   public static Color rnaHelices[] = null;
@@ -621,17 +124,28 @@ public class ColourSchemeProperty
     // Generate random colors and store
     for (; j <= n; j++)
     {
-      rnaHelices[j] = jalview.util.ColorUtils
-              .generateRandomColor(Color.white);
+      rnaHelices[j] = ColorUtils.generateRandomColor(Color.white);
     }
   }
 
   /**
-   * delete the existing cached RNA helces colours
+   * delete the existing cached RNA helices colours
    */
   public static void resetRnaHelicesShading()
   {
     rnaHelices = null;
   }
 
+  /**
+   * Returns the name of the colour scheme (or "None" if it is null)
+   * 
+   * @param cs
+   * @return
+   */
+  public static String getColourName(ColourSchemeI cs)
+  {
+    return cs == null ? ResidueColourScheme.NONE : cs
+            .getSchemeName();
+  }
+
 }
diff --git a/src/jalview/schemes/ColourSchemes.java b/src/jalview/schemes/ColourSchemes.java
new file mode 100644 (file)
index 0000000..817fb01
--- /dev/null
@@ -0,0 +1,290 @@
+package jalview.schemes;
+
+import jalview.binding.JalviewUserColours;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
+import java.awt.Color;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class ColourSchemes
+{
+  /*
+   * singleton instance of this class
+   */
+  private static ColourSchemes instance = new ColourSchemes();
+
+  /*
+   * a map from scheme name to an instance of it
+   */
+  private Map<String, ColourSchemeI> schemes;
+
+  /**
+   * Returns the singleton instance of this class
+   * 
+   * @return
+   */
+  public static ColourSchemes getInstance()
+  {
+    return instance;
+  }
+
+  private ColourSchemes()
+  {
+    loadColourSchemes();
+  }
+
+  /**
+   * Loads an instance of each standard or user-defined colour scheme
+   * 
+   * @return
+   */
+  void loadColourSchemes()
+  {
+    /*
+     * store in an order-preserving map, so items can be added to menus 
+     * in the order in which they are 'discovered'
+     */
+    schemes = new LinkedHashMap<String, ColourSchemeI>();
+
+    for (JalviewColourScheme cs : JalviewColourScheme.values())
+    {
+      try
+      {
+        registerColourScheme(cs.getSchemeClass().newInstance());
+      } catch (InstantiationException | IllegalAccessException e)
+      {
+        System.err.println("Error instantiating colour scheme for "
+                + cs.toString() + " " + e.getMessage());
+      }
+    }
+  }
+
+  /**
+   * Registers a colour scheme
+   * 
+   * @param cs
+   */
+  public void registerColourScheme(ColourSchemeI cs)
+  {
+    String name = cs.getSchemeName();
+    if (name == null)
+    {
+      System.err.println("ColourScheme name may not be null");
+      return;
+    }
+
+    /*
+     * name is lower-case for non-case-sensitive lookup
+     * (name in the colour keeps its true case)
+     */
+    String lower = name.toLowerCase();
+    if (schemes.containsKey(lower))
+    {
+      System.err
+              .println("Warning: overwriting colour scheme named " + name);
+    }
+    schemes.put(lower, cs);
+  }
+
+  /**
+   * Removes a colour scheme by name
+   * 
+   * @param name
+   */
+  public void removeColourScheme(String name)
+  {
+    schemes.remove(name);
+  }
+  
+  /**
+   * Returns an instance of the colour scheme with which the given view may be
+   * coloured
+   * 
+   * @param name
+   *          name of the colour scheme
+   * @param forData
+   *          the data to be coloured
+   * @param optional
+   *          map from hidden representative sequences to the sequences they
+   *          represent
+   * @return
+   */
+  public ColourSchemeI getColourScheme(String name,
+          AnnotatedCollectionI forData,
+          Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  {
+    if (name == null)
+    {
+      return null;
+    }
+    ColourSchemeI cs = schemes.get(name.toLowerCase());
+    return cs == null ? null : cs.getInstance(forData, hiddenRepSequences);
+  }
+
+  /**
+   * Returns an instance of the colour scheme with which the given view may be
+   * coloured
+   * 
+   * @param name
+   *          name of the colour scheme
+   * @param forData
+   *          the data to be coloured
+   * @return
+   */
+  public ColourSchemeI getColourScheme(String name,
+          AnnotatedCollectionI forData)
+  {
+    return getColourScheme(name, forData, null);
+  }
+
+  /**
+   * Returns an iterable set of the colour schemes, in the order in which they
+   * were added
+   * 
+   * @return
+   */
+  public Iterable<ColourSchemeI> getColourSchemes()
+  {
+    return schemes.values();
+  }
+
+  /**
+   * Answers true if there is a scheme with the given name, else false. The test
+   * is not case-sensitive.
+   * 
+   * @param name
+   * @return
+   */
+  public boolean nameExists(String name)
+  {
+    if (name == null)
+    {
+      return false;
+    }
+    name = name.toLowerCase();
+    for (ColourSchemeI scheme : getColourSchemes())
+    {
+      if (name.equals(scheme.getSchemeName().toLowerCase()))
+      {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  /**
+   * Loads a user defined colour scheme from file. The file should contain a
+   * definition of residue colours in XML format as defined in
+   * JalviewUserColours.xsd.
+   * 
+   * @param filePath
+   * 
+   * @return
+   */
+  public static UserColourScheme loadColourScheme(String filePath)
+  {
+    UserColourScheme ucs = null;
+    Color[] newColours = null;
+    File file = new File(filePath);
+    try
+    {
+      InputStreamReader in = new InputStreamReader(
+              new FileInputStream(file), "UTF-8");
+  
+      jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours();
+  
+      org.exolab.castor.xml.Unmarshaller unmar = new org.exolab.castor.xml.Unmarshaller(
+              jucs);
+      jucs = (jalview.schemabinding.version2.JalviewUserColours) unmar
+              .unmarshal(in);
+  
+      /*
+       * non-case-sensitive colours are for 20 amino acid codes,
+       * B, Z, X and Gap
+       * optionally, lower-case alternatives for all except Gap
+       */
+      newColours = new Color[24];
+      Color[] lowerCase = new Color[23];
+      boolean caseSensitive = false;
+  
+      String name;
+      int index;
+      for (int i = 0; i < jucs.getColourCount(); i++)
+      {
+        name = jucs.getColour(i).getName();
+        if (ResidueProperties.aa3Hash.containsKey(name))
+        {
+          index = ResidueProperties.aa3Hash.get(name).intValue();
+        }
+        else
+        {
+          index = ResidueProperties.aaIndex[name.charAt(0)];
+        }
+        if (index == -1)
+        {
+          continue;
+        }
+  
+        Color color = new Color(Integer.parseInt(jucs.getColour(i)
+                .getRGB(), 16));
+        if (name.toLowerCase().equals(name))
+        {
+          caseSensitive = true;
+          lowerCase[index] = color;
+        }
+        else
+        {
+          newColours[index] = color;
+        }
+      }
+  
+      /*
+       * instantiate the colour scheme
+       */
+      ucs = new UserColourScheme(newColours);
+      ucs.setName(jucs.getSchemeName());
+      if (caseSensitive)
+      {
+        ucs.setLowerCaseColours(lowerCase);
+      }
+    } catch (Exception ex)
+    {
+      // Could be old Jalview Archive format
+      try
+      {
+        InputStreamReader in = new InputStreamReader(new FileInputStream(
+                file), "UTF-8");
+  
+        jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();
+  
+        jucs = JalviewUserColours.unmarshal(in);
+  
+        newColours = new Color[jucs.getColourCount()];
+  
+        for (int i = 0; i < 24; i++)
+        {
+          newColours[i] = new Color(Integer.parseInt(jucs.getColour(i)
+                  .getRGB(), 16));
+        }
+        ucs = new UserColourScheme(newColours);
+        ucs.setName(jucs.getSchemeName());
+      } catch (Exception ex2)
+      {
+        ex2.printStackTrace();
+      }
+  
+      if (newColours == null)
+      {
+        System.out.println("Error loading User ColourFile\n" + ex);
+      }
+    }
+  
+    return ucs;
+  }
+}
index 49d5dee..6cb095b 100644 (file)
 package jalview.schemes;
 
 import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+import jalview.util.ColorUtils;
 
 import java.awt.Color;
 import java.util.Hashtable;
+import java.util.Map;
 
 /**
  * Became RNAHelicesColour.java. Placeholder for true covariation color scheme
@@ -33,15 +38,26 @@ import java.util.Hashtable;
  */
 public class CovariationColourScheme extends ResidueColourScheme
 {
-  public Hashtable helixcolorhash = new Hashtable();
+  public Map<String, Color> helixcolorhash = new Hashtable<String, Color>();
 
-  public Hashtable positionsToHelix = new Hashtable();
+  public Map<Integer, String> positionsToHelix = new Hashtable<Integer, String>();
 
   int numHelix = 0;
 
   public AlignmentAnnotation annotation;
 
   /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new CovariationColourScheme(coll.getAlignmentAnnotation()[0]);
+  }
+
+  /**
    * Creates a new CovariationColourScheme object.
    */
   public CovariationColourScheme(AlignmentAnnotation annotation)
@@ -71,8 +87,8 @@ public class CovariationColourScheme extends ResidueColourScheme
 
     for (int j = 0; j <= numHelix; j++)
     {
-      helixcolorhash.put(Integer.toString(j),
-              jalview.util.ColorUtils.generateRandomColor(Color.white));
+      helixcolorhash.put(String.valueOf(j),
+              ColorUtils.generateRandomColor(Color.white));
     }
 
   }
@@ -85,6 +101,7 @@ public class CovariationColourScheme extends ResidueColourScheme
    * 
    * @return DOCUMENT ME!
    */
+  @Override
   public Color findColour(char c)
   {
     // System.out.println("called"); log.debug
@@ -108,12 +125,12 @@ public class CovariationColourScheme extends ResidueColourScheme
     Color currentColour = Color.white;
     String currentHelix = null;
     // System.out.println(c + " " + j);
-    currentHelix = (String) positionsToHelix.get(j);
+    currentHelix = positionsToHelix.get(j);
     // System.out.println(positionsToHelix.get(j));
 
     if (currentHelix != null)
     {
-      currentColour = (Color) helixcolorhash.get(currentHelix);
+      currentColour = helixcolorhash.get(currentHelix);
     }
 
     // System.out.println(c + " " + j + " helix " + currentHelix + " " +
@@ -121,4 +138,21 @@ public class CovariationColourScheme extends ResidueColourScheme
     return currentColour;
   }
 
+  @Override
+  public boolean isNucleotideSpecific()
+  {
+    return true;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return "Covariation";
+  }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
 }
index 23087a8..dbe4901 100644 (file)
@@ -22,6 +22,7 @@ package jalview.schemes;
 
 import jalview.api.FeatureColourI;
 import jalview.datamodel.SequenceFeature;
+import jalview.util.ColorUtils;
 import jalview.util.Format;
 
 import java.awt.Color;
@@ -121,7 +122,7 @@ public class FeatureColour implements FeatureColourI
       /*
        * only a simple colour specification - parse it
        */
-      Color colour = UserColourScheme.getColourFromString(descriptor);
+      Color colour = ColorUtils.parseColourString(descriptor);
       if (colour == null)
       {
         throw new IllegalArgumentException("Invalid colour descriptor: "
@@ -212,9 +213,9 @@ public class FeatureColour implements FeatureColourI
     FeatureColour featureColour;
     try
     {
-      featureColour = new FeatureColour(
-              new UserColourScheme(mincol).findColour('A'),
-              new UserColourScheme(maxcol).findColour('A'), min, max);
+      Color minColour = ColorUtils.parseColourString(mincol);
+      Color maxColour = ColorUtils.parseColourString(maxcol);
+      featureColour = new FeatureColour(minColour, maxColour, min, max);
       featureColour.setColourByLabel(labelColour);
       featureColour.setAutoScaled(autoScaled);
       // add in any additional parameters
@@ -306,6 +307,14 @@ public class FeatureColour implements FeatureColourI
    */
   public FeatureColour(Color low, Color high, float min, float max)
   {
+    if (low == null)
+    {
+      low = Color.white;
+    }
+    if (high == null)
+    {
+      high = Color.black;
+    }
     graduatedColour = true;
     colour = null;
     minColour = low;
@@ -533,7 +542,7 @@ public class FeatureColour implements FeatureColourI
   {
     if (isColourByLabel())
     {
-      return UserColourScheme
+      return ColorUtils
               .createColourFromName(feature.getDescription());
     }
 
index 35be31b..94f92b7 100644 (file)
 package jalview.schemes;
 
 import jalview.analysis.Conservation;
+import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.ProfilesI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
+import java.util.Map;
 
 /**
  * Colourscheme that takes its colours from some other colourscheme
@@ -66,4 +71,21 @@ public class FollowerColourScheme extends ResidueColourScheme
     }
   }
 
+  @Override
+  public String getSchemeName()
+  {
+    return "Follower";
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new FollowerColourScheme();
+  }
+
 }
index 1242cd3..7123d93 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
 import java.awt.Color;
+import java.util.Map;
 
 public class HelixColourScheme extends ScoreColourScheme
 {
@@ -30,8 +35,32 @@ public class HelixColourScheme extends ScoreColourScheme
             ResidueProperties.helixmin, ResidueProperties.helixmax);
   }
 
+  @Override
   public Color makeColour(float c)
   {
     return new Color(c, (float) 1.0 - c, c);
   }
+
+  @Override
+  public boolean isPeptideSpecific()
+  {
+    return true;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.Helix.toString();
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new HelixColourScheme();
+  }
 }
index 055000f..69af3c9 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
 import java.awt.Color;
+import java.util.Map;
 
 /**
  * DOCUMENT ME!
@@ -47,8 +52,32 @@ public class HydrophobicColourScheme extends ScoreColourScheme
    * 
    * @return DOCUMENT ME!
    */
+  @Override
   public Color makeColour(float c)
   {
     return new Color(c, (float) 0.0, (float) 1.0 - c);
   }
+
+  @Override
+  public boolean isPeptideSpecific()
+  {
+    return true;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.Hydrophobic.toString();
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new HydrophobicColourScheme();
+  }
 }
diff --git a/src/jalview/schemes/JalviewColourScheme.java b/src/jalview/schemes/JalviewColourScheme.java
new file mode 100644 (file)
index 0000000..185d2b4
--- /dev/null
@@ -0,0 +1,66 @@
+package jalview.schemes;
+
+
+/**
+ * An enum with the colour schemes supported by Jalview.
+ */
+public enum JalviewColourScheme
+{
+  /*
+   * the order of declaration is the default order in which 
+   * items are added to Colour menus
+   */
+  Clustal("Clustal", ClustalxColourScheme.class), Blosum62("Blosum62",
+          Blosum62ColourScheme.class), PID("% Identity",
+          PIDColourScheme.class), Zappo("Zappo", ZappoColourScheme.class),
+  Taylor("Taylor", TaylorColourScheme.class), Hydrophobic("Hydrophobic",
+          HydrophobicColourScheme.class), Helix("Helix Propensity",
+          HelixColourScheme.class), Strand("Strand Propensity",
+          StrandColourScheme.class), Turn("Turn Propensity",
+          TurnColourScheme.class), Buried("Buried Index",
+          BuriedColourScheme.class), Nucleotide("Nucleotide",
+          NucleotideColourScheme.class), PurinePyrimidine(
+          "Purine/Pyrimidine", PurinePyrimidineColourScheme.class),
+  RNAHelices("RNA Helices", RNAHelicesColour.class), TCoffee(
+          "T-Coffee Scores", TCoffeeColourScheme.class);
+  // RNAInteraction("RNA Interaction type", RNAInteractionColourScheme.class)
+
+  private String name;
+
+  private Class<? extends ColourSchemeI> myClass;
+
+  /**
+   * Constructor given the name of the colour scheme (as used in Jalview
+   * parameters). Note this is not necessarily the same as the 'display name'
+   * used in menu options (as this may be language-dependent).
+   * 
+   * @param s
+   */
+  JalviewColourScheme(String s, Class<? extends ColourSchemeI> cl)
+  {
+    name = s;
+    myClass = cl;
+  }
+
+  /**
+   * Returns the class of the colour scheme
+   * 
+   * @return
+   */
+  public Class<? extends ColourSchemeI> getSchemeClass()
+  {
+    return myClass;
+  }
+
+  /**
+   * Returns the 'official' name of this colour scheme. This is the name that
+   * identifies the colour scheme as a start-up parameter for the Jalview
+   * application or applet. Note that it may not be the name shown in menu
+   * options, as these may be internationalised.
+   */
+  @Override
+  public String toString()
+  {
+    return name;
+  }
+}
index dff2bf3..3a71732 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
 
 import java.awt.Color;
+import java.util.Map;
 
 /**
  * DOCUMENT ME!
@@ -92,4 +95,27 @@ public class NucleotideColourScheme extends ResidueColourScheme
 
     return currentColour;
   }
+
+  @Override
+  public boolean isNucleotideSpecific()
+  {
+    return true;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.Nucleotide.toString();
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new NucleotideColourScheme();
+  }
 }
index 0ad5b5c..389655c 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.ProfileI;
+import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.util.Comparison;
 
 import java.awt.Color;
+import java.util.Map;
 
 public class PIDColourScheme extends ResidueColourScheme
 {
@@ -94,4 +97,27 @@ public class PIDColourScheme extends ResidueColourScheme
 
     return currentColour;
   }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.PID.toString();
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new PIDColourScheme();
+  }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
 }
index d2b878d..e451135 100644 (file)
  */
 package jalview.schemes;
 
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
 import java.awt.Color;
+import java.util.Map;
 
 /**
  * Class is based off of NucleotideColourScheme
@@ -47,6 +52,7 @@ public class PurinePyrimidineColourScheme extends ResidueColourScheme
    * @return Color from purinepyrimidineIndex in
    *         jalview.schemes.ResidueProperties
    */
+  @Override
   public Color findColour(char c)
   {
     return colors[ResidueProperties.purinepyrimidineIndex[c]];
@@ -87,4 +93,27 @@ public class PurinePyrimidineColourScheme extends ResidueColourScheme
 
     return currentColour;
   }
+
+  @Override
+  public boolean isNucleotideSpecific()
+  {
+    return true;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.PurinePyrimidine.toString();
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new PurinePyrimidineColourScheme();
+  }
 }
index 9729a83..056a167 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.schemes;
 
 import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
@@ -54,6 +55,14 @@ public class RNAHelicesColour extends ResidueColourScheme
   public AlignmentAnnotation annotation;
 
   /**
+   * Default constructor (required for ColourSchemes cache)
+   */
+  public RNAHelicesColour()
+  {
+
+  }
+
+  /**
    * Creates a new RNAHelicesColour object.
    */
   public RNAHelicesColour(AlignmentAnnotation annotation)
@@ -197,9 +206,44 @@ public class RNAHelicesColour extends ResidueColourScheme
   }
 
   @Override
-  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+  public ColourSchemeI getInstance(AnnotatedCollectionI sg,
           Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
   {
-    return new RNAHelicesColour(this);
+    return new RNAHelicesColour(sg);
+  }
+
+  @Override
+  public boolean isNucleotideSpecific()
+  {
+    return true;
+  }
+
+  /**
+   * Answers true if the data has RNA secondary structure annotation
+   */
+  @Override
+  public boolean isApplicableTo(AnnotatedCollectionI ac)
+  {
+    if (ac instanceof AlignmentI && ((AlignmentI) ac).hasRNAStructure())
+    {
+      return true;
+    }
+
+    /*
+     * not currently supporting this option for group annotation / colouring
+     */
+    return false;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.RNAHelices.toString();
+  }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
   }
-}
\ No newline at end of file
+}
index b1b3c5a..90cc14f 100644 (file)
@@ -25,8 +25,8 @@ import jalview.api.AlignmentViewPanel;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.SequenceGroup;
 
-import java.awt.event.ActionEvent;
 import java.util.Hashtable;
+import java.util.Map;
 import java.util.Vector;
 
 /**
@@ -34,8 +34,9 @@ import java.util.Vector;
  * change colors based on covariation.
  * 
  * @author Lauren Michelle Lui
- * 
+ * @deprecated this seems to be unfinished - just use RNAHelicesColour
  */
+@Deprecated
 public class RNAHelicesColourChooser
 {
 
@@ -45,9 +46,9 @@ public class RNAHelicesColourChooser
 
   ColourSchemeI oldcs;
 
-  Hashtable oldgroupColours;
+  Map<SequenceGroup, ColourSchemeI> oldgroupColours;
 
-  jalview.datamodel.AlignmentAnnotation currentAnnotation;
+  AlignmentAnnotation currentAnnotation;
 
   boolean adjusting = false;
 
@@ -57,7 +58,7 @@ public class RNAHelicesColourChooser
     oldcs = av.getGlobalColourScheme();
     if (av.getAlignment().getGroups() != null)
     {
-      oldgroupColours = new Hashtable();
+      oldgroupColours = new Hashtable<SequenceGroup, ColourSchemeI>();
       for (SequenceGroup sg : ap.getAlignment().getGroups())
       {
         if (sg.cs != null)
@@ -69,14 +70,8 @@ public class RNAHelicesColourChooser
     this.av = av;
     this.ap = ap;
 
-    if (oldcs instanceof RNAHelicesColour)
-    {
-      RNAHelicesColour rhc = (RNAHelicesColour) oldcs;
-
-    }
-
     adjusting = true;
-    Vector list = new Vector();
+    Vector<String> list = new Vector<String>();
     int index = 1;
     AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
     if (anns != null)
@@ -96,9 +91,7 @@ public class RNAHelicesColourChooser
     }
 
     adjusting = false;
-
     changeColour();
-
   }
 
   void changeColour()
@@ -108,30 +101,10 @@ public class RNAHelicesColourChooser
     {
       return;
     }
-    RNAHelicesColour rhc = null;
-
-    rhc = new RNAHelicesColour(av.getAlignment());
+    RNAHelicesColour rhc = new RNAHelicesColour(av.getAlignment());
 
     av.setGlobalColourScheme(rhc);
 
     ap.paintAlignment(true);
   }
-
-  void reset()
-  {
-    av.setGlobalColourScheme(oldcs);
-    if (av.getAlignment().getGroups() != null)
-    {
-      for (SequenceGroup sg : ap.getAlignment().getGroups())
-      {
-        sg.cs = (ColourSchemeI) oldgroupColours.get(sg);
-      }
-    }
-  }
-
-  public void annotations_actionPerformed(ActionEvent e)
-  {
-    changeColour();
-  }
-
 }
index 794195a..f4c831a 100644 (file)
  */
 package jalview.schemes;
 
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
 
 import java.awt.Color;
+import java.util.Map;
 
 public class RNAInteractionColourScheme extends ResidueColourScheme
 {
@@ -31,34 +34,17 @@ public class RNAInteractionColourScheme extends ResidueColourScheme
     super();
   }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param n
-   *          DOCUMENT ME!
-   * 
-   * @return DOCUMENT ME!
-   */
   @Override
   public Color findColour(char c)
   {
-    // System.out.println("called"); log.debug
+    // FIXME this is just a copy of NucleotideColourScheme
     return colors[ResidueProperties.nucleotideIndex[c]];
   }
 
-  /**
-   * DOCUMENT ME!
-   * 
-   * @param n
-   *          DOCUMENT ME!
-   * @param j
-   *          DOCUMENT ME!
-   * 
-   * @return DOCUMENT ME!
-   */
   @Override
   public Color findColour(char c, int j, SequenceI seq)
   {
+    // FIXME this is just a copy of NucleotideColourScheme
     Color currentColour;
     if ((threshold == 0) || aboveThreshold(c, j))
     {
@@ -82,4 +68,27 @@ public class RNAInteractionColourScheme extends ResidueColourScheme
 
     return currentColour;
   }
+
+  @Override
+  public boolean isNucleotideSpecific()
+  {
+    return true;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return "RNA Interaction type";
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new RNAInteractionColourScheme();
+  }
 }
index f6b7c5e..217786a 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.schemes;
 
 import jalview.analysis.Conservation;
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.ProfileI;
 import jalview.datamodel.ProfilesI;
@@ -28,23 +29,30 @@ import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
 import jalview.util.ColorUtils;
 import jalview.util.Comparison;
-import jalview.util.MessageManager;
 
 import java.awt.Color;
 import java.util.Map;
 
 /**
- * DOCUMENT ME!
- * 
- * @author $author$
- * @version $Revision$
+ * Base class for residue-based colour schemes
  */
-public class ResidueColourScheme implements ColourSchemeI
+public abstract class ResidueColourScheme implements ColourSchemeI
 {
+  public static final String NONE = "None";
+
+  public static final String USER_DEFINED = "User Defined";
+
+  /*
+   * lookup up by character value e.g. 'G' to the colors array index
+   * e.g. if symbolIndex['K'] = 11 then colors[11] is the colour for K
+   */
   final int[] symbolIndex;
 
   boolean conservationColouring = false;
 
+  /*
+   * colour for residue characters as indexed by symbolIndex
+   */
   Color[] colors = null;
 
   int threshold = 0;
@@ -115,24 +123,46 @@ public class ResidueColourScheme implements ColourSchemeI
   @Override
   public Color findColour(char c, int j, SequenceI seq)
   {
-    Color currentColour;
+    Color colour = Color.white;
 
-    if (colors != null && symbolIndex != null && (threshold == 0)
-            || aboveThreshold(c, j))
+    if (colors != null && symbolIndex != null)
     {
-      currentColour = colors[symbolIndex[c]];
+      colour = colors[symbolIndex[c]];
     }
-    else
+    colour = adjustColour(c, j, colour);
+
+    return colour;
+  }
+
+  /**
+   * Adjusts colour by applying thresholding or conservation shading, if in
+   * force. That is
+   * <ul>
+   * <li>if there is a threshold set for colouring, and the residue doesn't
+   * match the consensus (or a joint consensus) residue, or the consensus score
+   * is not above the threshold, then the colour is set to white</li>
+   * <li>if conservation colouring is selected, the colour is faded by an amount
+   * depending on the conservation score for the column, and the conservation
+   * colour threshold</li>
+   * </ul>
+   * 
+   * @param symbol
+   * @param column
+   * @param colour
+   * @return
+   */
+  protected Color adjustColour(char symbol, int column, Color colour)
+  {
+    if (!aboveThreshold(symbol, column))
     {
-      currentColour = Color.white;
+      colour = Color.white;
     }
 
     if (conservationColouring)
     {
-      currentColour = applyConservation(currentColour, j);
+      colour = applyConservation(colour, column);
     }
-
-    return currentColour;
+    return colour;
   }
 
   /**
@@ -176,6 +206,10 @@ public class ResidueColourScheme implements ColourSchemeI
    */
   public boolean aboveThreshold(char residue, int column)
   {
+    if (threshold == 0)
+    {
+      return true;
+    }
     if ('a' <= residue && residue <= 'z')
     {
       // TO UPPERCASE !!!
@@ -329,18 +363,75 @@ public class ResidueColourScheme implements ColourSchemeI
   {
   }
 
+  /**
+   * Answers false if the colour scheme is nucleotide or peptide specific, and
+   * the data does not match, else true. Override to modify or extend this test
+   * as required.
+   */
   @Override
-  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
-          Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  public boolean isApplicableTo(AnnotatedCollectionI ac)
   {
-    try
+    if (!isPeptideSpecific() && !isNucleotideSpecific())
     {
-      return getClass().newInstance();
-    } catch (Exception q)
+      return true;
+    }
+
+    /*
+     * inspect the data context (alignment) for residue type
+     */
+    boolean nucleotide = false;
+    if (ac instanceof AlignmentI)
     {
-      throw new Error(MessageManager.formatMessage(
-              "error.implementation_error_cannot_duplicate_colour_scheme",
-              new String[] { getClass().getName() }), q);
+      nucleotide = ((AlignmentI) ac).isNucleotide();
     }
+    else
+    {
+      AnnotatedCollectionI context = ac.getContext();
+      if (context instanceof AlignmentI)
+      {
+        nucleotide = ((AlignmentI) context).isNucleotide();
+      }
+      else
+      {
+        // not sure what's going on, play safe
+        return true;
+      }
+    }
+
+    /*
+     * does data type match colour scheme type?
+     */
+    return (nucleotide && isNucleotideSpecific())
+            || (!nucleotide && isPeptideSpecific());
+  }
+
+  /**
+   * Answers true if the colour scheme is normally only for peptide data
+   * 
+   * @return
+   */
+  public boolean isPeptideSpecific()
+  {
+    return false;
+  }
+
+  /**
+   * Answers true if the colour scheme is normally only for nucleotide data
+   * 
+   * @return
+   */
+  public boolean isNucleotideSpecific()
+  {
+    return false;
+  }
+
+  /**
+   * Default method returns true. Override this to return false in colour
+   * schemes that are not determined solely by the sequence symbol.
+   */
+  @Override
+  public boolean isSimple()
+  {
+    return true;
   }
 }
index 7eb920d..ec06e06 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
 
 import java.awt.Color;
+import java.util.Map;
 
 /**
  * DOCUMENT ME!
@@ -129,4 +132,21 @@ public class ScoreColourScheme extends ResidueColourScheme
   {
     return new Color(c, (float) 0.0, (float) 1.0 - c);
   }
+
+  @Override
+  public String getSchemeName()
+  {
+    return "Score";
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new ScoreColourScheme(symbolIndex, scores, min, max);
+  }
 }
index 1340de3..5f11c29 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
 import java.awt.Color;
+import java.util.Map;
 
 /**
  * DOCUMENT ME!
@@ -47,8 +52,32 @@ public class StrandColourScheme extends ScoreColourScheme
    * 
    * @return DOCUMENT ME!
    */
+  @Override
   public Color makeColour(float c)
   {
     return new Color(c, c, (float) 1.0 - c);
   }
+
+  @Override
+  public boolean isPeptideSpecific()
+  {
+    return true;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.Strand.toString();
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new StrandColourScheme();
+  }
 }
index 2be51c2..13d1d55 100644 (file)
@@ -31,6 +31,7 @@ import jalview.io.TCoffeeScoreFile;
 import java.awt.Color;
 import java.util.ArrayList;
 import java.util.IdentityHashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -44,20 +45,15 @@ import java.util.Map;
  */
 public class TCoffeeColourScheme extends ResidueColourScheme
 {
+  IdentityHashMap<SequenceI, Color[]> seqMap;
 
-  static final Color[] colors = { new Color(102, 102, 255), // #6666FF
-      new Color(0, 255, 0), // #00FF00
-      new Color(102, 255, 0), // #66FF00
-      new Color(204, 255, 0), // #CCFF00
-      new Color(255, 255, 0), // #FFFF00
-      new Color(255, 204, 0), // #FFCC00
-      new Color(255, 153, 0), // #FF9900
-      new Color(255, 102, 0), // #FF6600
-      new Color(255, 51, 0), // #FF3300
-      new Color(255, 34, 0) // #FF2000
-  };
+  /**
+   * Default constructor (required for Class.newInstance())
+   */
+  public TCoffeeColourScheme()
+  {
 
-  IdentityHashMap<SequenceI, Color[]> seqMap;
+  }
 
   /**
    * the color scheme needs to look at the alignment to get and cache T-COFFEE
@@ -71,6 +67,13 @@ public class TCoffeeColourScheme extends ResidueColourScheme
     alignmentChanged(alignment, null);
   }
 
+  /**
+   * Finds the TCoffeeScore annotation (if any) for each sequence and notes the
+   * annotation colour for each column position. The colours are fixed for
+   * scores 0-9 and are set when annotation is parsed.
+   * 
+   * @see TCoffeeScoreFile#annotateAlignment(AlignmentI, boolean)
+   */
   @Override
   public void alignmentChanged(AnnotatedCollectionI alignment,
           Map<SequenceI, SequenceCollectionI> hiddenReps)
@@ -80,7 +83,7 @@ public class TCoffeeColourScheme extends ResidueColourScheme
 
     // assume only one set of TCOFFEE scores - but could have more than one
     // potentially.
-    ArrayList<AlignmentAnnotation> annots = new ArrayList<AlignmentAnnotation>();
+    List<AlignmentAnnotation> annots = new ArrayList<AlignmentAnnotation>();
     // Search alignment to get all tcoffee annotation and pick one set of
     // annotation to use to colour seqs.
     seqMap = new IdentityHashMap<SequenceI, Color[]>();
@@ -119,9 +122,12 @@ public class TCoffeeColourScheme extends ResidueColourScheme
   @Override
   public Color findColour(char c, int j, SequenceI seq)
   {
-    Color[] cols;
-
-    if (seqMap == null || (cols = seqMap.get(seq)) == null)
+    if (seqMap == null)
+    {
+      return Color.WHITE;
+    }
+    Color[] cols = seqMap.get(seq);
+    if (cols == null)
     {
       // see above TODO about computing a colour for each residue in each
       // column: cc = _rcols[i][indexFor[c]];
@@ -136,9 +142,38 @@ public class TCoffeeColourScheme extends ResidueColourScheme
   }
 
   @Override
-  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+  public ColourSchemeI getInstance(AnnotatedCollectionI sg,
           Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
   {
     return new TCoffeeColourScheme(sg);
   }
+
+  /**
+   * Answers true if the data has TCoffee score annotation
+   */
+  @Override
+  public boolean isApplicableTo(AnnotatedCollectionI ac)
+  {
+    AnnotatedCollectionI alcontext = ac instanceof AlignmentI ? ac : ac
+            .getContext();
+    if (alcontext == null)
+    {
+      return false;
+    }
+    Iterable<AlignmentAnnotation> anns = alcontext
+            .findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE);
+    return anns.iterator().hasNext();
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.TCoffee.toString();
+  }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
 }
index 8c46bba..cae3e15 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
+import java.util.Map;
+
 public class TaylorColourScheme extends ResidueColourScheme
 {
   public TaylorColourScheme()
   {
     super(ResidueProperties.aaIndex, ResidueProperties.taylor, 0);
   }
+
+  @Override
+  public boolean isPeptideSpecific()
+  {
+    return true;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.Taylor.toString();
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new TaylorColourScheme();
+  }
 }
index 22422ff..67116b8 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
 import java.awt.Color;
+import java.util.Map;
 
 /**
  * DOCUMENT ME!
@@ -47,8 +52,32 @@ public class TurnColourScheme extends ScoreColourScheme
    * 
    * @return DOCUMENT ME!
    */
+  @Override
   public Color makeColour(float c)
   {
     return new Color(c, 1 - c, 1 - c);
   }
+
+  @Override
+  public boolean isPeptideSpecific()
+  {
+    return true;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.Turn.toString();
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new TurnColourScheme();
+  }
 }
index 9ae14ca..969e6b3 100755 (executable)
@@ -23,13 +23,23 @@ package jalview.schemes;
 import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
+import jalview.util.ColorUtils;
+import jalview.util.StringUtils;
 
 import java.awt.Color;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.StringTokenizer;
 
 public class UserColourScheme extends ResidueColourScheme
 {
+  /*
+   * lookup (by symbol index) of lower case colours (if configured)
+   */
   Color[] lowerCaseColours;
 
   protected String schemeName;
@@ -46,37 +56,86 @@ public class UserColourScheme extends ResidueColourScheme
   }
 
   @Override
-  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+  public ColourSchemeI getInstance(AnnotatedCollectionI sg,
           Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
   {
-    UserColourScheme usc = new UserColourScheme(colors);
-    if (lowerCaseColours != null)
+    return new UserColourScheme(this);
+  }
+
+  /**
+   * Copy constructor
+   * 
+   * @return
+   */
+  protected UserColourScheme(UserColourScheme from)
+  {
+    this(from.colors);
+    schemeName = from.schemeName;
+    if (from.lowerCaseColours != null)
     {
-      usc.schemeName = new String(schemeName);
-      usc.lowerCaseColours = new Color[lowerCaseColours.length];
-      System.arraycopy(lowerCaseColours, 0, usc.lowerCaseColours, 0,
-              lowerCaseColours.length);
+      lowerCaseColours = new Color[lowerCaseColours.length];
+      System.arraycopy(from.lowerCaseColours, 0, lowerCaseColours, 0,
+              from.lowerCaseColours.length);
     }
-    return usc;
   }
 
+  /**
+   * Constructor for an animino acid colour scheme. The colour specification may
+   * be one of
+   * <ul>
+   * <li>an AWT colour name e.g. red</li>
+   * <li>an AWT hex rgb colour e.g. ff2288</li>
+   * <li>residue colours list e.g. D,E=red;K,R,H=0022FF;c=yellow</li>
+   * </ul>
+   * 
+   * @param colour
+   */
   public UserColourScheme(String colour)
   {
     super(ResidueProperties.aaIndex);
-    Color col = getColourFromString(colour);
+
+    if (colour.contains("="))
+    {
+      /*
+       * a list of colours per residue(s)
+       */
+      parseAppletParameter(colour);
+      return;
+    }
+
+    Color col = ColorUtils.parseColourString(colour);
 
     if (col == null)
     {
       System.out.println("Making colour from name: " + colour);
-      col = createColourFromName(colour);
+      col = ColorUtils.createColourFromName(colour);
     }
 
-    colors = new Color[24];
-    for (int i = 0; i < 24; i++)
+    setAll(col);
+    schemeName = colour;
+  }
+
+  /**
+   * Sets all symbols to the specified colour
+   * 
+   * @param col
+   */
+  protected void setAll(Color col)
+  {
+    if (symbolIndex == null)
+    {
+      return;
+    }
+    int max = 0;
+    for (int index : symbolIndex)
+    {
+      max = Math.max(max, index);
+    }
+    colors = new Color[max + 1];
+    for (int i = 0; i <= max; i++)
     {
       colors[i] = col;
     }
-    schemeName = colour;
   }
 
   public Color[] getColours()
@@ -99,77 +158,25 @@ public class UserColourScheme extends ResidueColourScheme
     return schemeName;
   }
 
-  public static Color getColourFromString(String colour)
-  {
-    if (colour == null)
-    {
-      return null;
-    }
-    colour = colour.trim();
-
-    Color col = null;
-    try
-    {
-      int value = Integer.parseInt(colour, 16);
-      col = new Color(value);
-    } catch (NumberFormatException ex)
-    {
-    }
-
-    if (col == null)
-    {
-      col = ColourSchemeProperty.getAWTColorFromName(colour);
-    }
-
-    if (col == null)
-    {
-      try
-      {
-        java.util.StringTokenizer st = new java.util.StringTokenizer(
-                colour, ",");
-        int r = Integer.parseInt(st.nextToken());
-        int g = Integer.parseInt(st.nextToken());
-        int b = Integer.parseInt(st.nextToken());
-        col = new Color(r, g, b);
-      } catch (Exception ex)
-      {
-      }
-    }
-
-    return col;
-
-  }
-
-  public static Color createColourFromName(String name)
+  /**
+   * Parse and save residue colours specified as (for example)
+   * 
+   * <pre>
+   *     D,E=red; K,R,H=0022FF; c=100,50,75
+   * </pre>
+   * 
+   * This should be a semi-colon separated list of colours, which may be defined
+   * by colour name, hex value or comma-separated RGB triple. Each colour is
+   * defined for a comma-separated list of amino acid single letter codes. (Note
+   * that this also allows a colour scheme to be defined for ACGT, but not for
+   * U.)
+   * 
+   * @param paramValue
+   */
+  void parseAppletParameter(String paramValue)
   {
-    int r, g, b;
-
-    int lsize = name.length();
-    int start = 0, end = lsize / 3;
-
-    int rgbOffset = Math.abs(name.hashCode() % 10) * 15;
-
-    r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
-    start = end;
-    end += lsize / 3;
-    if (end > lsize)
-    {
-      end = lsize;
-    }
+    setAll(Color.white);
 
-    g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
-
-    b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20;
-
-    Color color = new Color(r, g, b);
-
-    return color;
-  }
-
-  public void parseAppletParameter(String paramValue)
-  {
-    // TODO: need a function to generate appletParameter colour string from a
-    // UCS
     StringTokenizer st = new StringTokenizer(paramValue, ";");
     StringTokenizer st2;
     String token = null, colour, residues;
@@ -184,43 +191,42 @@ public class UserColourScheme extends ResidueColourScheme
         st2 = new StringTokenizer(residues, " ,");
         while (st2.hasMoreTokens())
         {
-          token = st2.nextToken();
+          String residue = st2.nextToken();
 
-          if (ResidueProperties.aaIndex[token.charAt(0)] == -1)
+          int colIndex = ResidueProperties.aaIndex[residue.charAt(0)];
+          if (colIndex == -1)
           {
             continue;
           }
 
-          int colIndex = ResidueProperties.aaIndex[token.charAt(0)];
-
-          if (token.equalsIgnoreCase("lowerCase"))
+          if (residue.equalsIgnoreCase("lowerCase"))
           {
             if (lowerCaseColours == null)
             {
-              lowerCaseColours = new Color[23];
+              lowerCaseColours = new Color[colors.length];
             }
-            for (int i = 0; i < 23; i++)
+            for (int i = 0; i < lowerCaseColours.length; i++)
             {
               if (lowerCaseColours[i] == null)
               {
-                lowerCaseColours[i] = getColourFromString(colour);
+                lowerCaseColours[i] = ColorUtils.parseColourString(colour);
               }
             }
 
             continue;
           }
 
-          if (token.equals(token.toLowerCase()))
+          if (residue.equals(residue.toLowerCase()))
           {
             if (lowerCaseColours == null)
             {
-              lowerCaseColours = new Color[23];
+              lowerCaseColours = new Color[colors.length];
             }
-            lowerCaseColours[colIndex] = getColourFromString(colour);
+            lowerCaseColours[colIndex] = ColorUtils.parseColourString(colour);
           }
           else
           {
-            colors[colIndex] = getColourFromString(colour);
+            colors[colIndex] = ColorUtils.parseColourString(colour);
           }
         }
       }
@@ -267,4 +273,110 @@ public class UserColourScheme extends ResidueColourScheme
     lowerCaseColours = lcolours;
   }
 
+  /**
+   * Returns the colour for the given residue character. If the residue is
+   * lower-case, and there is a specific colour defined for lower case, that
+   * colour is returned, else the colour for the upper case residue.
+   */
+  @Override
+  public Color findColour(char c)
+  {
+    if ('a' <= c && c <= 'z' && lowerCaseColours != null)
+    {
+      Color colour = lowerCaseColours[symbolIndex[c]];
+      if (colour != null)
+      {
+        return colour;
+      }
+    }
+    return super.findColour(c);
+  }
+
+  /**
+   * Answers the customised name of the colour scheme, if it has one, else
+   * "User Defined"
+   */
+  @Override
+  public String getSchemeName()
+  {
+    if (schemeName != null && schemeName.length() > 0)
+    {
+      return schemeName;
+    }
+    return "User Defined";
+  }
+
+  /**
+   * Generate an applet colour parameter like A,C,D=12ffe9;Q,W=2393fd;w=9178dd
+   * 
+   * @return
+   */
+  public String toAppletParameter()
+  {
+    /*
+     * step 1: build a map from colours to the symbol(s) that have the colour
+     */
+    Map<Color, List<String>> colours = new HashMap<Color, List<String>>();
+
+    for (char symbol = 'A'; symbol <= 'Z'; symbol++)
+    {
+      String residue = String.valueOf(symbol);
+      int index = symbolIndex[symbol];
+      Color c = colors[index];
+      if (c != null && !c.equals(Color.white))
+      {
+        if (colours.get(c) == null)
+        {
+          colours.put(c, new ArrayList<String>());
+        }
+        colours.get(c).add(residue);
+      }
+      if (lowerCaseColours != null)
+      {
+        c = lowerCaseColours[index];
+        if (c != null && !c.equals(Color.white))
+        {
+          residue = residue.toLowerCase();
+          if (colours.get(c) == null)
+          {
+            colours.put(c, new ArrayList<String>());
+          }
+          colours.get(c).add(residue);
+        }
+      }
+    }
+
+    /*
+     * step 2: make a list of { A,G,R=12f9d6 } residues/colour specs
+     */
+    List<String> residueColours = new ArrayList<String>();
+    for (Entry<Color, List<String>> cols : colours.entrySet())
+    {
+      boolean first = true;
+      StringBuilder sb = new StringBuilder();
+      for (String residue : cols.getValue())
+      {
+        if (!first)
+        {
+          sb.append(",");
+        }
+        sb.append(residue);
+        first = false;
+      }
+      sb.append("=");
+      /*
+       * get color as hex value, dropping the alpha (ff) part
+       */
+      String hexString = Integer.toHexString(cols.getKey().getRGB())
+              .substring(2);
+      sb.append(hexString);
+      residueColours.add(sb.toString());
+    }
+
+    /*
+     * sort and output
+     */
+    Collections.sort(residueColours);
+    return StringUtils.listToDelimitedString(residueColours, ";");
+  }
 }
index 8fa1656..d193714 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
+import java.util.Map;
+
 /**
  * DOCUMENT ME!
  * 
@@ -35,4 +41,27 @@ public class ZappoColourScheme extends ResidueColourScheme
   {
     super(ResidueProperties.aaIndex, ResidueProperties.zappo, 0);
   }
+
+  @Override
+  public boolean isPeptideSpecific()
+  {
+    return true;
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+    return JalviewColourScheme.Zappo.toString();
+  }
+
+  /**
+   * Returns a new instance of this colour scheme with which the given data may
+   * be coloured
+   */
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+          Map<SequenceI, SequenceCollectionI> hrs)
+  {
+    return new ZappoColourScheme();
+  }
 }
index 063eacf..fda08fd 100644 (file)
  */
 package jalview.structures.models;
 
+import jalview.api.AlignmentViewPanel;
+import jalview.api.FeatureRenderer;
+import jalview.api.SequenceRenderer;
 import jalview.api.StructureSelectionManagerProvider;
 import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.io.DataSourceType;
+import jalview.schemes.ColourSchemeI;
 import jalview.structure.AtomSpec;
 import jalview.structure.StructureListener;
 import jalview.structure.StructureMapping;
+import jalview.structure.StructureMappingcommandSet;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.Comparison;
 import jalview.util.MessageManager;
 
+import java.awt.Color;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -85,6 +92,8 @@ public abstract class AAStructureBindingModel extends
    */
   protected String[] modelFileNames = null;
 
+  public String fileLoadingError;
+
   /**
    * Data bean class to simplify parameterisation in superposeStructures
    */
@@ -688,4 +697,80 @@ public abstract class AAStructureBindingModel extends
   {
     return null;
   }
+
+  public abstract void setJalviewColourScheme(ColourSchemeI cs);
+
+  public abstract void superposeStructures(AlignmentI[] als, int[] alm,
+          ColumnSelection[] alc);
+
+  public abstract void setBackgroundColour(Color col);
+
+  protected abstract StructureMappingcommandSet[] getColourBySequenceCommands(
+          String[] files, SequenceRenderer sr, FeatureRenderer fr,
+          AlignmentI alignment);
+
+  /**
+   * returns the current featureRenderer that should be used to colour the
+   * structures
+   * 
+   * @param alignment
+   * 
+   * @return
+   */
+  public abstract FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment);
+
+  /**
+   * returns the current sequenceRenderer that should be used to colour the
+   * structures
+   * 
+   * @param alignment
+   * 
+   * @return
+   */
+  public abstract SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment);
+
+  protected abstract void colourBySequence(
+          StructureMappingcommandSet[] colourBySequenceCommands);
+
+  public abstract void colourByChain();
+
+  public abstract void colourByCharge();
+
+  /**
+   * colour any structures associated with sequences in the given alignment
+   * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
+   * if colourBySequence is enabled.
+   */
+  public void colourBySequence(AlignmentViewPanel alignmentv)
+  {
+    boolean showFeatures = alignmentv.getAlignViewport()
+            .isShowSequenceFeatures();
+    if (!colourBySequence || !isLoadingFinished())
+    {
+      return;
+    }
+    if (getSsm() == null)
+    {
+      return;
+    }
+    String[] files = getPdbFile();
+  
+    SequenceRenderer sr = getSequenceRenderer(alignmentv);
+  
+    FeatureRenderer fr = null;
+    if (showFeatures)
+    {
+      fr = getFeatureRenderer(alignmentv);
+    }
+    AlignmentI alignment = alignmentv.getAlignment();
+  
+    StructureMappingcommandSet[] colourBySequenceCommands = getColourBySequenceCommands(
+            files, sr, fr, alignment);
+    colourBySequence(colourBySequenceCommands);
+  }
+
+  public boolean hasFileLoadingError()
+  {
+    return fileLoadingError != null && fileLoadingError.length() > 0;
+  }
 }
index 525bfdb..d7829df 100644 (file)
@@ -191,4 +191,167 @@ public class ColorUtils
       return new Color(red, green, blue);
     }
   }
+
+  /**
+   * Parses a string into a Color, where the accepted formats are
+   * <ul>
+   * <li>an AWT colour name e.g. white</li>
+   * <li>a hex colour value (without prefix) e.g. ff0000</li>
+   * <li>an rgb triple e.g. 100,50,150</li>
+   * </ul>
+   * 
+   * @param colour
+   * @return the parsed colour, or null if parsing fails
+   */
+  public static Color parseColourString(String colour)
+  {
+    if (colour == null)
+    {
+      return null;
+    }
+    colour = colour.trim();
+  
+    Color col = null;
+    try
+    {
+      int value = Integer.parseInt(colour, 16);
+      col = new Color(value);
+    } catch (NumberFormatException ex)
+    {
+    }
+  
+    if (col == null)
+    {
+      col = ColorUtils.getAWTColorFromName(colour);
+    }
+  
+    if (col == null)
+    {
+      try
+      {
+        String[] tokens = colour.split(",");
+        if (tokens.length == 3)
+        {
+          int r = Integer.parseInt(tokens[0].trim());
+          int g = Integer.parseInt(tokens[1].trim());
+          int b = Integer.parseInt(tokens[2].trim());
+          col = new Color(r, g, b);
+        }
+      } catch (Exception ex)
+      {
+        // non-numeric token or out of 0-255 range
+      }
+    }
+  
+    return col;
+  }
+
+  /**
+   * Constructs a colour from a text string. The hashcode of the whole string is
+   * scaled to the range 0-135. This is added to RGB values made from the
+   * hashcode of each third of the string, and scaled to the range 20-229.
+   * 
+   * @param name
+   * @return
+   */
+  public static Color createColourFromName(String name)
+  {
+    if (name == null)
+    {
+      return Color.white;
+    }
+    int lsize = name.length();
+    int start = 0;
+    int end = lsize / 3;
+  
+    int rgbOffset = Math.abs(name.hashCode() % 10) * 15; // 0-135
+  
+    /*
+     * red: first third
+     */
+    int r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
+    start = end;
+    end += lsize / 3;
+    if (end > lsize)
+    {
+      end = lsize;
+    }
+  
+    /*
+     * green: second third
+     */
+    int g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
+  
+    /*
+     * blue: third third
+     */
+    int b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20;
+  
+    Color color = new Color(r, g, b);
+  
+    return color;
+  }
+
+  /**
+   * Returns the Color constant for a given colour name e.g. "pink", or null if
+   * the name is not recognised
+   * 
+   * @param name
+   * @return
+   */
+  public static Color getAWTColorFromName(String name)
+  {
+    if (name == null)
+    {
+      return null;
+    }
+    Color col = null;
+    name = name.toLowerCase();
+  
+    // or make a static map; or use reflection on the field name
+    switch (name)
+    {
+    case "black":
+      col = Color.black;
+      break;
+    case "blue":
+      col = Color.blue;
+      break;
+    case "cyan":
+      col = Color.cyan;
+      break;
+    case "darkgray":
+      col = Color.darkGray;
+      break;
+    case "gray":
+      col = Color.gray;
+      break;
+    case "green":
+      col = Color.green;
+      break;
+    case "lightgray":
+      col = Color.lightGray;
+      break;
+    case "magenta":
+      col = Color.magenta;
+      break;
+    case "orange":
+      col = Color.orange;
+      break;
+    case "pink":
+      col = Color.pink;
+      break;
+    case "red":
+      col = Color.red;
+      break;
+    case "white":
+      col = Color.white;
+      break;
+    case "yellow":
+      col = Color.yellow;
+      break;
+    }
+  
+    return col;
+  }
 }
index f1b83b8..139ee19 100644 (file)
@@ -97,12 +97,12 @@ public class ParseHtmlBodyAndLinks
   public ParseHtmlBodyAndLinks(String description, boolean removeHTML,
           String newline)
   {
-    StringBuilder sb = new StringBuilder(description.length());
     if (description == null || description.length() == 0)
     {
       htmlContent = false;
       return;
     }
+    StringBuilder sb = new StringBuilder(description.length());
     if (description.toUpperCase().indexOf("<HTML>") == -1)
     {
       htmlContent = false;
index fecccb0..0171fd1 100644 (file)
@@ -642,7 +642,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
           sg.cs = null;
           continue;
         }
-        sg.cs = cs.applyTo(sg, getHiddenRepSequences());
+        sg.cs = cs.getInstance(sg, getHiddenRepSequences());
         sg.setConsPercGaps(ConsPercGaps);
         if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
                 || cs instanceof Blosum62ColourScheme)
index c1ad465..8468329 100644 (file)
@@ -28,7 +28,7 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.renderer.seqfeatures.FeatureRenderer;
 import jalview.schemes.FeatureColour;
-import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
 
 import java.awt.Color;
 import java.beans.PropertyChangeListener;
@@ -542,7 +542,7 @@ public abstract class FeatureRendererModel implements
     FeatureColourI fc = featureColours.get(featureType);
     if (fc == null)
     {
-      Color col = UserColourScheme.createColourFromName(featureType);
+      Color col = ColorUtils.createColourFromName(featureType);
       fc = new FeatureColour(col);
       featureColours.put(featureType, fc);
     }
index 0cf76e0..001f6a8 100644 (file)
@@ -29,7 +29,7 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.schemes.FeatureColour;
-import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.params.WsParamSetI;
 
@@ -308,7 +308,7 @@ public class AADisorderClient extends JabawsCalcWorker
                 annot.description += "<br/>" + threshNote;
               }
               annot.description += "</html>";
-              Color col = UserColourScheme.createColourFromName(typeName
+              Color col = ColorUtils.createColourFromName(typeName
                       + scr.getMethod());
               for (int p = 0, ps = annot.annotations.length; p < ps; p++)
               {
index 618bac5..7af77f5 100644 (file)
@@ -611,6 +611,12 @@ public class AlignmentTest
     AlignmentAnnotation ann = iter.next();
     assertEquals("D.melanogaster.2", ann.sequenceRef.getName());
     assertFalse(iter.hasNext());
+
+    // invalid id
+    anns = al.findAnnotation("CalcIdForD.melanogaster.?");
+    assertFalse(iter.hasNext());
+    anns = al.findAnnotation(null);
+    assertFalse(iter.hasNext());
   }
 
   @Test(groups = { "Functional" })
index d0ea751..ffb886c 100644 (file)
@@ -30,6 +30,7 @@ import java.util.Arrays;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.SortedMap;
 
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
@@ -47,7 +48,7 @@ public class ChimeraCommandsTest
   @Test(groups = { "Functional" })
   public void testAddColourRange()
   {
-    Map<Color, Map<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, Map<Integer, Map<String, List<int[]>>>>();
+    Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, SortedMap<Integer, Map<String, List<int[]>>>>();
     ChimeraCommands.addColourRange(map, Color.pink, 1, 2, 4, "A");
     ChimeraCommands.addColourRange(map, Color.pink, 1, 8, 8, "A");
     ChimeraCommands.addColourRange(map, Color.pink, 1, 5, 7, "B");
@@ -96,7 +97,7 @@ public class ChimeraCommandsTest
   public void testBuildColourCommands()
   {
 
-    Map<Color, Map<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, Map<Integer, Map<String, List<int[]>>>>();
+    Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, SortedMap<Integer, Map<String, List<int[]>>>>();
     ChimeraCommands.addColourRange(map, Color.blue, 0, 2, 5, "A");
     ChimeraCommands.addColourRange(map, Color.blue, 0, 7, 7, "B");
     ChimeraCommands.addColourRange(map, Color.blue, 0, 9, 23, "A");
index 5695b15..213f769 100644 (file)
@@ -345,9 +345,9 @@ public class AlignViewportTest
   public void testSetGlobalColourScheme()
   {
     /*
-     * test for JAL-2283 don't inadvertently turn on colour by conservation
+     * test for JAL-2283: don't inadvertently turn on colour by conservation
      */
-    Cache.applicationProperties.setProperty("DEFAULT_COLOUR_PROT", "NONE");
+    Cache.applicationProperties.setProperty("DEFAULT_COLOUR_PROT", "None");
     Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
             Boolean.TRUE.toString());
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
index 922d457..335240b 100644 (file)
@@ -321,7 +321,8 @@ public class PopupMenuTest
 
     assertEquals(4, showOptions.length); // includes 'All' and separator
     assertEquals(4, hideOptions.length);
-    assertEquals("All", ((JMenuItem) showOptions[0]).getText());
+    String all = MessageManager.getString("label.all");
+    assertEquals(all, ((JMenuItem) showOptions[0]).getText());
     assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
     assertEquals(JSeparator.HORIZONTAL,
             ((JSeparator) showOptions[1]).getOrientation());
@@ -331,7 +332,7 @@ public class PopupMenuTest
     assertEquals("SSP", ((JMenuItem) showOptions[3]).getText());
     assertEquals("JPred", ((JMenuItem) showOptions[3]).getToolTipText());
 
-    assertEquals("All", ((JMenuItem) hideOptions[0]).getText());
+    assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
     assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
     assertEquals(JSeparator.HORIZONTAL,
             ((JSeparator) hideOptions[1]).getOrientation());
@@ -383,12 +384,13 @@ public class PopupMenuTest
 
     assertEquals(2, showOptions.length); // includes 'All' and separator
     assertEquals(4, hideOptions.length);
-    assertEquals("All", ((JMenuItem) showOptions[0]).getText());
+    String all = MessageManager.getString("label.all");
+    assertEquals(all, ((JMenuItem) showOptions[0]).getText());
     assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
     assertEquals(JSeparator.HORIZONTAL,
             ((JSeparator) showOptions[1]).getOrientation());
 
-    assertEquals("All", ((JMenuItem) hideOptions[0]).getText());
+    assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
     assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
     assertEquals(JSeparator.HORIZONTAL,
             ((JSeparator) hideOptions[1]).getOrientation());
@@ -440,7 +442,8 @@ public class PopupMenuTest
 
     assertEquals(4, showOptions.length); // includes 'All' and separator
     assertEquals(2, hideOptions.length);
-    assertEquals("All", ((JMenuItem) showOptions[0]).getText());
+    String all = MessageManager.getString("label.all");
+    assertEquals(all, ((JMenuItem) showOptions[0]).getText());
     assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
     assertEquals(JSeparator.HORIZONTAL,
             ((JSeparator) showOptions[1]).getOrientation());
@@ -450,7 +453,7 @@ public class PopupMenuTest
     assertEquals("Temp", ((JMenuItem) showOptions[3]).getText());
     assertEquals("PDB2", ((JMenuItem) showOptions[3]).getToolTipText());
 
-    assertEquals("All", ((JMenuItem) hideOptions[0]).getText());
+    assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
     assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
     assertEquals(JSeparator.HORIZONTAL,
             ((JSeparator) hideOptions[1]).getOrientation());
index de12086..734bfe0 100644 (file)
@@ -45,6 +45,8 @@ import jalview.gui.JvOptionPane;
 import jalview.schemes.AnnotationColourGradient;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
+import jalview.schemes.JalviewColourScheme;
+import jalview.schemes.RNAHelicesColour;
 import jalview.schemes.TCoffeeColourScheme;
 import jalview.structure.StructureImportSettings;
 import jalview.viewmodel.AlignmentViewport;
@@ -64,6 +66,7 @@ import org.testng.annotations.Test;
 public class Jalview2xmlTests extends Jalview2xmlBase
 {
 
+  @Override
   @BeforeClass(alwaysRun = true)
   public void setUpJvOptionPane()
   {
@@ -82,10 +85,10 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     assertTrue("Didn't read input file " + inFile, af != null);
     int olddsann = countDsAnn(af.getViewport());
     assertTrue("Didn't find any dataset annotations", olddsann > 0);
-    af.rnahelicesColour_actionPerformed(null);
-    assertTrue(
-            "Couldn't apply RNA helices colourscheme",
-            af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
+    af.changeColour_actionPerformed(JalviewColourScheme.RNAHelices
+            .toString());
+    assertTrue("Couldn't apply RNA helices colourscheme", af.getViewport()
+            .getGlobalColourScheme() instanceof RNAHelicesColour);
     assertTrue("Failed to store as a project.",
             af.saveAlignment(tfile, FileFormat.Jalview));
     af.closeMenuItem_actionPerformed(true);
@@ -102,7 +105,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase
                     + olddsann + ")");
     assertTrue(
             "RNA helices colourscheme was not applied on import.",
-            af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
+            af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour);
   }
 
   @Test(groups = { "Functional" })
@@ -118,9 +121,9 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     assertSame("Didn't set T-coffee colourscheme", af.getViewport()
             .getGlobalColourScheme().getClass(), TCoffeeColourScheme.class);
     assertNotNull("Recognise T-Coffee score from string",
-            ColourSchemeProperty.getColour(af.getViewport()
-                    .getAlignment(), ColourSchemeProperty.getColourName(af
-                    .getViewport().getGlobalColourScheme())));
+            ColourSchemeProperty.getColourScheme(af.getViewport()
+                    .getAlignment(), af.getViewport()
+                    .getGlobalColourScheme().getSchemeName()));
 
     assertTrue("Failed to store as a project.",
             af.saveAlignment(tfile, FileFormat.Jalview));
diff --git a/test/jalview/schemes/ClustalxColourSchemeTest.java b/test/jalview/schemes/ClustalxColourSchemeTest.java
new file mode 100644 (file)
index 0000000..acd2e8d
--- /dev/null
@@ -0,0 +1,134 @@
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.datamodel.AlignmentI;
+import jalview.gui.AlignFrame;
+import jalview.io.DataSourceType;
+import jalview.io.FileLoader;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class ClustalxColourSchemeTest
+{
+  // @formatter:off
+  private static final String FASTA = 
+          ">seq1\nAAANNNRQ\n" + 
+          ">seq2\nAAANNNRQ\n" + 
+          ">seq3\nAAANNNRQ\n" + 
+          ">seq4\nAAANNNRQ\n" + 
+          ">seq5\nAAANYYKQ\n" + 
+          ">seq6\nAAANYYKQ\n" + 
+          ">seq7\nAVKWYYKQ\n" + 
+          ">seq8\nKKKWYYQQ\n" + 
+          ">seq9\nKKKWWYQQ\n" + 
+          ">seq0\nKKKWWWQW\n";
+  // @formatter:on
+
+  @Test(groups = "Functional")
+  public void testFindColour()
+  {
+    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(FASTA,
+            DataSourceType.PASTE);
+    AlignmentI al = af.getViewport().getAlignment();
+    ColourSchemeI cs = new ClustalxColourScheme(al, null);
+
+    /*
+     * column 1 is 70% A which is above Clustalx threshold of 60%
+     */
+    Color clustalBlue = new Color(0.5f, 0.7f, 0.9f);
+    assertEquals(cs.findColour('A', 0, al.getSequenceAt(0)), clustalBlue);
+
+    /*
+     * column 2 is 70% A or V which is above Clustalx threshold for group
+     */
+    assertEquals(cs.findColour('A', 0, al.getSequenceAt(1)), clustalBlue);
+
+    /*
+     * column 3 is 60% A which is not above Clustalx threshold
+     * the Ks in the other rows are not in the same Clustalx group
+     */
+    assertEquals(cs.findColour('A', 2, al.getSequenceAt(1)), Color.white);
+
+    /*
+     * column 4 is 60% N which is above Clustalx threshold of 50%
+     */
+    Color clustalGreen = new Color(0.1f, 0.8f, 0.1f);
+    assertEquals(cs.findColour('N', 3, al.getSequenceAt(1)), clustalGreen);
+
+    /*
+     * column 5 is 40% N and 40% Y which fails to pass the threshold of
+     * 50% N or 85% either
+     */
+    assertEquals(cs.findColour('N', 4, al.getSequenceAt(1)), Color.white);
+
+    /*
+     * column 6 is 40% N and 50% Y which fails to pass the threshold of
+     * 85% for either
+     */
+    assertEquals(cs.findColour('N', 5, al.getSequenceAt(1)), Color.white);
+
+    /*
+     * column 7 is 40% R and 30% K which combine to make > 60%
+     */
+    Color clustalRed = new Color(0.9f, 0.2f, 0.1f);
+    assertEquals(cs.findColour('R', 6, al.getSequenceAt(1)), clustalRed);
+    assertEquals(cs.findColour('K', 6, al.getSequenceAt(7)), clustalRed);
+
+    /*
+     * column 8 is >85% Q which qualifies K and R to be red
+     */
+    assertEquals(cs.findColour('R', 7, al.getSequenceAt(1)), clustalRed);
+    assertEquals(cs.findColour('K', 7, al.getSequenceAt(1)), clustalRed);
+
+    // TODO more test cases; check if help documentation matches implementation
+  }
+
+  // @formatter:on
+  
+  /**
+   * Test for colour calculation when the consensus percentage ignores gapped
+   * sequences
+   */
+  @Test(groups = "Functional")
+  public void testFindColour_ignoreGaps()
+  {
+    /*
+     * CCC
+     * CCC
+     * -CC
+     * first column is 66% C (blue) including gaps
+     * or 100% C ignoring gaps
+     */
+    String fasta = ">seq1\nCCC\n>seq2\nccc\n>seq3\n-CC\n";
+    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(fasta,
+            DataSourceType.PASTE);
+    AlignmentI al = af.getViewport().getAlignment();
+    ClustalxColourScheme cs = new ClustalxColourScheme(al, null);
+  
+    /*
+     * column 1 is 66% C which is above Clustalx threshold of 60%
+     */
+    Color clustalBlue = ClustalxColourScheme.ClustalColour.BLUE.colour;
+    assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalBlue);
+
+    /*
+     * set directly to ignore gaps
+     */
+    cs.setIncludeGaps(false);
+    Color clustalPink = ClustalxColourScheme.ClustalColour.PINK.colour;
+    assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalPink);
+
+    /*
+     * set ignore gaps on the viewport...
+     */
+    cs.setIncludeGaps(true);
+    assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalBlue);
+    af.getViewport().setIgnoreGapsConsensus(true, af.alignPanel);
+    // next test fails: colour scheme does not read ignore gaps flag from
+    // viewport
+    // assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalPink);
+  }
+}
diff --git a/test/jalview/schemes/ColourSchemePropertyTest.java b/test/jalview/schemes/ColourSchemePropertyTest.java
new file mode 100644 (file)
index 0000000..2854784
--- /dev/null
@@ -0,0 +1,120 @@
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class ColourSchemePropertyTest
+{
+  @Test(groups = "Functional")
+  public void testGetColourName()
+  {
+    SequenceI seq = new Sequence("Seq1", "abcd");
+    AlignmentI al = new Alignment(new SequenceI[] { seq });
+    ColourSchemeI cs = new ClustalxColourScheme(al, null);
+    assertEquals(ColourSchemeProperty.getColourName(cs), "Clustal");
+    cs = new Blosum62ColourScheme();
+    assertEquals(ColourSchemeProperty.getColourName(cs), "Blosum62");
+    cs = new PIDColourScheme();
+    assertEquals(ColourSchemeProperty.getColourName(cs), "% Identity");
+    cs = new HydrophobicColourScheme();
+    assertEquals(ColourSchemeProperty.getColourName(cs), "Hydrophobic");
+    cs = new ZappoColourScheme();
+    assertEquals(ColourSchemeProperty.getColourName(cs), "Zappo");
+    cs = new TaylorColourScheme();
+    assertEquals(ColourSchemeProperty.getColourName(cs), "Taylor");
+    cs = new HelixColourScheme();
+    assertEquals(ColourSchemeProperty.getColourName(cs),
+            "Helix Propensity");
+    cs = new StrandColourScheme();
+    assertEquals(ColourSchemeProperty.getColourName(cs),
+            "Strand Propensity");
+    cs = new TurnColourScheme();
+    assertEquals(ColourSchemeProperty.getColourName(cs), "Turn Propensity");
+    cs = new BuriedColourScheme();
+    assertEquals(ColourSchemeProperty.getColourName(cs), "Buried Index");
+    cs = new NucleotideColourScheme();
+    assertEquals(ColourSchemeProperty.getColourName(cs), "Nucleotide");
+    cs = new PurinePyrimidineColourScheme();
+    assertEquals(ColourSchemeProperty.getColourName(cs),
+            "Purine/Pyrimidine");
+    cs = new TCoffeeColourScheme(al);
+    assertEquals(ColourSchemeProperty.getColourName(cs), "T-Coffee Scores");
+    cs = new RNAHelicesColour(al);
+    assertEquals(ColourSchemeProperty.getColourName(cs), "RNA Helices");
+    cs = new RNAInteractionColourScheme();
+    assertEquals(ColourSchemeProperty.getColourName(cs),
+            "RNA Interaction type");
+    cs = new UserColourScheme();
+    assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
+
+    /*
+     * UserColourScheme may have a bespoke name
+     */
+    ((UserColourScheme) cs).setName("stripy");
+    assertEquals(ColourSchemeProperty.getColourName(cs), "stripy");
+    ((UserColourScheme) cs).setName("");
+    assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
+    ((UserColourScheme) cs).setName(null);
+    assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
+
+    assertEquals(ColourSchemeProperty.getColourName(null), "None");
+  }
+
+  @Test(groups = "Functional")
+  public void testGetColourScheme()
+  {
+    SequenceI seq = new Sequence("Seq1", "abcd");
+    AlignmentI al = new Alignment(new SequenceI[] { seq });
+    // the strings here correspond to JalviewColourScheme.toString() values
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "Clustal") instanceof ClustalxColourScheme);
+    // not case-sensitive
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "CLUSTAL") instanceof ClustalxColourScheme);
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "clustal") instanceof ClustalxColourScheme);
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "Blosum62") instanceof Blosum62ColourScheme);
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "% Identity") instanceof PIDColourScheme);
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "Zappo") instanceof ZappoColourScheme);
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "Taylor") instanceof TaylorColourScheme);
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "Hydrophobic") instanceof HydrophobicColourScheme);
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "Helix Propensity") instanceof HelixColourScheme);
+    assertTrue(ColourSchemeProperty
+            .getColourScheme(al, "Strand Propensity") instanceof StrandColourScheme);
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "Turn Propensity") instanceof TurnColourScheme);
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "Buried Index") instanceof BuriedColourScheme);
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "Nucleotide") instanceof NucleotideColourScheme);
+    assertTrue(ColourSchemeProperty
+            .getColourScheme(al, "Purine/Pyrimidine") instanceof PurinePyrimidineColourScheme);
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "T-Coffee Scores") instanceof TCoffeeColourScheme);
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "RNA Helices") instanceof RNAHelicesColour);
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "User Defined") instanceof UserColourScheme);
+    // 'None' is a special value
+    assertNull(ColourSchemeProperty.getColourScheme(al, "None"));
+    assertNull(ColourSchemeProperty.getColourScheme(al, "none"));
+    // default is to convert the name into a fixed colour
+    assertTrue(ColourSchemeProperty.getColourScheme(al, "elephants") instanceof UserColourScheme);
+
+    /*
+     * explicit aa colours
+     */
+    ColourSchemeI cs = ColourSchemeProperty.getColourScheme(al,
+            "R,G=red;C=blue;c=green;Q=10,20,30;S,T=11ffdd");
+    assertEquals(cs.findColour('H'), Color.white);
+    assertEquals(cs.findColour('R'), Color.red);
+    assertEquals(cs.findColour('r'), Color.red);
+    assertEquals(cs.findColour('G'), Color.red);
+    assertEquals(cs.findColour('C'), Color.blue);
+    assertEquals(cs.findColour('c'), Color.green);
+    assertEquals(cs.findColour('Q'), new Color(10, 20, 30));
+    assertEquals(cs.findColour('S'), new Color(0x11ffdd));
+    assertEquals(cs.findColour('T'), new Color(0x11ffdd));
+  }
+}
diff --git a/test/jalview/schemes/ColourSchemesTest.java b/test/jalview/schemes/ColourSchemesTest.java
new file mode 100644 (file)
index 0000000..6527756
--- /dev/null
@@ -0,0 +1,358 @@
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import jalview.bin.Cache;
+import jalview.bin.Jalview;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
+import jalview.gui.Desktop;
+import jalview.gui.SequenceRenderer;
+import jalview.io.DataSourceType;
+import jalview.io.FileLoader;
+import jalview.schemes.ClustalxColourScheme.ClustalColour;
+
+import java.awt.Color;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class ColourSchemesTest
+{
+  /*
+   * a colour scheme that alternates Taylor and Zappo
+   * colouring by column
+   */
+  class Stripy extends ResidueColourScheme
+  {
+    private ColourSchemeI odd;
+
+    private ColourSchemeI even;
+
+    private Stripy()
+    {
+    }
+
+    /**
+     * constructor given colours for odd and even columns
+     * 
+     * @param odd
+     * @param even
+     */
+    private Stripy(ColourSchemeI cs1, ColourSchemeI cs2)
+    {
+      odd = cs1;
+      even = cs2;
+    }
+
+    @Override
+    public ColourSchemeI getInstance(AnnotatedCollectionI sg,
+            Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+    {
+      final ColourSchemeI cs1 = ColourSchemes.getInstance()
+              .getColourScheme(JalviewColourScheme.Taylor.toString(),
+                      (AnnotatedCollectionI) null);
+      final ColourSchemeI cs2 = ColourSchemes.getInstance()
+              .getColourScheme(JalviewColourScheme.Zappo.toString(),
+                      (AnnotatedCollectionI) null);
+      return new Stripy(cs1, cs2);
+    }
+
+    @Override
+    public Color findColour(char c, int j, SequenceI seq)
+    {
+      if (j % 2 == 1)
+      {
+        return odd.findColour(c, j, seq);
+      }
+      else
+      {
+        return even.findColour(c, j, seq);
+      }
+    }
+
+    @Override
+    public String getSchemeName()
+    {
+      return "stripy";
+    }
+  };
+  
+  /*
+   * a colour scheme that is Clustal but using AWT colour equivalents
+   */
+  class MyClustal extends ResidueColourScheme
+  {
+    ColourSchemeI delegate;
+
+    private MyClustal()
+    {
+    }
+
+    private MyClustal(ColourSchemeI scheme)
+    {
+      delegate = scheme;
+    }
+
+    @Override
+    public Color findColour(char c, int j, SequenceI seq)
+    {
+      Color col = delegate.findColour(c, j, seq);
+      Color result = col;
+      if (col.equals(ClustalColour.BLUE.colour))
+      {
+        result = Color.blue;
+      }
+      else if (col.equals(ClustalColour.CYAN.colour))
+      {
+        result = Color.cyan;
+      }
+      else if (col.equals(ClustalColour.GREEN.colour))
+      {
+        result = Color.green;
+      }
+      else if (col.equals(ClustalColour.MAGENTA.colour))
+      {
+        result = Color.magenta;
+      }
+      else if (col.equals(ClustalColour.ORANGE.colour))
+      {
+        result = Color.orange;
+      }
+      else if (col.equals(ClustalColour.PINK.colour))
+      {
+        result = Color.pink;
+      }
+      else if (col.equals(ClustalColour.RED.colour))
+      {
+        result = Color.red;
+      }
+      else if (col.equals(ClustalColour.YELLOW.colour))
+      {
+        result = Color.yellow;
+      }
+      return result;
+    }
+
+    @Override
+    public ColourSchemeI getInstance(AnnotatedCollectionI sg,
+            Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+    {
+      return new MyClustal(new ClustalxColourScheme().getInstance(sg,
+              hiddenRepSequences));
+    }
+
+    @Override
+    public String getSchemeName()
+    {
+      return "MyClustal";
+    }
+
+  }
+
+  @BeforeClass(alwaysRun = true)
+  public static void setUpBeforeClass() throws Exception
+  {
+    /*
+     * use read-only test properties file
+     */
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+    Jalview.main(new String[] { "-nonews" });
+  }
+
+  @AfterClass(alwaysRun = true)
+  public static void tearDownAfterClass() throws Exception
+  {
+    Desktop.instance.closeAll_actionPerformed(null);
+  }
+
+  @Test(groups = "Functional")
+  public void testGetColourSchemes()
+  {
+    /*
+     * this just verifies that built-in colour schemes are loaded into ColourSchemes
+     * in the order in which they are declared in the JalviewColourScheme enum
+     * (this also determines their order in Colour menus)
+     */
+    Iterator<ColourSchemeI> schemes = ColourSchemes.getInstance().getColourSchemes().iterator();
+    JalviewColourScheme[] jalviewSchemes = JalviewColourScheme.values();
+    int i = 0;
+    while (schemes.hasNext() && i < jalviewSchemes.length)
+    {
+      assertTrue(schemes.next().getSchemeName()
+              .equals(jalviewSchemes[i].toString()));
+      i++;
+    }
+  }
+
+  @Test(groups = "Functional")
+  public void testGetColourScheme_forViewport()
+  {
+    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+            ">seq1\nAGLRTWQU", DataSourceType.PASTE);
+    ColourSchemes cs = ColourSchemes.getInstance();
+
+    AlignViewport viewport = af.getViewport();
+    AlignmentI alignment = viewport.getAlignment();
+    assertTrue(cs.getColourScheme(JalviewColourScheme.Blosum62.toString(),
+            alignment) instanceof Blosum62ColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.Buried.toString(),
+            alignment) instanceof BuriedColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.Clustal.toString(),
+            alignment) instanceof ClustalxColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.Helix.toString(),
+            alignment) instanceof HelixColourScheme);
+    assertTrue(cs.getColourScheme(
+            JalviewColourScheme.Hydrophobic.toString(), alignment) instanceof HydrophobicColourScheme);
+    assertTrue(cs.getColourScheme(
+            JalviewColourScheme.Nucleotide.toString(), alignment) instanceof NucleotideColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.PID.toString(),
+            alignment) instanceof PIDColourScheme);
+    assertTrue(cs.getColourScheme(
+            JalviewColourScheme.PurinePyrimidine.toString(), alignment) instanceof PurinePyrimidineColourScheme);
+    assertTrue(cs.getColourScheme(
+            JalviewColourScheme.RNAHelices.toString(), alignment) instanceof RNAHelicesColour);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.Strand.toString(),
+            alignment) instanceof StrandColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.Taylor.toString(),
+            alignment) instanceof TaylorColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.TCoffee.toString(),
+            alignment) instanceof TCoffeeColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.Turn.toString(),
+            alignment) instanceof TurnColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.Zappo.toString(),
+            alignment) instanceof ZappoColourScheme);
+    af.closeMenuItem_actionPerformed(true);
+  }
+
+  @Test(groups = "Functional")
+  public void testGetColourScheme_forAnnotatedCollection()
+  {
+    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+            ">seq1\nAGLRTWQU", DataSourceType.PASTE);
+    ColourSchemes cs = ColourSchemes.getInstance();
+
+    AnnotatedCollectionI al = af.getViewport().getAlignment();
+    assertTrue(cs.getColourScheme(JalviewColourScheme.Blosum62.toString(),
+            al) instanceof Blosum62ColourScheme);
+    assertTrue(cs
+            .getColourScheme(JalviewColourScheme.Buried.toString(), al) instanceof BuriedColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.Clustal.toString(),
+            al) instanceof ClustalxColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.Helix.toString(), al) instanceof HelixColourScheme);
+    assertTrue(cs.getColourScheme(
+            JalviewColourScheme.Hydrophobic.toString(), al) instanceof HydrophobicColourScheme);
+    assertTrue(cs.getColourScheme(
+            JalviewColourScheme.Nucleotide.toString(), al) instanceof NucleotideColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.PID.toString(), al) instanceof PIDColourScheme);
+    assertTrue(cs.getColourScheme(
+            JalviewColourScheme.PurinePyrimidine.toString(), al) instanceof PurinePyrimidineColourScheme);
+    assertTrue(cs.getColourScheme(
+            JalviewColourScheme.RNAHelices.toString(), al) instanceof RNAHelicesColour);
+    assertTrue(cs
+            .getColourScheme(JalviewColourScheme.Strand.toString(), al) instanceof StrandColourScheme);
+    assertTrue(cs
+            .getColourScheme(JalviewColourScheme.Taylor.toString(), al) instanceof TaylorColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.TCoffee.toString(),
+            al) instanceof TCoffeeColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.Turn.toString(), al) instanceof TurnColourScheme);
+    assertTrue(cs.getColourScheme(JalviewColourScheme.Zappo.toString(), al) instanceof ZappoColourScheme);
+    af.closeMenuItem_actionPerformed(true);
+  }
+  
+  @Test(groups = "Functional")
+  public void testRegisterColourScheme()
+  {
+    ColourSchemes.getInstance().registerColourScheme(new Stripy());
+    ColourSchemes.getInstance().registerColourScheme(new MyClustal());
+    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+            "examples/uniref50.fa", DataSourceType.FILE);
+    /*
+     * set a breakpoint here to see and play with the newly registered
+     *  colour schemes in the AlignFrame colour menu
+     */
+    SequenceRenderer sr = new SequenceRenderer(af.getViewport());
+    SequenceI seq = af.getViewport().getAlignment().findName("FER_CAPAA");
+
+    /*
+     * set and check Taylor colours
+     */
+    af.changeColour_actionPerformed(JalviewColourScheme.Taylor.toString());
+    Color taylor1 = sr.getResidueBoxColour(seq, 88); // E 255,0,102
+    Color taylor2 = sr.getResidueBoxColour(seq, 89); // A 204,255,0
+    Color taylor3 = sr.getResidueBoxColour(seq, 90); // G 255,153,0
+    assertEquals(taylor1, new Color(255, 0, 102));
+    assertEquals(taylor2, new Color(204, 255, 0));
+    assertEquals(taylor3, new Color(255, 153, 0));
+
+    /*
+     * set and check Zappo colours
+     */
+    af.changeColour_actionPerformed(JalviewColourScheme.Zappo.toString());
+    Color zappo1 = sr.getResidueBoxColour(seq, 88); // E red
+    Color zappo2 = sr.getResidueBoxColour(seq, 89); // A pink
+    Color zappo3 = sr.getResidueBoxColour(seq, 90); // G magenta
+    assertEquals(zappo1, Color.red);
+    assertEquals(zappo2, Color.pink);
+    assertEquals(zappo3, Color.magenta);
+
+    /*
+     * set 'stripy' colours - odd columns are Taylor and even are Zappo 
+     */
+    af.changeColour_actionPerformed("stripy");
+    Color stripy1 = sr.getResidueBoxColour(seq, 88);
+    Color stripy2 = sr.getResidueBoxColour(seq, 89);
+    Color stripy3 = sr.getResidueBoxColour(seq, 90);
+    assertEquals(stripy1, zappo1);
+    assertEquals(stripy2, taylor2);
+    assertEquals(stripy3, zappo3);
+
+    /*
+     * set and check Clustal colours
+     */
+    af.changeColour_actionPerformed(JalviewColourScheme.Clustal.toString());
+    Color clustal1 = sr.getResidueBoxColour(seq, 88);
+    Color clustal2 = sr.getResidueBoxColour(seq, 89);
+    Color clustal3 = sr.getResidueBoxColour(seq, 90);
+    assertEquals(clustal1, ClustalColour.MAGENTA.colour);
+    assertEquals(clustal2, ClustalColour.BLUE.colour);
+    assertEquals(clustal3, ClustalColour.ORANGE.colour);
+
+    /*
+     * set 'MyClustal' colours - uses AWT colour equivalents
+     */
+    af.changeColour_actionPerformed("MyClustal");
+    Color myclustal1 = sr.getResidueBoxColour(seq, 88);
+    Color myclustal2 = sr.getResidueBoxColour(seq, 89);
+    Color myclustal3 = sr.getResidueBoxColour(seq, 90);
+    assertEquals(myclustal1, Color.MAGENTA);
+    assertEquals(myclustal2, Color.BLUE);
+    assertEquals(myclustal3, Color.ORANGE);
+  }
+
+  /**
+   * Tests for check if scheme name exists. Built-in scheme names are the
+   * toString() values of enum JalviewColourScheme.
+   */
+  @Test(groups = "Functional")
+  public void testNameExists()
+  {
+    ColourSchemes cs = ColourSchemes.getInstance();
+    assertFalse(cs.nameExists(null));
+    assertFalse(cs.nameExists(""));
+    assertTrue(cs.nameExists("Clustal"));
+    assertTrue(cs.nameExists("CLUSTAL"));
+    assertFalse(cs.nameExists("CLUSTAL "));
+    assertTrue(cs.nameExists("% Identity"));
+    assertFalse(cs.nameExists("PID"));
+  }
+}
index 47613a1..c16d541 100644 (file)
@@ -27,6 +27,7 @@ import static org.testng.AssertJUnit.fail;
 
 import jalview.datamodel.SequenceFeature;
 import jalview.gui.JvOptionPane;
+import jalview.util.ColorUtils;
 import jalview.util.Format;
 
 import java.awt.Color;
@@ -146,7 +147,7 @@ public class FeatureColourTest
     fc.setColourByLabel(true);
     SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 1f,
             null);
-    Color expected = UserColourScheme.createColourFromName("desc");
+    Color expected = ColorUtils.createColourFromName("desc");
     assertEquals(expected, fc.getColor(sf));
   }
 
diff --git a/test/jalview/schemes/JalviewColourSchemeTest.java b/test/jalview/schemes/JalviewColourSchemeTest.java
new file mode 100644 (file)
index 0000000..d9403d2
--- /dev/null
@@ -0,0 +1,48 @@
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import org.testng.annotations.Test;
+
+public class JalviewColourSchemeTest
+{
+  @Test(groups = "Functional")
+  public void testGetSchemeClass()
+  {
+    assertTrue(JalviewColourScheme.Clustal.getSchemeClass() == ClustalxColourScheme.class);
+    assertTrue(JalviewColourScheme.Blosum62.getSchemeClass() == Blosum62ColourScheme.class);
+    assertTrue(JalviewColourScheme.PID.getSchemeClass() == PIDColourScheme.class);
+    assertTrue(JalviewColourScheme.Hydrophobic.getSchemeClass() == HydrophobicColourScheme.class);
+    assertTrue(JalviewColourScheme.Zappo.getSchemeClass() == ZappoColourScheme.class);
+    assertTrue(JalviewColourScheme.Taylor.getSchemeClass() == TaylorColourScheme.class);
+    assertTrue(JalviewColourScheme.Helix.getSchemeClass() == HelixColourScheme.class);
+    assertTrue(JalviewColourScheme.Strand.getSchemeClass() == StrandColourScheme.class);
+    assertTrue(JalviewColourScheme.Turn.getSchemeClass() == TurnColourScheme.class);
+    assertTrue(JalviewColourScheme.Buried.getSchemeClass() == BuriedColourScheme.class);
+    assertTrue(JalviewColourScheme.Nucleotide.getSchemeClass() == NucleotideColourScheme.class);
+    assertTrue(JalviewColourScheme.PurinePyrimidine.getSchemeClass() == PurinePyrimidineColourScheme.class);
+    assertTrue(JalviewColourScheme.TCoffee.getSchemeClass() == TCoffeeColourScheme.class);
+    assertTrue(JalviewColourScheme.RNAHelices.getSchemeClass() == RNAHelicesColour.class);
+  }
+
+  @Test(groups = "Functional")
+  public void testToString()
+  {
+    assertEquals(JalviewColourScheme.Clustal.toString(), "Clustal");
+    assertEquals(JalviewColourScheme.Blosum62.toString(), "Blosum62");
+    assertEquals(JalviewColourScheme.PID.toString(), "% Identity");
+    assertEquals(JalviewColourScheme.Zappo.toString(), "Zappo");
+    assertEquals(JalviewColourScheme.Taylor.toString(), "Taylor");
+    assertEquals(JalviewColourScheme.Hydrophobic.toString(), "Hydrophobic");
+    assertEquals(JalviewColourScheme.Helix.toString(), "Helix Propensity");
+    assertEquals(JalviewColourScheme.Strand.toString(), "Strand Propensity");
+    assertEquals(JalviewColourScheme.Turn.toString(), "Turn Propensity");
+    assertEquals(JalviewColourScheme.Buried.toString(), "Buried Index");
+    assertEquals(JalviewColourScheme.Nucleotide.toString(), "Nucleotide");
+    assertEquals(JalviewColourScheme.PurinePyrimidine.toString(),
+            "Purine/Pyrimidine");
+    assertEquals(JalviewColourScheme.TCoffee.toString(), "T-Coffee Scores");
+    assertEquals(JalviewColourScheme.RNAHelices.toString(), "RNA Helices");
+  }
+}
index d3a4fff..c3ea385 100644 (file)
@@ -24,10 +24,18 @@ import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertTrue;
 
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.Annotation;
 import jalview.datamodel.Profile;
 import jalview.datamodel.ProfileI;
 import jalview.datamodel.Profiles;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
 import jalview.gui.JvOptionPane;
+import jalview.io.TCoffeeScoreFile;
 
 import java.awt.Color;
 
@@ -36,6 +44,11 @@ import org.testng.annotations.Test;
 
 public class ResidueColourSchemeTest
 {
+  @BeforeClass(alwaysRun = true)
+  public void setUp()
+  {
+
+  }
 
   @BeforeClass(alwaysRun = true)
   public void setUpJvOptionPane()
@@ -59,7 +72,7 @@ public class ResidueColourSchemeTest
     profiles[1] = new Profile(4, 0, 4, "R");
     profiles[2] = new Profile(4, 4, 0, "");
     profiles[3] = new Profile(4, 1, 2, "T");
-    ResidueColourScheme rcs = new ResidueColourScheme();
+    ResidueColourScheme rcs = new PIDColourScheme();
     rcs.setConsensus(new Profiles(profiles));
     
     /*
@@ -68,11 +81,11 @@ public class ResidueColourSchemeTest
     rcs.setThreshold(0, true);
     assertTrue(rcs.aboveThreshold('a', 0));
     assertTrue(rcs.aboveThreshold('S', 0));
-    assertFalse(rcs.aboveThreshold('W', 0));
+    assertTrue(rcs.aboveThreshold('W', 0));
     assertTrue(rcs.aboveThreshold('R', 1));
-    assertFalse(rcs.aboveThreshold('W', 2));
+    assertTrue(rcs.aboveThreshold('W', 2));
     assertTrue(rcs.aboveThreshold('t', 3));
-    assertFalse(rcs.aboveThreshold('Q', 3));
+    assertTrue(rcs.aboveThreshold('Q', 3));
 
     /*
      * with threshold, include gaps
@@ -102,7 +115,7 @@ public class ResidueColourSchemeTest
   @Test(groups = "Functional")
   public void testApplyConservation()
   {
-    ResidueColourScheme rcs = new ResidueColourScheme();
+    ResidueColourScheme rcs = new PIDColourScheme();
 
     // no conservation present - no fading
     assertEquals(Color.RED, rcs.applyConservation(Color.RED, 12));
@@ -176,4 +189,151 @@ public class ResidueColourSchemeTest
     assertEquals(colour, rcs.applyConservation(colour, 11));
     assertEquals(Color.WHITE, rcs.applyConservation(colour, 12));
   }
+
+  @Test(groups = "Functional")
+  public void testIsApplicableTo()
+  {
+    SequenceI pep1 = new Sequence("pep1", "APQTWLS");
+    SequenceI pep2 = new Sequence("pep2", "AILFQYG");
+    SequenceI dna1 = new Sequence("dna1", "ACTGAC");
+    SequenceI dna2 = new Sequence("dna2", "TCCAAG");
+    AlignmentI peptide = new Alignment(new SequenceI[] { pep1, pep2 });
+    AlignmentI nucleotide = new Alignment(new SequenceI[] { dna1, dna2 });
+
+    /*
+     * peptide-specific colour schemes
+     */
+    assertTrue(new ClustalxColourScheme(peptide, null)
+            .isApplicableTo(peptide));
+    assertFalse(new ClustalxColourScheme(nucleotide, null)
+            .isApplicableTo(nucleotide));
+    assertTrue(new Blosum62ColourScheme().isApplicableTo(peptide));
+    assertFalse(new Blosum62ColourScheme().isApplicableTo(nucleotide));
+    assertTrue(new BuriedColourScheme().isApplicableTo(peptide));
+    assertFalse(new BuriedColourScheme().isApplicableTo(nucleotide));
+    assertTrue(new HelixColourScheme().isApplicableTo(peptide));
+    assertFalse(new HelixColourScheme().isApplicableTo(nucleotide));
+    assertTrue(new HydrophobicColourScheme().isApplicableTo(peptide));
+    assertFalse(new HydrophobicColourScheme().isApplicableTo(nucleotide));
+    assertTrue(new StrandColourScheme().isApplicableTo(peptide));
+    assertFalse(new StrandColourScheme().isApplicableTo(nucleotide));
+    assertTrue(new TaylorColourScheme().isApplicableTo(peptide));
+    assertFalse(new TaylorColourScheme().isApplicableTo(nucleotide));
+    assertTrue(new TurnColourScheme().isApplicableTo(peptide));
+    assertFalse(new TurnColourScheme().isApplicableTo(nucleotide));
+    assertTrue(new ZappoColourScheme().isApplicableTo(peptide));
+    assertFalse(new ZappoColourScheme().isApplicableTo(nucleotide));
+
+    /*
+     * nucleotide-specific colour schemes
+     */
+    assertFalse(new NucleotideColourScheme().isApplicableTo(peptide));
+    assertTrue(new NucleotideColourScheme().isApplicableTo(nucleotide));
+    assertFalse(new PurinePyrimidineColourScheme().isApplicableTo(peptide));
+    assertTrue(new PurinePyrimidineColourScheme()
+            .isApplicableTo(nucleotide));
+    assertFalse(new RNAInteractionColourScheme().isApplicableTo(peptide));
+    assertTrue(new RNAInteractionColourScheme().isApplicableTo(nucleotide));
+
+    /*
+     * indifferent
+     */
+    assertTrue(new UserColourScheme().isApplicableTo(peptide));
+    assertTrue(new UserColourScheme().isApplicableTo(nucleotide));
+    assertTrue(new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d)
+            .isApplicableTo(peptide));
+    assertTrue(new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d)
+            .isApplicableTo(nucleotide));
+    ResidueColourScheme rcs = new PIDColourScheme();
+    assertTrue(rcs.isApplicableTo(peptide));
+    assertTrue(rcs.isApplicableTo(nucleotide));
+    assertTrue(new PIDColourScheme().isApplicableTo(peptide));
+    assertTrue(new PIDColourScheme().isApplicableTo(nucleotide));
+    assertTrue(new FollowerColourScheme().isApplicableTo(peptide));
+    assertTrue(new FollowerColourScheme().isApplicableTo(nucleotide));
+
+    /*
+     * TCoffee colour requires the presence of TCoffee score annotation
+     */
+    assertFalse(new TCoffeeColourScheme(peptide).isApplicableTo(peptide));
+    assertFalse(new TCoffeeColourScheme(nucleotide)
+            .isApplicableTo(nucleotide));
+    AlignmentAnnotation aa = new AlignmentAnnotation("T-COFFEE", "", null);
+    aa.setCalcId(TCoffeeScoreFile.TCOFFEE_SCORE);
+    peptide.addAnnotation(aa);
+    aa = new AlignmentAnnotation("T-COFFEE", "", null);
+    aa.setCalcId(TCoffeeScoreFile.TCOFFEE_SCORE);
+    nucleotide.addAnnotation(aa);
+    assertTrue(new TCoffeeColourScheme(peptide).isApplicableTo(peptide));
+    assertTrue(new TCoffeeColourScheme(nucleotide)
+            .isApplicableTo(nucleotide));
+
+    /*
+     * RNAHelices requires the presence of rna secondary structure
+     */
+    assertFalse(new RNAHelicesColour(peptide).isApplicableTo(peptide));
+    assertFalse(new RNAHelicesColour(nucleotide).isApplicableTo(nucleotide));
+    // add secondary structure (small but perfectly formed)
+    Annotation[] ss = new Annotation[2];
+    ss[0] = new Annotation("", "", '{', 0f);
+    ss[1] = new Annotation("", "", '}', 0f);
+    nucleotide.addAnnotation(new AlignmentAnnotation("SS", "", ss));
+    assertTrue(new RNAHelicesColour(nucleotide).isApplicableTo(nucleotide));
+  }
+
+  @Test(groups = "Functional")
+  public void testIsApplicableTo_dynamicColourScheme()
+  {
+    SequenceI pep1 = new Sequence("pep1", "APQTWLS");
+    SequenceI pep2 = new Sequence("pep2", "AILFQYG");
+    AlignmentI peptide = new Alignment(new SequenceI[] { pep1, pep2 });
+  
+    /*
+     * demonstrate that we can 'plug in' a colour scheme with specified
+     * criteria for applicability; here, that there are more than 2 sequences
+     */
+    ColourSchemeI cs = new UserColourScheme()
+    {
+      @Override
+      public boolean isApplicableTo(AnnotatedCollectionI ac)
+      {
+        AlignmentI al = ac.getContext() == null ? (AlignmentI) ac
+                : (AlignmentI) ac.getContext();
+        return al.getSequences().size() > 2;
+      }
+    };
+    assertFalse(cs.isApplicableTo(peptide));
+    peptide.addSequence(pep1);
+    assertTrue(cs.isApplicableTo(peptide));
+  }
+
+  @Test(groups = "Functional")
+  public void testGetName()
+  {
+    SequenceI pep1 = new Sequence("pep1", "APQTWLS");
+    AlignmentI peptide = new Alignment(new SequenceI[] { pep1 });
+
+    assertEquals("Blosum62", new Blosum62ColourScheme().getSchemeName());
+    assertEquals("Buried Index", new BuriedColourScheme().getSchemeName());
+    assertEquals("Helix Propensity", new HelixColourScheme().getSchemeName());
+    assertEquals("Hydrophobic", new HydrophobicColourScheme().getSchemeName());
+    assertEquals("Strand Propensity", new StrandColourScheme().getSchemeName());
+    assertEquals("Taylor", new TaylorColourScheme().getSchemeName());
+    assertEquals("Turn Propensity", new TurnColourScheme().getSchemeName());
+    assertEquals("Zappo", new ZappoColourScheme().getSchemeName());
+    assertEquals("Nucleotide", new NucleotideColourScheme().getSchemeName());
+    assertEquals("Purine/Pyrimidine",
+            new PurinePyrimidineColourScheme().getSchemeName());
+    assertEquals("RNA Interaction type",
+            new RNAInteractionColourScheme().getSchemeName());
+    assertEquals("User Defined", new UserColourScheme().getSchemeName());
+    assertEquals("Score", new ScoreColourScheme(new int[] {},
+            new double[] {}, 0, 0d).getSchemeName());
+    assertEquals("% Identity", new PIDColourScheme().getSchemeName());
+    assertEquals("Follower", new FollowerColourScheme().getSchemeName());
+    assertEquals("T-Coffee Scores",
+            new TCoffeeColourScheme(peptide).getSchemeName());
+    assertEquals("RNA Helices",
+            new RNAHelicesColour(peptide).getSchemeName());
+  }
 }
index 645d5b8..497014e 100644 (file)
@@ -21,8 +21,6 @@
 package jalview.schemes;
 
 import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertSame;
 
 import jalview.gui.JvOptionPane;
 
@@ -42,40 +40,44 @@ public class UserColourSchemeTest
   }
 
   @Test(groups = "Functional")
-  public void testGetColourFromString()
+  public void testParseAppletParameter()
   {
-    /*
-     * by colour name - if known to AWT, and included in
-     * 
-     * @see ColourSchemeProperty.getAWTColorFromName()
-     */
-    assertSame(Color.RED, UserColourScheme.getColourFromString("red"));
-    assertSame(Color.RED, UserColourScheme.getColourFromString("Red"));
-    assertSame(Color.RED, UserColourScheme.getColourFromString(" RED "));
+    UserColourScheme cs = new UserColourScheme("white");
+    cs.parseAppletParameter("D,E=red; K,R,H=0022FF; c=10 , 20,30");
+    assertEquals(Color.RED, cs.findColour('D'));
+    assertEquals(Color.RED, cs.findColour('d'));
+    assertEquals(Color.RED, cs.findColour('E'));
+    assertEquals(Color.RED, cs.findColour('e'));
+    Color c1 = new Color(0x0022ff);
+    assertEquals(c1, cs.findColour('K'));
+    assertEquals(c1, cs.findColour('R'));
+    assertEquals(c1, cs.findColour('h'));
+    Color c2 = new Color(10, 20, 30);
+    assertEquals(c2, cs.findColour('c'));
 
-    /*
-     * by RGB hex code
-     */
-    String hexColour = Integer.toHexString(Color.RED.getRGB() & 0xffffff);
-    assertEquals(Color.RED, UserColourScheme.getColourFromString(hexColour));
-    // 'hex' prefixes _not_ wanted here
-    assertNull(UserColourScheme.getColourFromString("0x" + hexColour));
-    assertNull(UserColourScheme.getColourFromString("#" + hexColour));
-
-    /*
-     * by RGB triplet
-     */
-    String rgb = String.format("%d,%d,%d", Color.red.getRed(),
-            Color.red.getGreen(), Color.red.getBlue());
-    assertEquals(Color.RED, UserColourScheme.getColourFromString(rgb));
+    cs = new UserColourScheme("white");
+    cs.parseAppletParameter("D,E=red; K,R,H=0022FF; c=10 , 20,30;t=orange;lowercase=blue;s=pink");
+    assertEquals(Color.RED, cs.findColour('D'));
+    assertEquals(Color.blue, cs.findColour('d'));
+    assertEquals(Color.RED, cs.findColour('E'));
+    assertEquals(Color.blue, cs.findColour('e'));
+    assertEquals(c1, cs.findColour('K'));
+    assertEquals(c1, cs.findColour('R'));
+    assertEquals(Color.blue, cs.findColour('h'));
+    assertEquals(c2, cs.findColour('c'));
+    // 'lowercase' sets all lower-case not already set to the given colour
+    assertEquals(Color.orange, cs.findColour('t'));
+    assertEquals(Color.blue, cs.findColour('k'));
+    assertEquals(Color.blue, cs.findColour('a'));
+    assertEquals(Color.pink, cs.findColour('s'));
+  }
 
-    /*
-     * odds and ends
-     */
-    assertNull(UserColourScheme.getColourFromString(null));
-    assertNull(UserColourScheme.getColourFromString("rubbish"));
-    assertEquals(Color.WHITE, UserColourScheme.getColourFromString("-1"));
-    assertNull(UserColourScheme.getColourFromString(String
-            .valueOf(Integer.MAX_VALUE)));
+  @Test(groups = "Functional")
+  public void testToAppletParameter()
+  {
+    UserColourScheme cs = new UserColourScheme(
+            "E,D=red; K,R,H=0022FF; c=10 , 20,30");
+    String param = cs.toAppletParameter();
+    assertEquals("D,E=ff0000;H,K,R=0022ff;c=0a141e", param);
   }
 }
index b74a089..0422537 100644 (file)
@@ -24,18 +24,25 @@ import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertTrue;
 
+import jalview.api.AlignmentViewPanel;
+import jalview.api.FeatureRenderer;
+import jalview.api.SequenceRenderer;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.PDBEntry.Type;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
 import jalview.gui.JvOptionPane;
 import jalview.io.DataSourceType;
+import jalview.schemes.ColourSchemeI;
 import jalview.structure.AtomSpec;
+import jalview.structure.StructureMappingcommandSet;
 import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel.SuperposeData;
 
+import java.awt.Color;
 import java.util.Arrays;
 import java.util.List;
 
@@ -155,6 +162,59 @@ public class AAStructureBindingModelTest
       {
         return null;
       }
+
+      @Override
+      public void setJalviewColourScheme(ColourSchemeI cs)
+      {
+      }
+
+      @Override
+      public void superposeStructures(AlignmentI[] als, int[] alm,
+              ColumnSelection[] alc)
+      {
+      }
+
+      @Override
+      public void setBackgroundColour(Color col)
+      {
+      }
+
+      @Override
+      protected StructureMappingcommandSet[] getColourBySequenceCommands(
+              String[] files, SequenceRenderer sr, FeatureRenderer fr,
+              AlignmentI alignment)
+      {
+        return null;
+      }
+
+      @Override
+      public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
+      {
+        return null;
+      }
+
+      @Override
+      public SequenceRenderer getSequenceRenderer(
+              AlignmentViewPanel alignment)
+      {
+        return null;
+      }
+
+      @Override
+      protected void colourBySequence(
+              StructureMappingcommandSet[] colourBySequenceCommands)
+      {
+      }
+
+      @Override
+      public void colourByChain()
+      {
+      }
+
+      @Override
+      public void colourByCharge()
+      {
+      }
     };
   }
 
@@ -239,4 +299,14 @@ public class AAStructureBindingModelTest
     assertFalse(matched[4]); // superposable, but hidden, column
     assertTrue(matched[5]);
   }
+
+  public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
+  {
+    return null;
+  }
+
+  public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
+  {
+    return null;
+  }
 }
index 9a5d093..d267ebc 100644 (file)
@@ -166,4 +166,79 @@ public class ColorUtilsTest
     assertEquals(new Color(46, 31, 16), // with rounding down
             ColorUtils.bleachColour(colour, -0.7f));
   }
+
+  @Test(groups = "Functional")
+  public void testParseColourString()
+  {
+    /*
+     * by colour name - if known to AWT, and included in
+     * 
+     * @see ColourSchemeProperty.getAWTColorFromName()
+     */
+    assertSame(Color.RED, ColorUtils.parseColourString("red"));
+    assertSame(Color.RED, ColorUtils.parseColourString("Red"));
+    assertSame(Color.RED, ColorUtils.parseColourString(" RED "));
+
+    /*
+     * by RGB hex code
+     */
+    String hexColour = Integer.toHexString(Color.RED.getRGB() & 0xffffff);
+    assertEquals("ff0000", hexColour);
+    assertEquals(Color.RED, ColorUtils.parseColourString(hexColour));
+    // 'hex' prefixes _not_ wanted here
+    assertNull(ColorUtils.parseColourString("0x" + hexColour));
+    assertNull(ColorUtils.parseColourString("#" + hexColour));
+    // out of range, but Color constructor just or's the rgb value with 0
+    assertEquals(Color.black, ColorUtils.parseColourString("1000000"));
+
+    /*
+     * by RGB triplet
+     */
+    Color c = Color.pink;
+    String rgb = String.format("%d,%d,%d", c.getRed(), c.getGreen(),
+            c.getBlue());
+    assertEquals("255,175,175", rgb);
+    assertEquals(c, ColorUtils.parseColourString(rgb));
+    assertEquals(c, ColorUtils.parseColourString("255, 175 , 175"));
+
+    /*
+     * odds and ends
+     */
+    assertNull(ColorUtils.parseColourString(null));
+    assertNull(ColorUtils.parseColourString("rubbish"));
+    assertEquals(Color.WHITE, ColorUtils.parseColourString("-1"));
+    assertNull(ColorUtils.parseColourString(String
+            .valueOf(Integer.MAX_VALUE)));
+    assertNull(ColorUtils.parseColourString("100,200,300")); // out of range
+    assertNull(ColorUtils.parseColourString("100,200")); // too few
+    assertNull(ColorUtils.parseColourString("100,200,100,200")); // too many
+  }
+
+  @Test(groups = "Functional")
+  public void testGetAWTColorFromName() {
+    assertEquals(Color.white, ColorUtils.getAWTColorFromName("white"));
+    assertEquals(Color.white, ColorUtils.getAWTColorFromName("White"));
+    assertEquals(Color.white, ColorUtils.getAWTColorFromName("WHITE"));
+    assertEquals(Color.pink, ColorUtils.getAWTColorFromName("pink"));
+    assertNull(ColorUtils.getAWTColorFromName("mauve")); // no such name
+    assertNull(ColorUtils.getAWTColorFromName(""));
+    assertNull(ColorUtils.getAWTColorFromName(null));
+  }
+
+  @Test(groups = "Functional")
+  public void testCreateColourFromName()
+  {
+    assertEquals(Color.white, ColorUtils.createColourFromName(null));
+    assertEquals(new Color(20, 20, 20), ColorUtils.createColourFromName(""));
+    assertEquals(new Color(123, 211, 122),
+            ColorUtils.createColourFromName("hello world"));
+    assertEquals(new Color(27, 147, 112),
+            ColorUtils.createColourFromName("HELLO WORLD"));
+    /*
+     * the algorithm makes the same values for r,g,b if 
+     * the string consists of 3 repeating substrings
+     */
+    assertEquals(new Color(184, 184, 184),
+            ColorUtils.createColourFromName("HELLO HELLO HELLO "));
+  }
 }