KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > graph > control > AntiAliasAction


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.graph.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.graph.model.DisplayListener;
30 import org.objectweb.fractal.gui.graph.model.Rect;
31 import org.objectweb.fractal.swing.AbstractAction;
32
33 import java.awt.event.ActionEvent JavaDoc;
34 import java.net.URL JavaDoc;
35
36 import javax.swing.ImageIcon JavaDoc;
37 import javax.swing.KeyStroke JavaDoc;
38
39 /**
40  * An action that just calls the {@link Display#setIsAntialiasing
41  * setIsAntiAliasing} method on a {@link Display}. This action listens to the
42  * display model in order to change its name when the anti aliasing option
43  * changes.
44  */

45
46 public class AntiAliasAction extends AbstractAction implements
47   DisplayListener,
48   BindingController
49 {
50
51   /**
52    * A mandatory client interface bound to a {@link Display display} model. This
53    * is the display whose anti aliasing option is modified by this controller
54    * component.
55    */

56
57   public final static String JavaDoc DISPLAY_BINDING = "display";
58
59   /**
60    * The display client interface.
61    */

62
63   private Display display;
64
65   /**
66    * Constructs a new {@link AntiAliasAction} component.
67    */

68
69   public AntiAliasAction () {
70     putValue(NAME, "Antialiasing");
71     URL JavaDoc url = getClass().getResource(
72       "/org/objectweb/fractal/gui/resources/empty.gif");
73     putValue(SMALL_ICON, new ImageIcon JavaDoc(url));
74     putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt L"));
75   }
76
77   // -------------------------------------------------------------------------
78
// Implementation of the BindingController interface
79
// -------------------------------------------------------------------------
80

81   public String JavaDoc[] listFc () {
82     return new String JavaDoc[] { DISPLAY_BINDING };
83   }
84
85   public Object JavaDoc lookupFc (final String JavaDoc clientItfName) {
86     if (DISPLAY_BINDING.equals(clientItfName)) {
87       return display;
88     }
89     return null;
90   }
91
92   public void bindFc (
93     final String JavaDoc clientItfName,
94     final Object JavaDoc serverItf)
95   {
96     if (DISPLAY_BINDING.equals(clientItfName)) {
97       display = (Display)serverItf;
98     }
99   }
100
101   public void unbindFc (final String JavaDoc clientItfName) {
102     if (DISPLAY_BINDING.equals(clientItfName)) {
103       display = null;
104     }
105   }
106
107   // -------------------------------------------------------------------------
108
// Implementation of the DisplayListener interface
109
// -------------------------------------------------------------------------
110

111   public void displayedAreaChanged (final Rect oldValue) {
112     // does nothing
113
}
114
115   public void antialiasingChanged () {
116     if (display.isAntialiasing()) {
117       putValue(NAME, "Aliasing");
118     } else {
119       putValue(NAME, "Antialiasing");
120     }
121   }
122
123   public void maxDepthChanged () {
124     // does nothing
125
}
126
127   public void itfNameDisplayModeChanged () {
128     // does nothing
129
}
130
131   // -------------------------------------------------------------------------
132
// Overriden JCheckBoxMenuItem methods
133
// -------------------------------------------------------------------------
134

135   public void actionPerformed (final ActionEvent JavaDoc e) {
136     display.setIsAntialiasing(!display.isAntialiasing());
137   }
138 }
139
Popular Tags