Package DisplayProject

Source Code of DisplayProject.RadioList

/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package DisplayProject;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Insets;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Iterator;

import javax.swing.JList;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.apache.log4j.Logger;

import DisplayProject.binding.TypeAwareValueModel;
import DisplayProject.binding.list.SelectionInList;
import DisplayProject.binding.value.ValueModel;
import DisplayProject.controls.ReadOnlyButtonModel;
import DisplayProject.controls.ReadOnlyListSelectionModel;
import DisplayProject.factory.ListFieldFactory;
import Framework.Array_Of_ListElement;
import Framework.CloneHelper;
import Framework.DataValue;
import Framework.ErrorMgr;
import Framework.ListElement;
import Framework.MsgCatalog;
import Framework.TextData;
import Framework.UsageException;

/**
* The RadioList class defines radio lists, which display a group of options (list elements) as radio buttons, from which a user can choose one option.
* A radio button is a simple boolean check button.
*
*/
public class RadioList extends JList implements ListField {
    private static final long serialVersionUID = -911325224650893895L;
    protected Array_Of_ListElement<ListElement> kids = null;
    protected int orientation = Constants.FO_VERTICAL;
    protected int layoutPolicy = Constants.LP_CONSTANT;
    private int previousValue = 0;
    private static Logger log = Logger.getLogger(RadioList.class);
    protected int wrapSize = 1;
    private static final String uiClassID = "RadioListUI";
    private String[] namesForVisualEditor = {""};
    private int lastSelectedIndex = 0;
    private boolean allowDeselect = false; // Allow the user to not select any radio item
    // TF:02/07/2008:Added support for text message catalogs
    private int textValueSetNum = 0;

  /**
   * Whether this radio list is "editable", that is pressable without changing the display. (Hence the difference
   * between editable and enabled is that enabled = false sets the list to grey and doesn't fire events, but
   * editable = false doesn't change the list appearance but still prevents events being fired.)
   */
    private boolean editable = true;
  private boolean isCalledFromSetEditable = false;

    /**
     * This is the main constructor that should be used.
     *
     * @param xy default, horizontal or vertical orientation
     * @param caption
     * @param pNamesForVisualEditor
     * @param pWrapSize
     * @param pLayoutPolicy
     */
    public RadioList(int xy, String caption, String[] pNamesForVisualEditor, int pWrapSize, int pLayoutPolicy) {
        this(xy, caption);
        this.wrapSize = pWrapSize;
        this.namesForVisualEditor = pNamesForVisualEditor;
        this.layoutPolicy = pLayoutPolicy;
      // TF:15/12/2009:DET-141:Set this up to allow inheriting of popup menu
      this.setInheritsPopupMenu(true);
    }

    public RadioList(int xy, RadioListModel l, String caption)
    {
        this(xy,caption);
        this.setModel(l);
        this.addListSelectionListener(l);
        this.setBackground(null);
      // TF:15/12/2009:DET-141:Set this up to allow inheriting of popup menu
      this.setInheritsPopupMenu(true);
    }

    public RadioList(int xy, String caption)
    {
        super();
        this.setOrientation(xy);
        this.kids = new Array_Of_ListElement<ListElement>();
        this.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        this.setBorder(new GridTitledBorder(caption, true));
        this.setBackground(null);
      // TF:15/12/2009:DET-141:Set this up to allow inheriting of popup menu
      this.setInheritsPopupMenu(true);
    }

    public String getUIClassID() {
        return uiClassID;
    }

    public void updateUI() {
        setUI(RadioListUI.createUI(this));
        invalidate();
        log.debug("Installing radio list's UI.");
    }

    public RadioListModel getRadioListModel() {
        return (RadioListModel)this.getModel();
    }

    public int getOrientation() {
        return this.orientation;
    }

    /**
     * @param pAllowDeselect set to true to allow the radio list to be unselected.  Only do this if it mapped to a nullable type.
     * Written by Craig Mitchell 11/10/2007
     */
    public void setAllowDeselect(boolean pAllowDeselect) {
        this.allowDeselect = pAllowDeselect;
    }
   
    /**
     * Determine whether this radio list allows deselection of the mark. This is only allowed for nullable types
     * @return
     */
    public boolean getAllowDeselect() {
      return this.allowDeselect;
    }


    /**
     * If the radio list font changes, we need to change both the current font (used for rendering the buttons)
     * and the title font if there is one.
     */
    @Override
    public void setFont(Font font) {
        super.setFont(font);
        Border border = this.getBorder();
        if (border != null && border instanceof TitledBorder) {
            ((TitledBorder)border).setTitleFont(font);
        }
        updateSize();
    }

    /**
     * The Orientation attribute (int) determines whether a radio list is vertical or horizontal. A vertical
     * radio list arranges its elements extending from top to bottom, while a horizontal radio list arranges
     * them from left to right.<p>
     * <p>
     * You set the Orientation attribute to one of the following values:<p>
     * <p>
     * <table>
     *   <tr><th>Value</th><th>Definition</th></tr>
     *   <tr><td>FO_DEFAULT</td><td>Same as FO_VERTICAL.</td>
     *   <tr><td>FO_HORIZONTAL</td><td>Horizontal orientation, organizing elements from left to right, and using WrapSize to determine how wide.</td></tr>
     <tr><td>FO_VERTICAL</td><td>Vertical orientation, organizing elements from top to bottom.</td>
     * </table>
     * <p>
     * Any other value passed with throw an IllegalArguemntException
     * @param or
     */
    public void setOrientation(int or) {
        switch (or) {
        case Constants.FO_DEFAULT:
        case Constants.FO_HORIZONTAL:
        case Constants.FO_VERTICAL:
            int oldValue = this.orientation;
            this.orientation = or;
            this.firePropertyChange("orientation", oldValue, this.orientation);
            updateSize();
            break;
        default:
            UsageException errorVar = new UsageException("The value " + or + " cannot be set as the orientation on a RadioList");
            ErrorMgr.addError(errorVar);
            throw errorVar;
        }
    }

    /**
     * The Layoutpolicy attribute (integer) sets the width of an element in a horizontal radio list. <p>
     * <p>
     * To set all the list elements to a constant width -- the width of the widest element on the list --
     * give the LayoutPolicy attribute the value of LP_CONSTANT. To set each element in the list to the
     * minimum width necessary to accommodate its content, give the LayoutPolicy attribute the value of LP_PACKED.<p>
     * <p>
     * The default value for the LayoutPolicy attribute is LP_CONSTANT.    
     */
    public void setLayoutPolicy(int pPolicy) {
        switch (pPolicy) {
        case Constants.LP_CONSTANT:
        case Constants.LP_PACKED:
        case Constants.LP_DEFAULT:
            int oldValue = this.layoutPolicy;
            this.layoutPolicy = pPolicy;
            this.firePropertyChange("layoutPolicy", oldValue, this.layoutPolicy);
            updateSize();
            break;
        default:
            UsageException errorVar = new UsageException("The value " + pPolicy + " cannot be set as the orientation on a RadioList");
            ErrorMgr.addError(errorVar);
            throw errorVar;
        }
    }

    /**
     * Sets the index value of the radio list to the passed value. The passed value is 0-based .<p>
     * <p>
     * Note that this method assumes that it is being executed on the EDT and is not thread-safe. Use
     * IndexValue.set() in preference to this method if this is not the case.
     * @param index
     */
    public void setIndexValue(int index) {
        if (index < 0)
            return;
        super.setSelectedIndex(index);
    }

    /**
     * Gets the index value of the radio list. The returned value is 0-based .<p>
     * <p>
     * Note that this method assumes that it is being executed on the EDT and is not thread-safe. Use
     * IndexValue.get() in preference to this method if this is not the case.
     * @return the index value
     */
    public int getIndexValue() {
        return super.getSelectedIndex();
    }

    private PropertyChangeListener listener = new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent evt) {
      // TF:Mar 9, 2010:If the values in the element list have changed, we need
      // to notify the control so it can adjust its size too.
      RadioList.this.firePropertyChange("elementList", null, null);
      updateSize();
    }
  };
 
    /**
     * Set the list of elements that are mapped to the radio buttons
     * This method should not be called directly, only from the RadioListModel.setElementList
     * to ensure the lists are synchronised
     * @param list The data to be displayed in radio lists.
     */
    public void setElementList(Array_Of_ListElement<ListElement> list) {
      if (list != kids) {
        if (kids != null) {
          for (ListElement le : kids) {
            le.removePropertyChangeListener(listener);
          }
          kids.clear();
        }
        Array_Of_ListElement<ListElement> oldValue = kids;
          kids = list;
          // TF:Mar 9, 2010:Add in the property change listener to ensure we hear changes to the text value
          if (kids != null) {
            for (ListElement le : kids) {
              le.addPropertyChangeListener("textValue", listener);
            }
          }
          this.firePropertyChange("elementList", oldValue, kids);
          this.updateSize();
      }
    }
   
    @Override
    public void setPreferredSize(Dimension preferredSize) {
      super.setPreferredSize(preferredSize);
    }

    /**
     * Compute various parameters once the list of elements is set up in kids.
     * CraigM:02/04/2007 - Renamed and made method public so Caption could call it.
     */
    public void updateSize() {
        // Only set the dimension if we've been set up properly
        Dimension d;
        if (this.getModel() != null && this.getModel().getSize() > 0) {
            d = getUI().getPreferredSize(this);
        }
        else {
            d = new Dimension(0, 0);
        }
        this.setSize(d);
        this.setMinimumSize(d);
        this.setPreferredSize(d);
        if (this.getParent() != null)
            this.getParent().invalidate();
    }

    private void syncKidsWithModel(ListModel model) {
      Array_Of_ListElement<ListElement> elements = new Array_Of_ListElement<ListElement>();
        for (int i = 0; i < model.getSize(); i++ ) {

            // Check to stop Swing Designer from crashing. CraigM: 02/08/2007
            if (model.getElementAt(i) instanceof String) {
                elements.add(new ListElement((String)model.getElementAt(i)));
            }
            else {
                elements.add((ListElement)model.getElementAt(i));
            }
        }
        this.setElementList(elements);
        this.updateSize();
    }

    /**
     * Set this component to be editable or not. An editable toggle field allows its value to be
     * changed whereas a non-editable one does not allow it's value to be changed by the user, but
     * can still be changed programmatically. This is needed so that view-only components will still
     * fire mouse events like click and child click, whereas simply disabling the component would
     * not allow these events to be fired.
     * @param editable
     */
    public void setEditable(boolean editable) {
      if (this.editable != editable) {
        this.editable = editable;
        this.isCalledFromSetEditable = true;
        // Invoke setModel so we set the model to be the correct sort of model
        if (editable) {
          ListSelectionModel model = getSelectionModel();
          if (model instanceof ReadOnlyListSelectionModel) {
            this.setSelectionModel(((ReadOnlyListSelectionModel)model).getOriginalModel());
          }
        }
        else {
          ListSelectionModel model = getSelectionModel();
          if (!(model instanceof ReadOnlyButtonModel)) {
            this.setSelectionModel(new ReadOnlyListSelectionModel(model));
          }
        }
        this.isCalledFromSetEditable = false;
        this.firePropertyChange("editable", !editable, editable);
      }
  }
   
    /**
     * Return true if the the component's value can be changed by the user.
     * @return
     */
    public boolean isEditable() {
    return editable;
  }

    public void setModel(ListModel model)
    {
      if (model instanceof ReadOnlyButtonModel) {
        editable = false;
      }
      else {
        editable = true;
      }

        // If the model is not a RadioListModel, then it is Swing Designer trying to render the window. CraigM: 02/08/2007
        if (model instanceof RadioListModel == false && model instanceof ReadOnlyButtonModel == false) {

            // Fix the border for the Swing Designer
            Border border = RadioList.this.getBorder();

            if (border != null && border instanceof GridTitledBorder) {
                RadioList.this.setBorder(new TitledBorder(((GridTitledBorder)border).getTitle()));
            }

            model = new ListModel() {
                public void addListDataListener(ListDataListener l) {}

                public Object getElementAt(int index) {
                    return new ListElement( index, namesForVisualEditor[index], ListElement.qq_Resolver.cINTEGERVALUE_TEXTVALUE );
                }

                public int getSize() {
                    if (RadioList.this.namesForVisualEditor == null || RadioList.this.namesForVisualEditor.length == 0)
                        return 1;
                    return RadioList.this.namesForVisualEditor.length;
                }

                public void removeListDataListener(ListDataListener l) {
                }
            };
        }

        super.setModel(model);
        this.syncKidsWithModel(model);
    }

    public Array_Of_ListElement<ListElement> getElementList() {
        return kids;
    }

    public ListElement extractListElementByIndex(int index) {
        ListElement le = null;
        if ((kids != null) && (index > 0) && (index <= kids.size())) {
            le = kids.get(index - 1);
        }
        return le;
    }

    public ListElement extractListElement(int value) {
        for (Iterator<ListElement> it = kids.iterator(); it.hasNext();) {
            ListElement le = it.next();
            if (le.getIntegerValue() == value)
                return le;
        }
        return null;
    }

    public ListElement extractListElement(TextData value) {
        return extractListElement(value.toString());
    }

    public ListElement extractListElement(String value) {
      if (kids != null) {
        for (ListElement le : kids) {
              if (le.getTextValue().toString().equals(value)) {
                  return le;
              }
          }
      }
        return null;
    }

    public ListElement extractListElement(Object value) {
      if (kids != null) {
        for (ListElement le : kids) {
          if (le.getObjectValue().equals(value)) {
            return le;
          }
        }
        }
        return null;
    }

    public void setCaption(TextData cap) {
        setCaption(cap.toString());
    }

    public void setCaption(String cap) {
        TitledBorder tb = (TitledBorder) getBorder();
        tb.setTitle(cap);
    }

    public TextData getCaption() {
        TitledBorder tb = (TitledBorder) getBorder();
        return new TextData(tb.getTitle());
    }

    public TextData getTextValue() {
        return ((ListElement) getSelectedValue()).getTextValue();
    }

    public int getIntegerValue() {
        return ((ListElement) getSelectedValue()).getIntegerValue();
    }
    public int getPreviousValue(){
        return this.previousValue;
    }

    public void setPreviousValue(){
        ((RadioListModel)this.getModel()).setSelectedIndex(this.previousValue);

    }

    public int getLayoutPolicy(){
        return this.layoutPolicy;
    }

    public Object getObjectValue() {
        return ((ListElement) getSelectedValue()).getObjectValue();
    }

    public void setIntegerValue(int value) {
        for (int i = 0; i < this.getRadioListModel().getSize(); i++) {
            ListElement le = ((ListElement)this.getRadioListModel().getElementAt(i));
            if (le.equals(value)){
                this.setSelectedIndex(i);
                break;
            }
        }
    }

    public void setObjectValue(Object value) {
        for (int i = 0; i < this.getRadioListModel().getSize(); i++) {
            ListElement le = ((ListElement)this.getRadioListModel().getElementAt(i));
            if (le.getObjectValue() == null)
                continue;
            if (le.getObjectValue().equals(value)){
                this.setSelectedIndex(i);
                break;
            }
        }
    }

    public void setTextValue(TextData value) {
        this.setTextValue(value.toString());
    }
    public void setTextValue(String value) {
        for (int i = 0; i < this.getRadioListModel().getSize(); i++) {
            ListElement le = ((ListElement)this.getRadioListModel().getElementAt(i));
            if (le.equals(value)){
                this.setSelectedIndex(i);
                break;
            }
        }
    }
    //PM:14/3/08 properties for binding the text value
    public void setText(String value){
      this.setTextValue(new TextData(value));
    }
    //PM:14/3/08 properties for binding the text value
    public String getText(){
      return getTextValue().toString();
    }

    public int getWrapSize() {
        return wrapSize;
    }

    /**
     * The WrapSize attribute (integer) determines when the list wraps to form a new row or column.<p>
     * For example, a WrapSize attribute setting of 3 starts a new row in horizontal radio list at the fourth list
     * element, as shown in the figure below. In a vertical radio list, this setting starts a new column at the
     * fourth list element. The default WrapSize value is one.<p>
     * You determine whether a radio list is horizontal or vertical by setting its Orientation attribute.<p>
     * @param wrapSize
     */
    public void setWrapSize(int wrapSize) {
        int oldValue = this.wrapSize;
        this.wrapSize = Math.max(1, wrapSize);
        firePropertyChange("wrapSize", oldValue, this.wrapSize);
        updateSize();
    }

    public RadioList cloneComponent(){
        RadioList clone = ListFieldFactory.newRadioList(getOrientation(), getCaption().toString());
        CloneHelper.cloneComponent(this, clone, new String[]{"parent", "model", "textValue", "integerValue"});
        return clone;
    }

    protected void unconditionallyFireSelectionValueChanged(int firstIndex, int lastIndex, boolean isAdjusting) {
        super.fireSelectionValueChanged(firstIndex, lastIndex, isAdjusting);
    }

    /**
     * Set the insets to make the radio list display similar to the Forte one
     */
    @Override
    public Insets getInsets() {
        FontMetrics fm = this.getFontMetrics(this.getFont());
        TitledBorder tb = (TitledBorder)this.getBorder();
        if (tb != null) {
          // TF:30/10/2008:Radio buttons always have space at the top, irrespective of whether they have a title or not
//            if (tb.getTitle() != null && !"".equals(tb.getTitle())) {
                return new Insets(fm.getAscent(),fm.getDescent(),fm.getDescent(),fm.getDescent());
//            }
        }
        return new Insets(fm.getDescent(),fm.getDescent(),fm.getDescent(),fm.getDescent());
    }

    @Override
    protected void processKeyEvent(KeyEvent e) {
      // If the selection is empty, we are probably selecting something on a different button, and the
      // old focus border needs to be told to repaint itself.  CraigM: 25/03/2008.
      if (this.isSelectionEmpty()) {
        this.repaint();
      }

      // Treat SPACE as a select, and unselect if necessary. CraigM 11/10/2007.
        if (e.getKeyChar() == KeyEvent.VK_SPACE) {
            if (e.getID() == KeyEvent.KEY_PRESSED) {
                if (this.getSelectedIndex() == -1) {
                    this.setSelectedIndex(this.lastSelectedIndex);
                }
                else if (this.allowDeselect) {
                    this.lastSelectedIndex = this.getSelectedIndex();
                    this.getSelectionModel().clearSelection();
                }
            }
            e.consume();
        }
        else {
            super.processKeyEvent(e);
        }
    }

    @Override
    protected void processFocusEvent(FocusEvent e) {
      super.processFocusEvent(e);
      if (this.isSelectionEmpty()) {
        this.repaint();
      }
    }
   
    @Override
    protected void processMouseEvent(MouseEvent e) {
      // If the selection is empty, we are probably selecting something on a different button, and the
      // old focus border needs to be told to repaint itself.  CraigM: 25/03/2008.
      if (this.isSelectionEmpty()) {
        this.repaint();
      }

      // Allow the mouse to unselect if required.  CraigM 11/10/2007
      // TF:16/01/2009:DET-71:Deselect of a radio list should happen only on left click, not other mouse clicks
        if (this.allowDeselect && e.getID() == MouseEvent.MOUSE_PRESSED && e.getButton() == MouseEvent.BUTTON1) {
            int oldSelection = this.getSelectedIndex();
            super.processMouseEvent(e);
            int newSelection = this.getSelectedIndex();

            if (oldSelection == newSelection) {
                this.lastSelectedIndex = newSelection;
                this.getSelectionModel().clearSelection();
            }
        }
        else {
            super.processMouseEvent(e);
        }
    }
   
    /**
     * Return the index which last had selection. This may be different to the current selection in cases where
     * there currently is no selection in the radiolist.
     * @return
     */
    protected int getLastSelectedIndex() {
      return this.lastSelectedIndex;
    }
   
  /* (non-Javadoc)
   * @see com.lumley.gennetica.genneticaframework.displayproject.ListField#setElementSelected(int, boolean)
     * @author AD:26/5/2008
   */
  public void setElementSelected(int index, boolean isSelected) {
    if (isSelected) {
      this.setSelectedIndex(index);
    } else {
      // Set no item to be selected
      this.setSelectedIndex(-1);
    }
   
  }
    // TF:02/07/2008:Added support for text message catalogs
  /**
   * Set the set number for the message catalog associated with the elements in the
   * radio list. If the passed value is 0, then the set number associated with the
   * window will be used instead. This method will replace all the text values of
   * the elements in the list of elements with their translated set value, as per forte
   * @param setNumber the set number to use for the list elements.
   */
    public void setTextValueSetNum(int setNumber) {
      int oldValue = this.textValueSetNum;
      this.textValueSetNum = setNumber;

      boolean changeValues = true;
    if (setNumber == 0) {
      // This should default back to the Window set number
      setNumber = UIutils.getDefaultMessageSet(this);
      if (setNumber <= 0) {
        // There's no valid set loaded, so do nothing.
        changeValues = false;
      }
    }

    if (changeValues) {
      Array_Of_ListElement<ListElement>elements = getElementList();
        for (ListElement thisElement : elements) {
            if (thisElement.getTextValueMsgNum() > 0) {
              int msgNumber = thisElement.getTextValueMsgNum();
              String result = MsgCatalog.getInstance().getString(setNumber, msgNumber);
              if (thisElement.getTextValue().compare(result) != 0) {
                thisElement.getTextValue().setValue(result);
              }
            }
        }
    }
      firePropertyChange("textValueSetNum", oldValue, setNumber);
      updateSize();
    }
    /**
     * Return the message catalog set number associated with the elements in the
     * list.
     * @return
     */
    public int getTextValueSetNum() {
      return this.textValueSetNum;
    }

    private void setDefault(SelectionInList list) {
    boolean requiresDefault = false;
    if (getModel().getSize() > 0) {
      if (list == null) {
        requiresDefault = true;
      }
      else if (list.getSelectionHolder() == null) {
        requiresDefault = true;
      }
      else {
        ValueModel model = list.getSelectionHolder();
        if (model instanceof TypeAwareValueModel) {
          if (DataValue.class.isAssignableFrom(((TypeAwareValueModel)model).getValueType())) {
            requiresDefault = false;
          }
          else {
            requiresDefault = true;
          }
        }
        else {
          requiresDefault = (model.getValue() == null);
        }
      }
      if (requiresDefault) {
        // TF:05/11/2008:Fixed this up so it actually sets the underlying model
        getSelectionModel().setSelectionInterval(0, 0);
        list.getSelectionHolder().setValue(getSelectedValue());
      }
    }
    }

    /**
     * Set the selection model. Note that radio lists always display a valid value unless mapped to a class type
     */
    @Override
    public void setSelectionModel(ListSelectionModel selectionModel) {
      if (selectionModel instanceof ReadOnlyListSelectionModel) {
        editable = false;
      }
      else {
        editable = true;
      }
      super.setSelectionModel(selectionModel);
      if (!isCalledFromSetEditable) {
        if (getModel() instanceof RadioListModel) {
          setDefault(((RadioListModel)getModel()).list);
        }
        if (selectionModel != null) {
            selectionModel.addListSelectionListener(new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting() && getSelectedIndex() < 0 && getModel() instanceof RadioListModel) {
                  RadioListModel model = (RadioListModel)getModel();
                  setDefault( model.list );
                }
                // TF:20/04/2009:DET-94:We need to ensure that the data changed flag is set even if no-one is listening
                // for the AfterValueChange event on this component. Note that the setDataChangedFlag method will
                // automatically take care of setting the flag only if the user is pressing a radio button
                UIutils.setDataChangedFlag(RadioList.this);
              }
            });
        }
      }
    }
}
TOP

Related Classes of DisplayProject.RadioList

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.