Package net.helipilot50.stocktrade.displayproject

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

/*
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;

/*"*****************************************************************************
Author      :  Craig Mitchell
Creation Date :  21/06/2005
Functionality : 

Last Author    : 
Last Update    : 
Last Changes  : 
*********1*********2*********3*********4*********5*********6*********7*********/


import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Hashtable;

import javax.swing.JList;
import javax.swing.KeyStroke;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import net.helipilot50.stocktrade.displayproject.events.ClientEventManager;
import net.helipilot50.stocktrade.framework.DynamicArray;
import net.helipilot50.stocktrade.framework.ErrorMgr;
import net.helipilot50.stocktrade.framework.ParameterHolder;
import net.helipilot50.stocktrade.framework.UsageException;


/**
* @author Craig Mitchell 22/06/2005.
* @version 1.0
*
* @author Peter
* @version 1.1
* added behaviour to mimic listview in Image Mode
* added forte event AfterCurrentNodeChange
* added forte mouse events
*
* A JListView is a view that mimics the windows file explorer view.
* Able to show large icons.
* Has windows like selection.
* Has drag and drop ability.
* Has double click and keyboard enter, space, and esc listeners.
*/
@Deprecated
@SuppressWarnings("serial")
public class JListView extends JList implements MouseListener, KeyListener, FocusListener {
private DisplayNode oldNode = null;
private DisplayNode currentNode = null;
private int oldRow = -1;
private int currentRow = -1;
private int ListStyle = Constants.LT_IMAGE;


public JListView(int Style) {
    super();
    this.setAutoscrolls(true);
    this.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    new DisplayNodeDragListener(this);
    this.addMouseListener(this);
    this.addKeyListener(this);
    this.addFocusListener(this);
    this.addMouseListener(new ForteMouseAdapter(this));
    this.addListSelectionListener(new ListSelectionListener(){

        public void valueChanged(ListSelectionEvent ev) {
            if (!ev.getValueIsAdjusting()){
                oldNode = currentNode;
                currentNode = ((DisplayNode)getSelectedValue());
                oldRow = currentRow;
                currentRow = ev.getFirstIndex();
                Hashtable<String, Object> qq_Params = new Hashtable<String, Object>();
                qq_Params.put( "OldNode", new ParameterHolder(oldNode) );
                qq_Params.put( "NewNode", new ParameterHolder( currentNode ));
                qq_Params.put( "OldRowNumber", new ParameterHolder(oldRow) );
                qq_Params.put( "NewRowNumber", new ParameterHolder(currentRow) );
                ClientEventManager.postEvent( ev.getSource(), "AfterCurrentNodeChange", qq_Params );
            }
        }

    });
    this.setListStyle(Style);
    this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), PsuedoDoubleClickAction.PSUED0_DOUBLE_CLICK);
    this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_MASK),PsuedoDoubleClickAction.PSUED0_DOUBLE_CLICK);
    this.getActionMap().put(PsuedoDoubleClickAction.PSUED0_DOUBLE_CLICK, new PsuedoDoubleClickAction());

}

/**
* When a user double clicks or presses enter, this method is called.
* @param pItem = The item that was selected.
*/
public void itemSelected(DisplayNode pItem){

}

/**
* This method is called when a key is pressed that is not an arrow key,
* enter, space, or the escape key.
* @param pKey = The key event that was received.
*/
public void keyHandler(KeyEvent pKey) {
}

/**
* Set the data for the list.
* @param pData = The data which must be of type DisplayNode[]
*/
public final void setListData(Object[] pData) {
    if (pData != null) {
        if (pData instanceof DisplayNode[]) {
            int aIndex = this.getSelectedIndex();
            super.setListData(pData);
            if (pData.length-1 < aIndex) {
                aIndex = pData.length-1;
            }
            this.setSelectedIndex(aIndex);
        }
        else {
            UsageException errorVar = new UsageException("pData must be of type DisplayNode[]");
            ErrorMgr.addError(errorVar);
            throw errorVar;
        }
    }
    else {
        UsageException errorVar = new UsageException("pData must not be null");
        ErrorMgr.addError(errorVar);
        throw errorVar;
    }
}
/**
* Set the View Nodes for the list.
* @param pData = The data which must be of type DynamicArray
*/
public final void setViewNodes(DynamicArray<Object> pData) {
    if (pData != null) {
        //  if (pData.getItemType().isInstance(DisplayNode.class)) {
        int aIndex = this.getSelectedIndex();
        super.setListData(pData.toArray());
        if (pData.size()-1 < aIndex) {
            aIndex = pData.size()-1;
        }
        this.setSelectedIndex(aIndex);
        //  }
        //  else {
        //    throw new UsageException("pData must be of type Array_Of_DisplayNode");
        //  }
    }
    else {
        UsageException errorVar = new UsageException("pData must not be null");
        ErrorMgr.addError(errorVar);
        throw errorVar;

    }
}

public final void mouseClicked(MouseEvent e) {
    // Double click
    if (e.getClickCount() % 2 == 0) {
        Object aSelected = this.getSelectedValue();

        if (aSelected != null && aSelected instanceof DisplayNode) {
            this.itemSelected((DisplayNode)aSelected);
        }
    }
}

public final void mouseEntered(MouseEvent e) {
}

public final void mouseExited(MouseEvent e) {
}

public final void mousePressed(MouseEvent e) {
}

public final void mouseReleased(MouseEvent e) {
}

public final void keyPressed(KeyEvent e) {
    int aKey = e.getKeyCode();

    if (aKey == KeyEvent.VK_ENTER || aKey == KeyEvent.VK_SPACE) {
        Object aSelected = this.getSelectedValue();

        if (aSelected != null && aSelected instanceof DisplayNode) {
            this.itemSelected((DisplayNode)aSelected);
            /*
             * fire the doubleClick mouse event
             */

        }
    }
    else if (aKey == KeyEvent.VK_ESCAPE) {
        this.clearSelection();
    }
    this.keyHandler(e);
}

public final void keyReleased(KeyEvent e) {
}

public final void keyTyped(KeyEvent e) {
}

public final void focusGained(FocusEvent e) {
    if (this.getSelectedValue() == null) {
        this.setSelectedIndex(0);
    }
}

public final void focusLost(FocusEvent e) {
}

public DisplayNode getCurrentNode() {
    return currentNode;
}
public void setCurrentNode(DisplayNode currentNode) {
    this.setSelectedValue(currentNode, true);
    this.currentNode = currentNode;

}

//public void setCurrentNode(DisplayNode currentNode) {
//  this.currentNode = currentNode;
//}

public int getListStyle() {
    return ListStyle;
}

public void setListStyle(int listStyle) {
    ListStyle = listStyle;
    switch (ListStyle) {
    case Constants.LT_SMALLICON:
        this.setLayoutOrientation(JList.HORIZONTAL_WRAP);
        this.setVisibleRowCount(0);
        //this.setFixedCellHeight(30);
        this.setCellRenderer(new DisplayNodeRenderer(DisplayNodeRenderer.SMALL_ICON));
        break;
    case Constants.LT_IMAGE:
        this.setLayoutOrientation(JList.HORIZONTAL_WRAP);
        this.setVisibleRowCount(0);
        //this.setFixedCellHeight(75);
        this.setFixedCellWidth(95);
        this.setCellRenderer(new DisplayNodeRenderer(DisplayNodeRenderer.LARGE_ICON));
        break;
    case Constants.LT_LIST:
        this.setLayoutOrientation(JList.VERTICAL_WRAP);
        this.setVisibleRowCount(0);
        //this.setFixedCellHeight(30);
        this.setCellRenderer(new DisplayNodeRenderer(DisplayNodeRenderer.SMALL_ICON));
        break;
        default:
            throw new RuntimeException(
                    "JListView.setListStyle() cannot be set to LT_DETAIL or LT_DEFAULT at runtime");

    }
}

}
TOP

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

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.