From: amwaterhouse Date: Mon, 17 Jan 2005 14:15:30 +0000 (+0000) Subject: New class X-Git-Tag: Release_2_0~757 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e1012ab0fcd9e420b2d619d853917d8ec481aa80;p=jalview.git New class --- diff --git a/src/jalview/gui/SecondaryStructurePanel.java b/src/jalview/gui/SecondaryStructurePanel.java new file mode 100755 index 0000000..1c8bd36 --- /dev/null +++ b/src/jalview/gui/SecondaryStructurePanel.java @@ -0,0 +1,194 @@ +package jalview.gui; + +import javax.swing.JPanel; +import java.awt.event.*; +import java.awt.*; +import java.util.*; +import javax.swing.*; +import jalview.datamodel.*; + +public class SecondaryStructurePanel extends JPanel implements ActionListener +{ + AlignViewport av; + Vector structures; + + SecondaryStructure amend; + + public SecondaryStructurePanel(AlignViewport av) + { + this.av = av; + structures = new Vector(); + setPreferredSize(new Dimension(500,30)); + + addMouseListener(new MouseAdapter() + { + public void mousePressed(MouseEvent evt) + { doMousePressed(evt); } + public void mouseReleased(MouseEvent evt) + { doMouseReleased(evt); } + }); + addMouseMotionListener(new MouseMotionAdapter() + { + public void mouseDragged(MouseEvent evt) + { doMouseDragged(evt); } + }); + } + + int startRes = 0; + int endRes = 0; + boolean amendStart = false; + boolean amendEnd = false; + + public void doMousePressed(MouseEvent evt) + { + amend = null; + amendStart =false; + amendEnd = false; + + startRes = evt.getX() / av.getCharWidth() + av.getStartRes(); + for(int i=0; i=ss.start && startRes<=ss.end) + { + amend = ss; + if(startRes==ss.start) + amendStart = true; + + if(startRes==ss.end) + amendEnd = true; + + if(evt.getClickCount()==2) + { + String label = JOptionPane.showInputDialog(this, "Amend label", "Amend label", JOptionPane.QUESTION_MESSAGE ); + if(label==null) + label = ""; + ss.label = label; + } + break; + } + } + repaint(); + + } + + public void doMouseReleased(MouseEvent evt) + { + endRes = evt.getX() / av.getCharWidth() + av.getStartRes(); + + if(amend!=null) + { + if(amendStart) + amend.start = endRes; + if(amendEnd) + amend.end = endRes; + + amend=null; + repaint(); + return; + } + + endRes = evt.getX() / av.getCharWidth() + av.getStartRes(); + + JPopupMenu pop = new JPopupMenu("Structure type"); + JMenuItem item = new JMenuItem("Helix"); + item.addActionListener(this); + pop.add(item); + item = new JMenuItem("Sheet"); + item.addActionListener(this); + pop.add(item); + pop.show(this, evt.getX(), evt.getY()); + + } + + public void actionPerformed(ActionEvent evt) + { + + int type = 0; + if(evt.getActionCommand().equals("Helix")) + type = SecondaryStructure.HELIX; + else if(evt.getActionCommand().equals("Sheet")) + type = SecondaryStructure.SHEET; + + String label = JOptionPane.showInputDialog(this, "Enter a label for the structure?", "Enter label", JOptionPane.QUESTION_MESSAGE ); + if(label==null) + label = ""; + + SecondaryStructure ss = new SecondaryStructure(startRes, endRes, type, label); + structures.add(ss); + repaint(); + + } + + public void doMouseDragged(MouseEvent evt) + { + paintNow(getGraphics()); + } + + void paintNow(Graphics g) + { + g.setColor(Color.white); + g.setFont(new Font("Verdana", Font.PLAIN, 10)); + g.fillRect(0,0,getWidth(),getHeight()); + for(int i=0; i