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.SessionListEvent;
030: import jacareto.cleverphl.session.SessionListListener;
031: import jacareto.cleverphl.session.SessionListener;
032: import jacareto.system.Language;
033:
034: import java.awt.BorderLayout;
035: import java.awt.event.WindowEvent;
036: import java.awt.event.WindowListener;
037:
038: import javax.swing.JToolBar;
039:
040: /**
041: * The main frame of CleverPHL.
042: *
043: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
044: * @version 1.02
045: */
046: public class CleverPHLMainFrame extends CleverPHLFrame implements
047: WindowListener, SessionListListener, SessionListener {
048: /** The sessions pane. */
049: private SessionPane sessionsPane;
050:
051: /** The toolbar. */
052: private JToolBar toolBar;
053:
054: /** The sidebar. */
055: private ManipulationToolBar manipulationToolBar;
056:
057: /** Whether or not the close operation causes an exit. */
058: private boolean isExitOnClose;
059:
060: /** The language instance. */
061: private Language language;
062:
063: /**
064: * Creates a new frame.
065: *
066: * @param cleverPHL the CleverPHL instance
067: */
068: public CleverPHLMainFrame(CleverPHL cleverPHL) {
069: super (cleverPHL, "CleverPHL.MainFrame", null);
070:
071: language = cleverPHL.getLanguage();
072:
073: setTitle(language.getString("CleverPHL.MainFrame.Title"));
074: addWindowListener(this );
075:
076: createMenu("CleverPHL.Menu.MainFrame.MenuBar");
077:
078: //setLocation (0, 0);
079: //setToPreferredSize (850, 500);
080: // The sessions pane
081: sessionsPane = new SessionPane(cleverPHL);
082:
083: // The toolbar
084: toolBar = new JToolBar();
085: createToolBar(toolBar, "CleverPHL.ToolBar.MainFrame");
086:
087: // The sidebar
088: manipulationToolBar = new ManipulationToolBar(cleverPHL
089: .getEnvironment(), JToolBar.VERTICAL,
090: getCleverPHLMenuBar());
091:
092: getContentPane().setLayout(new BorderLayout());
093: getContentPane().add(toolBar, BorderLayout.NORTH);
094: getContentPane().add(sessionsPane, BorderLayout.CENTER);
095: getContentPane().add(manipulationToolBar, BorderLayout.WEST);
096:
097: setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
098:
099: cleverPHL.getSessionList().addSessionListListener(this );
100:
101: setExitOnClose(true);
102: getMenuState().setState(MenuState.NO_SESSION);
103: }
104:
105: /**
106: * Specifies whether or not the closing operation causes an exit.
107: *
108: * @param isExitOnClose set to true if window should close on exit
109: */
110: public void setExitOnClose(boolean isExitOnClose) {
111: this .isExitOnClose = isExitOnClose;
112: }
113:
114: /**
115: * Returns the session pane.
116: *
117: * @return SessionPane
118: */
119: public SessionPane getSessionPane() {
120: return sessionsPane;
121: }
122:
123: /**
124: * Does nothing.
125: *
126: * @param w WindowEvent
127: */
128: public void windowActivated(WindowEvent w) {
129: }
130:
131: /**
132: * Does nothing.
133: *
134: * @param w WindowEvent
135: */
136: public void windowClosed(WindowEvent w) {
137: }
138:
139: /**
140: * Does nothing.
141: *
142: * @param w WindowEvent
143: */
144: public void windowDeactivated(WindowEvent w) {
145: }
146:
147: /**
148: * Does nothing.
149: *
150: * @param w WindowEvent
151: */
152: public void windowDeiconified(WindowEvent w) {
153: }
154:
155: /**
156: * Does nothing.
157: *
158: * @param w WindowEvent
159: */
160: public void windowIconified(WindowEvent w) {
161: }
162:
163: /**
164: * Does nothing.
165: *
166: * @param w WindowEvent
167: */
168: public void windowOpened(WindowEvent w) {
169: }
170:
171: /**
172: * Exits the system.
173: *
174: * @param w WindowEvent
175: */
176: public void windowClosing(WindowEvent w) {
177: if (isExitOnClose) {
178: cleverPHL.exit();
179: }
180: }
181:
182: /**
183: * Called when the session list has changed.
184: *
185: * @param event SessionEvent
186: */
187: public void sessionListChanged(SessionListEvent event) {
188: Session session = event.getSession();
189:
190: if (event.getID() == SessionListEvent.SESSION_ADDED) {
191: session.addSessionListener(this );
192: } else if (event.getID() == SessionListEvent.SESSION_REMOVED) {
193: session.removeSessionListener(this );
194: setTitle(language.getString("CleverPHL.MainFrame.Title"));
195: } else if (event.getID() == SessionListEvent.NEW_ACTUAL_SESSION) {
196: setTitle(language.getString("CleverPHL.MainFrame.Title")
197: + " - [" + session.getName() + "]");
198: manipulationToolBar.setManipulationManagement(session
199: .getManipulationManagement());
200: }
201: }
202:
203: /**
204: * Called when a session has been changed.
205: *
206: * @param event SessionEvent
207: */
208: public void sessionStateChanged(SessionEvent event) {
209: Session session = event.getSession();
210:
211: switch (event.getID()) {
212: case SessionEvent.NAME_CHANGED:
213: setTitle(language.getString("CleverPHL.MainFrame.Title")
214: + " - [" + session.getName() + "]");
215:
216: break;
217: }
218: }
219: }
|