📄 graphconstructiondialog2.java
字号:
package gui;
import javax.swing.JDialog;
import javax.swing.JSlider;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JSpinner;
import java.util.Hashtable;
import javax.swing.SpinnerNumberModel;
import graph.GraphEventManager;
public class GraphConstructionDialog2 extends JDialog
{
public GraphConstructionDialog2()
{
initComponents();
}
protected void initComponents()
{
panelMain = new JPanel();
labelNbLevels = new JLabel();
labelWithProbability = new JLabel();
label1 = new JLabel();
label2 = new JLabel();
label3 = new JLabel();
label4 = new JLabel();
radio1 = new JRadioButton("With probability for edges", true);
radio1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
setLastType(0);
}
});
radio2 = new JRadioButton("Fully interconnected");
radio2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
setLastType(1);
}
});
radio3 = new JRadioButton("Circular");
radio3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
setLastType(2);
}
});
radio4 = new JRadioButton("Star");
radio4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
setLastType(3);
}
});
buttonGroupOrganisation = new ButtonGroup();
buttonGroupOrganisation.add(radio1);
buttonGroupOrganisation.add(radio2);
buttonGroupOrganisation.add(radio3);
buttonGroupOrganisation.add(radio4);
//checkBoxWithProbability = new javax.swing.JCheckBox();
//checkBoxWithProbability = new java.awt.Checkbox("Allow edges between nodes at");
buttonOK = new javax.swing.JButton();
sliderProbability = new JSlider(JSlider.HORIZONTAL,0,10,5);
sliderCapacity = new JSlider(JSlider.HORIZONTAL,1,10,5);
spinnerModelNbNodes = new SpinnerNumberModel(2, 1, 30, 1);
spinnerNbNodes = new JSpinner(spinnerModelNbNodes);
panelMain.setLayout(null);
setSize(235,410);
panelMain.setOpaque(false);
setResizable(false);
setTitle("Graph Construction Wizard Step 2");
setName("Graph Construction Wizard Step 2");
addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowClosing(java.awt.event.WindowEvent evt) {
cancel();
}
});
label1.setText("Properties for level "); //#Changed
label1.setBounds(15,10,125,15);
panelMain.add(label1);
label2.setText("1"); //#Changed
label2.setBounds(140,10,30,15);
panelMain.add(label2);
labelNbLevels.setText("Nodes on this level: "); //#Changed
labelNbLevels.setBounds(15,50,125,15);
panelMain.add(labelNbLevels);
spinnerNbNodes.setBounds(145,48,40,20);
panelMain.add(spinnerNbNodes);
label3.setText("Choose layout: ");
label3.setBounds(15,80,250,15);
panelMain.add(label3);
radio1.setBounds(20,110,200,20);
panelMain.add(radio1);
//SLIDER
sliderProbability.setMajorTickSpacing(2);
sliderProbability.setMinorTickSpacing(1);
sliderProbability.setBounds(45, 140, 150, 35);
Hashtable labelTable = new Hashtable();
labelTable.put( new Integer( 0 ), new JLabel("0") );
labelTable.put( new Integer( 10 ), new JLabel("1") );
sliderProbability.setLabelTable( labelTable );
sliderProbability.setPaintLabels(true);
//sliderProbability.setPaintTicks(true);
panelMain.add(sliderProbability);
//RADIO 2
radio2.setBounds(20,180,200,20);
panelMain.add(radio2);
//RADIO 3
radio3.setBounds(20,205,200,20);
panelMain.add(radio3);
//RADIO 4
radio4.setBounds(20,230,200,20);
panelMain.add(radio4);
//Capacity - label
label4.setText("Capacity of the connections");
label4.setBounds(15,265,200,20);
panelMain.add(label4);
sliderCapacity.setMajorTickSpacing(2);
sliderCapacity.setMinorTickSpacing(1);
sliderCapacity.setBounds(20, 285, 150, 35);
labelTable = new Hashtable();
labelTable.put( new Integer( 1 ), new JLabel("Small") );
labelTable.put( new Integer( 10 ), new JLabel("Large") );
sliderCapacity.setLabelTable( labelTable );
sliderCapacity.setPaintLabels(true);
panelMain.add(sliderCapacity);
buttonOK.setText("Next");
buttonOK.setBounds(120,340,100,30); // 235 - 400
buttonOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
askNextParameters();
}
});
panelMain.add(buttonOK);
getContentPane().add(panelMain);
setLocation(100,100);
}
protected void nextLevel()
{
setVisible(false);
setVisible(true);
}
protected void cancel()
{
setVisible(false);
dispose();
}
public void askNextParameters()
{
nbNodes[current] = ((SpinnerNumberModel)spinnerNbNodes.getModel()).getNumber().intValue();
organisation[current] = lastType;
capacities[current] = sliderCapacity.getValue();
edgeProbs[current] = sliderProbability.getValue() / 10;
if ((current + 1) == nbLevels)
{
//STOP
dispose();
GraphEventManager.getReference().eventConstructNetworkGraph(nbNodes, organisation, edgeProbs, capacities);
}
else
{
current++;
hide();
label2.setText(String.valueOf(current+1));
show();
}
}
public void askParametersForLevels(int nbLevels)
{
nbNodes = new int[nbLevels];
organisation = new int[nbLevels];
edgeProbs = new double[nbLevels];
capacities = new int[nbLevels];
this.nbLevels = nbLevels;
current = 0;
lastType = 0;
label2.setText(String.valueOf(1));
show();
}
private void setLastType(int newLastType)
{
lastType = newLastType;
}
private JPanel panelMain;
private JLabel labelNbLevels, labelWithProbability, label1, label2, label3, label4;
private JSlider sliderProbability, sliderCapacity;
private SpinnerNumberModel spinnerModelNbNodes;
private JSpinner spinnerNbNodes;
private JButton buttonOK;
private ButtonGroup buttonGroupOrganisation;
private JRadioButton radio1, radio2, radio3, radio4;
private int[] nbNodes, organisation, capacities;
private double[] edgeProbs;
private int current;
private int lastType;
private int nbLevels;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -