KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > actions > ResetRotationCenterAction


1 /**
2  * <p> Project: com.nightlabs.editor2d </p>
3  * <p> Copyright: Copyright (c) 2004 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 18.04.2005 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.actions;
9
10 import java.util.Iterator JavaDoc;
11 import java.util.Map JavaDoc;
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 JavaDoc ID = ResetRotationCenterAction.class.getName();
29   
30   /**
31    * @param part
32    */

33   public ResetRotationCenterAction(IWorkbenchPart part)
34   {
35     super(part);
36   }
37
38   protected EditorRotateCenterRequest request = new EditorRotateCenterRequest();
39   protected Map JavaDoc dc2RotationCenter;
40   
41   /* (non-Javadoc)
42    * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
43    */

44   protected boolean calculateEnabled()
45   {
46     for (Iterator JavaDoc it = getSelectedObjects().iterator(); it.hasNext(); ) {
47       Object JavaDoc 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 JavaDoc 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 // setImageDescriptor(ImageDescriptor.createFromFile(EditorPlugin.class,"icons/editShape16.gif"));
87
}
88 }
89
Popular Tags