📄 mxgraphcomponent.java
字号:
if (rect.width > 0 || rect.height > 0) { if (parent == null) { parent = graph.getDefaultParent(); } if (parent != null) { Point previousTranslate = canvas.getTranslate(); double previousScale = canvas.getScale(); try { canvas.setScale(graph.getView().getScale()); canvas.setTranslate(0, 0); mxIGraphModel model = graph.getModel(); mxGraphView view = graph.getView(); int childCount = model.getChildCount(parent); for (int i = 0; i < childCount; i++) { Object cell = model.getChildAt(parent, i); mxCellState state = view.getState(cell); if (graph.isCellVisible(cell) && state != null) { if (canvas.contains(this, rect, state)) { result.add(cell); } else { result.addAll(Arrays .asList(getCells(rect, cell))); } } } } finally { canvas.setScale(previousScale); canvas.setTranslate(previousTranslate.x, previousTranslate.y); } } } return result.toArray(); } /** * * @param cells * @param event */ public void selectCellsForEvent(Object[] cells, MouseEvent event) { if (isToggleEvent(event)) { graph.addSelectionCells(cells); } else { graph.setSelectionCells(cells); } } /** * * @param cell * @param e */ public void selectCellForEvent(Object cell, MouseEvent e) { boolean isSelected = graph.isSelected(cell); if (isToggleEvent(e)) { if (isSelected) { graph.removeSelectionCell(cell); } else { graph.addSelectionCell(cell); } } else if (!isSelected || graph.getSelectionCount() != 1) { graph.setSelectionCell(cell); } } /** * Returns true if the absolute value of one of the given parameters is * greater than the tolerance. */ public boolean isSignificant(double dx, double dy) { return Math.abs(dx) > tolerance || Math.abs(dy) > tolerance; } /** * Returns the icon used to display the collapsed state of * the specified cell state. */ public ImageIcon getFoldingIcon(mxCellState state) { if (state != null) { Object cell = state.getCell(); boolean tmp = graph.isCellCollapsed(cell); if (graph.isCellFoldable(cell, !tmp)) { return (tmp) ? collapsedIcon : expandedIcon; } } return null; } /** * */ 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); } /** * */ public boolean hitFoldingIcon(Object cell, int x, int y) { if (cell != null) { mxIGraphModel model = graph.getModel(); // Draws the collapse/expand icons boolean isEdge = model.isEdge(cell); if (foldingEnabled && (model.isVertex(cell) || isEdge)) { mxCellState state = graph.getView().getState(cell); if (state != null) { ImageIcon icon = getFoldingIcon(state); if (icon != null) { return getFoldingIconBounds(state, icon).contains(x, y); } } } } return false; } /** * * @param enabled */ public void setToolTips(boolean enabled) { if (enabled) { ToolTipManager.sharedInstance().registerComponent(graphControl); ToolTipManager.sharedInstance().registerComponent(graphHandler); } else { ToolTipManager.sharedInstance().unregisterComponent(graphControl); ToolTipManager.sharedInstance().unregisterComponent(graphHandler); } } /** * */ public boolean isConnectable() { return connectionHandler.isEnabled(); } /** * @param connectable */ public void setConnectable(boolean connectable) { connectionHandler.setEnabled(connectable); } /** * */ public boolean isPanning() { return panningHandler.isEnabled(); } /** * @param enabled */ public void setPanning(boolean enabled) { panningHandler.setEnabled(enabled); } /** * @return the escapeEnabled */ public boolean isEscapeEnabled() { return escapeEnabled; } /** * @param escapeEnabled the escapeEnabled to set */ public void setEscapeEnabled(boolean escapeEnabled) { boolean oldValue = this.escapeEnabled; this.escapeEnabled = escapeEnabled; firePropertyChange("escapeEnabled", oldValue, escapeEnabled); } /** * @return the escapeEnabled */ public boolean isInvokesStopCellEditing() { return invokesStopCellEditing; } /** * @param invokesStopCellEditing the invokesStopCellEditing to set */ public void setInvokesStopCellEditing(boolean invokesStopCellEditing) { boolean oldValue = this.invokesStopCellEditing; this.invokesStopCellEditing = invokesStopCellEditing; firePropertyChange("invokesStopCellEditing", oldValue, invokesStopCellEditing); } /** * @return the enterStopsCellEditing */ public boolean isEnterStopsCellEditing() { return enterStopsCellEditing; } /** * @param enterStopsCellEditing the enterStopsCellEditing to set */ public void setEnterStopsCellEditing(boolean enterStopsCellEditing) { boolean oldValue = this.enterStopsCellEditing; this.enterStopsCellEditing = enterStopsCellEditing; firePropertyChange("enterStopsCellEditing", oldValue, enterStopsCellEditing); } /** * @return the dragEnabled */ public boolean isDragEnabled() { return dragEnabled; } /** * @param dragEnabled the dragEnabled to set */ public void setDragEnabled(boolean dragEnabled) { boolean oldValue = this.dragEnabled; this.dragEnabled = dragEnabled; firePropertyChange("dragEnabled", oldValue, dragEnabled); } /** * @return the gridVisible */ public boolean isGridVisible() { return gridVisible; } /** * Fires a property change event for <code>gridVisible</code>. * * @param gridVisible the gridVisible to set */ public void setGridVisible(boolean gridVisible) { boolean oldValue = this.gridVisible; this.gridVisible = gridVisible; firePropertyChange("gridVisible", oldValue, gridVisible); } /** * @return the gridVisible */ public boolean isAntiAlias() { return antiAlias; } /** * Fires a property change event for <code>antiAlias</code>. * * @param antiAlias the antiAlias to set */ public void setAntiAlias(boolean antiAlias) { boolean oldValue = this.antiAlias; this.antiAlias = antiAlias; firePropertyChange("antiAlias", oldValue, antiAlias); } /** * @return the gridVisible */ public boolean isTextAntiAlias() { return antiAlias; } /** * Fires a property change event for <code>textAntiAlias</code>. * * @param textAntiAlias the textAntiAlias to set */ public void setTextAntiAlias(boolean textAntiAlias) { boolean oldValue = this.textAntiAlias; this.textAntiAlias = textAntiAlias; firePropertyChange("textAntiAlias", oldValue, textAntiAlias); } /** * @return the tripleBuffered */ public boolean isTripleBuffered() { return tripleBuffered; } /** * Hook for dynamic triple buffering condition. */ public boolean isForceTripleBuffered() { // LATER: Dynamic condition (cell density) to use triple // buffering for a large number of cells on a small rect return false; } /** * @param tripleBuffered the tripleBuffered to set */ public void setTripleBuffered(boolean tripleBuffered) { boolean oldValue = this.tripleBuffered; this.tripleBuffered = tripleBuffered; firePropertyChange("tripleBuffered", oldValue, tripleBuffered); } /** * @return the gridColor */ public Color getGridColor() { return gridColor; } /** * Fires a property change event for <code>gridColor</code>. * * @param gridColor the gridColor to set */ public void setGridColor(Color gridColor) { Color oldValue = this.gridColor; this.gridColor = gridColor; firePropertyChange("gridColor", oldValue, gridColor); } /** * @return the gridStyle */ public int getGridStyle() { return gridStyle; } /** * Fires a property change event for <code>gridStyle</code>. * * @param gridStyle the gridStyle to set */ public void setGridStyle(int gridStyle) { int oldValue = this.gridStyle; this.gridStyle = gridStyle; firePropertyChange("gridStyle", oldValue, gridStyle); } /** * @return the importEnabled */ public boolean isImportEnabled() { return importEnabled; } /** * @param importEnabled the importEnabled to set */ public void setImportEnabled(boolean value) { boolean oldValue = importEnabled; importEnabled = value; firePropertyChange("importEnabled", oldValue, importEnabled); } /** * Returns all cells which may be imported via datatransfer. */ public Object[] getImportableCells(Object[] cells) { return mxGraphModel.filterCells(cells, new Filter() { public boolean filter(Object cell) { return canImportCell(cell); } }); } /** * Returns true if the given cell can be imported via datatransfer. * This returns importEnabled. */ public boolean canImportCell(Object cell) { return isImportEnabled(); } /** * @return the exportEnabled */ public boolean isExportEnabled() { return exportEnabled; } /** * @param value the exportEnabled to set */ public void setExportEnabled(boolean value) { boolean oldValue = exportEnabled; this.exportEnabled = value; firePropertyChange("exportEnabled", oldValue, exportEnabled); } /** * Returns all cells which may be exported via datatransfer. */ public Object[] getExportableCells(Object[] cells) { return mxGraphModel.filterCells(cells, new Filter() { public boolean filter(Object cell) { return canExportCell(cell); } }); } /** * Returns true if the given cell can be exported via datatransfer. */ public boolean canExportCell(Object cell) { return isExportEnabled(); } /** * @return the foldingEnabled */ public boolean isFoldingEnabled() { return foldingEnabled; } /** * @param foldingEnabled the foldingEnabled to set */ public void setFoldingEnabled(boolean foldingEnabled) { boolean oldValue = this.foldingEnabled; this.foldingEnabled = foldingEnabled; firePropertyChange("foldingEnabled", oldValue, foldingEnabled); } /** * */ public boolean isEditEvent(MouseEvent e) { return (e != null) ? e.getClickCount() == 2 : false; } /** * * @param event * @return Returns true if the given event should toggle selected cells. */ public boolean isCloneEvent(MouseEvent event) { return (event != null) ? event.isControlDown() : false; } /** * * @param event * @return Returns true if the given event should toggle selected cells. */ public boolean isToggleEvent(MouseEvent event) { return (event != null) ? event.isControlDown() : false; } /** * * @param event * @return Returns true if the given event allows the grid to be applied. */ public boolean isGridEnabledEvent(MouseEvent event) { return (event != null) ? !event.isAltDown() : false; } /** * Note: This is not used during drag and drop operations due to * limitations of the underlying API. To enable this for move * operations set dragEnabled to false. * * @param event * @return Returns true if the given event is a panning event. */ public boolean isPanningEvent(MouseEvent event) { return (event != null) ? event.isShiftDown() && event.isControlDown() : false; } /** * Note: This is not used during drag and drop operations due to * limitations of the underlying API. To enable this for move * operations set dragEnabled to false.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -