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 org.apache.log4j.Logger;
036:
037: import javax.swing.JTabbedPane;
038: import javax.swing.event.ChangeEvent;
039: import javax.swing.event.ChangeListener;
040:
041: /**
042: * The tabbed pane for the sessions.
043: *
044: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
045: * @version 1.02
046: */
047: public class SessionPane extends JTabbedPane implements ChangeListener,
048: SessionListListener, SessionListener {
049: /** The CleverPHL instance. */
050: private CleverPHL cleverPHL;
051:
052: /** Whether this instance should listen to session list events or not. */
053: private boolean listenToSessionList;
054:
055: /** Whether this instance should listen to change events or not. */
056: private boolean listenToChangeEvents;
057:
058: /**
059: * Creates a new session pane.
060: *
061: * @param cleverPHL the CleverPHL instance
062: */
063: public SessionPane(CleverPHL cleverPHL) {
064: super ();
065: this .cleverPHL = cleverPHL;
066: addChangeListener(this );
067: cleverPHL.getSessionList().addSessionListListener(this );
068: listenToSessionList = true;
069: listenToChangeEvents = true;
070: }
071:
072: /**
073: * Invoked when the state of the tabbed pane has changed.
074: *
075: * @param event the change event
076: */
077: public void stateChanged(ChangeEvent event) {
078: if (listenToChangeEvents) {
079: listenToSessionList = false;
080: cleverPHL.getSessionList().setActual(getSelectedIndex());
081: listenToSessionList = true;
082:
083: RecordPanel actualPanel = getActualRecordPanel();
084:
085: if (actualPanel != null) {
086: actualPanel.updateMenuItems();
087: }
088: }
089: }
090:
091: /**
092: * Invoked when the session list has changed.
093: *
094: * @param event the session list event
095: */
096: public void sessionListChanged(SessionListEvent event) {
097: if (listenToSessionList) {
098: Logger logger = cleverPHL.getLogger();
099: Language language = cleverPHL.getLanguage();
100:
101: int ID = event.getID();
102: int index = event.getIndex();
103: Session session = event.getSession();
104:
105: if (ID == SessionListEvent.SESSION_ADDED) {
106: logger.debug("SessionPane.SESSION_ADDED");
107: listenToChangeEvents = false;
108: addTab(session.getName(), new RecordPanel(cleverPHL,
109: session));
110: session.addSessionListener(this );
111: cleverPHL.getMainFrame().repaint();
112: listenToChangeEvents = true;
113: } else if (ID == SessionListEvent.SESSION_REMOVED) {
114: listenToChangeEvents = false;
115: removeTabAt(index);
116: session.removeSessionListener(this );
117: listenToChangeEvents = true;
118: } else if (ID == SessionListEvent.NEW_ACTUAL_SESSION) {
119: logger.debug("SessionPane.NEW_ACTUAL_SESSION");
120: listenToChangeEvents = false;
121: setSelectedIndex(index);
122: logger
123: .debug(language
124: .getString("CleverPHL.SessionPane.Msg.NewSelectedIndex")
125: + " " + index);
126: listenToChangeEvents = true;
127: }
128:
129: RecordPanel actualPanel = getActualRecordPanel();
130:
131: if (actualPanel != null) {
132: actualPanel.updateMenuItems();
133: }
134: }
135: }
136:
137: /**
138: * Invoked when the session state changed.
139: *
140: * @param event the session event
141: */
142: public void sessionStateChanged(SessionEvent event) {
143: SessionList sessionList = cleverPHL.getSessionList();
144: Session session = event.getSession();
145: int ID = event.getID();
146:
147: if (session == sessionList.getActual()) {
148: if ((ID == SessionEvent.CAPTURE_START)
149: || (ID == SessionEvent.REPLAY_START)
150: || (ID == SessionEvent.REPLAY_CONTINUE)) {
151: for (int i = 0; i < getTabCount(); i++) {
152: if (sessionList.get(i) != session) {
153: setEnabledAt(i, false);
154: }
155: }
156: } else if ((ID == SessionEvent.CAPTURE_STOP)
157: || (ID == SessionEvent.REPLAY_STOP)
158: || (ID == SessionEvent.REPLAY_RESET)) {
159: for (int i = 0; i < getTabCount(); i++) {
160: setEnabledAt(i, true);
161: }
162: } else if (ID == SessionEvent.NAME_CHANGED) {
163: setTitleAt(getSelectedIndex(), session.getName());
164: }
165: }
166: }
167:
168: /**
169: * Returns the actual record panel, or <code>null</code> if there is none.
170: *
171: * @return DOCUMENT ME!
172: */
173: public RecordPanel getActualRecordPanel() {
174: if (getSelectedIndex() >= 0) {
175: return (RecordPanel) getComponentAt(getSelectedIndex());
176: } else {
177: return null;
178: }
179: }
180: }
|