javauis/lcdui_qt/src/javax/microedition/lcdui/Gauge.java
changeset 56 abc41079b313
parent 23 98ccebc37403
child 57 59b3b4473dc8
equal deleted inserted replaced
50:023eef975703 56:abc41079b313
    50     public static final int INCREMENTAL_UPDATING = 3;
    50     public static final int INCREMENTAL_UPDATING = 3;
    51 
    51 
    52     private int maxValue;
    52     private int maxValue;
    53     private int value;
    53     private int value;
    54     private boolean interactive;
    54     private boolean interactive;
       
    55     private boolean isGaugeCreation;
    55 
    56 
    56     /**
    57     /**
    57      * Constructor.
    58      * Constructor.
    58      *
    59      *
    59      * @param name the label.
    60      * @param name the label.
    62      * @param initVal the initial value.
    63      * @param initVal the initial value.
    63      */
    64      */
    64     public Gauge(String name, boolean interactive, int maxVal, int initVal)
    65     public Gauge(String name, boolean interactive, int maxVal, int initVal)
    65     {
    66     {
    66         setLabel(name);
    67         setLabel(name);
       
    68         isGaugeCreation = true;
    67         this.interactive = interactive;
    69         this.interactive = interactive;
    68         setMaxValue(maxVal);
    70         setMaxValue(maxVal);
    69         setValue(initVal);
    71         setValue(initVal);
       
    72         isGaugeCreation = false;
    70     }
    73     }
    71 
    74 
    72     /**
    75     /**
    73      * Check value validity.
    76      * Check value validity.
    74      *
    77      *
    75      * @param value the value.
    78      * @param value the value.
    76      * @param maxVal the maximum value.
    79      * @param maxVal the maximum value.
    77      * @return validated value.
    80      * @return validated value.
    78      */
    81      */
    79     private static int checkValue(int value, int maxVal)
    82     private int checkValue(int value, int maxVal)
    80     {
    83     {
    81         if(maxVal == INDEFINITE)
    84         if(maxVal == INDEFINITE)
    82         {
    85         {
    83             switch(value)
    86             if(isGaugeCreation)
    84             {
    87             {
    85             case CONTINUOUS_IDLE:
    88                 switch(value)
    86             case INCREMENTAL_IDLE:
    89                 {
    87             case CONTINUOUS_RUNNING:
    90                 case CONTINUOUS_IDLE:
    88             case INCREMENTAL_UPDATING:
    91                 case INCREMENTAL_IDLE:
    89                 break;
    92                 case CONTINUOUS_RUNNING:
    90             default:
    93                 case INCREMENTAL_UPDATING:
    91                 throw new IllegalArgumentException(
    94                     break;
    92                     MsgRepository.GAUGE_EXCEPTION_INVALID_VALUE);
    95                 default:
       
    96                     throw new IllegalArgumentException(
       
    97                         MsgRepository.GAUGE_EXCEPTION_INVALID_VALUE);
       
    98                 }
       
    99                 
       
   100                 return value;
    93             }
   101             }
    94             return value;
   102             else
       
   103             {
       
   104             	return CONTINUOUS_IDLE;
       
   105             }
    95         }
   106         }
    96         else
   107         else
    97         {
   108         {
    98             // make sure the value is in [0, maxValue] range
   109             // make sure the value is in [0, maxValue] range
    99             value = (value < 0 ? 0 : value);
   110             value = (value < 0 ? 0 : value);
   109      * @param interactive is interactive.
   120      * @param interactive is interactive.
   110      * @return validated maximum value.
   121      * @return validated maximum value.
   111      */
   122      */
   112     private static int checkMaxValue(int maxVal, boolean interactive)
   123     private static int checkMaxValue(int maxVal, boolean interactive)
   113     {
   124     {
   114         if(!interactive)
   125         if(interactive)
   115         {
   126         {
   116             if(maxVal == INDEFINITE)
   127             if(maxVal <= 0)
   117             {
   128             {
   118                 return maxVal;
   129                 throw new IllegalArgumentException(
       
   130                     MsgRepository.GAUGE_EXCEPTION_INVALID_MAXVALUE);
   119             }
   131             }
   120         }
       
   121         if(maxVal <= 0)
       
   122         {
       
   123             throw new IllegalArgumentException(
       
   124                 MsgRepository.GAUGE_EXCEPTION_INVALID_MAXVALUE);
       
   125         }
   132         }
   126         return maxVal;
   133         return maxVal;
   127     }
   134     }
   128 
   135 
   129     /**
   136     /**
   255      */
   262      */
   256     boolean isSuitableForAlert()
   263     boolean isSuitableForAlert()
   257     {
   264     {
   258         return (!isInteractive()
   265         return (!isInteractive()
   259                 && getParent() == null
   266                 && getParent() == null
   260                 && !hasLabel()
   267                 && getLabel() == null
   261                 && getLayout() == Item.LAYOUT_DEFAULT
   268                 && getLayout() == Item.LAYOUT_DEFAULT
   262                 && !isSizeLocked()
   269                 && !isSizeLocked()
   263                 && getNumCommands() == 0
   270                 && getNumCommands() == 0
   264                 && getItemCommandListener() == null);
   271                 && getItemCommandListener() == null);
   265     }
   272     }