📄 defaultgridmodel.java
字号:
package org.nebula.cwt.grid;
import org.nebula.cwt.grid.GridModel;
/**
* DefaultGridModel
*
* Description:
*
* @author xuan
*
*/
public class DefaultGridModel implements GridModel {
protected Object blocks[][];
protected int cols, rows;
/**
* Listeners.
*/
protected GridModelListener listener = null;
public DefaultGridModel(int c, int r) {
cols = c;
rows = r;
blocks = new Object[cols][rows];
for (int i = 0; i < cols; i++)
for (int j = 0; j < rows; j++) {
blocks[i][j] = null;
}
}
/**
* AbstractGridModel subclasses must call this method <b>after</b> one or
* more chessmen removed.
*
* @see EventListenerList
*/
public void fireDataChanged() {
// Logger.debug("DefaultGridModel::fireDataChanged");
if (listener != null) {
// Logger.debug("calling fireDataChanged");
listener.gridDataChanged();
}
}
/**
* Add a listener to the Grid that's notified each time a change to the data
* model occurs.
*
* @param l
* the GridDataListener
*/
public void setGridModelListener(GridModelListener l) {
listener = l;
}
public int getColumns() {
return cols;
}
public int getRows() {
return rows;
}
public Object getObject(int x, int y) {
return blocks[x][y];
}
public void setObject(int x, int y, Object obj) {
blocks[x][y] = obj;
fireDataChanged();
}
public boolean isEmpty(int x, int y) {
if (blocks[x][y] == null)
return true;
else
return false;
}
public void reset(int c, int r) {
cols = c;
rows = r;
blocks = new Object[cols][rows];
for (int i = 0; i < cols; i++)
for (int j = 0; j < rows; j++) {
blocks[i][j] = null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -