KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > menu > control > ExportSVGAction


1 /***
2  * FractalGUI: a graphical tool to edit Fractal component configurations.
3  * Copyright (C) 2003 France Telecom R&D
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 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 Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: fractal@objectweb.org
20  *
21  * Authors: Eric Bruneton, Patrice Fauvel
22  */

23
24 package org.objectweb.fractal.gui.menu.control;
25
26 import org.objectweb.fractal.api.control.BindingController;
27
28 import org.objectweb.fractal.gui.graph.model.Display;
29 import org.objectweb.fractal.gui.model.Component;
30 import org.objectweb.fractal.gui.model.Configuration;
31 import org.objectweb.fractal.gui.graph.view.Printer;
32 import org.objectweb.fractal.gui.selection.model.Selection;
33 import org.objectweb.fractal.swing.AbstractAction;
34
35 import java.awt.event.ActionEvent JavaDoc;
36 import java.net.URL JavaDoc;
37
38 import javax.swing.ImageIcon JavaDoc;
39 import javax.swing.KeyStroke JavaDoc;
40
41 /**
42  * An action to export a configuration view to an SVG file.
43  */

44
45 public class ExportSVGAction extends AbstractAction implements
46   BindingController
47 {
48
49   public final static String JavaDoc CONFIGURATION_BINDING = "configuration";
50
51   public final static String JavaDoc SELECTION_BINDING = "selection";
52
53   public final static String JavaDoc DISPLAY_BINDING = "display";
54
55   public final static String JavaDoc PRINT_BINDING = "print";
56
57   private Configuration configuration;
58
59   private Selection selection;
60
61   private Display display;
62
63   private Printer printer;
64
65   /**
66    * Constructs a new {@link PrintAction} component.
67    */

68
69   public ExportSVGAction () {
70     putValue(NAME, "ExportSVG");
71     putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control 2"));
72     putValue(SHORT_DESCRIPTION, "Export to SVG");
73     URL JavaDoc url = getClass().getResource(
74       "/org/objectweb/fractal/gui/resources/export.gif");
75     putValue(SMALL_ICON, new ImageIcon JavaDoc(url));
76     setEnabled(true);
77   }
78
79   // -------------------------------------------------------------------------
80
// Implementation of the BindingController interface
81
// -------------------------------------------------------------------------
82

83   public String JavaDoc[] listFc () {
84     return new String JavaDoc[] {
85       CONFIGURATION_BINDING,
86       SELECTION_BINDING,
87       DISPLAY_BINDING,
88       PRINT_BINDING
89     };
90   }
91
92   public Object JavaDoc lookupFc (final String JavaDoc clientItfName) {
93     if (CONFIGURATION_BINDING.equals(clientItfName)) {
94       return configuration;
95     } else if (SELECTION_BINDING.equals(clientItfName)) {
96       return selection;
97     } else if (DISPLAY_BINDING.equals(clientItfName)) {
98       return display;
99     } else if (PRINT_BINDING.equals(clientItfName)) {
100       return printer;
101     }
102     return null;
103   }
104
105   public void bindFc (final String JavaDoc clientItfName, final Object JavaDoc serverItf) {
106     if (CONFIGURATION_BINDING.equals(clientItfName)) {
107       configuration = (Configuration)serverItf;
108     } else if (SELECTION_BINDING.equals(clientItfName)) {
109       selection = (Selection)serverItf;
110     } else if (DISPLAY_BINDING.equals(clientItfName)) {
111       display = (Display)serverItf;
112     } else if (PRINT_BINDING.equals(clientItfName)) {
113       printer = (Printer)serverItf;
114     }
115   }
116
117   public void unbindFc (final String JavaDoc clientItfName) {
118     if (CONFIGURATION_BINDING.equals(clientItfName)) {
119       configuration = null;
120     } else if (SELECTION_BINDING.equals(clientItfName)) {
121       selection = null;
122     } else if (DISPLAY_BINDING.equals(clientItfName)) {
123       display = null;
124     } else if (PRINT_BINDING.equals(clientItfName)) {
125       printer = null;
126     }
127   }
128
129   // -------------------------------------------------------------------------
130
// Implementation of the ActionListener interface
131
// -------------------------------------------------------------------------
132

133   public void actionPerformed (final ActionEvent JavaDoc e) {
134     Object JavaDoc o = selection.getSelection();
135     if (o instanceof Component) {
136       Component c = (Component)o;
137       printer.setType(Printer.TYPE_EXPORT);
138       printer.print(true, c);
139     }
140   }
141 }
142
Popular Tags