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.SessionEvent;
029: import jacareto.cleverphl.session.SessionList;
030: import jacareto.cleverphl.session.SessionListEvent;
031: import jacareto.cleverphl.session.SessionListListener;
032: import jacareto.cleverphl.session.SessionListener;
033: import jacareto.system.Language;
034:
035: import java.awt.event.WindowEvent;
036: import java.awt.event.WindowListener;
037:
038: import java.util.Hashtable;
039:
040: import javax.swing.JCheckBoxMenuItem;
041:
042: /**
043: * The data set frame of CleverPHL.
044: *
045: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
046: * @version 1.03
047: */
048: public class DataSetFrame extends CleverPHLFrame implements
049: WindowListener, SessionListListener, SessionListener {
050: /** The hashtable which maps sessions to data set panes. */
051: private Hashtable dataSetPanes;
052:
053: /** The actual data set pane. */
054: private DataSetPane actualPane;
055:
056: /**
057: * Creates a new data set frame.
058: *
059: * @param cleverPHL the CleverPHL instance
060: */
061: public DataSetFrame(CleverPHL cleverPHL) {
062: super (cleverPHL, "CleverPHL.DataSetFrame",
063: "CleverPHL.Menu.ViewDataSetWindow");
064:
065: Language language = cleverPHL.getLanguage();
066:
067: setTitle(language.getString("CleverPHL.DataSetFrame.Title"));
068: addWindowListener(this );
069: actualPane = null;
070:
071: createMenu("CleverPHL.Menu.DataSetFrame.MenuBar");
072:
073: //setLocation (100, 100);
074: //setToPreferredSize (400, 400);
075: dataSetPanes = new Hashtable();
076:
077: cleverPHL.getSessionList().addSessionListListener(this );
078: updateMenu(false);
079:
080: setDefaultCloseOperation(HIDE_ON_CLOSE);
081: }
082:
083: /**
084: * Invoked when the session list has changed.
085: *
086: * @param event the session list event
087: */
088: public void sessionListChanged(SessionListEvent event) {
089: int ID = event.getID();
090: Session session = event.getSession();
091:
092: if (ID == SessionListEvent.SESSION_ADDED) {
093: DataSetPane pane = new DataSetPane(cleverPHL, session);
094: dataSetPanes.put(session, pane);
095: session.addSessionListener(this );
096: } else if (ID == SessionListEvent.SESSION_REMOVED) {
097: if (dataSetPanes.containsKey(session)) {
098: dataSetPanes.remove(session);
099:
100: if (dataSetPanes.size() == 0) {
101: actualPane = null;
102: updateMenu(false);
103: }
104:
105: session.removeSessionListener(this );
106: }
107: } else if (ID == SessionListEvent.NEW_ACTUAL_SESSION) {
108: if (dataSetPanes.containsKey(session)) {
109: getContentPane().removeAll();
110: actualPane = (DataSetPane) dataSetPanes.get(session);
111: getContentPane().add(actualPane);
112: updateMenu(actualPane.getTabCount() > 0);
113: validate();
114: repaint();
115: }
116: }
117: }
118:
119: /**
120: * Invoked when the session state changed.
121: *
122: * @param event the session event
123: */
124: public void sessionStateChanged(SessionEvent event) {
125: SessionList sessionList = cleverPHL.getSessionList();
126: Session session = event.getSession();
127: int ID = event.getID();
128:
129: if (session == sessionList.getActual()) {
130: if (ID == SessionEvent.REPLAY_RESET) {
131: updateMenu(actualPane.getTabCount() > 0);
132: }
133: }
134: }
135:
136: /**
137: * Returns the actual data set pane.
138: *
139: * @return DOCUMENT ME!
140: */
141: public DataSetPane getActualPane() {
142: return actualPane;
143: }
144:
145: /**
146: * Updates the menu, belonging on whether a data set is shown or not.
147: *
148: * @param isDataSetShown DOCUMENT ME!
149: */
150: public void updateMenu(boolean isDataSetShown) {
151: getCleverPHLMenuBar().setMenuItemEnabled(
152: "CleverPHL.Menu.SaveDataSet", isDataSetShown);
153: getCleverPHLMenuBar().setMenuItemEnabled(
154: "CleverPHL.Menu.SaveDataSetCSV", isDataSetShown);
155: getCleverPHLMenuBar().setMenuItemEnabled(
156: "CleverPHL.Menu.CloseDataSet", isDataSetShown);
157: getCleverPHLMenuBar().setMenuItemEnabled(
158: "CleverPHL.Menu.EditDataSet", isDataSetShown);
159: }
160:
161: /**
162: * Does nothing.
163: *
164: * @param w DOCUMENT ME!
165: */
166: public void windowActivated(WindowEvent w) {
167: }
168:
169: /**
170: * Does nothing.
171: *
172: * @param w DOCUMENT ME!
173: */
174: public void windowClosed(WindowEvent w) {
175: }
176:
177: /**
178: * Does nothing.
179: *
180: * @param w DOCUMENT ME!
181: */
182: public void windowDeactivated(WindowEvent w) {
183: }
184:
185: /**
186: * Does nothing.
187: *
188: * @param w DOCUMENT ME!
189: */
190: public void windowDeiconified(WindowEvent w) {
191: }
192:
193: /**
194: * Does nothing.
195: *
196: * @param w DOCUMENT ME!
197: */
198: public void windowIconified(WindowEvent w) {
199: }
200:
201: /**
202: * Does nothing.
203: *
204: * @param w DOCUMENT ME!
205: */
206: public void windowOpened(WindowEvent w) {
207: }
208:
209: /**
210: * Exits the system.
211: *
212: * @param w DOCUMENT ME!
213: */
214: public void windowClosing(WindowEvent w) {
215: close();
216: }
217:
218: /**
219: * Closes the frame.
220: */
221: public void close() {
222: setVisible(false);
223: ((JCheckBoxMenuItem) cleverPHL.getMainFrame()
224: .getCleverPHLMenuBar().getMenuItem(
225: "CleverPHL.Menu.ViewDataSetWindow"))
226: .setSelected(false);
227: }
228: }
|