javacommons/utils/javasrc/com/nokia/mj/impl/rt/ui/ConfirmData.java
changeset 21 2a9601315dfc
child 80 d6dafc5d983f
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 package com.nokia.mj.impl.rt.ui;
       
    19 
       
    20 public class ConfirmData
       
    21 {
       
    22 
       
    23     // constant identifying that the answer is not available
       
    24     public static final int NO_ANSWER = -1;
       
    25 
       
    26     // question, answer options, answer suggestion and answer
       
    27     private String iQuestion = null;
       
    28     private String[] iAnswerOptions = null;
       
    29     private int iAnswerSuggestion = 0;
       
    30     private int iAnswer = NO_ANSWER;
       
    31 
       
    32     /**
       
    33      * Constructor
       
    34      *
       
    35      * @param aQuestion              the question (as localized text) to be
       
    36      *                               asked from user
       
    37      * @param aAnswerOptions         the answer options (as localized texts)
       
    38      * @param aAnswerSuggestion      the suggestion for the option to be
       
    39      *                               selected (e.g. the option to be
       
    40      *                               highlighted when presenting the answer
       
    41      *                               options). This must be a valid index
       
    42      *                               within aAnswerOptions, otherwise the first
       
    43      *                               option from aAnswerOptions is treated as
       
    44      *                               the answer suggestion
       
    45      */
       
    46     public ConfirmData(String aQuestion, String[] aAnswerOptions,
       
    47                        int aAnswerSuggestion)
       
    48     {
       
    49         iQuestion = aQuestion;
       
    50         iAnswerOptions = aAnswerOptions;
       
    51         iAnswerSuggestion = aAnswerSuggestion;
       
    52         iAnswer = NO_ANSWER;
       
    53     }
       
    54 
       
    55     /**
       
    56      * Setter for the user's answer
       
    57      *
       
    58      * @param aAnswer This must be a valid index within the answer options
       
    59      *                encapsulated by this class, otherwise this parameter is
       
    60      *                ignored
       
    61      */
       
    62     public void setAnswer(int aAnswer)
       
    63     {
       
    64         iAnswer = aAnswer;
       
    65     }
       
    66 
       
    67     /**
       
    68      * Getter for the user's question
       
    69      *
       
    70      * @return the question (as localized text) to be asked from user
       
    71      */
       
    72     public String getQuestion()
       
    73     {
       
    74         return iQuestion;
       
    75     }
       
    76 
       
    77     /**
       
    78      * Getter for the user's answer options
       
    79      *
       
    80      * @return the answer options (as localized texts) or null if there are no
       
    81      *         answer options
       
    82      */
       
    83     public String[] getAnswerOptions()
       
    84     {
       
    85         return iAnswerOptions;
       
    86     }
       
    87 
       
    88     /**
       
    89      * Getter for the user's answer suggestion
       
    90      *
       
    91      * @return the suggestion for the option to be selected. This is be a valid
       
    92      *         index within return value of getAnswerOptions()
       
    93      */
       
    94     public int getAnswerSuggestion()
       
    95     {
       
    96         return iAnswerSuggestion;
       
    97     }
       
    98 
       
    99     /**
       
   100      * Getter for the user's answer
       
   101      *
       
   102      * @return  An index from within the answer options encapsulated by this
       
   103      *          class, indicating the user's response or NO_ANSWER constant
       
   104      *          if there is no answer available
       
   105      */
       
   106     public int getAnswer()
       
   107     {
       
   108         return iAnswer;
       
   109     }
       
   110 
       
   111     public String toString()
       
   112     {
       
   113         StringBuffer buf = new StringBuffer();
       
   114         buf.append(iQuestion).append("\n");
       
   115         if (iAnswerOptions != null)
       
   116         {
       
   117             for (int i = 0; i < iAnswerOptions.length; i++)
       
   118             {
       
   119                 buf.append("   Answer option ").append(i).append(": ")
       
   120                 .append(iAnswerOptions[i]).append("\n");
       
   121             }
       
   122             buf.append("Answer suggestion: " + iAnswerSuggestion)
       
   123             .append("\n");
       
   124         }
       
   125         return buf.toString();
       
   126     }
       
   127 
       
   128 }