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

📄 cachetablemodel.java

📁 自行开发的高缓存table
💻 JAVA
字号:
// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov  Date: 2004-2-20 9:17:08
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   CacheTableModel.java

package utility.HWCacheTable;

import java.util.Vector;
import javax.swing.table.AbstractTableModel;

// Referenced classes of package utility.HWCacheTable:
//            CacheManager, ModificationValue, ServerModel, CacheTableStatusViewer

public class CacheTableModel extends AbstractTableModel
{

    public CacheTableModel(ServerModel servermodel)
    {
        _cacheManager = null;
        _serverModel = null;
        _columnIndentifiers = null;
        _statusViewer = null;
        _modification = new Vector();
        _batchBegin = false;
        _batchData = null;
        _selectedRows = null;
        _cacheManager = new CacheManager(servermodel, this);
        setServerModel(servermodel);
    }

    public void setServerModel(ServerModel servermodel)
    {
        _cacheManager.setServerModel(servermodel);
        servermodel.setTableModel(this);
        _serverModel = servermodel;
    }

    public Object getValueAt(int i, int j)
    {
        if(_modification.size() > 0)
        {
            _tempObj.row = i;
            _tempObj.column = j;
            int k = _modification.lastIndexOf(_tempObj);
            try
            {
                ModificationValue modificationvalue = (ModificationValue)_modification.get(k);
                return modificationvalue.value;
            }
            catch(Exception exception)
            {
                return _cacheManager.getValueAt(i, j);
            }
        } else
        {
            return _cacheManager.getValueAt(i, j);
        }
    }

    public int getRowCount()
    {
        int i = 0;
        if(_cacheManager != null)
            i = _cacheManager.getRowCount();
        try
        {
            if(_statusViewer != null)
                _statusViewer.showItemCount(i);
        }
        catch(Exception exception) { }
        return i;
    }

    public void setColumnIdentifiers(Object aobj[])
    {
        if(aobj != null)
            _columnIndentifiers = aobj;
        else
            _columnIndentifiers = new Object[0];
        fireTableStructureChanged();
    }

    public int getColumnCount()
    {
        if(_columnIndentifiers != null)
            return _columnIndentifiers.length;
        else
            return 0;
    }

    public String getColumnName(int i)
    {
        if(_columnIndentifiers == null || _columnIndentifiers.length <= i)
            return super.getColumnName(i);
        Object obj = _columnIndentifiers[i];
        if(obj == null)
            return super.getColumnName(i);
        else
            return obj.toString();
    }

    public void refresh()
    {
        _cacheManager.restoreCache();
        fireTableDataChanged();
    }

    public void updateSize()
    {
        _cacheManager.clearSizeRelativeValue();
        fireTableDataChanged();
    }

    public void reloadCacheData()
    {
        _cacheManager.throwCacheData();
        fireTableRowsUpdated(0, getRowCount());
    }

    public void setStatusViewer(CacheTableStatusViewer cachetablestatusviewer)
    {
        _cacheManager.setStatusViewer(cachetablestatusviewer);
        _statusViewer = cachetablestatusviewer;
    }

    public void repaintLoadingStatus()
    {
        _cacheManager.repaintLoadingStatus();
    }

    void showLoadingStatus(int i)
    {
        if(_statusViewer != null)
            _statusViewer.showLoadingStatus(i);
    }

    void showItemCount(int i)
    {
        if(_statusViewer != null)
            _statusViewer.showItemCount(i);
    }

    public void release()
    {
        if(_cacheManager != null)
            _cacheManager.release();
        _cacheManager = null;
        if(_serverModel != null)
            _serverModel.release();
        _serverModel = null;
        _columnIndentifiers = null;
        _statusViewer = null;
    }

    public void setIDList(Vector vector)
    {
        _serverModel.setIDList(vector);
        if(_modification.size() > 0)
            _modification.clear();
        refresh();
    }

    public Vector getSelectedId(int ai[])
    {
        Vector vector = new Vector();
        _serverModel.getScope(vector, ai);
        return vector;
    }

    public void getSelectedId(Vector vector, int ai[])
    {
        _serverModel.getScope(vector, ai);
    }

    public void removeRows(int ai[])
    {
        _serverModel.removeRows(ai);
        if(_modification != null && _modification.size() > 0)
            _modification.clear();
        refresh();
    }

    public int getFrom()
    {
        return _cacheManager.getFrom();
    }

    public int getTo()
    {
        return _cacheManager.getTo();
    }

    public int getSize()
    {
        return _serverModel.getSize();
    }

    public void getAllId(Vector vector)
    {
        if(vector == null)
        {
            return;
        } else
        {
            int i = getSize();
            _serverModel.getScope(vector, 0, i - 1);
            return;
        }
    }

    public int isItemInCurrentShownTable(Object obj)
    {
        int i = _serverModel.getIndexById(obj);
        if(!isRowDataInCache(i))
            return -1;
        else
            return i;
    }

    public boolean isRowDataInCache(int i)
    {
        return _cacheManager.isDataInTheCache(i);
    }

    public void insertRow(int i, Object obj, Vector vector)
    {
        if(_modification != null && _modification.size() > 0)
            _modification.clear();
        _serverModel.insertRow(i, obj);
    }

    public Vector getCachedData()
    {
        return null;
    }

    public void setValueAt(Object obj, int i, int j)
    {
        modifyValueAt(i, j, obj);
    }

    public void modifyValueAt(int i, int j, Object obj)
    {
        ModificationValue modificationvalue = new ModificationValue(i, j, obj);
        _modification.remove(modificationvalue);
        _modification.addElement(modificationvalue);
        fireTableCellUpdated(i, j);
    }

    public void applyModification()
    {
        if(_modification.size() > 0)
        {
            _serverModel.applyModification(_modification);
            _modification.clear();
            refresh();
        }
    }

    public boolean beModified()
    {
        return _modification.size() > 0;
    }

    public boolean beginReadSelectedBatch(int ai[])
    {
        if(_batchBegin)
        {
            _batchData = null;
            _selectedRows = null;
        }
        if(ai == null)
            return false;
        Vector vector = new Vector(ai.length, 10);
        _serverModel.getScopeEx(vector, ai);
        _selectedRows = ai;
        _batchData = _serverModel.getPageData(vector);
        if(_batchData == null || _batchData.size() != ai.length)
        {
            _batchBegin = false;
            _selectedRows = null;
            return false;
        } else
        {
            _batchBegin = true;
            return true;
        }
    }

    public Object getValueAtEx(int i, int j)
    {
        if(_cacheManager.isDataInTheCache(i))
            return getValueAt(i, j);
        if(_batchBegin)
        {
            int k = getPosition(i);
            if(k == -1)
                return null;
            else
                return _serverModel.translate(_batchData.elementAt(k), j, i);
        }
        Vector vector = new Vector(1, 1);
        int ai[] = new int[1];
        ai[0] = i;
        _serverModel.getScopeEx(vector, ai);
        Vector vector1 = _serverModel.getPageData(vector);
        if(vector1 == null || vector1.size() != 1)
            return null;
        else
            return _serverModel.translate(vector1.elementAt(0), j, i);
    }

    private int getPosition(int i)
    {
        for(int j = 0; j < _selectedRows.length; j++)
            if(_selectedRows[j] == i)
                return j;

        return -1;
    }

    public void endReadSelectedBatch()
    {
        _batchBegin = false;
        _batchData = null;
        _selectedRows = null;
    }

    public boolean isDataInTheCache(int ai[])
    {
        if(ai == null || ai.length == 0)
            return false;
        boolean flag = true;
        for(int i = 0; i < ai.length; i++)
        {
            boolean flag1 = _cacheManager.isDataInTheCache(ai[i]) && _cacheManager.gettingDataFinished();
            if(flag1)
                continue;
            flag = false;
            break;
        }

        return flag;
    }

    public CacheManager getCacheManager()
    {
        return _cacheManager;
    }

    public boolean isFinished()
    {
        if(_cacheManager != null)
            return _cacheManager.gettingDataFinished();
        else
            return false;
    }

    public static final int Cache_SIZE = 150;
    private CacheManager _cacheManager;
    private ServerModel _serverModel;
    private static ModificationValue _tempObj = new ModificationValue(-1, -1, null);
    private Object _columnIndentifiers[];
    private CacheTableStatusViewer _statusViewer;
    private Vector _modification;
    private boolean _batchBegin;
    private Vector _batchData;
    private int _selectedRows[];

}

⌨️ 快捷键说明

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