X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FUserDefinedColours.java;h=ede020c6101fd71d3c79968e9024763c3adb4123;hb=612a0d5bdd02f8eb03760d9b773609d46504c683;hp=0477391df7a4ba04311a2daabe7b7fb838f254de;hpb=4fe5e959d104419f1f313f493e00d683b6b5cd0a;p=jalview.git diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index 0477391..ede020c 100755 --- a/src/jalview/gui/UserDefinedColours.java +++ b/src/jalview/gui/UserDefinedColours.java @@ -52,6 +52,7 @@ public class UserDefinedColours extends GUserDefinedColours Vector selectedButtons; ColourSchemeI oldColourScheme; JInternalFrame frame; + MCview.PDBCanvas pdbcanvas; /** * Creates a new UserDefinedColours object. @@ -68,7 +69,7 @@ public class UserDefinedColours extends GUserDefinedColours if (System.getProperty("os.name").startsWith("Mac")) { - frame.setSize(450, 560); + frame.setSize(760, 370); } if (sg != null) @@ -106,6 +107,40 @@ public class UserDefinedColours extends GUserDefinedColours makeButton("Gap", "-"); } + public UserDefinedColours(MCview.PDBCanvas pdb, ColourSchemeI oldcs) + { + super(); + frame = new JInternalFrame(); + frame.setContentPane(this); + Desktop.addInternalFrame(frame, "User Defined Colours", 720, 370, true); + pdbcanvas = pdb; + + if (System.getProperty("os.name").startsWith("Mac")) + { + frame.setSize(760, 370); + } + + colorChooser.getSelectionModel().addChangeListener(this); + + oldColourScheme = oldcs; + + if (oldColourScheme instanceof UserColourScheme) + { + schemeName.setText( ( (UserColourScheme) oldColourScheme).getName()); + } + for (int i = 0; i < 20; i++) + { + makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) + + "", ResidueProperties.aa[i]); + } + + makeButton("B", "B"); + makeButton("Z", "Z"); + makeButton("X", "X"); + makeButton("Gap", "-"); + } + + /** * DOCUMENT ME! * @@ -139,8 +174,12 @@ public class UserDefinedColours extends GUserDefinedColours if(e.isShiftDown()) { - JButton start = (JButton)selectedButtons.elementAt(selectedButtons.size()-1); - JButton end = (JButton) e.getSource(); + JButton start, end = (JButton) e.getSource(); + if(selectedButtons.size()>0) + start = (JButton)selectedButtons.elementAt(selectedButtons.size()-1); + else + start = (JButton) e.getSource(); + int startIndex=0, endIndex=0; for(int b=0; b-1) colours = colours.substring(0, colours.indexOf("|")); - return loadColours(colours); + ret = loadColours(colours); } - else + + if(ret == null) { - return null; + Color[] newColours = new Color[24]; + for (int i = 0; i < 24; i++) + { + newColours[i] = Color.white; + } + ret = new UserColourScheme(newColours); } + + return ret; } /** @@ -357,7 +413,7 @@ public class UserDefinedColours extends GUserDefinedColours * * @return DOCUMENT ME! */ - public static UserColourScheme loadColours(String file) + static UserColourScheme loadColours(String file) { UserColourScheme ucs = null; Color[] newColours = null; @@ -367,10 +423,14 @@ public class UserDefinedColours extends GUserDefinedColours InputStreamReader in = new InputStreamReader(new FileInputStream( file), "UTF-8"); - jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours(); - jucs = (jalview.binding.JalviewUserColours) jucs.unmarshal(in); + 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[jucs.getColourCount()]; + newColours = new Color[jucs.getColourCount()]; for (int i = 0; i < 24; i++) { @@ -386,10 +446,35 @@ public class UserDefinedColours extends GUserDefinedColours } catch (Exception ex) { - System.out.println("Error loading User ColourFile\n"+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 = (jalview.binding.JalviewUserColours) 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; } @@ -435,7 +520,7 @@ public class UserDefinedColours extends GUserDefinedColours String defaultColours = jalview.bin.Cache.getDefault("USER_DEFINED_COLOURS", choice); if(defaultColours.indexOf(choice)==-1) { - if(defaultColours.length()<1) + if(defaultColours.length()>0) defaultColours = defaultColours.concat("|"); defaultColours = defaultColours.concat(choice); } @@ -480,16 +565,23 @@ public class UserDefinedColours extends GUserDefinedColours */ protected void cancelButton_actionPerformed(ActionEvent e) { + if (ap != null) + { if (seqGroup != null) { - seqGroup.cs = oldColourScheme; + seqGroup.cs = oldColourScheme; } - else + else if (ap != null) { - ap.av.setGlobalColourScheme(oldColourScheme); + ap.av.setGlobalColourScheme(oldColourScheme); } - ap.repaint(); + } + + if(pdbcanvas!=null) + { + pdbcanvas.pdb.setColours(oldColourScheme); + } try { @@ -512,9 +604,10 @@ public class UserDefinedColours extends GUserDefinedColours { userColourSchemes = new Hashtable(); - if(files==null) + 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(); @@ -540,7 +633,50 @@ public class UserDefinedColours extends GUserDefinedColours } if (!files.equals(coloursFound.toString())) { - jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", 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"); + } }