📄 simulatorpanel.java
字号:
/*
* @(#)SimulatorPanel.java ver 1.2 6/20/2005
*
* Copyright 2005 Weishuai Yang (wyang@cs.binghamton.edu).
* All rights reserved.
*
*/
package gps.gui;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Properties;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
/**
* Panel which holds all protocol panels.
*
*
* @author Weishuai Yang
* @version 1.2, 6/20/2005
*/
public class SimulatorPanel extends JPanel implements ActionListener {
private JPanel networkPanel, ioPanel, systemPanel;
private JLabel mLabelTT, mLabelTS, mLabelSS, mMs1, mMs2, mMs3, mK1, mK2, mK3;
private JTextField mTextFieldDelayTT, mTextFieldDelayTS, mTextFieldDelaySS;
private JTextField mTextFieldBandwidthTT, mTextFieldBandwidthTS, mTextFieldBandwidthSS;
private JLabel mLabelOutputDir, mLabelScenarioFile, mLabelDocumentsFile, mLabelEventsFile;
private JTextField mTextFieldOutputDir, mTextFieldScenarioFile, mTextFieldDocumentsFile, mTextFieldEventsFile;
private JCheckBox mCheckBoxTraceLog, mCheckBoxEventLog, mCheckBoxDebugLog;
private JLabel mLabelRandomSeed;
private JTextField mTextFieldRandomSeed;
private Properties mProperties;
private JComboBox mChoices = null;
private JPanel mChoicePanel;
private int current=0;
private ControlPanel mParent=null;
/**
* intializer
* @param p reference back to control panel
* @prarm properties properties from outside
*/
public SimulatorPanel(ControlPanel p, Properties properties){
mProperties=properties;
mParent=p;
//Create and initialize the buttons.
final JButton saveButton = new JButton("Save");
saveButton.setActionCommand("Save");
saveButton.addActionListener(this);
//getRootPane().setDefaultButton(saveButton);
final JButton applyButton = new JButton("Apply");
applyButton.setActionCommand("Apply");
applyButton.addActionListener(this);
setBorder(new javax.swing.border.TitledBorder("Simulator Properties:"));
String[] simulation = { "BT", "Empty" };
mChoices = new JComboBox(simulation);
mChoices.setSelectedIndex(0);
mChoices.setSize(40, 20);
mChoices.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
if ("comboBoxChanged".equals(evt.getActionCommand())) {
//Update the icon to display the new phase
if(current==mChoices.getSelectedIndex())
return;
if(0==mChoices.getSelectedIndex()){
current=mChoices.getSelectedIndex();
//updateprotocolpanel();
}
else{
JOptionPane.showMessageDialog(mParent.getSimGuiControl().getSimGui().getFrame(),"Not implemented yet!", "Error!", JOptionPane.ERROR_MESSAGE);
return;
}
}
}
});
mChoicePanel=new JPanel();
mChoicePanel.setLayout(null);
//mChoicePanel.setLayout(new BoxLayout(mChoicePanel, BoxLayout.LINE_AXIS));
//mChoicePanel.add(Box.createHorizontalGlue());
JLabel l=new JLabel("P2P protocol to simulate:");
l.setBounds(10, 0, 160, 20);
mChoices.setBounds(190, 0, 80, 18);
mChoicePanel.add(l);
mChoicePanel.add(mChoices);
mChoicePanel.setPreferredSize(new Dimension(295,22));
mChoicePanel.setMinimumSize(new Dimension(295,22));
add(mChoicePanel);
//Create a container so that we can add a title around
//the scroll pane. Can't add a title directly to the
//scroll pane because its background would be white.
//Lay out the label and scroll pane from top to bottom.
JPanel optionPane = new JPanel();
//optionPane.setLayout(new BoxLayout(optionPane, BoxLayout.PAGE_AXIS));
JTabbedPane tabbedPane = new JTabbedPane();
JComponent panel1 = makeIOPanel();
panel1.setPreferredSize(new Dimension(295, 140));
tabbedPane.addTab("Input/Output", panel1);
tabbedPane.setMnemonicAt(0, KeyEvent.VK_I);
JComponent panel2 = makeNetworkPanel();
tabbedPane.addTab("Delay/Bandwidth", panel2);
tabbedPane.setMnemonicAt(1, KeyEvent.VK_D);
JComponent panel3 = makeSystemPanel();
tabbedPane.addTab("System", panel3);
tabbedPane.setMnemonicAt(2, KeyEvent.VK_S);
//Uncomment the following line to use scrolling tabs.
//tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
//Add the tabbed pane to this panel.
optionPane.add(tabbedPane);
//optionPane.add(Box.createRigidArea(new Dimension(0,5)));
//optionPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
//Lay out the buttons from left to right.
JPanel buttonPane = new JPanel();
//buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
//buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
buttonPane.add(Box.createHorizontalGlue());
buttonPane.add(saveButton);
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPane.add(applyButton);
buttonPane.setMinimumSize(new Dimension(305,20));
buttonPane.setPreferredSize(new Dimension(305,20));
add(optionPane);
//add(buttonPane);
}
protected JComponent makeTextPanel(String text) {
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
protected JComponent makeNetworkPanel() {
networkPanel=new JPanel();
//networkPanel.setBorder(new javax.swing.border.TitledBorder("Delay/Bandwidth"));
networkPanel.setLayout(null);
mLabelTT = new JLabel("Transit-Transit:");
mLabelTT.setBounds(10, 20, 100, 20);
mTextFieldDelayTT = new JFormattedTextField(new java.text.DecimalFormat("##0.0#"));
mTextFieldDelayTT.setBounds(120, 20, 35, 20);
//mTextFieldDelayTT.setText("5");
mMs1=new JLabel("ms");
mMs1.setBounds(160, 20, 20, 20);
mTextFieldBandwidthTT = new JFormattedTextField(new java.text.DecimalFormat("##0.0#"));
mTextFieldBandwidthTT.setBounds(195, 20, 50, 20);
//mTextFieldBandwidthTT.setText("100000");
mK1=new JLabel("Mbps");
mK1.setBounds(250, 20, 35, 20);
mLabelTS = new JLabel("Transit-Stub:");
mLabelTS.setBounds(10, 45, 100, 20);
mTextFieldDelayTS = new JFormattedTextField(new java.text.DecimalFormat("##0.0#"));
mTextFieldDelayTS.setBounds(120, 45, 35, 20);
//mTextFieldDelayTS.setText("10");
mMs2=new JLabel("ms");
mMs2.setBounds(160, 45, 20, 20);
mTextFieldBandwidthTS = new JFormattedTextField(new java.text.DecimalFormat("##0.0#"));
mTextFieldBandwidthTS.setBounds(195, 45, 50, 20);
//mTextFieldBandwidthTS.setText("100");
mK2=new JLabel("Mbps");
mK2.setBounds(250, 45, 35, 20);
mLabelSS = new javax.swing.JLabel("Within Stub:");
mLabelSS.setBounds(10, 70, 100, 20);
mTextFieldDelaySS = new JFormattedTextField(new java.text.DecimalFormat("##0.0#"));
mTextFieldDelaySS.setBounds(120, 70, 35, 20);
//mTextFieldDelaySS.setText("30");
mMs3=new JLabel("ms");
mMs3.setBounds(160, 70, 20, 20);
mTextFieldBandwidthSS = new JFormattedTextField(new java.text.DecimalFormat("##0.0#"));
mTextFieldBandwidthSS.setBounds(195, 70, 50, 20);
//mTextFieldBandwidthSS.setText("10");
mK3=new JLabel("Mbps");
mK3.setBounds(250, 70, 35, 20);
networkPanel.add(mLabelTT);
networkPanel.add(mTextFieldDelayTT);
networkPanel.add(mMs1);
networkPanel.add(mTextFieldBandwidthTT);
networkPanel.add(mK1);
networkPanel.add(mLabelTS);
networkPanel.add(mTextFieldDelayTS);
networkPanel.add(mMs2);
networkPanel.add(mTextFieldBandwidthTS);
networkPanel.add(mK2);
networkPanel.add(mLabelSS);
networkPanel.add(mTextFieldDelaySS);
networkPanel.add(mMs3);
networkPanel.add(mTextFieldBandwidthSS);
networkPanel.add(mK3);
return networkPanel;
}
protected JComponent makeIOPanel() {
ioPanel=new JPanel();
//ioPanel.setBorder(new javax.swing.border.TitledBorder("Input/Output"));
ioPanel.setLayout(null);
mLabelDocumentsFile = new JLabel("Document File:");
mLabelDocumentsFile.setBounds(10, 20, 110, 20);
mTextFieldDocumentsFile = new JTextField();
mTextFieldDocumentsFile.setBounds(120, 20, 140, 20);
//mTextFieldDocumentsFile.setText("documents.txt");
mLabelEventsFile = new javax.swing.JLabel("Events File:");
mLabelEventsFile.setBounds(10, 45, 110, 20);
mTextFieldEventsFile = new JTextField();
mTextFieldEventsFile.setBounds(120, 45, 140, 20);
//mTextFieldEventsFile.setText("events.txt");
mLabelOutputDir = new JLabel("Output Directory:");
mLabelOutputDir.setBounds(10, 70, 110, 20);
mTextFieldOutputDir = new JTextField();
mTextFieldOutputDir.setBounds(120, 70, 140, 20);
//mTextFieldOutputDir.setText("output");
mCheckBoxTraceLog = new JCheckBox("Trace Log", true);
//mCheckBoxTraceLog.setMnemonic(KeyEvent.VK_T);
mCheckBoxTraceLog.setBounds(10, 95, 85, 20);
mCheckBoxEventLog = new JCheckBox("Event Log", true);
//mCheckBoxEventLog.setMnemonic(KeyEvent.VK_E);
mCheckBoxEventLog.setBounds(100, 95, 85, 20);
mCheckBoxDebugLog = new JCheckBox("Debug Log", true);
//mCheckBoxDebugLog.setMnemonic(KeyEvent.VK_D);
mCheckBoxDebugLog.setBounds(190, 95, 85, 20);
ioPanel.add(mLabelDocumentsFile);
ioPanel.add(mTextFieldDocumentsFile);
ioPanel.add(mLabelEventsFile);
ioPanel.add(mTextFieldEventsFile);
ioPanel.add(mLabelOutputDir);
ioPanel.add(mTextFieldOutputDir);
ioPanel.add(mCheckBoxTraceLog);
ioPanel.add(mCheckBoxEventLog);
ioPanel.add(mCheckBoxDebugLog);
return ioPanel;
}
protected JComponent makeSystemPanel() {
systemPanel=new JPanel();
//systemPanel.setBorder(new javax.swing.border.TitledBorder("System"));
systemPanel.setLayout(null);
mLabelRandomSeed = new JLabel("Random Seed:");
mLabelRandomSeed.setBounds(10, 20, 180, 20);
mTextFieldRandomSeed = new JFormattedTextField(new java.text.DecimalFormat("##0"));
mTextFieldRandomSeed.setBounds(200, 20, 60, 20);
//mTextFieldRandomSeed.setText("12345");
systemPanel.add(mLabelRandomSeed);
systemPanel.add(mTextFieldRandomSeed);
return systemPanel;
}
/**
* Handle clicks on the Set and Cancel buttons.
* @param e action event
*/
public void actionPerformed(ActionEvent e) {
if ("Save".equals(e.getActionCommand())) {
apply();
//Config.saveConfToFile();
}
else if ("Apply".equals(e.getActionCommand())) {
apply();
}
}
/**
* retrieve values from properties to panel
*/
public void retrieve(){
mTextFieldRandomSeed.setText(mProperties.getProperty("RandomSeed"));
mTextFieldDelayTT.setText(mProperties.getProperty("DelayTT"));
mTextFieldDelayTS.setText(mProperties.getProperty("DelayTS"));
mTextFieldDelaySS.setText(mProperties.getProperty("DelaySS"));
mTextFieldBandwidthTT.setText(mProperties.getProperty("BandwidthTT"));
mTextFieldBandwidthTS.setText(mProperties.getProperty("BandwidthTS"));
mTextFieldBandwidthSS.setText(mProperties.getProperty("BandwidthSS"));
mTextFieldDocumentsFile.setText(mProperties.getProperty("DocumentsFile"));
mTextFieldEventsFile.setText(mProperties.getProperty("EventsFile"));
mTextFieldOutputDir.setText(mProperties.getProperty("OutputDir"));
if(mProperties.getProperty("TraceLog").compareToIgnoreCase("True")==0)
mCheckBoxTraceLog.setSelected(true);
else
mCheckBoxTraceLog.setSelected(false);
if(mProperties.getProperty("EventLog").compareToIgnoreCase("True")==0)
mCheckBoxEventLog.setSelected(true);
else
mCheckBoxEventLog.setSelected(false);
if(mProperties.getProperty("DebugLog").compareToIgnoreCase("True")==0)
mCheckBoxDebugLog.setSelected(true);
else
mCheckBoxDebugLog.setSelected(false);
}
/**
* save values from panel to properties
*/
public void apply(){
mProperties.setProperty("RandomSeed", mTextFieldRandomSeed.getText());
mProperties.setProperty("DelayTT", mTextFieldDelayTT.getText());
mProperties.setProperty("DelayTS", mTextFieldDelayTS.getText());
mProperties.setProperty("DelaySS", mTextFieldDelaySS.getText());
mProperties.setProperty("BandwidthTT", mTextFieldBandwidthTT.getText());
mProperties.setProperty("BandwidthTS", mTextFieldBandwidthTS.getText());
mProperties.setProperty("BandwidthSS", mTextFieldBandwidthSS.getText());
mProperties.setProperty("DocumentsFile", mTextFieldDocumentsFile.getText());
mProperties.setProperty("EventsFile", mTextFieldEventsFile.getText());
mProperties.setProperty("OutputDir", mTextFieldOutputDir.getText());
mProperties.setProperty("TraceLog", Boolean.toString(mCheckBoxTraceLog.isSelected()));
mProperties.setProperty("EventLog", Boolean.toString(mCheckBoxEventLog.isSelected()));
mProperties.setProperty("DebugLog", Boolean.toString(mCheckBoxDebugLog.isSelected()));
}
/**
* gets protocol index
* @return protocol index
*/
public int getProtocolIndex(){
return mChoices.getSelectedIndex();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -