站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

Editor Settings Storage - NetBeans Architecture Questions - NetBeans API Javadoc (Current Development Version)

NetBeans Architecture Answers for Editor Settings Storage module


Interfaces table

Group of java interfaces
Interface NameIn/OutStabilitySpecified in What Document?
org.netbeans.modules.editor.settingsImportedPrivate

Editor Settings API

EditorSettingsStorageAPIExportedFriend
SpecialProfilesAndMimeTypesAPIExportedFriend
MimeLookupAPIImportedOfficial .../overview-summary.html

The module is needed for compilation. The module is used during runtime. Specification version 1.0 is required.

EditorSettingsAPIImportedOfficial .../overview-summary.html

The module is needed for compilation. The module is used during runtime. Specification version 1.9 is required.

FilesystemsAPIImportedOfficial .../overview-summary.html

The module is needed for compilation. The module is used during runtime. Specification version 6.2 is required.

UtilitiesAPIImportedOfficial../org-openide-util/overview-summary.html

The module is needed for compilation. The module is used during runtime. Specification version 6.2 is required.

Group of dtd interfaces
Interface NameIn/OutStabilitySpecified in What Document?
EditorFontsColors-1_1.dtdExportedOfficial .../dtds/EditorFontsColors-1_1.dtd

-//NetBeans//DTD Editor Fonts and Colors settings 1.1//EN

EditorKeyBindings-1_1.dtdExportedOfficial .../dtds/EditorKeyBindings-1_1.dtd

-//NetBeans//DTD Editor KeyBindings settings 1.1//EN


General Information

    Question (arch-what): What is this project good for?

    Answer: The module is an implementation of the org.netbeans.modules.editor.settings - Editor Settings API providing a settings storage on the default filesystem.

    Question (arch-overall): Describe the overall architecture.

    Answer:

    The editor/settings/storage module provides friend EditorSettingsStorageAPI comprising classes in the org.netbeans.modules.editor.settings.storage.api package. It also defines the structure of the settings storage and the structure of XML files with settings. The following XML files are supported.

    • Fonts & Colors - contains colorings that define various attributes for rendering text tokens in the editor.
      EditorFontsColors-1_1.dtd - -//NetBeans//DTD Editor Fonts and Colors settings 1.1//EN
    • Key Bindings - contains definitions of keyboard shortcust and their associated editor actions.
      EditorKeyBindings-1_1.dtd - -//NetBeans//DTD Editor KeyBindings settings 1.1//EN

    Profiles and setting folders

    The setting files are stored in MimeLookup in the folders hierarchy under the Editors/ folder on the default filesystem. The storage follows the main principle of MimeLookup and allows to define mime type specific settings as well as settings that apply for all editors. This is achieved by placing the setting files in the appropriate folder (i.e. in the mime type folder such as Editors/<mime-type> or in the Editors/ folder itself for the global settings).

    No matter whether the files are stored in Editors/ or in a mime type specific folder their further position relative to that folder and their meaning is the same.

    Both font & colors and key bindings are grouped in so called profiles that allow user switching quickly between predefined sets of colorings or key bindings. An example of profiles can be key bindings for NetBeans, Eclipse and Emacs. Each of those profiles defines keyboard shortcuts for IDE actions that are known from other products. Another example is the profiles defining normal and inverse color schemes. In Netbeans they are called NetBeans and CityLights.

    The editor/settings/storage module dedicates a special folder for each profile and stores all the profile related files in that folder.

    Special profiles and mime types

    The module provides a special treatment for profiles with names starting with the "test" string. These profiles are handled as a temporary in-memory profiles, which are not persisted to the disk. They are mainly used for 'preview' purposes in the Options dialog.

    The module also recognizes special mime paths, which String representation starts with the "test*_" string (e.g. "test123ed_text/x-java") and provides MimeLookup for those mime paths. The contents of MimeLookup for those special mime paths is basically the same as MimeLookup for the mime path without the leading test*_ string, but it contains FontColorsSettings and KeyBindingSettings instances specially constructed for the 'test' mime type. Again this is mainly used for 'preview' purposes by the Options dialog.

    Since this functionality is defacto an API it is being tracked as SpecialProfilesAndMimeTypesAPI.

    User changes and defaults

    The editor settings storage is organized in the way that allows storing user changes separately from the default values provided by modules. This is useful when a users wants to reset their profiles back to the original values shipped with the product. This is achieved by defining a special subfolder called Defaults for every profile. The default colorings and key bindings provided by modules are then registered in this Defaults subfolder while user changes are stored directly in the profile's folder. When restoring the original values the files with user changes are simply deleted and the profile is reloaded from the default files.

    Font & color files

    Since version 1.10 the storage module does not require coloring files to be called any special name. The coloring profiles and files are expected to be registered by modules under a special folder called FontsColors. The structure below shows an example of registering several different coloring files for all editors and the text/x-java mime type.

        Editors
         |- FontsColors
         |   |- NetBeans
         |       |- Defaults
         |           |- foo.xml
         |           |- bar.xml
         |- text
             |- x-java
                 |- FontsColors
                     |- NetBeans
                         |- Defaults
                             |- xyz.xml
                             |- abc.xml
    

    In order to distinguish files containing token-related colorings from those with highlight-related colorings the storage module recognizes a special file attribute called nbeditor-settings-ColoringType, which value can either be token or highlight. If a coloring file does not specify this attribute it is automatically expected to contain token-related colorings.

    Generally, the files with default values are stored in Defaults subfolders while the files with user changes are stored directly in the profile's folder.

    The default profile for font & colors is called 'NetBeans'.

    Prior to version 1.10 the storage module expected colorings in the three different types of files. They are still recognized to support backwards compatibility, but modules are suggusted to use the new registration scheme. All of those three files had the same structure, but different purpose.

    • coloring.xml - defines colorings used for rendering tokens from a particular language (i.e. mime type).
    • defaultColoring.xml - defines language neutral colorings, which can be used as fallback for language specific colorings. This file can only be specified in the Editors/<profile-name>/Defaults folders. If specified in a mime type subfolder it will be ignored.
    • editorColoring.xml - defines colorings that do not apply for tokens. These colorings define for example the color for highlighting the row with a caret, etc. They are not mime type specific and can only be specified in the Editors/<profile-name>/Defaults folders. If specified in a mime type subfolder it will be ignored.

    Key bindings files

    Since version 1.10 modules can provide their keybindings in multiple files placed under the special folder called Keybindings and its profiles' subfolders. Similarily as for colorings the files with default key bindings are stored in Defaults subfolder and user changes are stored in files directly in the profile's folder. The example below shows registration of several keybinding files for all editors and the text/x-java mime type.

        Editors
         |- Keybindings
         |   |- NetBeans
         |       |- Defaults
         |           |- foo.xml
         |           |- bar.xml
         |- text
             |- x-java
                 |- Keybindings
                     |- NetBeans
                         |- Defaults
                             |- xyz.xml
                             |- abc.xml
    

    Prior to version 1.10 the default profile for key bindings, called NetBeans, had not been stored in its own folder. Therefore the default key bindings for the NetBeans profile used to be stored directly in Editors/<mime-type>/Defaults/keybindings.xml and similarily user changes used to be stored in Editors/<mime-type>/keybindings.xml. This has been deprecated, but is still supported for backwards compatibility reasons.

    Also the special mime type called text/base, has been deprecated and should not be used anymore. It is however still supported to preserve backwards compatibility.

    Platform specific settings

    Since 1.10 it is possible to mark setting files as applicable only on a certain platform (a.k.a. operating system). This was mainly introduced for keybindings, which are generally platform sensitive settings, but can be used for any other setting type supported by the storage module.

    Some platforms (eg. Mac) define their own special rules for the use of some combinations of keystrokes (eg. ctrl+Q closes the app) that applications on that platform have to obey. NetBeans mitigates this problem by introducing a special module ide/applemenu, which is only loaded on Mac and which overrides keybindings.xml files provided by some Netbeans modules (eg. editor and java). This approach works albeit some severe limitations. However with introducing multiple setting files this would no longer be practical, which is why platform specific settings have been introduced.

    The storage module recognizes a special file attribute for marking platform specific setting files called nbeditor-settings-targetOS. The rules for its use follow.

    • Any file that does not define nbeditor-settings-targetOS is loaded on all platforms. All such files will be loaded exactly in the same order as they appear on the system filesystem.
    • If a file defines nbeditor-settings-targetOS attribute, but its value does not correspond to the current Operating System, the file is ignored.
    • If a file defines nbeditor-settings-targetOS attribute and its value designates the current Operating System, the file will be loaded. Furthermore, any such a file will be loaded after other files in the same folder that do not define this attribute and therefore its settings will override settings from those other files.
    • If there is more files that define nbeditor-settings-targetOS attribute and are eligible for loading on the current Operating System, they will be loaded in the same order as they appear on the system filesystem.

    The available values that can be used for the nbeditor-settings-targetOS attribute are the string names of the OS_* constants in org.openide.util.Utilities class. So, for example the following file will only be loaded on MacOS and its settings will override settings from all other files that do not specify the target OS attribute.

    <folder name="Editors">
      <folder name="Keybindings">
        <folder name="NetBeans">
          <folder name="Defaults">
            <file name="keybindings-for-mac.xml" url="...">
              <attr name="nbeditor-settings-targetOS" stringvalue="OS_MAC"/>
            </file>
          </folder>
        </folder>
      </folder>
    </folder>
    

    Question (arch-usecases): Describe the main use cases of the new API. Who will use it under what circumstances? What kind of code would typically need to be written to use the module?

    Answer:

    New Options Dialog

    The friend API provided by this module is used only by the new options dialog. It is not expected to have any other clients or users. The API gives the options dialog a read/write access to the editor settings storage allowing it to implement UI for maintaining the settings.

    Defining a coloring

    Various modules need to provide predefined font a colors for text tokens from languages they support. An example of such a module is java/editor which defines colorings for tokens in java files. Defining colorings is as simple as writing an XML file with the appropriate information. The example below shows how to do that.

    <?xml version="1.0"  encoding="UTF-8"?>
    <!DOCTYPE fontscolors PUBLIC "-//NetBeans//DTD Editor Fonts and Colors settings 1.1//EN" "http://www.netbeans.org/dtds/EditorFontsColors-1_1.dtd">
    
    <fontscolors>
        <fontcolor name="mylang-keyword" foreColor="0000CC" default="keyword">
            <font style="bold" />
        </fontcolor>
    </fontscolors>
    

    Please see the http://www.netbeans.org/dtds/EditorFontsColors-1_1.dtd for more details.

    Defining a key binding

    As well as providing predefined colorings modules need to provide predefined key bindings. This can be accomplished by writing another simple XML file.

    <?xml version="1.0"  encoding="UTF-8"?>
    <!DOCTYPE bindings PUBLIC "-//NetBeans//DTD Editor KeyBindings settings 1.1//EN" "http://www.netbeans.org/dtds/EditorKeyBindings-1_1.dtd">
    
    <bindings>
        <bind actionName="goto-source" key="O-O"/>
    </bindings>
    

    Please see the http://www.netbeans.org/dtds/EditorKeyBindings-1_1.dtd for more details.

    Question (arch-time): What are the time estimates of the work?

    Answer: The modules is available in CVS trunk.

    Question (arch-quality): How will the quality of your code be tested and how are future regressions going to be prevented?

    Answer: There are unit tests available covering the module's functionality.

    Question (arch-where): Where one can find sources for your module?

    Answer:

    The sources for the module are in NetBeans CVS in editor/settings/storage directory.


Project and platform dependencies

    Question (dep-nb): What other NetBeans projects and modules does this one depend on?

    Answer:

    These modules are required in project.xml:

    • MimeLookupAPI - The module is needed for compilation. The module is used during runtime. Specification version 1.0 is required.
    • EditorSettingsAPI - The module is needed for compilation. The module is used during runtime. Specification version 1.9 is required.
    • FilesystemsAPI - The module is needed for compilation. The module is used during runtime. Specification version 6.2 is required.
    • UtilitiesAPI - The module is needed for compilation. The module is used during runtime. Specification version 6.2 is required.

    Question (dep-non-nb): What other projects outside NetBeans does this one depend on?

    Answer: No other projects.

    Question (dep-platform): On which platforms does your module run? Does it run in the same way on each?

    Answer: All platforms.

    Question (dep-jre): Which version of JRE do you need (1.2, 1.3, 1.4, etc.)?

    Answer: JDK1.4 and higher can be used.

    Question (dep-jrejdk): Do you require the JDK or is the JRE enough?

    Answer: JRE is sufficient.

Deployment

    Question (deploy-jar): Do you deploy just module JAR file(s) or other files as well?

    Answer: No additional files.

    Question (deploy-nbm): Can you deploy an NBM via the Update Center?

    Answer: Yes.

    Question (deploy-shared): Do you need to be installed in the shared location only, or in the user directory only, or can your module be installed anywhere?

    Answer: Anywhere.

    Question (deploy-packages): Are packages of your module made inaccessible by not declaring them public?

    Answer: Yes, only the package with the friend API is public.

    Question (deploy-dependencies): What do other modules need to do to declare a dependency on this one, in addition to or instead of the normal module dependency declaration (e.g. tokens to require)?

    Answer: Nothing.

Compatibility with environment

    Question (compat-i18n): Is your module correctly internationalized?

    Answer: Yes.

    Question (compat-standards): Does the module implement or define any standards? Is the implementation exact or does it deviate somehow?

    Answer: Compatible with standards.

    Question (compat-version): Can your module coexist with earlier and future versions of itself? Can you correctly read all old settings? Will future versions be able to read your current settings? Can you read or politely ignore settings stored by a future version?

    Answer:

    The module stores settings in its own XML files in the folders hierarchy under the Editors folder on the default file system. Changes in settings are stored as differences from the default values.

    The legacy settings are not handled by this module. The editor module itself supports the legacy settings and combines them with the new ones.

    Question (compat-deprecation): How the introduction of your project influences functionality provided by previous version of the product?

    Answer: No changes.

Access to resources

    Question (resources-file): Does your module use java.io.File directly?

    Answer: No.

    Question (resources-layer): Does your module provide own layer? Does it create any files or folders in it? What it is trying to communicate by that and with which components?

    Answer: Yes. The layer is used for registering DTDs in the Netbeans catalog and MIME type resolvers for editor settings files.

    Question (resources-read): Does your module read any resources from layers? For what purpose?

    Answer: Yes. It reads settings files. Please see the format types descriptions here.

    Question (resources-mask): Does your module mask/hide/override any resources provided by other modules in their layers?

    Answer: No.

    Question (resources-preferences): Does your module uses preferences via Preferences API? Does your module use NbPreferences or or regular JDK Preferences ? Does it read, write or both ? Does it share preferences with other modules ? If so, then why ?

    Answer: No.

Lookup of components

    Question (lookup-lookup): Does your module use org.openide.util.Lookup or any similar technology to find any components to communicate with? Which ones?

    Answer: Yes. module creates a new MimeDataProvider and plug it into the MimeLookup. Also EditorSettings implementation is registered into default lookup.

    Question (lookup-register): Do you register anything into lookup for other code to find?

    Answer: Yes. The implementation of MimeDataProvider is registered via META-INF/services.

    Question (lookup-remove): Do you remove entries of other modules from lookup?

    Answer: No.

Execution Environment

    Question (exec-property): Is execution of your code influenced by any environment or Java system (System.getProperty) property? On a similar note, is there something interesting that you pass to java.util.logging.Logger? Or do you observe what others log?

    Answer: No.

    Question (exec-component): Is execution of your code influenced by any (string) property of any of your components?

    Answer: No.

    Question (exec-ant-tasks): Do you define or register any ant tasks that other can use?

    Answer: No.

    Question (exec-classloader): Does your code create its own class loader(s)?

    Answer: No.

    Question (exec-reflection): Does your code use Java Reflection to execute other code?

    Answer: No.

    Question (exec-privateaccess): Are you aware of any other parts of the system calling some of your methods by reflection?

    Answer: No.

    Question (exec-process): Do you execute an external process from your module? How do you ensure that the result is the same on different platforms? Do you parse output? Do you depend on result code?

    Answer: No.

    Question (exec-introspection): Does your module use any kind of runtime type information (instanceof, work with java.lang.Class, etc.)?

    Answer: No.

    Question (exec-threading): What threading models, if any, does your module adhere to? How the project behaves with respect to threading?

    Answer: No special threading model is used.

    Question (security-policy): Does your functionality require modifications to the standard policy file?

    Answer: No.

    Question (security-grant): Does your code grant additional rights to some other code?

    Answer: No.

Format of files and protocols


Performance and Scalability

    Question (perf-startup): Does your module run any code on startup?

    Answer: No.

    Question (perf-exit): Does your module run any code on exit?

    Answer: No.

    Question (perf-scale): Which external criteria influence the performance of your program (size of file in editor, number of files in menu, in source directory, etc.) and how well your code scales?

    Answer: There is no performance sensitive code in the module.

    Question (perf-limit): Are there any hard-coded or practical limits in the number or size of elements your code can handle?

    Answer: No limits.

    Question (perf-mem): How much memory does your component consume? Estimate with a relation to the number of windows, etc.

    Answer: No specific memory usage.

    Question (perf-wakeup): Does any piece of your code wake up periodically and do something even when the system is otherwise idle (no user interaction)?

    Answer: No.

    Question (perf-progress): Does your module execute any long-running tasks?

    Answer: No.

    Question (perf-huge_dialogs): Does your module contain any dialogs or wizards with a large number of GUI controls such as combo boxes, lists, trees, or text areas?

    Answer: No.

    Question (perf-menus): Does your module use dynamically updated context menus, or context-sensitive actions with complicated and slow enablement logic?

    Answer: No.

    Question (perf-spi): How the performance of the plugged in code will be enforced?

    Answer: No pluggins allowad.

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.