1 8 package com.nightlabs.editor2d.actions; 9 10 import java.util.Iterator ; 11 import java.util.Map ; 12 13 import org.eclipse.gef.EditPart; 14 import org.eclipse.gef.ui.actions.SelectionAction; 15 import org.eclipse.ui.IWorkbenchPart; 16 17 import com.nightlabs.editor2d.DrawComponent; 18 import com.nightlabs.editor2d.EditorPlugin; 19 import com.nightlabs.editor2d.edit.AbstractDrawComponentEditPart; 20 import com.nightlabs.editor2d.request.EditorRequestConstants; 21 import com.nightlabs.editor2d.request.EditorRotateCenterRequest; 22 23 24 public class ResetRotationCenterAction 25 extends SelectionAction 26 implements EditorRequestConstants 27 { 28 public static final String ID = ResetRotationCenterAction.class.getName(); 29 30 33 public ResetRotationCenterAction(IWorkbenchPart part) 34 { 35 super(part); 36 } 37 38 protected EditorRotateCenterRequest request = new EditorRotateCenterRequest(); 39 protected Map dc2RotationCenter; 40 41 44 protected boolean calculateEnabled() 45 { 46 for (Iterator it = getSelectedObjects().iterator(); it.hasNext(); ) { 47 Object o = it.next(); 48 if (o instanceof EditPart) { 49 EditPart editPart = (EditPart) o; 50 if (editPart instanceof AbstractDrawComponentEditPart) { 51 DrawComponent dc = ((AbstractDrawComponentEditPart) editPart).getDrawComponent(); 52 if (dc.getRotationX() != DrawComponent.ROTATION_X_DEFAULT || 53 dc.getRotationX() != DrawComponent.ROTATION_Y_DEFAULT) 54 { 55 return true; 56 } 57 } 58 } 59 } 60 return false; 61 } 62 63 public void run() 64 { 65 for (Iterator it = getSelectedObjects().iterator(); it.hasNext(); ) 66 { 67 EditPart editPart = (EditPart) it.next(); 68 if (editPart instanceof AbstractDrawComponentEditPart) { 69 DrawComponent dc = ((AbstractDrawComponentEditPart) editPart).getDrawComponent(); 70 if (dc.getRotationX() != DrawComponent.ROTATION_X_DEFAULT || 71 dc.getRotationX() != DrawComponent.ROTATION_Y_DEFAULT) 72 { 73 dc.setRotationX(DrawComponent.ROTATION_X_DEFAULT); 74 dc.setRotationY(DrawComponent.ROTATION_Y_DEFAULT); 75 } 76 } 77 } 78 } 79 80 protected void init() 81 { 82 super.init(); 83 setText(EditorPlugin.getResourceString("action.resetrotationcenter.label")); 84 setToolTipText(EditorPlugin.getResourceString("action.resetrotationcenter.tooltip")); 85 setId(ID); 86 } 88 } 89 | Popular Tags |