📄 attemppanel.java
字号:
/**
* <p>Title: 卓博营运支撑系统</p>
*
* <p>Description: 为本企业内部运作提供支撑,为企业資源的E化管理提供解決方案</p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: 卓博信息科技有限公司</p>
*
* @author Henry
* @version 1.0
*/
package com.jobcn.ui;
import java.util.ArrayList;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import com.jobcn.control.AttempTableModel;
import com.jobcn.control.Constant;
public class AttempPanel extends JPanel {
/**
* Create the panel
*/
public AttempPanel(final TaskDialog taskDialog) {
super(new BorderLayout());
this.taskDialog = taskDialog;
JPanel panel = new JPanel();
final JButton newAttemp = new JButton();
newAttemp.setBounds(20, 20, 60, 25);
newAttemp.setText("新建");
panel.add(newAttemp);
final JButton editAttemp = new JButton();
editAttemp.setBounds(80, 20, 60, 25);
editAttemp.setText("编辑");
panel.add(editAttemp);
final JButton delAttemp = new JButton();
delAttemp.setBounds(140, 20, 60, 25);
delAttemp.setText("删除");
panel.add(delAttemp);
add(panel, BorderLayout.NORTH);
model = new AttempTableModel(columnNames, 0);
table = new JTable(model);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
TableColumnModel colModel = table.getColumnModel();
int columnCount = table.getColumnCount();
TableColumn[] columns = new TableColumn[columnCount];
for (int i = 0; i < columnCount; i++) {
columns[i] = colModel.getColumn(i);
columns[i].setPreferredWidth(colWidths[i]);
}
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane, BorderLayout.CENTER);
newAttempDialog = new AttempNewPanel(this);
newAttemp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
newAttempDialog.updateUIAndData(null);
newAttempDialog.setEditable(false);
newAttempDialog.setVisible(true);
}
});
editAttemp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editAttemp();
}
});
delAttemp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int idx = table.getSelectedRow();
if (idx < 0){
JOptionPane.showMessageDialog(taskDialog, "请选择一个调度!");
return;
}
int n = JOptionPane.showConfirmDialog(
taskDialog, "您确定要删除该调度吗?", "删除调度", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
for (int i = idx + 1; i < table.getRowCount(); i++) {
attempData.get(i)[0] = String.valueOf(i);
table.setValueAt(new Integer(i), i, 0);
}
attempData.remove(idx);
model.removeRow(idx);
}
}
});
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
editAttemp();
}
}
});
}
public void editAttemp() {
int rowNo = table.getSelectedRow();
if (rowNo < 0) {
JOptionPane.showMessageDialog(taskDialog, "请选择您想要编辑的调度!");
return;
}
String[] oneAttemp = attempData.get(rowNo);
newAttempDialog.updateUIAndData(oneAttemp);
newAttempDialog.setEditable(true);
newAttempDialog.setVisible(true);
}
private ArrayList<String[]> attempData = new ArrayList<String[]>();
private JTable table;
private AttempTableModel model;
private int ID;
private TaskDialog taskDialog;
private String[] columnNames = Constant.attempData;
private int[] colWidths = { 25, 150, 100, 100, 110, 110};
private AttempNewPanel newAttempDialog;
public JDialog getNewAttempDialog() {
return newAttempDialog;
}
public ArrayList<String[]> getAttempData() {
return attempData;
}
public void setAttempData(ArrayList<String[]> attempData) {
this.attempData = attempData;
}
public AttempTableModel getModel() {
return model;
}
public void setModel(AttempTableModel model) {
this.model = model;
}
public JTable getTable() {
return table;
}
public void setTable(JTable table) {
this.table = table;
}
public int getID() {
return ID;
}
public void setID(int id) {
ID = id;
}
public TaskDialog getTaskDialog() {
return taskDialog;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -