KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * Project author: Daniel Mazurek <Daniel.Mazurek [at] nightlabs [dot] org> *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin St, Fifth Floor, *
20  * Boston, MA 02110-1301 USA *
21  * *
22  * Or get it online : *
23  * http://www.gnu.org/copyleft/lesser.html *
24  * *
25  * *
26  ******************************************************************************/

27
28 package org.nightlabs.editor2d.actions;
29
30 import java.util.Iterator JavaDoc;
31 import java.util.Map JavaDoc;
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 JavaDoc ID = ResetRotationCenterAction.class.getName();
49   
50   /**
51    * @param part
52    */

53   public ResetRotationCenterAction(IWorkbenchPart part)
54   {
55     super(part);
56   }
57
58   protected EditorRotateCenterRequest request = new EditorRotateCenterRequest();
59   protected Map JavaDoc dc2RotationCenter;
60   
61   /* (non-Javadoc)
62    * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
63    */

64   protected boolean calculateEnabled()
65   {
66     for (Iterator JavaDoc it = getSelectedObjects().iterator(); it.hasNext(); ) {
67       Object JavaDoc 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 JavaDoc 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 // setImageDescriptor(ImageDescriptor.createFromFile(EditorPlugin.class,"icons/editShape16.gif"));
107
}
108 }
109
Popular Tags