Package net.helipilot50.stocktrade.displayproject.events

Source Code of net.helipilot50.stocktrade.displayproject.events.TextMenuStatusChangedListener

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

import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.FlavorEvent;
import java.awt.datatransfer.FlavorListener;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.Hashtable;

import net.helipilot50.stocktrade.displayproject.Constants;
import net.helipilot50.stocktrade.displayproject.WindowSystem;
import net.helipilot50.stocktrade.framework.ParameterHolder;


/**
* This class provide similar event behaviour to the Forte event TextMenuStatusChange.
* @author Peter
* @since 11/4/08
*
*/
public class TextMenuStatusChangedListener implements InstallableListener, FlavorListener {

    int cutState = Constants.MS_USAGESTATE; //Constants.MS_ENABLED
    int copyState = Constants.MS_USAGESTATE; //Constants.MS_ENABLED
    int pasteState = Constants.MS_USAGESTATE; //Constants.MS_ENABLED
    int deleteState = Constants.MS_USAGESTATE;//Constants.MS_ENABLED
    int selectAllState = -1; //Constants.CT_SELECTALL
    int undoState = -1; //Constants.CT_UNDO
    int redoState = -1; //Constants.CT_REDO

  public void install(Object o, String event) {
    Clipboard cb = WindowSystem.getClipboard();
    cb.addFlavorListener(this);   

  }

  public void flavorsChanged(FlavorEvent e) {
        Clipboard cb = (Clipboard) e.getSource();
       
        Transferable contents = cb.getContents(this);
        if (contents != null){
          try {
            if (contents.getTransferData(DataFlavor.stringFlavor) != null){
              setPasteState(Constants.MS_ENABLED);
            } else {
              setPasteState(Constants.MS_DISABLED);
            }
          } catch (UnsupportedFlavorException e1) {
           
          } catch (IOException e1) {
           
          }
        }

  }

    /**
     * Fires the TextMenuStatusChanged event
     * @param cutState Constants.MS_DISABLED or Constants.MS_ENABLED
     * @param copyState Constants.MS_DISABLED or Constants.MS_ENABLED
     * @param pasteState Constants.MS_DISABLED or Constants.MS_ENABLED
     * @param deleteState Constants.MS_DISABLED or Constants.MS_ENABLED
     * @param selectAllState Constants.CT_SELECTALL
     * @param undoState Constants.CT_UNDO
     * @param redoState Constants.CT_REDO
     */
    public void fireTextMenuStatusChanged(int cutState, int copyState, int pasteState, int deleteState, int selectAllState, int undoState, int redoState){
        Hashtable<String, ParameterHolder> params = new Hashtable<String, ParameterHolder>();
        params.put("CutState", new ParameterHolder(cutState));
        params.put("CopyState", new ParameterHolder(copyState));
        params.put("PasteState", new ParameterHolder(pasteState));
        params.put("DeleteState", new ParameterHolder(deleteState));
        params.put("SelectAllState", new ParameterHolder(selectAllState));
        params.put("UndoState", new ParameterHolder(undoState));
        params.put("RedoState", new ParameterHolder(redoState));
        ClientEventManager.postEvent(WindowSystem.class, "TextMenuStatusChange", params);  

    }

  public int getCutState() {
    return cutState;
  }

  public void setCutState(int cutState) {
    if(cutState != this.cutState) {
    this.cutState = cutState;
        fireTextMenuStatusChanged(cutState, copyState, pasteState, deleteState, selectAllState, undoState, redoState)
    }
  }

  public int getCopyState() {
    return copyState;
  }

  public void setCopyState(int copyState) {
    if(copyState != this.copyState) {
    this.copyState = copyState;
        fireTextMenuStatusChanged(cutState, copyState, pasteState, deleteState, selectAllState, undoState, redoState)
    }
  }

  public int getPasteState() {
    return pasteState;
  }

  public void setPasteState(int pasteState) {
    if(pasteState != this.pasteState) {
    this.pasteState = pasteState;
        fireTextMenuStatusChanged(cutState, copyState, pasteState, deleteState, selectAllState, undoState, redoState)
    }
  }

  public int getDeleteState() {
    return deleteState;
  }

  public void setDeleteState(int deleteState) {
    if(deleteState != this.deleteState) {
    this.deleteState = deleteState;
        fireTextMenuStatusChanged(cutState, copyState, pasteState, deleteState, selectAllState, undoState, redoState)
    }
  }

  public int getSelectAllState() {
    return selectAllState;
  }

  public void setSelectAllState(int selectAllState) {
    if(selectAllState != this.selectAllState) {
    this.selectAllState = selectAllState;
        fireTextMenuStatusChanged(cutState, copyState, pasteState, deleteState, selectAllState, undoState, redoState)
    }
  }

  public int getUndoState() {
    return undoState;
  }

  public void setUndoState(int undoState) {
    if(undoState != this.undoState) {
    this.undoState = undoState;
        fireTextMenuStatusChanged(cutState, copyState, pasteState, deleteState, selectAllState, undoState, redoState)
    }
  }

  public int getRedoState() {
    return redoState;
  }

  public void setRedoState(int redoState) {
    if(redoState != this.redoState) {
    this.redoState = redoState;
        fireTextMenuStatusChanged(cutState, copyState, pasteState, deleteState, selectAllState, undoState, redoState)
    }
  }

  public void setSelectedTextState(int value) {
    if(value != this.cutState) {
    this.cutState = value;
    this.copyState = value;
    this.deleteState = value;
        fireTextMenuStatusChanged(cutState, copyState, pasteState, deleteState, selectAllState, undoState, redoState)
    }
  }
 
 
}
TOP

Related Classes of net.helipilot50.stocktrade.displayproject.events.TextMenuStatusChangedListener

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.