📄 operatorinfoscreen.java
字号:
/*
* YALE - Yet Another Learning Environment
* Copyright (C) 2001-2004
* Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,
* Katharina Morik, Oliver Ritthoff
* Artificial Intelligence Unit
* Computer Science Department
* University of Dortmund
* 44221 Dortmund, Germany
* email: yale-team@lists.sourceforge.net
* 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.operator.Operator;
import edu.udo.cs.yale.operator.OperatorChain;
import edu.udo.cs.yale.tools.Tools;
import javax.swing.*;
import java.awt.event.*;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Frame;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.Component;
import java.util.List;
import java.util.Iterator;
public class OperatorInfoScreen extends JDialog {
private JTextArea userDescription = null;
private boolean ok = false;
public OperatorInfoScreen(Frame owner, Operator operator) {
super(owner, "Operator Info", true);
JPanel rootPanel = new JPanel(new BorderLayout());
rootPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
GridBagLayout layout = new GridBagLayout();
JPanel mainPanel = new JPanel(layout);
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.ipadx = 10;
c.weightx = 1.0d;
JLabel label = null;
Image img = operator.getOperatorDescription().getIcon();
if (img != null) {
label = new JLabel(new ImageIcon(img));
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(label, c);
mainPanel.add(label);
}
Component sep = Box.createVerticalStrut(10);
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(sep, c);
mainPanel.add(sep);
label = new JLabel("Name");
label.setToolTipText("The name of the operator");
c.gridwidth = GridBagConstraints.RELATIVE;
layout.setConstraints(label, c);
mainPanel.add(label);
label = new JLabel(operator.getName());
label.setToolTipText("The name of the operator");
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(label, c);
mainPanel.add(label);
label = new JLabel("Group");
label.setToolTipText("The group of the operator");
c.gridwidth = GridBagConstraints.RELATIVE;
layout.setConstraints(label, c);
mainPanel.add(label);
label = new JLabel(operator.getOperatorDescription().getGroup());
label.setToolTipText("The group of the operator");
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(label, c);
mainPanel.add(label);
label = new JLabel("Class");
label.setToolTipText("The type of the operator");
c.gridwidth = GridBagConstraints.RELATIVE;
layout.setConstraints(label, c);
mainPanel.add(label);
label = new JLabel(operator.getOperatorDescription().getName());
label.setToolTipText("The type of the operator");
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(label, c);
mainPanel.add(label);
sep = Box.createVerticalStrut(10);
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(sep, c);
mainPanel.add(sep);
label = new JLabel("Input");
label.setToolTipText("Expected input");
c.gridwidth = GridBagConstraints.RELATIVE;
layout.setConstraints(label, c);
mainPanel.add(label);
Class[] input = operator.getInputClasses();
String inputString = "";
if (input == null) inputString = "none";
else {
for (int i = 0; i < input.length; i++) {
if (i != 0) inputString +=", ";
inputString += Tools.classNameWOPackage(input[i]);
}
}
if (inputString.length() == 0) inputString = "none";
label = new JLabel(inputString);
label.setToolTipText("Expected input");
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(label, c);
mainPanel.add(label);
label = new JLabel("Output");
label.setToolTipText("Delivered output");
c.gridwidth = GridBagConstraints.RELATIVE;
layout.setConstraints(label, c);
mainPanel.add(label);
Class[] output = operator.getOutputClasses();
String outputString = "";
if (output == null) outputString = "none";
else {
for (int i = 0; i < output.length; i++) {
if (i != 0) outputString +=", ";
outputString += Tools.classNameWOPackage(output[i]);
}
}
if (outputString.length() == 0) outputString = "none";
label = new JLabel(outputString);
label.setToolTipText("Delivered output");
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(label, c);
mainPanel.add(label);
if (operator instanceof OperatorChain) {
OperatorChain chain = (OperatorChain)operator;
sep = Box.createVerticalStrut(10);
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(sep, c);
mainPanel.add(sep);
if (chain.getMinNumberOfInnerOperators() == chain.getMaxNumberOfInnerOperators()) {
label = new JLabel("Inner Operators");
label.setToolTipText("Number of inner operators");
c.gridwidth = GridBagConstraints.RELATIVE;
layout.setConstraints(label, c);
mainPanel.add(label);
label = new JLabel(((OperatorChain)operator).getMinNumberOfInnerOperators() + "");
label.setToolTipText("Number of inner operators");
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(label, c);
mainPanel.add(label);
} else {
label = new JLabel("Min Inner");
label.setToolTipText("Minimum number of inner operators");
c.gridwidth = GridBagConstraints.RELATIVE;
layout.setConstraints(label, c);
mainPanel.add(label);
label = new JLabel(((OperatorChain)operator).getMinNumberOfInnerOperators() + "");
label.setToolTipText("Minimum number of inner operators");
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(label, c);
mainPanel.add(label);
label = new JLabel("Max Inner");
label.setToolTipText("Maximum number of inner operators");
c.gridwidth = GridBagConstraints.RELATIVE;
layout.setConstraints(label, c);
mainPanel.add(label);
int maxInner = ((OperatorChain)operator).getMaxNumberOfInnerOperators();
label = new JLabel(maxInner == Integer.MAX_VALUE ? "Max" : (maxInner + ""));
label.setToolTipText("Maximum number of inner operators");
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(label, c);
mainPanel.add(label);
}
}
JTextArea description = new JTextArea("",4,20);
description.setToolTipText("A short description of this operator");
description.setEditable(false);
description.setLineWrap(true);
description.setWrapStyleWord(true);
description.setBackground(this.getBackground());
description.setText(operator.getOperatorDescription().getDescription());
JScrollPane textScrollPane = new JScrollPane(description);
textScrollPane.setBorder(BorderFactory.createEmptyBorder(10,0,10,0));
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(textScrollPane, c);
mainPanel.add(textScrollPane);
List errorList = operator.getErrorList();
if (errorList.size() > 0) {
JEditorPane errors = new JEditorPane("text/html", "");
errors.setToolTipText("Errors of this operator");
errors.setEditable(false);
errors.setBackground(this.getBackground());
errors.setForeground(java.awt.Color.red);
String errorText = "<h3>Errors:</h3><ul>";
Iterator i = errorList.iterator();
while (i.hasNext()) {
errorText += "<li>" + (String)i.next() + "</li>";
}
errorText += "</ul>";
errors.setText(SwingTools.text2DisplayHtml(errorText));
JScrollPane errorsScrollPane = new JScrollPane(errors);
errorsScrollPane.setBorder(BorderFactory.createEmptyBorder(10,0,10,0));
c.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(errorsScrollPane, c);
mainPanel.add(errorsScrollPane);
}
userDescription = new JTextArea("",4,20);
userDescription.setToolTipText("User defined description of this operator");
userDescription.setEditable(true);
userDescription.setLineWrap(true);
userDescription.setWrapStyleWord(true);
userDescription.setText(SwingTools.text2SimpleHtml(operator.getUserDescription()));
JScrollPane userDescriptionScrollPane = new JScrollPane(userDescription);
userDescriptionScrollPane.setBorder(BorderFactory.createTitledBorder("User description"));
c.gridwidth = GridBagConstraints.REMAINDER;
c.weighty = 1.0d;
layout.setConstraints(userDescriptionScrollPane, c);
mainPanel.add(userDescriptionScrollPane);
rootPanel.add(mainPanel, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
JButton okButton = new JButton("Ok");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { ok(); }
});
buttonPanel.add(okButton);
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { cancel(); }
});
buttonPanel.add(cancelButton);
rootPanel.add(buttonPanel, BorderLayout.SOUTH);
getContentPane().add(rootPanel);
pack();
setLocationRelativeTo(owner);
}
public boolean isOk() { return ok; }
public String getUserDescription() { return SwingTools.html2YaleText(userDescription.getText()); }
private void ok() {
ok = true;
dispose();
}
private void cancel() {
ok = false;
dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -