📄 operatorinfoscreen.java
字号:
/* * YALE - Yet Another Learning Environment * Copyright (C) 2002 * 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.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 { 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; 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", ""); //("",4,20); errors.setToolTipText("Errors of this operator"); errors.setEditable(false); errors.setBackground(this.getBackground()); errors.setForeground(java.awt.Color.red); String errorText = "<html><h3>Errors:</h3><ul>"; Iterator i = errorList.iterator(); while (i.hasNext()) { errorText += "<li><font size=\"-1\">" + (String)i.next() + "</font></li>"; } errorText += "</html></ul>"; errors.setText(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); } 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); rootPanel.add(buttonPanel, BorderLayout.SOUTH); getContentPane().add(rootPanel); pack(); setLocationRelativeTo(owner); } private void ok() { dispose(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -