Refine search
public void addGraphComponent(mxGraph graph) { mxGraphComponent graphComponent = new mxGraphComponent(graph); getContentPane().add(graphComponent); }
@Override public void mousePressed( final MouseEvent e ) { if ( graphComponent.isEnabled() && isEnabled() && !e.isConsumed() && !graphComponent.isForceMarqueeEvent( e ) ) { cell = graphComponent.getCellAt( e.getX(), e.getY(), false ); initialCell = cell; if ( cell != null ) { if ( isSelectEnabled() && !graphComponent.getGraph().isCellSelected( cell ) ) { graphComponent.selectCellForEvent( cell, e ); cell = null; } // Starts move if the cell under the mouse is movable // and/or any // cells of the selection are movable if ( isMoveEnabled() && !e.isPopupTrigger() ) { start( e ); e.consume(); } } } }
/** * */ public void updateDragImage(Object[] cells) { dragImage = null; if (cells != null && cells.length > 0) { Image img = mxCellRenderer.createBufferedImage( graphComponent.getGraph(), cells, graphComponent.getGraph() .getView().getScale(), null, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); if (img != null) { dragImage = new ImageIcon(img); previewBounds.setSize(dragImage.getIconWidth(), dragImage.getIconHeight()); } } }
public void mouseReleased(MouseEvent e) { if (isEnabled()) { if (!e.isConsumed() && isEditEvent(e)) { Object cell = getCellAt(e.getX(), e.getY(), false); if (cell != null && getGraph().isCellEditable(cell)) { startEditingAtCell(cell, e); } } else { // Other languages use focus traversal here, in Java // we explicitely stop editing after a click elsewhere stopEditing(!invokesStopCellEditing); } } }
/** * Draws the preview using the graphics canvas. */ protected void paintPreview(mxGraphics2DCanvas canvas) { graphComponent.getGraphControl().drawCell(graphComponent.getCanvas(), previewState.getCell()); }
/** * */ public ImageIcon createTransferableImage(mxGraphComponent graphComponent, Object[] cells) { ImageIcon icon = null; Color bg = (transferImageBackground != null) ? transferImageBackground : graphComponent.getBackground(); Image img = mxCellRenderer.createBufferedImage( graphComponent.getGraph(), cells, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); if (img != null) { icon = new ImageIcon(img); } return icon; }
if (graphComponent.isAutoScroll()) graphComponent.getGraphControl().scrollRectToVisible( new Rectangle(e.getPoint())); if (!e.isConsumed()) gridEnabledEvent = graphComponent.isGridEnabledEvent(e); constrainedEvent = graphComponent.isConstrainedEvent(e); int x = e.getX(); int y = e.getY(); double dy = e.getY() - first.y; if (graphComponent.isGridEnabledEvent(e)) mxGraph graph = graphComponent.getGraph(); && graphComponent.isCloneEvent(e); movePreview.update(e, dx, dy, clone); e.consume(); if (!isVisible() && graphComponent.isSignificant(dx, dy)) && !graphComponent.isDragEnabled())
if ( graphComponent.isEnabled() && isEnabled() && !e.isConsumed() ) final mxGraph lGraph = graphComponent.getGraph(); double dx = 0; double dy = 0; if ( first == null || !graphComponent.isSignificant( e.getX() - first.x, e.getY() - first.y ) ) if ( cell != null && !e.isPopupTrigger() && isSelectEnabled() && ( first != null || !isMoveEnabled() ) ) graphComponent.selectCellForEvent( cell, e ); if ( graphComponent.isFoldingEnabled() && graphComponent.hitFoldingIcon( initialCell, e.getX(), e.getY() ) ) final Object tmp = graphComponent.getCellAt( e.getX(), e.getY(), graphComponent.isSwimlaneSelectionEnabled() ); if ( tmp == null && e.getButton() == MouseEvent.BUTTON1 ) else if ( lGraph.isSwimlane( tmp ) && graphComponent.getCanvas().hitSwimlaneContent( graphComponent, lGraph.getView().getState( tmp ), e.getX(), e.getY() ) ) graphComponent.selectCellForEvent( tmp, e ); if ( graphComponent.isFoldingEnabled() && graphComponent.hitFoldingIcon( tmp, e.getX(), e.getY() ) ) if ( graphComponent.isConstrainedEvent( e ) ) final boolean clone = isCloneEnabled() && graphComponent.isCloneEvent( e ); final Object[] result = movePreview.stop( true, e, dx, dy, clone, target );
/** * */ public void mouseDragged(MouseEvent e) { if (!e.isConsumed() && start != null) { int dx = e.getX() - start.x; int dy = e.getY() - start.y; Rectangle r = graphComponent.getViewport().getViewRect(); int right = r.x + ((dx > 0) ? 0 : r.width) - dx; int bottom = r.y + ((dy > 0) ? 0 : r.height) - dy; graphComponent.getGraphControl().scrollRectToVisible( new Rectangle(right, bottom, 0, 0)); e.consume(); } }
mxGraph graph = graphComponent.getGraph(); if (!e.isConsumed() && first != null) double dx = e.getX() - first.x; double dy = e.getY() - first.y; if (graphComponent.isSignificant(dx, dy)) mxPoint abs = state.getAbsoluteOffset(); dx = abs.getX() - first.x; dy = abs.getY() - first.y; pt = graphComponent.snapScaledPoint(pt, dx, dy); && (isSource(index) || isTarget(index))) connect(state.getCell(), marker.getValidState().getCell(), isSource(index), graphComponent.isCloneEvent(e) && isCloneEnabled()); || graphComponent.getGraph().isAllowDanglingEdges()) if (!e.isConsumed() && isFlipEvent(e)) graph.flipEdge(state.getCell()); e.consume();
int x = (int) source.getCenterX() - imgWidth / 2; int y = (int) source.getCenterY() - imgHeight / 2; if (graphComponent.getGraph().isSwimlane(source.getCell())) mxRectangle size = graphComponent.getGraph().getStartSize( source.getCell()); setBounds(new Rectangle(x, y, imgWidth, imgHeight)); if (source != null && (bounds == null || bounds.contains(e.getPoint()))) graphComponent.getGraphControl().setCursor(CONNECT_CURSOR); e.consume();
/** * Returns true if the given cells should be removed from the parent for the specified * mousereleased event. */ protected boolean shouldRemoveCellFromParent(Object parent, Object[] cells, MouseEvent e) { if (graphComponent.getGraph().getModel().isVertex(parent)) { mxCellState pState = graphComponent.getGraph().getView() .getState(parent); return pState != null && !pState.contains(e.getX(), e.getY()); } return false; }
/** * */ protected Cursor getCursor(MouseEvent e) { Cursor cursor = null; if (isMoveEnabled()) { Object cell = graphComponent.getCellAt(e.getX(), e.getY(), false); if (cell != null) { if (graphComponent.isFoldingEnabled() && graphComponent.hitFoldingIcon(cell, e.getX(), e.getY())) { cursor = FOLD_CURSOR; } else if (graphComponent.getGraph().isCellMovable(cell)) { cursor = MOVE_CURSOR; } } } return cursor; }
/** * */ public void mousePressed(MouseEvent e) { if (!graphComponent.isForceMarqueeEvent(e) && !graphComponent.isPanningEvent(e) && !e.isPopupTrigger() && graphComponent.isEnabled() && isEnabled() && !e.isConsumed() && ((isHighlighting() && marker.hasValidState()) || (!isHighlighting() && bounds != null && bounds.contains(e.getPoint())))) { start(e, marker.getValidState()); e.consume(); } }
/** * */ public Rectangle getFoldingIconBounds(mxCellState state, ImageIcon icon) { mxIGraphModel model = graph.getModel(); boolean isEdge = model.isEdge(state.getCell()); double scale = getGraph().getView().getScale(); int x = (int) Math.round(state.getX() + 4 * scale); int y = (int) Math.round(state.getY() + 4 * scale); int w = (int) Math.max(8, icon.getIconWidth() * scale); int h = (int) Math.max(8, icon.getIconHeight() * scale); if (isEdge) { mxPoint pt = graph.getView().getPoint(state); x = (int) pt.getX() - w / 2; y = (int) pt.getY() - h / 2; } return new Rectangle(x, y, w, h); }
if (graphComponent.getGraph().isCellResizable(getState().getCell())) Rectangle bounds = getState().getRectangle(); int half = mxConstants.HANDLE_SIZE / 2; h[0] = new Rectangle(left, top, s, s); h[1] = new Rectangle(w2, top, s, s); h[2] = new Rectangle(right, top, s, s); h[3] = new Rectangle(left, h2, s, s); h[4] = new Rectangle(right, h2, s, s); mxRectangle bounds = state.getLabelBounds(); h[h.length - 1] = new Rectangle((int) (bounds.getX() + bounds.getWidth() / 2 - s), (int) (bounds.getY()
/** * Sets the translation of the preview. */ public void start(MouseEvent e, mxCellState state) { startState = state; movingCells = getCells(state); previewStates = (!placeholderPreview) ? getPreviewStates() : null; if (previewStates == null || previewStates.length >= threshold) { placeholder = getPlaceholderBounds(startState).getRectangle(); initialPlaceholder = new Rectangle(placeholder); graphComponent.getGraphControl().repaint(placeholder); } fireEvent(new mxEventObject(mxEvent.START, "event", e, "state", startState)); }
/** * */ public void start(MouseEvent e) { initialAngle = mxUtils.getDouble(currentState.getStyle(), mxConstants.STYLE_ROTATION) * mxConstants.RAD_PER_DEG; currentAngle = initialAngle; first = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), graphComponent.getGraphControl()); if (!graphComponent.getGraph().isCellSelected(currentState.getCell())) { graphComponent.selectCellForEvent(currentState.getCell(), e); } }
mxIGraphModel model = graphComponent.getGraph().getModel(); TransferHandler th = graphComponent.getTransferHandler(); boolean isLocal = th instanceof mxGraphTransferHandler && ((mxGraphTransferHandler) th).isLocalDrag(); mxGraph graph = graphComponent.getGraph(); Object cell = super.getCell(e); Object[] cells = (isLocal) ? graph.getSelectionCells() : dragCells; cells = cells != null? cells : graph.getSelectionCells(); cell = graph.getDropTarget(cells, e.getPoint(), cell); boolean clone = graphComponent.isCloneEvent(e) && cloneEnabled;