|
|
@ -2,6 +2,7 @@ package com.fr.design.data.tabledata.tabledatapane; |
|
|
|
|
|
|
|
|
|
|
|
import com.fine.theme.light.ui.FineTableHeaderUI; |
|
|
|
import com.fine.theme.light.ui.FineTableHeaderUI; |
|
|
|
import com.fine.theme.utils.FineUIScale; |
|
|
|
import com.fine.theme.utils.FineUIScale; |
|
|
|
|
|
|
|
import com.formdev.flatlaf.ui.FlatUIUtils; |
|
|
|
import com.fr.data.impl.EmbeddedTableData; |
|
|
|
import com.fr.data.impl.EmbeddedTableData; |
|
|
|
import com.fr.design.constants.LayoutConstants; |
|
|
|
import com.fr.design.constants.LayoutConstants; |
|
|
|
import com.fr.design.dialog.BasicDialog; |
|
|
|
import com.fr.design.dialog.BasicDialog; |
|
|
@ -18,18 +19,19 @@ import com.fr.stable.StringUtils; |
|
|
|
import javax.swing.DefaultCellEditor; |
|
|
|
import javax.swing.DefaultCellEditor; |
|
|
|
import javax.swing.JPanel; |
|
|
|
import javax.swing.JPanel; |
|
|
|
import javax.swing.JTable; |
|
|
|
import javax.swing.JTable; |
|
|
|
import javax.swing.UIManager; |
|
|
|
|
|
|
|
import javax.swing.event.TableModelEvent; |
|
|
|
import javax.swing.event.TableModelEvent; |
|
|
|
import javax.swing.event.TableModelListener; |
|
|
|
import javax.swing.event.TableModelListener; |
|
|
|
|
|
|
|
import javax.swing.table.AbstractTableModel; |
|
|
|
import javax.swing.table.DefaultTableCellRenderer; |
|
|
|
import javax.swing.table.DefaultTableCellRenderer; |
|
|
|
import javax.swing.table.TableCellEditor; |
|
|
|
import javax.swing.table.TableCellEditor; |
|
|
|
import javax.swing.table.TableColumn; |
|
|
|
import javax.swing.table.TableColumn; |
|
|
|
import java.awt.BorderLayout; |
|
|
|
import java.awt.BorderLayout; |
|
|
|
import java.awt.Color; |
|
|
|
import java.awt.Color; |
|
|
|
import java.awt.Component; |
|
|
|
import java.awt.Component; |
|
|
|
import java.awt.Dimension; |
|
|
|
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import java.awt.event.ActionListener; |
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
|
|
import java.awt.event.ComponentEvent; |
|
|
|
|
|
|
|
import java.awt.event.ComponentListener; |
|
|
|
import java.awt.event.KeyAdapter; |
|
|
|
import java.awt.event.KeyAdapter; |
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
import java.awt.event.MouseAdapter; |
|
|
@ -67,6 +69,7 @@ public class EmbeddedTableDataPane extends AbstractTableDataPane<EmbeddedTableDa |
|
|
|
// prepare the data in this way as default if no arguments is passed in
|
|
|
|
// prepare the data in this way as default if no arguments is passed in
|
|
|
|
EmbeddedTableModel tableModel = new EmbeddedTableModel(new EmbeddedTableData()); |
|
|
|
EmbeddedTableModel tableModel = new EmbeddedTableModel(new EmbeddedTableData()); |
|
|
|
dataJTable = new JTable(tableModel); |
|
|
|
dataJTable = new JTable(tableModel); |
|
|
|
|
|
|
|
dataJTable.setBackground(FlatUIUtils.getUIColor("default.background", new Color(246, 248, 250))); |
|
|
|
scrollPane = new UITableScrollPane(dataJTable);; |
|
|
|
scrollPane = new UITableScrollPane(dataJTable);; |
|
|
|
|
|
|
|
|
|
|
|
// 显示double,date类;渲染date类
|
|
|
|
// 显示double,date类;渲染date类
|
|
|
@ -87,7 +90,6 @@ public class EmbeddedTableDataPane extends AbstractTableDataPane<EmbeddedTableDa |
|
|
|
editbysingleclick(dataJTable, Integer.class); |
|
|
|
editbysingleclick(dataJTable, Integer.class); |
|
|
|
|
|
|
|
|
|
|
|
// AUTO RESIZE
|
|
|
|
// AUTO RESIZE
|
|
|
|
dataJTable.setAutoResizeMode(tableModel.getColumnCount() * PREVIEW_TABLE_MIN_COLUMN_WIDTH <= PREVIEW_TABLE_WIDTH ? JTable.AUTO_RESIZE_ALL_COLUMNS : JTable.AUTO_RESIZE_OFF); |
|
|
|
|
|
|
|
dataJTable.setRowSelectionAllowed(true); |
|
|
|
dataJTable.setRowSelectionAllowed(true); |
|
|
|
dataJTable.setColumnSelectionAllowed(true); |
|
|
|
dataJTable.setColumnSelectionAllowed(true); |
|
|
|
|
|
|
|
|
|
|
@ -102,6 +104,7 @@ public class EmbeddedTableDataPane extends AbstractTableDataPane<EmbeddedTableDa |
|
|
|
selectedChanged(); |
|
|
|
selectedChanged(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
addDataTableListener(); |
|
|
|
|
|
|
|
|
|
|
|
// 添加表模型监听器以监听行列变化更新按钮状态
|
|
|
|
// 添加表模型监听器以监听行列变化更新按钮状态
|
|
|
|
tableModel.addTableModelListener(new TableModelListener() { |
|
|
|
tableModel.addTableModelListener(new TableModelListener() { |
|
|
@ -113,6 +116,46 @@ public class EmbeddedTableDataPane extends AbstractTableDataPane<EmbeddedTableDa |
|
|
|
this.add(column(LayoutConstants.VERTICAL_GAP, cell(getNorthPaneComponents()), cell(scrollPane).weight(1)).getComponent()); |
|
|
|
this.add(column(LayoutConstants.VERTICAL_GAP, cell(getNorthPaneComponents()), cell(scrollPane).weight(1)).getComponent()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addDataTableListener() { |
|
|
|
|
|
|
|
dataJTable.addMouseListener(new MouseAdapter() { |
|
|
|
|
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
|
|
|
|
// kel:加上一个鼠标点击的监控,鼠标点击时,返回选中的行坐标和列坐标。
|
|
|
|
|
|
|
|
selectedChanged(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
dataJTable.addKeyListener(new KeyAdapter() { |
|
|
|
|
|
|
|
public void keyTyped(KeyEvent e) { |
|
|
|
|
|
|
|
selectedChanged(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
dataJTable.addComponentListener(new ComponentListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentResized(ComponentEvent e) { |
|
|
|
|
|
|
|
adjustTableAutoResizeMode(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentMoved(ComponentEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentShown(ComponentEvent e) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentHidden(ComponentEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void adjustTableAutoResizeMode() { |
|
|
|
|
|
|
|
int previewTableWidth = scrollPane.getSize().width - FineUIScale.scale(MIN_CELL_WIDTH); |
|
|
|
|
|
|
|
AbstractTableModel tableModel = (AbstractTableModel) dataJTable.getModel(); |
|
|
|
|
|
|
|
dataJTable.setAutoResizeMode((tableModel.getColumnCount() - 1) * PREVIEW_TABLE_MIN_COLUMN_WIDTH <= previewTableWidth ? JTable.AUTO_RESIZE_ALL_COLUMNS : JTable.AUTO_RESIZE_OFF); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private JPanel getNorthPaneComponents() { |
|
|
|
private JPanel getNorthPaneComponents() { |
|
|
|
// kel:在左上角加一个JLabel用来显示坐标,方便用户查看。
|
|
|
|
// kel:在左上角加一个JLabel用来显示坐标,方便用户查看。
|
|
|
|
coordinatelabel = new UILabel("0/0,0/0"); |
|
|
|
coordinatelabel = new UILabel("0/0,0/0"); |
|
|
@ -135,7 +178,7 @@ public class EmbeddedTableDataPane extends AbstractTableDataPane<EmbeddedTableDa |
|
|
|
localDefaultModel.fireTableDataChanged(); |
|
|
|
localDefaultModel.fireTableDataChanged(); |
|
|
|
tableStructureChanged(); |
|
|
|
tableStructureChanged(); |
|
|
|
selectedChanged(); |
|
|
|
selectedChanged(); |
|
|
|
dataJTable.setAutoResizeMode(localDefaultModel.getColumnCount() * PREVIEW_TABLE_MIN_COLUMN_WIDTH <= PREVIEW_TABLE_WIDTH ? JTable.AUTO_RESIZE_ALL_COLUMNS : JTable.AUTO_RESIZE_OFF); |
|
|
|
adjustTableAutoResizeMode(); |
|
|
|
dataJTable.repaint(); |
|
|
|
dataJTable.repaint(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
@ -253,11 +296,11 @@ public class EmbeddedTableDataPane extends AbstractTableDataPane<EmbeddedTableDa |
|
|
|
tableColumn.setCellRenderer(new CellRenderer()); |
|
|
|
tableColumn.setCellRenderer(new CellRenderer()); |
|
|
|
tableColumn.setMaxWidth(FineUIScale.scale(Math.max(dataJTable.getColumnCount(), MIN_CELL_WIDTH))); |
|
|
|
tableColumn.setMaxWidth(FineUIScale.scale(Math.max(dataJTable.getColumnCount(), MIN_CELL_WIDTH))); |
|
|
|
|
|
|
|
|
|
|
|
// 没有列数据的时候,压缩行号
|
|
|
|
// 没有列数据的时候, 隐藏行号列
|
|
|
|
if (dataJTable.getColumnModel().getColumnCount() > 1) { |
|
|
|
if (dataJTable.getColumnModel().getColumnCount() > 1) { |
|
|
|
dataJTable.getTableHeader().setPreferredSize(new Dimension(super.getWidth(), FineUIScale.scale((Integer) UIManager.get("Table.rowHeight")))); |
|
|
|
dataJTable.getTableHeader().setVisible(true); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
dataJTable.getTableHeader().setPreferredSize(new Dimension(super.getWidth(), FineUIScale.scale(4))); |
|
|
|
dataJTable.getTableHeader().setVisible(false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|