use of java.awt.dnd.DropTarget in project openchemlib by Actelion.
the class JDrawArea method initializeDragAndDrop.
private void initializeDragAndDrop(int dropAction) {
if (dropAction != DnDConstants.ACTION_NONE) {
MoleculeDropAdapter d = new MoleculeDropAdapter() {
public void onDropMolecule(StereoMolecule m, Point pt) {
if (m != null && m.getAllAtoms() != 0) {
for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
// deselect all current atoms
mMol.setAtomSelection(atom, false);
}
double avbl = mMol.getAverageBondLength();
double dropAVBL = m.getAverageBondLength();
m.scaleCoords(avbl / dropAVBL);
Point cog = new Point();
for (int atom = 0; atom < m.getAllAtoms(); atom++) {
// select all new atoms
m.setAtomSelection(atom, true);
cog.x += m.getAtomX(atom);
cog.y += m.getAtomY(atom);
}
cog.x /= m.getAllAtoms();
cog.y /= m.getAllAtoms();
m.translateCoords(pt.x - cog.x, pt.y - cog.y);
m.removeAtomColors();
m.removeBondHiliting();
mMol.addMolecule(m);
fireMoleculeChanged();
update(UPDATE_CHECK_COORDS);
}
}
};
new DropTarget(this, dropAction, d, true, new OurFlavorMap());
}
}
use of java.awt.dnd.DropTarget in project GCViewer by chewiebug.
the class TestGCModelLoaderController method dropOnDesktopPane.
/**
* Test drag and drop action on GCViewerGui.
*/
@Test
public void dropOnDesktopPane() throws Exception {
// TODO SWINGWORKER: test drag and drop on GCDocument
assertThat("number of gcdocuments before", controller.getGCViewerGui().getDesktopPane().getAllFrames().length, is(0));
List<File> fileList = new ArrayList<File>();
fileList.add(new File(UnittestHelper.getResource(FOLDER.OPENJDK, "SampleSun1_6_0G1_MarkStackFull.txt").getPath()));
Transferable tr = Mockito.mock(Transferable.class);
Mockito.when(tr.getTransferData(DataFlavor.javaFileListFlavor)).thenReturn(fileList);
DropTargetDropEvent dte = Mockito.mock(DropTargetDropEvent.class);
Mockito.when(dte.isDataFlavorSupported(DataFlavor.javaFileListFlavor)).thenReturn(true);
Mockito.when(dte.getTransferable()).thenReturn(tr);
DropTarget target = controller.getGCViewerGui().getDesktopPane().getDropTarget();
target.drop(dte);
assertThat("number of gcdocuments after drop", controller.getGCViewerGui().getDesktopPane().getAllFrames().length, is(1));
}
use of java.awt.dnd.DropTarget in project bytecode-viewer by Konloch.
the class FileDrop method makeDropTarget.
// END 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.
private void makeDropTarget(final PrintStream out, final Component c, final boolean recursive) {
// Make drop target
final DropTarget dt = new DropTarget();
try {
dt.addDropTargetListener(dropListener);
}// end try
catch (final java.util.TooManyListenersException e) {
BytecodeViewer.handleException(e);
log(out, "FileDrop: Drop will not work due to previous error. Do you have another listener attached?");
}
// end catch
// Listen for hierarchy changes and remove the drop target when the
// parent gets cleared out.
// end hierarchyChanged
c.addHierarchyListener(evt -> {
log(out, "FileDrop: Hierarchy changed.");
final Component parent = c.getParent();
if (parent == null) {
c.setDropTarget(null);
log(out, "FileDrop: Drop target cleared from component.");
} else // end if: null parent
{
new DropTarget(c, dropListener);
log(out, "FileDrop: Drop target added to component.");
}
// end else: parent not null
});
// end hierarchy listener
if (c.getParent() != null) {
new DropTarget(c, dropListener);
}
if (recursive && (c instanceof Container)) {
// Get the container
final Container cont = (Container) c;
// Get its components
final Component[] comps = cont.getComponents();
// Set its components as listeners also
for (Component comp : comps) {
makeDropTarget(out, comp, true);
}
}
// end if: recursively set components as listener
}
use of java.awt.dnd.DropTarget in project GCViewer by chewiebug.
the class GCModelLoaderControllerImpl method openGCResource.
private void openGCResource(GCResource gcResource, GCModelLoader loader) {
GCDocument document = new GCDocument(gcViewerGui.getPreferences(), gcResource.getResourceName());
document.setDropTarget(new DropTarget(document, DnDConstants.ACTION_COPY, new FileDropTargetListener(this, DropFlavor.ADD)));
document.addInternalFrameListener(new GCViewerGuiInternalFrameController());
gcViewerGui.addDocument(document);
GCDocumentController docController = new GCDocumentController(document);
docController.addGCResource(loader, getViewMenuController());
loader.execute();
}
use of java.awt.dnd.DropTarget in project airavata by apache.
the class GraphCanvas method initGUI.
/**
* Initializes the GUI.
*/
private void initGUI() {
this.panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
GraphCanvas.this.paintComponent((Graphics2D) g);
}
};
this.panel.setLayout(null);
// To make the background color visible.
this.panel.setOpaque(true);
this.panel.setBackground(new Color(255, 255, 255));
this.panel.setDoubleBuffered(true);
this.panel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
GraphCanvas.this.mouseClicked(event);
}
@Override
public void mousePressed(MouseEvent event) {
GraphCanvas.this.mousePressed(event);
}
@Override
public void mouseReleased(MouseEvent event) {
GraphCanvas.this.mouseReleased(event);
notifyListeners(new GraphCanvasEvent(GraphCanvasEvent.GraphCanvasEventType.WORKFLOW_CHANGED, GraphCanvas.this, GraphCanvas.this.workflow));
}
});
this.panel.addMouseMotionListener(new MouseMotionListener() {
public void mouseDragged(MouseEvent event) {
GraphCanvas.this.mouseDragged(event);
}
public void mouseMoved(MouseEvent event) {
GraphCanvas.this.mouseMoved(event);
}
});
this.panel.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
GraphCanvas.this.keyPressed(event);
}
@Override
public void keyReleased(KeyEvent event) {
GraphCanvas.this.keyReleased(event);
}
});
this.scrollPane = new JScrollPane(this.panel);
// Set up drag and drop
DropTargetListener dropTargetListener = new DropTargetAdapter() {
public void drop(DropTargetDropEvent event) {
GraphCanvas.this.drop(event);
}
};
new DropTarget(this.panel, DnDConstants.ACTION_COPY_OR_MOVE, dropTargetListener);
createPopupMenu();
}
Aggregations