KickJava   Java API By Example, From Geeks To Geeks.

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


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#setMaxDepth setMax} method on
41  * a {@link Display}. This action listens to the display model in order to
42  * enable or disable itself when the max depth changes.
43  */

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

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

61
62   private Display display;
63
64   /**
65    * <tt>true</tt> if this action must increase the max depth, or <tt>false</tt>
66    * if it must decrease it.
67    */

68
69   private boolean increase;
70
71   /**
72    * Constructs a new {@link ChangeDepthAction} component.
73    */

74
75   public ChangeDepthAction () {
76     URL JavaDoc url = getClass().getResource(
77       "/org/objectweb/fractal/gui/resources/empty.gif");
78     putValue(SMALL_ICON, new ImageIcon JavaDoc(url));
79   }
80
81   // -------------------------------------------------------------------------
82
// Implementation of the BindingController interface
83
// -------------------------------------------------------------------------
84

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

115   public boolean getIsIncrease () {
116     return increase;
117   }
118
119   public void setIsIncrease (final boolean isIncrease) {
120     increase = isIncrease;
121     if (increase) {
122       putValue(NAME, "Increase depth");
123       putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt I"));
124     } else {
125       putValue(NAME, "Decrease depth");
126       putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt D"));
127     }
128   }
129
130   // -------------------------------------------------------------------------
131
// Implementation of the DisplayListener interface
132
// -------------------------------------------------------------------------
133

134   public void displayedAreaChanged (final Rect oldValue) {
135     // does nothing
136
}
137
138   public void antialiasingChanged () {
139     // does nothing
140
}
141
142   public void maxDepthChanged () {
143     if (!increase) {
144       setEnabled(display.getMaxDepth() > 0);
145     }
146   }
147
148   public void itfNameDisplayModeChanged () {
149     // does nothing
150
}
151
152   // -------------------------------------------------------------------------
153
// Implementation of the ActionListener interface
154
// -------------------------------------------------------------------------
155

156   public void actionPerformed (final ActionEvent JavaDoc e) {
157     if (increase) {
158       display.setMaxDepth(display.getMaxDepth() + 1);
159     } else {
160       display.setMaxDepth(display.getMaxDepth() - 1);
161     }
162   }
163 }
164
Popular Tags