|
|
|
@ -2,6 +2,7 @@ package com.fr.design.data.tabledata.tabledatapane;
|
|
|
|
|
|
|
|
|
|
import com.fine.theme.light.ui.FineTableHeaderUI; |
|
|
|
|
import com.fine.theme.utils.FineUIScale; |
|
|
|
|
import com.formdev.flatlaf.ui.FlatUIUtils; |
|
|
|
|
import com.fr.data.impl.EmbeddedTableData; |
|
|
|
|
import com.fr.design.constants.LayoutConstants; |
|
|
|
|
import com.fr.design.dialog.BasicDialog; |
|
|
|
@ -18,18 +19,19 @@ import com.fr.stable.StringUtils;
|
|
|
|
|
import javax.swing.DefaultCellEditor; |
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import javax.swing.JTable; |
|
|
|
|
import javax.swing.UIManager; |
|
|
|
|
import javax.swing.event.TableModelEvent; |
|
|
|
|
import javax.swing.event.TableModelListener; |
|
|
|
|
import javax.swing.table.AbstractTableModel; |
|
|
|
|
import javax.swing.table.DefaultTableCellRenderer; |
|
|
|
|
import javax.swing.table.TableCellEditor; |
|
|
|
|
import javax.swing.table.TableColumn; |
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
import java.awt.Color; |
|
|
|
|
import java.awt.Component; |
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
import java.awt.event.ComponentEvent; |
|
|
|
|
import java.awt.event.ComponentListener; |
|
|
|
|
import java.awt.event.KeyAdapter; |
|
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
|
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
|
|
|
|
|
EmbeddedTableModel tableModel = new EmbeddedTableModel(new EmbeddedTableData()); |
|
|
|
|
dataJTable = new JTable(tableModel); |
|
|
|
|
dataJTable.setBackground(FlatUIUtils.getUIColor("default.background", new Color(246, 248, 250))); |
|
|
|
|
scrollPane = new UITableScrollPane(dataJTable);; |
|
|
|
|
|
|
|
|
|
// 显示double,date类;渲染date类
|
|
|
|
@ -87,7 +90,6 @@ public class EmbeddedTableDataPane extends AbstractTableDataPane<EmbeddedTableDa
|
|
|
|
|
editbysingleclick(dataJTable, Integer.class); |
|
|
|
|
|
|
|
|
|
// 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.setColumnSelectionAllowed(true); |
|
|
|
|
|
|
|
|
@ -102,6 +104,7 @@ public class EmbeddedTableDataPane extends AbstractTableDataPane<EmbeddedTableDa
|
|
|
|
|
selectedChanged(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
addDataTableListener(); |
|
|
|
|
|
|
|
|
|
// 添加表模型监听器以监听行列变化更新按钮状态
|
|
|
|
|
tableModel.addTableModelListener(new TableModelListener() { |
|
|
|
@ -113,37 +116,52 @@ public class EmbeddedTableDataPane extends AbstractTableDataPane<EmbeddedTableDa
|
|
|
|
|
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() { |
|
|
|
|
// kel:在左上角加一个JLabel用来显示坐标,方便用户查看。
|
|
|
|
|
coordinatelabel = new UILabel("0/0,0/0"); |
|
|
|
|
coordinatelabel.setHorizontalAlignment(UILabel.CENTER); |
|
|
|
|
// 表结构设置
|
|
|
|
|
UIButton columnSetButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tabledata_Embedded_Table_Design")); |
|
|
|
|
columnSetButton.setMnemonic('C'); |
|
|
|
|
|
|
|
|
|
columnSetButton.addActionListener(new ActionListener() { |
|
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
|
|
|
|
|
|
|
|
final EmbeddedTableModel localDefaultModel = (EmbeddedTableModel) dataJTable.getModel(); |
|
|
|
|
final EmbeddedTableDataDefinedPane columnSetPane = new EmbeddedTableDataDefinedPane(); |
|
|
|
|
columnSetPane.populate(((EmbeddedTableModel) dataJTable.getModel()).getEditableTableData()); |
|
|
|
|
|
|
|
|
|
DialogActionAdapter l = new DialogActionAdapter() { |
|
|
|
|
public void doOk() { |
|
|
|
|
localDefaultModel.setEditableTableData(columnSetPane.update()); |
|
|
|
|
localDefaultModel.fireTableStructureChanged(); |
|
|
|
|
localDefaultModel.fireTableDataChanged(); |
|
|
|
|
tableStructureChanged(); |
|
|
|
|
selectedChanged(); |
|
|
|
|
dataJTable.setAutoResizeMode(localDefaultModel.getColumnCount() * PREVIEW_TABLE_MIN_COLUMN_WIDTH <= PREVIEW_TABLE_WIDTH ? JTable.AUTO_RESIZE_ALL_COLUMNS : JTable.AUTO_RESIZE_OFF); |
|
|
|
|
dataJTable.repaint(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
BasicDialog dlg = columnSetPane.showWindow(DesignerContext.getDesignerFrame(), l); |
|
|
|
|
dlg.setAlwaysOnTop(true); |
|
|
|
|
dlg.setVisible(true); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
UIButton columnSetButton = initColumnSetButton(); |
|
|
|
|
|
|
|
|
|
// DataSourceEditor-Insert_Row
|
|
|
|
|
insertRowButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Utils_Insert_Row")); |
|
|
|
@ -174,6 +192,35 @@ public class EmbeddedTableDataPane extends AbstractTableDataPane<EmbeddedTableDa
|
|
|
|
|
).getComponent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private UIButton initColumnSetButton() { |
|
|
|
|
UIButton columnSetButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tabledata_Embedded_Table_Design")); |
|
|
|
|
columnSetButton.setMnemonic('C'); |
|
|
|
|
columnSetButton.addActionListener(new ActionListener() { |
|
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
|
|
|
|
|
|
|
|
final EmbeddedTableModel localDefaultModel = (EmbeddedTableModel) dataJTable.getModel(); |
|
|
|
|
final EmbeddedTableDataDefinedPane columnSetPane = new EmbeddedTableDataDefinedPane(); |
|
|
|
|
columnSetPane.populate(((EmbeddedTableModel) dataJTable.getModel()).getEditableTableData()); |
|
|
|
|
|
|
|
|
|
DialogActionAdapter l = new DialogActionAdapter() { |
|
|
|
|
public void doOk() { |
|
|
|
|
localDefaultModel.setEditableTableData(columnSetPane.update()); |
|
|
|
|
localDefaultModel.fireTableStructureChanged(); |
|
|
|
|
localDefaultModel.fireTableDataChanged(); |
|
|
|
|
tableStructureChanged(); |
|
|
|
|
selectedChanged(); |
|
|
|
|
adjustTableAutoResizeMode(); |
|
|
|
|
dataJTable.repaint(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
BasicDialog dlg = columnSetPane.showWindow(DesignerContext.getDesignerFrame(), l); |
|
|
|
|
dlg.setAlwaysOnTop(true); |
|
|
|
|
dlg.setVisible(true); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return columnSetButton; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 更新按钮状态 |
|
|
|
|
*/ |
|
|
|
@ -253,11 +300,11 @@ public class EmbeddedTableDataPane extends AbstractTableDataPane<EmbeddedTableDa
|
|
|
|
|
tableColumn.setCellRenderer(new CellRenderer()); |
|
|
|
|
tableColumn.setMaxWidth(FineUIScale.scale(Math.max(dataJTable.getColumnCount(), MIN_CELL_WIDTH))); |
|
|
|
|
|
|
|
|
|
// 没有列数据的时候,压缩行号
|
|
|
|
|
// 没有列数据的时候, 隐藏行号列
|
|
|
|
|
if (dataJTable.getColumnModel().getColumnCount() > 1) { |
|
|
|
|
dataJTable.getTableHeader().setPreferredSize(new Dimension(super.getWidth(), FineUIScale.scale((Integer) UIManager.get("Table.rowHeight")))); |
|
|
|
|
dataJTable.getTableHeader().setVisible(true); |
|
|
|
|
} else { |
|
|
|
|
dataJTable.getTableHeader().setPreferredSize(new Dimension(super.getWidth(), FineUIScale.scale(4))); |
|
|
|
|
dataJTable.getTableHeader().setVisible(false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|