📄 conditionalaction.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 java.util.List;
import java.util.LinkedList;
import java.util.Iterator;
import javax.swing.Icon;
import javax.swing.AbstractAction;
/** An action that must be enabled/disabled depending on certain conditions.
* These conditions can be mandatrory, disallowed, or irrelevant. All ConditionalActions created are
* added to a collection. */
public abstract class ConditionalAction extends AbstractAction {
private static final List ALL_ACTIONS = new LinkedList();
public static final int DISALLOWED = -1;
public static final int DONT_CARE = 0;
public static final int MANDATORY = 1;
public static final int OPERATOR_SELECTED = 0;
public static final int OPERATOR_CHAIN_SELECTED = 1;
public static final int ROOT_SELECTED = 2;
public static final int CLIPBOARD_FILLED = 3;
public static final int EXPERIMENT_RUNNING = 4;
public static final int NUMBER_OF_CONDITIONS = 5;
private int[] conditions = new int[NUMBER_OF_CONDITIONS];
public ConditionalAction(String name) {
this(name, null);
}
public ConditionalAction(String name, Icon icon) {
super(name, icon);
ALL_ACTIONS.add(this);
}
/** @param index one out of OPERATOR_SELECTED, OPERATOR_CHAIN_SELECTED, ROOT_SELECTED, CLIPBOARD_FILLED, and EXPERIMENT_RUNNING
* @param condition one out of DISALLOWED, DONT_CARE, and MANDATORY
*/
public void setCondition(int index, int condition) {
conditions[index] = condition;
}
/** Updates all actions. */
public static void updateAll(boolean[] states) {
Iterator i = ALL_ACTIONS.iterator();
while (i.hasNext()) {
((ConditionalAction)i.next()).update(states);
}
}
/** Updates an action given the set of states that can be true or false. States refer to OPERATOR_SELECTED...
* An action is enabled iff for all states the condition is DONT_CARE or MANDATORY and state is true or
* DISALLOWED and state is false. */
private void update(boolean[] state) {
boolean ok = true;
for (int i = 0; i < conditions.length;i++) {
if (conditions[i] != DONT_CARE) {
if (((conditions[i] == MANDATORY) && (state[i] == false)) ||
((conditions[i] == DISALLOWED) && (state[i] == true))) {
ok = false;
break;
}
}
}
setEnabled(ok);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -