?? mainframe.java
字號:
JMenuItem newTask = new JMenuItem("新建任務");
newTask.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
proxy.createNewTask();
}
});
JMenuItem editTask = new JMenuItem("編輯任務");
editTask.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
proxy.editTask(table.getSelectedRow(), 0);
}
});
JMenuItem delTask = new JMenuItem("刪除任務");
delTask.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
proxy.delTask();
}
});
JMenuItem historyLog = new JMenuItem("歷史記錄");
historyLog.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String logText =
proxy.getParser().getBuffers()[table.getSelectedRow()].toString();
historyDialog.setLogText(logText);
historyDialog.setVisible(true);
}
});
final JMenuItem runOrStopTask = new JMenuItem("啟動/中止任務");
if (rowNo < 0) {
instantRun.setEnabled(false);
editTask.setEnabled(false);
delTask.setEnabled(false);
runOrStopTask.setEnabled(false);
historyLog.setEnabled(false);
}
else if (!proxy.isLoadSuccessful()
|| rowNo >= proxy.getParser().getBuffers().length) {
historyLog.setEnabled(false);
}
final int runColumn = columnCount - 1;
final boolean isStartup = ((Boolean) table.getValueAt(
rowNo, runColumn)).booleanValue();
if (isStartup) {
instantRun.setEnabled(false);
}
runOrStopTask.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (proxy.runOrStopTask(rowNo, !isStartup, 0)) {
table.setValueAt(new Boolean(!isStartup),
rowNo, runColumn);
}
}
});
JPopupMenu popup = new JPopupMenu();
popup.add(instantRun);
popup.add(newTask);
popup.add(editTask);
popup.add(delTask);
popup.add(runOrStopTask);
popup.add(historyLog);
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
});
table.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
int rowNo = table.getSelectedRow();
if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN) {
if (keyCode == KeyEvent.VK_UP && rowNo > 0) {
rowNo--;
}
else if (keyCode == KeyEvent.VK_DOWN && rowNo < table.getRowCount()-1) {
rowNo++;
}
}
else if (keyCode == KeyEvent.VK_ENTER) {
proxy.editTask(table.getSelectedRow(), 0);
}
}
});
newTaskMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
proxy.createNewTask();
}
});
loadTaskMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
proxy.loadTaskList();
}
});
exitMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
exitSystem();
}
});
windowSkinMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String lafClassName = UIManager.getSystemLookAndFeelClassName();
changeSkin(lafClassName);
}
});
swingSkinMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String lafClassName = UIManager.getCrossPlatformLookAndFeelClassName();
changeSkin(lafClassName);
}
});
mailMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
clearLogItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
logInfo.setText(null);
}
});
aboutMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(
mainFrame, aboutText, "關于", JOptionPane.INFORMATION_MESSAGE
);
}
});
newTaskButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
proxy.createNewTask();
}
});
editTaskButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
proxy.editTask(table.getSelectedRow(), 0);
}
});
delTaskButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
proxy.delTask();
}
});
saveTaskListButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
proxy.saveTaskList();
}
});
clearTaskListButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
proxy.clearTaskList();
}
});
editor.addCellEditorListener(new CellEditorListener() {
public void editingStopped(ChangeEvent e){
int rowNo = table.getSelectedRow();
int runColumn = columnCount-1;
boolean isStartup = ((Boolean)table.getValueAt(rowNo, runColumn)).booleanValue();
proxy.runOrStopTask(rowNo, isStartup, 0);
}
public void editingCanceled(ChangeEvent arg0) {
}
});
runAllButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
proxy.runAllTask();
}
});
stopAllButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
proxy.stopAllTask();
}
});
logInfo.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3){ // 鼠標右鍵
JMenuItem clear = new JMenuItem("清空");
clear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
logInfo.setText(null);
}
});
JPopupMenu popup = new JPopupMenu();
popup.add(clear);
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
});
}
private void changeSkin(String skinClassName) {
if (UIManager.getLookAndFeel().toString().indexOf(
skinClassName) != -1) {
return;
}
try {
UIManager.setLookAndFeel(skinClassName);
SwingUtilities.updateComponentTreeUI(mainFrame);
SwingUtilities.updateComponentTreeUI(taskDialog);
JDialog stepDialog = taskDialog.getStepPanel().getNewStepDialog();
AttempNewPanel attempDialog =
(AttempNewPanel)taskDialog.getAttempPanel().getNewAttempDialog();
JButton runDateButton = attempDialog.getRunDateButton();
JButton startDateButton = attempDialog.getStartDateButton();
JButton endDateButton = attempDialog.getEndDateButton();
SwingUtilities.updateComponentTreeUI(proxy.getFileChooser());
SwingUtilities.updateComponentTreeUI(stepDialog);
SwingUtilities.updateComponentTreeUI(attempDialog);
SwingUtilities.updateComponentTreeUI(runDateButton);
SwingUtilities.updateComponentTreeUI(startDateButton);
SwingUtilities.updateComponentTreeUI(endDateButton);
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void exitSystem() {
mainFrame.dispose();
WindowsTrayIcon.cleanUp();
System.exit(0);
}
public static void createAndShowGUI() {
//long start = System.currentTimeMillis();
/* 設置系統默認外觀*/
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
mainFrame = new MainFrame(Constant.systemName);
if (outerInvoke) {
mainFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
else {
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
mainFrame.setIconImage(((ImageIcon) Constant.systemIcon).getImage());
mainFrame.setSize(new Dimension(X, Y));
mainFrame.setLocation(offsetX/2, offsetY/4);
mainFrame.setVisible(true);
//long end = System.currentTimeMillis();
//System.out.println("total cost times: "+(end-start));
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
//new MainFrame();
}
private JButton runAllButton, stopAllButton, newTaskButton, editTaskButton,
delTaskButton, clearTaskListButton, saveTaskListButton;
private JMenuItem newTaskMenuItem, loadTaskMenuItem, exitMenuItem,
windowSkinMenuItem, swingSkinMenuItem, mailMenuItem, clearLogItem, aboutMenuItem;
public static MainFrame mainFrame;
private MainFrameTableModel model;
private JTable table;
private TableCellEditor editor;
private JFileChooser fileChooser;
private TaskDialog taskDialog;
private HistoryLog historyDialog;
private TaskProxy proxy;
private XmlFilter filter;
private JTextPane logInfo;
private static Dimension screenSize = Toolkit.getDefaultToolkit()
.getScreenSize();
private static int maxX = screenSize.width;
private static int maxY = screenSize.height;
private static int offsetX = 400;
private static int offsetY = 300;
private static int X = maxX - offsetX;
private static int Y = maxY - offsetY;
private int[] colWidths = { 25, 100, 100, 200, 110, 110, 50 };
private static boolean outerInvoke;
public String taskListName = "";
public int columnCount;
public static String aboutText;
public void setTaskListName(String taskListName) {
this.taskListName = taskListName;
}
public MainFrameTableModel getModel() {
return model;
}
public void setModel(MainFrameTableModel model) {
this.model = model;
}
public JTable getTable() {
return table;
}
public JFileChooser getFileChooser() {
return fileChooser;
}
public void setFileChooser(JFileChooser fileChooser) {
this.fileChooser = fileChooser;
}
public TaskDialog getTaskDialog() {
return taskDialog;
}
public JTextPane getLogInfo() {
return logInfo;
}
public TaskProxy getProxy() {
return proxy;
}
}
class XmlFilter extends FileFilter{
public boolean accept(java.io.File f) {
if (f != null){
String fileName = f.getName();
String ext = fileName.substring(
fileName.lastIndexOf(".") + 1).toLowerCase();
if (f.isDirectory() || ext.equals("xml")){
return true;
}
}
return false;
}
public String getDescription() {
return "xml文件";
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -