+++ /dev/null
-package jalview.gui;\r
-\r
-import jalview.jbgui.GColourKey;\r
-import jalview.schemes.*;\r
-import javax.swing.*;\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-\r
-\r
-public class ColourKey extends GColourKey\r
-{\r
-\r
- Color midBlue = new Color(100,100,255);\r
- public ColourKey(ColourSchemeI current)\r
- {\r
- if(current==null)\r
- zappoMenuItem_actionPerformed(null);\r
-\r
- else if(current instanceof Blosum62ColourScheme)\r
- blosumMenuItem_actionPerformed(null);\r
-\r
- else if(current instanceof BuriedColourScheme)\r
- buriedMenuItem_actionPerformed(null);\r
-\r
-// else if(current instanceof ClustalxColourScheme)\r
- // cl\r
- else if(current instanceof HelixColourScheme)\r
- helixMenuItem_actionPerformed(null);\r
-\r
- else if(current instanceof HydrophobicColourScheme)\r
- hydroMenuItem_actionPerformed(null);\r
-\r
- else if(current instanceof StrandColourScheme)\r
- strandMenuItem_actionPerformed(null);\r
-\r
- else if(current instanceof TaylorColourScheme)\r
- taylorMenuItem_actionPerformed(null);\r
-\r
- else if(current instanceof TurnColourScheme)\r
- turnMenuItem_actionPerformed(null);\r
-\r
- else // default\r
- zappoMenuItem_actionPerformed(null);\r
- }\r
-\r
- void displayKey(String [] residue, String [] description, Color [] colour, String comment)\r
- {\r
- this.getContentPane().removeAll();\r
-\r
- for(int i=0; i<colour.length; i++)\r
- {\r
- JPanel rowPanel = new JPanel();\r
- JLabel residueLabel = new JLabel();\r
- JLabel textLabel = new JLabel();\r
- JPanel colourPanel = new JPanel();\r
- rowPanel.setLayout(new BorderLayout());\r
- residueLabel.setFont(new java.awt.Font("Verdana", Font.BOLD, 12));\r
- residueLabel.setPreferredSize(new Dimension(80, 20));\r
- if(residue!=null)\r
- residueLabel.setText(residue[i]);\r
- residueLabel.setOpaque(false);\r
- residueLabel.setHorizontalAlignment(SwingConstants.CENTER);\r
- residueLabel.setHorizontalTextPosition(SwingConstants.CENTER);\r
- textLabel.setFont(new java.awt.Font("Verdana", 0, 12));\r
- textLabel.setPreferredSize(new Dimension(250,20));\r
- textLabel.setBackground(Color.white);\r
- if(description != null)\r
- textLabel.setText(description[i]);\r
-\r
- colourPanel.setBackground(colour[i]);\r
- colourPanel.setBorder(BorderFactory.createRaisedBevelBorder());\r
- colourPanel.setPreferredSize(new Dimension(80, 20));\r
- colourPanel.setLayout(new BorderLayout());\r
- colourPanel.add(residueLabel, BorderLayout.CENTER);\r
-\r
- rowPanel.add(colourPanel, BorderLayout.CENTER);\r
- if(description!=null)\r
- rowPanel.add(textLabel, BorderLayout.WEST);\r
- this.getContentPane().add(rowPanel);\r
- }\r
-\r
- if(comment!=null)\r
- {\r
- JTextArea ta = new JTextArea(comment);\r
- ta.setLineWrap(true);\r
- ta.setWrapStyleWord(true);\r
- ta.setPreferredSize( new Dimension(this.getWidth()-20, 120) );\r
- this.getContentPane().add(ta);\r
- }\r
- validate();\r
- repaint();\r
- }\r
-\r
-\r
-protected void clustalMenuItem_actionPerformed(ActionEvent e)\r
-{\r
- menu.setText("ClustalX colour scheme");\r
- this.getContentPane().removeAll();\r
- repaint();\r
-}\r
-\r
-protected void zappoMenuItem_actionPerformed(ActionEvent e)\r
-{\r
- menu.setText("Zappo colour scheme");\r
- displayKey(\r
- new String[]{"ILVAM", "FWY", "KRH", "DE", "STNQ", "PG", "C"},\r
- new String[]{"Aliphatic/hydrophobic residues", "Aromatic",\r
- "Positive", "Negative", "Hydrophilic", "conformationally special", "Cysteine"},\r
- new Color[]{ Color.pink, Color.orange, midBlue, Color.red, Color.green, Color.magenta, Color.yellow}\r
- ,null\r
- );\r
-\r
-}\r
-\r
-protected void taylorMenuItem_actionPerformed(ActionEvent e)\r
-{\r
- menu.setText("Taylor colour scheme");\r
- String [] res = new String[]{"A","V","I","L","M","F","Y","W","H","R","K","N","Q","E","D","S","T","G","P","C"};\r
- Color [] col = new Color[res.length];\r
- for (int i=0; i<res.length; i++)\r
- col[i] = ResidueProperties.taylor[ ((Integer)ResidueProperties.aaHash.get(res[i])).intValue() ];\r
-\r
-\r
- displayKey( res, null, col, "These colours were invented by Willie Taylor and an entertaining description of their birth can be found in Protein Engineering, Vol 10 , 743-746 (1997)"\r
- );\r
-}\r
-\r
-protected void hydroMenuItem_actionPerformed(ActionEvent e)\r
-{\r
-\r
- menu.setText("Hydrophobicity colour scheme");\r
- String [] res = new String[]{"I","V","L","F","C","M","A","G","X","T","S","W","Y","P","H","E","Z","Q","D","B","N","K","R"};\r
- Color [] col = new Color[res.length];\r
- HydrophobicColourScheme cs = new HydrophobicColourScheme();\r
- for (int i=0; i<res.length; i++)\r
- col[i] = cs.findColour( res[i], -1, null);\r
-\r
- displayKey( res, null, col, "According to the hydrophobicity table of Kyte, J., and Doolittle, R.F., J. Mol. Biol. 1157, 105-132, 1982. The most hydrophobic residues according to this table are coloured red and the most hydrophilic ones are coloured blue.");\r
-\r
-}\r
-\r
-protected void helixMenuItem_actionPerformed(ActionEvent e)\r
-{\r
- menu.setText("Helix propensity colour scheme");\r
- String[] res = new String[]\r
- {"E","M","A","Z","L","K","F","Q","I","W","V","D","X","H","R","B","T","S","C","Y","N","G","P"};\r
- Color[] col = new Color[res.length];\r
- HelixColourScheme cs = new HelixColourScheme();\r
- for (int i = 0; i < res.length; i++)\r
- col[i] = cs.findColour( res[i], -1, null);\r
-\r
- displayKey(res, null, col, null);\r
-}\r
-\r
-protected void strandMenuItem_actionPerformed(ActionEvent e)\r
-{\r
- menu.setText("Strand propensity colour scheme");\r
- String[] res = new String[]\r
- {"V","I","Y","F","W","L","T","C","Q","M","X","R","N","H","A","S","G","Z","K","B","P","D","E"};\r
-Color[] col = new Color[res.length];\r
-StrandColourScheme cs = new StrandColourScheme();\r
-for (int i = 0; i < res.length; i++)\r
- col[i] = cs.findColour( res[i], -1, null);\r
- displayKey(res, null, col, null);\r
-}\r
-\r
-protected void turnMenuItem_actionPerformed(ActionEvent e)\r
-{\r
- menu.setText("Turn propensity colour scheme");\r
- String[] res = new String[]\r
- {"N","G","P","B","D","S","C","Y","K","X","Q","W","T","R","H","Z","E","A","F","M","L","V","I"};\r
-Color[] col = new Color[res.length];\r
-TurnColourScheme cs = new TurnColourScheme();\r
-for (int i = 0; i < res.length; i++)\r
- col[i] = cs.findColour( res[i], -1, null);\r
-\r
- displayKey(res, null, col, null);\r
-}\r
-\r
-protected void buriedMenuItem_actionPerformed(ActionEvent e)\r
-{\r
- menu.setText("Buried Index colour scheme");\r
- String[] res = new String[]\r
- {"C","I","V","L","F","M","G","A","W","X","S","H","T","P","Y","N","B","D","Q","Z","E","R","K"};\r
-Color[] col = new Color[res.length];\r
-BuriedColourScheme cs = new BuriedColourScheme();\r
-for (int i = 0; i < res.length; i++)\r
- col[i] = cs.findColour( res[i], -1, null);\r
-\r
- displayKey(res, null, col, null);\r
-}\r
-\r
-protected void blosumMenuItem_actionPerformed(ActionEvent e)\r
-{\r
- menu.setText("BLOSUM62 colour scheme");\r
- displayKey( null,\r
- new String[]{"Consensus","+ve Blosum62", " "},\r
- new Color[]{ new Color(154, 154, 255), new Color(204, 204, 255), Color.white },\r
- "Gaps are coloured white. If a residue matchs the consensus sequence residue at that position"\r
- +" it is colored dark blue. If it does not match the consensus residue but the 2 residues have a positive Blosum62 score, it is colored light blue.");\r
-\r
-}\r
-}\r
-\r
-\r
-/*\r
-Blosum62 - Sequence positions which are gaps are colored white. For sequence positions which are non-gaps,\r
-if a residue matchs the consensus sequence residue at that position, it is colored dark blue.\r
-If it does not match the consensus residue but the 2 residues have a positive Blosum62 score, it is colored light blue.\r
-Otherwise, it is colored white.\r
-Percentage Identity - Sequence positions which are gaps are colored white. For sequence positions which are non-gaps,\r
-if the residue at a given position is conserved in less than 40% of the sequences in the alignment, it is colored white.\r
-For residues conserved in greater than 40% of the sequences in the alignment, a shade of blue is assigned depending on\r
-the level of conservation, with darker blues corresponding to residues that are more conserver.\r
-*/\r
-\r
- /*\r
- This depends on the applet having performed a consensus calculation on the alignment. This is done automatically when the applet first starts up but is not done for subsequent alignment windows. If the consensus seuqence is calculated again by selecting 'Consensus' from the Calculate menu then the consensus is calculated for the selected sequences only and all the alignment sequences are coloured according to that consensus. This can be useful to display how similar all the other sequences in the alignment are compared to one (or a few) selected sequences.\r
-The PID option colours the residues (boxes and/or text) according to the percentage of the residues in each column that agree with the consensus sequence. Only the residues that agree with the consensus residue for each column are coloured.\r
-\r
- Percentage agreement Colour\r
-> 80 % Mid blue\r
-> 60 % Light blue\r
-> 40 % Light grey\r
-<= 40% White\r
-*/\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
+++ /dev/null
-package jalview.gui;\r
-\r
-import jalview.datamodel.*;\r
-import jalview.schemes.*;\r
-import java.awt.*;\r
-import java.util.*;\r
-\r
-public class DrawableSequence implements SequenceI {\r
- protected boolean fastDraw = true;\r
- protected Color color = Color.black;\r
-\r
- protected SequenceI sequence;\r
-\r
- ColourSchemeI cs = null;\r
-\r
- public Vector sequenceFeatures = new Vector();\r
- public void setSequenceFeatures(Vector v)\r
- { sequenceFeatures = v; }\r
- public Vector getSequenceFeatures()\r
- {return sequenceFeatures; }\r
-\r
- String pdbId;\r
- public void setPDBId(String id)\r
- { pdbId = id; }\r
- public String getPDBId()\r
- { return pdbId; }\r
-\r
-\r
- public DrawableSequence(SequenceI s) {\r
- this.sequence = s;\r
-\r
- _init();\r
- }\r
-\r
- public DrawableSequence(String name,String seq, int start, int end) {\r
- sequence = new Sequence(name,seq,start,end);\r
-\r
- _init();\r
- }\r
-\r
- private void _init() {\r
-\r
- }\r
-\r
- public void setColourScheme(ColourSchemeI cs) {\r
- this.cs = cs;\r
- }\r
-\r
- public Color getResidueBoxColour(int i) {\r
- Color c = cs.findColour( sequence.getSequence(i,i+1),i,null);\r
- return c;\r
- }\r
-\r
- public void drawSequence(Graphics g,int start, int end, int x1, int y1, int width, int height,boolean showScores, boolean displayBoxes, boolean displayText) {\r
-\r
- if (displayBoxes == true) {\r
- drawBoxes(g,start,end,x1,y1,width, height);\r
- }\r
- if (displayText == true) {\r
- drawText(g,start,end,x1,y1,width,height);\r
- }\r
- }\r
-\r
- public void drawBoxes(Graphics g,int start, int end, int x1, int y1, int width, int height) {\r
- int i = start;\r
- int length = getSequence().length();\r
-\r
- Color currentColor = Color.white;\r
-\r
- int curStart = x1;\r
- int curWidth = width;\r
-\r
- while (i <= end && i < length) {\r
- Color c = getResidueBoxColour(i);\r
-\r
- if (c != currentColor || c != null) {\r
- g.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
-\r
- currentColor = c;\r
- g.setColor(c);\r
-\r
- curStart = i;\r
- curWidth = width;\r
- } else {\r
- curWidth += width;\r
- }\r
-\r
- i++;\r
- }\r
- g.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
- }\r
-\r
- public void drawText(Graphics g, int start, int end, int x1, int y1, int width, int height) {\r
- int pady = 2;\r
- g.setColor(Color.black);\r
-System.out.println("drawablesequence is drawing");\r
- // Need to find the sequence position here.\r
-\r
- if (fastDraw) {\r
- String s;\r
- if (end < getSequence().length()) {\r
- s = getSequence().substring(start,end+1);\r
- } else {\r
- s = getSequence().substring(start);\r
- }\r
- System.out.println(s+" "+x1+" "+y1);\r
- g.drawString(s,x1,y1+height-pady);\r
- } else {\r
-\r
- for (int i=start; i <= end; i++) {\r
- String s = "";\r
-\r
- if (i < end && i < getSequence().length()) {\r
- s = getSequence().substring(i,i+1);\r
- } else {\r
- s = getSequence().substring(i,i+1);\r
- }\r
-\r
-\r
- g.drawString(s,x1+width*(i-start),y1+height-pady);\r
- }\r
-\r
- }\r
- }\r
-\r
-\r
- public int getPosition(int res) {\r
-\r
- return res;\r
- }\r
-\r
- public int getResidue(int pos) {\r
-\r
- return pos;\r
- }\r
-\r
- // SequenceI methods\r
-\r
- public void setName(String name) {\r
- sequence.setName(name);\r
- }\r
- public String getName() {\r
- return sequence.getName();\r
- }\r
- public String getDisplayId() {\r
- return sequence.getDisplayId();\r
- }\r
-\r
- public void setStart(int start) {\r
- sequence.setStart(start);\r
- }\r
- public int getStart() {\r
- return sequence.getStart();\r
- }\r
-\r
- public void setEnd(int end) {\r
- sequence.setEnd(end);\r
- }\r
- public int getEnd() {\r
- return sequence.getEnd();\r
- }\r
-\r
- public int getLength() {\r
- return sequence.getLength();\r
- }\r
-\r
- public void setSequence(String seq) {\r
- sequence.setSequence(seq);\r
- }\r
- public String getSequence() {\r
- return sequence.getSequence();\r
- }\r
- public String getSequence(int start,int end) {\r
- return sequence.getSequence(start,end);\r
- }\r
- public char getCharAt(int i) {\r
- return sequence.getCharAt(i);\r
- }\r
-\r
- public void setDescription(String desc) {\r
- sequence.setDescription(desc);\r
- }\r
- public String getDescription() {\r
- return sequence.getDescription();\r
- }\r
-\r
- public int findIndex(int pos) {\r
- return sequence.findIndex(pos);\r
- }\r
- public int findPosition(int i) {\r
- return sequence.findPosition(i);\r
- }\r
-\r
-\r
- public void deleteCharAt(int i) {\r
- sequence.deleteCharAt(i);\r
- }\r
-\r
- public void deleteChars(int i, int j)\r
- {\r
-\r
- }\r
-\r
- public void insertCharAt(int i,char c) {\r
- sequence.insertCharAt(i,c);\r
-\r
- }\r
-\r
- public void insertCharAt(int i,char c,boolean chop) {\r
- sequence.insertCharAt(i,c,chop);\r
-\r
- }\r
- public Color getColor() {\r
- return this.color;\r
- }\r
-\r
- public void setColor(Color c) {\r
- this.color = c;\r
- }\r
-\r
-}\r
+++ /dev/null
-package jalview.jbgui;
-
-import javax.swing.*;
-import java.awt.event.*;
-import java.awt.*;
-
-public class GColourKey extends JInternalFrame
-{
- JMenuBar jMenuBar1 = new JMenuBar();
- protected JMenu menu = new JMenu();
- JRadioButtonMenuItem clustalMenuItem = new JRadioButtonMenuItem();
- JRadioButtonMenuItem zappoMenuItem = new JRadioButtonMenuItem();
- JRadioButtonMenuItem taylorMenuItem = new JRadioButtonMenuItem();
- JRadioButtonMenuItem hydroMenuItem = new JRadioButtonMenuItem();
- JRadioButtonMenuItem helixMenuItem = new JRadioButtonMenuItem();
- JRadioButtonMenuItem strandMenuItem = new JRadioButtonMenuItem();
- JRadioButtonMenuItem turnMenuItem = new JRadioButtonMenuItem();
- JRadioButtonMenuItem buriedMenuItem = new JRadioButtonMenuItem();
- JRadioButtonMenuItem blosumMenuItem = new JRadioButtonMenuItem();
- FlowLayout flowLayout1 = new FlowLayout();
-
- public GColourKey()
- {
- try
- {
- jbInit();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
-
- this.setJMenuBar( jMenuBar1 );
- ButtonGroup colours = new ButtonGroup();
- colours.add(clustalMenuItem);
- colours.add(zappoMenuItem);
- colours.add(taylorMenuItem);
- colours.add(hydroMenuItem);
- colours.add(helixMenuItem);
- colours.add(strandMenuItem);
- colours.add(turnMenuItem);
- colours.add(buriedMenuItem);
- colours.add(blosumMenuItem);
-
- }
- private void jbInit() throws Exception
- {
- menu.setBackground(new Color(212, 208, 255));
- menu.setActionCommand("Color Scheme");
- menu.setText("Zappo Colour Scheme");
- clustalMenuItem.setBackground(new Color(212, 208, 255));
- clustalMenuItem.setText("ClustalX ");
- clustalMenuItem.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- clustalMenuItem_actionPerformed(e);
- }
- });
- zappoMenuItem.setBackground(new Color(212, 208, 255));
- zappoMenuItem.setSelected(true);
- zappoMenuItem.setText("Zappo");
- zappoMenuItem.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- zappoMenuItem_actionPerformed(e);
- }
- });
- taylorMenuItem.setBackground(new Color(212, 208, 255));
- taylorMenuItem.setText("Taylor");
- taylorMenuItem.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- taylorMenuItem_actionPerformed(e);
- }
- });
- hydroMenuItem.setBackground(new Color(212, 208, 255));
- hydroMenuItem.setText("Hydrophobicity");
- hydroMenuItem.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- hydroMenuItem_actionPerformed(e);
- }
- });
- helixMenuItem.setBackground(new Color(212, 208, 255));
- helixMenuItem.setText("Helix Propensity");
- helixMenuItem.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- helixMenuItem_actionPerformed(e);
- }
- });
- strandMenuItem.setBackground(new Color(212, 208, 255));
- strandMenuItem.setText("Strand Propensity");
- strandMenuItem.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- strandMenuItem_actionPerformed(e);
- }
- });
- turnMenuItem.setBackground(new Color(212, 208, 255));
- turnMenuItem.setText("Turn Propensity");
- turnMenuItem.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- turnMenuItem_actionPerformed(e);
- }
- });
- buriedMenuItem.setBackground(new Color(212, 208, 255));
- buriedMenuItem.setText("Buried Index");
- buriedMenuItem.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- buriedMenuItem_actionPerformed(e);
- }
- });
- blosumMenuItem.setBackground(new Color(212, 208, 255));
- blosumMenuItem.setText("Blosum62");
- blosumMenuItem.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- blosumMenuItem_actionPerformed(e);
- }
- });
- this.getContentPane().setLayout(flowLayout1);
- this.getContentPane().setBackground(new Color(212, 208, 255));
- jMenuBar1.setBackground(new Color(212, 208, 255));
- jMenuBar1.add(menu);
- menu.add(clustalMenuItem);
- menu.add(zappoMenuItem);
- menu.add(taylorMenuItem);
- menu.add(hydroMenuItem);
- menu.add(helixMenuItem);
- menu.add(strandMenuItem);
- menu.add(turnMenuItem);
- menu.add(buriedMenuItem);
- menu.add(blosumMenuItem);
-
- }
-
- protected void clustalMenuItem_actionPerformed(ActionEvent e)
- {
-
- }
-
- protected void zappoMenuItem_actionPerformed(ActionEvent e)
- {
-
- }
-
- protected void taylorMenuItem_actionPerformed(ActionEvent e)
- {
-
- }
-
- protected void hydroMenuItem_actionPerformed(ActionEvent e)
- {
-
- }
-
- protected void helixMenuItem_actionPerformed(ActionEvent e)
- {
-
- }
-
- protected void strandMenuItem_actionPerformed(ActionEvent e)
- {
-
- }
-
- protected void turnMenuItem_actionPerformed(ActionEvent e)
- {
-
- }
-
- protected void buriedMenuItem_actionPerformed(ActionEvent e)
- {
-
- }
-
- protected void blosumMenuItem_actionPerformed(ActionEvent e)
- {
-
- }
-
-
-
-
-
-
-
-
-}
+++ /dev/null
-package jalview.schemes;\r
-\r
-import jalview.gui.DrawableSequence;\r
-\r
-import java.util.*;\r
-import java.awt.*;\r
-\r
-\r
-public class SecondaryColourScheme extends ResidueColourScheme {\r
-\r
- public Color getColor(DrawableSequence seq, int j, Vector aa) {\r
- Color c = Color.white;\r
-\r
- String s = seq.getSequence().substring(j,j+1);\r
-\r
- if (ResidueProperties.ssHash.containsKey(s)) {\r
- c = (Color)ResidueProperties.ssHash.get(s);\r
- } else {\r
- c = Color.white;\r
- }\r
- return c;\r
- }\r
-}\r
-\r
-\r
-\r
-\r
-\r
+++ /dev/null
-package jalview.util;\r
-\r
-import java.io.*;\r
-\r
-public class ErrorLog {\r
- static PrintStream errStream = System.err;\r
- static PrintStream teeFile = null;\r
-\r
- private ErrorLog() {}\r
-\r
- public static void println(String str) {\r
- errStream.println("Error Logger: " + str);\r
- }\r
-\r
- public static void main(String [] argv) {\r
- ErrorLog.println("ERROR");\r
- }\r
-}\r
+++ /dev/null
-/*\r
- * Cay S. Horstmann & Gary Cornell, Core Java\r
- * Published By Sun Microsystems Press/Prentice-Hall\r
- * Copyright (C) 1997 Sun Microsystems Inc.\r
- * All Rights Reserved.\r
- *\r
- * Permission to use, copy, modify, and distribute this \r
- * software and its documentation for NON-COMMERCIAL purposes\r
- * and without fee is hereby granted provided that this \r
- * copyright notice appears in all copies. \r
- * \r
- * THE AUTHORS AND PUBLISHER MAKE NO REPRESENTATIONS OR \r
- * WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER \r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE \r
- * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A \r
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHORS\r
- * AND PUBLISHER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED \r
- * BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING \r
- * THIS SOFTWARE OR ITS DERIVATIVES.\r
- */\r
- \r
-/**\r
- * A class for formatting numbers that follows printf conventions.\r
- * Also implements C-like atoi and atof functions\r
- * @version 1.03 25 Oct 1997\r
- * @author Cay Horstmann\r
- */\r
-\r
-package jalview.util;\r
-\r
-import java.io.*;\r
-\r
-public class Format\r
-\r
-{ /** \r
- * Formats the number following printf conventions.\r
- * Main limitation: Can only handle one format parameter at a time\r
- * Use multiple Format objects to format more than one number\r
- * @param s the format string following printf conventions\r
- * The string has a prefix, a format code and a suffix. The prefix and suffix\r
- * become part of the formatted output. The format code directs the\r
- * formatting of the (single) parameter to be formatted. The code has the\r
- * following structure\r
- * <ul>\r
- * <li> a % (required)\r
- * <li> a modifier (optional)\r
- * <dl>\r
- * <dt> + <dd> forces display of + for positive numbers\r
- * <dt> 0 <dd> show leading zeroes\r
- * <dt> - <dd> align left in the field\r
- * <dt> space <dd> prepend a space in front of positive numbers\r
- * <dt> # <dd> use "alternate" format. Add 0 or 0x for octal or hexadecimal numbers. Don't suppress trailing zeroes in general floating point format.\r
- * </dl>\r
- * <li> an integer denoting field width (optional)\r
- * <li> a period followed by an integer denoting precision (optional)\r
- * <li> a format descriptor (required)\r
- * <dl>\r
- * <dt>f <dd> floating point number in fixed format\r
- * <dt>e, E <dd> floating point number in exponential notation (scientific format). The E format results in an uppercase E for the exponent (1.14130E+003), the e format in a lowercase e.\r
- * <dt>g, G <dd> floating point number in general format (fixed format for small numbers, exponential format for large numbers). Trailing zeroes are suppressed. The G format results in an uppercase E for the exponent (if any), the g format in a lowercase e.\r
- * <dt>d, i <dd> integer in decimal\r
- * <dt>x <dd> integer in hexadecimal\r
- * <dt>o <dd> integer in octal\r
- * <dt>s <dd> string\r
- * <dt>c <dd> character\r
- * </dl>\r
- * </ul>\r
- * @exception IllegalArgumentException if bad format\r
- */\r
-\r
- public Format(String s)\r
- { width = 0;\r
- precision = -1;\r
- pre = "";\r
- post = "";\r
- leading_zeroes = false;\r
- show_plus = false;\r
- alternate = false;\r
- show_space = false;\r
- left_align = false;\r
- fmt = ' '; \r
- \r
- int state = 0; \r
- int length = s.length();\r
- int parse_state = 0; \r
- // 0 = prefix, 1 = flags, 2 = width, 3 = precision,\r
- // 4 = format, 5 = end\r
- int i = 0;\r
- \r
- while (parse_state == 0)\r
- { if (i >= length) parse_state = 5;\r
- else if (s.charAt(i) == '%')\r
- { if (i < length - 1)\r
- { if (s.charAt(i + 1) == '%')\r
- { pre = pre + '%';\r
- i++;\r
- }\r
- else\r
- parse_state = 1;\r
- }\r
- else throw new java.lang.IllegalArgumentException();\r
- }\r
- else\r
- pre = pre + s.charAt(i);\r
- i++;\r
- }\r
- while (parse_state == 1)\r
- { if (i >= length) parse_state = 5;\r
- else if (s.charAt(i) == ' ') show_space = true;\r
- else if (s.charAt(i) == '-') left_align = true; \r
- else if (s.charAt(i) == '+') show_plus = true;\r
- else if (s.charAt(i) == '0') leading_zeroes = true;\r
- else if (s.charAt(i) == '#') alternate = true;\r
- else { parse_state = 2; i--; }\r
- i++;\r
- } \r
- while (parse_state == 2)\r
- { if (i >= length) parse_state = 5;\r
- else if ('0' <= s.charAt(i) && s.charAt(i) <= '9')\r
- { width = width * 10 + s.charAt(i) - '0';\r
- i++;\r
- }\r
- else if (s.charAt(i) == '.')\r
- { parse_state = 3;\r
- precision = 0;\r
- i++;\r
- }\r
- else \r
- parse_state = 4; \r
- }\r
- while (parse_state == 3)\r
- { if (i >= length) parse_state = 5;\r
- else if ('0' <= s.charAt(i) && s.charAt(i) <= '9')\r
- { precision = precision * 10 + s.charAt(i) - '0';\r
- i++;\r
- }\r
- else \r
- parse_state = 4; \r
- }\r
- if (parse_state == 4) \r
- { if (i >= length) parse_state = 5;\r
- else fmt = s.charAt(i);\r
- i++;\r
- }\r
- if (i < length)\r
- post = s.substring(i, length);\r
- } \r
-\r
- /** \r
- * prints a formatted number following printf conventions\r
- * @param s a PrintStream\r
- * @param fmt the format string\r
- * @param x the double to print\r
- */\r
- \r
- public static void print(java.io.PrintStream s, String fmt, double x)\r
- { s.print(new Format(fmt).form(x));\r
- }\r
-\r
- /** \r
- * prints a formatted number following printf conventions\r
- * @param s a PrintStream\r
- * @param fmt the format string\r
- * @param x the long to print\r
- */\r
- public static void print(java.io.PrintStream s, String fmt, long x)\r
- { s.print(new Format(fmt).form(x));\r
- }\r
-\r
- /** \r
- * prints a formatted number following printf conventions\r
- * @param s a PrintStream\r
- * @param fmt the format string\r
- * @param x the character to \r
- */\r
- \r
- public static void print(java.io.PrintStream s, String fmt, char x)\r
- { s.print(new Format(fmt).form(x));\r
- }\r
-\r
- /** \r
- * prints a formatted number following printf conventions\r
- * @param s a PrintStream, fmt the format string\r
- * @param x a string that represents the digits to print\r
- */\r
- \r
- public static void print(java.io.PrintStream s, String fmt, String x)\r
- { s.print(new Format(fmt).form(x));\r
- }\r
- \r
- /** \r
- * Converts a string of digits (decimal, octal or hex) to an integer\r
- * @param s a string\r
- * @return the numeric value of the prefix of s representing a base 10 integer\r
- */\r
- \r
- public static int atoi(String s)\r
- { return (int)atol(s);\r
- } \r
- \r
- /** \r
- * Converts a string of digits (decimal, octal or hex) to a long integer\r
- * @param s a string\r
- * @return the numeric value of the prefix of s representing a base 10 integer\r
- */\r
- \r
- public static long atol(String s)\r
- { int i = 0;\r
-\r
- while (i < s.length() && Character.isWhitespace(s.charAt(i))) i++;\r
- if (i < s.length() && s.charAt(i) == '0')\r
- { if (i + 1 < s.length() && (s.charAt(i + 1) == 'x' || s.charAt(i + 1) == 'X'))\r
- return parseLong(s.substring(i + 2), 16);\r
- else return parseLong(s, 8);\r
- }\r
- else return parseLong(s, 10);\r
- }\r
-\r
- private static long parseLong(String s, int base)\r
- { int i = 0;\r
- int sign = 1;\r
- long r = 0;\r
- \r
- while (i < s.length() && Character.isWhitespace(s.charAt(i))) i++;\r
- if (i < s.length() && s.charAt(i) == '-') { sign = -1; i++; }\r
- else if (i < s.length() && s.charAt(i) == '+') { i++; }\r
- while (i < s.length())\r
- { char ch = s.charAt(i);\r
- if ('0' <= ch && ch < '0' + base)\r
- r = r * base + ch - '0';\r
- else if ('A' <= ch && ch < 'A' + base - 10)\r
- r = r * base + ch - 'A' + 10 ;\r
- else if ('a' <= ch && ch < 'a' + base - 10)\r
- r = r * base + ch - 'a' + 10 ;\r
- else \r
- return r * sign;\r
- i++;\r
- }\r
- return r * sign; \r
- }\r
- \r
- /** \r
- * Converts a string of digits to an double\r
- * @param s a string\r
- */\r
- \r
- public static double atof(String s)\r
- { int i = 0;\r
- int sign = 1;\r
- double r = 0; // integer part\r
- double f = 0; // fractional part\r
- double p = 1; // exponent of fractional part\r
- int state = 0; // 0 = int part, 1 = frac part\r
- \r
- while (i < s.length() && Character.isWhitespace(s.charAt(i))) i++;\r
- if (i < s.length() && s.charAt(i) == '-') { sign = -1; i++; }\r
- else if (i < s.length() && s.charAt(i) == '+') { i++; }\r
- while (i < s.length())\r
- { char ch = s.charAt(i);\r
- if ('0' <= ch && ch <= '9')\r
- { if (state == 0)\r
- r = r * 10 + ch - '0';\r
- else if (state == 1)\r
- { p = p / 10;\r
- r = r + p * (ch - '0');\r
- }\r
- }\r
- else if (ch == '.') \r
- { if (state == 0) state = 1; \r
- else return sign * r;\r
- }\r
- else if (ch == 'e' || ch == 'E')\r
- { long e = (int)parseLong(s.substring(i + 1), 10);\r
- return sign * r * Math.pow(10, e);\r
- }\r
- else return sign * r;\r
- i++;\r
- }\r
- return sign * r;\r
- }\r
- \r
- /** \r
- * Formats a double into a string (like sprintf in C)\r
- * @param x the number to format\r
- * @return the formatted string \r
- * @exception IllegalArgumentException if bad argument\r
- */\r
- \r
- public String form(double x)\r
- { String r;\r
- if (precision < 0) precision = 6;\r
- int s = 1;\r
- if (x < 0) { x = -x; s = -1; }\r
- if (fmt == 'f')\r
- r = fixed_format(x);\r
- else if (fmt == 'e' || fmt == 'E' || fmt == 'g' || fmt == 'G')\r
- r = exp_format(x);\r
- else throw new java.lang.IllegalArgumentException();\r
- \r
- return pad(sign(s, r));\r
- }\r
- \r
- /** \r
- * Formats a long integer into a string (like sprintf in C)\r
- * @param x the number to format\r
- * @return the formatted string \r
- */\r
- \r
- public String form(long x)\r
- { String r; \r
- int s = 0;\r
- if (fmt == 'd' || fmt == 'i')\r
- { if (x < 0) \r
- { r = ("" + x).substring(1);\r
- s = -1; \r
- }\r
- else \r
- { r = "" + x; \r
- s = 1;\r
- }\r
- }\r
- else if (fmt == 'o')\r
- r = convert(x, 3, 7, "01234567");\r
- else if (fmt == 'x')\r
- r = convert(x, 4, 15, "0123456789abcdef");\r
- else if (fmt == 'X')\r
- r = convert(x, 4, 15, "0123456789ABCDEF");\r
- else throw new java.lang.IllegalArgumentException();\r
- \r
- return pad(sign(s, r));\r
- }\r
- \r
- /** \r
- * Formats a character into a string (like sprintf in C)\r
- * @param x the value to format\r
- * @return the formatted string \r
- */\r
- \r
- public String form(char c)\r
- { if (fmt != 'c')\r
- throw new java.lang.IllegalArgumentException();\r
-\r
- String r = "" + c;\r
- return pad(r);\r
- }\r
- \r
- /** \r
- * Formats a string into a larger string (like sprintf in C)\r
- * @param x the value to format\r
- * @return the formatted string \r
- */\r
- \r
- public String form(String s)\r
- { if (fmt != 's')\r
- throw new java.lang.IllegalArgumentException();\r
- if (precision >= 0) s = s.substring(0, precision);\r
- return pad(s);\r
- }\r
- \r
- \r
- /**\r
- * a test stub for the format class\r
- */\r
- \r
- public static void main(String[] a)\r
- { double x = 1.23456789012;\r
- double y = 123;\r
- double z = 1.2345e30;\r
- double w = 1.02;\r
- double u = 1.234e-5;\r
- int d = 0xCAFE;\r
- Format.print(System.out, "x = |%f|\n", x);\r
- Format.print(System.out, "u = |%20f|\n", u);\r
- Format.print(System.out, "x = |% .5f|\n", x);\r
- Format.print(System.out, "w = |%20.5f|\n", w);\r
- Format.print(System.out, "x = |%020.5f|\n", x);\r
- Format.print(System.out, "x = |%+20.5f|\n", x);\r
- Format.print(System.out, "x = |%+020.5f|\n", x);\r
- Format.print(System.out, "x = |% 020.5f|\n", x);\r
- Format.print(System.out, "y = |%#+20.5f|\n", y);\r
- Format.print(System.out, "y = |%-+20.5f|\n", y);\r
- Format.print(System.out, "z = |%20.5f|\n", z);\r
- \r
- Format.print(System.out, "x = |%e|\n", x);\r
- Format.print(System.out, "u = |%20e|\n", u);\r
- Format.print(System.out, "x = |% .5e|\n", x);\r
- Format.print(System.out, "w = |%20.5e|\n", w);\r
- Format.print(System.out, "x = |%020.5e|\n", x);\r
- Format.print(System.out, "x = |%+20.5e|\n", x);\r
- Format.print(System.out, "x = |%+020.5e|\n", x);\r
- Format.print(System.out, "x = |% 020.5e|\n", x);\r
- Format.print(System.out, "y = |%#+20.5e|\n", y);\r
- Format.print(System.out, "y = |%-+20.5e|\n", y);\r
- \r
- Format.print(System.out, "x = |%g|\n", x);\r
- Format.print(System.out, "z = |%g|\n", z);\r
- Format.print(System.out, "w = |%g|\n", w);\r
- Format.print(System.out, "u = |%g|\n", u);\r
- Format.print(System.out, "y = |%.2g|\n", y);\r
- Format.print(System.out, "y = |%#.2g|\n", y);\r
-\r
- Format.print(System.out, "d = |%d|\n", d);\r
- Format.print(System.out, "d = |%20d|\n", d); \r
- Format.print(System.out, "d = |%020d|\n", d); \r
- Format.print(System.out, "d = |%+20d|\n", d);\r
- Format.print(System.out, "d = |% 020d|\n", d);\r
- Format.print(System.out, "d = |%-20d|\n", d);\r
- Format.print(System.out, "d = |%20.8d|\n", d);\r
- Format.print(System.out, "d = |%x|\n", d); \r
- Format.print(System.out, "d = |%20X|\n", d); \r
- Format.print(System.out, "d = |%#20x|\n", d);\r
- Format.print(System.out, "d = |%020X|\n", d);\r
- Format.print(System.out, "d = |%20.8x|\n", d);\r
- Format.print(System.out, "d = |%o|\n", d); \r
- Format.print(System.out, "d = |%020o|\n", d); \r
- Format.print(System.out, "d = |%#20o|\n", d);\r
- Format.print(System.out, "d = |%#020o|\n", d);\r
- Format.print(System.out, "d = |%20.12o|\n", d);\r
- \r
- Format.print(System.out, "s = |%-20s|\n", "Hello"); \r
- Format.print(System.out, "s = |%-20c|\n", '!'); \r
-\r
- // regression test to confirm fix of reported bugs\r
-\r
- Format.print(System.out, "|%i|\n", Long.MIN_VALUE);\r
-\r
- Format.print(System.out, "|%6.2e|\n", 0.0);\r
- Format.print(System.out, "|%6.2g|\n", 0.0);\r
-\r
- Format.print(System.out, "|%6.2f|\n", 9.99);\r
- Format.print(System.out, "|%6.2f|\n", 9.999);\r
-\r
- Format.print(System.out, "|%6.0f|\n", 9.999);\r
- }\r
- \r
- private static String repeat(char c, int n)\r
- { if (n <= 0) return "";\r
- StringBuffer s = new StringBuffer(n);\r
- for (int i = 0; i < n; i++) s.append(c);\r
- return s.toString();\r
- }\r
-\r
- private static String convert(long x, int n, int m, String d)\r
- { if (x == 0) return "0";\r
- String r = "";\r
- while (x != 0)\r
- { r = d.charAt((int)(x & m)) + r;\r
- x = x >>> n;\r
- }\r
- return r;\r
- }\r
-\r
- private String pad(String r)\r
- { String p = repeat(' ', width - r.length());\r
- if (left_align) return pre + r + p + post;\r
- else return pre + p + r + post;\r
- }\r
- \r
- private String sign(int s, String r)\r
- { String p = "";\r
- if (s < 0) p = "-"; \r
- else if (s > 0)\r
- { if (show_plus) p = "+";\r
- else if (show_space) p = " ";\r
- }\r
- else\r
- { if (fmt == 'o' && alternate && r.length() > 0 && r.charAt(0) != '0') p = "0";\r
- else if (fmt == 'x' && alternate) p = "0x";\r
- else if (fmt == 'X' && alternate) p = "0X";\r
- }\r
- int w = 0;\r
- if (leading_zeroes) \r
- w = width;\r
- else if ((fmt == 'd' || fmt == 'i' || fmt == 'x' || fmt == 'X' || fmt == 'o') \r
- && precision > 0) w = precision;\r
- \r
- return p + repeat('0', w - p.length() - r.length()) + r;\r
- }\r
- \r
- private String fixed_format(double d)\r
- { boolean removeTrailing\r
- = (fmt == 'G' || fmt == 'g') && !alternate;\r
- // remove trailing zeroes and decimal point\r
-\r
- if (d > 0x7FFFFFFFFFFFFFFFL) return exp_format(d);\r
- if (precision == 0) \r
- return (long)(d + 0.5) + (removeTrailing ? "" : ".");\r
-\r
- long whole = (long)d;\r
- double fr = d - whole; // fractional part\r
- if (fr >= 1 || fr < 0) return exp_format(d);\r
-\r
- double factor = 1;\r
- String leading_zeroes = "";\r
- for (int i = 1; i <= precision && factor <= 0x7FFFFFFFFFFFFFFFL; i++) \r
- { factor *= 10; \r
- leading_zeroes = leading_zeroes + "0"; \r
- }\r
- long l = (long) (factor * fr + 0.5);\r
- if (l >= factor) { l = 0; whole++; } // CSH 10-25-97\r
- \r
- String z = leading_zeroes + l;\r
- z = "." + z.substring(z.length() - precision, z.length());\r
-\r
- if (removeTrailing)\r
- { int t = z.length() - 1;\r
- while (t >= 0 && z.charAt(t) == '0') t--;\r
- if (t >= 0 && z.charAt(t) == '.') t--;\r
- z = z.substring(0, t + 1);\r
- }\r
-\r
- return whole + z;\r
- }\r
-\r
- private String exp_format(double d)\r
- { String f = "";\r
- int e = 0;\r
- double dd = d;\r
- double factor = 1;\r
- if (d != 0)\r
- { while (dd > 10) { e++; factor /= 10; dd = dd / 10; }\r
- while (dd < 1) { e--; factor *= 10; dd = dd * 10; }\r
- }\r
- if ((fmt == 'g' || fmt == 'G') && e >= -4 && e < precision) \r
- return fixed_format(d);\r
- \r
- d = d * factor;\r
- f = f + fixed_format(d);\r
- \r
- if (fmt == 'e' || fmt == 'g')\r
- f = f + "e";\r
- else\r
- f = f + "E";\r
-\r
- String p = "000"; \r
- if (e >= 0) \r
- { f = f + "+";\r
- p = p + e;\r
- }\r
- else\r
- { f = f + "-";\r
- p = p + (-e);\r
- }\r
- \r
- return f + p.substring(p.length() - 3, p.length());\r
- }\r
- \r
- private int width;\r
- private int precision;\r
- private String pre;\r
- private String post;\r
- private boolean leading_zeroes;\r
- private boolean show_plus;\r
- private boolean alternate;\r
- private boolean show_space;\r
- private boolean left_align;\r
- private char fmt; // one of cdeEfgGiosxXos\r
-}\r
-\r
-\r
-\r
-\r
-\r
+++ /dev/null
-package jalview.util;\r
-\r
-import java.util.*;\r
-\r
-public class ListenList {\r
- protected Vector listeners;\r
- public ListenList() {\r
- listeners = new Vector();\r
- }\r
-\r
- public void addListener(EventListener l) {\r
- if (l == null) {\r
- return;\r
- }\r
- if (!listeners.contains(l)) {\r
- listeners.addElement(l);\r
- }\r
- }\r
-\r
- public void removeListener(EventListener l) {\r
- if (l == null) {\r
- return;\r
- }\r
- if (listeners.contains(l)) {\r
- listeners.removeElement(l);\r
- }\r
- }\r
-}\r
+++ /dev/null
-package jalview.util;\r
-\r
-import java.awt.*;\r
-import java.lang.reflect.*;\r
-\r
-public class WindowUtil {\r
-\r
- public static Window getWindowAncestor(Component c) {\r
- for(Container p = c.getParent(); p != null; p = p.getParent()) {\r
- if (p instanceof Window) {\r
- return (Window)p;\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- public static void removeComponents(Container cont) {\r
- Component[] components = cont.getComponents();\r
- Component comp;\r
- \r
- for (int i = 0; i < components.length; i++) {\r
- comp = components[i];\r
- if (comp != null) {\r
- cont.remove(comp);\r
- if (comp instanceof Container)\r
- removeComponents((Container) comp);\r
- }\r
- }\r
- }\r
- public static void invalidateComponents(Container cont) {\r
- Component[] components = cont.getComponents();\r
- Component comp;\r
- \r
- cont.invalidate();\r
- for (int i = 0; i < components.length; i++) {\r
- comp = components[i];\r
- if (comp != null) {\r
- if (comp instanceof Container)\r
- invalidateComponents((Container) comp);\r
- else \r
- comp.invalidate();\r
- }\r
- }\r
- }\r
-}\r