⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 erdviewerpanel.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * ErdViewerPanel.java * * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * */package org.executequery.gui.erd;import java.awt.*;import java.awt.event.*;import java.awt.print.*;import javax.swing.*;import java.util.*;import java.io.*;import org.executequery.gui.browser.*;import org.executequery.*;import org.executequery.base.DefaultTabView;import org.executequery.databasemediators.DatabaseConnection;import org.executequery.print.*;import org.executequery.gui.SaveFunction;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the  *           release of version 3.0.0beta1 has meant a  *           resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * * @author   Takis Diakoumis * @version  $Revision: 1.8 $ * @date     $Date: 2006/09/21 13:16:25 $ */public class ErdViewerPanel extends DefaultTabView                            implements PrintFunction,                                       SaveFunction,                                       ActiveComponent {        /** The panel's title */    public static final String TITLE = "Entity Relationship Diagram";    /** The panel's icon */    public static final String FRAME_ICON = "ErdPanel16.gif";        /** Whether this instance has a tool bar palatte */    private boolean showTools;    /** Whether this is a static diagram */    private boolean editable;    /** The base panel */    private JPanel base;    /** The background panel */    private ErdBackgroundPanel bgPanel;    /** The pane containing the tables */    private ErdLayeredPane layeredPane;    /** The customised scroll pane */    private ErdScrollPane scroll;    /** The panel to draw dependencies */    private ErdDependanciesPanel dependsPanel;    /** The status bar containing zoom controls */    private ErdToolBarPalette tools;    /** The title panel */    private ErdTitlePanel erdTitlePanel;    /** The ERD tools palette */    //private InternalFramePalette toolPalette;    /** An open saved erd file */    private ErdSaveFileFormat savedErd;    /** A <code>Vector</code> containing all tables */    private Vector tables;    /** The font name displayed */    private String tableFontName;    /** The font size displayed */    private int tableFontSize;    /** The font style displayed for a table name */    private int tableNameFontStyle;    /** The font style displayed for a column name */    private int columnNameFontStyle;    /** The default file name */    private String fileName;        /** The font for the column names */    private Font columnNameFont;    /** The font for the table name */    private Font tableNameFont;        /** the connection props object */    private DatabaseConnection databaseConnection;        /** The scale values */    protected static final String[] scaleValues = {"25%", "50%", "75%", "100%",                                                   "125%", "150%", "175%", "200%"};        private static int openCount = 1;                                                       private ErdViewerPanel() {        this(null, null, true, true, true);    }        public ErdViewerPanel(boolean showTools, boolean editable) {        this(null, null, true, showTools, editable);    }        public ErdViewerPanel(Vector tableNames, Vector columnData, boolean isNew) {                this(tableNames, columnData, isNew, true, true);    }        public ErdViewerPanel(Vector tableNames, Vector columnData,                          boolean isNew, boolean showTools, boolean editable) {                super(new GridBagLayout());                this.showTools = showTools;        this.editable = editable;                try {            jbInit();        }        catch (Exception e) {            e.printStackTrace();        }        //setCanvasBackground(Color.WHITE);                // build all the tables to display        if (!isNew) {            setTables(tableNames, columnData);        } else {            tables = new Vector();        }                if (tableNames != null && columnData != null) {            dependsPanel.setTableDependencies(buildTableRelationships());            resizeCanvas();            layeredPane.validate();        }        fileName = "erd" + (openCount++) + ".eqd";        setScaledView(0.75);    }        public ErdViewerPanel(ErdSaveFileFormat savedErd, String absolutePath) {        this(null, null, true, true, true);        //setSavedErd(savedErd, absolutePath);        fileName = savedErd.getFileName();            }        private void jbInit() throws Exception {        // set the background panel        bgPanel = new ErdBackgroundPanel(true);        // set the layered pane        layeredPane = new ErdLayeredPane(this);                // add the dependencies line panel        dependsPanel = new ErdDependanciesPanel(this);        layeredPane.add(dependsPanel, Integer.MIN_VALUE + 1);                // initialise the fonts        tableFontName = "Dialog";        tableFontSize = 10;        tableNameFontStyle = Font.PLAIN;        columnNameFontStyle = Font.PLAIN;        tableNameFont = new Font(tableFontName, tableNameFontStyle, tableFontSize + 1);        columnNameFont = new Font(tableFontName, columnNameFontStyle, tableFontSize);        // add the background component        layeredPane.add(bgPanel, Integer.MIN_VALUE);                addComponentListener(new ComponentAdapter() {            public void componentResized(ComponentEvent e) {                resizeCanvas(); }        });                // setup the base panel and add the layered pane        base = new JPanel(new BorderLayout());        base.add(layeredPane, BorderLayout.CENTER);                // set the view's scroller        scroll = new ErdScrollPane(this);        scroll.setViewportView(base);        scroll.setBorder(BorderFactory.createMatteBorder(                    1, 1, 1, 1, GUIUtilities.getDefaultBorderColour()));        JPanel scrollPanel = new JPanel(new BorderLayout());        scrollPanel.add(scroll, BorderLayout.CENTER);        scrollPanel.setBorder(BorderFactory.createEmptyBorder(0, 3, 3, 3));                // add all components to a main panel        JPanel mainPanel = new JPanel(new BorderLayout());                // add the tool bar        if (showTools) {            tools = new ErdToolBarPalette(this);            mainPanel.add(tools, BorderLayout.NORTH);        }        mainPanel.add(scrollPanel, BorderLayout.CENTER);        add(mainPanel, new GridBagConstraints(                                        1, 1, 1, 1, 1.0, 1.0,                                        GridBagConstraints.SOUTHEAST,                                         GridBagConstraints.BOTH,                                        Constants.EMPTY_INSETS, 0, 0));            }        public void addTitlePanel(ErdTitlePanel erdTitlePanel) {        layeredPane.add(erdTitlePanel);        erdTitlePanel.setBounds(50, 50,        erdTitlePanel.getWidth(), erdTitlePanel.getHeight());        layeredPane.moveToFront(erdTitlePanel);        this.erdTitlePanel = erdTitlePanel;        layeredPane.repaint();    }        public boolean isEditable() {        return editable;    }        public void resetTableValues(Vector tableNames, Vector columnData) {        removeAllTables();        setTables(tableNames, columnData);        dependsPanel.setTableDependencies(buildTableRelationships());        resizeCanvas();        layeredPane.validate();    }        /** <p>Builds the ERD table views on feature startup.     *     *  @param a <code>Vector</code> of table names     *  @param the column meta data for the tables     */    public void setTables(Vector tableNames, Vector columnData) {        ErdTable table = null;                // next position of component added        int next_x = 20;        int next_y = 20;                // height and width of current table        int height = -1;        int width = -1;        // width of last table        int lastWidth = 0;        // vertical and horizontal differences        int vertDiff = 50;        int horizDiff = 50;                int v_size = tableNames.size();        tables = new Vector(v_size);                for (int i = 0; i < v_size; i++) {                        // create the ERD display component            table = new ErdTable((String)tableNames.elementAt(i),                                 (ColumnData[])columnData.elementAt(i), this);            table.setEditable(editable);            height = table.getHeight();            width = table.getWidth();                        // if it doesn't fit vertically within the            // initial size of the view, move to a new            // column within the grid display            if (next_y + height + 20 > 450) {                next_y = 20;                                if (i > 0)                    next_x += lastWidth + horizDiff;                                lastWidth = 0;                            }                        // position within the layered pane            table.setBounds(next_x, next_y, width, height);            layeredPane.add(table);                        table.toFront();                        next_y += height + vertDiff;                        if (lastWidth < width)                lastWidth = width;                        // add to the vector            tables.add(table);                    }    }        /** <p>Sets the relationships between each table.     *     *  @return the <code>Vector</code> of     *          <code>ErdTableDependency</code> objects     */    public Vector buildTableRelationships() {                String referencedTable = null;        ColumnData[] cda = null;        ColumnConstraint[] cca = null;                ErdTable[] tables_array = getAllComponentsArray();                Vector tableDependencies = new Vector();        ErdTableDependency dependency = null;                ErdTable table = null;        HashMap tempHash = new HashMap();                for (int k = 0, m = tables.size(); k < m; k++) {                        cda = tables_array[k].getTableColumns();            if (cda == null) {                continue;            }                        for (int i = 0; i < cda.length; i++) {                if (!cda[i].isForeignKey())                    continue;                                cca = cda[i].getColumnConstraintsArray();                                for (int n = 0; n < cca.length; n++) {                                        if (cca[n].getType() == ColumnConstraint.PRIMARY_KEY)                        continue;                                        referencedTable =  cca[n].getRefTable();                                        for (int j = 0; j < m; j++) {                                                if (referencedTable.equalsIgnoreCase(                                tables.elementAt(j).toString())) {                                                        table = (ErdTable)tables.elementAt(j);                                                        // check to see that the combination                            // does not already exist                            if ( (tempHash.containsKey(tables_array[k]) &&                                tempHash.get(tables_array[k]) == table) ||                                (tempHash.containsKey(table) &&                                tempHash.get(table) == tables_array[k]) ) {                                break;                            }                                                        dependency = new ErdTableDependency(tables_array[k], table);                                                        // place the tables in the temp HashMap so                            // the combination is not added a second time                            tempHash.put(tables_array[k], table);                            tempHash.put(table, tables_array[k]);                                                        tableDependencies.add(dependency);                            break;                        }                                            }                                    }                            }                    }                return tableDependencies;        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -