📄 operatortreemodel.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.operator.Operator;import edu.udo.cs.yale.operator.OperatorChain;import java.util.List;import java.util.LinkedList;import java.util.Iterator;import javax.swing.tree.*;import javax.swing.event.*;/** A TreeModel hiding an operator (which itself already has a tree-like structure). * Most of the method calls delegate to an operator. Events can be fired when * operators are inserted or removed. */public class OperatorTreeModel implements TreeModel { private Operator root; private List treeModelListeners = new LinkedList(); public OperatorTreeModel(Operator root) { this.root = root; } public Object getRoot() { return root; } public Object getChild(Object parent, int index) { if (parent instanceof OperatorChain) { return ((OperatorChain)parent).getOperator(index); } else return null; } public int getChildCount(Object parent) { if (parent instanceof OperatorChain) { return ((OperatorChain)parent).getNumberOfOperators(); } else return 0; } public int getIndexOfChild(Object parent, Object child) { if (parent instanceof OperatorChain) { return ((OperatorChain)parent).getIndexOfOperator((Operator)child); } else return -1; } public boolean isLeaf(Object node) { return getChildCount(node) == 0; } public void valueForPathChanged(TreePath path, Object node) { Operator op = (Operator)path.getLastPathComponent(); op.rename(((String)node).trim()); YaleGUI.getMainFrame().experimentChanged(); } public void addTreeModelListener(TreeModelListener l) { treeModelListeners.add(l); } public void removeTreeModelListener(TreeModelListener l) { treeModelListeners.remove(l); } public void fireOperatorInserted(Object source, TreePath path, int index, Operator operator) { Iterator i = treeModelListeners.iterator(); while (i.hasNext()) { ((TreeModelListener)i.next()).treeNodesInserted(new TreeModelEvent(source, path, new int[] { index }, new Object[] { operator })); } } public void fireOperatorRemoved(Object source, TreePath path, int index, Operator operator) { Iterator i = treeModelListeners.iterator(); while (i.hasNext()) { ((TreeModelListener)i.next()).treeNodesRemoved(new TreeModelEvent(source, path, new int[] { index }, new Object[] { operator })); } } public void fireOperatorRenamed(Object source, TreePath path) { Iterator i = treeModelListeners.iterator(); while (i.hasNext()) { ((TreeModelListener)i.next()).treeNodesChanged(new TreeModelEvent(source, path)); } } public void fireOperatorChanged(Object source, TreePath path) { Iterator i = treeModelListeners.iterator(); while (i.hasNext()) { ((TreeModelListener)i.next()).treeNodesChanged(new TreeModelEvent(source, path)); } } public void fireStructureChanged(Object source, TreePath path) { Iterator i = treeModelListeners.iterator(); while (i.hasNext()) { ((TreeModelListener)i.next()).treeStructureChanged(new TreeModelEvent(source, path)); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -