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