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

📄 gridstoragearray.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 array-based storage model for the grid control.
 * Use this storage model when you don't want to change te number of the
 * row and columns, because it users a array of array of GridCell objects
 * and copy from the old array to the new array when you change the number
 * of rows and coluns, and this could be EXTREME SLOW!
 * 
 * @author Virgilio Alexandre Fornazin (mailto:virgiliofornazin@gmail.com)
 */
public final class GridStorageArray extends GridStorageModel 
{
	/** Model rows count */
	private int m_iRowCount;
	/** Model cols count */
	private int m_iColCount;
	/** Cell's array */
	private GridCell [][] m_Cells;
	
	/**
	 * Default constructor
	 */
	public GridStorageArray()
	{
		eraseAllCells();
	}
	
	public GridCell createCell(GridCellID cellID) 
	{
		try
		{
			GridCell cell = m_Cells[cellID.Row][cellID.Col];
			
			if (cell == null)
			{
				cell = new GridCell();
				
				m_Cells[cellID.Row][cellID.Col] = cell;
			}
			
			return cell;
		}
		catch (Exception e)
		{
			return null;
		}
	}

	public GridCell getCell(GridCellID cellID) 
	{
		try
		{
			return m_Cells[cellID.Row][cellID.Col];
		}
		catch (Exception e)
		{
			return null;
		}
	}

	public void putCell(GridCellID cellID, GridCell cell) 
	{
		try
		{
			m_Cells[cellID.Row][cellID.Col] = cell;
		}
		catch (Exception e)
		{
		}
	}

	public void eraseCell(GridCellID cellID) 
	{
		try
		{
			m_Cells[cellID.Row][cellID.Col] = null;
		}
		catch (Exception e)
		{
		}
	}

	public void eraseAllCells()
	{	
		m_iRowCount = 0;
		m_iColCount = 0;

		m_Cells = null;
	}

	public GridCellHashtable getRowCells(int iRow)
	{
		GridCellHashtable gcht = new GridCellHashtable((int) (m_iColCount / 2));
		
		try
		{
			for (int i = 0; i < m_iColCount; i++)
			{
				if (m_Cells[iRow][i] != null)
				{
					gcht.put(i, m_Cells[iRow][i]);
				}
			}
		}
		catch (Exception e)
		{
		}
		
		return gcht;
	}
	
	public GridCellHashtable getColCells(int iCol)
	{
		GridCellHashtable gcht = new GridCellHashtable((int) (m_iRowCount / 2));
		
		try
		{
			for (int i = 0; i < m_iRowCount; i++)
			{
				if (m_Cells[i][iCol] != null)
				{
					gcht.put(i, m_Cells[i][iCol]);
				}
			}
		}
		catch (Exception e)
		{
		}
		
		return gcht;
	}
		
	public void setRowCount(int iRowCount) 
	{
		if (m_iRowCount == iRowCount)
		{
			return;
		}
		
		GridCell [][] cells = null;
		
		if ((iRowCount > 0) && (m_iColCount > 0))
		{
			int iLoop = Math.min(m_iRowCount, iRowCount);

			cells = new GridCell[iRowCount][m_iColCount];
			
			for (int r = 0; r < iLoop; r++)
			{
				for (int c = 0; c < m_iColCount; c++)
				{
					cells[r][c] = m_Cells[r][c];
				}
			}
		}
			
		m_Cells = cells;
	
		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);
		
		GridCell [][] cells = null;
		
		if ((iRowCount > 0) && (m_iColCount > 0))
		{
			int i;
			
			cells = new GridCell[iRowCount][m_iColCount];
			
			for (i = 0; i < iRowStart; i++)
			{
				for (int c = 0; c < m_iColCount; c++)
				{
					cells[i][c] = m_Cells[i][c];
				}
			}
			
			for (int ni = iRowEnd + 1; ni < m_iRowCount; ni++)
			{
				for (int c = 0; c < m_iColCount; c++)
				{
					cells[i][c] = m_Cells[ni][c];
				}

				i++;
			}
		}
			
		m_Cells = cells;
		m_iRowCount = iRowCount;

		return m_iRowCount;
	}

	public void setColCount(int iColCount) 
	{
		if (m_iColCount == iColCount)
		{
			return;
		}
		
		GridCell [][] cells = null;
		
		if ((iColCount > 0) && (m_iRowCount > 0))
		{
			int iLoop = Math.min(m_iColCount, iColCount);

			cells = new GridCell[m_iRowCount][iColCount];
			
			for (int c = 0; c < iLoop; c++)
			{
				for (int r = 0; r < m_iRowCount; r++)
				{
					cells[r][c] = m_Cells[r][c];
				}
			}
		}
			
		m_Cells = cells;
	
		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);
		
		GridCell [][] cells = null;
		
		if ((iColCount > 0) && (m_iRowCount > 0))
		{
			int i;
			
			cells = new GridCell[m_iRowCount][iColCount];
			
			for (i = 0; i < iColStart; i++)
			{
				for (int r = 0; r < m_iRowCount; r++)
				{
					cells[r][i] = m_Cells[r][i];
				}
			}
			
			for (int ni = iColEnd + 1; ni < m_iColCount; ni++)
			{
				for (int r = 0; r < m_iRowCount; r++)
				{
					cells[r][i] = m_Cells[r][ni];
				}

				i++;
			}
		}
			
		m_Cells = cells;
		m_iColCount = iColCount;
		
		return m_iColCount;
	}
}

⌨️ 快捷键说明

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