001 package org.LiveGraph.gui; 002 003 import java.awt.BorderLayout; 004 005 import javax.swing.JFrame; 006 import javax.swing.WindowConstants; 007 008 import org.LiveGraph.LiveGraph; 009 import org.LiveGraph.events.Event; 010 import org.LiveGraph.events.EventListener; 011 import org.LiveGraph.events.EventManager; 012 import org.LiveGraph.events.EventType; 013 014 015 /** 016 * This is the superclass for all LiveGraph frames (windows). This class executes initialisation 017 * and event handling commonly shared between all windows. Each window may ovverride any 018 * of this behaviour if desired. 019 * 020 * <p> 021 * <strong>LiveGraph</strong> 022 * (<a href="http://www.live-graph.org" target="_blank">http://www.live-graph.org</a>). 023 * </p> 024 * <p>Copyright (c) 2007-2008 by G. Paperin.</p> 025 * <p>File: LiveGraphFrame.java</p> 026 * <p style="font-size:smaller;">Redistribution and use in source and binary forms, with or 027 * without modification, are permitted provided that the following terms and conditions are met: 028 * </p> 029 * <p style="font-size:smaller;">1. Redistributions of source code must retain the above 030 * acknowledgement of the LiveGraph project and its web-site, the above copyright notice, 031 * this list of conditions and the following disclaimer.<br /> 032 * 2. Redistributions in binary form must reproduce the above acknowledgement of the 033 * LiveGraph project and its web-site, the above copyright notice, this list of conditions 034 * and the following disclaimer in the documentation and/or other materials provided with 035 * the distribution.<br /> 036 * 3. All advertising materials mentioning features or use of this software or any derived 037 * software must display the following acknowledgement:<br /> 038 * <em>This product includes software developed by the LiveGraph project and its 039 * contributors.<br />(http://www.live-graph.org)</em><br /> 040 * 4. All advertising materials distributed in form of HTML pages or any other technology 041 * permitting active hyper-links that mention features or use of this software or any 042 * derived software must display the acknowledgment specified in condition 3 of this 043 * agreement, and in addition, include a visible and working hyper-link to the LiveGraph 044 * homepage (http://www.live-graph.org). 045 * </p> 046 * <p style="font-size:smaller;">THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY 047 * OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 048 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 049 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 050 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 051 * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 052 * </p> 053 * 054 * @author Greg Paperin (<a href="http://www.paperin.org" target="_blank">http://www.paperin.org</a>) 055 * @version {@value org.LiveGraph.LiveGraph#version} 056 * 057 */ 058 public class LiveGraphFrame extends JFrame implements EventListener { 059 060 /** 061 * The constructor setts up options common to all LiveGraph windows. 062 * A window may still override them during initialisation. 063 * 064 */ 065 public LiveGraphFrame() { 066 this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); 067 this.setTitle("Superclass Frame (LiveGraph)"); 068 getContentPane().setLayout(new BorderLayout()); 069 } 070 071 /** 072 * Permits to register as listener with the main LiveGraph event manager and 073 * only with the main LiveGraph event manager. 074 * 075 * @param manager The {@code EventManager} for the registering attempt. 076 * @return {@code (LiveGraph.application().eventManager() == manager)}. 077 * @see EventListener#permissionRegisterWithEventManager(EventManager) 078 */ 079 public boolean permissionRegisterWithEventManager(EventManager manager) { 080 return LiveGraph.application().eventManager() == manager; 081 } 082 083 /** 084 * Does not permit any unregistering. 085 * 086 * @param manager The {@code EventManager} for the registering attempt. 087 * @return {@code false}. 088 * @see EventListener#permissionUnregisterWithEventManager(EventManager) 089 */ 090 public boolean permissionUnregisterWithEventManager(EventManager manager) { 091 return false; 092 } 093 094 /** 095 * Does nothing. 096 * 097 * @param manager The {@code EventManager} with which this {@code EventListener} is now registered. 098 * @see EventListener#completedRegisterWithEventManager(EventManager) 099 */ 100 public void completedRegisterWithEventManager(EventManager manager) { 101 } 102 103 /** 104 * Does nothing. 105 * 106 * @param manager The {@code EventManager} with which this {@code EventListener} is now unregistered. 107 * @see EventListener#completedUnregisterWithEventManager(EventManager) 108 */ 109 public void completedUnregisterWithEventManager(EventManager manager) { 110 } 111 112 /** 113 * Does nothing. 114 * 115 * @param event An event in which this {@code EventListener} may be interested. 116 * @return {@code false}. 117 * @see EventListener#checkEventInterest(Event) 118 */ 119 public boolean checkEventInterest(Event<? extends EventType> event) { 120 return false; 121 } 122 123 /** 124 * Does nothing. 125 * 126 * @param event The event to be validated. 127 * @param soFar Whether {@code event} has been successfuly validated by whichever {@code EventListener}s 128 * (if any) were invoked to validate {@code event} before this {@code EventListener}. 129 * @return {@code true}. 130 * @see EventListener#checkEventValid(Event, boolean) 131 */ 132 public boolean checkEventValid(Event<? extends EventType> event, boolean soFar) { 133 return true; 134 } 135 136 /** 137 * Calls {@link #processGUIEvent(Event)} to process LiveGraph GUI events. 138 * Subclasses can override this method to process events of other types, however, 139 * they <em>must</em> make sure to call this superclass method to ensure that 140 * the GUI events handled here are processed correctly. 141 * 142 * @param event Event to process. 143 */ 144 public void eventRaised(Event<? extends EventType> event) { 145 146 if (event.getDomain() == GUIEvent.class) { 147 processGUIEvent(event.cast(GUIEvent.class)); 148 return; 149 } 150 } 151 152 /** 153 * If the event is of type {@link GUIEvent#GUI_DisposeAll} this method disposes this frame. 154 * Subclasses may override this method to process other GUI events, however, 155 * they <em>must</em> make sure to call this superclass method to ensure that 156 * the {@code GUI_DisposeAll} event is processed correctly. 157 * 158 * @param event A GUI event. 159 */ 160 protected void processGUIEvent(Event<GUIEvent> event) { 161 162 if (GUIEvent.GUI_DisposeAll == event.getType()) { 163 dispose(); 164 } 165 } 166 167 } // public class LiveGraphFrame