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

📄 grid.java

📁 PDBView是一个可以查看palmOS执行包*.pdb(类似于java包*.jar)结构的小工具
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			}
			else
			{
				m_mapColAttributes.put(i, colAttr);
			}
		}

		for (i = iColStart; i <= m_iColCount; i++)
		{
			cellType = m_mapColCellTypes.remove(i + iColStep);
			
			if (cellType == null)
			{
				m_mapColCellTypes.remove(i);
			}
			else
			{
				m_mapColCellTypes.put(i, cellType);
			}
		}
		
		if (iColEnd == m_iColCount - 1)
		{
			setColCount(iColStart);
		}
		else
		{
			setColCount(m_Storage.removeCols(iColStart, iColEnd));
		}
		
		if ((iColStart <= m_userSelectedCellID.Col) && (m_userSelectedCellID.Col <= iColEnd))
		{
			m_userSelectedCellID.Col = -1;
		}
		
		m_bUpdating = bUpdating;
		
		_repaintGridIfNeeded();
	}
	
	/**
	 * Remove a column from grid
	 */
	public void removeCol(int iCol)
	{
		removeCols(iCol, 1);
	}
	
	/**
	 * Scroll the grid vertically
	 */
	public void scrollVertical(int iDelta)
	{
		if ((iDelta == 0) || (m_iRowCount == 0))
		{
			return;
		}
		
		int iNewRow = m_userSelectedCellID.Row + iDelta;
		
		if (iNewRow < m_iFixedRowCount)
		{
			iNewRow = m_iFixedRowCount;
		}
		else if (iNewRow > (m_iRowCount - 1))
		{
			iNewRow = m_iRowCount - 1;
		}
		
		if (m_userSelectedCellID.Row == iNewRow)
		{
			return;
		}
		
		m_userSelectedCellID.Row = iNewRow;
		
		if (m_userSelectedCellID.Row < m_iTopRow)
		{
			m_iTopRow = m_userSelectedCellID.Row;
		}
		else if (m_userSelectedCellID.Row >= m_iBottomRow)
		{
			m_iTopRow += ((m_userSelectedCellID.Row + (m_bBottomRowFullDraw ? 0 : 1)) - m_iBottomRow);
		}
		
		if (m_userSelectedCellID.Col == -1)
		{
			m_userSelectedCellID.Col = m_iFixedColCount;
		}
		
		m_VertScroll.setValue(m_iTopRow - m_iFixedRowCount);
		
		GridEvent evt = new GridEvent();
		
		evt.target = this;
		evt.type = GridEvent.SELECTION_CHANGED;
		evt.cellID = new GridCellID(m_userSelectedCellID.Row, m_userSelectedCellID.Col);
		
		postEvent(evt);
		
		_repaintGridIfNeeded();
	}

	/**
	 * Scroll the grid horizontally
	 */
	public void scrollHorizontal(int iDelta)
	{
		if ((iDelta == 0) || (m_iColCount == 0))
		{
			return;
		}

		int iNewCol = m_userSelectedCellID.Col + iDelta;
		
		if (iNewCol < m_iFixedColCount)
		{
			iNewCol = m_iFixedColCount;
		}
		else if (iNewCol > (m_iColCount - 1))
		{
			iNewCol = m_iColCount - 1;
		}

		if (m_userSelectedCellID.Col == iNewCol)
		{
			return;
		}
		
		m_userSelectedCellID.Col = iNewCol;
		
		if (m_userSelectedCellID.Col < m_iLeftCol)
		{
			m_iLeftCol = m_userSelectedCellID.Col;
		}
		else if (m_userSelectedCellID.Col >= m_iRightCol)
		{
			m_iLeftCol += ((m_userSelectedCellID.Col + (m_bRightColFullDraw ? 0 : 1)) - m_iRightCol);
		}
		
		if (m_userSelectedCellID.Row == -1)
		{
			m_userSelectedCellID.Row = m_iFixedRowCount;
		}
		
		m_HorzScroll.setValue(m_iLeftCol - m_iFixedColCount);
		
		GridEvent evt = new GridEvent();
		
		evt.target = this;
		evt.type = GridEvent.SELECTION_CHANGED;
		evt.cellID = new GridCellID(m_userSelectedCellID.Row, m_userSelectedCellID.Col);
		
		postEvent(evt);
		
		_repaintGridIfNeeded();
	}
	
	/**
	 * Scroll the grid up one row
	 */
	public void scrollUp()
	{
		scrollVertical(-1);
	}
	
	/**
	 * Scroll the grid down one row
	 */
	public void scrollDown()
	{
		scrollVertical(1);
	}
	   
	/**
	 * Scroll the grid left one column
	 */
	public void scrollLeft()
	{
		scrollHorizontal(-1);
	}
	
	/**
	 * Scroll the grid right one column
	 */
	public void scrollRight()
	{
		scrollHorizontal(1);
	}

	/**
	 * Scroll the grid up N rows
	 */
	public void scrollUpLines(int iLinesCount)
	{
		scrollVertical(0 - iLinesCount);
	}

	/**
	 * Scroll the grid down N rows
	 */
	public void scrollDownLines(int iLinesCount)
	{
		scrollVertical(iLinesCount);
	}

	/**
	 * Scroll the grid left N columns
	 */
	public void scrollLeftColumns(int iColumnsCount)
	{
		scrollHorizontal(0 - iColumnsCount);
	}
	
	/**
	 * Scroll the grid right N columns
	 */
	public void scrollRightColumns(int iColumnsCount)
	{
		scrollHorizontal(iColumnsCount);
	}
	
	/**
	 * Scroll to the first grid row 
	 */
	public void toUp()
	{
		m_userSelectedCellID.Row = 0;
		
		if (m_userSelectedCellID.Col == -1)
		{
			m_userSelectedCellID.Col = m_iFixedColCount;
		}
		
		setTopRow(0);
   }
	
	/**
	 * Scroll to the last grid row 
	 */
	public void toDown()
	{
		m_userSelectedCellID.Row = m_iRowCount - 1;
		
		if (m_userSelectedCellID.Col == -1)
		{
			m_userSelectedCellID.Col = m_iFixedColCount;
		}
		
		setTopRow(m_iRowCount - 1);
	}
	
	/**
	 * Scroll to the first grid column 
	 */
	public void toLeft()
	{
		m_userSelectedCellID.Col = 0;
		
		if (m_userSelectedCellID.Row == -1)
		{
			m_userSelectedCellID.Row = m_iFixedRowCount;
		}
		
		setLeftCol(0);
	}
	
	/**
	 * Scroll to the last grid column 
	 */
	public void toRight()
	{
		m_userSelectedCellID.Col = m_iColCount - 1;
		
		if (m_userSelectedCellID.Row == -1)
		{
			m_userSelectedCellID.Row = m_iFixedRowCount;
		}
		
		setLeftCol(m_iColCount - 1);
	}
	
	/** 
	 * Ensure that current selected cell is visible 
	 */
	public void ensureVisibleSelection()
	{
		boolean bChanged = false;
		boolean bUpdating = m_bUpdating;

		m_bUpdating = false;
				
		if (m_userSelectedCellID.Col != -1) 
		{
			if ((m_userSelectedCellID.Col < m_iLeftCol) || ((m_userSelectedCellID.Col > m_iRightCol) 
				|| ((m_userSelectedCellID.Col == m_iRightCol) && !m_bRightColFullDraw)))
			{
				m_iLeftCol = m_userSelectedCellID.Col;
				m_HorzScroll.setValue(m_iLeftCol);
				
				bChanged = true;
			}
		}
		
		if (m_userSelectedCellID.Row != -1) 
		{
			if ((m_userSelectedCellID.Row < m_iTopRow) || ((m_userSelectedCellID.Row > m_iBottomRow) 
				|| ((m_userSelectedCellID.Row == m_iBottomRow) && !m_bBottomRowFullDraw)))
			{
				m_iTopRow = m_userSelectedCellID.Row;
				m_VertScroll.setValue(m_iTopRow);
				
				bChanged = true;
			}
		}
		
		m_bUpdating = bUpdating;
		
		if (bChanged)
		{
			_repaintGridIfNeeded();
		}
	}
	
	private Rect _getCellDrawRect()
	{
		Rect rc = getRect();

		rc.x = 1;
		rc.y = 1;
		rc.width -= (1 + (m_VertScroll.isVisible() ? m_iVerticalScrollWidth : 0));
		rc.height -= (1 + (m_HorzScroll.isVisible() ? m_iHorizontalScrollHeight : 0));
		
		return rc;
	}
	
	private void _repaintGridIfNeeded()
	{
		if (isVisible() && m_bUpdating)
		{
			repaint();
		}
	}

	public void onPaint(Graphics g)
	{
		m_iRightCol = -1;
		m_iBottomRow = -1;
		
		m_bBottomRowFullDraw = true;
		m_bRightColFullDraw = true;
		
		if (!m_bUpdating)
		{
			return;
		}
		
		Rect rc = _getCellDrawRect();

		if ((rc.width < 1) || (rc.height < 1))
		{
			return;
		}

		if ((m_iRowCount > 0) && (m_iColCount > 0))
		{
			GridCellID cellID = new GridCellID();
			GridCellDrawParams params = new GridCellDrawParams();
			GridCell cell;
			
			boolean bFixedRowExceededHeight = true;
			boolean bFixedColExceededWidth = true;
			
			boolean bExceededHeight = true;
			boolean bExceededWidth = true;
			
			int iRowLoop;
			int iColLoop;
			
			int iRightX = params.rcClip.x;
			int iBottomY = params.rcClip.y;
			
			m_iLeftColX = params.rcClip.x;
			m_iTopRowY = params.rcClip.y;
			
			params.graphics = g;
			params.clrGridCellSeparatorColor = m_clrGridCellSeparatorColor;
			params.iColSeparatorWidth = m_iColSeparatorWidth;
			params.iRowSeparatorHeight = m_iRowSeparatorHeight;
			
			params.clrCellBackColor = m_cellAttributesFixed.m_clrCellBackColor;
			params.clrCellForeColor = m_cellAttributesFixed.m_clrCellForeColor;
			params.font = m_cellAttributesFixed.m_CellFont;
			
			params.bDrawHorizontalLine = m_bDrawRowSeparators;
			params.rcClip.y = rc.y;
	
			bFixedRowExceededHeight = false;
			
			for (iRowLoop = 0; (iRowLoop < m_iFixedRowCount) && !bFixedRowExceededHeight; iRowLoop++)
			{
				cellID.Row = iRowLoop;
				params.iCellHeight = getRowHeight(iRowLoop);
				
				params.bDrawVerticalLine = m_bDrawColSeparators;
				params.rcClip.x = rc.x;
				
				bFixedRowExceededHeight = ((params.rcClip.y + params.iCellHeight) > rc.height);
				
				if (bFixedRowExceededHeight)
				{
					params.rcClip.height = rc.height - params.rcClip.y;
					params.bDrawHorizontalLine = false;
				}
				else
				{
					params.rcClip.height = params.iCellHeight;
				}
				
				bFixedColExceededWidth = false;
				
				for (iColLoop = 0; (iColLoop < m_iFixedColCount) && !bFixedColExceededWidth; iColLoop++)
				{
					cellID.Col = iColLoop;
					params.iCellWidth = getColWidth(iColLoop);

					cell = m_Storage.getCell(cellID);
					
					if (cell == null)
					{
						cell = m_cellAttributesFixed;
					}
					
					bFixedColExceededWidth = ((params.rcClip.x + params.iCellWidth) > rc.width);
					
					if (bFixedColExceededWidth)
					{
						params.rcClip.width = rc.width - params.rcClip.x;
						params.bDrawVerticalLine = false;
					}
					else
					{
						params.rcClip.width = params.iCellWidth;
					}
					
					params.iCellAlignment = GridCellAttributes.handleAlign(cell.m_iCellAlignment, m_cellAttributesFixed.m_iCellAlignment);
	
					g.setClip(params.rcClip);
					cell.onPaint(params);
					
					if (!bFixedColExceededWidth)
					{
						params.rcClip.x += params.iCellWidth;
						m_iLeftColX = params.rcClip.x;
						
						if (iRightX < params.rcClip.x)
						{
							iRightX = params.rcClip.x;
						}
					}
				}
				
				if (!bFixedRowExceededHeight)
				{
					params.rcClip.y += params.iCellHeight;
					m_iTopRowY = params.rcClip.y;
					
					if (iBottomY < params.rcClip.y)
					{
						iBottomY = params.rcClip.y;
					}
				}
			}
			
			if (!bFixedColExceededWidth)
			{
				params.bDrawHorizontalLine = m_bDrawRowSeparators;
				params.rcClip.y = rc.y;
				
				bExceededHeight = false;
				
				for (iRowLoop = 0; (iRowLoop < m_iFixedRowCount) && !bExceededHeight; iRowLoop++)
				{
					cellID.Row = iRowLoop;
					params.iCellHeight = getRowHeight(iRowLoop);
					
					params.bDrawVerticalLine = m_bDrawColSeparators;
					params.rcClip.x = m_iLeftColX;
					
					bExceededHeight = ((params.rcClip.y + params.iCellHeight) > rc.height);
					
					if (bExceededHeight)
					{
						params.rcClip.height = rc.height - params.rcClip.y;
						params.bDrawHorizontalLine = false;
					}
					else
					{
						params.rcClip.height = params.iCellHeight;
					}
					
					bExceededWidth = false;
					
					for (iColLoop = m_iLeftCol; (iColLoop < m_iColCount) && !bExceededWidth; iColLoop++)
					{
						cellID.Col = iColLoop;
						params.iCellWidth = getColWidth(iColLoop);
						
						cell = m_Storage.getCell(cellID);
						
						if (cell == null)
						{
							cell = m_cellAttributesFixed;
						}
						
						bExceededWidth = ((params.rcClip.x + params.iCellWidth) > rc.width);
						
						if (bExceededWidth)
						{
							params.rcClip.width = rc.width - params.rcClip.x;
							params.bDrawVerticalLine = false;
						}
						else
						{
							params.rcClip.width = params.iCellWidth;
						}
						
						params.iCellAlignment = GridCellAttributes.handleAlign(cell.m_iCellAlignment, m_cellAttributesFixed.m_iCellAlignment);
						
						g.setClip(params.rcClip);
						cell.onPaint(params);
						
						if (!bExceededWidth)
						{
							params.rcClip.x += params.iCellWidth;
							
							if (iRightX < params.rcClip.x)
							{
								iRightX = params.rcClip.x;
							}
						}
					}
					
					if (!bExceededHeight)
					{
						params.rcClip.y += params.iCellHeight;
						m_iTopRowY = params.rcClip.y;
						
						if (iBottomY < params.rcClip.y)
						{
							iBottomY = params.rcClip.y;
						}
					}
				}
			}
			
			if (!bFixedRowExceededHeight)
			{
				params.bDrawVerticalLine = m_bDrawColSeparators;
				params.rcClip.x = rc.x;
				
				bExceededWidth = false;
				
				for (iColLoop = 0; (iColLoop < m_iFixedColCount) && !bExceededWidth; iColLoop++)
				{
					cellID.Col = iColLoop;
					params.iCellWidth = getColWidth(iColLoop);
					
					params.bDrawHorizontalLine = m_bDrawRowSeparators;
					params.rcClip.y = m_iTopRowY;
					
					bExceededWidth = ((params.rcClip.x + params.iCellWidth) > rc.width);
					
					if (bExceededWidth)
					{
						params.rcClip.width = rc.width - params.rcClip.x;
						params.bDrawVerticalLine = false;
					}
					else
					{
						params.rcClip.width = params.iCellWidth;
					}
					
					bExceededHeight = false;
					
					for (iRowLoop = m_iTopRow; (iRowLoop < m_iRowCount) && !bExceededHeight; iRowLoop++)
					{
						cellID.Row = iRowLoop;
						params.iCellHeight = getRowHeight(iRowLoop);
						
						cell = m_Storage.getCell(cellID);
						
						if (cell == null)
						{
							cell = m_cellAttributesFixed;
						}
						
						bExceededHeight = ((params.rcClip.y + params.iCellHeight) > rc.height);
						
						if (bExceededHeight)
						{
							params.rcClip.height = rc.height - params.rcClip.y;
							params.bDrawHorizontalLine = false;
						}
						else
						{
							params.rcClip.height = params.iCellHeight;
						}
						
						params.iCellAlignment = GridCellAttributes.handleAlign(cell.m_iCellAlignment, m_cellAttributesFixed.m_iCellAlignment);
						
						g.setClip(params.rcClip);
						cell.onPaint(params);
						
						if (!bExceededHeight)
						{
							params.rcClip.y += params.iCellHeight;
							
							if (iBottomY < params.rcClip.y)
							{
								iBottomY = params.rcClip.y;
							}
						}
					}
					
					if (!bExceededWidth)
					{
						params.rcClip.x += params.iCellWidth;
						m_iLeftColX = params.rcClip.x;
						
						if (iRightX < params.rcClip.x)
						{
							iRightX = params.rcClip.x;
						}
					}
				}
			}
			
			if (!bFixedColExceededWidth || !bFixedRowExceededHeight)
			{
				GridCellAttributes rowAttr;
				GridCellAttributes colAttr;
				GridCellAttributes cellAttr;
				
				boolean bCellIsSelected;
				
				params.bDrawHorizontalLine = m_bDrawRowSeparators;
				params.rcClip.y = m_iTo

⌨️ 快捷键说明

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