From 7d0ee5869e28d0cdde911336e9bbe290b143f0bc Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Wed, 25 May 2005 16:40:13 +0000 Subject: [PATCH] usercolours changed --- src/jalview/gui/AlignFrame.java | 27 +++++----- src/jalview/gui/AlignViewport.java | 10 ++-- src/jalview/gui/Finder.java | 8 +-- src/jalview/gui/UserDefinedColours.java | 87 +++++++++++++++++-------------- 4 files changed, 68 insertions(+), 64 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index de2d8ef..1f04fa3 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -105,9 +105,8 @@ public class AlignFrame extends GAlignFrame protected void outputText_actionPerformed(ActionEvent e) { - CutAndPasteTransfer cap = new CutAndPasteTransfer(false); + CutAndPasteTransfer cap = new CutAndPasteTransfer(); JInternalFrame frame = new JInternalFrame(); - cap.formatForOutput(); frame.setContentPane(cap); Desktop.addInternalFrame(frame, "Alignment output - "+e.getActionCommand(), 600, 500); cap.setText( FormatAdapter.formatSequences(e.getActionCommand(), viewport.getAlignment().getSequences())); @@ -115,8 +114,7 @@ public class AlignFrame extends GAlignFrame protected void htmlMenuItem_actionPerformed(ActionEvent e) { - HTMLOutput htmlOutput = new HTMLOutput(viewport); - htmlOutput = null; + new HTMLOutput(viewport); } protected void createPNG_actionPerformed(ActionEvent e) @@ -737,7 +735,6 @@ public class AlignFrame extends GAlignFrame public void clustalColour_actionPerformed(ActionEvent e) { - abovePIDThreshold.setSelected(false); changeColour(new ClustalxColourScheme(viewport.alignment.getSequences(), viewport.alignment.getWidth())); } @@ -834,7 +831,7 @@ public class AlignFrame extends GAlignFrame ccs.setConsensus( viewport.vconsensus ); viewport.setGlobalColourScheme(ccs); - SliderPanel.setConservationSlider(alignPanel, ccs, "Background"); + ccs.inc = SliderPanel.setConservationSlider(alignPanel, ccs, "Background"); } else @@ -853,16 +850,16 @@ public class AlignFrame extends GAlignFrame { SequenceGroup sg = (SequenceGroup)groups.elementAt(i); - if (cs instanceof ClustalxColourScheme) - { + if(cs==null) + sg.cs = null; + else if (cs instanceof ClustalxColourScheme) sg.cs = new ClustalxColourScheme(sg.sequences, sg.getWidth()); - } - else if(cs!=null) - { + else if (cs instanceof UserColourScheme) + sg.cs = new UserColourScheme( ((UserColourScheme)cs).getColours()); + else try{ sg.cs = (ColourSchemeI) cs.getClass().newInstance(); - }catch(Exception ex){ex.printStackTrace();} - } + }catch(Exception ex){} if(viewport.getAbovePIDThreshold()) { @@ -959,7 +956,7 @@ public class AlignFrame extends GAlignFrame public void userDefinedColour_actionPerformed(ActionEvent e) { - UserDefinedColours chooser = new UserDefinedColours( alignPanel, null); + new UserDefinedColours( alignPanel, null); } public void PIDColour_actionPerformed(ActionEvent e) @@ -1063,7 +1060,7 @@ public class AlignFrame extends GAlignFrame protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e) { - NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62PID"); + NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62"); } void NewTreePanel(String type, String pwType, String title) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 82d2e3e..7256bed 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -100,6 +100,8 @@ public class AlignViewport if(Preferences.defaultColour!=null) { globalColourScheme = ColourSchemeProperty.getColour(alignment, Preferences.defaultColour); + if(globalColourScheme instanceof UserColourScheme) + globalColourScheme = UserDefinedColours.loadDefaultColours(); if(globalColourScheme!=null) globalColourScheme.setConsensus( vconsensus ); } @@ -479,14 +481,10 @@ public class AlignViewport } public boolean getShowAnnotation() - { - return showAnnotation; - } + { return showAnnotation; } public void setShowAnnotation(boolean b) - { - showAnnotation = b; - } + { showAnnotation = b; } public boolean getScaleAboveWrapped() { return scaleAboveWrapped;} diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index 594baf8..ef28ebe 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -75,12 +75,12 @@ public class Finder extends GFinder public void createNewGroup_actionPerformed(ActionEvent e) { - jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(); + Color [] newColors = new Color[24]; for(int i=0; i<24; i++) newColors[i] = new Color(60,160,115); - ucs.setColourScheme(newColors); + jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(newColors); String searchString = textfield.getText(); searchGroup = new SuperGroup(searchString, ucs , true, true, false); @@ -140,12 +140,12 @@ public class Finder extends GFinder /////////////////////////////////////////////// - jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(); + Color [] newColors = new Color[24]; for(int i=0; i<24; i++) newColors[i] = new Color(60,160,115); - ucs.setColourScheme(newColors); + jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(newColors); searchGroup = new SuperGroup(searchString, ucs , true, true, false); diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index 077a268..a35180b 100755 --- a/src/jalview/gui/UserDefinedColours.java +++ b/src/jalview/gui/UserDefinedColours.java @@ -22,6 +22,7 @@ public class UserDefinedColours extends GUserDefinedColours implements ChangeLis ColourSchemeI oldColourScheme; JInternalFrame frame; + public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg) { super(); @@ -56,7 +57,7 @@ public class UserDefinedColours extends GUserDefinedColours implements ChangeLis if(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR")!=null) { - loadColour(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR")); + loadColours(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR")); } } @@ -109,7 +110,6 @@ public class UserDefinedColours extends GUserDefinedColours implements ChangeLis protected void applyButton_actionPerformed(ActionEvent e) { - Color [] newColours = new Color[24]; for(int i=0; i<24; i++) { @@ -117,16 +117,17 @@ public class UserDefinedColours extends GUserDefinedColours implements ChangeLis newColours[i] = button.getBackground(); } - UserColourScheme ucs = new UserColourScheme(); + UserColourScheme ucs = new UserColourScheme(newColours); ucs.setThreshold(0); - ucs.setColourScheme( newColours ); if(seqGroup!=null) + { seqGroup.cs = ucs; + ap.repaint(); + } else - ap.av.setGlobalColourScheme(ucs); + ap.alignFrame.changeColour(ucs); - ap.repaint(); } protected void loadbutton_actionPerformed(ActionEvent e) @@ -144,51 +145,52 @@ public class UserDefinedColours extends GUserDefinedColours implements ChangeLis { File choice = chooser.getSelectedFile(); jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent()); - loadColour(choice.getAbsolutePath()); + Color[] colors = loadColours(choice.getAbsolutePath()); + for (int i = 0; i < colors.length; i++) + { + JButton button = (JButton) buttonPanel.getComponent(i); + button.setBackground(colors[i]); + } + } + } + public static UserColourScheme loadDefaultColours() + { + if(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR")!=null) + return loadDefaultColours(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR")); + else + return null; } public static UserColourScheme loadDefaultColours(String file) { - UserColourScheme ucs = null; - try - { - BufferedReader in = new BufferedReader(new FileReader(file)); - Color [] newColours = new Color[24]; - for (int i = 0; i < 24; i++) - { - newColours[i] = new Color(Integer.parseInt(in.readLine())); - } - - ucs = new UserColourScheme(); + UserColourScheme ucs = null; + ucs = new UserColourScheme(loadColours(file)); ucs.setThreshold(0); - ucs.setColourScheme(newColours); - - } - catch (Exception ex) - {} - - return ucs; + return ucs; } - void loadColour(String file) + static Color [] loadColours(String file) { + Color [] newColours=null; try { - BufferedReader in = new BufferedReader(new FileReader(file)); + InputStreamReader in = new InputStreamReader( + new FileInputStream(file), "UTF-8"); + + jalview.binding.JalviewUserColours ucs = new jalview.binding.JalviewUserColours(); + ucs = (jalview.binding.JalviewUserColours)ucs.unmarshal(in); + + newColours = new Color[ucs.getColourCount()]; for (int i = 0; i < 24; i++) - { - JButton button = (JButton) buttonPanel.getComponent(i); - Color c = new Color(Integer.parseInt(in.readLine())); - button.setBackground(c); - } + newColours[i] = new Color(Integer.parseInt(ucs.getColour(i).getRGB(), 16)); - jalview.bin.Cache.setProperty("USER_DEFINED_COLOUR", file); } catch (Exception ex) - {} + {ex.printStackTrace();} + return newColours; } protected void savebutton_actionPerformed(ActionEvent e) @@ -207,15 +209,21 @@ public class UserDefinedColours extends GUserDefinedColours implements ChangeLis { String choice = chooser.getSelectedFile().getPath(); jalview.bin.Cache.setProperty("USER_DEFINED_COLOUR", choice); + jalview.binding.JalviewUserColours ucs = new jalview.binding.JalviewUserColours(); try{ - PrintWriter out = new PrintWriter(new FileWriter(choice)); + PrintWriter out = new PrintWriter(new OutputStreamWriter( + new FileOutputStream(choice), "UTF-8")); for(int i=0; i<24; i++) { - JButton button = (JButton)buttonPanel.getComponent(i); - out.println(button.getBackground().getRGB() + ""); + JButton button = (JButton)buttonPanel.getComponent(i); + jalview.binding.Colour col = new jalview.binding.Colour(); + col.setName(button.getText()); + col.setRGB( jalview.util.Format.getHexString( button.getBackground() )); + ucs.addColour(col); } + ucs.marshal(out); out.close(); } catch(Exception ex) @@ -226,7 +234,7 @@ public class UserDefinedColours extends GUserDefinedColours implements ChangeLis protected void cancelButton_actionPerformed(ActionEvent e) { - UserColourScheme ucs = new UserColourScheme(); + Color [] newColours = new Color[24]; for(int i=0; i<24; i++) { @@ -234,7 +242,8 @@ public class UserDefinedColours extends GUserDefinedColours implements ChangeLis buttonPanel.getComponent(i).setBackground(newColours[i]); } - ucs.setColourScheme( newColours ); + UserColourScheme ucs = new UserColourScheme( newColours ); + if (seqGroup != null) seqGroup.cs = ucs; else -- 1.7.10.2