📄 erdtable.java
字号:
if (this.dropConstraintScript == null) { this.dropConstraintScript = dropConstraintScript; } else { this.dropConstraintScript += dropConstraintScript; } } /** <p>Returns the CREATE TABLE script for this table. * * @return the CREATE TABLE script */ public String getCreateTableScript() { return createTableScript; } /** <p>Sets the CREATE TABLE script for this table. * * @return the CREATE TABLE script */ public void setCreateTableScript(String createTableScript) { this.createTableScript = createTableScript; } /** <p>Notifies this table that all changes have been * commited to the database and all SQL script values * can be reset. */ public void changesCommited() { alterTableHash = null; createTableScript = null; alterTableScript = null; dropConstraintScript = null; addConstraintScript = null; newTable = false; } /** <p>Sets this table as a newly created table - ie. * this table does not exist as yet in the database * and is only a part of the ERD or sets this table as * an existing table within the database after the CREATE * TABLE script has been successfully executed. * * @param <code>true</code> to set this as a new table | * <code>false</code> otherwise */ public void setNewTable(boolean newTable) { this.newTable = newTable; } /** <p>Returns whether this table is a new table - ie. * this table does not exist as yet in the database * and is only a part of the ERD. */ public boolean isNewTable() { return newTable; } public void setParentContainer(ErdViewerPanel parent) { this.parent = parent; } protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D)g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); drawTable(g2d, 0, 0); } protected Color getTableBackground() { return tableBackground; } protected void setTableBackground(Color tableBackground) { this.tableBackground = tableBackground; } protected void drawTable(Graphics2D g, int offsetX, int offsetY) { Font tableNameFont = parent.getTableNameFont(); Font columnNameFont = parent.getColumnNameFont(); // set the table value background g.setColor(TITLE_BAR_BG_COLOR); g.fillRect(offsetX, offsetY, FINAL_WIDTH - 1, TITLE_BAR_HEIGHT); // set the table value FontMetrics fm = g.getFontMetrics(tableNameFont); int lineHeight = fm.getHeight(); int titleXPosn = (FINAL_WIDTH / 2) - (fm.stringWidth(tableName) / 2) + offsetX; g.setColor(Color.BLACK); g.setFont(tableNameFont); g.drawString(tableName, titleXPosn, lineHeight + offsetY); // draw the line separator lineHeight = TITLE_BAR_HEIGHT + offsetY - 1; g.drawLine(offsetX, lineHeight, offsetX + FINAL_WIDTH - 1, lineHeight); // fill the white background g.setColor(tableBackground); g.fillRect(offsetX, TITLE_BAR_HEIGHT + offsetY, FINAL_WIDTH - 1, FINAL_HEIGHT - TITLE_BAR_HEIGHT - 1); // add the column names fm = g.getFontMetrics(columnNameFont); int heightPlusSep = 1 + TITLE_BAR_HEIGHT + offsetY; int leftMargin = 5 + offsetX; lineHeight = fm.getHeight(); g.setColor(Color.BLACK); g.setFont(columnNameFont); int drawCount = 0; String value = null; for (int i = 0; i < columns.length; i++) { ColumnData column = columns[i]; if (displayReferencedKeysOnly && !column.isKey()) { continue; } int y = (((drawCount++)+1) * lineHeight) + heightPlusSep; int x = leftMargin; // draw the column value string value = column.getColumnName(); g.drawString(value, x, y); // draw the data type and size string x = leftMargin + dataTypeOffset; value = column.getFormattedDataType(); g.drawString(value, x, y); // draw the key label if (column.isKey()) { if (column.isPrimaryKey() && column.isForeignKey()) { value = PRIMARY + FOREIGN; } else if (column.isPrimaryKey()) { value = PRIMARY; } else if (column.isForeignKey()) { value = FOREIGN; } x = leftMargin + dataTypeOffset + keyLabelOffset; g.drawString(value, x, y); } } // draw the rectangle border double scale = g.getTransform().getScaleX(); if (selected && scale != ErdPrintable.PRINT_SCALE) { g.setStroke(focusBorderStroke); g.setColor(Color.BLUE); } else { g.setColor(Color.BLACK); } g.drawRect(offsetX, offsetY, FINAL_WIDTH - 1, FINAL_HEIGHT - 1); // g.setColor(Color.DARK_GRAY); // g.draw3DRect(offsetX, offsetY, FINAL_WIDTH - 2, FINAL_HEIGHT - 2, true); } /** <p>Resets all of this component's joins. */ public void resetAllJoins() { for (int i = 0; i < verticalLeftJoins.length; i++) { verticalLeftJoins[i].reset(); verticalRightJoins[i].reset(); } for (int i = 0; i < horizontalBottomJoins.length; i++) { horizontalBottomJoins[i].reset(); horizontalTopJoins[i].reset(); } } /** <p>Retrieves the next available join point on the * specified axis for this component. * * @return the next join position */ public int getNextJoin(int axis) { switch (axis) { case LEFT_JOIN: return getNextJoin(verticalLeftJoins); case RIGHT_JOIN: return getNextJoin(verticalRightJoins); case TOP_JOIN: return getNextJoin(horizontalTopJoins); case BOTTOM_JOIN: return getNextJoin(horizontalBottomJoins); } return 0; } private int getNextJoin(ErdTableConnectionPoint[] points) { int connectionCount = 0; int lastConnectionCount = 0; for (int i = 0; i < points.length; i++) { ErdTableConnectionPoint point = points[i]; connectionCount = point.getConnectionCount(); if (connectionCount == 0 || connectionCount < lastConnectionCount) { point.addConnection(); return point.getPosition(); } lastConnectionCount = connectionCount; } // default to the first connection point if (points.length > 0) { return points[0].getPosition(); } return 0; } /** <p>Retrieves the table column meta data for * this table as a <code>ColumnData</code> array. * * @return this table's column meta data */ public ColumnData[] getTableColumns() { return columns; } /** <p>Retrieves the table column meta data for * this table as a <code>Vector</code> of * <code>ColumnData</code> objects. * * @return this table's column meta data */ public Vector getTableColumnsVector() { Vector columnsVector = new Vector(columns.length); for (int i = 0; i < columns.length; i++) { columnsVector.add(columns[i]); } return columnsVector; } /** <p>Retrieves the original table column meta data for * this table as a <code>ColumnData</code> array before * changes (if (any) were or have been applied. * * @return this table's original column meta data */ public ColumnData[] getOriginalTableColumns() { return originalData; } /** <p>Sets this table's name to the specified value. * * @param the table name */ public void setTableName(String tableName) { this.tableName = tableName.toUpperCase(); } /** <p>Sets this table's column metadata to the specified * values as a <code>ColumnData</code> array. * * @param the column metadata values */ public void setTableColumns(ColumnData[] columns) { this.columns = columns; } /** <p>Returns this table's name. * * @return this table's name */ public String getTableName() { return tableName; } /** <p>Retrieves this component's height. * * @return the component's height */ public int getHeight() { return FINAL_HEIGHT; } public void setHeight(int FINAL_HEIGHT) { this.FINAL_HEIGHT = FINAL_HEIGHT; } public void setWidth(int FINAL_WIDTH) { this.FINAL_WIDTH = FINAL_WIDTH; } /** <p>Retrieves this component's width. * * @return the component's width */ public int getWidth() { return FINAL_WIDTH; } /** <p>Gets the bounds of this component as a <code>Rectangle</code> * object. The bounds specify this component's width, height, and * location relative to its parent. * * @return a rectangle indicating this component's bounds */ public Rectangle getBounds() { return new Rectangle(getX(), getY(), FINAL_WIDTH, FINAL_HEIGHT); } public void doubleClicked(MouseEvent e) { /* if (!newTable) new ErdEditTableDialog(parent, this); else*/ if (editable) { new ErdNewTableDialog(parent, this); } } public void selected(MouseEvent e) { super.selected(e); Rectangle bounds = getBounds(); Rectangle titleBar = new Rectangle((int)bounds.getX(), (int)bounds.getY(), FINAL_WIDTH, TITLE_BAR_HEIGHT); if (titleBar.contains(xDifference, yDifference)) { dragging = true; } else { dragging = false; } // need to repaint layered pane to show // selected border on tables parent.repaintLayeredPane(); } /** <p>Returns a string representation of this * component - the table name. * * @return the table name */ public String toString() { return tableName; } public void clean() { parent = null; columns = null; verticalLeftJoins = null; verticalRightJoins = null; horizontalTopJoins = null; horizontalBottomJoins = null; } class ErdTableConnectionPoint implements Serializable { private int axisType; private int position; private int tablesConnected; public ErdTableConnectionPoint(int axisType, int position) { this.axisType = axisType; this.position = position; tablesConnected = 0; } public ErdTableConnectionPoint(int axisType) { this.axisType = axisType; tablesConnected = 0; } public void addConnection() { tablesConnected++; } public int getConnectionCount() { return tablesConnected; } public void reset() { tablesConnected = 0; } public void setPosition(int position) { this.position = position; } public int getAxisType() { return axisType; } public int getPosition() { return position; } public boolean hasConnection() { return tablesConnected > 0; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -