DroppableXYGraph.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 package com.generalrobotix.ui.view.graph;
11 
12 import org.eclipse.swt.widgets.Composite;
13 import java.awt.*;
14 import java.awt.event.*;
15 import java.awt.datatransfer.*;
16 import java.awt.dnd.*;
17 
24 public class DroppableXYGraph
25  extends XYLineGraph
26  implements DropTargetListener
27 {
28  private Object droppedObject_; // ドロップされたオブジェクト
29  DropTarget dropTarget_; // ドロップターゲット
30  ActionListener actionListener_; // アクションリスナ
31 
32  boolean dropSucceeded_;
33 
34  // -----------------------------------------------------------------
35  // コンストラクタ
45  Composite parent,
46  int leftMargin, // 左マージン
47  int rightMargin, // 右マージン
48  int topMargin, // 上マージン
49  int bottomMargin // 下マージン
50  ) {
51  super(parent, leftMargin, rightMargin, topMargin, bottomMargin);
52  //TODO hattori
53  /*
54  dropTarget_ = new DropTarget(
55  this,
56  DnDConstants.ACTION_COPY_OR_MOVE,
57  this,
58  true
59  );
60  */
61  droppedObject_ = null;
62  dropSucceeded_ = true;
63  }
64 
65  // -----------------------------------------------------------------
66  // インスタンスメソッド
72  public void setDropActive(
73  boolean active
74  ) {
75  dropTarget_.setActive(active);
76  }
77 
83  public Object getDroppedObject() {
84  return droppedObject_;
85  }
86 
87  public void setDropSucceeded(boolean flag) {
88  dropSucceeded_ = flag;
89  }
90 
91  // -----------------------------------------------------------------
92  // ActionListener登録および削除
93  public void addActionListener(ActionListener listener) {
94  actionListener_ = AWTEventMulticaster.add(actionListener_, listener);
95  }
96  public void removeActionListener(ActionListener listener) {
97  actionListener_ = AWTEventMulticaster.remove(actionListener_, listener);
98  }
99 
100  // -----------------------------------------------------------------
101  // DropTargetListenerの実装
107  public void drop(DropTargetDropEvent evt) {
108  if (
109  evt.isDataFlavorSupported(AttributeInfo.dataFlavor)
110  && (
111  evt.getDropAction()
112  & DnDConstants.ACTION_COPY_OR_MOVE
113  ) != 0
114  ) { // 受け入れ可?
115  evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); // ドロップ受け入れ
116  try {
117  Transferable tr = evt.getTransferable();
118  if (tr.isDataFlavorSupported(AttributeInfo.dataFlavor)){
119  droppedObject_ = tr.getTransferData(AttributeInfo.dataFlavor);
120  if(actionListener_ != null) {
121  actionListener_.actionPerformed(
122  new ActionEvent(
123  this,
124  ActionEvent.ACTION_PERFORMED,
125  "Dropped"
126  )
127  );
128  }
129  evt.dropComplete(dropSucceeded_);
130  } else {
131  System.err.println("サポートしないフレーバ");
132  evt.dropComplete(false);
133  }
134  } catch (Exception ex) {
135  ex.printStackTrace();
136  System.err.println("ドロップ失敗");
137  evt.dropComplete(false);
138  }
139  } { // 受け入れ不可?
140  evt.rejectDrop(); // ドロップ不許可通知
141  evt.dropComplete(false); // ドロップ失敗通知
142  }
143  }
144 
150  public void dragEnter(DropTargetDragEvent evt) {
151  if (
152  evt.isDataFlavorSupported(AttributeInfo.dataFlavor)
153  && (evt.getSourceActions() & DnDConstants.ACTION_COPY_OR_MOVE) != 0 // 受け入れ可?
154  ) {
155  evt.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); // ドラッグを受け入れる
156  } else {
157  evt.rejectDrag(); // ドラッグ受け入れ拒否
158  }
159  }
160 
161  public void dragExit(DropTargetEvent evt) {}
162  public void dragOver(DropTargetDragEvent evt) {}
163  public void dropActionChanged(DropTargetDragEvent evt) {}
164 }
#define null
our own NULL pointer
Definition: IceTypes.h:57
DroppableXYGraph(Composite parent, int leftMargin, int rightMargin, int topMargin, int bottomMargin)
org
png_infop png_uint_32 flag
Definition: png.h:2159


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:21