📄 setting.java
字号:
Setting setting = Setting.getSetting(xmlNode + xmlName); if (setting != null) return setting; return new Setting(name, group, xmlNode, xmlName, location, description, Integer.valueOf(factory)); } /** * Factory methods to create a long project setting objects. * @param name the name of this Pref. * @param group group of preferences to which a new Pref belongs * @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). */ public static Setting makeLongSetting(String name, Pref.Group group, String xmlNode, String xmlName, String location, String description, long factory) { Setting setting = Setting.getSetting(xmlNode + xmlName); if (setting != null) return setting; return new Setting(name, group, xmlNode, xmlName, location, description, Long.valueOf(factory)); } /** * Factory methods to create a double project setting objects. * @param name the name of this Pref. * @param group group of preferences to which a new Pref belongs * @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). */ public static Setting makeDoubleSetting(String name, Pref.Group group, String xmlNode, String xmlName, String location, String description, double factory) { Setting setting = Setting.getSetting(xmlNode + xmlName); if (setting != null) return setting; return new Setting(name, group, xmlNode, xmlName, location, description, Double.valueOf(factory)); } /** * Factory methods to create a string project setting objects. * @param name the name of this Pref. * @param group group of preferences to which a new Pref belongs * @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). */ public static Setting makeStringSetting(String name, Pref.Group group, String xmlNode, String xmlName, String location, String description, String factory) { Setting setting = Setting.getSetting(xmlNode + xmlName); if (setting != null) return setting; return new Setting(name, group, xmlNode, xmlName, location, description, factory); } /** * Method to find the project Setting object by its xml path. * @param xmlPath the xml path of the desired project Setting object. * @return the project Setting object. */ public static Setting getSetting(String xmlPath) { return allSettingsByXmlPath.get(xmlPath); } /** * Method to find the project Setting object by its pref path. * @param prefPath the pref path of the desired project Setting object. * @return the project Setting object. */ public static Setting getSettingByPrefPath(String prefPath) { return allSettingsByPrefPath.get(prefPath); } public static Comparator<Setting> SETTINGS_BY_PREF_NAME = new Comparator<Setting> () { public int compare(Setting s1, Setting s2) { String n1 = s1.getPrefName(); String n2 = s2.getPrefName(); return n1.compareTo(n2); } };// /**// * Comparator class for sorting Preferences by their name.// */// private static final Comparator<Setting> SettingsByName = new Comparator<Setting>() {// /**// * Method to sort Setting by their prefName.// */// public int compare(Setting setting1, Setting setting2) {// String s1 = setting1.getPrefName();// String s2 = setting2.getPrefName();// return s1.compareToIgnoreCase(s2);// }// }; /** * Method to adjust project that were saved with a library. * Presents the user with a dialog to help reconcile the difference * between project settings stored in a library and the original values. */ public static Map<Setting,Object> reconcileSettings(Map<Setting,Object> projectSettings) { HashSet<Setting> markedSettings = new HashSet<Setting>(); Map<Setting,Object> settingsToReconcile = new HashMap<Setting,Object>(); for (Map.Entry<Setting,Object> e: projectSettings.entrySet()) { Setting setting = e.getKey(); Object value = e.getValue(); markedSettings.add(setting); if (DBMath.objectsReallyEqual(value, setting.getValue())) continue; if (!setting.isValidOption()) continue; settingsToReconcile.put(setting, value); } for (Setting setting: allSettingsByXmlPath.values()) { if (markedSettings.contains(setting)) continue; // this one is not mentioned in the library: make sure it is at factory defaults if (DBMath.objectsReallyEqual(setting.getValue(), setting.getFactoryValue())) continue; if (!setting.isValidOption()) continue; settingsToReconcile.put(setting, null); } return settingsToReconcile; } /** * This method is called after reconciling project settings with OptionReconcile dialog or in a batch mode */ public static void finishSettingReconcilation(Map<Setting,Object> settingsToReconcile) { // delay flushing of preferences until all chanages are made Pref.delayPrefFlushing(); for (Map.Entry<Setting,Object> e: settingsToReconcile.entrySet()) { Setting setting = e.getKey(); Object obj = e.getValue(); if (obj == null) obj = setting.factoryObj; // set the option if (obj.getClass() != setting.factoryObj.getClass()) { if (obj instanceof Integer && setting.factoryObj instanceof Boolean) obj = Boolean.valueOf(((Integer)obj).intValue() != 0); else if (obj instanceof Float && setting.factoryObj instanceof Double) obj = Double.valueOf(((Float)obj).doubleValue()); else continue; } setting.set(obj); System.out.println("Project Setting "+setting.xmlPath+" changed to "+obj); } // resume flushing, and save everything just set Pref.resumePrefFlushing(); } static void saveAllSettingsToPreferences() { for (Setting setting: allSettingsByXmlPath.values()) { Object value = setting.getValue(); setting.saveToPreferences(value); } } private void saveToPreferences(Object v) { assert v.getClass() == factoryObj.getClass(); if (v.equals(factoryObj)) { prefs.remove(prefName); return; } if (v instanceof Boolean) prefs.putBoolean(prefName, ((Boolean)v).booleanValue()); else if (v instanceof Integer) prefs.putInt(prefName, ((Integer)v).intValue()); else if (v instanceof Long) prefs.putLong(prefName, ((Long)v).longValue()); else if (v instanceof Double) prefs.putDouble(prefName, ((Double)v).doubleValue()); else if (v instanceof String) prefs.put(prefName, (String)v); else { assert false; } } private void setCachedObjFromPreferences() { Object cachedObj = null; if (factoryObj instanceof Boolean) { cachedObj = Boolean.valueOf(prefs.getBoolean(prefName, ((Boolean)factoryObj).booleanValue())); } else if (factoryObj instanceof Integer) { cachedObj = Integer.valueOf(prefs.getInt(prefName, ((Integer)factoryObj).intValue())); } else if (factoryObj instanceof Long) { cachedObj = Long.valueOf(prefs.getLong(prefName, ((Long)factoryObj).longValue())); } else if (factoryObj instanceof Double) { cachedObj = Double.valueOf(prefs.getDouble(prefName, ((Double)factoryObj).doubleValue())); } else if (factoryObj instanceof String) { cachedObj = prefs.get(prefName, (String)factoryObj); } assert cachedObj != null; this.currentObj = cachedObj; } public static class SettingChangeBatch implements Serializable { public HashMap<String,Object> changesForSettings = new HashMap<String,Object>(); public void add(Setting setting, Object newValue) { changesForSettings.put(setting.xmlPath, newValue); } } /** * Method to make a collection of project settings changes. * In order to make project settings changes on the server, * it is necessary to gather them on the client, and send * the changes to the server for actual change. * This method runs on the server. * @param batch the collection of project setting changes. */ public static void implementSettingChanges(SettingChangeBatch batch) { for (Map.Entry<String,Object> e: batch.changesForSettings.entrySet()) { String xmlPath = e.getKey(); Object newValue = e.getValue(); Setting setting = getSetting(xmlPath); setting.set(newValue); } }// public static List<Object> getContext() { return new ArrayList<Object>(values); } public static Map<Setting,Object> resetContext() { HashMap<Setting,Object> savedContext = new HashMap<Setting,Object>(); for (Setting setting: allSettingsByXmlPath.values()) { savedContext.put(setting, setting.getValue()); setting.set(setting.getFactoryValue()); } return savedContext; } public static void restoreContext(Map<Setting,Object> savedContext) { for (Map.Entry<Setting,Object> e: savedContext.entrySet()) { Setting setting = e.getKey(); setting.set(e.getValue()); } } public static Collection<Setting> getSettings() { return allSettingsByXmlPath.values(); } static void printAllSettings(PrintStream out) { TreeMap<String,Setting> sortedSettings = new TreeMap<String,Setting>(); for (Setting setting: allSettingsByXmlPath.values()) sortedSettings.put(setting.xmlPath, setting); out.println("PROJECT SETTINGS"); int i = 0; for (Setting setting: sortedSettings.values()) out.println((i++) + "\t" + setting.xmlPath + " " + setting.getValue());// printSettings(out, ProjSettings.getSettings(), 0); }// private static int i;//// private static void printSettings(PrintStream out, ProjSettingsNode node, int level) {// Set<String> keys = node.getKeys();// for (String key: keys) {// out.print((i++) + "\t");// for (int i = 0; i < level; i++) out.print(" ");// out.print(key);// ProjSettingsNode subNode = node.getNode(key);// if (subNode != null) {// out.println(".");// printSettings(out, subNode, level + 1);// continue;// }// Setting setting = node.getValue(key);// out.println(" " + setting.prefName + " " + setting.getValue());// }// }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -