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

📄 tableconstraintspanel.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * TableConstraintsPanel.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.table;import java.awt.BorderLayout;import java.awt.event.FocusListener;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import java.util.Vector;import javax.swing.DefaultCellEditor;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.table.AbstractTableModel;import javax.swing.table.TableCellEditor;import javax.swing.table.TableColumn;import javax.swing.table.TableColumnModel;import org.executequery.gui.DefaultTable;import org.executequery.gui.browser.ColumnConstraint;import org.underworldlabs.swing.table.ComboBoxCellEditor;import org.underworldlabs.swing.table.StringCellEditor;import org.executequery.gui.browser.ColumnData;/* ---------------------------------------------------------- * 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.5 $ * @date     $Date: 2006/07/15 13:14:12 $ */public abstract class TableConstraintsPanel extends JPanel                                            implements CreateTableSQLSyntax {        /** The table containing the constraint data */    protected JTable table;        /** The table's model */    protected ColumnConstraintModel model;        /** The constraint name cell editor */    protected StringCellEditor conNameEditor;        /** The string cell editor */    protected DefaultCellEditor strEditor;        /** The keys combo box cell editor */    protected ComboBoxCellEditor keysCombo;        public TableConstraintsPanel() {        super(new BorderLayout());                try {            jbInit();        } catch (Exception e) {            e.printStackTrace();        }            }        private void jbInit() throws Exception {        table = new DefaultTable();                conNameEditor = new StringCellEditor();                // create the key listener to notify changes        KeyAdapter colKeyListener = new KeyAdapter() {            public void keyReleased(KeyEvent e) {                columnValuesChanged(table.getEditingColumn(),                                    table.getEditingRow(),                                    conNameEditor.getValue());             }        };                conNameEditor.addKeyListener(colKeyListener);                add(new JScrollPane(table), BorderLayout.CENTER);                if (getMode() == CREATE_TABLE_MODE) {            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);        }        table.setColumnSelectionAllowed(false);        table.setRowSelectionAllowed(false);        table.getTableHeader().setReorderingAllowed(false);        table.setRowHeight(20);                keysCombo = new ComboBoxCellEditor(CreateTableSQLSyntax.KEY_NAMES);                strEditor = new DefaultCellEditor(conNameEditor) {            public Object getCellEditorValue() {                return conNameEditor.getValue();             }        };    }        public abstract ColumnData[] getTableColumnData();        public abstract void updateCellEditor(int col, int row, String value);        public abstract void columnValuesChanged();        public abstract void columnValuesChanged(int col, int row, String value);        public abstract int getMode();        public Vector getKeys() {        return model.getKeys();    }        public ColumnConstraint[] getColumnConstraintArray() {        Vector keys = model.getKeys();        int v_size = keys.size();                ColumnConstraint[] cca = new ColumnConstraint[v_size];                for (int i = 0; i < v_size; i++) {            cca[i] = new ColumnConstraint();            cca[i].setValues((ColumnConstraint)keys.elementAt(i));        }                return cca;    }        public void fireEditingStopped() {        table.editingStopped(null);        if (table.isEditing()) {            table.removeEditor();        }    }        public void setData(Vector keys, boolean fillCombos) {                boolean keysEmpty = keys.isEmpty();        if (table.isEditing()) {            table.removeEditor();        }        // add an empty constraint for input if vector empty        if (keysEmpty) {            keys.add(new ColumnConstraint(getMode() == EDIT_TABLE_MODE));        }        if (model == null) {            model = new ColumnConstraintModel(keys);            setModel(model);            setColumnProperties();        }        else {            model.setNewData(keys);            setModel(model);        }                if (keysEmpty || fillCombos) {            try {                table.getColumnModel().getColumn(2).setCellEditor(keysCombo);                table.getColumnModel().getColumn(3).setCellEditor(                            new ComboBoxCellEditor(getTableColumnData()));            } catch (ArrayIndexOutOfBoundsException e) { // TODO: what is this - test                e.printStackTrace();            }        }                model.fireTableDataChanged();    }        public int getSelectedRow() {        return table.getSelectedRow();    }        public void insertRowAfter() {        model.insertRowAfter(getMode() == EDIT_TABLE_MODE);    }        public void deleteSelectedRow() {        int row = table.getSelectedRow();        if (row == -1) {            return;        }                table.editingStopped(null);        if (table.isEditing()) {            table.removeEditor();        }                model.deleteRow(row);        model.fireTableRowsDeleted(row, row);                if (model.getKeys().size() == 0) {            model.insertRowAfter(getMode() == EDIT_TABLE_MODE);            table.setEditingRow(0);        }        else {            table.setEditingRow(row);        }                table.setEditingColumn(1);        columnValuesChanged();    }        public void setCellEditor(int col, TableCellEditor editor) {        table.getColumnModel().getColumn(col).setCellEditor(editor);    }        /**     * Sets some default column property values on the table     * display such as renderers, editors and column widths.     */    protected void setColumnProperties() {        TableColumnModel tcm = table.getColumnModel();        tcm.getColumn(0).setPreferredWidth(25);        //tcm.getColumn(0).setMinWidth(25);        tcm.getColumn(0).setMaxWidth(25);        tcm.getColumn(1).setPreferredWidth(125);        tcm.getColumn(2).setPreferredWidth(75);        tcm.getColumn(3).setPreferredWidth(110);        tcm.getColumn(4).setPreferredWidth(120);        tcm.getColumn(5).setPreferredWidth(120);        tcm.getColumn(6).setPreferredWidth(120);                tcm.getColumn(0).setCellRenderer(new ConstraintCellRenderer());        tcm.getColumn(1).setCellEditor(strEditor);        tcm.getColumn(2).setCellEditor(keysCombo);    }        public boolean tableHasFocus(JTable _table) {        return table == _table;    }        private void setTableProperty(int col, int width,                                  DefaultCellEditor editor) {                TableColumn column = table.getColumnModel().getColumn(col);        if (editor != null) {            column.setCellEditor(editor);        }    }        /** <p>Adds the specified focus listener to the table.     *     *  @param the listener to add to the table     */

⌨️ 快捷键说明

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