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.cleverphl.gui;
025:
026: import jacareto.cleverphl.CleverPHL;
027: import jacareto.cleverphl.session.Session;
028: import jacareto.cleverphl.session.SessionListEvent;
029: import jacareto.cleverphl.session.SessionListListener;
030: import jacareto.interactionmodel.InteractionModel;
031: import jacareto.system.Language;
032:
033: import java.awt.BorderLayout;
034: import java.awt.event.WindowEvent;
035: import java.awt.event.WindowListener;
036:
037: import java.util.Hashtable;
038:
039: import javax.swing.JCheckBoxMenuItem;
040: import javax.swing.JScrollPane;
041: import javax.swing.JToolBar;
042:
043: /**
044: * The interaction-model frame of CleverPHL.
045: *
046: * @author <a href="mailto:markus.bois@web.de">Markus Bois</a>
047: * @version 1.01
048: */
049: public class InteractionModelFrame extends CleverPHLFrame implements
050: SessionListListener, WindowListener {
051: /** The toolbar. */
052: private JToolBar toolBar;
053:
054: /** The Hashtable of interaction-model trees tree visualizations. */
055: private Hashtable visualizations;
056:
057: /** The interaction-model tree */
058: private InteractionModelTreeVisualization actualVisualization;
059:
060: /**
061: * Creates a new interaction-model frame.
062: *
063: * @param cleverPHL the CleverPHL instance
064: */
065: public InteractionModelFrame(CleverPHL cleverPHL) {
066: super (cleverPHL, "CleverPHL.InteractionModelFrame",
067: "CleverPHL.Menu.ViewInteractionModelWindow");
068:
069: Language language = cleverPHL.getLanguage();
070:
071: visualizations = new Hashtable();
072: actualVisualization = null;
073:
074: setTitle(language
075: .getString("CleverPHL.InteractionModelFrame.Title"));
076: addWindowListener(this );
077:
078: createMenu("CleverPHL.Menu.InteractionModelFrame.MenuBar");
079:
080: //setLocation (850,0);
081: //setLocation (100, 100);
082: //setToPreferredSize (400, 500);
083: // The toolbar
084: toolBar = new JToolBar();
085: createToolBar(toolBar,
086: "CleverPHL.ToolBar.InteractionModelFrame");
087:
088: getContentPane().setLayout(new BorderLayout());
089: getContentPane().add(toolBar, BorderLayout.NORTH);
090:
091: cleverPHL.getSessionList().addSessionListListener(this );
092:
093: setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
094: }
095:
096: /**
097: * Returns the actual interaction-model tree
098: *
099: * @return DOCUMENT ME!
100: */
101: public InteractionModelTreeVisualization getActualVisualization() {
102: return actualVisualization;
103: }
104:
105: /**
106: * Called when the state of the session list has changed.
107: *
108: * @param event DOCUMENT ME!
109: */
110: /**
111: * Invoked when the session list has changed.
112: *
113: * @param event the session list event
114: */
115: public void sessionListChanged(SessionListEvent event) {
116: Session session = event.getSession();
117: InteractionModel interactionModel = session
118: .getInteractionModel();
119: int ID = event.getID();
120:
121: if (ID == SessionListEvent.SESSION_ADDED) {
122: if (!visualizations.containsKey(interactionModel)) {
123: visualizations.put(interactionModel,
124: new InteractionModelTreeVisualization(
125: interactionModel));
126: }
127: } else if (ID == SessionListEvent.SESSION_REMOVED) {
128: if (visualizations.containsKey(interactionModel)) {
129: visualizations.remove(interactionModel);
130: }
131: } else if (ID == SessionListEvent.NEW_ACTUAL_SESSION) {
132: visualize(interactionModel);
133: }
134: }
135:
136: /**
137: * Changes the components visualization
138: *
139: * @param interactionModel the InteractionModel
140: */
141: private void visualize(InteractionModel interactionModel) {
142: if (!visualizations.containsKey(interactionModel)) {
143: visualizations.put(interactionModel,
144: new InteractionModelTreeVisualization(
145: interactionModel));
146: }
147:
148: if (actualVisualization != null) {
149: getContentPane().removeAll();
150: }
151:
152: actualVisualization = (InteractionModelTreeVisualization) visualizations
153: .get(interactionModel);
154: getContentPane().add(new JScrollPane(actualVisualization));
155: validate();
156: repaint();
157: }
158:
159: /**
160: * Does nothing.
161: *
162: * @param w DOCUMENT ME!
163: */
164: public void windowActivated(WindowEvent w) {
165: }
166:
167: /**
168: * Does nothing.
169: *
170: * @param w DOCUMENT ME!
171: */
172: public void windowClosed(WindowEvent w) {
173: }
174:
175: /**
176: * Does nothing.
177: *
178: * @param w DOCUMENT ME!
179: */
180: public void windowDeactivated(WindowEvent w) {
181: }
182:
183: /**
184: * Does nothing.
185: *
186: * @param w DOCUMENT ME!
187: */
188: public void windowDeiconified(WindowEvent w) {
189: }
190:
191: /**
192: * Does nothing.
193: *
194: * @param w DOCUMENT ME!
195: */
196: public void windowIconified(WindowEvent w) {
197: }
198:
199: /**
200: * Does nothing.
201: *
202: * @param w DOCUMENT ME!
203: */
204: public void windowOpened(WindowEvent w) {
205: }
206:
207: /**
208: * Exits the system.
209: *
210: * @param w DOCUMENT ME!
211: */
212: public void windowClosing(WindowEvent w) {
213: close();
214: }
215:
216: /**
217: * Closes the frame.
218: */
219: public void close() {
220: setVisible(false);
221: ((JCheckBoxMenuItem) cleverPHL.getMainFrame()
222: .getCleverPHLMenuBar().getMenuItem(
223: "CleverPHL.Menu.ViewInteractionModelWindow"))
224: .setSelected(false);
225: }
226: }
|