1 package fr.orsay.lri.varna.applications.templateEditor;
3 import java.awt.geom.Point2D;
5 import javax.swing.undo.UndoManager;
6 import javax.swing.undo.UndoableEditSupport;
8 import fr.orsay.lri.varna.applications.templateEditor.GraphicalTemplateElement.RelativePosition;
9 import fr.orsay.lri.varna.models.templates.RNATemplate;
11 public class TemplateEditorPanelUI {
13 private UndoableEditSupport _undoableEditSupport;
14 private TemplatePanel _tp;
15 private Tool selectedTool = Tool.CREATE_HELIX;
20 SELECT, CREATE_HELIX, CREATE_UNPAIRED
23 public TemplateEditorPanelUI(TemplatePanel tp)
26 _undoableEditSupport = new UndoableEditSupport(tp);
29 public Tool getSelectedTool() {
33 public void setSelectedTool(Tool selectedTool) {
34 this.selectedTool = selectedTool;
37 /* Generic undoable event firing for edge movement */
38 public void undoableEdgeMove(GraphicalTemplateElement h, GraphicalTemplateElement.RelativePosition edge,double nx, double ny)
40 _undoableEditSupport.postEdit(new TemplateEdits.ElementEdgeMoveTemplateEdit( h,edge,nx,ny,_tp));
41 h.setEdgePosition(edge, new Point2D.Double(nx,ny));
45 public void setEdge5UI(GraphicalTemplateElement h, double nx, double ny)
46 { undoableEdgeMove(h,GraphicalTemplateElement.RelativePosition.RP_CONNECT_START5, nx,ny); }
47 public void setEdge3UI(UnpairedRegion h, double nx, double ny)
48 { undoableEdgeMove(h,GraphicalTemplateElement.RelativePosition.RP_CONNECT_END3, nx,ny); }
49 public void setEdge5TangentUI(UnpairedRegion h, double nx, double ny)
50 { undoableEdgeMove(h,GraphicalTemplateElement.RelativePosition.RP_EDIT_TANGENT_5, nx,ny); }
51 public void setEdge3TangentUI(UnpairedRegion h, double nx, double ny)
52 { undoableEdgeMove(h,GraphicalTemplateElement.RelativePosition.RP_EDIT_TANGENT_3, nx,ny); }
53 public void moveUnpairedUI(UnpairedRegion u, double nx, double ny)
54 { undoableEdgeMove(u,GraphicalTemplateElement.RelativePosition.RP_INNER_MOVE, nx,ny); }
55 public void moveHelixUI(Helix h, double nx, double ny)
56 { undoableEdgeMove(h,GraphicalTemplateElement.RelativePosition.RP_INNER_MOVE, nx,ny); }
57 public void setHelixPosUI(Helix h, double nx, double ny)
58 { undoableEdgeMove(h,GraphicalTemplateElement.RelativePosition.RP_EDIT_START, nx,ny); }
59 public void setHelixExtentUI(Helix h, double nx, double ny)
60 { undoableEdgeMove(h,GraphicalTemplateElement.RelativePosition.RP_EDIT_END, nx,ny); }
63 public void addElementUI(GraphicalTemplateElement h)
65 _undoableEditSupport.postEdit(new TemplateEdits.ElementAddTemplateEdit( h,_tp));
69 public void removeElementUI(GraphicalTemplateElement h)
71 _undoableEditSupport.postEdit(new TemplateEdits.ElementRemoveTemplateEdit( h,_tp));
76 public void addUndoableEditListener(UndoManager manager)
78 _undoableEditSupport.addUndoableEditListener(manager);
81 public void addConnectionUI(GraphicalTemplateElement h1,
82 GraphicalTemplateElement.RelativePosition e1,
83 GraphicalTemplateElement h2,
84 GraphicalTemplateElement.RelativePosition e2)
86 if (GraphicalTemplateElement.canConnect(h1, e1,h2, e2))
88 Connection c = _tp.addConnection(h1,e1,h2,e2);
89 _undoableEditSupport.postEdit(new TemplateEdits.ElementAttachTemplateEdit(c,_tp));
93 public void removeConnectionUI(Connection c)
95 _undoableEditSupport.postEdit(new TemplateEdits.ElementDetachTemplateEdit(c,_tp));
96 _tp.removeConnection(c);
99 public void flipHelixUI(Helix h)
101 _undoableEditSupport.postEdit(new TemplateEdits.HelixFlipTemplateEdit(h,_tp));
106 public RNATemplate getTemplate()
108 return _tp.getTemplate();