editor/settings/storage module provides friend
comprising classes in the
package. It also defines the structure of the settings storage and the structure
of XML files with settings. The following XML files are supported.
-//NetBeans//DTD Editor Fonts and Colors settings 1.1//EN
-//NetBeans//DTD Editor KeyBindings settings 1.1//EN
The setting files are stored in
MimeLookup in the folders hierarchy
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
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.
editor/settings/storage module dedicates a special folder for
each profile and stores all the profile related files in that folder.
The module provides a special treatment for profiles with names starting with
"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
starts with the
"test*_" string (e.g.
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
test*_ string, but it contains
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.
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
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.
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
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
nbeditor-settings-ColoringType, which value can
highlight. If a coloring file does
not specify this attribute it is automatically expected to contain token-related
Generally, the files with default values are stored in
subfolders while the files with user changes are stored directly in the
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>/Defaultsfolders. 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>/Defaultsfolders. If specified in a mime type subfolder it will be ignored.
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
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
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
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
The rules for its use follow.
nbeditor-settings-targetOSis loaded on all platforms. All such files will be loaded exactly in the same order as they appear on the system filesystem.
nbeditor-settings-targetOSattribute, but its value does not correspond to the current Operating System, the file is ignored.
nbeditor-settings-targetOSattribute 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.
nbeditor-settings-targetOSattribute 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
attribute are the string names of the
OS_* constants in
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>
Basic infrastructure for settings separated to a library.
EditorSettings is extended to handle saving and loading annotations colorings for any profile.
Class org.netbeans.modules.editor.settings.storage.api.EditorSettings [sigtest] "E5.2 - Adding abstract methods" : method public abstract void org.netbeans.modules.editor.settings.storage.api.EditorSettings.setAnnotations(java.lang.String,java.util.Map) [sigtest] "E5.2 - Adding abstract methods" : method public abstract java.util.Map org.netbeans.modules.editor.settings.storage.api.EditorSettings.getAnnotations(java.lang.String) [sigtest] "E5.2 - Adding abstract methods" : method public abstract java.util.Map org.netbeans.modules.editor.settings.storage.api.EditorSettings.getAnnotationDefaults(java.lang.String) [sigtest]
OverridePreferences can be used to detect whether the setting is defined for
the specific MIME type, or inherited from default ('all languages') settings.
During options editing,
MemoryPreferences can be used to create Preferences
object, that propagates changes to its (persistent) delegate upon flush().
EditorSettings.PROP_MIME_TYPES to notify about changes in mimetypes returned
StorageDescription now have second parameter, which
is a mime path string of the file being read or writter respectively.
StorageReader.getMimePath method was added alongside
with a new constructor that takse two parameters
that the reader is dealing with and the mime path
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.
Various modules need to provide predefined font a colors for text tokens from
languages they support. An example of such a module is
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.
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.
The sources for the module are in the NetBeans Mercurial repositories.
Read more about the implementation in the answers to architecture questions.
Built on August 28 2016. | Portions Copyright 1997-2016 Oracle. All rights reserved.