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

📄 gridstoragesinglehashtable.java

📁 PDBView是一个可以查看palmOS执行包*.pdb(类似于java包*.jar)结构的小工具
💻 JAVA
字号:
/* 
 * WExtLib - A class library for the Superwaba Virtual Machine
 * Copyright (C) 2005, Virgilio Alexandre Fornazin
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package wextlib.ui.grid;

/**
 * This class implements an single hashtable-based storage model for the grid control.
 * Use this storage when you don't plan to remove lines or columns, just add. This is
 * the default storage model for the Grid control, because it could grow too fast
 * (don't need to copy from old to new storage like GridStorageArray).
 * 
 * @author Virgilio Alexandre Fornazin (mailto:virgiliofornazin@gmail.com)
 */
public final class GridStorageSingleHashtable extends GridStorageModel 
{
	/** Model rows count */
	private int m_iRowCount;
	/** Model cols count */
	private int m_iColCount;
	/** Cell's Hashtable */
	private GridCellHashtable m_mapCells;
	
	/**
	 * Default constructor
	 */
	public GridStorageSingleHashtable()
	{
		eraseAllCells();
	}
	
	public GridCell createCell(GridCellID cellID) 
	{
		int ID = cellID.getCellID();
		
		GridCell cell = m_mapCells.get(ID);
		
		if (cell == null)
		{
			cell = new GridCell();
			
			m_mapCells.put(ID, cell);
		}
		
		return cell;
	}

	public GridCell getCell(GridCellID cellID) 
	{
		return m_mapCells.get(cellID.getCellID());
	}

	public void putCell(GridCellID cellID, GridCell cell) 
	{
		m_mapCells.put(cellID.getCellID(), cell);
	}

	public void eraseCell(GridCellID cellID) 
	{
		m_mapCells.remove(cellID.getCellID());
	}

	public void eraseAllCells()
	{
		m_iRowCount = 0;
		m_iColCount = 0;
		
		m_mapCells = new GridCellHashtable(24);
	}

	public GridCellHashtable getRowCells(int iRow)
	{
		GridCellHashtable gcht = new GridCellHashtable((int) (m_iColCount / 4));
		GridCellID cellID = new GridCellID(iRow, -1);
		GridCell cell;
		
		for (int i = 0; i < m_iColCount; i++)
		{
			cellID.Col = i;
			
			cell = m_mapCells.get(cellID.getCellID());
			
			if (cell != null)
			{
				gcht.put(i, cell);
			}
		}
		
		return gcht;
	}
	
	public GridCellHashtable getColCells(int iCol)
	{
		GridCellHashtable gcht = new GridCellHashtable((int) (m_iRowCount / 4));
		GridCellID cellID = new GridCellID(-1, iCol);
		GridCell cell;
		
		for (int i = 0; i < m_iRowCount; i++)
		{
			cellID.Row = i;
			
			cell = m_mapCells.get(cellID.getCellID());
			
			if (cell != null)
			{
				gcht.put(i, cell);
			}
		}
		
		return gcht;
	}
	
	public void setRowCount(int iRowCount) 
	{
		if (m_iRowCount == iRowCount)
		{
			return;
		}
		
		if (iRowCount < m_iRowCount)
		{
			_removePendingRows(iRowCount, m_iRowCount);
		}

		m_iRowCount = iRowCount;
	}
	
	public int getRowCount()
	{
		return m_iRowCount;
	}
	
	public int removeRows(int iRowStart, int iRowEnd)
	{
		if (iRowEnd == m_iRowCount - 1)
		{
			setRowCount(iRowStart);
			
			return m_iRowCount;
		}
		
		int iRowCount = m_iRowCount - ((iRowEnd - iRowStart) + 1);
		
		if ((iRowCount < 1) || (m_iColCount == 0))
		{
			iRowCount = 0;
			
			m_mapCells = new GridCellHashtable(24);
		}
		else
		{
			GridCellID readID = new GridCellID();
			GridCellID writeID = new GridCellID();
			
			GridCell cell;
			
			readID.Row = iRowEnd + 1;
			writeID.Row = iRowStart;
			
			while (readID.Row <= iRowCount)
			{
				for (int c = 0; c < m_iColCount; c++)
				{
					readID.Col = c;
					writeID.Col = c;
					
					cell = m_mapCells.get(readID.getCellID());
					
					if (cell == null)
					{
						m_mapCells.remove(writeID.getCellID());
					}
					else
					{
						m_mapCells.put(writeID.getCellID(), cell);
					}
				}
				
				readID.Row++;
				writeID.Row++;
			}
		}
		
		if (iRowCount < m_iRowCount)
		{
			_removePendingRows(iRowCount, m_iRowCount);
		}
		
		m_iRowCount = iRowCount;
		
		return m_iRowCount;
	}

	public void setColCount(int iColCount) 
	{
		if (m_iColCount == iColCount)
		{
			return;
		}
		
		if (iColCount < m_iColCount)
		{
			_removePendingCols(iColCount, m_iColCount);
		}
	
		m_iColCount = iColCount;
	}

	public int getColCount()
	{
		return m_iColCount;
	}
	
	public int removeCols(int iColStart, int iColEnd)
	{
		if (iColEnd == m_iColCount - 1)
		{
			setColCount(iColStart);
			
			return m_iColCount;
		}
		
		int iColCount = m_iColCount - ((iColEnd - iColStart) + 1);
		
		if ((iColCount < 1) || (m_iRowCount == 0))
		{
			iColCount = 0;
			
			m_mapCells = new GridCellHashtable(24);
		}
		else
		{
			GridCellID readID = new GridCellID();
			GridCellID writeID = new GridCellID();
			
			GridCell cell;
			
			readID.Col = iColEnd + 1;
			writeID.Col = iColStart;
			
			while (readID.Col <= iColCount)
			{
				for (int r = 0; r < m_iRowCount; r++)
				{
					readID.Row = r;
					writeID.Row = r;
					
					cell = m_mapCells.get(readID.getCellID());
					
					if (cell == null)
					{
						m_mapCells.remove(writeID.getCellID());
					}
					else
					{
						m_mapCells.put(writeID.getCellID(), cell);
					}
				}
				
				readID.Col++;
				writeID.Col++;
			}
		}
	
		if (iColCount < m_iColCount)
		{
			_removePendingCols(iColCount, m_iColCount);
		}
		
		m_iColCount = iColCount;
		
		return m_iColCount;
	}
	
	private void _removePendingRows(int iRowStart, int iRowEnd)
	{
		GridCellID cellID = new GridCellID();
		
		for (int r = iRowStart; r < iRowEnd; r++)
		{
			cellID.Row = r;
			
			for (int c = 0; c < m_iRowCount; c++)
			{
				cellID.Col = c;
				
				m_mapCells.remove(cellID.getCellID());
			}
		}
	}
	
	private void _removePendingCols(int iColStart, int iColEnd)
	{
		GridCellID cellID = new GridCellID();
		
		for (int c = iColStart; c < iColEnd; c++)
		{
			cellID.Col = c;
			
			for (int r = 0; r < m_iRowCount; r++)
			{
				cellID.Row = r;
				
				m_mapCells.remove(cellID.getCellID());
			}
		}
	}
}

⌨️ 快捷键说明

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