帆软报表设计器源代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

192 lines
5.6 KiB

package com.fr.design.gui.itableeditorpane;
import com.fine.swing.ui.layout.Layouts;
import com.fine.theme.light.ui.FineRoundBorder;
import com.fine.theme.utils.FineUIScale;
import com.fr.design.constants.LayoutConstants;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icontainer.UITableScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itable.FineUITable;
import com.fr.design.layout.FRGUIPaneFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.event.TableModelListener;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Insets;
import java.util.List;
/**
* 表格编辑面板,一般是两列.键-值 用泛型实现,用的时候请定义T.model里面的T要一样
*
* @editor zhou
* @since 2012-3-28下午3:06:30
*/
public class UITableEditorPane<T> extends BasicPane {
/**
*
*/
private static final long serialVersionUID = 6855793816972735815L;
protected FineUITable editTable;
// 放置action 的按钮.
protected UITableModelAdapter<T> tableModel;
private String leftLabelName;
private JPanel buttonPane;
protected JScrollPane scrollPane;
protected JPanel verticalScrollBar;
public UITableEditorPane(UITableModelAdapter<T> model) {
this.tableModel = model;
this.initComponent(model.createAction());
}
public UITableEditorPane(UITableModelAdapter<T> model, JPanel panel) {
this.tableModel = model;
this.initComponent(model.createAction(), panel);
}
public UITableEditorPane(UITableModelAdapter<T> model, String s) {
leftLabelName = s;
this.tableModel = model;
this.initComponent(model.createAction());
}
protected void initComponent(UITableEditAction[] action) {
this.initComponent(action, null);
}
protected void initComponent(UITableEditAction[] action, JPanel content) {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel pane = new JPanel(new BorderLayout(4, 4));
this.add(pane, BorderLayout.CENTER);
UILabel l = new UILabel(leftLabelName);
editTable = tableModel.createTable();
UITableScrollPane scrollPane = new UITableScrollPane(editTable);
scrollPane.setBorder(new FineRoundBorder());
initbuttonPane(action);
JPanel controlPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
controlPane.add(buttonPane, BorderLayout.EAST);
controlPane.add(content == null ? l : content, BorderLayout.WEST);
pane.add(Layouts.column(LayoutConstants.HGAP_LARGE, Layouts.cell(controlPane), Layouts.cell(scrollPane).weight(1)).getComponent());
this.editTable.setRowHeight(FineUIScale.scale(24));
}
public UITableModelAdapter<T> getTableModel() {
return tableModel;
}
protected void initbuttonPane(UITableEditAction[] action) {
buttonPane = new JPanel();
if (action != null) {
buttonPane.setLayout(new GridLayout(1, action.length, FineUIScale.scale(2), 0));
for (int i = 0; i < action.length; i++) {
final UIButton newButton = new UIButton(action[i]);
newButton.set4ToolbarButton();
newButton.setMargin(new Insets(0, 0, 0, 0));
newButton.setText("");
newButton.setName(action[i].getName());
newButton.setToolTipText(action[i].getName());
newButton.setMargin(null);
newButton.setOpaque(false);
newButton.setPreferredSize(FineUIScale.scale(new Dimension(24, 24)));
buttonPane.add(newButton);
}
}
}
/**
* 增加事件监听
*
* @param l 加的东东
*/
public void addTableListener(TableModelListener l) {
tableModel.addTableModelListener(l);
}
/**
* 移除事件监听
*
* @param l 去的东东
*/
public void removeTableListener(TableModelListener l) {
tableModel.removeTableModelListener(l);
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_TableData_Dynamic_Parameter_Setting");
}
public void populate(T[] objs) {
tableModel.clear();
if (objs == null) {
return;
}
for (T obj : objs) {
tableModel.addRow(obj);
}
this.tableModel.fireTableDataChanged();
if (objs.length > 0) {
this.editTable.getSelectionModel().setSelectionInterval(0, 0);
}
}
// TODO:august这个最好还是返回数组
public List<T> update() {
tableModel.stopCellEditing();
return tableModel.getList();
}
public void update(List list) {
tableModel.stopCellEditing();
tableModel.setList(list);
}
public int getSelectedRow() {
return this.editTable.getSelectedRow();
}
public int getSelectedColumn() {
return this.editTable.getSelectedColumn();
}
public JPanel getbuttonPane() {
return buttonPane;
}
/**
* @return jTable
*/
public FineUITable getEditTable() {
return editTable;
}
public void setEditTable(FineUITable editTable) {
this.editTable = editTable;
}
/**
* 停止编辑
*/
public void stopEditing() {
tableModel.stopCellEditing();
}
/**
* 设置表头是否可以改变大小
*/
public void setHeaderResizing(boolean resizingAllowed) {
editTable.getTableHeader().setResizingAllowed(resizingAllowed);
}
}