001    package org.LiveGraph.settings;
002    
003    import org.LiveGraph.LiveGraph;
004    import org.LiveGraph.events.Event;
005    import org.LiveGraph.events.EventProcessingException;
006    import org.LiveGraph.events.EventProducer;
007    import org.LiveGraph.events.EventType;
008    import org.LiveGraph.events.UncheckedEventProcessingException;
009    
010    /**
011     * Base class for all settings classes which can hadle observers to listen to
012     * settings events. This class handles all observer and event handling.
013     * 
014     * <p style="font-size:smaller;">This product includes software developed by the
015     *    <strong>LiveGraph</strong> project and its contributors.<br />
016     *    (<a href="http://www.live-graph.org" target="_blank">http://www.live-graph.org</a>)<br />
017     *    Copyright (c) 2007-2008 G. Paperin.<br />
018     *    All rights reserved.
019     * </p>
020     * <p style="font-size:smaller;">File: ObservableSettings.java</p> 
021     * <p style="font-size:smaller;">Redistribution and use in source and binary forms, with or
022     *    without modification, are permitted provided that the following terms and conditions are met:
023     * </p>
024     * <p style="font-size:smaller;">1. Redistributions of source code must retain the above
025     *    acknowledgement of the LiveGraph project and its web-site, the above copyright notice,
026     *    this list of conditions and the following disclaimer.<br />
027     *    2. Redistributions in binary form must reproduce the above acknowledgement of the
028     *    LiveGraph project and its web-site, the above copyright notice, this list of conditions
029     *    and the following disclaimer in the documentation and/or other materials provided with
030     *    the distribution.<br />
031     *    3. All advertising materials mentioning features or use of this software or any derived
032     *    software must display the following acknowledgement:<br />
033     *    <em>This product includes software developed by the LiveGraph project and its
034     *    contributors.<br />(http://www.live-graph.org)</em><br />
035     *    4. All advertising materials distributed in form of HTML pages or any other technology
036     *    permitting active hyper-links that mention features or use of this software or any
037     *    derived software must display the acknowledgment specified in condition 3 of this
038     *    agreement, and in addition, include a visible and working hyper-link to the LiveGraph
039     *    homepage (http://www.live-graph.org).
040     * </p>
041     * <p style="font-size:smaller;">THIS SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY
042     *    OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
043     *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND  NONINFRINGEMENT. IN NO EVENT SHALL
044     *    THE AUTHORS, CONTRIBUTORS OR COPYRIGHT  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
045     *    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  FROM, OUT OF OR
046     *    IN CONNECTION WITH THE SOFTWARE OR THE USE OR  OTHER DEALINGS IN THE SOFTWARE.
047     * </p>
048     * 
049     * @author Greg Paperin (<a href="http://www.paperin.org" target="_blank">http://www.paperin.org</a>)
050     * @version {@value org.LiveGraph.LiveGraph#version}
051     */
052    public class ObservableSettings implements EventProducer {
053    
054    public void eventProcessingFinished(Event<? extends EventType> event) { }
055    
056    /**
057     * Objects of this class do not handle {@code eventProcessingException} notofications.
058     * 
059     * @param event Ignored. 
060     * @param exception Never actually thrown.
061     * @return {@code false}.
062     */
063    public boolean eventProcessingException(Event<? extends EventType> event, EventProcessingException exception) {
064            return false;
065    }
066    
067    public void notifyObservers(Event<? extends SettingsEvent> event) {
068            LiveGraph.application().eventManager().raiseEvent(event);
069    }
070    
071    public Event<SettingsEvent> checkObservers(SettingsEvent eventType, boolean info) throws UncheckedEventProcessingException {
072            
073            Class<? extends SettingsEvent> eventTypeClass = eventType.getClass();     
074            Event<SettingsEvent> event = new Event<SettingsEvent>(this, eventTypeClass, eventType, info);
075            try {
076                    if (LiveGraph.application().eventManager().validateEvent(event))
077                            return event;
078                    return null;
079            } catch(EventProcessingException e) {
080                    throw new UncheckedEventProcessingException(e);
081            }
082    }
083    
084    
085    public Event<SettingsEvent> checkObservers(SettingsEvent eventType, long info) throws UncheckedEventProcessingException {
086            
087            Class<? extends SettingsEvent> eventTypeClass = eventType.getClass();     
088            Event<SettingsEvent> event = new Event<SettingsEvent>(this, eventTypeClass, eventType, info);
089            try {
090                    if (LiveGraph.application().eventManager().validateEvent(event))
091                            return event;
092                    return null;
093            } catch(EventProcessingException e) {
094                    throw new UncheckedEventProcessingException(e);
095            }
096    }
097    
098    
099    public Event<SettingsEvent> checkObservers(SettingsEvent eventType, double info) throws UncheckedEventProcessingException {
100            
101            Class<? extends SettingsEvent> eventTypeClass = eventType.getClass();     
102            Event<SettingsEvent> event = new Event<SettingsEvent>(this, eventTypeClass, eventType, info);
103            try {
104                    if (LiveGraph.application().eventManager().validateEvent(event))
105                            return event;
106                    return null;
107            } catch(EventProcessingException e) {
108                    throw new UncheckedEventProcessingException(e);
109            }
110    }
111    
112    
113    public Event<SettingsEvent> checkObservers(SettingsEvent eventType, Object info) throws UncheckedEventProcessingException {
114            
115            Class<? extends SettingsEvent> eventTypeClass = eventType.getClass();     
116            Event<SettingsEvent> event = new Event<SettingsEvent>(this, eventTypeClass, eventType, info);
117            try {
118                    if (LiveGraph.application().eventManager().validateEvent(event))
119                            return event;
120                    return null;
121            } catch(EventProcessingException e) {
122                    throw new UncheckedEventProcessingException(e);
123            }
124    }
125    
126    
127    public Event<SettingsEvent> checkObservers(SettingsEvent eventType,
128                                                              boolean infoBoolean, long infoLong, double infoDouble, Object infoObject)
129                                                                                                                                            throws UncheckedEventProcessingException {
130            
131            Class<? extends SettingsEvent> eventTypeClass = eventType.getClass();     
132            Event<SettingsEvent> event = new Event<SettingsEvent>(this, eventTypeClass, eventType,
133                                                                                                                      infoBoolean, infoLong, infoDouble, infoObject);
134            try {
135                    if (LiveGraph.application().eventManager().validateEvent(event))
136                            return event;
137                    return null;
138            } catch(EventProcessingException e) {
139                    throw new UncheckedEventProcessingException(e);
140            }
141    }
142    
143    }