📄 resultswindow.java
字号:
protected JTextField samples, mean, lower, upper;
protected JButton abortButton;
protected FastGraph graph, popupGraph;
protected JPanel graphPanel;
protected JFrame popupFrame;
protected JTextArea textState;
public MeasurePanel(MeasureDefinition md, int measureIndex) {
this.md = md;
this.measureIndex = measureIndex;
values = md.getValues(measureIndex);
createPanel();
addListeners();
}
/**
* Used to create the panel holding all measure's data
*/
protected void createPanel() {
this.setLayout(new BorderLayout(5,5));
this.setBorder(BorderFactory.createRaisedBevelBorder());
// Sets correct icon for this measure
icon = new JLabel();
icon.setIcon(ImageLoader.loadImage(IN_PROGRESS_IMAGE));
add(icon, BorderLayout.WEST);
//Adds mainPanel with all informations on this measure
JLabel label;
JTextField field;
JPanel mainPanel = new JPanel(new SpringLayout());
// Station name
label = new JLabel("Station Name: ");
field = new JTextField();
field.setEditable(false);
field.setMaximumSize(new Dimension(field.getMaximumSize().width, field.getMinimumSize().height)); label.setLabelFor(field);
// If station name is undefined, disables its fields
String stationName = md.getStationName(measureIndex);
if (stationName != null && !stationName.equals("")) {
field.setText(stationName);
field.setToolTipText("Name of the station");
}
else {
field.setText(ALL_STATIONS);
field.setToolTipText("This measure is referred to the entire network");
}
mainPanel.add(label);
mainPanel.add(field);
// Class name
label = new JLabel("Class Name: ");
field = new JTextField();
field.setEditable(false);
field.setMaximumSize(new Dimension(field.getMaximumSize().width, field.getMinimumSize().height)); label.setLabelFor(field);
// If class name is undefined, shows ALL_CLASSES constant
String className = md.getClassName(measureIndex);
if (className != null && !className.equals("")) {
field.setText(className);
field.setToolTipText("Name of the class");
}
else {
field.setText(ResultsConstants.ALL_CLASSES);
field.setToolTipText("This measure is an aggregate of every class");
}
mainPanel.add(label);
mainPanel.add(field);
// Alpha/Precision
label = new JLabel("Conf.Int/Max Rel.Err: ");
field = new JTextField();
field.setEditable(false);
field.setMaximumSize(new Dimension(field.getMaximumSize().width, field.getMinimumSize().height));
label.setLabelFor(field);
field.setText(md.getAlpha(measureIndex) + " / " + md.getPrecision(measureIndex)); // AnalyzedSamples
field.setToolTipText("Confidence Interval and Maximum Relative Error requested for this measure");
mainPanel.add(label);
mainPanel.add(field);
// Analyzed samples
label = new JLabel("Analyzed samples: ");
samples = new JTextField();
samples.setEditable(false);
samples.setMaximumSize(new Dimension(samples.getMaximumSize().width, samples.getMinimumSize().height));
label.setLabelFor(samples);
samples.setText(""+md.getAnalizedSamples(measureIndex));
samples.setToolTipText("Number of samples currently analized");
mainPanel.add(label);
mainPanel.add(samples);
MeasureDefinition.Value lastValue = (MeasureDefinition.Value)values.lastElement();
// Lower Bound
label = new JLabel("Min: ");
lower = new JTextField("-");
lower.setEditable(false);
lower.setMaximumSize(new Dimension(lower.getMaximumSize().width, lower.getMinimumSize().height));
label.setLabelFor(lower);
if (lastValue.getLowerBound() > 0 && !Double.isInfinite(lastValue.getLowerBound()))
lower.setText(doubleToString(lastValue.getLowerBound()));
lower.setToolTipText("Minimum value of current confidence interval");
mainPanel.add(label);
mainPanel.add(lower);
// Upper Bound
label = new JLabel("Max: ");
upper = new JTextField("-");
upper.setEditable(false);
upper.setMaximumSize(new Dimension(upper.getMaximumSize().width, upper.getMinimumSize().height));
label.setLabelFor(upper);
if (lastValue.getUpperBound() > 0 && !Double.isInfinite(lastValue.getUpperBound()))
upper.setText(doubleToString(lastValue.getUpperBound()));
upper.setToolTipText("Maximum value of current confidence interval");
mainPanel.add(label);
mainPanel.add(upper);
SpringUtilities.makeCompactGrid(mainPanel,
3, 4, //rows, cols
6, 6, //initX, initY
6, 6);//xPad, yPad
// Temp mean and abort button are threated in a separate panel
JPanel bottomPanel = new JPanel(new BorderLayout(6,6));
label = new JLabel(TEMP_MEAN);
mean = new JTextField();
mean.setEditable(false);
mean.setToolTipText("Current mean value of this measure");
label.setLabelFor(mean);
mean.setText(doubleToString(((MeasureDefinition.Value)values.lastElement()).getMeanValue()));
bottomPanel.add(label, BorderLayout.WEST);
bottomPanel.add(mean, BorderLayout.CENTER);
// AbortButton
abortButton = new JButton();
abortButton.setText("Abort Measure");
bottomPanel.add(abortButton, BorderLayout.EAST);
bottomPanel.setBorder(BorderFactory.createEmptyBorder(0,6,6,6));
JPanel pivotPanel = new JPanel(new BorderLayout());
pivotPanel.add(mainPanel, BorderLayout.CENTER);
pivotPanel.add(bottomPanel, BorderLayout.SOUTH);
// Pack text area in the north of the panel
JPanel pivotPanel2 = new JPanel(new BorderLayout());
pivotPanel2.add(pivotPanel, BorderLayout.NORTH);
// Adds a textPanel to show state
textState = new JTextArea();
textState.setEditable(false);
textState.setLineWrap(true);
textState.setWrapStyleWord(true);
JPanel textStatePanel = new JPanel(new BorderLayout());
textStatePanel.add(textState, BorderLayout.CENTER);
textStatePanel.setBorder(BorderFactory.createEmptyBorder(BORDERSIZE/2, BORDERSIZE/2, BORDERSIZE/2, BORDERSIZE/2));
pivotPanel2.add(textStatePanel, BorderLayout.SOUTH);
// Sets a minimal size for text area panel
pivotPanel2.setPreferredSize(new Dimension(360,150));
// Adds graph
graphPanel = new JPanel(new BorderLayout());
graph = new FastGraph(values, md.getPollingInterval());
graph.setToolTipText("Double click on this graph to open it in a new window");
graphPanel.add(graph, BorderLayout.CENTER);
graphPanel.add(pivotPanel2, BorderLayout.WEST);
add(graphPanel, BorderLayout.CENTER);
// Sets icon image and abort button state
setCorrectState();
}
/**
* Adds listeners to this panel, to refresh measures and abort simulation
*/
protected void addListeners() {
if(md.getMeasureState(measureIndex) == MeasureDefinition.MEASURE_IN_PROGRESS){
// If simulation is not finished, adds a measure listener
md.addMeasureListener(measureIndex, new MeasureDefinition.MeasureListener() {
public void measureChanged(Vector measureValues, boolean finished) {
// Update graphics
graph.repaint();
if (popupGraph != null)
popupGraph.repaint();
MeasureDefinition.Value lastValue = (MeasureDefinition.Value)measureValues.lastElement();
// Updates mean, lower, upper and samples
if (lastValue.getLowerBound() > 0 && !Double.isInfinite(lastValue.getUpperBound())) {
lower.setText(doubleToString(lastValue.getLowerBound()));
upper.setText(doubleToString(lastValue.getUpperBound()));
}
else {
lower.setText("-");
upper.setText("-");
}
mean.setText(doubleToString(lastValue.getMeanValue()));
samples.setText(""+md.getAnalizedSamples(measureIndex));
// If finished is true, state was changed
if (finished)
setCorrectState();
repaint();
}
});
// Sets AbortButton action, only if abort is available
if (abort != null) {
abortButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
abortButton.setEnabled(false);
abort.abortMeasure(measureIndex);
}
});
}
}
// Popups graph if graph window is double clicked
graph.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
if (popupFrame == null) {
popupFrame = new JFrame();
popupGraph = new FastGraph(values, md.getPollingInterval());
popupFrame.getContentPane().add(popupGraph);
popupFrame.setTitle(md.getName(measureIndex));
popupFrame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
int width = 640, height=480;
Dimension scrDim = Toolkit.getDefaultToolkit().getScreenSize();
popupFrame.setBounds((scrDim.width-width)/2,(scrDim.height-height)/2,width,height);
}
popupFrame.show();
}
}
});
}
/**
* Sets correct state to icon and abort button
*/
protected void setCorrectState() {
switch (md.getMeasureState(measureIndex)) {
case MeasureDefinition.MEASURE_IN_PROGRESS:
icon.setIcon(ImageLoader.loadImage(IN_PROGRESS_IMAGE));
icon.setToolTipText(IN_PROGRESS_TEXT);
textState.setText(IN_PROGRESS_TEXT);
abortButton.setEnabled(true);
break;
case MeasureDefinition.MEASURE_SUCCESS:
icon.setIcon(ImageLoader.loadImage(SUCCESS_IMAGE));
icon.setToolTipText(SUCCESS_TEXT);
textState.setText(SUCCESS_TEXT);
abortButton.setEnabled(false);
break;
case MeasureDefinition.MEASURE_FAILED:
icon.setIcon(ImageLoader.loadImage(FAILED_IMAGE));
icon.setToolTipText(FAILED_TEXT);
textState.setText(FAILED_TEXT);
abortButton.setEnabled(false);
break;
case MeasureDefinition.MEASURE_NO_SAMPLES:
icon.setIcon(ImageLoader.loadImage(NO_SAMPLES_IMAGE));
icon.setToolTipText(NO_SAMPLES_TEXT);
textState.setText(NO_SAMPLES_TEXT);
abortButton.setEnabled(false);
graph.setVisible(false); // Hides graph if no samples were received
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -