📄 mxgraph.java
字号:
mxCellState state = view.getState(cells[0]); Hashtable style = (state != null) ? state.getStyle() : getCellStyle(cells[0]); if (style != null) { String value = (mxUtils.isTrue(style, key, defaultValue)) ? "0" : "1"; setCellStyles(key, value, cells); } } return cells; } /** * Sets the key to value in the styles of the selection cells. * * @param key String representing the key to be assigned. * @param value String representing the new value for the key. */ public Object[] setCellStyles(String key, String value) { return setCellStyles(key, value, null); } /** * Sets the key to value in the styles of the given cells. This will modify * the existing cell styles in-place and override any existing assignment * for the given key. If no cells are specified, then the selection cells * are changed. If no value is specified, then the respective key is * removed from the styles. * * @param key String representing the key to be assigned. * @param value String representing the new value for the key. * @param cells Array of cells to change the style for. */ public Object[] setCellStyles(String key, String value, Object[] cells) { if (cells == null) { cells = getSelectionCells(); } mxUtils.setCellStyles(model, cells, key, value); return cells; } /** * Toggles the given bit for the given key in the styles of the selection * cells. * * @param key String representing the key to toggle the flag in. * @param flag Integer that represents the bit to be toggled. */ public Object[] toggleCellStyleFlags(String key, int flag) { return toggleCellStyleFlags(key, flag, null); } /** * Toggles the given bit for the given key in the styles of the specified * cells. * * @param key String representing the key to toggle the flag in. * @param flag Integer that represents the bit to be toggled. * @param cells Optional array of <mxCells> to change the style for. Default is * the selection cells. */ public Object[] toggleCellStyleFlags(String key, int flag, Object[] cells) { return setCellStyleFlags(key, flag, null, cells); } /** * Sets or toggles the given bit for the given key in the styles of the * selection cells. * * @param key String representing the key to toggle the flag in. * @param flag Integer that represents the bit to be toggled. * @param value Boolean value to be used or null if the value should be * toggled. */ public Object[] setCellStyleFlags(String key, int flag, boolean value) { return setCellStyleFlags(key, flag, value, null); } /** * Sets or toggles the given bit for the given key in the styles of the * specified cells. * * @param key String representing the key to toggle the flag in. * @param flag Integer that represents the bit to be toggled. * @param value Boolean value to be used or null if the value should be * toggled. * @param cells Optional array of cells to change the style for. If no * cells are specified then the selection cells are used. */ public Object[] setCellStyleFlags(String key, int flag, Boolean value, Object[] cells) { if (cells == null) { cells = getSelectionCells(); } if (cells != null && cells.length > 0) { if (value == null) { mxCellState state = view.getState(cells[0]); Hashtable style = (state != null) ? state.getStyle() : getCellStyle(cells[0]); if (style != null) { int current = mxUtils.getInt(style, key); value = !((current & flag) == flag); } } mxUtils.setCellStyleFlags(model, cells, key, flag, value); } return cells; } // // Cell alignment and orientation // /** * Aligns the selection cells vertically or horizontally according to the * given alignment. * * @param align Specifies the alignment. Possible values are all constants * in mxConstants with an ALIGN prefix. */ public Object[] alignCells(String align) { return alignCells(align, null); } /** * Aligns the given cells vertically or horizontally according to the given * alignment. * * @param align Specifies the alignment. Possible values are all constants * in mxConstants with an ALIGN prefix. * @param cells Array of cells to be aligned. */ public Object[] alignCells(String align, Object[] cells) { return alignCells(align, cells, null); } /** * Aligns the given cells vertically or horizontally according to the given * alignment using the optional parameter as the coordinate. * * @param align Specifies the alignment. Possible values are all constants * in mxConstants with an ALIGN prefix. * @param cells Array of cells to be aligned. * @param param Optional coordinate for the alignment. */ public Object[] alignCells(String align, Object[] cells, Object param) { if (cells == null) { cells = getSelectionCells(); } if (cells != null && cells.length > 1) { // Finds the required coordinate for the alignment if (param == null) { for (int i = 0; i < cells.length; i++) { mxGeometry geo = getCellGeometry(cells[i]); if (geo != null && !model.isEdge(cells[i])) { if (param == null) { if (align == null || align.equals(mxConstants.ALIGN_LEFT)) { param = geo.getX(); } else if (align.equals(mxConstants.ALIGN_CENTER)) { param = geo.getX() + geo.getWidth() / 2; break; } else if (align.equals(mxConstants.ALIGN_RIGHT)) { param = geo.getX() + geo.getWidth(); } else if (align.equals(mxConstants.ALIGN_TOP)) { param = geo.getY(); } else if (align.equals(mxConstants.ALIGN_MIDDLE)) { param = geo.getY() + geo.getHeight() / 2; break; } else if (align.equals(mxConstants.ALIGN_BOTTOM)) { param = geo.getY() + geo.getHeight(); } } else { double tmp = Double.parseDouble(String .valueOf(param)); if (align == null || align.equals(mxConstants.ALIGN_LEFT)) { param = Math.min(tmp, geo.getX()); } else if (align.equals(mxConstants.ALIGN_RIGHT)) { param = Math.max(tmp, geo.getX() + geo.getWidth()); } else if (align.equals(mxConstants.ALIGN_TOP)) { param = Math.min(tmp, geo.getY()); } else if (align.equals(mxConstants.ALIGN_BOTTOM)) { param = Math.max(tmp, geo.getY() + geo.getHeight()); } } } } } // Aligns the cells to the coordinate model.beginUpdate(); try { double tmp = Double.parseDouble(String.valueOf(param)); for (int i = 0; i < cells.length; i++) { mxGeometry geo = getCellGeometry(cells[i]); if (geo != null && !model.isEdge(cells[i])) { geo = (mxGeometry) geo.clone(); if (align == null || align.equals(mxConstants.ALIGN_LEFT)) { geo.setX(tmp); } else if (align.equals(mxConstants.ALIGN_CENTER)) { geo.setX(tmp - geo.getWidth() / 2); } else if (align.equals(mxConstants.ALIGN_RIGHT)) { geo.setX(tmp - geo.getWidth()); } else if (align.equals(mxConstants.ALIGN_TOP)) { geo.setY(tmp); } else if (align.equals(mxConstants.ALIGN_MIDDLE)) { geo.setY(tmp - geo.getHeight() / 2); } else if (align.equals(mxConstants.ALIGN_BOTTOM)) { geo.setY(tmp - geo.getHeight()); } model.setGeometry(cells[i], geo); if (isResetEdgesOnMove()) { resetEdges(new Object[] { cells[i] }); } } } fireEvent(mxEvent.ALIGN_CELLS, new mxEventObject( new Object[] { cells })); } finally { model.endUpdate(); } } return cells; } /** * Called when the main control point of the edge is double-clicked. This * implementation switches between null (default) and alternateEdgeStyle * and resets the edges control points. Finally, a flip event is fired * before endUpdate is called on the model. * * @param edge Cell that represents the edge to be flipped. * @return Returns the edge that has been flipped. */ public Object flipEdge(Object edge) { if (edge != null && alternateEdgeStyle != null) { model.beginUpdate(); try { String style = model.getStyle(edge); if (style == null || style.length() == 0) { model.setStyle(edge, alternateEdgeStyle); } else { model.setStyle(edge, null); } // Removes all existing control points resetEdge(edge); fireEvent(mxEvent.FLIP_EDGE, new mxEventObject( new Object[] { edge })); } finally { model.endUpdate(); } } return edge; } // // Order // /** * Moves the selection cells to the front or back. This is a shortcut method. * * @param back Specifies if the cells should be moved to back. */ public Object[] orderCells(boolean back) { return orderCells(back, null); } /** * Moves the given cells to the front or back. The change is carried out * using cellsOrdered. This method fires mxEvent.ORDER_CELLS while the * transaction is in progress. * * @param back Specifies if the cells should be moved to back. * @param cells Array of cells whose order should be changed. If null is * specified then the selection cells are used. */ public Object[] orderCells(boolean back, Object[] cells) { if (cells == null) { cells = mxUtils.sortCells(getSelectionCells(), true); } model.beginUpdate(); try { cellsOrdered(cells, back); fireEvent(mxEvent.ORDER_CELLS, new mxEventObject(new Object[] { back, cells })); } finally { model.endUpdate(); } return cells; } /** * Moves the given cells to the front or back. This method fires * mxEvent.CELLS_ORDERED while the transaction is in progress. * * @param cells Array of cells whose order should be changed. * @param back Specifies if the cells should be moved to back. */ public void cellsOrdered(Object[] cells, boolean back) { if (cells != null) { model.beginUpdate(); try { for (int i = 0; i < cells.length; i++) { Object parent = model.getParent(cells[i]); if (back) { model.add(parent, cells[i], i); } else { model.add(parent, cells[i], model.getChildCount(parent) - 1); } } fireEvent(mxEvent.CELLS_ORDERED, new mxEventObject( new Object[] { cells, back })); } finally { model.endUpdate(); } } } // // Grouping // /** * Groups the selection cells. This is a shortcut method. * * @return Returns the new group. */ public Object groupCells() { return groupCells(null); } /** * Groups the selection cells and adds them to the given group. This is a * shortcut method. * * @return Returns the new group. */ public Object groupCells(Object group) { return groupCells(group, 0); } /** * Groups the selection cells and adds them to the given group. This is a * shortcut method. * * @return Returns the new group. */ public Object groupCells(Object group, double border) { return groupCells(group, border, null); } /** * Adds the cells into the given group. The change is carried out using * cellsAdded, cellsMoved and cellsResized. This method fires * mxEvent.GROUP_CELLS while the transaction is in progress. Returns the * new group. * * @param group Cell that represents the target group. If null is specified * then a new group is created using createGroupCell. * @param border Integer that specifies the border between the child area * and the group bounds. * @param cells Optional array of cells to be grouped. If null is specified * then the selection cells are used. */ public Object groupCells(Object group, double border, Object[] cells) { if (cells == null) { cells = mxUtils.sortCells(getSelectionCells(), true); } cells = getCellsForGroup(cells); mxRectangle bounds = getBoundsForGroup(group, cells, border); if (cells.length > 1 && bounds != null) { Object parent = model.getParent(cells[0]); model.beginUpdate(); try { if (group == null) { group = createGroupCell(cells); } // Checks if the group has a geometry and // creates one if one does not exist if (getCellGeometry(group) == null) { model.setGeometry(group, new mxGeometry()); } // Adds the children into the group and moves int index = model.getChildCount(group);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -