📄 btpanel.java
字号:
/*
* @(#)BTPanel.java ver 1.2 6/20/2005
*
* Copyright 2005 Weishuai Yang (wyang@cs.binghamton.edu). All rights reserved.
*
*/
package gps.protocol.BT;
import gps.gui.ControlPanel;
import gps.gui.ProtocolPanel;
import gps.protocol.Protocol;
import gps.util.Config;
import gps.util.MyFileChooser;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
* Protocol panel for BT.
*
*
* @author Weishuai Yang
* @version 1.2, 6/20/2005
*/
public class BTPanel extends ProtocolPanel implements ActionListener {
private JPanel mPanel0, mPanel1, mPanel2, mPanel3;
private JLabel mLabelBTTrackers, mLabelBTPeers;
private JTextField mTextFieldBTTrackers, mTextFieldBTPeers;
private JButton mSaveConfig, mLoadConfig, mApply;
private MyFileChooser fileChooser = new MyFileChooser();
private String mGraphFile;
/**
* constructor
*
*/
public BTPanel(ControlPanel p) {
super(p);
mProtocolIndex=0;
mProtocol = BT.getInstance();
mProtocolProperties = mProtocol.getProtocolProperties();
makeShape();
setInitialValue();
}
/**
* gets protocol object
*/
public Protocol getProtocol(){
return mProtocol;
}
/**
* retrieve initial value from properties and set it to GUI interface
*/
public void setInitialValue() {
//set initial value from properties
mTextFieldBTTrackers.setText(mProtocolProperties.getProperty("BTTrackers"));
mTextFieldBTPeers.setText(mProtocolProperties.getProperty("BTPeers"));
String path=mProtocolProperties.getProperty("GraphFile");
if((path!=null)&&(path.length()!=0))
mParent.getSimGuiControl().openGraph(path);
}
/**
* action event handler
*/
public void actionPerformed(ActionEvent e) {
if ("Load".equals(e.getActionCommand())) {
fileChooser.setFileFilter(MyFileChooser.configFilter);
int res = fileChooser.showOpenDialog(mParent.getSimGuiControl().getSimGui());
if (res == JFileChooser.CANCEL_OPTION)
return;
File file = fileChooser.getSelectedFile();
loadConfig(file);
} else if ("Save".equals(e.getActionCommand())) {
fileChooser.setFileFilter(MyFileChooser.configFilter);
int res = fileChooser.showSaveDialog(mParent.getSimGuiControl().getSimGui());
if (res == JFileChooser.CANCEL_OPTION)
return;
File file = fileChooser.getSelectedFile();
saveConfig(file);
}
else if ("Apply".equals(e.getActionCommand())) {
apply();
}
}
/**
* called after load success
*/
public void loadSuccess() {
mProtocolProperties.setProperty("GraphFile", getGraph().getGraphFile());
}
/**
* synchronize user input in gui and properties
*/
public void updateProtocolProperties() {
mProtocolProperties.setProperty("BTTrackers", mTextFieldBTTrackers.getText());
mProtocolProperties.setProperty("BTPeers", mTextFieldBTPeers.getText());
//mProtocolProperties.setProperty("GraphFile",
// getGraph().getGraphFile());
int nodeNum = Integer.parseInt(mProtocolProperties.getProperty("BTTrackers")) + Integer.parseInt(mProtocolProperties.getProperty("BTPeers"));
mProtocolProperties.setProperty("TotalNodeNum", "" + nodeNum);
}
/**
* save properties into config file
* @param f File object
*/
public void saveConfig(File f) {
Config.saveConfToFileGUI(f, mProtocolProperties, mParent.getSimGuiControl().getSimGui().getFrame());
}
/**
* load config file into properties
* @param f File object
*/
public void loadConfig(File f) {
Config.loadConfFromFileGUI(f, mProtocolProperties, mParent.getSimGuiControl().getSimGui().getFrame());
int nodeNum = Integer.parseInt(mProtocolProperties.getProperty("BTTrackers")) + Integer.parseInt(mProtocolProperties.getProperty("BTPeers"));
mProtocolProperties.setProperty("TotalNodeNum", "" + nodeNum);
setInitialValue();
/*
* String graphfile=mProtocolProperties.getProperty("GraphFile");
* if((graphfile!=null)&&(graphfile!=""))
* mParent.getSimGuiControl().openGraph(graphfile);
*/
// mParent.getSimGuiControl().resetProgress();
// mSim.reset();
}
/**
* draws components
*/
public void makeShape() {
super.makeShape();
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
//Misc Panel
mPanel0 = new JPanel();
mPanel0.setLayout(null);
mLabelBTTrackers = new JLabel("BT Trackers:");
mLabelBTTrackers.setBounds(10, 0, 180, 20);
mTextFieldBTTrackers = new JFormattedTextField(new java.text.DecimalFormat("##0"));
mTextFieldBTTrackers.setBounds(200, 0, 60, 20);
//mTextFieldBTTrackers.setText("1");
mLabelBTPeers = new JLabel("BT Peers:");
mLabelBTPeers.setBounds(10, 25, 180, 20);
mTextFieldBTPeers = new JFormattedTextField(new java.text.DecimalFormat("##0"));
mTextFieldBTPeers.setBounds(200, 25, 60, 20);
//mTextFieldBTPeers.setText("10");
mPanel0.add(mLabelBTTrackers);
mPanel0.add(mTextFieldBTTrackers);
mPanel0.add(mLabelBTPeers);
mPanel0.add(mTextFieldBTPeers);
mPanel0.setMinimumSize(new Dimension(320, 65));
mPanel0.setPreferredSize(new Dimension(320, 65));
mPanel3 = new JPanel();
mPanel3.setLayout(new BoxLayout(mPanel3, BoxLayout.LINE_AXIS));
mLoadConfig = new JButton("Load");
mLoadConfig.setEnabled(true);
mLoadConfig.addActionListener(this);
mSaveConfig = new JButton("Save");
mSaveConfig.setEnabled(true);
mSaveConfig.addActionListener(this);
mApply = new JButton("Apply");
mApply.setEnabled(true);
mApply.addActionListener(this);
mPanel3.add(mLoadConfig);
mPanel3.add(mSaveConfig);
mPanel3.add(mApply);
mPanel3.setMinimumSize(new Dimension(320, 20));
mPanel3.setPreferredSize(new Dimension(320, 20));
add(mPanel0);
add(mPanel3);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -