Coverage Report - org.jtheque.core.managers.feature.Feature
 
Classes in this File Line Coverage Branch Coverage Complexity
Feature
0 %
0/38
0 %
0/2
1.111
Feature$FeatureType
0 %
0/6
N/A
1.111
 
 1  
 package org.jtheque.core.managers.feature;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import javax.swing.Action;
 20  
 import java.util.ArrayList;
 21  
 import java.util.Collection;
 22  
 
 23  
 /**
 24  
  * A Feature of JTheque.
 25  
  *
 26  
  * @author Baptiste Wicht
 27  
  */
 28  
 public class Feature {
 29  
     private FeatureType type;
 30  
     private String titleKey;
 31  
     private Action action;
 32  
     private Integer position;
 33  
     private String icon;
 34  
     private String baseName;
 35  
 
 36  0
     private final Collection<Feature> subFeatures = new ArrayList<Feature>(20);
 37  
 
 38  
     /**
 39  
      * Construct a new Feature.
 40  
      */
 41  
     public Feature(){
 42  0
         super();
 43  0
     }
 44  
 
 45  
     /**
 46  
      * Construct a new Feature for an action.
 47  
      *
 48  
      * @param type The type of feature.
 49  
      * @param position The position of the feature in the parent.
 50  
      * @param action The action to execute when the feature is pressed.
 51  
      */
 52  
     public Feature(FeatureType type, Integer position, Action action){
 53  0
         super();
 54  
 
 55  0
         this.action = action;
 56  0
         this.type = type;
 57  0
         this.position = position;
 58  0
     }
 59  
 
 60  
     /**
 61  
      * Construct a new Feature for a menu.
 62  
      *
 63  
      * @param type The type of feature.
 64  
      * @param titleKey The i18n key of the title of the feature.
 65  
      * @param position The position of the feature in the parent. 
 66  
      */
 67  
     public Feature(FeatureType type, String titleKey, Integer position){
 68  0
         super();
 69  
 
 70  0
         this.type = type;
 71  0
         this.titleKey = titleKey;
 72  0
         this.position = position;
 73  0
     }
 74  
 
 75  
     /**
 76  
      * The Feature Type.
 77  
      *
 78  
      * @author Baptiste Wicht
 79  
      */
 80  0
     public enum FeatureType {
 81  0
         PACK,
 82  0
         SEPARATED_ACTIONS,
 83  0
         ACTIONS,
 84  0
         SEPARATED_ACTION,
 85  0
         ACTION
 86  
     }
 87  
 
 88  
     /**
 89  
      * Return the type of the feature.
 90  
      *
 91  
      * @return The type of the feature.
 92  
      */
 93  
     public final FeatureType getType() {
 94  0
         return type;
 95  
     }
 96  
 
 97  
     /**
 98  
      * Set the type of the feature.
 99  
      *
 100  
      * @param type The type of the feature.
 101  
      */
 102  
     public final void setType(FeatureType type) {
 103  0
         this.type = type;
 104  0
     }
 105  
 
 106  
     /**
 107  
      * Return the internationalization key of the title of the feature.
 108  
      *
 109  
      * @return The internationalisation key of the feature.
 110  
      */
 111  
     public final String getTitleKey() {
 112  0
         return titleKey;
 113  
     }
 114  
 
 115  
     /**
 116  
      * Set the internationalization key of the title of the feature.
 117  
      *
 118  
      * @param titleKey The title key.
 119  
      */
 120  
     public final void setTitleKey(String titleKey) {
 121  0
         this.titleKey = titleKey;
 122  0
     }
 123  
 
 124  
     /**
 125  
      * Return the action of the feature.
 126  
      *
 127  
      * @return The action.
 128  
      */
 129  
     public final Action getAction() {
 130  0
         return action;
 131  
     }
 132  
 
 133  
     /**
 134  
      * Set the action of the feature.
 135  
      *
 136  
      * @param action The action.
 137  
      */
 138  
     public final void setAction(Action action) {
 139  0
         this.action = action;
 140  0
     }
 141  
 
 142  
     /**
 143  
      * Return the sub features of the feature.
 144  
      *
 145  
      * @return A List containing all the sub feature of the feature.
 146  
      */
 147  
     public final Collection<Feature> getSubFeatures() {
 148  0
         return subFeatures;
 149  
     }
 150  
 
 151  
     /**
 152  
      * Add a sub feature to the feature.
 153  
      *
 154  
      * @param feature The feature to add.
 155  
      */
 156  
     public void addSubFeature(Feature feature) {
 157  0
         if (feature.type == FeatureType.PACK) {
 158  0
             throw new IllegalArgumentException(
 159  
                     "Unable to add feature of type Pack to a menu");
 160  
         }
 161  
 
 162  0
         subFeatures.add(feature);
 163  0
     }
 164  
 
 165  
     /**
 166  
      * Remove a sub feature to the feature.
 167  
      *
 168  
      * @param feature The feature to remove.
 169  
      */
 170  
     public void removeSubFeature(Feature feature) {
 171  0
         subFeatures.remove(feature);
 172  0
     }
 173  
 
 174  
     /**
 175  
      * Return the position of the feature.
 176  
      *
 177  
      * @return The position of the feature.
 178  
      */
 179  
     public final Integer getPosition() {
 180  0
         return position;
 181  
     }
 182  
 
 183  
     /**
 184  
      * Set the position of the feature.
 185  
      *
 186  
      * @param position The position of the feature.
 187  
      */
 188  
     public final void setPosition(Integer position) {
 189  0
         this.position = position;
 190  0
     }
 191  
 
 192  
     /**
 193  
      * Return the icon of the feature.
 194  
      *
 195  
      * @return The icon of the feature.
 196  
      */
 197  
     public final String getIcon() {
 198  0
         return icon;
 199  
     }
 200  
 
 201  
     /**
 202  
      * Set the icon of the feature.
 203  
      *
 204  
      * @param icon The icon of the feature.
 205  
      */
 206  
     public final void setIcon(String icon) {
 207  0
         this.icon = icon;
 208  0
     }
 209  
 
 210  
     /**
 211  
      * Return the base name for getting the icon.
 212  
      *
 213  
      * @return The base name.
 214  
      */
 215  
     public final String getBaseName() {
 216  0
         return baseName;
 217  
     }
 218  
 
 219  
     /**
 220  
      * Set the base name for the resources.
 221  
      *
 222  
      * @param baseName The base name.
 223  
      */
 224  
     public final void setBaseName(String baseName) {
 225  0
         this.baseName = baseName;
 226  0
         }
 227  
 }