示例#1
0
 /// <summary>
 /// Sets the selected item in this <code>Choice</code> menu to be the
 /// item at the specified position.
 ///
 /// <para>Note that this method should be primarily used to
 /// initially select an item in this component.
 /// Programmatically calling this method will <i>not</i> trigger
 /// an <code>ItemEvent</code>.  The only way to trigger an
 /// <code>ItemEvent</code> is by user interaction.
 ///
 /// </para>
 /// </summary>
 /// <param name="pos">      the position of the selected item </param>
 /// <exception cref="IllegalArgumentException"> if the specified
 ///                            position is greater than the
 ///                            number of items or less than zero </exception>
 /// <seealso cref=        #getSelectedItem </seealso>
 /// <seealso cref=        #getSelectedIndex </seealso>
 public virtual void Select(int pos)
 {
     lock (this)
     {
         if ((pos >= PItems.Size()) || (pos < 0))
         {
             throw new IllegalArgumentException("illegal Choice item position: " + pos);
         }
         if (PItems.Size() > 0)
         {
             SelectedIndex_Renamed = pos;
             ChoicePeer peer = (ChoicePeer)this.Peer_Renamed;
             if (peer != null)
             {
                 peer.Select(pos);
             }
         }
     }
 }
示例#2
0
        /// <summary>
        /// Inserts an item to this <code>Choice</code>,
        /// but does not invalidate the <code>Choice</code>.
        /// Client methods must provide their own synchronization before
        /// invoking this method. </summary>
        /// <param name="item"> the item to be added </param>
        /// <param name="index"> the new item position </param>
        /// <exception cref="NullPointerException"> if the item's value is equal to
        ///          <code>null</code> </exception>
        private void InsertNoInvalidate(String item, int index)
        {
            if (item == null)
            {
                throw new NullPointerException("cannot add null item to Choice");
            }
            PItems.InsertElementAt(item, index);
            ChoicePeer peer = (ChoicePeer)this.Peer_Renamed;

            if (peer != null)
            {
                peer.Add(item, index);
            }
            // no selection or selection shifted up
            if (SelectedIndex_Renamed < 0 || SelectedIndex_Renamed >= index)
            {
                Select(0);
            }
        }
示例#3
0
        /// <summary>
        /// Removes an item from the <code>Choice</code> at the
        /// specified position, but does not invalidate the <code>Choice</code>.
        /// Client methods must provide their
        /// own synchronization before invoking this method. </summary>
        /// <param name="position">   the position of the item </param>
        private void RemoveNoInvalidate(int position)
        {
            PItems.RemoveElementAt(position);
            ChoicePeer peer = (ChoicePeer)this.Peer_Renamed;

            if (peer != null)
            {
                peer.Remove(position);
            }
            /* Adjust selectedIndex if selected item was removed. */
            if (PItems.Size() == 0)
            {
                SelectedIndex_Renamed = -1;
            }
            else if (SelectedIndex_Renamed == position)
            {
                Select(0);
            }
            else if (SelectedIndex_Renamed > position)
            {
                Select(SelectedIndex_Renamed - 1);
            }
        }