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.Collection;
024import java.util.Collections;
025import java.util.EnumSet;
026import java.util.List;
027
028public class PButton
029                        extends TypedValuedClass<PButton.Type, Boolean>
030        implements java.io.Serializable {
031        public static final long serialVersionUID=1l;
032
033        public enum Type{
034                LEFT(TypeGroup.MOUSE), CENTER(TypeGroup.MOUSE), RIGHT(TypeGroup.MOUSE),
035                /**
036                Used whenever the {@link Pen} {@link PLevel.Type#PRESSURE} level value changes from/to 0.
037                */
038                ON_PRESSURE(TypeGroup.LEVEL),
039
040                CONTROL(TypeGroup.MODIFIER), SHIFT(TypeGroup.MODIFIER), ALT(TypeGroup.MODIFIER),
041                /* nicarran: experimental keyboard buttons support:
042                VK_1(TypeGroup.VK_NUMBER), VK_2(TypeGroup.VK_NUMBER), VK_3(TypeGroup.VK_NUMBER), VK_4(TypeGroup.VK_NUMBER), VK_5(TypeGroup.VK_NUMBER), VK_6(TypeGroup.VK_NUMBER), VK_7(TypeGroup.VK_NUMBER), VK_8(TypeGroup.VK_NUMBER), VK_9(TypeGroup.VK_NUMBER), VK_0(TypeGroup.VK_NUMBER),
043                */
044
045                CUSTOM(TypeGroup.UNDEFINED);
046                
047                private final TypeGroup group;
048
049                Type(TypeGroup group){
050                        this.group=group;
051                        group.types.add(this);
052                }
053                
054                public TypeGroup getGroup(){
055                        return group;
056                }
057
058                public static final List<Type> ALL_VALUES=Collections.unmodifiableList(Arrays.asList(values()));
059                public static final List<Type> VALUES=TypedClass.createStandardTypes(ALL_VALUES);
060        }
061
062        public enum TypeGroup{
063                /**
064                Standard mouse buttons.
065                */
066                MOUSE,
067                /**
068                Level condition buttons.
069                */
070                LEVEL,
071                /**
072                Modifier buttons.
073                */
074                MODIFIER,
075                /* nicarran: experimental keyboard buttons support:
076                /**
077                Virtual key number buttons.
078                VK_NUMBER,
079                */
080                UNDEFINED;
081
082                private Collection<Type> types=new ArrayList<Type>();
083                private Collection<Type> typesAccess;
084
085                public Collection<Type> getTypes(){
086                        if(typesAccess==null){
087                                types=EnumSet.copyOf(types);
088                                typesAccess=Collections.unmodifiableCollection(types);
089                        }
090                        return typesAccess;
091                }
092        }
093
094        public PButton(Type type, Boolean value){
095                this(type.ordinal(), value);
096        }
097
098        public PButton(int typeNumber, Boolean value) {
099                super(typeNumber, value);
100        }
101
102        @Override
103        final List<Type> getAllTypes(){
104                return Type.ALL_VALUES;
105        }
106}