/** * Starts handling a gesture at the given handle index. */ public void start(MouseEvent e, int index) { this.index = index; first = e.getPoint(); preview = createPreview(); if (preview != null) { graphComponent.getGraphControl().add(preview, 0); } }
/** * Paints the visible handles of this handler. */ public void paint(Graphics g) { if (handles != null && isHandlesVisible()) { for (int i = 0; i < handles.length; i++) { if (isHandleVisible(i) && g.hitClip(handles[i].x, handles[i].y, handles[i].width, handles[i].height)) { g.setColor(getHandleFillColor(i)); g.fillRect(handles[i].x, handles[i].y, handles[i].width, handles[i].height); g.setColor(getHandleBorderColor(i)); g.drawRect(handles[i].x, handles[i].y, handles[i].width - 1, handles[i].height - 1); } } } }
/** * Returns true if the given index is the index of the last handle. */ public boolean isLabel(int index) { return index == getHandleCount() - 1; }
/** * Processes the given event. */ public void mousePressed(MouseEvent e) { if (!e.isConsumed()) { int tmp = getIndexAt(e.getX(), e.getY()); if (!isIgnoredEvent(e) && tmp >= 0 && isHandleEnabled(tmp)) { graphComponent.stopEditing(true); start(e, tmp); e.consume(); } } }
handler.refresh(state); handler.setHandlesVisible(handlesVisible); handlers.put(tmp[i], handler); Rectangle bounds = handler.getBounds(); Stroke stroke = handler.getSelectionStroke(); handler.destroy();
/** * Processes the given event. */ public void mouseMoved(MouseEvent e) { if (!e.isConsumed() && handles != null) { int index = getIndexAt(e.getX(), e.getY()); if (index >= 0 && isHandleEnabled(index)) { Cursor cursor = getCursor(e, index); if (cursor != null) { graphComponent.getGraphControl().setCursor(cursor); e.consume(); } else { graphComponent.getGraphControl().setCursor( new Cursor(Cursor.HAND_CURSOR)); } } } }
/** * Refreshes the cell handler. */ public void refresh(mxCellState state) { this.state = state; handles = createHandles(); mxGraph graph = graphComponent.getGraph(); mxRectangle tmp = graph.getBoundingBox(state.getCell()); if (tmp != null) { bounds = tmp.getRectangle(); if (handles != null) { for (int i = 0; i < handles.length; i++) { if (isHandleVisible(i)) { bounds.add(handles[i]); } } } } }
/** * * @param x * @param y * @return Returns the inde of the handle at the given location. */ public int getIndexAt(int x, int y) { int index = super.getIndexAt(x, y); // Makes the complete label a trigger for the label handle if (index < 0 && handles != null && handlesVisible && isLabelMovable() && state.getLabelBounds().getRectangle().contains(x, y)) { index = handles.length - 1; } return index; }
/** * */ protected Color getHandleFillColor(int index) { boolean source = isSource(index); if (source || isTarget(index)) { mxGraph graph = graphComponent.getGraph(); Object terminal = graph.getModel().getTerminal(state.getCell(), source); if (terminal == null && !graphComponent.getGraph().isTerminalPointMovable( state.getCell(), source)) { return mxSwingConstants.LOCKED_HANDLE_FILLCOLOR; } else if (terminal != null) { return (graphComponent.getGraph().isCellDisconnectable( state.getCell(), terminal, source)) ? mxSwingConstants.CONNECT_HANDLE_FILLCOLOR : mxSwingConstants.LOCKED_HANDLE_FILLCOLOR; } } return super.getHandleFillColor(index); }
/** * * @param state * Cell state for which a handler should be created. * @return Returns the handler to be used for the given cell state. */ public mxCellHandler createHandler(mxCellState state) { if (graph.getModel().isVertex(state.getCell())) { return new mxVertexHandler(this, state); } else if (graph.getModel().isEdge(state.getCell())) { mxEdgeStyleFunction style = graph.getView().getEdgeStyle(state, null, null, null); if (graph.isLoop(state) || style == mxEdgeStyle.ElbowConnector || style == mxEdgeStyle.SideToSide || style == mxEdgeStyle.TopToBottom) { return new mxElbowEdgeHandler(this, state); } return new mxEdgeHandler(this, state); } return new mxCellHandler(this, state); }
handler.refresh(state); handler.setHandlesVisible(handlesVisible); handlers.put(tmp[i], handler); Rectangle bounds = handler.getBounds(); Stroke stroke = handler.getSelectionStroke(); handler.destroy();
/** * Processes the given event. */ public void mousePressed(MouseEvent e) { if (!e.isConsumed()) { int tmp = getIndexAt(e.getX(), e.getY()); if (!isIgnoredEvent(e) && tmp >= 0 && isHandleEnabled(tmp)) { graphComponent.stopEditing(true); start(e, tmp); e.consume(); } } }
/** * Processes the given event. */ public void mouseMoved(MouseEvent e) { if (!e.isConsumed() && handles != null) { int index = getIndexAt(e.getX(), e.getY()); if (index >= 0 && isHandleEnabled(index)) { Cursor cursor = getCursor(e, index); if (cursor != null) { graphComponent.getGraphControl().setCursor(cursor); e.consume(); } else { graphComponent.getGraphControl().setCursor( new Cursor(Cursor.HAND_CURSOR)); } } } }
/** * Refreshes the cell handler. */ public void refresh(mxCellState state) { this.state = state; handles = createHandles(); mxGraph graph = graphComponent.getGraph(); mxRectangle tmp = graph.getBoundingBox(state.getCell()); if (tmp != null) { bounds = tmp.getRectangle(); if (handles != null) { for (int i = 0; i < handles.length; i++) { if (isHandleVisible(i)) { bounds.add(handles[i]); } } } } }
/** * * @param x * @param y * @return Returns the inde of the handle at the given location. */ public int getIndexAt(int x, int y) { int index = super.getIndexAt(x, y); // Makes the complete label a trigger for the label handle if (index < 0 && handles != null && handlesVisible && isLabelMovable() && state.getLabelBounds().getRectangle().contains(x, y)) { index = handles.length - 1; } return index; }
/** * */ protected Color getHandleFillColor(int index) { boolean source = isSource(index); if (source || isTarget(index)) { mxGraph graph = graphComponent.getGraph(); Object terminal = graph.getModel().getTerminal(state.getCell(), source); if (terminal == null && !graphComponent.getGraph().isTerminalPointMovable( state.getCell(), source)) { return mxSwingConstants.LOCKED_HANDLE_FILLCOLOR; } else if (terminal != null) { return (graphComponent.getGraph().isCellDisconnectable( state.getCell(), terminal, source)) ? mxSwingConstants.CONNECT_HANDLE_FILLCOLOR : mxSwingConstants.LOCKED_HANDLE_FILLCOLOR; } } return super.getHandleFillColor(index); }
/** * * @param state * Cell state for which a handler should be created. * @return Returns the handler to be used for the given cell state. */ public mxCellHandler createHandler(mxCellState state) { if (graph.getModel().isVertex(state.getCell())) { return new mxVertexHandler(this, state); } else if (graph.getModel().isEdge(state.getCell())) { mxEdgeStyleFunction style = graph.getView().getEdgeStyle(state, null, null, null); if (graph.isLoop(state) || style == mxEdgeStyle.ElbowConnector || style == mxEdgeStyle.SideToSide || style == mxEdgeStyle.TopToBottom) { return new mxElbowEdgeHandler(this, state); } return new mxEdgeHandler(this, state); } return new mxCellHandler(this, state); }
/** * Paints the visible handles of this handler. */ public void paint(Graphics g) { if (handles != null && isHandlesVisible()) { for (int i = 0; i < handles.length; i++) { if (isHandleVisible(i) && g.hitClip(handles[i].x, handles[i].y, handles[i].width, handles[i].height)) { g.setColor(getHandleFillColor(i)); g.fillRect(handles[i].x, handles[i].y, handles[i].width, handles[i].height); g.setColor(getHandleBorderColor(i)); g.drawRect(handles[i].x, handles[i].y, handles[i].width - 1, handles[i].height - 1); } } } }
/** * Returns true if the given index is the index of the last handle. */ public boolean isLabel(int index) { return index == getHandleCount() - 1; }
/** * Starts handling a gesture at the given handle index. */ public void start(MouseEvent e, int index) { this.index = index; first = e.getPoint(); preview = createPreview(); if (preview != null) { graphComponent.getGraphControl().add(preview, 0); } }