📄 experimentrenderer.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.operator.ExperimentOperator;
import edu.udo.cs.yale.operator.SimpleOperatorChain;
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
/** A pure renderer that cannot (yet) edit the experiment. Can be used for printing. */
public class ExperimentRenderer extends JPanel implements ExperimentEditor {
private Operator operator;
private static OperatorRenderer leafRenderer = new LeafRenderer();
private static OperatorRenderer chainRenderer = new SimpleChainRenderer();
private static OperatorRenderer wrapperRenderer = new WrapperRenderer();
public ExperimentRenderer() {
}
public void experimentChanged(Operator operator) {
setOperator(operator);
}
public void setOperator(Operator operator) {
this.operator = operator;
repaint();
}
public void paint(Graphics g) {
if (operator == null) {
return;
}
g.clearRect(0,0,getWidth(), getHeight());
Graphics2D g2d = (Graphics2D)g;
Dimension size = getRenderer(operator).getSize(operator, g2d);
Dimension dimension = new Dimension((int)size.getWidth()+20, (int)size.getHeight()+20);
setMinimumSize(dimension);
setPreferredSize(dimension);
//setMaximumSize(dimension);
g2d.translate(getWidth()/2 - size.getWidth()/2,10);
getRenderer(operator).drawOperator(operator, g2d);
}
public void print(Graphics g) {
if (operator == null) {
return;
}
Graphics2D g2d = (Graphics2D)g;
getRenderer(operator).drawOperator(operator, g2d);
}
public static OperatorRenderer getRenderer(Operator op) {
if (op instanceof OperatorChain) {
if ((op instanceof SimpleOperatorChain) ||
(op instanceof ExperimentOperator))
return chainRenderer;
else
return wrapperRenderer;
}
else return leafRenderer;
}
public Component getMainComponent() {
return this;
}
public void validateExperiment() {}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -