📄 tool.java
字号:
/** * Method to set this Tool to fix errors. */ public void setFixErrors() { toolState |= TOOLFIX; } /** * Method to set this Tool to fix errors. */ public void clearFixErrors() { toolState &= ~TOOLFIX; } /** * Method to tell whether this Tool fixes errors. * @return true if this Tool fixes errors. */ public boolean isFixErrors() { return (toolState & TOOLFIX) != 0; } /** * Method to set this Tool to be incremental. */ public void setIncremental() { toolState |= TOOLINCREMENTAL; } /** * Method to set this Tool to be incremental. */ public void clearIncremental() { toolState &= ~TOOLINCREMENTAL; } /** * Method to tell whether this Tool is incremental. * @return true if this Tool is incremental. */ public boolean isIncremental() { return (toolState & TOOLINCREMENTAL) != 0; } /** * Method to set this Tool to be analysis. */ public void setAnalysis() { toolState |= TOOLANALYSIS; } /** * Method to set this Tool to be analysis. */ public void clearAnalysis() { toolState &= ~TOOLANALYSIS; } /** * Method to tell whether this Tool does analysis. * @return true if this Tool does analysis. */ public boolean isAnalysis() { return (toolState & TOOLANALYSIS) != 0; } /** * Method to set this Tool to be synthesis. */ public void setSynthesis() { toolState |= TOOLSYNTHESIS; } /** * Method to set this Tool to be synthesis. */ public void clearSynthesis() { toolState &= ~TOOLSYNTHESIS; } /** * Method to tell whether this Tool does synthesis. * @return true if this Tool does synthesis. */ public boolean isSynthesis() { return (toolState & TOOLSYNTHESIS) != 0; } public String getProjectSettings() { return toolName+"Tool."; } /** * Method to get a list of project Settings associatiated with this Tool * which should be written to disk libraries * @return a collection of project Settings */ public Collection<Setting> getDiskSettings() { ArrayList<Setting> settings = new ArrayList<Setting>(); for (Setting setting: settingsByXmlPath.values()) { if (!setting.isValidOption()) continue; if (setting.getValue().equals(setting.getFactoryValue())) continue; settings.add(setting); } Collections.sort(settings, Setting.SETTINGS_BY_PREF_NAME); return settings; } public Setting getSetting(String xmlPath) { return settingsByXmlPath.get(getProjectSettings() + xmlPath); } /** * Compares Tools by their definition order. * @param obj the other Tool. * @return a comparison between the Tools. */ public int compareTo(Object obj) { Tool that = (Tool)obj; return this.toolIndex - that.toolIndex; } /** * Returns a printable version of this Tool. * @return a printable version of this Tool. */ public String toString() { return "Tool '" + toolName + "'"; } /** * Subclasses override this method to create ProjectSettings by Tool.makeXXXSetting methods declared below. */ protected void initProjectSettings() {} /** * Factory methods to create a boolean project setting objects. * The created object is stored into a field of this Tool whose name is "cache"+name. * @param name the name of this Pref. * @param location the user-command that can affect this meaning option. * @param description the description of this meaning option. * @param factory the "factory" default value (if nothing is stored). */ protected void makeBooleanSetting(String name, String location, String description, boolean factory) { setCacheField(Setting.makeBooleanSetting(name, prefs, getProjectSettings(), null, location, description, factory)); } /** * Factory methods to create an integer project setting objects. * The created object is stored into a field of this Tool whose name is "cache"+name. * @param name the name of this Pref. * @param location the user-command that can affect this meaning option. * @param description the description of this meaning option. * @param factory the "factory" default value (if nothing is stored). */ protected void makeIntSetting(String name, String location, String description, int factory) { setCacheField(Setting.makeIntSetting(name, prefs, getProjectSettings(), null, location, description, factory)); } /** * Factory methods to create a long project setting objects. * The created object is stored into a field of this Tool whose name is "cache"+name. * @param name the name of this Pref. * @param location the user-command that can affect this meaning option. * @param description the description of this meaning option. * @param factory the "factory" default value (if nothing is stored). */ protected void makeLongSetting(String name, String location, String description, long factory) { setCacheField(Setting.makeLongSetting(name, prefs, getProjectSettings(), null, location, description, factory)); } /** * Factory methods to create a double project setting objects. * The created object is stored into a field of this Tool whose name is "cache"+name. * @param name the name of this Pref. * @param location the user-command that can affect this meaning option. * @param description the description of this meaning option. * @param factory the "factory" default value (if nothing is stored). */ protected void makeDoubleSetting(String name, String location, String description, double factory) { setCacheField(Setting.makeDoubleSetting(name, prefs, getProjectSettings(), null, location, description, factory)); } /** * Factory methods to create a string project setting objects. * The created object is stored into a field of this Tool whose name is "cache"+name. * @param name the name of this Pref. * @param location the user-command that can affect this meaning option. * @param description the description of this meaning option. * @param factory the "factory" default value (if nothing is stored). */ protected void makeStringSetting(String name, String location, String description, String factory) { setCacheField(Setting.makeStringSetting(name, prefs, getProjectSettings(), null, location, description, factory)); } /** * Method to store Setting variable in a cache field of this Tool. * The name of a field for Setting with name "SettingName" is "cacheSettingName". * @param setting Setting variable. */ private void setCacheField(Setting setting) { try { Field fld = getClass().getDeclaredField("cache" + setting.getPrefName()); fld.setAccessible(true); fld.set(this, setting); Setting oldSetting = settingsByXmlPath.put(setting.getXmlPath(), setting); assert oldSetting == null; } catch (Exception e) { e.printStackTrace(); } } /** * Method to set a variable on an ElectricObject in a new Job. * @param obj the ElectricObject on which to set the variable. * @param key the Variable key. * @param newVal the new value of the Variable. */ public void setVarInJob(ElectricObject obj, Variable.Key key, Object newVal) { new SetVarJob(this, obj, key, newVal); } /** * Class for scheduling a wiring task. */ private static class SetVarJob extends Job { ElectricObject obj; Variable.Key key; Object newVal; protected SetVarJob(Tool tool, ElectricObject obj, Variable.Key key, Object newVal) { super("Add Variable", tool, Job.Type.CHANGE, null, null, Job.Priority.USER); this.obj = obj; this.key = key; this.newVal = newVal; startJob(); } public boolean doIt() throws JobException { obj.newVar(key, newVal); return true; } } /** * The initialization method for this Tool. * Gets overridden by tools that want to do initialization. */ public void init() {} /*********************************** * Test interface ***********************************/ public static boolean testAll() { return true; // nothing to test }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -