1 27 28 package org.nightlabs.editor2d.actions; 29 30 import java.util.Iterator ; 31 import java.util.Map ; 32 33 import org.eclipse.gef.EditPart; 34 import org.eclipse.gef.ui.actions.SelectionAction; 35 import org.eclipse.ui.IWorkbenchPart; 36 37 import org.nightlabs.editor2d.DrawComponent; 38 import org.nightlabs.editor2d.EditorPlugin; 39 import org.nightlabs.editor2d.edit.AbstractDrawComponentEditPart; 40 import org.nightlabs.editor2d.request.EditorRequestConstants; 41 import org.nightlabs.editor2d.request.EditorRotateCenterRequest; 42 43 44 public class ResetRotationCenterAction 45 extends SelectionAction 46 implements EditorRequestConstants 47 { 48 public static final String ID = ResetRotationCenterAction.class.getName(); 49 50 53 public ResetRotationCenterAction(IWorkbenchPart part) 54 { 55 super(part); 56 } 57 58 protected EditorRotateCenterRequest request = new EditorRotateCenterRequest(); 59 protected Map dc2RotationCenter; 60 61 64 protected boolean calculateEnabled() 65 { 66 for (Iterator it = getSelectedObjects().iterator(); it.hasNext(); ) { 67 Object o = it.next(); 68 if (o instanceof EditPart) { 69 EditPart editPart = (EditPart) o; 70 if (editPart instanceof AbstractDrawComponentEditPart) { 71 DrawComponent dc = ((AbstractDrawComponentEditPart) editPart).getDrawComponent(); 72 if (dc.getRotationX() != DrawComponent.ROTATION_X_DEFAULT || 73 dc.getRotationX() != DrawComponent.ROTATION_Y_DEFAULT) 74 { 75 return true; 76 } 77 } 78 } 79 } 80 return false; 81 } 82 83 public void run() 84 { 85 for (Iterator it = getSelectedObjects().iterator(); it.hasNext(); ) 86 { 87 EditPart editPart = (EditPart) it.next(); 88 if (editPart instanceof AbstractDrawComponentEditPart) { 89 DrawComponent dc = ((AbstractDrawComponentEditPart) editPart).getDrawComponent(); 90 if (dc.getRotationX() != DrawComponent.ROTATION_X_DEFAULT || 91 dc.getRotationX() != DrawComponent.ROTATION_Y_DEFAULT) 92 { 93 dc.setRotationX(DrawComponent.ROTATION_X_DEFAULT); 94 dc.setRotationY(DrawComponent.ROTATION_Y_DEFAULT); 95 } 96 } 97 } 98 } 99 100 protected void init() 101 { 102 super.init(); 103 setText(EditorPlugin.getResourceString("action.resetrotationcenter.label")); 104 setToolTipText(EditorPlugin.getResourceString("action.resetrotationcenter.tooltip")); 105 setId(ID); 106 } 108 } 109 | Popular Tags |