--- /dev/null
+package jalview.gui;\r
+\r
+import javax.swing.JPanel;\r
+import java.awt.event.*;\r
+import java.awt.*;\r
+import java.util.*;\r
+import javax.swing.*;\r
+import jalview.datamodel.*;\r
+\r
+public class SecondaryStructurePanel extends JPanel implements ActionListener\r
+{\r
+ AlignViewport av;\r
+ Vector structures;\r
+\r
+ SecondaryStructure amend;\r
+\r
+ public SecondaryStructurePanel(AlignViewport av)\r
+ {\r
+ this.av = av;\r
+ structures = new Vector();\r
+ setPreferredSize(new Dimension(500,30));\r
+\r
+ addMouseListener(new MouseAdapter()\r
+ {\r
+ public void mousePressed(MouseEvent evt)\r
+ { doMousePressed(evt); }\r
+ public void mouseReleased(MouseEvent evt)\r
+ { doMouseReleased(evt); }\r
+ });\r
+ addMouseMotionListener(new MouseMotionAdapter()\r
+ {\r
+ public void mouseDragged(MouseEvent evt)\r
+ { doMouseDragged(evt); }\r
+ });\r
+ }\r
+\r
+ int startRes = 0;\r
+ int endRes = 0;\r
+ boolean amendStart = false;\r
+ boolean amendEnd = false;\r
+\r
+ public void doMousePressed(MouseEvent evt)\r
+ {\r
+ amend = null;\r
+ amendStart =false;\r
+ amendEnd = false;\r
+\r
+ startRes = evt.getX() / av.getCharWidth() + av.getStartRes();\r
+ for(int i=0; i<structures.size(); i++)\r
+ {\r
+ SecondaryStructure ss = (SecondaryStructure) structures.get(i);\r
+ if(startRes>=ss.start && startRes<=ss.end)\r
+ {\r
+ amend = ss;\r
+ if(startRes==ss.start)\r
+ amendStart = true;\r
+\r
+ if(startRes==ss.end)\r
+ amendEnd = true;\r
+\r
+ if(evt.getClickCount()==2)\r
+ {\r
+ String label = JOptionPane.showInputDialog(this, "Amend label", "Amend label", JOptionPane.QUESTION_MESSAGE );\r
+ if(label==null)\r
+ label = "";\r
+ ss.label = label;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ repaint();\r
+\r
+ }\r
+\r
+ public void doMouseReleased(MouseEvent evt)\r
+ {\r
+ endRes = evt.getX() / av.getCharWidth() + av.getStartRes();\r
+\r
+ if(amend!=null)\r
+ {\r
+ if(amendStart)\r
+ amend.start = endRes;\r
+ if(amendEnd)\r
+ amend.end = endRes;\r
+\r
+ amend=null;\r
+ repaint();\r
+ return;\r
+ }\r
+\r
+ endRes = evt.getX() / av.getCharWidth() + av.getStartRes();\r
+\r
+ JPopupMenu pop = new JPopupMenu("Structure type");\r
+ JMenuItem item = new JMenuItem("Helix");\r
+ item.addActionListener(this);\r
+ pop.add(item);\r
+ item = new JMenuItem("Sheet");\r
+ item.addActionListener(this);\r
+ pop.add(item);\r
+ pop.show(this, evt.getX(), evt.getY());\r
+\r
+ }\r
+\r
+ public void actionPerformed(ActionEvent evt)\r
+ {\r
+\r
+ int type = 0;\r
+ if(evt.getActionCommand().equals("Helix"))\r
+ type = SecondaryStructure.HELIX;\r
+ else if(evt.getActionCommand().equals("Sheet"))\r
+ type = SecondaryStructure.SHEET;\r
+\r
+ String label = JOptionPane.showInputDialog(this, "Enter a label for the structure?", "Enter label", JOptionPane.QUESTION_MESSAGE );\r
+ if(label==null)\r
+ label = "";\r
+\r
+ SecondaryStructure ss = new SecondaryStructure(startRes, endRes, type, label);\r
+ structures.add(ss);\r
+ repaint();\r
+\r
+ }\r
+\r
+ public void doMouseDragged(MouseEvent evt)\r
+ {\r
+ paintNow(getGraphics());\r
+ }\r
+\r
+ void paintNow(Graphics g)\r
+ {\r
+ g.setColor(Color.white);\r
+ g.setFont(new Font("Verdana", Font.PLAIN, 10));\r
+ g.fillRect(0,0,getWidth(),getHeight());\r
+ for(int i=0; i<structures.size(); i++)\r
+ {\r
+ SecondaryStructure ss = (SecondaryStructure)structures.get(i);\r
+\r
+\r
+ if(ss.type==SecondaryStructure.SHEET)\r
+ {\r
+ g.setColor(Color.orange);\r
+ if(ss==amend)\r
+ g.setColor(Color.red);\r
+\r
+ g.fillRect( ( ss.start - av.startRes) * av.charWidth, 4,\r
+ (ss.end - ss.start) * av.charWidth, 7);\r
+\r
+ g.fillPolygon( new int[]{ (ss.end - av.startRes )* av.charWidth,\r
+ ( ss.end - av.startRes )* av.charWidth,\r
+ ( ss.end - av.startRes )* av.charWidth+7},\r
+ new int[]{0,14,7}, 3);\r
+ }\r
+\r
+ if(ss.type==SecondaryStructure.HELIX)\r
+ {\r
+ g.setColor(Color.magenta);\r
+ if(ss==amend)\r
+ g.setColor(Color.red);\r
+ g.fillRoundRect((ss.start -av.startRes)* av.charWidth, 4,\r
+ (ss.end - ss.start) * av.charWidth, 7, 8,8);\r
+ }\r
+\r
+\r
+\r
+ g.setColor(Color.black);\r
+\r
+ int labelWidth = g.getFontMetrics().stringWidth(ss.label);\r
+\r
+ g.drawString( ss.label, (ss.start +(ss.end-ss.start)/2 -av.startRes)*av.charWidth - labelWidth/2, 24);\r
+ }\r
+ }\r
+\r
+ public void paintComponent(Graphics g)\r
+ {\r
+ paintNow(g);\r
+ }\r
+}\r
+\r
+class SecondaryStructure\r
+{\r
+ public static int HELIX = 1;\r
+ public static int SHEET = 2;\r
+ public String label="";\r
+ public int start= 20;\r
+ public int end = 40;\r
+ public int type = HELIX;\r
+\r
+ public SecondaryStructure(int s, int e, int t, String l)\r
+ {\r
+ start = s; end = e; type = t; label = l;\r
+ }\r
+\r
+}\r
+\r
+\r