tiledconfiguration.java

来自「tiled地图编辑器是2d的,很不错的国外软件,使用起来很方便的」· Java 代码 · 共 108 行

JAVA
108
字号
/* *  Tiled Map Editor, (c) 2004-2006 * *  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. * *  Adam Turk <aturk@biggeruniverse.com> *  Bjorn Lindeijer <b.lindeijer@xs4all.nl> */package tiled.util;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.prefs.Preferences;/** * This class provides access to nodes in the user tiled preferences tree. In * addition it provides a number of related convenience methods. * * @version $Id: TiledConfiguration.java 683 2006-06-25 14:17:37Z bjorn $ */public final class TiledConfiguration{    public static final int RECENT_FILE_COUNT = 8;    private static final Preferences prefs = Preferences.userRoot().node("tiled");    // Prevent instanciation    private TiledConfiguration() {    }    /**     * Returns the node with the given path name relative from the root of     * Tiled configuration.     *     * @param pathName the path name relative from the root     * @return the requested preferences node     */    public static Preferences node(String pathName) {        return prefs.node(pathName);    }    /**     * Returns the root node for Tiled configuration.     *     * @return the root node for Tiled configuration     */    public static Preferences root() {        return prefs;    }    /**     * Adds the given filename to the top of the recent file list. It also     * makes sure it does not occur further down the list.     *     * @param mapFile the absolute path of the file to add, must not be     *                <code>null</code>     */    public static void addToRecentFiles(String mapFile) {        assert (mapFile != null);        // Get the existing recent file list        List recent = getRecentFiles();        // Remove all existing occurences of the file        Iterator iterator = recent.iterator();        while (iterator.hasNext()) {            String filename = (String) iterator.next();            if (filename.equals(mapFile)) {                iterator.remove();            }        }        // Add the given map file to the top        recent.add(0, mapFile);        // Store the new recent file listing        Preferences recentNode = prefs.node("recent");        for (int i = 0; i < RECENT_FILE_COUNT && i < recent.size(); i++)        {            String recentFile = (String) recent.get(i);            recentNode.put("file" + i, recentFile);        }    }    /**     * Returns the list of recently used files.     *     * @return the list of recently used files     */    public static List getRecentFiles() {        List recent = new ArrayList(RECENT_FILE_COUNT);        Preferences recentNode = prefs.node("recent");        for (int i = 0; i < RECENT_FILE_COUNT; i++)        {            String recentFile = recentNode.get("file" + i, "");            if (recentFile.length() > 0) {                recent.add(recentFile);            }        }        return recent;    }}

⌨️ 快捷键说明

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