if (isLocalDrag()) updateImportCount(t); result = importGraphTransferable(graphComponent, gt);
/** * */ protected TransferHandler createTransferHandler() { return new mxGraphTransferHandler(); }
/** * */ public void exportDone(JComponent c, Transferable data, int action) { initialImportCount = 1; if (c instanceof mxGraphComponent && data instanceof mxGraphTransferable) { // Requires that the graph handler resets the location to null if the drag leaves the // component. This is the condition to identify a cross-component move. boolean isLocalDrop = location != null; if (action == TransferHandler.MOVE && !isLocalDrop) { removeCells((mxGraphComponent) c, originalCells); initialImportCount = 0; } } originalCells = null; location = null; offset = null; }
handler.setLocation(new Point(pt)); handler.setOffset(new Point((int) graph.snap(dx / scale), (int) graph.snap(dy / scale))); pt.translate(dx, dy); if (!handler.isLocalDrag() && previewBounds != null)
/** * * @param e */ public void drop(DropTargetDropEvent e) { if (canImport) { mxGraphTransferHandler handler = getGraphTransferHandler(e); MouseEvent event = createEvent(e); // Ignores the event in mouseReleased if it is // handled by the transfer handler as a drop if (handler != null && !handler.isLocalDrag()) { event.consume(); } mouseReleased(event); } }
/** * (non-Javadoc) * * @see javax.swing.TransferHandler#createTransferable(javax.swing.JComponent) */ public Transferable createTransferable(JComponent c) { if (c instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) c; mxGraph graph = graphComponent.getGraph(); if (!graph.isSelectionEmpty()) { originalCells = graphComponent.getExportableCells(graph .getSelectionCells()); if (originalCells.length > 0) { ImageIcon icon = (transferImageEnabled) ? createTransferableImage( graphComponent, originalCells) : null; return createGraphTransferable(graphComponent, originalCells, icon); } } } return null; }
/** * * @param e */ public void dragExit(DropTargetEvent e) { mxGraphTransferHandler handler = getGraphTransferHandler(e); if (handler != null) { handler.setLocation(null); } dragCells = null; setVisible(false); marker.reset(); reset(); }
/** * */ public mxGraphTransferable createGraphTransferable( mxGraphComponent graphComponent, Object[] cells, ImageIcon icon) { mxGraph graph = graphComponent.getGraph(); mxPoint tr = graph.getView().getTranslate(); double scale = graph.getView().getScale(); mxRectangle bounds = graph.getPaintBounds(cells); // Removes the scale and translation from the bounds bounds.setX(bounds.getX() / scale - tr.getX()); bounds.setY(bounds.getY() / scale - tr.getY()); bounds.setWidth(bounds.getWidth() / scale); bounds.setHeight(bounds.getHeight() / scale); return createGraphTransferable(graphComponent, cells, bounds, icon); }
/** * Gets a drop target using getDropTarget and imports the cells using * mxGraph.splitEdge or mxGraphComponent.importCells depending on the * drop target and the return values of mxGraph.isSplitEnabled and * mxGraph.isSplitTarget. Selects and returns the cells that have been * imported. */ protected Object[] importCells(mxGraphComponent graphComponent, mxGraphTransferable gt, double dx, double dy) { Object target = getDropTarget(graphComponent, gt); mxGraph graph = graphComponent.getGraph(); Object[] cells = gt.getCells(); cells = graphComponent.getImportableCells(cells); if (graph.isSplitEnabled() && graph.isSplitTarget(target, cells)) { graph.splitEdge(target, cells, dx, dy); } else { cells = graphComponent.importCells(cells, dx, dy, target, location); graph.setSelectionCells(cells); } return cells; }
.createTransferable(graphComponent);
importCells(graphComponent, gt, dx, dy); location = null; offset = null;
handler.setLocation(new Point(pt)); handler.setOffset(new Point((int) graph.snap(dx / scale), (int) graph.snap(dy / scale))); pt.translate(dx, dy); if (!handler.isLocalDrag() && previewBounds != null)
/** * * @param e */ public void drop(DropTargetDropEvent e) { if (canImport) { mxGraphTransferHandler handler = getGraphTransferHandler(e); MouseEvent event = createEvent(e); // Ignores the event in mouseReleased if it is // handled by the transfer handler as a drop if (handler != null && !handler.isLocalDrag()) { event.consume(); } mouseReleased(event); } }
/** * (non-Javadoc) * * @see javax.swing.TransferHandler#createTransferable(javax.swing.JComponent) */ public Transferable createTransferable(JComponent c) { if (c instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) c; mxGraph graph = graphComponent.getGraph(); if (!graph.isSelectionEmpty()) { originalCells = graphComponent.getExportableCells(graph .getSelectionCells()); if (originalCells.length > 0) { ImageIcon icon = (transferImageEnabled) ? createTransferableImage( graphComponent, originalCells) : null; return createGraphTransferable(graphComponent, originalCells, icon); } } } return null; }
/** * * @param e */ public void dragExit(DropTargetEvent e) { mxGraphTransferHandler handler = getGraphTransferHandler(e); if (handler != null) { handler.setLocation(null); } dragCells = null; setVisible(false); marker.reset(); reset(); }
/** * */ public mxGraphTransferable createGraphTransferable( mxGraphComponent graphComponent, Object[] cells, ImageIcon icon) { mxGraph graph = graphComponent.getGraph(); mxPoint tr = graph.getView().getTranslate(); double scale = graph.getView().getScale(); mxRectangle bounds = graph.getPaintBounds(cells); // Removes the scale and translation from the bounds bounds.setX(bounds.getX() / scale - tr.getX()); bounds.setY(bounds.getY() / scale - tr.getY()); bounds.setWidth(bounds.getWidth() / scale); bounds.setHeight(bounds.getHeight() / scale); return createGraphTransferable(graphComponent, cells, bounds, icon); }
/** * Gets a drop target using getDropTarget and imports the cells using * mxGraph.splitEdge or mxGraphComponent.importCells depending on the * drop target and the return values of mxGraph.isSplitEnabled and * mxGraph.isSplitTarget. Selects and returns the cells that have been * imported. */ protected Object[] importCells(mxGraphComponent graphComponent, mxGraphTransferable gt, double dx, double dy) { Object target = getDropTarget(graphComponent, gt); mxGraph graph = graphComponent.getGraph(); Object[] cells = gt.getCells(); cells = graphComponent.getImportableCells(cells); if (graph.isSplitEnabled() && graph.isSplitTarget(target, cells)) { graph.splitEdge(target, cells, dx, dy); } else { cells = graphComponent.importCells(cells, dx, dy, target, location); graph.setSelectionCells(cells); } return cells; }
.createTransferable(graphComponent);
importCells(graphComponent, gt, dx, dy); location = null; offset = null;
if (isLocalDrag()) updateImportCount(t); result = importGraphTransferable(graphComponent, gt);