import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.tree.*;
import javax.swing.border.*;
public class javaants extends JFrame{
private JMenu file,edit,download,view,option,tool,help;
private JMenuItem exit,add,preference,bookmark;
private static JMenuItem start,stop;
private JMenuItem helptopic,about;
private JCheckBoxMenuItem istoolbar,isstatusbar;
private JMenuBar menubar;
private JToolBar toolbar;
private JButton addBut,helpBut;
private static JButton startBut,stopBut;
private JButton preferenceBut,exitBut;
private JComponent left,right;
Listener listener;
private Container contentPane;
private JSplitPane leftsp;
JScrollPane scrollPane;//
JPanel panel;
//static JProgressBar pb;
JLabel label,statusBar;
JTree tree;
DefaultTreeCellRenderer render;
public javaants(String name){
super(name);
init();
}
/*初始化程序界面*/
private void init(){
render=new DefaultTreeCellRenderer();
render.setBackgroundNonSelectionColor(Color.green);
render.setTextNonSelectionColor(Color.blue);
render.setTextSelectionColor(Color.red);
tree=new JTree(createNodes());
tree.setCellRenderer(render);
tree.setRootVisible(true);
//tree.setEditable(true);
tree.setBackground(Color.green);
label=new JLabel("ProgressMonitor:");
label.setForeground(Color.blue);
statusBar=new JLabel("StatusBar");
leftsp=new JSplitPane();
leftsp.setContinuousLayout(true);
leftsp.setDividerSize(10);
leftsp.setDividerLocation(204);
left=(JComponent)leftsp.getLeftComponent();
left.setBackground(Color.green);
right=(JComponent)leftsp.getRightComponent();
right.setBackground(Color.green);
panel=new JPanel();
panel.setBackground(Color.green);
//pb=new JProgressBar();
//pb.setBackground(Color.green);
//pb.setForeground(Color.red);
panel.add(label);
//panel.add(pb);
right.add(panel,BorderLayout.NORTH);
contentPane=getContentPane();
scrollPane=new JScrollPane(tree);
scrollPane.setBackground(Color.blue);
left.add(scrollPane);
listener=new Listener();
toolbar=new JToolBar();
//toolbar.setBackground(Color.green);
//toolbar.setForeground(Color.blue);
menubar=new JMenuBar();
//menubar.setBackground(Color.green);
//menubar.setForeground(Color.blue);
file=new JMenu("File");
file.setMnemonic('F');
exit=new JMenuItem("Exit");
exit.setMnemonic('X');
exit.addActionListener(listener);
exitBut=new JButton("Exit");
exitBut.setToolTipText("Exit");
exitBut.addActionListener(listener);
file.add(exit);
edit=new JMenu("Edit");
add=new JMenuItem("Add...");
add.addActionListener(listener);
addBut=new JButton("Add...");
addBut.setToolTipText("Add...");
addBut.addActionListener(listener);
edit.add(add);
download=new JMenu("Download");
start=new JMenuItem("Start");
start.addActionListener(listener);
start.setEnabled(false);
startBut=new JButton("Start");//
startBut.addActionListener(listener);
startBut.setEnabled(false);
startBut.setToolTipText("Start");
stopBut=new JButton("Stop");//
stopBut.addActionListener(listener);
stopBut.setToolTipText("Stop");
stopBut.setEnabled(false);
stop=new JMenuItem("Stop");
stop.addActionListener(listener);
stop.setEnabled(false);
download.add(start);
download.add(stop);
view=new JMenu("View");
istoolbar=new JCheckBoxMenuItem("ToolBar");
isstatusbar=new JCheckBoxMenuItem("StatusBar");
view.add(istoolbar);
view.add(isstatusbar);
option=new JMenu("Option");
preference=new JMenuItem("Preference...");
preference.addActionListener(listener);
preferenceBut=new JButton("Preference...");
preferenceBut.setToolTipText("Preference...");
preferenceBut.addActionListener(listener);
option.add(preference);
tool=new JMenu("Tool");
bookmark=new JMenuItem("BookMark...");
bookmark.addActionListener(listener);
tool.add(bookmark);
help=new JMenu("Help");
helptopic=new JMenuItem("Help Topic...");
helptopic.addActionListener(listener);
helpBut=new JButton("Help");
helpBut.setToolTipText("Help");
helpBut.addActionListener(listener);
about=new JMenuItem("About...");
about.addActionListener(listener);
help.add(helptopic);
help.add(about);
menubar.add(file);
menubar.add(edit);
menubar.add(download);
menubar.add(view);
menubar.add(option);
menubar.add(tool);
menubar.add(help);
toolbar.add(startBut);
toolbar.add(stopBut);
toolbar.add(addBut);
toolbar.add(preferenceBut);
toolbar.addSeparator();
toolbar.add(helpBut);
toolbar.addSeparator();
toolbar.add(exitBut);
contentPane.add(toolbar,BorderLayout.NORTH);
contentPane.add(leftsp,BorderLayout.CENTER);
contentPane.add(statusBar,BorderLayout.SOUTH);
setJMenuBar(menubar);
}
private DefaultMutableTreeNode createNodes(){
DefaultMutableTreeNode rootNode=new DefaultMutableTreeNode("Virtual Folder");
DefaultMutableTreeNode missionState=new DefaultMutableTreeNode("Mission State");
DefaultMutableTreeNode downDate=new DefaultMutableTreeNode("Down Date");
DefaultMutableTreeNode today=new DefaultMutableTreeNode("Today");
DefaultMutableTreeNode yesterday=new DefaultMutableTreeNode("Yesterday");
DefaultMutableTreeNode lastWeek=new DefaultMutableTreeNode("Last Week");
DefaultMutableTreeNode normal=new DefaultMutableTreeNode("Normal");
DefaultMutableTreeNode running=new DefaultMutableTreeNode("Running");
rootNode.add(missionState);
rootNode.add(downDate);
downDate.add(today);
downDate.add(yesterday);
downDate.add(lastWeek);
missionState.add(normal);
missionState.add(running);
return rootNode;
}
/*public static JProgressBar getProgressBar(){
return pb;
}*/
public static void setStartTrue(){
startBut.setEnabled(true);
start.setEnabled(true);
}
public static void setStartFalse(){
startBut.setEnabled(false);
start.setEnabled(false);
}
public static void setStopTrue(){
stopBut.setEnabled(true);
stop.setEnabled(true);
}
public static void setStopFalse(){
stopBut.setEnabled(false);
stop.setEnabled(false);
}
public void showAddDialog(){
AddDialog ad=new AddDialog(this);
ad.setSize(380,340);
ad.setModal(true);
ad.center();
ad.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
ad.show();
}
public void showPrefference(){
Prefference p=new Prefference(this);
p.setSize(380,340);
p.setModal(true);
p.center();
p.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
p.show();
}
public void showAbout(){
About about=new About(this);
about.setSize(380,340);
about.setModal(true);
about.center();
about.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
/*about.addWindowListener(new WindowAdapter(){
public void windowClosed(WindowEvent e){
about.dispose();
}
});*/
about.show();
}
class Listener implements ActionListener{
public void actionPerformed(ActionEvent e){
String arg=e.getActionCommand();
if(arg=="Exit"){
System.exit(0);
}
else if(arg=="Add..."){
showAddDialog();//
}
else if(arg=="Start"){
Utility.stop=false;
DownEnd de=new DownEnd();
de.start();
SplitFile split=new SplitFile();
split.start();
}
else if(arg=="Stop"){
stopBut.setEnabled(false);