Package net.helipilot50.stocktrade.displayproject

Source Code of net.helipilot50.stocktrade.displayproject.ScrollListModel

/*
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 net.helipilot50.stocktrade.displayproject;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import net.helipilot50.stocktrade.displayproject.binding.list.SelectionInList;
import net.helipilot50.stocktrade.framework.Array_Of_ListElement;
import net.helipilot50.stocktrade.framework.ListElement;
import net.helipilot50.stocktrade.framework.TextData;


/**
* This selection model is used by {@link net.helipilot50.stocktrade.displayproject.controls.ScrollList}
*/
@SuppressWarnings("serial")
public class ScrollListModel extends DefaultListModel implements ListSelectionListener {
  // TF:Cleaned this up and separated the GUI concerns from the model concerns. Also removed the implementation of ListSelectionListener interface
    protected JList scrollList;
    protected SelectionInList list;
    protected boolean isSingleSelect;
    // TF:26/07/2009:Moved this to the control rather than storing Gui information in the model
//  private int widthForModel = 0;

  // Removed this as it should never be called.
//    public ScrollListModel() {
//        super();
//    }

    public ScrollListModel(SelectionInList pModel, JList pList, boolean pIsSingleSelect) {
        super();
        this.list = pModel;
        this.scrollList = pList;
        this.isSingleSelect = pIsSingleSelect;
       
        // TF:26/07/2009:Added in the listener at the logical point, here, not each control
        scrollList.addListSelectionListener(this);
    }

    // TF:26/07/2009:Removed this as it's not needed.
//    public ValueModel getSelectionIndexHolder() {
//        return list.getSelectionIndexHolder();
//    }

    // TF:26/07/2009:Removed this as it's not needed.
//    public JList getScrollList() {
//        return scrollList;
//    }

    // TF:26/07/2009:Removed this as it's not needed.
//    public void setScrollList(JList scrollList) {
//        this.scrollList = scrollList;
//    }

    public Object getElementAt(int index) {
        return this.list.getElementAt(index);
        //return scrollList.getElementList().get(index);
    }
    public int getSize() {
        return this.list.getSize();
        //return scrollList.getElementList().size();
    }

    public void addListDataListener(ListDataListener l) {
        this.list.removeListDataListener(l);
        this.list.addListDataListener(l);
    }

    public void removeListDataListener(ListDataListener l) {
        this.list.removeListDataListener(l);
    }

    public void valueChanged(ListSelectionEvent ev) {
      // TF:26/07/2009:Removed this method as it's covered by the AfterValueChangeListener and the ChildAfterValueChangeListener
      // We cannot remove it totally as old code explicitly sets it and removing it results in compile errors.
//        if (!ev.getValueIsAdjusting() && EventManager.isPostingEnabled()){
//            //ListElement le = (ListElement)scrollList.getSelectedValue();
//            ClientEventManager.postEvent( ev.getSource(), "AfterValueChange" );
//            UIutils.setDataChangedFlag((JComponent)ev.getSource());
//
//            // TF:27/9/07:Revamped to use new event poster
//            ChildEventHelper.postEventToAllParents((Component)ev.getSource(), "ChildAfterValueChange");
//        }
    }

    public int getIntegerValue() {
        if (scrollList != null) {
            int index = this.list.getSelectionIndex();
            ListElement el = (ListElement)this.list.getElementAt(index);
            return el == null ? 0 : el.getIntegerValue();
        }
        else
            return 0;
    }

    public Object getObjectValue() {
        if (scrollList != null) {
            int index = this.list.getSelectionIndex();
            ListElement el = (ListElement)this.list.getElementAt(index);
            return el == null ? null : el.getObjectValue();
        }
        else
            return null;
    }

    public TextData getTextValue() {
        if (scrollList != null) {
            int index = this.list.getSelectionIndex();
            ListElement el = (ListElement)this.list.getElementAt(index);
            return el == null ? null : el.getTextValue();
        }
        else
            return null;
    }

    public void setIntegerValue(int value) {
        if (scrollList != null) {
            int limit = this.list.getSize();
            for (int i = 0; i < limit; i++) {
                ListElement el = (ListElement)this.list.getElementAt(i);
                if (el.getIntegerValue() == value) {
                    this.list.setSelection(el);
                    return;
                }
            }
        }
    }

    public void setObjectValue(Object value) {
        if (scrollList != null) {
            if (scrollList != null) {
                int limit = this.list.getSize();
                for (int i = 0; i < limit; i++) {
                    ListElement el = (ListElement)this.list.getElementAt(i);
                    if (el.getObjectValue() != null && el.getObjectValue().equals(value)) {
                        this.list.setSelection(el);
                        return;
                    }
                }
            }
        }
    }

    public void setTextValue(TextData value) {
        if (scrollList != null) {
            if (scrollList != null) {
                int limit = this.list.getSize();
                for (int i = 0; i < limit; i++) {
                    ListElement el = (ListElement)this.list.getElementAt(i);
                    if (el.getTextValue() == value) {
                        this.list.setSelection(el);
                        return;
                    }
                }
            }
        }
    }

    /**
     * Return a copy of the data in the underlying list.
     * @return
     */
    public Array_Of_ListElement<ListElement> getElementList() {
        Array_Of_ListElement<ListElement> result = new Array_Of_ListElement<ListElement>();
        for (int i = 0; i < this.list.getSize(); i++) {
            result.add((ListElement)this.getElementAt(i));
        }
        return result;
    }

    public void setElementList(Array_Of_ListElement<ListElement> les) {
        Object currentValue = this.list.getValue();
        this.list.setList(les);
        //scrollList.setElementList(les);
        if (this.isSingleSelect) {
            this.list.setValue(currentValue);
            if (this.list.getValue() == null && les.size() > 0) {
                // Always default the first one in the list if needed
                this.list.setValue(les.get(0));
                scrollList.setSelectedIndex(0);
            }
            this.scrollList.invalidate();
        }
        this.fireContentsChanged(this, 0, les.size()-1);
    }
   
    // TF:26/07/2009:Removed this as it's not needed. (It's a GUI concern, moved to the control)
//    public int getSelectedIndex() {
//        return scrollList.getSelectedIndex();
//    }

    // TF:26/07/2009:Removed this as it's not needed. (It's a GUI concern, moved to the control)
//    public void setSelectedIndex(int index) {
//        scrollList.setSelectedIndex(index);
//    }
   
  /* (non-Javadoc)
   * @see com.lumley.gennetica.genneticaframework.displayproject.ListField#setElementSelected(int, boolean)
     * @author AD:26/5/2008
   */
    // TF:26/07/2009:Removed this as it's not needed.
//  public void setElementSelected(int index, boolean isSelected) {
//    ((ScrollList)scrollList).setElementSelected(index, isSelected);
//  }

    // TF:26/07/2009:Removed this as it's not needed. (It's a GUI concern, moved to the control)
//  /**
//     * CraigM:08/01/2009 - Return the required width to show the data
//     */
//    public int getWidthForModel() {
//      return this.widthForModel;
//    }
}
TOP

Related Classes of net.helipilot50.stocktrade.displayproject.ScrollListModel

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.