⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pref.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * Factory methods to create an integer Pref objects.	 * The proper way to create an integer Pref is with makeIntPref;	 * use of this method is only for subclasses.	 * @param factory the "factory" default value (if nothing is stored).	 */	protected void initInt(int factory)	{		type = PrefType.INTEGER;		factoryObj = new Integer(factory);		cachedObj = new Integer(group.getInt(name, factory));	}	/**	 * Factory methods to create an integer Pref objects.	 * @param name the name of this Pref.	 * @param group group of preferences to which a new Pref belongs	 * @param factory the "factory" default value (if nothing is stored).	 */	public static Pref makeIntPref(String name, Group group, int factory) {		Pref pref = new Pref(group, name);		pref.initInt(factory);		return pref;	}	/**	 * Factory methods to create a long Pref objects.	 * The proper way to create a long Pref is with makeLongPref;	 * use of this method is only for subclasses.	 * @param factory the "factory" default value (if nothing is stored).	 */	protected void initLong(long factory)	{		type = PrefType.LONG;		factoryObj = new Long(factory);		cachedObj = new Long(group.getLong(name, factory));	}	/**	 * Factory methods to create a long Pref objects.	 * @param name the name of this Pref.	 * @param group group of preferences to which a new Pref belongs	 * @param factory the "factory" default value (if nothing is stored).	 */	public static Pref makeLongPref(String name, Group group, long factory) {		Pref pref = new Pref(group, name);		pref.initLong(factory);		return pref;	}	/**	 * Factory methods to create a double Pref objects.	 * The proper way to create a double Pref is with makeDoublePref;	 * use of this method is only for subclasses.	 * @param factory the "factory" default value (if nothing is stored).	 */	protected void initDouble(double factory)	{		type = PrefType.DOUBLE;		factoryObj = new Double(factory);		cachedObj = new Double(group.getDouble(name, factory));	}	/**	 * Factory methods to create a double Pref objects.	 * @param name the name of this Pref.	 * @param group group of preferences to which a new Pref belongs	 * @param factory the "factory" default value (if nothing is stored).	 */	public static Pref makeDoublePref(String name, Group group, double factory) {		Pref pref = new Pref(group, name);		pref.initDouble(factory);		return pref;	}	/**	 * Factory methods to create a string Pref objects.	 * The proper way to create a string Pref is with makeStringPref;	 * use of this method is only for subclasses.	 * @param factory the "factory" default value (if nothing is stored).	 */	protected void initString(String factory)	{		type = PrefType.STRING;		factoryObj = new String(factory);		cachedObj = new String(group.get(name, factory));	}	/**	 * Factory methods to create a string Pref objects.	 * @param name the name of this Pref.	 * @param group group of preferences to which a new Pref belongs	 * @param factory the "factory" default value (if nothing is stored).	 */	public static Pref makeStringPref(String name, Group group, String factory) {		Pref pref = new Pref(group, name);		pref.initString(factory);		return pref;	}    /**	 * Method to get the boolean value on this Pref object.	 * The object must have been created as "boolean".	 * @return the boolean value on this Pref object.	 */	public boolean getBoolean() { return ((Integer)cachedObj).intValue() != 0; }	/**	 * Method to get the integer value on this Pref object.	 * The object must have been created as "integer".	 * @return the integer value on this Pref object.	 */	public int getInt() { return ((Integer)cachedObj).intValue(); }	/**	 * Method to get the long value on this Pref object.	 * The object must have been created as "long".	 * @return the long value on this Pref object.	 */	public long getLong() { return ((Long)cachedObj).longValue(); }	/**	 * Method to get the double value on this Pref object.	 * The object must have been created as "double".	 * @return the double value on this Pref object.	 */	public double getDouble() { return ((Double)cachedObj).doubleValue(); }	/**	 * Method to get the string value on this Pref object.	 * The object must have been created as "string".	 * @return the string value on this Pref object.	 */	public String getString() { return (String)cachedObj; }	/**	 * Method to get the factory-default value of this Pref object.	 * @return the factory-default value of this Pref object.	 */	public Object getFactoryValue() { return factoryObj; }	/**	 * Method to get the factory-default boolean value of this Pref object.	 * @return the factory-default boolean value of this Pref object.	 */	public boolean getBooleanFactoryValue() { return ((Integer)factoryObj).intValue() != 0 ? true : false; }	/**	 * Method to get the factory-default integer value of this Pref object.	 * @return the factory-default integer value of this Pref object.	 */	public int getIntFactoryValue() { return ((Integer)factoryObj).intValue(); }	/**	 * Method to get the factory-default long value of this Pref object.	 * @return the factory-default long value of this Pref object.	 */	public long getLongFactoryValue() { return ((Long)factoryObj).longValue(); }	/**	 * Method to get the factory-default double value of this Pref object.	 * @return the factory-default double value of this Pref object.	 */	public double getDoubleFactoryValue() { return ((Double)factoryObj).doubleValue(); }	/**	 * Method to get the factory-default String value of this Pref object.	 * @return the factory-default String value of this Pref object.	 */	public String getStringFactoryValue() { return (String)factoryObj; }	/**	 * Method to get the name of this Pref object.	 * @return the name of this Pref object.	 */	public String getPrefName() { return name; }	/**	 * Method to get the value of this Pref object as an Object.	 * The proper way to get the current value is to use one of the type-specific	 * methods such as getInt(), getBoolean(), etc.	 * @return the Object value of this Pref object.	 */	public Object getValue() { return cachedObj; }	/**	 * Method to get the type of this Pref object.	 * @return an integer type: either BOOLEAN, INTEGER, LONG, DOUBLE, or STRING.	 */	public PrefType getType() { return type; }	public static class PrefChangeBatch implements Serializable	{        private HashMap<String,HashMap<String,Object>> changesForNodes = new HashMap<String,HashMap<String,Object>>();        private void add(Pref pref, Object newValue) {            String nodeName = pref.group.absolutePath();            HashMap<String,Object> changesForTheNode = changesForNodes.get(nodeName);            if (changesForTheNode == null) {                changesForTheNode = new HashMap<String,Object>();                changesForNodes.put(nodeName, changesForTheNode);            }            changesForTheNode.put(pref.name, newValue);        }	}	/**	 * Method to start accumulation of Pref changes.	 * All changes to preferences after this call are gathered,	 * and not actually implemented.	 * Call "getPrefChanges()" to get the gathered changes, and call	 * "implementPrefChanges()" to actually make the changes.	 */	public static void gatherPrefChanges()	{	}	/**	 * Method to get the accumulated Pref changes.	 * In order to make preference 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 client and gets a serializable	 * object that can be sent to the server.	 * @return a collection of changes to preferences that have	 * been made since the call to "gatherPrefChanges()".	 * Call "implementPrefChanges()" with the returned collection	 * to actually make the changes.	 */	public static PrefChangeBatch getPrefChanges()	{		return null;	}	/**	 * Method to make a collection of preference changes.	 * In order to make preference 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 obj the collection of preference changes.	 */	public static void implementPrefChanges(PrefChangeBatch obj)	{	}    /**	 * Method to delay the saving of preferences to disk.	 * Since individual saving is time-consuming, batches of preference	 * changes are wrapped with this, and "resumePrefFlushing()".	 */	public static void delayPrefFlushing()	{		doFlushing = false;		queueForFlushing = new HashSet<Preferences>();	}	/**	 * Method to resume the saving of preferences to disk.	 * Since individual saving is time-consuming, batches of preference	 * changes are wrapped with this, and "resumePrefFlushing()".	 * Besides resuming saving, this method also saves anything queued	 * while saving was delayed.	 */	public static void resumePrefFlushing()	{		doFlushing = true;		for(Preferences p : queueForFlushing)			flushOptions(p);	}	/**	 * Method to set a new boolean value on this Pref object.	 * @param v the new boolean value of this Pref object.	 */	public void setBoolean(boolean v)	{        checkModify();		boolean cachedBool = ((Integer)cachedObj).intValue() != 0 ? true : false;		if (v != cachedBool)		{			cachedObj = new Integer(v ? 1 : 0);            group.putBoolean(name, v);		}	}	/**	 * Method to set a new integer value on this Pref object.	 * @param v the new integer value of this Pref object.	 */	public void setInt(int v)	{        checkModify();		int cachedInt = ((Integer)cachedObj).intValue();		if (v != cachedInt)		{			cachedObj = new Integer(v);            group.putInt(name, v);		}	}	/**	 * Method to set a new long value on this Pref object.	 * @param v the new long value of this Pref object.	 */	public void setLong(long v)	{        checkModify();		long cachedLong = ((Long)cachedObj).longValue();		if (v != cachedLong)		{			cachedObj = new Long(v);            group.putLong(name, v);		}	}    /**	 * Method to set a new double value on this Pref object.	 * @param v the new double value of this Pref object.	 */	public void setDouble(double v)	{        checkModify();		double cachedDouble = ((Double)cachedObj).doubleValue();//		boolean changed = false;		if (v != cachedDouble)		{			cachedObj = new Double(v);            group.putDouble(name, v);//			changed = true;		}//		return (changed);	}	/**	 * Method to set a new string value on this Pref object.	 * @param str the new string value of this Pref object.	 */	public void setString(String str)	{        checkModify();		String cachedString = (String)cachedObj;		if (!str.equals(cachedString))		{			cachedObj = new String(str);            group.put(name, str);		}	}    private void checkModify() {//        if (Job.getDebug() && Job.getRunningJob() != null)//            System.out.println(getPrefName() + " is modified in " + Job.getRunningJob());    }    private static int numStrings;    private static int lenStrings;    private static int numValueStrings = 0;    private static int lenValueStrings = 0;    public static void printAllPrefs(PrintStream out, TechPool techPool) {        numValueStrings = lenValueStrings = 0;        TreeMap<String,Pref> sortedPrefs = new TreeMap<String,Pref>();        synchronized (allGroups) {            for (Group group: allGroups) {                for (Pref pref: group.prefs)                    sortedPrefs.put(pref.group.absolutePath() + "/" + pref.name, pref);            }        }        Preferences rootNode = Preferences.userRoot().node("com/sun/electric");        numStrings = lenStrings = 0;        try {            gatherPrefs(out, 0, rootNode, null);        } catch (BackingStoreException e) {            e.printStackTrace();        }        out.println(lenStrings + " chars in " + numStrings + " strings");        out.println(lenValueStrings + " chars in " + numValueStrings + " value strings");        Setting.printAllSettings(out);        out.println("ELECTRIC USER PREFERENCES");        int  i = 0;        for (Pref pref: sortedPrefs.values())            out.println((i++) + pref.group.absolutePath() + " " + pref.name + " " + pref.cachedObj);        for (Technology tech: techPool.values()) {            i = 0;            for (Pref.Group group: tech.getTechnologyAllPreferences()) {                for (Pref pref: group.prefs)                    out.println((i++) + pref.group.absolutePath() + " " + tech + " " + pref.name + " " + pref.cachedObj);            }        }    }    private static void gatherPrefs(PrintStream out, int level, Preferences topNode, List<String> ks) throws BackingStoreException {        for (int i = 0; i < level; i++) out.print("  ");        String[] keys = topNode.keys();        for (int i = 0; i < keys.length; i++) {            numStrings++;            lenStrings += keys.length;            String value = topNode.get(keys[i], null);            numValueStrings++;            lenValueStrings += value.length();        }        out.println(topNode.name() + " " + keys.length);        if (topNode.absolutePath().equals("/com/sun/electric/database/hierarchy")) return;        String[] children = topNode.childrenNames();        for (int i = 0; i < children.length; i++) {            String childName = children[i];            numStrings++;            lenStrings += children[i].length();            Preferences childNode = topNode.node(childName);            gatherPrefs(out, level + 1, childNode, ks);        }    }    /****************************** private methods ******************************/	/**	 * Method to force all Preferences to be saved.	 */	private static void flushOptions(Preferences p)	{		try		{			p.flush();		} catch (Exception e)		{            if (!Job.BATCHMODE) {			    System.out.println("Failed to save preferences");            }		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -