📄 grid.java
字号:
* Clear a grid cell object
*/
public void clearCell(GridCellID cellID)
{
m_Storage.eraseCell(cellID);
_repaintGridIfNeeded();
}
/**
* Clear a grid cell object
*/
public void clearCell(int iRow, int iCol)
{
clearCell(new GridCellID(iRow, iCol));
}
/**
* Get the grid cell text
*/
public String getCellText(GridCellID cellID)
{
try
{
return m_Storage.getCell(cellID).m_strCellText;
}
catch (Exception e)
{
return "";
}
}
/**
* Get the grid cell text
*/
public String getCellText(int iRow, int iCol)
{
return getCellText(new GridCellID(iRow, iCol));
}
/**
* Set the grid cell text
*/
public void setCellText(GridCellID cellID, String strCellText)
{
try
{
m_Storage.createCell(cellID).m_strCellText = strCellText;
_repaintGridIfNeeded();
}
catch (Exception e)
{
}
}
/**
* Set the grid cell text
*/
public void setCellText(int iRow, int iCol, String strCellText)
{
setCellText(new GridCellID(iRow, iCol), strCellText);
}
/**
* Clear the grid cell text
*/
public void clearCellText(GridCellID cellID)
{
try
{
m_Storage.getCell(cellID).m_strCellText = "";
_repaintGridIfNeeded();
}
catch (Exception e)
{
}
}
/**
* Clear the grid cell text
*/
public void clearCellText(int iRow, int iCol)
{
clearCellText(new GridCellID(iRow, iCol));
}
/**
* Get the grid cell Alignment
*/
public int getCellAlignment(GridCellID cellID)
{
try
{
return m_Storage.getCell(cellID).m_iCellAlignment;
}
catch (Exception e)
{
return GridCellAttributes.ALIGN_DEFAULT;
}
}
/**
* Get the grid cell Alignment
*/
public int getCellAlignment(int iRow, int iCol)
{
return getCellAlignment(new GridCellID(iRow, iCol));
}
/**
* Set the grid cell Alignment
*/
public void setCellAlignment(GridCellID cellID, int iCellAlignment)
{
try
{
m_Storage.createCell(cellID).m_iCellAlignment = iCellAlignment;
_repaintGridIfNeeded();
}
catch (Exception e)
{
}
}
/**
* Set the grid cell Alignment
*/
public void setCellAlignment(int iRow, int iCol, int iCellAlignment)
{
setCellAlignment(new GridCellID(iRow, iCol), iCellAlignment);
}
/**
* Clear the grid cell Alignment
*/
public void clearCellAlignment(GridCellID cellID)
{
try
{
m_Storage.getCell(cellID).m_iCellAlignment = GridCellAttributes.ALIGN_DEFAULT;
_repaintGridIfNeeded();
}
catch (Exception e)
{
}
}
/**
* Clear the grid cell Alignment
*/
public void clearCellAlignment(int iRow, int iCol)
{
clearCellAlignment(new GridCellID(iRow, iCol));
}
/**
* Get the grid cell background color
*/
public Color getCellBackColor(GridCellID cellID)
{
try
{
return m_Storage.getCell(cellID).m_clrCellBackColor;
}
catch (Exception e)
{
return null;
}
}
/**
* Get the grid cell background color
*/
public Color getCellBackColor(int iRow, int iCol)
{
return getCellBackColor(new GridCellID(iRow, iCol));
}
/**
* Set the grid cell background color
*/
public void setCellBackColor(GridCellID cellID, Color clrCellBackColor)
{
try
{
m_Storage.createCell(cellID).m_clrCellBackColor = clrCellBackColor;
_repaintGridIfNeeded();
}
catch (Exception e)
{
}
}
/**
* Set the grid cell background color
*/
public void setCellBackColor(int iRow, int iCol, Color clrCellBackColor)
{
setCellBackColor(new GridCellID(iRow, iCol), clrCellBackColor);
}
/**
* Clear the grid cell background color
*/
public void clearCellBackColor(GridCellID cellID)
{
try
{
m_Storage.getCell(cellID).m_clrCellBackColor = null;
_repaintGridIfNeeded();
}
catch (Exception e)
{
}
}
/**
* Clear the grid cell background color
*/
public void clearCellBackColor(int iRow, int iCol)
{
clearCellBackColor(new GridCellID(iRow, iCol));
}
/**
* Get the grid cell foreground color
*/
public Color getCellForeColor(GridCellID cellID)
{
try
{
return m_Storage.getCell(cellID).m_clrCellForeColor;
}
catch (Exception e)
{
return null;
}
}
/**
* Get the grid cell foreground color
*/
public Color getCellForeColor(int iRow, int iCol)
{
return getCellForeColor(new GridCellID(iRow, iCol));
}
/**
* Set the grid cell foreground color
*/
public void setCellForeColor(GridCellID cellID, Color clrCellForeColor)
{
try
{
m_Storage.createCell(cellID).m_clrCellForeColor = clrCellForeColor;
_repaintGridIfNeeded();
}
catch (Exception e)
{
}
}
/**
* Set the grid cell foreground color
*/
public void setCellForeColor(int iRow, int iCol, Color clrCellForeColor)
{
setCellForeColor(new GridCellID(iRow, iCol), clrCellForeColor);
}
/**
* Clear the grid cell foreground color
*/
public void clearCellForeColor(GridCellID cellID)
{
try
{
m_Storage.getCell(cellID).m_clrCellForeColor = null;
_repaintGridIfNeeded();
}
catch (Exception e)
{
}
}
/**
* Clear the grid cell foreground color
*/
public void clearCellForeColor(int iRow, int iCol)
{
clearCellForeColor(new GridCellID(iRow, iCol));
}
/**
* Get the grid cell font
*/
public Font getCellFont(GridCellID cellID)
{
try
{
return m_Storage.getCell(cellID).m_CellFont;
}
catch (Exception e)
{
return null;
}
}
/**
* Get the grid cell font
*/
public Font getCellFont(int iRow, int iCol)
{
return getCellFont(new GridCellID(iRow, iCol));
}
/**
* Set the grid cell font
*/
public void setCellFont(GridCellID cellID, Font cellFont)
{
try
{
m_Storage.createCell(cellID).m_CellFont = cellFont;
_repaintGridIfNeeded();
}
catch (Exception e)
{
}
}
/**
* Set the grid cell font
*/
public void setCellFont(int iRow, int iCol, Font cellFont)
{
setCellFont(new GridCellID(iRow, iCol), cellFont);
}
/**
* Clear the grid cell font
*/
public void clearCellFont(GridCellID cellID)
{
try
{
m_Storage.getCell(cellID).m_CellFont = null;
_repaintGridIfNeeded();
}
catch (Exception e)
{
}
}
/**
* Clear the grid cell font
*/
public void clearCellFont(int iRow, int iCol)
{
clearCellFont(new GridCellID(iRow, iCol));
}
/**
* Get current selected cell ID
*/
public GridCellID getUserSelectedCellID()
{
return m_userSelectedCellID;
}
/**
* Set current selected cell ID
*/
public void setUserSelectedCellID(GridCellID cellID)
{
if (!cellID.isValid(m_iRowCount, m_iColCount))
{
return;
}
boolean bUpdating = m_bUpdating;
m_bUpdating = false;
setUserSelectedCol(cellID.Col);
setUserSelectedCol(cellID.Row);
m_bUpdating = bUpdating;
_repaintGridIfNeeded();
}
/**
* Get current selected row
*/
public int getUserSelectedRow()
{
return m_userSelectedCellID.Row;
}
/**
* Set current selected row
*/
public void setUserSelectedRow(int iSelectedRow)
{
if ((iSelectedRow < m_iFixedRowCount) || (iSelectedRow >= m_iRowCount))
{
m_userSelectedCellID.Row = -1;
m_userSelectedCellID.Col = -1;
}
else
{
m_userSelectedCellID.Row = iSelectedRow;
if (m_userSelectedCellID.Col == -1)
{
m_userSelectedCellID.Col = 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();
}
/**
* Get current selected column
*/
public int getUserSelectedCol()
{
return m_userSelectedCellID.Col;
}
/**
* Set current selected column
*/
public void setUserSelectedCol(int iSelectedCol)
{
if ((iSelectedCol < m_iFixedColCount) || (iSelectedCol >= m_iColCount))
{
m_userSelectedCellID.Col = -1;
m_userSelectedCellID.Row = -1;
}
else
{
m_userSelectedCellID.Col = iSelectedCol;
if (m_userSelectedCellID.Row == -1)
{
m_userSelectedCellID.Row = 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();
}
/**
* Remove rows from grid
*/
public void removeRows(int iRowStart, int iRowCount)
{
if ((iRowStart < 0) || (iRowStart > (m_iRowCount - 1)) || (iRowCount < 1))
{
return;
}
if ((m_iRowCount - iRowCount) < 1)
{
clearGrid();
return;
}
int iRowStep;
int iRowEnd;
int iHeight;
int i;
GridCellAttributes rowAttr;
boolean bUpdating = m_bUpdating;
m_bUpdating = false;
iRowEnd = (iRowStart + iRowCount) - 1;
if (iRowEnd >= (m_iRowCount - 1))
{
iRowEnd = m_iRowCount - 1;
iRowStep = (iRowEnd - iRowStart) + 1;
if (iRowStep < 0)
{
iRowStep = 0;
}
}
else
{
iRowStep = iRowCount;
}
for (i = iRowStart; i < m_iRowCount; i++)
{
iHeight = m_mapRowHeights.remove(i + iRowStep);
if (iHeight == IntHashtable.INVALID)
{
m_mapRowHeights.remove(i);
}
else
{
m_mapRowHeights.put(i, iHeight);
}
}
for (i = iRowStart; i <= m_iRowCount; i++)
{
rowAttr = m_mapRowAttributes.remove(i + iRowStep);
if (rowAttr == null)
{
m_mapRowAttributes.remove(i);
}
else
{
m_mapRowAttributes.put(i, rowAttr);
}
}
if (iRowEnd == m_iRowCount - 1)
{
setRowCount(iRowStart);
}
else
{
setRowCount(m_Storage.removeRows(iRowStart, iRowEnd));
}
if ((iRowStart <= m_userSelectedCellID.Row) && (m_userSelectedCellID.Row <= iRowEnd))
{
m_userSelectedCellID.Row = -1;
}
m_bUpdating = bUpdating;
_repaintGridIfNeeded();
}
/**
* Remove a row from grid
*/
public void removeRow(int iRow)
{
removeRows(iRow, 1);
}
/**
* Remove columns from grid
*/
public void removeCols(int iColStart, int iColCount)
{
if ((iColStart < 0) || (iColStart > (m_iColCount - 1)) || (iColCount < 1))
{
return;
}
if ((m_iColCount - iColCount) < 1)
{
clearGrid();
return;
}
int iColStep;
int iColEnd;
int iHeight;
int i;
GridCellAttributes colAttr;
Class cellType;
boolean bUpdating = m_bUpdating;
m_bUpdating = false;
iColEnd = (iColStart + iColCount) - 1;
if (iColEnd >= (m_iColCount - 1))
{
iColEnd = m_iColCount - 1;
iColStep = (iColEnd - iColStart) + 1;
if (iColStep < 0)
{
iColStep = 0;
}
}
else
{
iColStep = iColCount;
}
for (i = iColStart; i < m_iColCount; i++)
{
iHeight = m_mapColWidths.remove(i + iColStep);
if (iHeight == IntHashtable.INVALID)
{
m_mapColWidths.remove(i);
}
else
{
m_mapColWidths.put(i, iHeight);
}
}
for (i = iColStart; i <= m_iColCount; i++)
{
colAttr = m_mapColAttributes.remove(i + iColStep);
if (colAttr == null)
{
m_mapColAttributes.remove(i);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -