Coverage Report - org.argouml.uml.reveng.Setting
 
Classes in this File Line Coverage Branch Coverage Complexity
Setting
0%
0/8
N/A
1.409
Setting$BooleanSelection
0%
0/8
N/A
1.409
Setting$PathListSelection
0%
0/8
N/A
1.409
Setting$PathSelection
0%
0/8
N/A
1.409
Setting$UniqueSelection
0%
0/19
0%
0/12
1.409
 
 1  
 /* $Id: Setting.java 17870 2010-01-12 20:49:32Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    tfmorris
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 2006-2008 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies. This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason. IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.uml.reveng;
 40  
 
 41  
 import java.util.Collections;
 42  
 import java.util.List;
 43  
 
 44  
 
 45  
 /**
 46  
  * Common class that all settings types inherit from.  It provides
 47  
  * a label to be associated with the setting in the user interface.
 48  
  */
 49  
 public class Setting implements SettingsTypes.Setting2 {
 50  
 
 51  
     /**
 52  
      * The message of the Label.
 53  
      */
 54  
     private String label;
 55  
 
 56  
     private String description;
 57  
     
 58  
     /**
 59  
      * Construct a new Setting with the given label text.
 60  
      * 
 61  
      * @param labelText string to use as the label
 62  
      */
 63  
     public Setting(String labelText) {
 64  0
         super();
 65  0
         label = labelText;
 66  0
     }
 67  
     
 68  
     /**
 69  
      * Construct a new Setting with the given label text and description.
 70  
      * 
 71  
      * @param labelText string to use as the label
 72  
      * @param descriptionText string to use as description
 73  
      */
 74  
     public Setting(String labelText, String descriptionText) {
 75  0
         this(labelText);
 76  0
         description = descriptionText;
 77  0
     }
 78  
 
 79  
 
 80  
     public final String getLabel() {
 81  0
         return label;
 82  
     }
 83  
     
 84  
     public String getDescription() {
 85  0
         return description;
 86  
     }
 87  
 
 88  
     /**
 89  
      * Setting which specifies a boolean value.  Typical user presentation
 90  
      * would be labeled checkbox.
 91  
      */
 92  
     public static class BooleanSelection extends Setting
 93  
         implements SettingsTypes.BooleanSelection2 {
 94  
 
 95  
         private boolean defaultValue;
 96  
         private boolean value;
 97  
 
 98  
 
 99  
         /**
 100  
          * Construct a new setting object which specifies a boolean selection.
 101  
          *
 102  
          * @param labelText the string to use for the user visible label
 103  
          * @param initialValue the default value (true or false)
 104  
          */
 105  
         public BooleanSelection(String labelText, boolean initialValue) {
 106  0
             super(labelText);
 107  0
             this.defaultValue = initialValue;
 108  0
             value = initialValue;
 109  0
         }
 110  
 
 111  
         /*
 112  
          * @see org.argouml.uml.reveng.SettingsTypes.BooleanSelection#isSelected()
 113  
          */
 114  
         public final boolean isSelected() {
 115  0
             return value;
 116  
         }
 117  
 
 118  
         /*
 119  
          * @see org.argouml.uml.reveng.SettingsTypes.BooleanSelection#getDefaultValue()
 120  
          */
 121  
         public final boolean getDefaultValue() {
 122  0
             return defaultValue;
 123  
         }
 124  
         
 125  
         public final void setSelected(boolean selected) {
 126  0
             this.value = selected;
 127  0
         }
 128  
     }
 129  
     
 130  
     /**
 131  
      * A setting that allows a single selection from a list of choices.
 132  
      * 
 133  
      * @see SettingsTypes.UniqueSelection2
 134  
      * @author Bogdan Pistol
 135  
      * 
 136  
      */
 137  
     public static class UniqueSelection extends Setting implements
 138  
             SettingsTypes.UniqueSelection2 {
 139  
 
 140  
         /**
 141  
          * The list of String options
 142  
          */
 143  
         private List<String> options;
 144  
         
 145  
         /**
 146  
          * Default selection is UNDEFINED
 147  
          */
 148  0
         private int defaultSelection = UNDEFINED_SELECTION;
 149  
         
 150  
         /**
 151  
          * The selection is UNDEFINED
 152  
          */
 153  0
         private int selection = UNDEFINED_SELECTION;
 154  
         
 155  
         /**
 156  
          * Constructor
 157  
          * 
 158  
          * @param label the user visible string to associate with this setting
 159  
          * @param variants
 160  
          *            the list of String options
 161  
          * @param defaultVariant
 162  
          *            the default selection or UNDEFINED_SELECTION
 163  
          */
 164  
         public UniqueSelection(String label, List<String> variants,
 165  
                 int defaultVariant) {
 166  0
             super(label);
 167  0
             options = variants;
 168  0
             if (isOption(defaultVariant)) {
 169  0
                 defaultSelection = defaultVariant;
 170  
             }
 171  0
         }
 172  
 
 173  
         /**
 174  
          * Tests if this is a valid option.
 175  
          * 
 176  
          * @param opt
 177  
          *            the option to test
 178  
          * @return true if it's OK and false otherwise
 179  
          */
 180  
         private boolean isOption(int opt) {
 181  0
             if (options == null) {
 182  0
                 return false;
 183  
             }
 184  0
             return opt >= 0 && opt < options.size() ? true : false;        
 185  
         }
 186  
 
 187  
         /*
 188  
          * @see org.argouml.uml.reveng.ImportSettingTypes.UniqueSelection#getDefaultSelection()
 189  
          */
 190  
         public int getDefaultSelection() {
 191  0
             return defaultSelection;
 192  
         }
 193  
 
 194  
         /*
 195  
          * We return a new List with the options instead of the options themself
 196  
          * because we don't want the user to be able to change the options.
 197  
          * 
 198  
          * @see org.argouml.uml.reveng.SettingsTypes.UniqueSelection#getOptions()
 199  
          */
 200  
         public List<String> getOptions() {
 201  0
             return Collections.unmodifiableList(options);
 202  
         }
 203  
 
 204  
         /*
 205  
          * @see org.argouml.uml.reveng.ImportSettingTypes.UniqueSelection#setSelection(int)
 206  
          */
 207  
         public boolean setSelection(int sel) {
 208  0
             if (isOption(sel)) {
 209  0
                 selection = sel;
 210  0
                 return true;
 211  
             } else {
 212  0
                 return false;
 213  
             }
 214  
         }
 215  
         
 216  
         /**
 217  
          * This method (package access) determines the selected option.
 218  
          * 
 219  
          * @return the 0-based index of the selected option or the default
 220  
          *         option if no other option was selected
 221  
          */
 222  
         public int getSelection() {
 223  0
             if (selection == UNDEFINED_SELECTION) {
 224  0
                 return defaultSelection;
 225  
             } else {
 226  0
                 return selection;
 227  
             }
 228  
         }
 229  
 
 230  
     }
 231  
 
 232  
     /**
 233  
      * A selection for a single path (e.g. file system path or directory).
 234  
      */
 235  
     public static class PathSelection extends Setting implements
 236  
             SettingsTypes.PathSelection {
 237  
 
 238  
         private String path;
 239  
 
 240  
         private String defaultPath;
 241  
 
 242  
         /**
 243  
          * Construct a PathSelection with the given attributes.
 244  
          * 
 245  
          * @param labelText string to use for the label of the path list
 246  
          * @param descriptionText longer description of the purpose of this
 247  
          *                pathlist (appropriate for a tooltip)
 248  
          * @param defaultValue initial value of the path 
 249  
          */
 250  
         public PathSelection(String labelText, String descriptionText,
 251  
                 String defaultValue) {
 252  0
             super(labelText, descriptionText);
 253  0
             defaultPath = defaultValue;
 254  0
             path = defaultValue;
 255  0
         }
 256  
 
 257  
         public String getDefaultPath() {
 258  0
             return defaultPath;
 259  
         }
 260  
 
 261  
         public String getPath() {
 262  0
             return path;
 263  
         }
 264  
 
 265  
         /**
 266  
          * Set the path selection so that it is available to the importer.
 267  
          * 
 268  
          * @param newPath string representing the new path
 269  
          */
 270  
         public void setPath(String newPath) {
 271  0
             path = newPath;
 272  0
         }
 273  
 
 274  
     }
 275  
 
 276  
     /**
 277  
      * An implementation of the PathListSelection.
 278  
      */
 279  
     public static class PathListSelection extends Setting implements
 280  
             SettingsTypes.PathListSelection {
 281  
 
 282  
         private List<String> defaultPathList;
 283  
 
 284  
         private List<String> pathList;
 285  
 
 286  
         /**
 287  
          * Construct a new PathListSelection with the given attributes.
 288  
          * 
 289  
          * @param labelText string to use for the label of the path list
 290  
          * @param descriptionText longer description of the purpose of this
 291  
          *                pathlist (appropriate for a tooltip)
 292  
          * @param defaultList inital values of the path list
 293  
          */
 294  
         public PathListSelection(String labelText, String descriptionText,
 295  
                 List<String> defaultList) {
 296  0
             super(labelText, descriptionText);
 297  0
             defaultPathList = defaultList;
 298  0
             pathList = defaultList;
 299  0
         }
 300  
 
 301  
         public List<String> getDefaultPathList() {
 302  0
             return defaultPathList;
 303  
         }
 304  
 
 305  
         public List<String> getPathList() {
 306  0
             return pathList;
 307  
         }
 308  
 
 309  
         public void setPathList(List<String> newPathList) {
 310  0
             pathList = newPathList;
 311  0
         }
 312  
 
 313  
     }
 314  
 
 315  
 }