parent
e98e0c67c2
commit
eed466075e
@ -0,0 +1,162 @@
|
|||||||
|
package com.connor.jd.plm.form;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
import javax.swing.table.DefaultTableCellRenderer;
|
||||||
|
|
||||||
|
import com.connor.jd.plm.table.CTMap;
|
||||||
|
import com.connor.jd.plm.table.CTable;
|
||||||
|
import com.teamcenter.rac.kernel.TCComponent;
|
||||||
|
import com.teamcenter.rac.kernel.TCComponentForm;
|
||||||
|
import com.teamcenter.rac.kernel.TCException;
|
||||||
|
import com.teamcenter.rac.stylesheet.AbstractRendering;
|
||||||
|
|
||||||
|
public class NewProductTestForm extends AbstractRendering {
|
||||||
|
private TCComponentForm form;
|
||||||
|
private CTMap model1;
|
||||||
|
private CTMap model2;
|
||||||
|
private CTable table1;
|
||||||
|
private CTable table2;
|
||||||
|
private Map<String, String> prop;
|
||||||
|
private List<String> disableEdit;
|
||||||
|
private List<String> disableEdit2;
|
||||||
|
private Map<String, int[]> general;
|
||||||
|
private Map<String, int[]> general2;
|
||||||
|
|
||||||
|
public NewProductTestForm(TCComponent arg0) throws Exception {
|
||||||
|
super(arg0);
|
||||||
|
if (arg0 instanceof TCComponentForm) {
|
||||||
|
this.form = (TCComponentForm) arg0;
|
||||||
|
loadRendering();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadRendering() throws TCException {
|
||||||
|
this.setLayout(new BorderLayout());
|
||||||
|
JPanel root = new JPanel(new BorderLayout());
|
||||||
|
root.setPreferredSize(new Dimension(800, 500));
|
||||||
|
JPanel inner = new JPanel(new BorderLayout());
|
||||||
|
|
||||||
|
JLabel title = new JLabel("新品项目测试单");
|
||||||
|
inner.add(title, BorderLayout.NORTH);
|
||||||
|
|
||||||
|
prop = form.getProperties();
|
||||||
|
|
||||||
|
// 初始化表格
|
||||||
|
model1 = new CTMap(6, 4);
|
||||||
|
model1.setValueAt("项目信息:", 0, 0);
|
||||||
|
disableEdit.add("0,0");
|
||||||
|
model1.setValueAt("项目信息:", 0, 2);
|
||||||
|
disableEdit.add("0,2");
|
||||||
|
model1.setValueAt("项目信息:", 1, 0);
|
||||||
|
disableEdit.add("1,0");
|
||||||
|
model1.setValueAt("项目信息:", 1, 2);
|
||||||
|
disableEdit.add("1,2");
|
||||||
|
model1.setValueAt("项目信息:", 2, 0);
|
||||||
|
disableEdit.add("2,0");
|
||||||
|
model1.setValueAt("项目信息:", 2, 2);
|
||||||
|
disableEdit.add("2,2");
|
||||||
|
model1.setValueAt("项目信息:", 3, 0);
|
||||||
|
disableEdit.add("3,0");
|
||||||
|
model1.setValueAt("项目信息:", 3, 2);
|
||||||
|
disableEdit.add("3,2");
|
||||||
|
model1.setValueAt("项目信息:", 4, 0);
|
||||||
|
disableEdit.add("4,0");
|
||||||
|
model1.setValueAt("项目信息:", 4, 2);
|
||||||
|
disableEdit.add("4,2");
|
||||||
|
model1.setValueAt("项目信息:", 5, 0);
|
||||||
|
disableEdit.add("5,0");
|
||||||
|
model1.setValueAt("项目信息:", 5, 2);
|
||||||
|
disableEdit.add("5,2");
|
||||||
|
general.put("jd2_xmxx", new int[] { 0, 1 });
|
||||||
|
general.put("jd2_lxsj", new int[] { 0, 3 });
|
||||||
|
general.put("jd2_jbxh", new int[] { 1, 1 });
|
||||||
|
general.put("jd2_csxh", new int[] { 1, 3 });
|
||||||
|
general.put("jd2_cpxh", new int[] { 2, 1 });
|
||||||
|
general.put("jd2_xmzl", new int[] { 2, 3 });
|
||||||
|
general.put("jd2_cpjl", new int[] { 3, 1 });
|
||||||
|
general.put("jd2_cpbgd", new int[] { 3, 3 });
|
||||||
|
general.put("jd2_pzjl", new int[] { 4, 1 });
|
||||||
|
general.put("jd2_kfrc", new int[] { 4, 3 });
|
||||||
|
general.put("jd2_kfdj", new int[] { 5, 1 });
|
||||||
|
general.put("jd2_kfjd", new int[] { 5, 3 });
|
||||||
|
|
||||||
|
table1 = new CTable(model1) {
|
||||||
|
@Override
|
||||||
|
public boolean isCellEditable(int row, int col) {
|
||||||
|
if (isEditorDisable(disableEdit, row, col)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
table1.setRowHeight(25);
|
||||||
|
table1.setBorder(BorderFactory.createLineBorder(Color.black));
|
||||||
|
table1.getColumnModel().getColumn(0).setPreferredWidth(100);
|
||||||
|
table1.getColumnModel().getColumn(1).setPreferredWidth(100);
|
||||||
|
table1.getColumnModel().getColumn(2).setPreferredWidth(100);
|
||||||
|
table1.getColumnModel().getColumn(3).setPreferredWidth(200);
|
||||||
|
|
||||||
|
DefaultTableCellRenderer tcr1 = new DefaultTableCellRenderer() {
|
||||||
|
// 重写方法
|
||||||
|
@Override
|
||||||
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
|
||||||
|
boolean hasFocus, int row, int column) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
if (value instanceof JPanel) {
|
||||||
|
return (JPanel) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int maxPreferredHeight = 0;
|
||||||
|
for (int i = 0; i < table.getColumnCount(); i++) {
|
||||||
|
setText("" + table.getValueAt(row, i));
|
||||||
|
setSize(table.getColumnModel().getColumn(column).getWidth(), 0);
|
||||||
|
maxPreferredHeight = Math.max(maxPreferredHeight, getPreferredSize().height);
|
||||||
|
}
|
||||||
|
setBackground(Color.white);
|
||||||
|
// if(points1.contains(new Point(row,column)))
|
||||||
|
// setForeground(new Color(0,0,255));
|
||||||
|
// else
|
||||||
|
setForeground(Color.black);
|
||||||
|
if (isSelected) {
|
||||||
|
setBackground(new Color(0, 120, 215));
|
||||||
|
setForeground(Color.white);
|
||||||
|
}
|
||||||
|
if (table.getRowHeight(row) != maxPreferredHeight) // 少了这行则处理器瞎忙
|
||||||
|
table.setRowHeight(row, maxPreferredHeight);
|
||||||
|
|
||||||
|
setText(value == null ? "" : value.toString());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
tcr1.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
table1.setAutoResizeMode(CTable.AUTO_RESIZE_NEXT_COLUMN);
|
||||||
|
table1.setDefaultRenderer(Object.class, tcr1);
|
||||||
|
inner.add(table1, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
model2 = new CTMap(131, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveRendering() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isEditorDisable(List<String> list, int row, int col) {
|
||||||
|
return list.contains(row + "," + col);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue