📄 resultdisplay.java
字号:
/* * YALE - Yet Another Learning Environment * Copyright (C) 2002, 2003 * Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, * Katharina Morik, Oliver Ritthoff * Artificial Intelligence Unit * Computer Science Department * University of Dortmund * 44221 Dortmund, Germany * email: yale@ls8.cs.uni-dortmund.de * web: http://yale.cs.uni-dortmund.de/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */package edu.udo.cs.yale.gui;import edu.udo.cs.yale.Statistics;import edu.udo.cs.yale.operator.Operator;import edu.udo.cs.yale.operator.ResultObject;import edu.udo.cs.yale.operator.IOContainer;import edu.udo.cs.yale.operator.MissingIOObjectException;import edu.udo.cs.yale.tools.Tools;import javax.swing.JComponent;import javax.swing.JTabbedPane;import javax.swing.JPanel;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.BorderFactory;import javax.swing.JScrollPane;import javax.swing.JLabel;import javax.swing.Action;import javax.swing.JButton;import java.awt.Component;import java.awt.FlowLayout;import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Collection;import java.util.List;import java.util.LinkedList;import java.util.Iterator;public class ResultDisplay extends JPanel implements ExperimentEditor { private int size; private List results; private JTabbedPane tabs = new JTabbedPane(JTabbedPane.RIGHT); private JLabel label = new JLabel("Results");; private Collection statistics = new LinkedList(); public ResultDisplay() { super(new BorderLayout()); add(tabs, BorderLayout.CENTER); add(label, BorderLayout.NORTH); setData(null, "Results"); } public void clear() { tabs.removeAll(); setStatistics(new LinkedList()); setData(null, null); } public void setStatistics(Collection statistics) { this.statistics = statistics; addStatistics(); } private void addStatistics() { Iterator i = statistics.iterator(); while (i.hasNext()) { Statistics stats = (Statistics)i.next(); tabs.addTab(stats.getName(), new PlotterPanel(stats)); } } public void setData(IOContainer results, String message) { int selectedIndex = tabs.getSelectedIndex(); //tabs.removeAll(); for (int i = tabs.getTabCount()-1; i >= 0; i--) { Component c = tabs.getComponentAt(i); if (!(c instanceof PlotterPanel)) { tabs.removeTabAt(i); } } label.setText(message); //addStatistics(); this.results = convertToList(results); if (this.results.size() > 0) { Iterator i = this.results.iterator(); while (i.hasNext()) { ResultObject result = (ResultObject)i.next(); JPanel resultPanel = new JPanel(new BorderLayout()); Component visualisationComponent = result.getVisualisationComponent(); JScrollPane scrollPane = new JScrollPane(visualisationComponent); resultPanel.putClientProperty("main.component", visualisationComponent); resultPanel.add(scrollPane, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); Iterator action = result.getActions().iterator(); while (action.hasNext()) { buttonPanel.add(new JButton((Action)action.next())); } resultPanel.add(buttonPanel, BorderLayout.SOUTH); tabs.addTab(result.getName(), resultPanel); } } else { label.setText("No results produced."); } if (selectedIndex < tabs.getTabCount()) { tabs.setSelectedIndex(selectedIndex); } else { if (tabs.getTabCount() > 0) tabs.setSelectedIndex(0); } } public static JDialog createDialog(IOContainer results, Component parent, List additionalButtons) { final JDialog dialog = new JDialog(); dialog.setTitle("Experiment results"); dialog.setModal(false); ResultDisplay display = new ResultDisplay(); display.setData(results, "Results:"); if (display.size != 0) { display.setBorder(BorderFactory.createEmptyBorder(11,11,11,11)); dialog.getContentPane().add(display, BorderLayout.CENTER); } else { dialog.getContentPane().add(new JLabel("No results produced."), BorderLayout.CENTER); } JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); if (additionalButtons != null) { Iterator i = additionalButtons.iterator(); while (i.hasNext()) { JButton button = (JButton)i.next(); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); buttonPanel.add(button); } } JButton close = new JButton("Close"); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); buttonPanel.add(close); dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH); dialog.pack(); dialog.setLocationRelativeTo(parent); return dialog; } private static List convertToList(IOContainer container) { List list = new LinkedList(); if (container != null) { ResultObject result = null; do { try { result = (ResultObject)container.getInput(ResultObject.class, list.size(), false); list.add(result); } catch (MissingIOObjectException e) { break; } } while (result != null); } return list; } public void experimentChanged(Operator operator) {} public void validateExperiment() throws Exception {} public Component getMainComponent() { JComponent c = (JComponent)tabs.getSelectedComponent(); Component main = (Component)c.getClientProperty("main.component"); if (main != null) return main; else return c; } public void showSomething() { if (tabs.getSelectedIndex() == -1) if (tabs.getTabCount() > 0) tabs.setSelectedIndex(0); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -