KickJava   Java API By Example, From Geeks To Geeks.

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


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

26 package org.nightlabs.editor2d.actions;
27
28 import java.awt.geom.AffineTransform JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31
32 import org.eclipse.gef.commands.Command;
33 import org.eclipse.gef.commands.CompoundCommand;
34 import org.nightlabs.editor2d.AbstractEditor;
35 import org.nightlabs.editor2d.DrawComponent;
36 import org.nightlabs.editor2d.EditorPlugin;
37 import org.nightlabs.editor2d.command.CreateDrawComponentCommand;
38
39 /**
40  * <p> Author: Daniel.Mazurek[AT]NightLabs[DOT]de </p>
41  */

42 public class MirrorAction
43 extends AbstractEditorSelectionAction
44 {
45     public static final String JavaDoc ID = MirrorAction.class.getName();
46     
47     /**
48      * @param editor
49      * @param style
50      */

51     public MirrorAction(AbstractEditor editor, int style) {
52         super(editor, style);
53     }
54
55     /**
56      * @param editor
57      */

58     public MirrorAction(AbstractEditor editor) {
59         super(editor);
60     }
61
62   protected void init()
63   {
64     super.init();
65     setText(EditorPlugin.getResourceString("action.mirror.text"));
66     setToolTipText(EditorPlugin.getResourceString("action.mirror.tooltip"));
67     setId(ID);
68   }
69     
70 ///**
71
//*@return true, if objects are selected
72
//*/
73
//protected boolean calculateEnabled() {
74
// return !getSelectedObjects().isEmpty();
75
//}
76

77     /**
78     *@return true, if objects are selected, except the RootEditPart or LayerEditParts
79     */

80     protected boolean calculateEnabled() {
81         return !getDefaultSelection(false).isEmpty();
82     }
83
84     public void run()
85     {
86         List JavaDoc dcs = getSelection(DrawComponent.class, true);
87         Command cmd = new CompoundCommand();
88         for (Iterator JavaDoc it = dcs.iterator(); it.hasNext(); ) {
89             DrawComponent dc = (DrawComponent) it.next();
90             CreateDrawComponentCommand createCmd = new CreateDrawComponentCommand();
91             DrawComponent clone = (DrawComponent) dc.clone();
92             AffineTransform JavaDoc at = new AffineTransform JavaDoc();
93             // TODO: find out how to mirror with an AffineTransform
94
clone.setName(clone.getName() + getCopyString());
95             createCmd.setChild(clone);
96             createCmd.setParent(dc.getParent());
97             
98             cmd.chain(createCmd);
99         }
100         execute(cmd);
101     }
102     
103     protected String JavaDoc getCopyString()
104     {
105         return " ("+EditorPlugin.getResourceString("action.copy.text")+")";
106     }
107 }
108
Popular Tags