📄 wizarddialog.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.Yale;import edu.udo.cs.yale.Experiment;import edu.udo.cs.yale.gui.Template;import edu.udo.cs.yale.tools.ParameterService;import edu.udo.cs.yale.tools.Tools;import edu.udo.cs.yale.tools.xml.XMLException;import javax.swing.JLabel;import javax.swing.JDialog;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.JScrollPane;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.BorderFactory;import javax.swing.ButtonGroup;import javax.swing.ImageIcon;import javax.swing.Icon;import java.awt.Component;import java.awt.FlowLayout;import java.awt.CardLayout;import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.IOException;import java.io.FileFilter;import javax.imageio.ImageIO;import java.awt.Image;/** The wizard dialog assists the user in creating a new experiment. Template experiments are loaded * from the etc/templates directory. Instances of all experiments are created and the parameters can * be set. */public class WizardDialog extends JDialog { private static Icon wizardIcon; static { try { wizardIcon = new ImageIcon(ImageIO.read(Tools.getResource("wizard.jpg"))); } catch (IOException e) { e.printStackTrace(); } } private MainFrame mainFrame; private JButton next = new JButton("Next >"); private JButton previous = new JButton("< Previous"); private CardLayout cardLayout = new CardLayout(); private JPanel mainPanel = new JPanel(cardLayout); private ExperimentRenderer experimentRenderer = new ExperimentRenderer(); private WizardPropertyTable propertyTable = new WizardPropertyTable(); private int currentStep = 0; private int numberOfSteps = 0; private Experiment[] experiments; private Template[] templates; private int selectedTemplateIndex; public WizardDialog(MainFrame mainFrame) { super(mainFrame, "Wizard", true); this.mainFrame = mainFrame; JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.add(next); buttonPanel.add(previous); previous.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { step(-1); } }); buttonPanel.add(next); next.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { step(1); } }); buttonPanel.add(Box.createHorizontalStrut(11)); JButton cancel = new JButton("Cancel"); buttonPanel.add(cancel); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancel(); } }); getContentPane().add(buttonPanel, BorderLayout.SOUTH); getContentPane().add(mainPanel, BorderLayout.CENTER); mainPanel.setBorder(BorderFactory.createEmptyBorder(11,11,11,11)); addTitle(); addChooseTemplate(); addParameters(); pack(); setSize(800,600); setLocationRelativeTo(mainFrame); step(0); } private static JPanel createPanel(String title, String text) { JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("<html><h2>"+title+"</h2><p>"+text+"</p></html>"); label.setFont(label.getFont().deriveFont(java.awt.Font.PLAIN)); panel.add(label, BorderLayout.NORTH); return panel; } private void addTitle() { JPanel panel = createPanel("Welcome to the Yale Experiment Wizard", "This wizard will guide you setting up a new experiment.</p>"); JPanel content = new JPanel(new FlowLayout(FlowLayout.LEFT)); JLabel image = new JLabel(wizardIcon); image.setBorder(BorderFactory.createLoweredBevelBorder()); content.add(image); JLabel label = new JLabel("<html>Using the wizard will involve the following steps:"+ "<ul>"+ "<li>Choose a template experiment</li>"+ "<li>Set some of the important parameters</li>"+ "<li>Create an attribute description file if necessary</li>"+ "</ul>"+ "<p>Completing these steps you can immediately start the experiment or "+ "go on editing and make advanced settings.</html>"); label.setPreferredSize(new java.awt.Dimension(300,200)); label.setFont(label.getFont().deriveFont(java.awt.Font.PLAIN)); content.add(label); panel.add(content, BorderLayout.CENTER); addStep(panel); } private void addChooseTemplate() { File[] templateFiles = ParameterService.getConfigFile("templates").listFiles(new FileFilter() { public boolean accept(File file) { return file.getName().endsWith(".template"); } }); JPanel panel = createPanel("Select a template", "Please select one of the following template experiments listed below. "+ "The image on the right is a schematic figure of the experiment showing operators as blue boxes and chains "+ "and wrappers as brownish boxes containing their inner operators."); Box radioBox = new Box(BoxLayout.Y_AXIS); ButtonGroup group = new ButtonGroup(); templates = new Template[templateFiles.length]; experiments = new Experiment[templateFiles.length]; for (int i = 0; i < templates.length; i++) { try { templates[i] = new Template(templateFiles[i]); experiments[i] = new Experiment(new File(templateFiles[i].getParent(), templates[i].getFilename())); experiments[i].setExperimentFile(null); } catch (Throwable e) { SwingTools.showErrorMessage("Cannot load template file '"+templateFiles[i]+"'", e); experiments[i] = new Experiment(); templates[i] = new Template(); } JRadioButton b = new JRadioButton("<html>"+templates[i].toHTML()+"</html>"); b.setFont(b.getFont().deriveFont(java.awt.Font.PLAIN)); if (i == 0) b.setSelected(true); final int j = i; b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { select(j); } }); radioBox.add(b); group.add(b); } select(0); panel.add(radioBox, BorderLayout.WEST); panel.add(new JScrollPane(experimentRenderer), BorderLayout.CENTER); addStep(panel); } private void addParameters() { JPanel panel = createPanel("Make Settings", "In the following, you find a list of the most important parameters of this experiment. "+ "Some of the parameters may have default values. The parameters set in bold face are mandatory. "+ "Pointing with the mouse on one of the parameters you will get some information about the meaning "+ "of the parameter."); panel.add(new JScrollPane(propertyTable), BorderLayout.CENTER); JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER)); //buttons.add(new JButton(mainFrame.ATTRIBUTE_EDITOR_ACTION)); panel.add(buttons, BorderLayout.SOUTH); addStep(panel); } private void addStep(Component c) { mainPanel.add(c, numberOfSteps+""); numberOfSteps++; } private void select(int index) { selectedTemplateIndex = index; Experiment experiment = experiments[index]; Template template = templates[index]; if ((experiment != null) && (template != null)) { experimentRenderer.setOperator(experiment.getRootOperator()); propertyTable.setExperiment(experiment, template.getParameters()); } else { experimentRenderer.setOperator(null); propertyTable.setExperiment(null, null); } } private void step(int dir) { currentStep += dir; if (currentStep < 0) currentStep = 0; if (currentStep == 0) previous.setEnabled(false); else previous.setEnabled(true); if (currentStep >= numberOfSteps) finish(); if (currentStep == numberOfSteps-1) { next.setText("Finish"); } else { next.setText("Next >"); } cardLayout.show(mainPanel, currentStep+""); } private void finish() { mainFrame.setExperiment(experiments[selectedTemplateIndex]); dispose(); } private void cancel() { dispose(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -