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

📄 tablemap.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id: TableMap.java,v 1.1 2003/03/07 13:49:45 per_nyfelt Exp $package org.ozoneDB.adminGui.widget;import javax.swing.event.TableModelEvent;import javax.swing.event.TableModelListener;import javax.swing.table.AbstractTableModel;import javax.swing.table.TableModel;import java.util.Vector;/** * In a chain of data manipulators some behaviour is common. TableMap * provides most of this behavour and can be subclassed by filters * that only need to override a handful of specific methods. TableMap * implements TableModel by routing all requests to its model, and * TableModelListener by routing all events to its listeners. Inserting * a TableMap which has not been subclassed into a chain of table filters * should have no effect. * * @author  <p align=center>Per Nyfelt * <br>Copyright &copy 1997-@year@ by SMB GmbH. All Rights Reserved.</p> * @author Ibsen Ramos-Bonilla * * @version 1.0 * */public class TableMap extends AbstractTableModel implements TableModelListener {    /** Contains the instance to the table model. */    protected TableModel model;    /** Contains the number of columns in panel tables. */    protected int columnCount;    /** Contains the number of rows in the panel tables. */    protected int rowCount;    /** Contains the panel tables column names. */    protected Vector columnNames = new Vector();    /** Contains the panel tables data. */    protected Vector data = new Vector();    /**     * This method returns a handle for the current table model.     *     * @return TableModel - the current model handle.     */    public TableModel getModel() {        //return this;        return this.model;    }    /**     * This method sets the current table model with the designated model.     *     * @param model - the new table model.     */    public void setModel(TableModel model) {        this.model = model;        this.model.addTableModelListener(this);        //this.setModel(model);    }    /**     * This method returns the value in a specified cell for the current table     * model.     *     * @param row - the row containing the cell to change.     * @param column - the column containing the cell to change.     * @return Object - the value at the specified table location.     */    public Object getValueAt(int row, int column) {        return ((Object[]) data.elementAt(row))[column];    }    /**     * This method sets the value in a specified cell for the current table     * model.     *     * @param aValue - the value to set in the table.     * @param aRow - the row containing the cell to change.     * @param aColumn - the column containing the cell to change.     */    public void setValueAt(Object aValue, int aRow, int aColumn) {        String value;        try {            value = (String) aValue;        } catch (Exception e) {            System.out.println("wrong format");            e.printStackTrace();            return;        }        ((Object[]) data.elementAt(aRow))[aColumn] = value;        fireTableCellUpdated(aRow, aColumn);    }    /**     * This method returns the row count in the current table model.     *     * @return int - the number of rows in the table.     */    public int getRowCount() {        return this.data.size();    }    /**     * This method returns the column count in the current table model.     *     * @return int - the number of columns in tne table.     */    public int getColumnCount() {        return this.columnNames.size();    }    /**     * This method returns the title of a column for the current table model.     *     * @param index - the selected column.     * @return String - the column name.     */    public String getColumnName(int index) {        return (String) columnNames.elementAt(index);    }    /**     * This method returns the class of objects the given column renders.     *     * @param index - the selected column.     * @return Class - the column's object type.     */    public Class getColumnClass(int index) {        return ((Object[]) data.elementAt(0))[index].getClass();    }    /**     * This method clears all the elements from the table.     */    public void clear() {        //first clear everything in the model        this.data.clear();        this.rowCount = 0;    } //-----  clear  -----//    /**     * This method returns a flag indicating if the cell is editable or not.     *     * @param row - the row containing the cell to change.     * @param column - the column containing the cell to change.     * @return boolean - the column's object type.     */    /*public boolean isCellEditable(int row, int column) {        return this.isCellEditable(row, column);    }*/    /**     * This method fires an event when the table is changed.     *     * @param e - table model event.     */    public void tableChanged(TableModelEvent e) {        fireTableChanged(e);    }}

⌨️ 快捷键说明

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