001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.comp.manipulation;
025:
026: import jacareto.comp.Components;
027: import jacareto.comp.glasspanes.DrawingPane;
028: import jacareto.comp.glasspanes.GlassPaneCompound;
029: import jacareto.comp.glasspanes.GlassPaneManager;
030: import jacareto.system.Environment;
031: import jacareto.system.EnvironmentMember;
032:
033: import java.awt.Component;
034: import java.awt.Window;
035:
036: import java.util.Iterator;
037: import java.util.Set;
038: import java.util.Vector;
039:
040: import javax.swing.JDialog;
041: import javax.swing.JFrame;
042:
043: /**
044: * <p>
045: * This class manages the manipulation modes for components. It can be drawn on windows, components
046: * can be selected and directly manipulated, and so on...
047: * </p>
048: *
049: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
050: * @version 1.01
051: */
052: public class ManipulationManagement extends EnvironmentMember {
053: public static final int USE_COMPONENTS = 0;
054: public static final int SELECT_COMPONENTS = 1;
055: public static final int DRAW_ON_COMPONENTS = 2;
056:
057: /** The actual manipulation mode. */
058: private int mode;
059:
060: /** The components. */
061: private Components components;
062:
063: /** The event listeners. */
064: private Vector listeners;
065:
066: /** The drawing tool component. */
067: private Component drawingToolsComponent;
068:
069: /**
070: * Creates a new instance. The default mode is {@link #USE_COMPONENTS}.
071: *
072: * @param env the environment
073: * @param components the components instance
074: * @param drawingToolsComponent the component which contains the drawing tools
075: */
076: public ManipulationManagement(Environment env,
077: Components components, Component drawingToolsComponent) {
078: super (env);
079: setComponents(components);
080: this .drawingToolsComponent = drawingToolsComponent;
081: listeners = new Vector(5, 5);
082: setMode(USE_COMPONENTS);
083: }
084:
085: /**
086: * Sets the manipulation mode.
087: *
088: * @param mode the new mode
089: */
090: public void setMode(int mode) {
091: if (this .mode == mode) {
092: return;
093: }
094:
095: int oldMode = this .mode;
096: this .mode = mode;
097:
098: //getCleverPHL ().getDrawingFrame ().close ();
099: GlassPaneManager glassPaneManager = components
100: .getGlassPaneManager();
101: glassPaneManager.setVisible(
102: GlassPaneCompound.COMPONENT_SELECTION_PANE,
103: (mode == SELECT_COMPONENTS));
104:
105: GlassPaneCompound[] compounds = glassPaneManager
106: .getGlassPaneCompounds();
107:
108: for (int i = 0; i < compounds.length; i++) {
109: DrawingPane drawingPane = (DrawingPane) compounds[i]
110: .getGlassPane(GlassPaneCompound.DRAWING_PANE);
111: drawingPane
112: .setMode((mode == DRAW_ON_COMPONENTS) ? DrawingPane.DRAW
113: : DrawingPane.SHOW);
114: drawingPane.setVisible(true);
115: }
116:
117: if (mode == DRAW_ON_COMPONENTS) {
118: components.allToFront();
119:
120: // To be replaced by a general mechanism for activating windows
121: Window activeWindow = null;
122: Set includedRoots = components.getIncludedRoots();
123: Iterator it = includedRoots.iterator();
124:
125: while (it.hasNext()) {
126: Object root = it.next();
127:
128: if ((root instanceof JFrame)
129: || (root instanceof JDialog)) {
130: activeWindow = (Window) root;
131:
132: break;
133: }
134: }
135:
136: if (activeWindow != null) {
137: drawingToolsComponent.setVisible(true);
138: activeWindow.toFront();
139: } else {
140: setMode(oldMode);
141:
142: return;
143: }
144: } else {
145: drawingToolsComponent.setVisible(false);
146: }
147:
148: fireManipulationManagementEvent(new ManipulationManagementEvent(
149: this , ManipulationManagementEvent.MODE_CHANGED));
150:
151: // Setting all panes invisible, just for debugging
152:
153: /*glassPaneManager.setVisible (GlassPaneCompound.COMPONENT_SELECTION_PANE, false);
154: glassPaneManager.setVisible (GlassPaneCompound.DRAWING_PANE, false);
155: glassPaneManager.setVisible (GlassPaneCompound.MARK_MODE_PANE, false);
156: glassPaneManager.setVisible (GlassPaneCompound.PSEUDO_MOUSE_PANE, false); */
157: }
158:
159: /**
160: * Returns the manipulation mode.
161: *
162: * @return the actual mode
163: */
164: public int getMode() {
165: return mode;
166: }
167:
168: /**
169: * Sets the glass pane manager.
170: *
171: * @param components the new glass pane manager
172: */
173: public void setComponents(Components components) {
174: this .components = components;
175: }
176:
177: /**
178: * Returns the components.
179: *
180: * @return the components
181: */
182: public Components getComponents() {
183: return components;
184: }
185:
186: /**
187: * Adds a listener
188: *
189: * @param listener the new listener
190: */
191: public void addManipulationManagementListener(
192: ManipulationManagementListener listener) {
193: if (!listeners.contains(listener)) {
194: listeners.add(listener);
195: }
196: }
197:
198: /**
199: * Removes a listener
200: *
201: * @param listener the listener to be removed
202: */
203: public void removeManipulationManagementListener(
204: ManipulationManagementListener listener) {
205: if (listeners.contains(listener)) {
206: listeners.remove(listener);
207: }
208: }
209:
210: /**
211: * Fires an event.
212: *
213: * @param event the event to be fired
214: */
215: protected void fireManipulationManagementEvent(
216: ManipulationManagementEvent event) {
217: Iterator it = listeners.iterator();
218:
219: while (it.hasNext()) {
220: ((ManipulationManagementListener) it.next())
221: .manipulationManagementChanged(event);
222: }
223: }
224: }
|