001/* [{
002Copyright 2007, 2008 Nicolas Carranza <nicarran at gmail.com>
003
004This file is part of jpen.
005
006jpen is free software: you can redistribute it and/or modify
007it under the terms of the GNU Lesser General Public License as published by
008the Free Software Foundation, either version 3 of the License,
009or (at your option) any later version.
010
011jpen is distributed in the hope that it will be useful,
012but WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014GNU Lesser General Public License for more details.
015
016You should have received a copy of the GNU Lesser General Public License
017along with jpen.  If not, see <http://www.gnu.org/licenses/>.
018}] */
019package jpen;
020
021import java.util.Collection;
022import jpen.owner.PenOwner;
023
024/**
025A {@code PenProvider } contains and maintains a collection of {@link PenDevice}s which access a pointer (pen tablet/mouse or similar) data source using an specific method (e.g. Wintab). Its main role is to feed pointer data using the following methods: {@link PenManager#scheduleLevelEvent(PenDevice device, long deviceTime, Collection levels, boolean levelsOnScreen)}, {@link PenManager#scheduleScrollEvent(PenDevice device, long deviceTime, PScroll scroll)}, and {@link PenManager#scheduleButtonEvent(PenDevice device, long deviceTime, PButton button)}. <p>
026
027Each {@code PenDevice} has a {@link PKind.Type}. A tablet provider constructs typically three {@code PenDevice}s, each one initialized with {@link PKind.Type#ERASER} for the eraser, {@link PKind.Type#STYLUS} for the stylus, and {@link PKind.Type#CURSOR} for the mouse. <p>
028
029The pointer creates its own thread (or uses native threads through JNI) to feed the data.
030*/
031public interface PenProvider {
032        /**
033        Each {@code PenProvider} is constructed using a {@code Constructor}. The available {@code Constructor}s are given by the {@link PenOwner#getPenProviderConstructors()} and are used by the {@link PenManager} to try to construct one {@code PenProvider} for each {@code Constructor}. 
034        */
035        public interface Constructor {
036                /**
037                @return The name of this provider. It corresponds to the method used by the {@code PenProvider} to access the pen/tablet.
038                */
039                String getName();
040                /**
041                @return {@code true} if the {@code PenProvider} can be constructed on this system, {@code false} otherwise.This method usually test for the name of the operating system and returns {@code true} if it matches an operating system in which this provider can run.
042                */
043                boolean constructable(PenManager pm);
044                /**
045                This method constructs the {@code PenProvider}. It is called only when {@link #constructable(PenManager)} returns {@code true}.  When this methods completes, it is expected that the {@link #getConstructed()} method returns the {@code PenProvider} constructed. If the {@code PenProvider} couldn't be constructed due to some condition (e.g. the required native drivers are not present) then the {@link #getConstructionException()} method is expected to return an exception describing the condition.
046                
047                @return {@code true} if the {@code PenProvider} was constructed. {@code false} if the {@code PenProvider} couldn't be constructed.
048                */
049                boolean construct(PenManager pm);
050                /**
051                @return The {@link PenManager} which called the {@link #construct(PenManager)} method. {@code null} if the {@code construct(PenManager)} has not being called.
052                */
053                PenManager getPenManager();
054                /**
055                @return An exception describing an unexpected condition which prevented the {@code PenProvider} from being constructed. {@code null} if the {@code PenProvider} was constructed on the {@link #construct(PenManager)} method call or if it has not yet being called.
056                */
057                ConstructionException getConstructionException();
058                /**
059                @return The {@code PenProvider} constructed when {@link #construct(PenManager)}  was called. {@code null} if it couldn't be constructed or if it has not yet being called. 
060                */
061                PenProvider getConstructed();
062                /**
063                @return the native library version number. {@code -1} if the provider does not use a native library. The version is used to construct the native library name. 
064                */
065                int getNativeVersion();
066                /**
067                @return the loaded native library build number. {@code -1} if the provider does not use a native library.
068                */
069                int getNativeBuild();
070                /**
071                @return the expected native library build number. {@code -1} if the provider does not use a native library.
072                */
073                int getExpectedNativeBuild();
074        }
075
076        /**
077        A condition which prevented the {@code PenProvider} from being constructed on the {@link Constructor#construct(PenManager)} method call.
078        */
079        public class ConstructionException extends Exception {
080                public static final long serialVersionUID=1l;
081                public ConstructionException(Throwable cause) {
082                        super(cause);
083                }
084                public ConstructionException(String m) {
085                        super(m);
086                }
087        }
088        /**
089        @return The {@code Constructor} which constructed this {@code PenProvider}.
090        */
091        Constructor getConstructor();
092        /**
093        @return A {@code Collection} of devices currently owned by this {@code PenProvider}. This {@code Collection} can change over the lifetime of this {@code PenProvider}. Each time the {@code Collection} changes,  {@link PenManager#firePenDeviceAdded(PenProvider.Constructor, PenDevice)} or {@link PenManager#firePenDeviceRemoved(PenProvider.Constructor, PenDevice)} must be called to notify the change. Warning: For convenience, there is no need to call {@link PenManager#firePenDeviceAdded(PenProvider.Constructor, PenDevice)} when constructing the {@code PenProvider} inside the {@code Constructor#construct(PenManager)} method because in this case it is automatically called by the {@link PenManager} when calling the {@code Constructor}.
094        */
095        Collection<PenDevice> getDevices();
096        /**
097        Called by the {@link PenManager} to notify that all the {@link PenDevice}s owned by this {@code PenProvider} must start/stop sending events. 
098        
099        @param paused If {@code true} then the devices must stop sending events. If {@code false} then the devices must start sending events. 
100        */
101        void penManagerPaused(boolean paused);
102        
103        /**
104        @return {@code true} if this provider needs a location filter to automatically detect if one of its devices is using mouse (relative) location mode and replace its movement levels values with mouse pointer location values.
105        */
106        boolean getUseRelativeLocationFilter();
107}