DroppableXYGraph.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
00009  */
00010 package com.generalrobotix.ui.view.graph;
00011 
00012 import org.eclipse.swt.widgets.Composite;
00013 import java.awt.*;
00014 import java.awt.event.*;
00015 import java.awt.datatransfer.*;
00016 import java.awt.dnd.*;
00017 
00024 public class DroppableXYGraph
00025     extends XYLineGraph
00026     implements DropTargetListener
00027 {
00028     private Object droppedObject_;  // ドロップされたオブジェクト
00029     DropTarget dropTarget_;         // ドロップターゲット
00030     ActionListener actionListener_; // アクションリスナ
00031 
00032     boolean dropSucceeded_;
00033 
00034     // -----------------------------------------------------------------
00035     // コンストラクタ
00044     public DroppableXYGraph(
00045         Composite parent,
00046         int leftMargin,     // 左マージン
00047         int rightMargin,    // 右マージン
00048         int topMargin,      // 上マージン
00049         int bottomMargin    // 下マージン
00050     ) {
00051         super(parent, leftMargin, rightMargin, topMargin, bottomMargin);
00052         //TODO hattori
00053         /*
00054         dropTarget_ = new DropTarget(
00055             this,
00056             DnDConstants.ACTION_COPY_OR_MOVE,
00057             this,
00058             true
00059         );
00060         */
00061         droppedObject_ = null;
00062         dropSucceeded_ = true;
00063     }
00064 
00065     // -----------------------------------------------------------------
00066     // インスタンスメソッド
00072     public void setDropActive(
00073         boolean active
00074     ) {
00075         dropTarget_.setActive(active);
00076     }
00077 
00083     public Object getDroppedObject() {
00084         return droppedObject_;
00085     }
00086 
00087     public void setDropSucceeded(boolean flag) {
00088         dropSucceeded_ = flag;
00089     }
00090 
00091     // -----------------------------------------------------------------
00092     // ActionListener登録および削除
00093     public void addActionListener(ActionListener listener) {
00094         actionListener_ = AWTEventMulticaster.add(actionListener_, listener);
00095     }
00096     public void removeActionListener(ActionListener listener) {
00097         actionListener_ = AWTEventMulticaster.remove(actionListener_, listener);
00098     }
00099 
00100     // -----------------------------------------------------------------
00101     // DropTargetListenerの実装
00107     public void drop(DropTargetDropEvent evt) {
00108         if (
00109             evt.isDataFlavorSupported(AttributeInfo.dataFlavor)
00110             && (
00111                 evt.getDropAction()
00112                 & DnDConstants.ACTION_COPY_OR_MOVE
00113             ) != 0
00114         ) { // 受け入れ可?
00115             evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);   // ドロップ受け入れ
00116             try {
00117                 Transferable tr = evt.getTransferable();
00118                 if (tr.isDataFlavorSupported(AttributeInfo.dataFlavor)){
00119                     droppedObject_ = tr.getTransferData(AttributeInfo.dataFlavor);
00120                     if(actionListener_ != null) {
00121                         actionListener_.actionPerformed(
00122                             new ActionEvent(
00123                                 this,
00124                                 ActionEvent.ACTION_PERFORMED,
00125                                 "Dropped"
00126                             )
00127                         );
00128                     }
00129                     evt.dropComplete(dropSucceeded_);
00130                 } else {
00131                     System.err.println("サポートしないフレーバ");
00132                     evt.dropComplete(false);
00133                 }
00134             } catch (Exception ex) {
00135                 ex.printStackTrace();
00136                 System.err.println("ドロップ失敗");
00137                 evt.dropComplete(false);
00138             }
00139         } { // 受け入れ不可?
00140             evt.rejectDrop();           // ドロップ不許可通知
00141             evt.dropComplete(false);    // ドロップ失敗通知
00142         }
00143     }
00144 
00150     public void dragEnter(DropTargetDragEvent evt) {
00151         if (
00152             evt.isDataFlavorSupported(AttributeInfo.dataFlavor)
00153             && (evt.getSourceActions() & DnDConstants.ACTION_COPY_OR_MOVE) != 0 // 受け入れ可?
00154         ) {
00155             evt.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);   // ドラッグを受け入れる
00156         } else {
00157             evt.rejectDrag();   // ドラッグ受け入れ拒否
00158         }
00159     }
00160 
00161     public void dragExit(DropTargetEvent evt) {}
00162     public void dragOver(DropTargetDragEvent evt) {}
00163     public void dropActionChanged(DropTargetDragEvent evt) {}
00164 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16