📄 operatortreecellrenderer.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.IllegalInputException;
import edu.udo.cs.yale.operator.IllegalNumberOfInnerOperatorsException;
import edu.udo.cs.yale.tools.OperatorDescription;
import edu.udo.cs.yale.tools.Tools;
import java.awt.Component;
import java.awt.Image;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.FlowLayout;
import javax.swing.*;
import javax.swing.tree.TreeCellRenderer;
import java.io.File;
import java.util.List;
/** A renderer for operator tree cells that displays the operator's icon, name, class, breakpoints and error
* hints.
* @version $Id: OperatorTreeCellRenderer.java,v 2.7 2004/08/27 11:57:33 ingomierswa Exp $
*/
public class OperatorTreeCellRenderer extends JPanel implements TreeCellRenderer {
private static final Color SELECTED_COLOR = UIManager.getColor("Tree.selectionBackground");
private static final Color NON_SELECTED_COLOR = UIManager.getColor("Tree.textBackground");
private static final Color TEXT_SELECTED_COLOR = UIManager.getColor("Tree.selectionForeground");
private static final Color TEXT_NON_SELECTED_COLOR = UIManager.getColor("Tree.textForeground");
private static final Color BORDER_SELECTED_COLOR = UIManager.getColor("Tree.selectionBorderColor");
private boolean hasFocus, isSelected;
private JLabel mainLabel = new JLabel();
private JLabel breakpoint = new JLabel();
private JLabel error = new JLabel();
public OperatorTreeCellRenderer() {
mainLabel.setHorizontalAlignment(JLabel.LEFT);
mainLabel.setFont(getFont().deriveFont(Font.PLAIN));
mainLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4));
setLayout(new FlowLayout(FlowLayout.LEFT));
setBackground(new java.awt.Color(0, 0, 0, 0));
//breakpoint.setToolTipText("Indicates if a breakpoint is used");
add(mainLabel);
add(breakpoint);
add(error);
}
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
this.isSelected = selected;
this.hasFocus = hasFocus;
if (selected) {
mainLabel.setForeground(TEXT_SELECTED_COLOR);
} else {
mainLabel.setForeground(TEXT_NON_SELECTED_COLOR);
}
if (value instanceof Operator) {
Operator operator = (Operator)value;
Image img = operator.getOperatorDescription().getIcon();
if (img != null) mainLabel.setIcon(new ImageIcon(img));
else mainLabel.setIcon(null);
OperatorDescription descr = operator.getOperatorDescription();
mainLabel.setText("<html>"+operator.getName() + "<br><font size=-2>" + descr.getName()+"</font></html>");
mainLabel.setEnabled(operator.isEnabled());
if (!operator.isEnabled()) mainLabel.setForeground(Color.gray);
// ICONS
if ((operator.hasBreakpoint(Operator.BREAKPOINT_BEFORE)) || (operator.hasBreakpoint(Operator.BREAKPOINT_AFTER))) {
breakpoint.setIcon(new ImageIcon(Tools.getResource("icons/icon_stop2.gif")));
} else {
breakpoint.setIcon(null);
}
breakpoint.setEnabled(operator.isEnabled());
List errors = operator.getErrorList();
if (errors.size() > 0) {
error.setIcon(new ImageIcon(Tools.getResource("icons/icon_error.gif")));
setToolTipText("Error: " + (String)errors.get(0));
} else {
error.setIcon(null);
setToolTipText(descr.getDescription());
}
error.setEnabled(operator.isEnabled());
setEnabled(operator.isEnabled());
} else {
mainLabel.setIcon(null);
mainLabel.setText(value.toString());
setEnabled(tree.isEnabled());
}
//setEnabled(tree.isEnabled());
return this;
}
public void paint(Graphics g) {
if (isSelected) {
g.setColor(SELECTED_COLOR);
g.fillRect(0, 0, getWidth(), getHeight());
}
if (hasFocus) {
g.setColor(BORDER_SELECTED_COLOR);
g.drawRect(0, 0, getWidth()-1, getHeight()-1);
}
super.paint(g);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -