|
|
@ -6,6 +6,7 @@ import com.fr.design.event.UIObserverListener; |
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
import com.fr.design.gui.itextfield.UITextField; |
|
|
|
import com.fr.design.gui.itextfield.UITextField; |
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory; |
|
|
|
import javax.swing.BorderFactory; |
|
|
|
import javax.swing.JComponent; |
|
|
|
import javax.swing.JComponent; |
|
|
@ -35,29 +36,29 @@ public class UITable extends JTable implements UIObserver { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int OFF_LEFT = 10; |
|
|
|
private static final int OFF_LEFT = 10; |
|
|
|
private static final int DEFAULT_ROW_HEIGHT =20; |
|
|
|
private static final int DEFAULT_ROW_HEIGHT = 20; |
|
|
|
private UIObserverListener uiObserverListener; |
|
|
|
private UIObserverListener uiObserverListener; |
|
|
|
UITableEditor editor ; |
|
|
|
UITableEditor editor; |
|
|
|
private boolean shouldResponseAwt; |
|
|
|
private boolean shouldResponseAwt; |
|
|
|
private boolean isEditingStopped; |
|
|
|
private boolean isEditingStopped; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 在没有任何数据的时候,使用此构造函数,然后通过populate更新数据 |
|
|
|
* 在没有任何数据的时候,使用此构造函数,然后通过populate更新数据 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param columnSize 列表的列数 |
|
|
|
* @param columnSize 列表的列数 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public UITable(int columnSize) { |
|
|
|
public UITable(int columnSize) { |
|
|
|
|
|
|
|
|
|
|
|
super(new UITableDataModel(columnSize)); |
|
|
|
super(new UITableDataModel(columnSize)); |
|
|
|
initComponents(); |
|
|
|
initComponents(); |
|
|
|
iniListener(); |
|
|
|
iniListener(); |
|
|
|
shouldResponseAwt = false; |
|
|
|
shouldResponseAwt = false; |
|
|
|
// kunsnat: 屏蔽: 对于下拉框, 无法等待选择结果之后在stop..
|
|
|
|
// kunsnat: 屏蔽: 对于下拉框, 无法等待选择结果之后在stop..
|
|
|
|
// Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK);
|
|
|
|
// Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public UITable (int columnSize, boolean needAWTEventListener) { |
|
|
|
public UITable(int columnSize, boolean needAWTEventListener) { |
|
|
|
this(columnSize); |
|
|
|
this(columnSize); |
|
|
|
shouldResponseAwt = needAWTEventListener; |
|
|
|
shouldResponseAwt = needAWTEventListener; |
|
|
|
isEditingStopped = true; |
|
|
|
isEditingStopped = true; |
|
|
@ -71,180 +72,182 @@ public class UITable extends JTable implements UIObserver { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* values不允许为空! |
|
|
|
* values不允许为空! |
|
|
|
* |
|
|
|
* |
|
|
|
* @param values 一个列表,里面装有字符串数组,每个数组代表一行内容 |
|
|
|
* @param values 一个列表,里面装有字符串数组,每个数组代表一行内容 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public UITable(List<Object[]> values) { |
|
|
|
public UITable(List<Object[]> values) { |
|
|
|
super(new UITableDataModel(values)); |
|
|
|
super(new UITableDataModel(values)); |
|
|
|
initComponents(); |
|
|
|
initComponents(); |
|
|
|
iniListener(); |
|
|
|
iniListener(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public UITable() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
public UITable() { |
|
|
|
|
|
|
|
|
|
|
|
public void populateBean(List<Object[]> values) { |
|
|
|
} |
|
|
|
getTableDataModel().populateBean(values); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void populateBean(List<Object[]> values) { |
|
|
|
|
|
|
|
getTableDataModel().populateBean(values); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private AWTEventListener awt = new AWTEventListener() { |
|
|
|
private AWTEventListener awt = new AWTEventListener() { |
|
|
|
public void eventDispatched(AWTEvent event) { |
|
|
|
public void eventDispatched(AWTEvent event) { |
|
|
|
if(!UITable.this.isShowing()){ |
|
|
|
if (!UITable.this.isShowing()) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
doSomeInAll(event); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void doSomeInAll(AWTEvent event) { |
|
|
|
|
|
|
|
Rectangle bounds = new Rectangle(getLocationOnScreen().x, getLocationOnScreen().y, getWidth(), getHeight()); |
|
|
|
|
|
|
|
if (event instanceof MouseEvent) { |
|
|
|
|
|
|
|
MouseEvent mv = (MouseEvent) event; |
|
|
|
|
|
|
|
if (mv.getClickCount() > 0) { |
|
|
|
|
|
|
|
Point point = new Point((int) (mv.getLocationOnScreen().getX()) - 2 * OFF_LEFT, (int) mv.getLocationOnScreen().getY()); |
|
|
|
|
|
|
|
// 判断鼠标点击是否在边界内
|
|
|
|
|
|
|
|
if (!bounds.contains(point) && shouldResponseAwt) { |
|
|
|
|
|
|
|
if (!isEditingStopped) { |
|
|
|
|
|
|
|
this.editor.stopCellEditing(); |
|
|
|
|
|
|
|
isEditingStopped = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
doSomeInAll(event); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void doSomeInAll(AWTEvent event) { |
|
|
|
public List<Object[]> updateBean() { |
|
|
|
Rectangle bounds = new Rectangle(getLocationOnScreen().x, getLocationOnScreen().y, getWidth(), getHeight()); |
|
|
|
return getTableDataModel().updateBean(); |
|
|
|
if (event instanceof MouseEvent) { |
|
|
|
} |
|
|
|
MouseEvent mv = (MouseEvent) event; |
|
|
|
|
|
|
|
if (mv.getClickCount() > 0) { |
|
|
|
/** |
|
|
|
Point point = new Point((int) (mv.getLocationOnScreen().getX()) - 2 * OFF_LEFT, (int) mv.getLocationOnScreen().getY()); |
|
|
|
* 在table底部增加一空行 |
|
|
|
// 判断鼠标点击是否在边界内
|
|
|
|
*/ |
|
|
|
if (!bounds.contains(point) && shouldResponseAwt) { |
|
|
|
public void addBlankLine() { |
|
|
|
if (!isEditingStopped) { |
|
|
|
getTableDataModel().addBlankLine(); |
|
|
|
this.editor.stopCellEditing(); |
|
|
|
} |
|
|
|
isEditingStopped = true; |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
} |
|
|
|
* 在table底部增加一行内容 |
|
|
|
} |
|
|
|
* |
|
|
|
} |
|
|
|
* @param line 该行的内容 |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
public void addLine(Object[] line) { |
|
|
|
public List<Object[]> updateBean() { |
|
|
|
getTableDataModel().addLine(line); |
|
|
|
return getTableDataModel().updateBean(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param rowIndex |
|
|
|
* 在table底部增加一空行 |
|
|
|
* @return 某一行的内容 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void addBlankLine() { |
|
|
|
public Object[] getLine(int rowIndex) { |
|
|
|
getTableDataModel().addBlankLine(); |
|
|
|
return getTableDataModel().getLine(rowIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 在table底部增加一行内容 |
|
|
|
* 删除某行内容 |
|
|
|
* @param line 该行的内容 |
|
|
|
* |
|
|
|
*/ |
|
|
|
* @param rowIndex 行号 |
|
|
|
public void addLine(Object[] line) { |
|
|
|
*/ |
|
|
|
getTableDataModel().addLine(line); |
|
|
|
public void removeLine(int rowIndex) { |
|
|
|
} |
|
|
|
getTableDataModel().removeLine(rowIndex); |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
|
|
|
|
* @param rowIndex |
|
|
|
/** |
|
|
|
* @return 某一行的内容 |
|
|
|
* 对某一行拖动时进行排序 |
|
|
|
*/ |
|
|
|
* |
|
|
|
public Object[] getLine(int rowIndex) { |
|
|
|
* @param rowIndex 行号 |
|
|
|
return getTableDataModel().getLine(rowIndex); |
|
|
|
* @param positive 鼠标移动的距离 |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
public void dragSort(int rowIndex, boolean positive) { |
|
|
|
/** |
|
|
|
((UITableDataModel) dataModel).dragSort(rowIndex, positive); |
|
|
|
* 删除某行内容 |
|
|
|
} |
|
|
|
* |
|
|
|
|
|
|
|
* @param rowIndex 行号 |
|
|
|
|
|
|
|
*/ |
|
|
|
/** |
|
|
|
public void removeLine(int rowIndex) { |
|
|
|
* 格子是否可编辑,可置顶某一列column不可编辑 |
|
|
|
getTableDataModel().removeLine(rowIndex); |
|
|
|
* |
|
|
|
} |
|
|
|
* @param row 行号 |
|
|
|
|
|
|
|
* @param column 列号 |
|
|
|
/** |
|
|
|
* @return 是否可编辑 |
|
|
|
* 对某一行拖动时进行排序 |
|
|
|
*/ |
|
|
|
* |
|
|
|
public boolean isCellEditable(int row, int column) { |
|
|
|
* @param rowIndex 行号 |
|
|
|
return true; |
|
|
|
* @param positive 鼠标移动的距离 |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
public void dragSort(int rowIndex, boolean positive) { |
|
|
|
/** |
|
|
|
((UITableDataModel) dataModel).dragSort(rowIndex, positive); |
|
|
|
* 清空数据 |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
public void clear() { |
|
|
|
|
|
|
|
getTableDataModel().clear(); |
|
|
|
/** |
|
|
|
} |
|
|
|
*格子是否可编辑,可置顶某一列column不可编辑 |
|
|
|
|
|
|
|
* @param row 行号 |
|
|
|
private UITableDataModel getTableDataModel() { |
|
|
|
* @param column 列号 |
|
|
|
return (UITableDataModel) dataModel; |
|
|
|
* @return 是否可编辑 |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
public boolean isCellEditable(int row, int column) { |
|
|
|
/** |
|
|
|
return true; |
|
|
|
* @param value 该行列的值(字符串) |
|
|
|
} |
|
|
|
* @param row |
|
|
|
|
|
|
|
* @param column |
|
|
|
/** |
|
|
|
* @return 列表中默认显示的东西,如果有很多内容,可以装载一个JPanel里再嵌进来 |
|
|
|
* 清空数据 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected JComponent getRenderCompoment(Object value, int row, int column) { |
|
|
|
public void clear() { |
|
|
|
UILabel text = new UILabel(); |
|
|
|
getTableDataModel().clear(); |
|
|
|
if (value != null) { |
|
|
|
} |
|
|
|
text.setText(value.toString()); |
|
|
|
|
|
|
|
} |
|
|
|
private UITableDataModel getTableDataModel() { |
|
|
|
return text; |
|
|
|
return (UITableDataModel) dataModel; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void initComponents() { |
|
|
|
/** |
|
|
|
setShowGrid(false); |
|
|
|
* @param value 该行列的值(字符串) |
|
|
|
setRowHeight(getRowHeight4Table()); |
|
|
|
* @param row |
|
|
|
setDragEnabled(false); |
|
|
|
* @param column |
|
|
|
editor = createTableEditor(); |
|
|
|
* @return 列表中默认显示的东西,如果有很多内容,可以装载一个JPanel里再嵌进来 |
|
|
|
editor.addCellEditorListener(new CellEditorListener() { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
protected JComponent getRenderCompoment(Object value, int row, int column) { |
|
|
|
public void editingStopped(ChangeEvent e) { |
|
|
|
UILabel text = new UILabel(); |
|
|
|
tableCellEditingStopped(e); |
|
|
|
if (value != null) { |
|
|
|
} |
|
|
|
text.setText(value.toString()); |
|
|
|
|
|
|
|
} |
|
|
|
@Override |
|
|
|
return text; |
|
|
|
public void editingCanceled(ChangeEvent e) { |
|
|
|
} |
|
|
|
tableCellEditingCanceled(e); |
|
|
|
|
|
|
|
} |
|
|
|
protected void initComponents() { |
|
|
|
|
|
|
|
setShowGrid(false); |
|
|
|
}); |
|
|
|
setRowHeight(getRowHeight4Table()); |
|
|
|
|
|
|
|
setDragEnabled(false); |
|
|
|
setBackground(UIConstants.NORMAL_BACKGROUND); |
|
|
|
editor = createTableEditor(); |
|
|
|
setDefaultEditor(UITable.class, editor); |
|
|
|
editor.addCellEditorListener(new CellEditorListener() { |
|
|
|
setDefaultRenderer(UITable.class, new UITableRender()); |
|
|
|
@Override |
|
|
|
|
|
|
|
public void editingStopped(ChangeEvent e) { |
|
|
|
|
|
|
|
tableCellEditingStopped(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void editingCanceled(ChangeEvent e) { |
|
|
|
|
|
|
|
tableCellEditingCanceled(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setBackground(UIConstants.NORMAL_BACKGROUND); |
|
|
|
|
|
|
|
setDefaultEditor(UITable.class, editor); |
|
|
|
|
|
|
|
setDefaultRenderer(UITable.class, new UITableRender()); |
|
|
|
|
|
|
|
// setUI(getUI());
|
|
|
|
// setUI(getUI());
|
|
|
|
|
|
|
|
|
|
|
|
TableColumn deleteTableColumn = new TableColumn(getTableDataModel().getColumnCount()); |
|
|
|
TableColumn deleteTableColumn = new TableColumn(getTableDataModel().getColumnCount()); |
|
|
|
deleteTableColumn.setCellEditor(null); |
|
|
|
deleteTableColumn.setCellEditor(null); |
|
|
|
deleteTableColumn.setCellRenderer(null); |
|
|
|
deleteTableColumn.setCellRenderer(null); |
|
|
|
deleteTableColumn.setMaxWidth(20); |
|
|
|
deleteTableColumn.setMaxWidth(20); |
|
|
|
getColumnModel().addColumn(deleteTableColumn); |
|
|
|
getColumnModel().addColumn(deleteTableColumn); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 鼠标悬浮再某一行时触发的事件 |
|
|
|
* 鼠标悬浮再某一行时触发的事件 |
|
|
|
* @param index 行号 |
|
|
|
* |
|
|
|
*/ |
|
|
|
* @param index 行号 |
|
|
|
public void dealWithRollOver(int index){ |
|
|
|
*/ |
|
|
|
|
|
|
|
public void dealWithRollOver(int index) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
private void iniListener(){ |
|
|
|
|
|
|
|
if(shouldResponseChangeListener()){ |
|
|
|
private void iniListener() { |
|
|
|
|
|
|
|
if (shouldResponseChangeListener()) { |
|
|
|
this.addChangeListener(new ChangeListener() { |
|
|
|
this.addChangeListener(new ChangeListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void stateChanged(ChangeEvent e) { |
|
|
|
public void stateChanged(ChangeEvent e) { |
|
|
|
if(uiObserverListener == null){ |
|
|
|
if (uiObserverListener == null) { |
|
|
|
return ; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
uiObserverListener.doChange(); |
|
|
|
uiObserverListener.doChange(); |
|
|
|
} |
|
|
|
} |
|
|
@ -252,138 +255,142 @@ public class UITable extends JTable implements UIObserver { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected int getRowHeight4Table() { |
|
|
|
protected int getRowHeight4Table() { |
|
|
|
return DEFAULT_ROW_HEIGHT; |
|
|
|
return DEFAULT_ROW_HEIGHT; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
*停止编辑事件 |
|
|
|
* 停止编辑事件 |
|
|
|
* @param e 事件 |
|
|
|
* |
|
|
|
*/ |
|
|
|
* @param e 事件 |
|
|
|
public void tableCellEditingStopped(ChangeEvent e) { |
|
|
|
*/ |
|
|
|
|
|
|
|
public void tableCellEditingStopped(ChangeEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
*取消编辑事件 |
|
|
|
* 取消编辑事件 |
|
|
|
|
|
|
|
* |
|
|
|
* @param e 事件 |
|
|
|
* @param e 事件 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void tableCellEditingCanceled(ChangeEvent e) { |
|
|
|
public void tableCellEditingCanceled(ChangeEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 编辑器 |
|
|
|
|
|
|
|
* @return 编辑器 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public UITableEditor createTableEditor() { |
|
|
|
|
|
|
|
return new UIDefaultTableCellEditor(new UITextField()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* 编辑器 |
|
|
|
* |
|
|
|
* |
|
|
|
|
|
|
|
* @return 编辑器 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public TableUI getUI() { |
|
|
|
public UITableEditor createTableEditor() { |
|
|
|
return new UITableUI(); |
|
|
|
return new UIDefaultTableCellEditor(new UITextField()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
@Override |
|
|
|
/** |
|
|
|
/** |
|
|
|
* |
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
// public TableCellEditor getDefaultEditor(Class<?> columnClass) {
|
|
|
|
public TableUI getUI() { |
|
|
|
// return super.getDefaultEditor(UITable.class);
|
|
|
|
return new UITableUI(); |
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public TableCellRenderer getDefaultRenderer(Class<?> columnClass) { |
|
|
|
|
|
|
|
// 处理null的情况用于创建时未指定数据结构的情况
|
|
|
|
|
|
|
|
if (columnClass == null) { |
|
|
|
|
|
|
|
return createDefaultRenderer(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return super.getDefaultRenderer(columnClass); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private @NotNull TableCellRenderer createDefaultRenderer() { |
|
|
|
|
|
|
|
Object renderer = defaultRenderersByColumnClass.get(UITable.class); |
|
|
|
|
|
|
|
return renderer != null ? (TableCellRenderer) renderer : new UITableRender(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* 给组件登记一个观察者监听事件 |
|
|
|
* |
|
|
|
* |
|
|
|
|
|
|
|
* @param listener 观察者监听事件 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
// public TableCellRenderer getDefaultRenderer(Class<?> columnClass) {
|
|
|
|
|
|
|
|
// return super.getDefaultRenderer(UITable.class);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 给组件登记一个观察者监听事件 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param listener 观察者监听事件 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void registerChangeListener(UIObserverListener listener) { |
|
|
|
public void registerChangeListener(UIObserverListener listener) { |
|
|
|
uiObserverListener = listener; |
|
|
|
uiObserverListener = listener; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 组件是否需要响应添加的观察者事件 |
|
|
|
* 组件是否需要响应添加的观察者事件 |
|
|
|
* |
|
|
|
* |
|
|
|
* @return 如果需要响应观察者事件则返回true,否则返回false |
|
|
|
* @return 如果需要响应观察者事件则返回true,否则返回false |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean shouldResponseChangeListener() { |
|
|
|
public boolean shouldResponseChangeListener() { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected class UITableRender implements TableCellRenderer { |
|
|
|
protected class UITableRender implements TableCellRenderer { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Component getTableCellRendererComponent(JTable table, |
|
|
|
public Component getTableCellRendererComponent(JTable table, |
|
|
|
Object value, boolean isSelected, boolean hasFocus, int row, |
|
|
|
Object value, boolean isSelected, boolean hasFocus, int row, |
|
|
|
int column) { |
|
|
|
int column) { |
|
|
|
JComponent comp = getRenderCompoment(value, row, column); |
|
|
|
JComponent comp = getRenderCompoment(value, row, column); |
|
|
|
comp.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); |
|
|
|
comp.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); |
|
|
|
return comp; |
|
|
|
return comp; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void fireTargetChanged() { |
|
|
|
protected void fireTargetChanged() { |
|
|
|
repaint(); |
|
|
|
repaint(); |
|
|
|
Object[] listeners = listenerList.getListenerList(); |
|
|
|
Object[] listeners = listenerList.getListenerList(); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = listeners.length - 2; i >= 0; i -= 2) { |
|
|
|
for (int i = listeners.length - 2; i >= 0; i -= 2) { |
|
|
|
if (listeners[i] == ChangeListener.class) { |
|
|
|
if (listeners[i] == ChangeListener.class) { |
|
|
|
((ChangeListener) listeners[i + 1]).stateChanged(new ChangeEvent(this)); |
|
|
|
((ChangeListener) listeners[i + 1]).stateChanged(new ChangeEvent(this)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 增加监听 |
|
|
|
* 增加监听 |
|
|
|
* @param l 监听 |
|
|
|
* |
|
|
|
*/ |
|
|
|
* @param l 监听 |
|
|
|
public void addChangeListener(ChangeListener l) { |
|
|
|
*/ |
|
|
|
this.listenerList.add(ChangeListener.class, l); |
|
|
|
public void addChangeListener(ChangeListener l) { |
|
|
|
} |
|
|
|
this.listenerList.add(ChangeListener.class, l); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
*移除监听 |
|
|
|
* 移除监听 |
|
|
|
|
|
|
|
* |
|
|
|
* @param l 监听 |
|
|
|
* @param l 监听 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void removeChangeListener(ChangeListener l) { |
|
|
|
public void removeChangeListener(ChangeListener l) { |
|
|
|
this.listenerList.remove(ChangeListener.class, l); |
|
|
|
this.listenerList.remove(ChangeListener.class, l); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
*测试主函数 |
|
|
|
* 测试主函数 |
|
|
|
|
|
|
|
* |
|
|
|
* @param args 参数 |
|
|
|
* @param args 参数 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void main(String... args) { |
|
|
|
public static void main(String... args) { |
|
|
|
JFrame jf = new JFrame("test"); |
|
|
|
JFrame jf = new JFrame("test"); |
|
|
|
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
JPanel content = (JPanel) jf.getContentPane(); |
|
|
|
JPanel content = (JPanel) jf.getContentPane(); |
|
|
|
content.setLayout(new BorderLayout()); |
|
|
|
content.setLayout(new BorderLayout()); |
|
|
|
List<Object[]> data = new ArrayList<Object[]>(); |
|
|
|
List<Object[]> data = new ArrayList<Object[]>(); |
|
|
|
String[] a = {"1", "11"}; |
|
|
|
String[] a = {"1", "11"}; |
|
|
|
String[] b = {"2", "22"}; |
|
|
|
String[] b = {"2", "22"}; |
|
|
|
String[] c = {"3", "33"}; |
|
|
|
String[] c = {"3", "33"}; |
|
|
|
String[] d = {"4", "44"}; |
|
|
|
String[] d = {"4", "44"}; |
|
|
|
data.add(a); |
|
|
|
data.add(a); |
|
|
|
data.add(b); |
|
|
|
data.add(b); |
|
|
|
data.add(c); |
|
|
|
data.add(c); |
|
|
|
data.add(d); |
|
|
|
data.add(d); |
|
|
|
UITable pane = new UITable(2); |
|
|
|
UITable pane = new UITable(2); |
|
|
|
pane.populateBean(data); |
|
|
|
pane.populateBean(data); |
|
|
|
content.add(pane, BorderLayout.CENTER); |
|
|
|
content.add(pane, BorderLayout.CENTER); |
|
|
|
GUICoreUtils.centerWindow(jf); |
|
|
|
GUICoreUtils.centerWindow(jf); |
|
|
|
jf.setSize(400, 400); |
|
|
|
jf.setSize(400, 400); |
|
|
|
jf.setVisible(true); |
|
|
|
jf.setVisible(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |