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.ArrayList;
022import java.util.Arrays;
023import java.util.Collections;
024import java.util.List;
025
026public class PKind
027                        extends TypedClass<PKind.Type>
028        implements java.io.Serializable {
029        public static final long serialVersionUID=1l;
030
031        public enum Type{
032                CURSOR, STYLUS, ERASER, 
033                /**
034                Used for devices that does not identify the pen, rater extend it, like the pad.
035                */
036                IGNORE, 
037                CUSTOM;
038                
039                public static final List<Type> ALL_VALUES=Collections.unmodifiableList(Arrays.asList(values()));
040                public static final List<Type> VALUES=TypedClass.createStandardTypes(ALL_VALUES);
041        }
042
043        private PKind(int typeNumber) {
044                super(typeNumber);
045        }
046
047        private static final List<PKind> VALUES_L=new ArrayList<PKind>(Type.VALUES.size());
048        private static final List<PKind> VALUES=Collections.unmodifiableList(VALUES_L);
049        
050        public static PKind valueOf(Type type){
051                return valueOf(type.ordinal());
052        }
053
054        public static PKind valueOf(int typeNumber){
055                while(VALUES_L.size()<=typeNumber)
056                        VALUES_L.add(new PKind(VALUES_L.size()));
057                return VALUES_L.get(typeNumber);
058        }
059
060        @Override
061        final List<Type> getAllTypes() {
062                return Type.ALL_VALUES;
063        }
064}